ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjMDSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 include_once("./classes/class.ilObjectGUI.php");
24 
25 
37 {
38 
44  public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
45  {
46  global $lng;
47 
48  $this->type = 'mds';
49  parent::ilObjectGUI($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
50 
51  $this->lng = $lng;
52  $this->lng->loadLanguageModule("meta");
53  }
54 
61  public function executeCommand()
62  {
63  global $rbacsystem,$ilErr,$ilAccess;
64 
65  $next_class = $this->ctrl->getNextClass($this);
66  $cmd = $this->ctrl->getCmd();
67 
68  $this->prepareOutput();
69 
70  if(!$ilAccess->checkAccess('read','',$this->object->getRefId()))
71  {
72  $ilErr->raiseError($this->lng->txt('no_permission'),$ilErr->WARNING);
73  }
74 
75  switch($next_class)
76  {
77  case 'iladvancedmdsettingsgui':
78  $this->tabs_gui->setTabActive('md_advanced');
79  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDSettingsGUI.php');
80  $adv_md = new ilAdvancedMDSettingsGUI();
81  $ret = $this->ctrl->forwardCommand($adv_md);
82  break;
83 
84  case 'ilpermissiongui':
85  $this->tabs_gui->setTabActive('perm_settings');
86  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
87  $perm_gui =& new ilPermissionGUI($this);
88  $ret =& $this->ctrl->forwardCommand($perm_gui);
89  break;
90 
91  default:
92  $this->initMDSettings();
93  if(!$cmd || $cmd == 'view')
94  {
95  $cmd = "showGeneralSettings";
96  }
97 
98  $this->$cmd();
99  break;
100  }
101  return true;
102  }
103 
110  public function getAdminTabs()
111  {
112  global $rbacsystem, $ilAccess;
113 
114  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
115  {
116  $this->tabs_gui->addTarget("md_general_settings",
117  $this->ctrl->getLinkTarget($this, "showGeneralSettings"),
118  array("showGeneralSettings", "view"));
119 
120  $this->tabs_gui->addTarget("md_copyright",
121  $this->ctrl->getLinkTarget($this, "showCopyrightSettings"),
122  array("showCopyrightSettings"));
123 
124  $this->tabs_gui->addTarget("md_advanced",
125  $this->ctrl->getLinkTargetByClass('iladvancedmdsettingsgui', ""),
126  '',
127  'iladvancedmdsettingsgui');
128 
129  }
130 
131  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
132  {
133  $this->tabs_gui->addTarget("perm_settings",
134  $this->ctrl->getLinkTargetByClass('ilpermissiongui',"perm"),
135  array(),'ilpermissiongui');
136  }
137  }
138 
142  public function showGeneralSettings()
143  {
144  global $tpl;
145 
146  $this->initGeneralSettingsForm();
147  $tpl->setContent($this->form->getHTML());
148  }
149 
155  public function initGeneralSettingsForm($a_mode = "edit")
156  {
157  global $lng;
158 
159  $this->tabs_gui->setTabActive('md_general_settings');
160 
161  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
162  $this->form = new ilPropertyFormGUI();
163 
164  $ti = new ilTextInputGUI($this->lng->txt("md_delimiter"), "delimiter");
165  $ti->setInfo($this->lng->txt("md_delimiter_info"));
166  $ti->setMaxLength(1);
167  $ti->setSize(1);
168  $ti->setValue($this->md_settings->getDelimiter());
169  $this->form->addItem($ti);
170 
171  $this->form->addCommandButton("saveGeneralSettings", $lng->txt("save"));
172  $this->form->addCommandButton("showGeneralSettings", $lng->txt("cancel"));
173 
174  $this->form->setTitle($lng->txt("md_general_settings"));
175  $this->form->setFormAction($this->ctrl->getFormAction($this));
176 
177  }
178 
183  {
184  global $ilCtrl;
185 
186  $delim = (trim($_POST['delimiter']) == "")
187  ? ","
188  : trim($_POST['delimiter']);
189  $this->md_settings->setDelimiter($delim);
190  $this->md_settings->save();
191  ilUtil::sendInfo($this->lng->txt('settings_saved'), true);
192 
193  $ilCtrl->redirect($this, "showGeneralSettings");
194  }
195 
196 
200  public function showCopyrightSettings()
201  {
202  $this->tabs_gui->setTabActive('md_copyright');
203  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.settings.html','Services/MetaData');
204 
205  $this->initSettingsForm();
206  $this->tpl->setVariable('SETTINGS_TABLE',$this->form->getHTML());
207 
208  include_once("./Services/MetaData/classes/class.ilMDCopyrightTableGUI.php");
209  $table_gui = new ilMDCopyrightTableGUI($this,'showCopyrightSettings');
210  $table_gui->setTitle($this->lng->txt("md_copyright_selection"));
211  $table_gui->parseSelections();
212 // $table_gui->addCommandButton("updateCopyrightSelection", $this->lng->txt("save"));
213  $table_gui->addCommandButton('addEntry',$this->lng->txt('add'));
214  $table_gui->addMultiCommand("confirmDeleteEntries", $this->lng->txt("delete"));
215  $table_gui->setSelectAllCheckbox("entry_id");
216  $this->tpl->setVariable('COPYRIGHT_TABLE',$table_gui->getHTML());
217  }
218 
222  public function saveCopyrightSettings()
223  {
224  $this->md_settings->activateCopyrightSelection((int) $_POST['active']);
225  $this->md_settings->save();
226  ilUtil::sendInfo($this->lng->txt('settings_saved'));
227  $this->showCopyrightSettings();
228  }
229 
230 
237  public function editEntry()
238  {
239  $this->ctrl->saveParameter($this,'entry_id');
240  $this->initCopyrightEditForm();
241  $this->tpl->setContent($this->form->getHTML());
242  }
243 
251  public function addEntry()
252  {
253  $this->initCopyrightEditForm('add');
254  $this->tpl->setContent($this->form->getHTML());
255  }
256 
257 
264  public function saveEntry()
265  {
266  global $ilErr;
267 
268  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
269  $this->entry = new ilMDCopyrightSelectionEntry(0);
270 
271  $this->entry->setTitle(ilUtil::stripSlashes($_POST['title']));
272  $this->entry->setDescription(ilUtil::stripSlashes($_POST['description']));
273  $this->entry->setCopyright($this->stripSlashes($_POST['copyright']));
274  $this->entry->setLanguage('en');
275  $this->entry->setCopyrightAndOtherRestrictions(true);
276  $this->entry->setCosts(false);
277 
278  if(!$this->entry->validate())
279  {
280  ilUtil::sendInfo($this->lng->txt('fill_out_all_required_fields'));
281  $this->addEntry();
282  return false;
283  }
284  $this->entry->add();
285  ilUtil::sendInfo($this->lng->txt('settings_saved'));
286  $this->showCopyrightSettings();
287  return true;
288  }
289 
296  public function confirmDeleteEntries()
297  {
298  if(!is_array($_POST['entry_id']) or !count($_POST['entry_id']))
299  {
300  ilUtil::sendInfo($this->lng->txt('select_one'));
301  $this->showCopyrightSettings();
302  return true;
303  }
304 
305  include_once('Services/Utilities/classes/class.ilConfirmationGUI.php');
306  $c_gui = new ilConfirmationGUI();
307 
308  // set confirm/cancel commands
309  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteEntries"));
310  $c_gui->setHeaderText($this->lng->txt("md_delete_cp_sure"));
311  $c_gui->setCancel($this->lng->txt("cancel"), "showCopyrightSettings");
312  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteEntries");
313 
314  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
315 
316  // add items to delete
317  foreach($_POST["entry_id"] as $entry_id)
318  {
319  $entry = new ilMDCopyrightSelectionEntry($entry_id);
320  $c_gui->addItem('entry_id[]',$entry_id,$entry->getTitle());
321  }
322  $this->tpl->setContent($c_gui->getHTML());
323  }
324 
331  public function deleteEntries()
332  {
333  if(!is_array($_POST['entry_id']) or !count($_POST['entry_id']))
334  {
335  ilUtil::sendInfo($this->lng->txt('select_one'));
336  $this->showCopyrightSettings();
337  return true;
338  }
339 
340  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
341  foreach($_POST["entry_id"] as $entry_id)
342  {
343  $entry = new ilMDCopyrightSelectionEntry($entry_id);
344  $entry->delete();
345  }
346  ilUtil::sendInfo($this->lng->txt('md_copyrights_deleted'));
347  $this->showCopyrightSettings();
348  return true;
349  }
350 
357  public function updateEntry()
358  {
359  global $ilErr;
360 
361  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
362  $this->entry = new ilMDCopyrightSelectionEntry((int) $_REQUEST['entry_id']);
363 
364  $this->entry->setTitle(ilUtil::stripSlashes($_POST['title']));
365  $this->entry->setDescription(ilUtil::stripSlashes($_POST['description']));
366  $this->entry->setCopyright($this->stripSlashes($_POST['copyright']));
367 
368  if(!$this->entry->validate())
369  {
370  ilUtil::sendInfo($this->lng->txt('fill_out_all_required_fields'));
371  $this->editEntry();
372  return false;
373  }
374  $this->entry->update();
375  ilUtil::sendInfo($this->lng->txt('settings_saved'));
376  $this->showCopyrightSettings();
377  return true;
378  }
379 
380 
386  protected function initSettingsForm()
387  {
388  if(is_object($this->form))
389  {
390  return true;
391  }
392  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
393  $this->form = new ilPropertyFormGUI();
394  $this->form->setFormAction($this->ctrl->getFormAction($this));
395  $this->form->setTitle($this->lng->txt('md_copyright_settings'));
396  $this->form->addCommandButton('saveCopyrightSettings',$this->lng->txt('save'));
397  $this->form->addCommandButton('showCopyrightSettings',$this->lng->txt('cancel'));
398 
399  $check = new ilCheckboxInputGUI($this->lng->txt('md_copyright_enabled'),'active');
400  $check->setChecked($this->md_settings->isCopyrightSelectionActive());
401  $check->setValue(1);
402  $check->setInfo($this->lng->txt('md_copyright_enable_info'));
403  $this->form->addItem($check);
404  }
405 
413  public function initCopyrightEditForm($a_mode = 'edit')
414  {
415  if(is_object($this->form))
416  {
417  return true;
418  }
419  if(!is_object($this->entry))
420  {
421  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
422  $this->entry = new ilMDCopyrightSelectionEntry((int) $_REQUEST['entry_id']);
423  }
424 
425  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
426  $this->form = new ilPropertyFormGUI();
427  $this->form->setFormAction($this->ctrl->getFormAction($this));
428 
429  $tit = new ilTextInputGUI($this->lng->txt('title'),'title');
430  $tit->setValue($this->entry->getTitle());
431  $tit->setRequired(true);
432  $tit->setSize(40);
433  $tit->setMaxLength(255);
434  $this->form->addItem($tit);
435 
436  $des = new ilTextAreaInputGUI($this->lng->txt('description'),'description');
437  $des->setValue($this->entry->getDescription());
438  $des->setRows(3);
439  $this->form->addItem($des);
440 
441  $cop = new ilTextAreaInputGUI($this->lng->txt('md_copyright_value'),'copyright');
442  $cop->setValue($this->entry->getCopyright());
443  $cop->setRows(5);
444  $this->form->addItem($cop);
445 
446  switch($a_mode)
447  {
448  case 'edit':
449  $this->form->setTitle($this->lng->txt('md_copyright_edit'));
450  $this->form->addCommandButton('updateEntry',$this->lng->txt('save'));
451  $this->form->addCommandButton('showCopyrightSettings',$this->lng->txt('cancel'));
452  break;
453 
454  case 'add':
455  $this->form->setTitle($this->lng->txt('md_copyright_add'));
456  $this->form->addCommandButton('saveEntry',$this->lng->txt('save'));
457  $this->form->addCommandButton('showCopyrightSettings',$this->lng->txt('cancel'));
458  break;
459  }
460 
461  }
462 
468  protected function initMDSettings()
469  {
470  include_once('Services/MetaData/classes/class.ilMDSettings.php');
471  $this->md_settings = ilMDSettings::_getInstance();
472  }
473 
479  protected function stripSlashes($a_str)
480  {
481  if (ini_get("magic_quotes_gpc"))
482  {
483  $a_str = stripslashes($a_str);
484  }
485  return $a_str;
486  }
487 }
488 ?>