ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjRoleFolderGUI.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 
24 require_once "./Services/Object/classes/class.ilObjectGUI.php";
25 
39 {
45  var $type;
46 
51  function ilObjRoleFolderGUI($a_data,$a_id,$a_call_by_reference)
52  {
53  global $lng;
54 
55  $this->type = "rolf";
56  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference, false);
57  $lng->loadLanguageModule('rbac');
58  }
59 
60  function executeCommand()
61  {
62  global $ilTabs;
63 
64  $next_class = $this->ctrl->getNextClass($this);
65  $cmd = $this->ctrl->getCmd();
66  $this->prepareOutput();
67 
68  switch($next_class)
69  {
70 
71  case 'ilpermissiongui':
72  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
73  $perm_gui =& new ilPermissionGUI($this);
74  $ret =& $this->ctrl->forwardCommand($perm_gui);
75  break;
76 
77  default:
78  if(!$cmd)
79  {
80  $cmd = "view";
81  }
82  $cmd .= "Object";
83  $this->$cmd();
84 
85  break;
86  }
87  return true;
88  }
89 
96  public function viewObject()
97  {
98  global $ilErr, $rbacsystem, $ilToolbar,$rbacreview,$ilTabs;
99 
100  $ilTabs->activateTab('view');
101 
102  if(!$rbacsystem->checkAccess('visible,read',$this->object->getRefId()))
103  {
104  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
105  }
106 
107  $this->ctrl->setParameter($this,'new_type','role');
108  $ilToolbar->addButton(
109  $this->lng->txt('rolf_create_role'),
110  $this->ctrl->getLinkTarget($this,'create')
111  );
112 
113  $this->ctrl->setParameter($this,'new_type','rolt');
114  $ilToolbar->addButton(
115  $this->lng->txt('rolf_create_rolt'),
116  $this->ctrl->getLinkTarget($this,'create')
117  );
118  $this->ctrl->clearParameters($this);
119 
120  $ilToolbar->addButton(
121  $this->lng->txt('rbac_import_role'),
122  $this->ctrl->getLinkTargetByClass('ilPermissionGUI','displayImportRoleForm')
123  );
124 
125  include_once './Services/AccessControl/classes/class.ilRoleTableGUI.php';
126  $table = new ilRoleTableGUI($this,'view');
127  $table->init();
128  $table->parse($this->object->getId());
129 
130  $this->tpl->setContent($table->getHTML());
131  }
132 
136  protected function roleSearchObject()
137  {
138  global $rbacsystem, $ilCtrl, $ilTabs;
139 
140  $ilTabs->clearTargets();
141  $ilTabs->setBackTarget(
142  $this->lng->txt('rbac_back_to_overview'),
143  $this->ctrl->getLinkTarget($this,'view')
144  );
145 
146  if(!$rbacsystem->checkAccess('visible,read',$this->object->getRefId()))
147  {
148  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
149  }
150 
151  $ilCtrl->setParameter($this,'copy_source',(int) $_REQUEST['copy_source']);
152  ilUtil::sendInfo($this->lng->txt('rbac_choose_copy_targets'));
153 
154  $form = $this->initRoleSearchForm();
155  $this->tpl->setContent($form->getHTML());
156  }
157 
161  protected function initRoleSearchForm()
162  {
163  global $ilCtrl;
164 
165  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
166  $form = new ilPropertyFormGUI();
167  $form->setTitle($this->lng->txt('rbac_role_title'));
168  $form->setFormAction($ilCtrl->getFormAction($this,'view'));
169 
170  $search = new ilTextInputGUI($this->lng->txt('title'), 'title');
171  $search->setRequired(true);
172  $search->setSize(30);
173  $search->setMaxLength(255);
174  $form->addItem($search);
175 
176  $form->addCommandButton('roleSearchForm', $this->lng->txt('search'));
177  return $form;
178  }
179 
180 
186  protected function roleSearchFormObject()
187  {
188  global $ilCtrl;
189 
190  $_SESSION['rolf_search_query'] = '';
191  $ilCtrl->setParameter($this,'copy_source',(int) $_REQUEST['copy_source']);
192 
193  $form = $this->initRoleSearchForm();
194  if($form->checkInput())
195  {
196  $_SESSION['rolf_search_query'] = $form->getInput('title');
197  return $this->roleSearchListObject();
198  }
199 
200  ilUtil::sendFailure($this->lng->txt('msg_no_search_string'), true);
201  $form->setValuesByPost();
202  $ilCtrl->redirect($this,'roleSearch');
203  }
204 
208  protected function roleSearchListObject()
209  {
210  global $ilTabs, $ilCtrl;
211 
212  $ilTabs->clearTargets();
213  $ilTabs->setBackTarget(
214  $this->lng->txt('rbac_back_to_overview'),
215  $this->ctrl->getLinkTarget($this,'roleSearchList')
216  );
217 
218  $ilCtrl->setParameter($this,'copy_source',(int) $_REQUEST['copy_source']);
219 
220  if(strlen($_SESSION['rolf_search_query']))
221  {
222  ilUtil::sendInfo($this->lng->txt('rbac_select_copy_targets'));
223 
224  include_once './Services/AccessControl/classes/class.ilRoleTableGUI.php';
225  $table = new ilRoleTableGUI($this,'roleSearchList');
226  $table->setType(ilRoleTableGUI::TYPE_SEARCH);
227  $table->setRoleTitleFilter($_SESSION['rolf_search_query']);
228  $table->init();
229  $table->parse($this->object->getId());
230  return $this->tpl->setContent($table->getHTML());
231  }
232 
233  ilUtil::sendFailure($this->lng->txt('msg_no_search_string'), true);
234  $ilCtrl->redirect($this,'roleSearch');
235  }
236 
241  protected function chooseCopyBehaviourObject()
242  {
243  global $ilCtrl, $ilTabs;
244 
245  $ilTabs->clearTargets();
246  $ilTabs->setBackTarget(
247  $this->lng->txt('rbac_back_to_overview'),
248  $this->ctrl->getLinkTarget($this,'roleSearchList')
249  );
250 
251  $GLOBALS['ilLog']->write(__METHOD__.': '.$_REQUEST['copy_source']);
252 
253  $ilCtrl->setParameter($this,'copy_source',(int) $_REQUEST['copy_source']);
254 
255  $form = $this->initCopyBehaviourForm();
256  $this->tpl->setContent($form->getHTML());
257  }
258 
262  protected function initCopyBehaviourForm()
263  {
264  global $ilCtrl;
265 
266  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
267  $form = new ilPropertyFormGUI();
268  $form->setTitle($this->lng->txt('rbac_copy_behaviour'));
269  $form->setFormAction($ilCtrl->getFormAction($this,'chooseCopyBehaviour'));
270 
271  $ce = new ilRadioGroupInputGUI($this->lng->txt('change_existing_objects'), 'change_existing');
272  $ce->setRequired(true);
273  $ce->setValue(1);
274  $form->addItem($ce);
275 
276  $ceo = new ilRadioOption($this->lng->txt('change_existing_objects'),1);
277  $ce->addOption($ceo);
278 
279  $cne = new ilRadioOption($this->lng->txt('rbac_not_change_existing_objects'), 0);
280  $ce->addOption($cne);
281 
282  $roles = new ilHiddenInputGUI('roles');
283  $roles->setValue(implode(',',(array) $_POST['roles']));
284  $form->addItem($roles);
285 
286 
287  // if source is role template show option add permission, remove permissions and copy permissions
288  if(ilObject::_lookupType((int) $_REQUEST['copy_source']) == 'rolt')
289  {
290  $form->addCommandButton('addRolePermissions', $this->lng->txt('rbac_copy_role_add_perm'));
291  $form->addCommandButton('removeRolePermissions', $this->lng->txt('rbac_copy_role_remove_perm'));
292  $form->addCommandButton('copyRole', $this->lng->txt('rbac_copy_role_copy'));
293  }
294  else
295  {
296  $form->addCommandButton('copyRole', $this->lng->txt('rbac_copy_role'));
297  }
298  return $form;
299  }
300 
301 
305  protected function copyRoleObject()
306  {
307  global $ilCtrl;
308 
309  // Finally copy role/rolt
310  $roles = explode(',',$_POST['roles']);
311  $source = (int) $_REQUEST['copy_source'];
312 
313  $form = $this->initCopyBehaviourForm();
314  if($form->checkInput())
315  {
316  foreach((array) $roles as $role_id)
317  {
318  if($role_id != $source)
319  {
320  $this->doCopyRole($source,$role_id,$form->getInput('change_existing'));
321  }
322  }
323 
324  ilUtil::sendSuccess($this->lng->txt('rbac_copy_finished'),true);
325  $ilCtrl->redirect($this,'view');
326  }
327  }
328 
332  protected function addRolePermissionsObject()
333  {
334  global $ilCtrl;
335 
336  // Finally copy role/rolt
337  $roles = explode(',',$_POST['roles']);
338  $source = (int) $_REQUEST['copy_source'];
339 
340  $form = $this->initCopyBehaviourForm();
341  if($form->checkInput())
342  {
343  foreach((array) $roles as $role_id)
344  {
345  if($role_id != $source)
346  {
347  $this->doAddRolePermissions($source,$role_id,$form->getInput('change_existing'));
348  }
349  }
350 
351  ilUtil::sendSuccess($this->lng->txt('rbac_copy_finished'),true);
352  $ilCtrl->redirect($this,'view');
353  }
354  }
355 
359  protected function doAddRolePermissions($source, $target, $change_existing)
360  {
361  global $rbacadmin, $rbacreview;
362 
363  $rbacadmin->copyRolePermissionUnion(
364  $source,
365  $this->object->getRefId(),
366  $target,
367  $rbacreview->getRoleFolderOfRole($target),
368  $target,
369  $rbacreview->getRoleFolderOfRole($target)
370  );
371  }
372 
376  protected function removeRolePermissionsObject()
377  {
378  global $ilCtrl;
379 
380  // Finally copy role/rolt
381  $roles = explode(',',$_POST['roles']);
382  $source = (int) $_REQUEST['copy_source'];
383 
384  $form = $this->initCopyBehaviourForm();
385  if($form->checkInput())
386  {
387  foreach((array) $roles as $role_id)
388  {
389  if($role_id != $source)
390  {
391  $this->doRemoveRolePermissions($source,$role_id,$form->getInput('change_existing'));
392  }
393  }
394 
395  ilUtil::sendSuccess($this->lng->txt('rbac_copy_finished'),true);
396  $ilCtrl->redirect($this,'view');
397  }
398  }
399 
403  protected function doRemoveRolePermissions($source, $target, $change_existing)
404  {
405  global $rbacadmin, $rbacreview;
406 
407  $rbacadmin->copyRolePermissionSubtract(
408  $source,
409  $this->object->getRefId(),
410  $target,
411  $rbacreview->getRoleFolderOfRole($target)
412  );
413  }
414 
415 
416 
427  protected function doCopyRole($source, $target, $change_existing)
428  {
429  global $tree, $rbacadmin, $rbacreview;
430 
431  $target_rolf = $rbacreview->getRoleFolderOfRole($target);
432 
433  // Copy role template permissions
434  $rbacadmin->copyRoleTemplatePermissions(
435  $source,
436  $this->object->getRefId(),
437  $target_rolf,
438  $target
439  );
440 
441  if(!$change_existing || !$target_rolf)
442  {
443  return true;
444  }
445 
446  $start = $tree->getParentId($target_rolf);
447 
448  include_once './Services/AccessControl/classes/class.ilObjRole.php';
449  if($rbacreview->isProtected($this->object->getRefId(),$source))
450  {
452  }
453  else
454  {
456  }
457 
458  if($start)
459  {
460  $role = new ilObjRole($target);
461  $role->changeExistingObjects(
462  $start,
463  $mode,
464  array('all')
465  );
466  }
467  }
468 
472  protected function applyFilterObject()
473  {
474  include_once './Services/AccessControl/classes/class.ilRoleTableGUI.php';
475  $table = new ilRoleTableGUI($this,'view');
476  $table->init();
477  $table->resetOffset();
478  $table->writeFilterToSession();
479 
480  $this->viewObject();
481  }
482 
486  function resetFilterObject()
487  {
488  include_once './Services/AccessControl/classes/class.ilRoleTableGUI.php';
489  $table = new ilRoleTableGUI($this,'view');
490  $table->init();
491  $table->resetOffset();
492  $table->resetFilter();
493 
494  $this->viewObject();
495  }
496 
500  protected function confirmDeleteObject()
501  {
502  global $ilCtrl;
503 
504  if(!count($_POST['roles']))
505  {
506  ilUtil::sendFailure($this->lng->txt('select_one'),true);
507  $ilCtrl->redirect($this,'view');
508  }
509 
510  $question = $this->lng->txt('rbac_role_delete_qst');
511 
512  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
513  $confirm = new ilConfirmationGUI();
514  $confirm->setHeaderText($question);
515  $confirm->setFormAction($ilCtrl->getFormAction($this));
516  $confirm->setHeaderText($this->lng->txt("info_delete_sure"));
517  $confirm->setConfirm($this->lng->txt('delete'), 'deleteRole');
518  $confirm->setCancel($this->lng->txt('cancel'), 'cancel');
519 
520 
521  include_once './Services/AccessControl/classes/class.ilObjRole.php';
522  foreach($_POST['roles'] as $role_id)
523  {
524  $confirm->addItem(
525  'roles[]',
526  $role_id,
528  );
529  }
530  $this->tpl->setContent($confirm->getHTML());
531  }
532 
536  protected function deleteRoleObject()
537  {
538  global $rbacsystem,$ilErr,$rbacreview,$ilCtrl;
539 
540  if(!$rbacsystem->checkAccess('delete',$this->object->getRefId()))
541  {
542  $ilErr->raiseError(
543  $this->lng->txt('msg_no_perm_delete'),
544  $ilErr->MESSAGE
545  );
546  }
547 
548  foreach((array) $_POST['roles'] as $id)
549  {
550  // instatiate correct object class (role or rolt)
551  $obj = ilObjectFactory::getInstanceByObjId($id,false);
552 
553  if ($obj->getType() == "role")
554  {
555  $rolf_arr = $rbacreview->getFoldersAssignedToRole($obj->getId(),true);
556  $obj->setParent($rolf_arr[0]);
557  }
558 
559  $obj->delete();
560  }
561 
562  // set correct return location if rolefolder is removed
563  ilUtil::sendSuccess($this->lng->txt("msg_deleted_roles_rolts"),true);
564  $ilCtrl->redirect($this,'view');
565  }
566 
567 
568 
569 
570 
576  function createObject()
577  {
578  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
579 
580  /*
581  $this->object->setTitle($this->lng->txt("obj_".$this->object->getType()."_local"));
582  $this->object->setDescription("obj_".$this->object->getType()."_local_desc");
583 
584  $this->saveObject();
585  */
586  }
587 
593  function deleteObject()
594  {
595  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
596  }
597 
604  {
605  ilUtil::sendSuccess($this->lng->txt("saved_successfully"),true);
606 
607  $this->ctrl->redirect($this, "view");
608  }
609 
616  function showPossibleSubObjects($a_tpl)
617  {
618  global $rbacsystem;
619 
620  $d = $this->objDefinition->getCreatableSubObjects($this->object->getType());
621 
622  if ($this->object->getRefId() != ROLE_FOLDER_ID or !$rbacsystem->checkAccess('create_rolt',ROLE_FOLDER_ID))
623  {
624  unset($d["rolt"]);
625  }
626 
627  if (!$rbacsystem->checkAccess('create_role',$this->object->getRefId()))
628  {
629  unset($d["role"]);
630  }
631 
632  if (count($d) > 0)
633  {
634  foreach ($d as $row)
635  {
636  $count = 0;
637  if ($row["max"] > 0)
638  {
639  //how many elements are present?
640  for ($i=0; $i<count($this->data["ctrl"]); $i++)
641  {
642  if ($this->data["ctrl"][$i]["type"] == $row["name"])
643  {
644  $count++;
645  }
646  }
647  }
648  if ($row["max"] == "" || $count < $row["max"])
649  {
650  $subobj[] = $row["name"];
651  }
652  }
653  }
654 
655  if (is_array($subobj))
656  {
657  //build form
658  $opts = ilUtil::formSelect(12,"new_type",$subobj);
659  $a_tpl->setCurrentBlock("add_object");
660  $a_tpl->setVariable("SELECT_OBJTYPE", $opts);
661  $a_tpl->setVariable("BTN_NAME", "create");
662  $a_tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
663  $a_tpl->parseCurrentBlock();
664  }
665 
666  return $a_tpl;
667  }
668 
673  function saveObject()
674  {
675  global $rbacadmin;
676 
677  // role folders are created automatically
678  $_GET["new_type"] = $this->object->getType();
679  $_POST["Fobject"]["title"] = $this->object->getTitle();
680  $_POST["Fobject"]["desc"] = $this->object->getDescription();
681 
682  // always call parent method first to create an object_data entry & a reference
683  $newObj = parent::saveObject();
684 
685  // put here your object specific stuff
686 
687  // always send a message
688  ilUtil::sendSuccess($this->lng->txt("rolf_added"),true);
689 
690  $this->ctrl->redirect($this, "view");
691  }
692 
699  function getAdminTabs(&$tabs_gui)
700  {
701  global $tree,$lng;
702 
703  if ($this->checkPermissionBool("visible,read"))
704  {
705  $tabs_gui->addTarget(
706  "view",
707  $this->ctrl->getLinkTarget($this, "view"),
708  array("", "view"),
709  get_class($this)
710  );
711 
712  $tabs_gui->addTarget(
713  "settings",
714  $this->ctrl->getLinkTarget($this, "editSettings"),
715  array("editSettings"),
716  get_class($this)
717  );
718  }
719 
720  if($this->checkPermissionBool("edit_permission"))
721  {
722  $tabs_gui->addTarget("perm_settings",
723  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'),
724  "perm"),
725  "",
726  "ilpermissiongui");
727  }
728  }
729 
730  function editSettingsObject(ilPropertyFormGUI $a_form = null)
731  {
732  if(!$a_form)
733  {
734  $a_form = $this->initSettingsForm();
735  }
736 
737  $this->tpl->setContent($a_form->getHTML());
738  }
739 
741  {
742  global $ilErr, $rbacreview, $ilUser;
743 
744  if (!$this->checkPermissionBool("write"))
745  {
746  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
747  }
748 
749  $form = $this->initSettingsForm();
750  if($form->checkInput())
751  {
752  include_once('./Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
753  $privacy = ilPrivacySettings::_getInstance();
754  $privacy->enableRbacLog((int) $_POST['rbac_log']);
755  $privacy->setRbacLogAge((int) $_POST['rbac_log_age']);
756  $privacy->save();
757 
758  if($rbacreview->isAssigned($ilUser->getId(),SYSTEM_ROLE_ID))
759  {
760  include_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
761  $security = ilSecuritySettings::_getInstance();
762  $security->protectedAdminRole((int) $_POST['admin_role']);
763  $security->save();
764  }
765 
766  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
767  $this->ctrl->redirect($this, "editSettings");
768  }
769 
770  $form->setValuesByPost();
771  $this->editSettingsObject($form);
772  }
773 
774  protected function initSettingsForm()
775  {
776  global $rbacreview, $ilUser;
777 
778  $this->lng->loadLanguageModule('ps');
779 
780  include_once('./Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
781  include_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
782  $privacy = ilPrivacySettings::_getInstance();
783  $security = ilSecuritySettings::_getInstance();
784 
785  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
786  $form = new ilPropertyFormGUI();
787  $form->setFormAction($this->ctrl->getFormAction($this, "saveSettings"));
788  $form->setTitle($this->lng->txt('settings'));
789 
790  // protected admin
791  $admin = new ilCheckboxInputGUI($GLOBALS['lng']->txt('adm_adm_role_protect'),'admin_role');
792  $admin->setDisabled(!$rbacreview->isAssigned($ilUser->getId(),SYSTEM_ROLE_ID));
793  $admin->setInfo($this->lng->txt('adm_adm_role_protect_info'));
794  $admin->setChecked((int) $security->isAdminRoleProtected());
795  $admin->setValue(1);
796  $form->addItem($admin);
797 
798  $check = new ilCheckboxInputGui($this->lng->txt('rbac_log'), 'rbac_log');
799  $check->setInfo($this->lng->txt('rbac_log_info'));
800  $check->setChecked($privacy->enabledRbacLog());
801  $form->addItem($check);
802 
803  $age = new ilNumberInputGUI($this->lng->txt('rbac_log_age'),'rbac_log_age');
804  $age->setInfo($this->lng->txt('rbac_log_age_info'));
805  $age->setValue($privacy->getRbacLogAge());
806  $age->setMinValue(1);
807  $age->setMaxValue(24);
808  $age->setSize(2);
809  $age->setMaxLength(2);
810  $check->addSubItem($age);
811 
812  $form->addCommandButton('saveSettings',$this->lng->txt('save'));
813 
814  return $form;
815  }
816 
817  public function addToExternalSettingsForm($a_form_id)
818  {
819  switch($a_form_id)
820  {
822 
823  include_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
824  $security = ilSecuritySettings::_getInstance();
825 
826  $fields = array('adm_adm_role_protect' => array($security->isAdminRoleProtected(), ilAdministrationSettingsFormHandler::VALUE_BOOL));
827 
828  return array(array("editSettings", $fields));
829 
831 
832  include_once('./Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
833  $privacy = ilPrivacySettings::_getInstance();
834 
835  $subitems = null;
836  if((bool)$privacy->enabledRbacLog())
837  {
838  $subitems = array('rbac_log_age' => $privacy->getRbacLogAge());
839  }
840  $fields = array('rbac_log' => array($privacy->enabledRbacLog(), ilAdministrationSettingsFormHandler::VALUE_BOOL, $subitems));
841 
842  return array(array("editSettings", $fields));
843  }
844  }
845 
846 } // END class.ilObjRoleFolderGUI
847 ?>