ILIAS  Release_3_10_x_branch Revision 61812
 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("./classes/class.ilPermissionGUI.php");
87  $perm_gui =& new ilPermissionGUI($this);
88  $ret =& $this->ctrl->forwardCommand($perm_gui);
89  break;
90 
91  default:
92  $this->tabs_gui->setTabActive('md_copyright');
93  $this->initMDSettings();
94  if(!$cmd || $cmd == 'view')
95  {
96  $cmd = "settings";
97  }
98 
99  $this->$cmd();
100  break;
101  }
102  return true;
103  }
104 
111  public function getAdminTabs()
112  {
113  global $rbacsystem, $ilAccess;
114 
115  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
116  {
117  $this->tabs_gui->addTarget("md_copyright",
118  $this->ctrl->getLinkTarget($this, "settings"),
119  array("settings", "view"));
120 
121  $this->tabs_gui->addTarget("md_advanced",
122  $this->ctrl->getLinkTargetByClass('iladvancedmdsettingsgui', ""),
123  '',
124  'iladvancedmdsettingsgui');
125 
126  }
127 
128  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
129  {
130  $this->tabs_gui->addTarget("perm_settings",
131  $this->ctrl->getLinkTargetByClass('ilpermissiongui',"perm"),
132  array(),'ilpermissiongui');
133  }
134  }
135 
139  public function settings()
140  {
141  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.settings.html','Services/MetaData');
142 
143  $this->initSettingsForm();
144  $this->tpl->setVariable('SETTINGS_TABLE',$this->form->getHTML());
145 
146  include_once("./Services/MetaData/classes/class.ilMDCopyrightTableGUI.php");
147  $table_gui = new ilMDCopyrightTableGUI($this,'settings');
148  $table_gui->setTitle($this->lng->txt("md_copyright_selection"));
149  $table_gui->parseSelections();
150 // $table_gui->addCommandButton("updateCopyrightSelection", $this->lng->txt("save"));
151  $table_gui->addCommandButton('addEntry',$this->lng->txt('add'));
152  $table_gui->addMultiCommand("confirmDeleteEntries", $this->lng->txt("delete"));
153  $table_gui->setSelectAllCheckbox("entry_id");
154  $this->tpl->setVariable('COPYRIGHT_TABLE',$table_gui->getHTML());
155 
156 
157  }
158 
162  public function saveSettings()
163  {
164  $this->md_settings->activateCopyrightSelection((int) $_POST['active']);
165  $this->md_settings->save();
166  ilUtil::sendInfo($this->lng->txt('settings_saved'));
167  $this->settings();
168  }
169 
170 
177  public function editEntry()
178  {
179  $this->ctrl->saveParameter($this,'entry_id');
180  $this->initCopyrightEditForm();
181  $this->tpl->setContent($this->form->getHTML());
182  }
183 
191  public function addEntry()
192  {
193  $this->initCopyrightEditForm('add');
194  $this->tpl->setContent($this->form->getHTML());
195  }
196 
197 
204  public function saveEntry()
205  {
206  global $ilErr;
207 
208  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
209  $this->entry = new ilMDCopyrightSelectionEntry(0);
210 
211  $this->entry->setTitle(ilUtil::stripSlashes($_POST['title']));
212  $this->entry->setDescription(ilUtil::stripSlashes($_POST['description']));
213  $this->entry->setCopyright($this->stripSlashes($_POST['copyright']));
214  $this->entry->setLanguage('en');
215  $this->entry->setCopyrightAndOtherRestrictions(true);
216  $this->entry->setCosts(false);
217 
218  if(!$this->entry->validate())
219  {
220  ilUtil::sendInfo($this->lng->txt('fill_out_all_required_fields'));
221  $this->addEntry();
222  return false;
223  }
224  $this->entry->add();
225  ilUtil::sendInfo($this->lng->txt('settings_saved'));
226  $this->settings();
227  return true;
228  }
229 
236  public function confirmDeleteEntries()
237  {
238  if(!is_array($_POST['entry_id']) or !count($_POST['entry_id']))
239  {
240  ilUtil::sendInfo($this->lng->txt('select_one'));
241  $this->settings();
242  return true;
243  }
244 
245  include_once('Services/Utilities/classes/class.ilConfirmationGUI.php');
246  $c_gui = new ilConfirmationGUI();
247 
248  // set confirm/cancel commands
249  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteEntries"));
250  $c_gui->setHeaderText($this->lng->txt("md_delete_cp_sure"));
251  $c_gui->setCancel($this->lng->txt("cancel"), "settings");
252  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteEntries");
253 
254  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
255 
256  // add items to delete
257  foreach($_POST["entry_id"] as $entry_id)
258  {
259  $entry = new ilMDCopyrightSelectionEntry($entry_id);
260  $c_gui->addItem('entry_id[]',$entry_id,$entry->getTitle());
261  }
262  $this->tpl->setContent($c_gui->getHTML());
263  }
264 
271  public function deleteEntries()
272  {
273  if(!is_array($_POST['entry_id']) or !count($_POST['entry_id']))
274  {
275  ilUtil::sendInfo($this->lng->txt('select_one'));
276  $this->settings();
277  return true;
278  }
279 
280  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
281  foreach($_POST["entry_id"] as $entry_id)
282  {
283  $entry = new ilMDCopyrightSelectionEntry($entry_id);
284  $entry->delete();
285  }
286  ilUtil::sendInfo($this->lng->txt('md_copyrights_deleted'));
287  $this->settings();
288  return true;
289  }
290 
297  public function updateEntry()
298  {
299  global $ilErr;
300 
301  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
302  $this->entry = new ilMDCopyrightSelectionEntry((int) $_REQUEST['entry_id']);
303 
304  $this->entry->setTitle(ilUtil::stripSlashes($_POST['title']));
305  $this->entry->setDescription(ilUtil::stripSlashes($_POST['description']));
306  $this->entry->setCopyright($this->stripSlashes($_POST['copyright']));
307 
308  if(!$this->entry->validate())
309  {
310  ilUtil::sendInfo($this->lng->txt('fill_out_all_required_fields'));
311  $this->editEntry();
312  return false;
313  }
314  $this->entry->update();
315  ilUtil::sendInfo($this->lng->txt('settings_saved'));
316  $this->settings();
317  return true;
318  }
319 
320 
326  protected function initSettingsForm()
327  {
328  if(is_object($this->form))
329  {
330  return true;
331  }
332  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
333  $this->form = new ilPropertyFormGUI();
334  $this->form->setFormAction($this->ctrl->getFormAction($this));
335  $this->form->setTitle($this->lng->txt('md_copyright_settings'));
336  $this->form->addCommandButton('saveSettings',$this->lng->txt('save'));
337  $this->form->addCommandButton('settings',$this->lng->txt('cancel'));
338 
339  $check = new ilCheckboxInputGUI($this->lng->txt('md_copyright_enabled'),'active');
340  $check->setChecked($this->md_settings->isCopyrightSelectionActive());
341  $check->setValue(1);
342  $check->setInfo($this->lng->txt('md_copyright_enable_info'));
343  $this->form->addItem($check);
344  }
345 
353  public function initCopyrightEditForm($a_mode = 'edit')
354  {
355  if(is_object($this->form))
356  {
357  return true;
358  }
359  if(!is_object($this->entry))
360  {
361  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
362  $this->entry = new ilMDCopyrightSelectionEntry((int) $_REQUEST['entry_id']);
363  }
364 
365  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
366  $this->form = new ilPropertyFormGUI();
367  $this->form->setFormAction($this->ctrl->getFormAction($this));
368 
369  $tit = new ilTextInputGUI($this->lng->txt('title'),'title');
370  $tit->setValue($this->entry->getTitle());
371  $tit->setRequired(true);
372  $tit->setSize(40);
373  $tit->setMaxLength(255);
374  $this->form->addItem($tit);
375 
376  $des = new ilTextAreaInputGUI($this->lng->txt('description'),'description');
377  $des->setValue($this->entry->getDescription());
378  $des->setRows(3);
379  $this->form->addItem($des);
380 
381  $cop = new ilTextAreaInputGUI($this->lng->txt('md_copyright_value'),'copyright');
382  $cop->setValue($this->entry->getCopyright());
383  $cop->setRows(5);
384  $this->form->addItem($cop);
385 
386  switch($a_mode)
387  {
388  case 'edit':
389  $this->form->setTitle($this->lng->txt('md_copyright_edit'));
390  $this->form->addCommandButton('updateEntry',$this->lng->txt('save'));
391  $this->form->addCommandButton('settings',$this->lng->txt('cancel'));
392  break;
393 
394  case 'add':
395  $this->form->setTitle($this->lng->txt('md_copyright_add'));
396  $this->form->addCommandButton('saveEntry',$this->lng->txt('save'));
397  $this->form->addCommandButton('settings',$this->lng->txt('cancel'));
398  break;
399  }
400 
401  }
402 
408  protected function initMDSettings()
409  {
410  include_once('Services/MetaData/classes/class.ilMDSettings.php');
411  $this->md_settings = ilMDSettings::_getInstance();
412  }
413 
419  protected function stripSlashes($a_str)
420  {
421  if (ini_get("magic_quotes_gpc"))
422  {
423  $a_str = stripslashes($a_str);
424  }
425  return $a_str;
426  }
427 }
428 ?>