ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  $ilErr->raiseError($this->lng->txt('no_permission'), $ilErr->WARNING);
72  }
73 
74  switch ($next_class) {
75  case 'iladvancedmdsettingsgui':
76  $this->tabs_gui->setTabActive('md_advanced');
77  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDSettingsGUI.php');
78  $adv_md = new ilAdvancedMDSettingsGUI();
79  $ret = $this->ctrl->forwardCommand($adv_md);
80  break;
81 
82  case 'ilpermissiongui':
83  $this->tabs_gui->setTabActive('perm_settings');
84  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
85  $perm_gui = new ilPermissionGUI($this);
86  $ret =&$this->ctrl->forwardCommand($perm_gui);
87  break;
88 
89  default:
90  $this->initMDSettings();
91  if (!$cmd || $cmd == 'view') {
92  $cmd = "showGeneralSettings";
93  }
94 
95  $this->$cmd();
96  break;
97  }
98  return true;
99  }
100 
107  public function getAdminTabs()
108  {
109  global $rbacsystem, $ilAccess;
110 
111  if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
112  $this->tabs_gui->addTarget(
113  "md_general_settings",
114  $this->ctrl->getLinkTarget($this, "showGeneralSettings"),
115  array("showGeneralSettings", "view")
116  );
117 
118  $this->tabs_gui->addTarget(
119  "md_copyright",
120  $this->ctrl->getLinkTarget($this, "showCopyrightSettings"),
121  array("showCopyrightSettings")
122  );
123 
124  $this->tabs_gui->addTarget(
125  "md_advanced",
126  $this->ctrl->getLinkTargetByClass('iladvancedmdsettingsgui', ""),
127  '',
128  'iladvancedmdsettingsgui'
129  );
130  }
131 
132  if ($rbacsystem->checkAccess('edit_permission', $this->object->getRefId())) {
133  $this->tabs_gui->addTarget(
134  "perm_settings",
135  $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm"),
136  array(),
137  'ilpermissiongui'
138  );
139  }
140  }
141 
145  public function showGeneralSettings()
146  {
147  global $tpl;
148 
149  $this->initGeneralSettingsForm();
150  $tpl->setContent($this->form->getHTML());
151  }
152 
158  public function initGeneralSettingsForm($a_mode = "edit")
159  {
160  global $lng, $ilAccess;
161 
162  $this->tabs_gui->setTabActive('md_general_settings');
163 
164  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
165  $this->form = new ilPropertyFormGUI();
166 
167  $ti = new ilTextInputGUI($this->lng->txt("md_delimiter"), "delimiter");
168  $ti->setInfo($this->lng->txt("md_delimiter_info"));
169  $ti->setMaxLength(1);
170  $ti->setSize(1);
171  $ti->setValue($this->md_settings->getDelimiter());
172  $this->form->addItem($ti);
173 
174  if ($ilAccess->checkAccess('write', '', $this->object->getRefId())) {
175  $this->form->addCommandButton("saveGeneralSettings", $lng->txt("save"));
176  $this->form->addCommandButton("showGeneralSettings", $lng->txt("cancel"));
177  }
178 
179  $this->form->setTitle($lng->txt("md_general_settings"));
180  $this->form->setFormAction($this->ctrl->getFormAction($this));
181  }
182 
186  public function saveGeneralSettings()
187  {
188  global $ilCtrl, $ilAccess;
189 
190  if (!$ilAccess->checkAccess('write', '', $this->object->getRefId())) {
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  // $table_gui->addCommandButton("updateCopyrightSelection", $this->lng->txt("save"));
227  $table_gui->addCommandButton('addEntry', $this->lng->txt('add'));
228  $table_gui->addMultiCommand("confirmDeleteEntries", $this->lng->txt("delete"));
229  $table_gui->setSelectAllCheckbox("entry_id");
230  }
231 
232  $this->tpl->setVariable('COPYRIGHT_TABLE', $table_gui->getHTML());
233  }
234 
238  public function saveCopyrightSettings()
239  {
240  global $ilAccess;
241 
242  if (!$ilAccess->checkAccess('write', '', $this->object->getRefId())) {
243  $this->ctrl->redirect($this, "showCopyrightSettings");
244  }
245 
246  $this->md_settings->activateCopyrightSelection((int) $_POST['active']);
247  $this->md_settings->save();
248  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
249  $this->showCopyrightSettings();
250  }
251 
252 
259  public function editEntry()
260  {
261  $this->ctrl->saveParameter($this, 'entry_id');
262  $this->initCopyrightEditForm();
263  $this->tpl->setContent($this->form->getHTML());
264  }
265 
273  public function addEntry()
274  {
275  $this->initCopyrightEditForm('add');
276  $this->tpl->setContent($this->form->getHTML());
277  }
278 
279 
286  public function saveEntry()
287  {
288  global $ilErr;
289 
290  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
291  $this->entry = new ilMDCopyrightSelectionEntry(0);
292 
293  $this->entry->setTitle(ilUtil::stripSlashes($_POST['title']));
294  $this->entry->setDescription(ilUtil::stripSlashes($_POST['description']));
295  $this->entry->setCopyright($this->stripSlashes($_POST['copyright']));
296  $this->entry->setLanguage('en');
297  $this->entry->setCopyrightAndOtherRestrictions(true);
298  $this->entry->setCosts(false);
299 
300  if (!$this->entry->validate()) {
301  ilUtil::sendInfo($this->lng->txt('fill_out_all_required_fields'));
302  $this->addEntry();
303  return false;
304  }
305  $this->entry->add();
306  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
307  $this->showCopyrightSettings();
308  return true;
309  }
310 
317  public function confirmDeleteEntries()
318  {
319  if (!is_array($_POST['entry_id']) or !count($_POST['entry_id'])) {
320  ilUtil::sendInfo($this->lng->txt('select_one'));
321  $this->showCopyrightSettings();
322  return true;
323  }
324 
325  include_once('Services/Utilities/classes/class.ilConfirmationGUI.php');
326  $c_gui = new ilConfirmationGUI();
327 
328  // set confirm/cancel commands
329  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteEntries"));
330  $c_gui->setHeaderText($this->lng->txt("md_delete_cp_sure"));
331  $c_gui->setCancel($this->lng->txt("cancel"), "showCopyrightSettings");
332  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteEntries");
333 
334  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
335 
336  // add items to delete
337  foreach ($_POST["entry_id"] as $entry_id) {
338  $entry = new ilMDCopyrightSelectionEntry($entry_id);
339  $c_gui->addItem('entry_id[]', $entry_id, $entry->getTitle());
340  }
341  $this->tpl->setContent($c_gui->getHTML());
342  }
343 
350  public function deleteEntries()
351  {
352  if (!is_array($_POST['entry_id']) or !count($_POST['entry_id'])) {
353  ilUtil::sendInfo($this->lng->txt('select_one'));
354  $this->showCopyrightSettings();
355  return true;
356  }
357 
358  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
359  foreach ($_POST["entry_id"] as $entry_id) {
360  $entry = new ilMDCopyrightSelectionEntry($entry_id);
361  $entry->delete();
362  }
363  ilUtil::sendSuccess($this->lng->txt('md_copyrights_deleted'));
364  $this->showCopyrightSettings();
365  return true;
366  }
367 
374  public function updateEntry()
375  {
376  global $ilErr;
377 
378  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
379  $this->entry = new ilMDCopyrightSelectionEntry((int) $_REQUEST['entry_id']);
380 
381  $this->entry->setTitle(ilUtil::stripSlashes($_POST['title']));
382  $this->entry->setDescription(ilUtil::stripSlashes($_POST['description']));
383  $this->entry->setCopyright($this->stripSlashes($_POST['copyright']));
384 
385  if (!$this->entry->validate()) {
386  ilUtil::sendInfo($this->lng->txt('fill_out_all_required_fields'));
387  $this->editEntry();
388  return false;
389  }
390  $this->entry->update();
391  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
392  $this->showCopyrightSettings();
393  return true;
394  }
395 
396 
402  protected function initSettingsForm()
403  {
404  global $ilAccess;
405 
406  if (is_object($this->form)) {
407  return true;
408  }
409  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
410  $this->form = new ilPropertyFormGUI();
411  $this->form->setFormAction($this->ctrl->getFormAction($this));
412  $this->form->setTitle($this->lng->txt('md_copyright_settings'));
413 
414  if ($ilAccess->checkAccess('write', '', $this->object->getRefId())) {
415  $this->form->addCommandButton('saveCopyrightSettings', $this->lng->txt('save'));
416  $this->form->addCommandButton('showCopyrightSettings', $this->lng->txt('cancel'));
417  }
418 
419  $check = new ilCheckboxInputGUI($this->lng->txt('md_copyright_enabled'), 'active');
420  $check->setChecked($this->md_settings->isCopyrightSelectionActive());
421  $check->setValue(1);
422  $check->setInfo($this->lng->txt('md_copyright_enable_info'));
423  $this->form->addItem($check);
424  }
425 
433  public function initCopyrightEditForm($a_mode = 'edit')
434  {
435  if (is_object($this->form)) {
436  return true;
437  }
438  if (!is_object($this->entry)) {
439  include_once('Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php');
440  $this->entry = new ilMDCopyrightSelectionEntry((int) $_REQUEST['entry_id']);
441  }
442 
443  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
444  $this->form = new ilPropertyFormGUI();
445  $this->form->setFormAction($this->ctrl->getFormAction($this));
446 
447  $tit = new ilTextInputGUI($this->lng->txt('title'), 'title');
448  $tit->setValue($this->entry->getTitle());
449  $tit->setRequired(true);
450  $tit->setSize(40);
451  $tit->setMaxLength(255);
452  $this->form->addItem($tit);
453 
454  $des = new ilTextAreaInputGUI($this->lng->txt('description'), 'description');
455  $des->setValue($this->entry->getDescription());
456  $des->setRows(3);
457  $this->form->addItem($des);
458 
459  $cop = new ilTextAreaInputGUI($this->lng->txt('md_copyright_value'), 'copyright');
460  $cop->setValue($this->entry->getCopyright());
461  $cop->setRows(5);
462  $this->form->addItem($cop);
463 
464  switch ($a_mode) {
465  case 'edit':
466  $this->form->setTitle($this->lng->txt('md_copyright_edit'));
467  $this->form->addCommandButton('updateEntry', $this->lng->txt('save'));
468  $this->form->addCommandButton('showCopyrightSettings', $this->lng->txt('cancel'));
469  break;
470 
471  case 'add':
472  $this->form->setTitle($this->lng->txt('md_copyright_add'));
473  $this->form->addCommandButton('saveEntry', $this->lng->txt('save'));
474  $this->form->addCommandButton('showCopyrightSettings', $this->lng->txt('cancel'));
475  break;
476  }
477  }
478 
484  protected function initMDSettings()
485  {
486  include_once('Services/MetaData/classes/class.ilMDSettings.php');
487  $this->md_settings = ilMDSettings::_getInstance();
488  }
489 
495  protected function stripSlashes($a_str)
496  {
497  if (ini_get("magic_quotes_gpc")) {
498  $a_str = stripslashes($a_str);
499  }
500  return $a_str;
501  }
502 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
initMDSettings()
init Md settings
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.
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.