ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjRoleTemplateGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once "./Services/Object/classes/class.ilObjectGUI.php";
6 
18 {
19 
20  const FORM_MODE_EDIT = 1;
21  const FORM_MODE_CREATE = 2;
22 
28  var $type;
29 
41  function ilObjRoleTemplateGUI($a_data,$a_id,$a_call_by_reference)
42  {
43  global $lng;
44 
45  $lng->loadLanguageModule('rbac');
46 
47  $this->type = "rolt";
48  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference,false);
49  $this->rolf_ref_id =& $this->ref_id;
50  $this->ctrl->saveParameter($this, "obj_id");
51  }
52 
53  function executeCommand()
54  {
55  global $rbacsystem;
56 
57  $this->prepareOutput();
58 
59  $next_class = $this->ctrl->getNextClass($this);
60  $cmd = $this->ctrl->getCmd();
61 
62  switch($next_class)
63  {
64  default:
65  if(!$cmd)
66  {
67  $cmd = "perm";
68  }
69  $cmd .= "Object";
70  $this->$cmd();
71 
72  break;
73  }
74 
75  return true;
76  }
77 
83  protected function initFormRoleTemplate($a_mode = self::FORM_MODE_CREATE)
84  {
85  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
86  $form = new ilPropertyFormGUI();
87 
88  if($this->creation_mode)
89  {
90  $this->ctrl->setParameter($this, "new_type", 'rolt');
91  }
92 
93  $form->setFormAction($this->ctrl->getFormAction($this));
94 
95  if($a_mode == self::FORM_MODE_CREATE)
96  {
97  $form->setTitle($this->lng->txt('rolt_new'));
98  $form->addCommandButton('save', $this->lng->txt('rolt_new'));
99  }
100  else
101  {
102  $form->setTitle($this->lng->txt('rolt_edit'));
103  $form->addCommandButton('update', $this->lng->txt('save'));
104 
105  }
106  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
107 
108  $title = new ilTextInputGUI($this->lng->txt('title'),'title');
109  if($a_mode != self::FORM_MODE_CREATE)
110  {
111  if($this->object->isInternalTemplate())
112  {
113  $title->setDisabled(true);
114  }
115  $title->setValue($this->object->getTitle());
116  }
117  $title->setSize(40);
118  $title->setMaxLength(70);
119  $title->setRequired(true);
120  $form->addItem($title);
121 
122  $desc = new ilTextAreaInputGUI($this->lng->txt('description'),'desc');
123 
124  if($a_mode != self::FORM_MODE_CREATE)
125  {
126  $desc->setValue($this->object->getDescription());
127  }
128  $desc->setCols(40);
129  $desc->setRows(3);
130  $form->addItem($desc);
131 
132  if($a_mode != self::FORM_MODE_CREATE)
133  {
134  $ilias_id = new ilNonEditableValueGUI($this->lng->txt("ilias_id"), "ilias_id");
135  $ilias_id->setValue('il_'.IL_INST_ID.'_'.ilObject::_lookupType($this->object->getId()).'_'.$this->object->getId());
136  $form->addItem($ilias_id);
137  }
138 
139  $pro = new ilCheckboxInputGUI($this->lng->txt('role_protect_permissions'),'protected');
140  $pro->setChecked($GLOBALS['rbacreview']->isProtected(
141  $this->rolf_ref_id,
142  $this->object->getId()
143  ));
144  $pro->setValue(1);
145  $form->addItem($pro);
146 
147  return $form;
148  }
149 
150 
156  function createObject(ilPropertyFormGUI $form = null)
157  {
158  global $rbacsystem;
159 
160  if (!$rbacsystem->checkAccess("create_rolt", $this->rolf_ref_id))
161  {
162  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
163  }
164  if(!$form)
165  {
166  $form = $this->initFormRoleTemplate(self::FORM_MODE_CREATE);
167  }
168  $this->tpl->setContent($form->getHTML());
169  return true;
170  }
171 
175  public function editObject(ilPropertyFormGUI $form = null)
176  {
177  global $rbacsystem;
178 
179  if (!$rbacsystem->checkAccess("write", $this->rolf_ref_id))
180  {
181  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
182  }
183 
184  if(!$form)
185  {
186  $form = $this->initFormRoleTemplate(self::FORM_MODE_EDIT);
187  }
188  $GLOBALS['tpl']->setContent($form->getHTML());
189  }
190 
196  public function updateObject()
197  {
198  global $rbacsystem, $rbacadmin, $rbacreview;
199 
200  // check write access
201  if (!$rbacsystem->checkAccess("write", $this->rolf_ref_id))
202  {
203  $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_rolt"),$this->ilias->error_obj->WARNING);
204  }
205 
206  $form = $this->initFormRoleTemplate(self::FORM_MODE_EDIT);
207  if($form->checkInput())
208  {
209  $this->object->setTitle($form->getInput('title'));
210  $this->object->setDescription($form->getInput('desc'));
211  $rbacadmin->setProtected(
212  $this->rolf_ref_id,
213  $this->object->getId(),
214  $form->getInput('protected') ? 'y' : 'n'
215  );
216  $this->object->update();
217  ilUtil::sendSuccess($this->lng->txt("saved_successfully"),true);
218  $this->ctrl->returnToParent($this);
219  }
220 
221  $form->setValuesByPost();
222  $this->editObject($form);
223  }
224 
225 
226 
232  public function saveObject()
233  {
234  global $rbacsystem,$rbacadmin, $rbacreview;
235 
236  if (!$rbacsystem->checkAccess("create_rolt",$this->rolf_ref_id))
237  {
238  $this->ilias->raiseError($this->lng->txt("msg_no_perm_create_rolt"),$this->ilias->error_obj->WARNING);
239  }
240  $form = $this->initFormRoleTemplate();
241  if($form->checkInput())
242  {
243  include_once("./Services/AccessControl/classes/class.ilObjRoleTemplate.php");
244  $roltObj = new ilObjRoleTemplate();
245  $roltObj->setTitle($form->getInput('title'));
246  $roltObj->setDescription($form->getInput('desc'));
247  $roltObj->create();
248  $rbacadmin->assignRoleToFolder($roltObj->getId(), $this->rolf_ref_id,'n');
249  $rbacadmin->setProtected(
250  $this->rolf_ref_id,
251  $roltObj->getId(),
252  $form->getInput('protected') ? 'y' : 'n'
253  );
254 
255  ilUtil::sendSuccess($this->lng->txt("rolt_added"),true);
256  // redirect to permission screen
257  $this->ctrl->setParameter($this,'obj_id',$roltObj->getId());
258  $this->ctrl->redirect($this,'perm');
259  }
260  $form->setValuesByPost();
261  $this->createObject($form);
262  }
263 
269  function permObject()
270  {
271  global $rbacadmin, $rbacreview, $rbacsystem,$objDefinition,$ilSetting;
272 
273  if (!$rbacsystem->checkAccess('write',$this->rolf_ref_id))
274  {
275  $this->ilias->raiseError($this->lng->txt("msg_no_perm_perm"),$this->ilias->error_obj->WARNING);
276  exit();
277  }
278 
279  $to_filter = $objDefinition->getSubobjectsToFilter();
280 
281  $tpl_filter = array();
282  $internal_tpl = false;
283 
284  if (($internal_tpl = $this->object->isInternalTemplate()))
285  {
286  $tpl_filter = $this->object->getFilterOfInternalTemplate();
287  }
288  $op_order = array();
289 
290  foreach(ilRbacReview::_getOperationList() as $op)
291  {
292  $op_order[$op["ops_id"]] = $op["order"];
293  }
294 
295  $operation_info = $rbacreview->getOperationAssignment();
296 
297  foreach($operation_info as $info)
298  {
299  if($objDefinition->getDevMode($info['type']))
300  {
301  continue;
302  }
303  // FILTER SUBOJECTS OF adm OBJECT
304  if(in_array($info['type'],$to_filter))
305  {
306  continue;
307  }
308  if ($internal_tpl and $tpl_filter and !in_array($info['type'],$tpl_filter))
309  {
310  continue;
311  }
312  $rbac_objects[$info['typ_id']] = array("obj_id" => $info['typ_id'],
313  "type" => $info['type']);
314 
315  $txt = $objDefinition->isPlugin($info['type'])
316  ? ilPlugin::lookupTxt("rep_robj", $info['type'], $info['type']."_".$info['operation'])
317  : $this->lng->txt($info['type']."_".$info['operation']);
318  if (substr($info['operation'], 0, 7) == "create_" &&
319  $objDefinition->isPlugin(substr($info['operation'], 7)))
320  {
321  $txt = ilPlugin::lookupTxt("rep_robj", substr($info['operation'], 7), $info['type']."_".$info['operation']);
322  }
323  elseif(substr($info['operation'],0,6) == 'create')
324  {
325  $txt = $this->lng->txt('rbac_'.$info['operation']);
326  }
327 
328  $order = $op_order[$info['ops_id']];
329  if(substr($info['operation'],0,6) == 'create')
330  {
331  $order = $objDefinition->getPositionByType($info['type']);
332  }
333 
334  $rbac_operations[$info['typ_id']][$info['ops_id']] = array(
335  "ops_id" => $info['ops_id'],
336  "title" => $info['operation'],
337  "name" => $txt,
338  "order" => $order);
339  }
340 
341  foreach ($rbac_objects as $key => $obj_data)
342  {
343  if ($objDefinition->isPlugin($obj_data["type"]))
344  {
345  $rbac_objects[$key]["name"] = ilPlugin::lookupTxt("rep_robj", $obj_data["type"],
346  "obj_".$obj_data["type"]);
347  }
348  else
349  {
350  $rbac_objects[$key]["name"] = $this->lng->txt("obj_".$obj_data["type"]);
351  }
352 
353  $rbac_objects[$key]["ops"] = $rbac_operations[$key];
354  }
355 
356  sort($rbac_objects);
357 
358  foreach ($rbac_objects as $key => $obj_data)
359  {
360  sort($rbac_objects[$key]["ops"]);
361  }
362 
363  // sort by (translated) name of object type
364  $rbac_objects = ilUtil::sortArray($rbac_objects,"name","asc");
365 
366  // BEGIN CHECK_PERM
367  foreach ($rbac_objects as $key => $obj_data)
368  {
369  $arr_selected = $rbacreview->getOperationsOfRole($this->object->getId(), $obj_data["type"], $this->rolf_ref_id);
370  $arr_checked = array_intersect($arr_selected,array_keys($rbac_operations[$obj_data["obj_id"]]));
371 
372  foreach ($rbac_operations[$obj_data["obj_id"]] as $operation)
373  {
374  $checked = in_array($operation["ops_id"],$arr_checked);
375  $disabled = false;
376 
377  // Es wird eine 2-dim Post Variable �bergeben: perm[rol_id][ops_id]
378  $box = ilUtil::formCheckBox($checked,"template_perm[".$obj_data["type"]."][]",$operation["ops_id"],$disabled);
379  $output["perm"][$obj_data["obj_id"]][$operation["ops_id"]] = $box;
380  }
381  }
382  // END CHECK_PERM
383 
384  $output["col_anz"] = count($rbac_objects);
385  $output["txt_save"] = $this->lng->txt("save");
386  $output["check_protected"] = ilUtil::formCheckBox($rbacreview->isProtected($this->rolf_ref_id,$this->object->getId()),"protected",1);
387  $output["text_protected"] = $this->lng->txt("role_protect_permissions");
388 
389 /************************************/
390 /* adopt permissions form */
391 /************************************/
392 
393  $output["message_middle"] = $this->lng->txt("adopt_perm_from_template");
394 
395  // send message for system role
396  if ($this->object->getId() == SYSTEM_ROLE_ID)
397  {
398  $output["adopt"] = array();
399  ilUtil::sendFailure($this->lng->txt("msg_sysrole_not_editable"));
400  }
401  else
402  {
403  // BEGIN ADOPT_PERMISSIONS
404  $parent_role_ids = $rbacreview->getParentRoleIds($this->rolf_ref_id,true);
405 
406  // sort output for correct color changing
407  ksort($parent_role_ids);
408 
409  foreach ($parent_role_ids as $key => $par)
410  {
411  if ($par["obj_id"] != SYSTEM_ROLE_ID)
412  {
413  $radio = ilUtil::formRadioButton(0,"adopt",$par["obj_id"]);
414  $output["adopt"][$key]["css_row_adopt"] = ilUtil::switchColor($key, "tblrow1", "tblrow2");
415  $output["adopt"][$key]["check_adopt"] = $radio;
416  $output["adopt"][$key]["type"] = ($par["type"] == 'role' ? 'Role' : 'Template');
417  $output["adopt"][$key]["role_name"] = $par["title"];
418  }
419  }
420 
421  $output["formaction_adopt"] = $this->ctrl->getFormAction($this);
422  // END ADOPT_PERMISSIONS
423  }
424 
425  $output["formaction"] =
426  $this->ctrl->getFormAction($this);
427 
428  $this->data = $output;
429 
430 
431 /************************************/
432 /* generate output */
433 /************************************/
434 
435  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.adm_perm_role.html",
436  "Services/AccessControl");
437 
438  foreach ($rbac_objects as $obj_data)
439  {
440  // BEGIN object_operations
441  $this->tpl->setCurrentBlock("object_operations");
442 
443  $obj_data["ops"] = ilUtil::sortArray($obj_data["ops"], 'order','asc',true,true);
444 
445  foreach ($obj_data["ops"] as $operation)
446  {
447  $ops_ids[] = $operation["ops_id"];
448 
449  $css_row = ilUtil::switchColor($key, "tblrow1", "tblrow2");
450  $this->tpl->setVariable("CSS_ROW",$css_row);
451  $this->tpl->setVariable("PERMISSION",$operation["name"]);
452  $this->tpl->setVariable("CHECK_PERMISSION",$this->data["perm"][$obj_data["obj_id"]][$operation["ops_id"]]);
453  $this->tpl->parseCurrentBlock();
454  } // END object_operations
455 
456  // BEGIN object_type
457  $this->tpl->setCurrentBlock("object_type");
458  $this->tpl->setVariable("TXT_OBJ_TYPE",$obj_data["name"]);
459 
460 // TODO: move this if in a function and query all objects that may be disabled or inactive
461  if ($this->objDefinition->getDevMode($obj_data["type"]))
462  {
463  $this->tpl->setVariable("TXT_NOT_IMPL", "(".$this->lng->txt("not_implemented_yet").")");
464  }
465  else if ($obj_data["type"] == "icrs" and !$this->ilias->getSetting("ilinc_active"))
466  {
467  $this->tpl->setVariable("TXT_NOT_IMPL", "(".$this->lng->txt("not_enabled_or_configured").")");
468  }
469 
470  // js checkbox toggles
471  $this->tpl->setVariable("JS_VARNAME","template_perm_".$obj_data["type"]);
472  $this->tpl->setVariable("JS_ONCLICK",ilUtil::array_php2js($ops_ids));
473  $this->tpl->setVariable("TXT_CHECKALL", $this->lng->txt("check_all"));
474  $this->tpl->setVariable("TXT_UNCHECKALL", $this->lng->txt("uncheck_all"));
475 
476 
477  $this->tpl->parseCurrentBlock();
478  // END object_type
479  }
480 
481  /*
482  // BEGIN ADOPT PERMISSIONS
483  foreach ($this->data["adopt"] as $key => $value)
484  {
485  $this->tpl->setCurrentBlock("ADOPT_PERM_ROW");
486  $this->tpl->setVariable("CSS_ROW_ADOPT",$value["css_row_adopt"]);
487  $this->tpl->setVariable("CHECK_ADOPT",$value["check_adopt"]);
488  $this->tpl->setVariable("TYPE",$value["type"]);
489  $this->tpl->setVariable("ROLE_NAME",$value["role_name"]);
490  $this->tpl->parseCurrentBlock();
491  }
492 
493  $this->tpl->setCurrentBlock("ADOPT_PERM_FORM");
494  $this->tpl->setVariable("MESSAGE_MIDDLE",$this->data["message_middle"]);
495  $this->tpl->setVariable("FORMACTION_ADOPT",$this->data["formaction_adopt"]);
496  $this->tpl->setVariable("ADOPT",$this->lng->txt('copy'));
497  $this->tpl->parseCurrentBlock();
498  // END ADOPT PERMISSIONS
499  */
500 
501  $this->tpl->setCurrentBlock("tblfooter_protected");
502  $this->tpl->setVariable("COL_ANZ",3);
503  $this->tpl->setVariable("CHECK_BOTTOM",$this->data["check_protected"]);
504  $this->tpl->setVariable("MESSAGE_TABLE",$this->data["text_protected"]);
505  $this->tpl->parseCurrentBlock();
506 
507  $this->tpl->setVariable("COL_ANZ_PLUS",4);
508  $this->tpl->setVariable("TXT_SAVE",$this->data["txt_save"]);
509  $this->tpl->setCurrentBlock("adm_content");
510  $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath("icon_".$this->object->getType().".svg"));
511  $this->tpl->setVariable("TBL_TITLE_IMG_ALT",$this->lng->txt($this->object->getType()));
512 
513  // compute additional information in title
514  if (substr($this->object->getTitle(),0,3) == "il_")
515  {
516  $desc = $this->lng->txt("predefined_template");//$this->lng->txt("obj_".$parent_node['type'])." (".$parent_node['obj_id'].") : ".$parent_node['title'];
517  }
518 
519  $description = "<br/>&nbsp;<span class=\"small\">".$desc."</span>";
520 
521  // translation for autogenerated roles
522  if (substr($this->object->getTitle(),0,3) == "il_")
523  {
524  include_once('./Services/AccessControl/classes/class.ilObjRole.php');
525 
526  $title = ilObjRole::_getTranslation($this->object->getTitle())." (".$this->object->getTitle().")";
527  }
528  else
529  {
530  $title = $this->object->getTitle();
531  }
532 
533  $this->tpl->setVariable("TBL_TITLE",$title.$description);
534 
535  $this->tpl->setVariable("TXT_PERMISSION",$this->data["txt_permission"]);
536  $this->tpl->setVariable("FORMACTION",$this->data["formaction"]);
537  $this->tpl->parseCurrentBlock();
538  }
539 
540 
546  function permSaveObject()
547  {
548  global $rbacadmin, $rbacsystem, $rbacreview,$objDefinition;
549 
550  if (!$rbacsystem->checkAccess('write',$this->rolf_ref_id))
551  {
552  $this->ilias->raiseError($this->lng->txt("msg_no_perm_perm"),$this->ilias->error_obj->WARNING);
553  }
554  else
555  {
556  // Alle Template Eintraege loeschen
557  $rbacadmin->deleteRolePermission($this->object->getId(), $this->rolf_ref_id);
558 
559  foreach ($_POST["template_perm"] as $key => $ops_array)
560  {
561  // Setzen der neuen template permissions
562  $rbacadmin->setRolePermission($this->object->getId(), $key,$ops_array,$this->rolf_ref_id);
563  }
564  }
565 
566  // update object data entry (to update last modification date)
567  $this->object->update();
568 
569  // set protected flag
570  // not applicable for role templates
571  #$rbacadmin->setProtected($this->rolf_ref_id,$this->object->getId(),ilUtil::tf2yn($_POST['protected']));
572 
573  ilUtil::sendSuccess($this->lng->txt("saved_successfully"),true);
574 
575  $this->ctrl->redirect($this, "perm");
576  }
577 
584  {
585  global $rbacadmin, $rbacsystem, $rbacreview;
586 
587  if (!$rbacsystem->checkAccess('write',$this->rolf_ref_id))
588  {
589  $this->ilias->raiseError($this->lng->txt("msg_no_perm_perm"),$this->ilias->error_obj->WARNING);
590  }
591  elseif ($this->obj_id == $_POST["adopt"])
592  {
593  ilUtil::sendFailure($this->lng->txt("msg_perm_adopted_from_itself"),true);
594  }
595  else
596  {
597  $rbacadmin->deleteRolePermission($this->obj_id, $this->rolf_ref_id);
598  $parentRoles = $rbacreview->getParentRoleIds($this->rolf_ref_id,true);
599  $rbacadmin->copyRoleTemplatePermissions($_POST["adopt"],$parentRoles[$_POST["adopt"]]["parent"],
600  $this->rolf_ref_id,$this->obj_id);
601  // update object data entry (to update last modification date)
602  $this->object->update();
603 
604  // send info
605  $obj_data =& $this->ilias->obj_factory->getInstanceByObjId($_POST["adopt"]);
606  ilUtil::sendSuccess($this->lng->txt("msg_perm_adopted_from1")." '".$obj_data->getTitle()."'.<br/>".$this->lng->txt("msg_perm_adopted_from2"),true);
607  }
608 
609  $this->ctrl->redirect($this, "perm");
610  }
611 
615  function getAdminTabs(&$tabs_gui)
616  {
617  $this->getTabs($tabs_gui);
618  }
619 
620  function getTabs(&$tabs_gui)
621  {
622  global $rbacsystem,$rbacreview;
623 
624  if ($rbacsystem->checkAccess('write',$this->rolf_ref_id))
625  {
626  $tabs_gui->addTarget("settings",
627  $this->ctrl->getLinkTarget($this, "edit"),
628  array("edit","update"), get_class($this));
629 
630  $tabs_gui->addTarget("default_perm_settings",
631  $this->ctrl->getLinkTarget($this, "perm"),
632  array("perm"), get_class($this));
633  }
634  }
635 
636 
641  function cancelObject()
642  {
643  $this->ctrl->redirectByClass("ilobjrolefoldergui","view");
644  }
645 
646 
647 
648 
654  {
655  global $ilLocator;
656 
658 
659  $ilLocator->addItem(ilObject::_lookupTitle(
660  ilObject::_lookupObjId($_GET["ref_id"])),
661  $this->ctrl->getLinkTargetByClass("ilobjrolefoldergui", "view"));
662  }
663 
664 } // END class.ilObjRoleTemplateGUI
665 ?>