ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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("./Services/Object/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::__construct($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, $ilAccess;
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  if($ilAccess->checkAccess('write','',$this->object->getRefId()))
172  {
173  $this->form->addCommandButton("saveGeneralSettings", $lng->txt("save"));
174  $this->form->addCommandButton("showGeneralSettings", $lng->txt("cancel"));
175  }
176 
177  $this->form->setTitle($lng->txt("md_general_settings"));
178  $this->form->setFormAction($this->ctrl->getFormAction($this));
179 
180  }
181 
186  {
187  global $ilCtrl, $ilAccess;
188 
189  if(!$ilAccess->checkAccess('write','',$this->object->getRefId()))
190  {
191  $ilCtrl->redirect($this, "showGeneralSettings");
192  }
193 
194  $delim = (trim($_POST['delimiter']) == "")
195  ? ","
196  : trim($_POST['delimiter']);
197  $this->md_settings->setDelimiter($delim);
198  $this->md_settings->save();
199  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
200 
201  $ilCtrl->redirect($this, "showGeneralSettings");
202  }
203 
204 
208  public function showCopyrightSettings()
209  {
210  global $ilAccess;
211 
212  $this->tabs_gui->setTabActive('md_copyright');
213  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.settings.html','Services/MetaData');
214 
215  $this->initSettingsForm();
216  $this->tpl->setVariable('SETTINGS_TABLE',$this->form->getHTML());
217 
218  $has_write = $ilAccess->checkAccess('write','',$this->object->getRefId());
219 
220  include_once("./Services/MetaData/classes/class.ilMDCopyrightTableGUI.php");
221  $table_gui = new ilMDCopyrightTableGUI($this,'showCopyrightSettings', $has_write);
222  $table_gui->setTitle($this->lng->txt("md_copyright_selection"));
223  $table_gui->parseSelections();
224 
225  if($has_write)
226  {
227  // $table_gui->addCommandButton("updateCopyrightSelection", $this->lng->txt("save"));
228  $table_gui->addCommandButton('addEntry',$this->lng->txt('add'));
229  $table_gui->addMultiCommand("confirmDeleteEntries", $this->lng->txt("delete"));
230  $table_gui->setSelectAllCheckbox("entry_id");
231  }
232 
233  $this->tpl->setVariable('COPYRIGHT_TABLE',$table_gui->getHTML());
234  }
235 
239  public function saveCopyrightSettings()
240  {
241  global $ilAccess;
242 
243  if(!$ilAccess->checkAccess('write','',$this->object->getRefId()))
244  {
245  $this->ctrl->redirect($this, "showCopyrightSettings");
246  }
247 
248  $this->md_settings->activateCopyrightSelection((int) $_POST['active']);
249  $this->md_settings->save();
250  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
251  $this->showCopyrightSettings();
252  }
253 
254 
261  public function editEntry()
262  {
263  $this->ctrl->saveParameter($this,'entry_id');
264  $this->initCopyrightEditForm();
265  $this->tpl->setContent($this->form->getHTML());
266  }
267 
275  public function addEntry()
276  {
277  $this->initCopyrightEditForm('add');
278  $this->tpl->setContent($this->form->getHTML());
279  }
280 
281 
288  public function saveEntry()
289  {
290  global $ilErr;
291 
292  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
293  $this->entry = new ilMDCopyrightSelectionEntry(0);
294 
295  $this->entry->setTitle(ilUtil::stripSlashes($_POST['title']));
296  $this->entry->setDescription(ilUtil::stripSlashes($_POST['description']));
297  $this->entry->setCopyright($this->stripSlashes($_POST['copyright']));
298  $this->entry->setLanguage('en');
299  $this->entry->setCopyrightAndOtherRestrictions(true);
300  $this->entry->setCosts(false);
301 
302  if(!$this->entry->validate())
303  {
304  ilUtil::sendInfo($this->lng->txt('fill_out_all_required_fields'));
305  $this->addEntry();
306  return false;
307  }
308  $this->entry->add();
309  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
310  $this->showCopyrightSettings();
311  return true;
312  }
313 
320  public function confirmDeleteEntries()
321  {
322  if(!is_array($_POST['entry_id']) or !count($_POST['entry_id']))
323  {
324  ilUtil::sendInfo($this->lng->txt('select_one'));
325  $this->showCopyrightSettings();
326  return true;
327  }
328 
329  include_once('Services/Utilities/classes/class.ilConfirmationGUI.php');
330  $c_gui = new ilConfirmationGUI();
331 
332  // set confirm/cancel commands
333  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteEntries"));
334  $c_gui->setHeaderText($this->lng->txt("md_delete_cp_sure"));
335  $c_gui->setCancel($this->lng->txt("cancel"), "showCopyrightSettings");
336  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteEntries");
337 
338  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
339 
340  // add items to delete
341  foreach($_POST["entry_id"] as $entry_id)
342  {
343  $entry = new ilMDCopyrightSelectionEntry($entry_id);
344  $c_gui->addItem('entry_id[]',$entry_id,$entry->getTitle());
345  }
346  $this->tpl->setContent($c_gui->getHTML());
347  }
348 
355  public function deleteEntries()
356  {
357  if(!is_array($_POST['entry_id']) or !count($_POST['entry_id']))
358  {
359  ilUtil::sendInfo($this->lng->txt('select_one'));
360  $this->showCopyrightSettings();
361  return true;
362  }
363 
364  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
365  foreach($_POST["entry_id"] as $entry_id)
366  {
367  $entry = new ilMDCopyrightSelectionEntry($entry_id);
368  $entry->delete();
369  }
370  ilUtil::sendSuccess($this->lng->txt('md_copyrights_deleted'));
371  $this->showCopyrightSettings();
372  return true;
373  }
374 
381  public function updateEntry()
382  {
383  global $ilErr;
384 
385  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
386  $this->entry = new ilMDCopyrightSelectionEntry((int) $_REQUEST['entry_id']);
387 
388  $this->entry->setTitle(ilUtil::stripSlashes($_POST['title']));
389  $this->entry->setDescription(ilUtil::stripSlashes($_POST['description']));
390  $this->entry->setCopyright($this->stripSlashes($_POST['copyright']));
391 
392  if(!$this->entry->validate())
393  {
394  ilUtil::sendInfo($this->lng->txt('fill_out_all_required_fields'));
395  $this->editEntry();
396  return false;
397  }
398  $this->entry->update();
399  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
400  $this->showCopyrightSettings();
401  return true;
402  }
403 
404 
410  protected function initSettingsForm()
411  {
412  global $ilAccess;
413 
414  if(is_object($this->form))
415  {
416  return true;
417  }
418  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
419  $this->form = new ilPropertyFormGUI();
420  $this->form->setFormAction($this->ctrl->getFormAction($this));
421  $this->form->setTitle($this->lng->txt('md_copyright_settings'));
422 
423  if($ilAccess->checkAccess('write','',$this->object->getRefId()))
424  {
425  $this->form->addCommandButton('saveCopyrightSettings',$this->lng->txt('save'));
426  $this->form->addCommandButton('showCopyrightSettings',$this->lng->txt('cancel'));
427  }
428 
429  $check = new ilCheckboxInputGUI($this->lng->txt('md_copyright_enabled'),'active');
430  $check->setChecked($this->md_settings->isCopyrightSelectionActive());
431  $check->setValue(1);
432  $check->setInfo($this->lng->txt('md_copyright_enable_info'));
433  $this->form->addItem($check);
434  }
435 
443  public function initCopyrightEditForm($a_mode = 'edit')
444  {
445  if(is_object($this->form))
446  {
447  return true;
448  }
449  if(!is_object($this->entry))
450  {
451  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
452  $this->entry = new ilMDCopyrightSelectionEntry((int) $_REQUEST['entry_id']);
453  }
454 
455  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
456  $this->form = new ilPropertyFormGUI();
457  $this->form->setFormAction($this->ctrl->getFormAction($this));
458 
459  $tit = new ilTextInputGUI($this->lng->txt('title'),'title');
460  $tit->setValue($this->entry->getTitle());
461  $tit->setRequired(true);
462  $tit->setSize(40);
463  $tit->setMaxLength(255);
464  $this->form->addItem($tit);
465 
466  $des = new ilTextAreaInputGUI($this->lng->txt('description'),'description');
467  $des->setValue($this->entry->getDescription());
468  $des->setRows(3);
469  $this->form->addItem($des);
470 
471  $cop = new ilTextAreaInputGUI($this->lng->txt('md_copyright_value'),'copyright');
472  $cop->setValue($this->entry->getCopyright());
473  $cop->setRows(5);
474  $this->form->addItem($cop);
475 
476  switch($a_mode)
477  {
478  case 'edit':
479  $this->form->setTitle($this->lng->txt('md_copyright_edit'));
480  $this->form->addCommandButton('updateEntry',$this->lng->txt('save'));
481  $this->form->addCommandButton('showCopyrightSettings',$this->lng->txt('cancel'));
482  break;
483 
484  case 'add':
485  $this->form->setTitle($this->lng->txt('md_copyright_add'));
486  $this->form->addCommandButton('saveEntry',$this->lng->txt('save'));
487  $this->form->addCommandButton('showCopyrightSettings',$this->lng->txt('cancel'));
488  break;
489  }
490 
491  }
492 
498  protected function initMDSettings()
499  {
500  include_once('Services/MetaData/classes/class.ilMDSettings.php');
501  $this->md_settings = ilMDSettings::_getInstance();
502  }
503 
509  protected function stripSlashes($a_str)
510  {
511  if (ini_get("magic_quotes_gpc"))
512  {
513  $a_str = stripslashes($a_str);
514  }
515  return $a_str;
516  }
517 }
518 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
initMDSettings()
init Md settings
global $ilErr
Definition: raiseError.php:16
stripSlashes($a_str)
Special function to strip slashes for copyright fields.
executeCommand()
Execute command.
showGeneralSettings()
Edit general settings.
This class represents a property form user interface.
saveCopyrightSettings()
Save news and external webfeeds settings.
showCopyrightSettings()
Edit copyright settings.
$cmd
Definition: sahs_server.php:35
setValue($a_value)
Set Value.
This class represents a checkbox property in a property form.
saveGeneralSettings()
Save general settings.
global $ilCtrl
Definition: ilias.php:18
static _getInstance()
get instance
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
Contructor.
setInfo($a_info)
Set Information Text.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
editEntry()
edit one selection
setChecked($a_checked)
Set Checked.
prepareOutput($a_show_subobjects=true)
prepare output
Class ilObjectGUI Basic methods of all Output classes.
This class represents a text property in a property form.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Create styles array
The data for the language used.
updateEntry()
update one entry
initGeneralSettingsForm($a_mode="edit")
Init general settings form.
Create new PHPExcel object
obj_idprivate
initCopyrightEditForm($a_mode='edit')
public
confirmDeleteEntries()
confirm deletion of entries
This class represents a text area property in a property form.
$ret
Definition: parser.php:6
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
setValue($a_value)
Set Value.
$_POST["username"]
Confirmation screen class.