ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 require_once('./Services/Repository/classes/class.ilObjectPlugin.php');
7 
19 {
20  const FORM_MODE_EDIT = 1;
21  const FORM_MODE_CREATE = 2;
22 
28  public $type;
29 
35  public $rolf_ref_id;
41  public function __construct($a_data, $a_id, $a_call_by_reference)
42  {
43  global $lng;
44 
45  $lng->loadLanguageModule('rbac');
46 
47  $this->type = "rolt";
48  parent::__construct($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  public 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  default:
64  if (!$cmd) {
65  $cmd = "perm";
66  }
67  $cmd .= "Object";
68  $this->$cmd();
69 
70  break;
71  }
72 
73  return true;
74  }
75 
81  protected function initFormRoleTemplate($a_mode = self::FORM_MODE_CREATE)
82  {
83  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
84  $form = new ilPropertyFormGUI();
85 
86  if ($this->creation_mode) {
87  $this->ctrl->setParameter($this, "new_type", 'rolt');
88  }
89 
90  $form->setFormAction($this->ctrl->getFormAction($this));
91 
92  if ($a_mode == self::FORM_MODE_CREATE) {
93  $form->setTitle($this->lng->txt('rolt_new'));
94  $form->addCommandButton('save', $this->lng->txt('rolt_new'));
95  } else {
96  $form->setTitle($this->lng->txt('rolt_edit'));
97  $form->addCommandButton('update', $this->lng->txt('save'));
98  }
99  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
100 
101  $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
102  if ($a_mode != self::FORM_MODE_CREATE) {
103  if ($this->object->isInternalTemplate()) {
104  $title->setDisabled(true);
105  }
106  $title->setValue($this->object->getTitle());
107  }
108  $title->setSize(40);
109  $title->setMaxLength(70);
110  $title->setRequired(true);
111  $form->addItem($title);
112 
113  $desc = new ilTextAreaInputGUI($this->lng->txt('description'), 'desc');
114 
115  if ($a_mode != self::FORM_MODE_CREATE) {
116  $desc->setValue($this->object->getDescription());
117  }
118  $desc->setCols(40);
119  $desc->setRows(3);
120  $form->addItem($desc);
121 
122  if ($a_mode != self::FORM_MODE_CREATE) {
123  $ilias_id = new ilNonEditableValueGUI($this->lng->txt("ilias_id"), "ilias_id");
124  $ilias_id->setValue('il_' . IL_INST_ID . '_' . ilObject::_lookupType($this->object->getId()) . '_' . $this->object->getId());
125  $form->addItem($ilias_id);
126  }
127 
128  $pro = new ilCheckboxInputGUI($this->lng->txt('role_protect_permissions'), 'protected');
129  $pro->setChecked($GLOBALS['rbacreview']->isProtected(
130  $this->rolf_ref_id,
131  $this->object->getId()
132  ));
133  $pro->setValue(1);
134  $form->addItem($pro);
135 
136  return $form;
137  }
138 
139 
145  public function createObject(ilPropertyFormGUI $form = null)
146  {
147  global $rbacsystem;
148 
149  if (!$rbacsystem->checkAccess("create_rolt", $this->rolf_ref_id)) {
150  $this->ilias->raiseError($this->lng->txt("permission_denied"), $this->ilias->error_obj->MESSAGE);
151  }
152  if (!$form) {
153  $form = $this->initFormRoleTemplate(self::FORM_MODE_CREATE);
154  }
155  $this->tpl->setContent($form->getHTML());
156  return true;
157  }
158 
162  public function editObject(ilPropertyFormGUI $form = null)
163  {
164  global $rbacsystem;
165 
166  $this->tabs_gui->activateTab('settings');
167 
168  if (!$rbacsystem->checkAccess("write", $this->rolf_ref_id)) {
169  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"), $this->ilias->error_obj->MESSAGE);
170  }
171 
172  if (!$form) {
173  $form = $this->initFormRoleTemplate(self::FORM_MODE_EDIT);
174  }
175  $GLOBALS['tpl']->setContent($form->getHTML());
176  }
177 
183  public function updateObject()
184  {
185  global $rbacsystem, $rbacadmin, $rbacreview;
186 
187  // check write access
188  if (!$rbacsystem->checkAccess("write", $this->rolf_ref_id)) {
189  $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_rolt"), $this->ilias->error_obj->WARNING);
190  }
191 
192  $form = $this->initFormRoleTemplate(self::FORM_MODE_EDIT);
193  if ($form->checkInput()) {
194  $this->object->setTitle($form->getInput('title'));
195  $this->object->setDescription($form->getInput('desc'));
196  $rbacadmin->setProtected(
197  $this->rolf_ref_id,
198  $this->object->getId(),
199  $form->getInput('protected') ? 'y' : 'n'
200  );
201  $this->object->update();
202  ilUtil::sendSuccess($this->lng->txt("saved_successfully"), true);
203  $this->ctrl->returnToParent($this);
204  }
205 
206  $form->setValuesByPost();
207  $this->editObject($form);
208  }
209 
210 
211 
217  public function saveObject()
218  {
219  global $rbacsystem,$rbacadmin, $rbacreview;
220 
221  if (!$rbacsystem->checkAccess("create_rolt", $this->rolf_ref_id)) {
222  $this->ilias->raiseError($this->lng->txt("msg_no_perm_create_rolt"), $this->ilias->error_obj->WARNING);
223  }
224  $form = $this->initFormRoleTemplate();
225  if ($form->checkInput()) {
226  include_once("./Services/AccessControl/classes/class.ilObjRoleTemplate.php");
227  $roltObj = new ilObjRoleTemplate();
228  $roltObj->setTitle($form->getInput('title'));
229  $roltObj->setDescription($form->getInput('desc'));
230  $roltObj->create();
231  $rbacadmin->assignRoleToFolder($roltObj->getId(), $this->rolf_ref_id, 'n');
232  $rbacadmin->setProtected(
233  $this->rolf_ref_id,
234  $roltObj->getId(),
235  $form->getInput('protected') ? 'y' : 'n'
236  );
237 
238  ilUtil::sendSuccess($this->lng->txt("rolt_added"), true);
239  // redirect to permission screen
240  $this->ctrl->setParameter($this, 'obj_id', $roltObj->getId());
241  $this->ctrl->redirect($this, 'perm');
242  }
243  $form->setValuesByPost();
244  $this->createObject($form);
245  }
246 
247 
251  protected function permObject()
252  {
253  global $DIC;
254 
258  $rbacsystem = $DIC->rbac()->system();
259 
263  $ilErr = $DIC['ilErr'];
264 
268  $objDefinition = $DIC['objDefinition'];
269 
270  if (!$rbacsystem->checkAccess('edit_permission', $this->ref_id)) {
271  $ilErr->raiseError($this->lng->txt('msg_no_perm_perm'), $ilErr->MESSAGE);
272  return true;
273  }
274  $this->tabs_gui->activateTab('perm');
275 
276  $this->tpl->addBlockFile(
277  'ADM_CONTENT',
278  'adm_content',
279  'tpl.rbac_template_permissions.html',
280  'Services/AccessControl'
281  );
282 
283  $this->tpl->setVariable('PERM_ACTION', $this->ctrl->getFormAction($this));
284 
285  include_once './Services/Accordion/classes/class.ilAccordionGUI.php';
286  $acc = new ilAccordionGUI();
287  $acc->setBehaviour(ilAccordionGUI::FORCE_ALL_OPEN);
288  $acc->setId('template_perm_' . $this->ref_id);
289 
290  $subs = $objDefinition->getSubObjectsRecursively('root', 'true', false);
291 
292  $sorted = array();
293  foreach ($subs as $subtype => $def) {
294  if ($objDefinition->isPlugin($subtype)) {
295  $translation = ilObjectPlugin::lookupTxtById($subtype, "obj_" . $subtype);
296  } elseif ($objDefinition->isSystemObject($subtype)) {
297  $translation = $this->lng->txt("obj_" . $subtype);
298  } else {
299  $translation = $this->lng->txt('objs_' . $subtype);
300  }
301 
302  $sorted[$subtype] = $def;
303  $sorted[$subtype]['translation'] = $translation;
304  }
305 
306  $sorted = ilUtil::sortArray($sorted, 'translation', 'asc', true, true);
307  foreach ($sorted as $subtype => $def) {
308  if ($objDefinition->isPlugin($subtype)) {
309  $translation = ilObjectPlugin::lookupTxtById($subtype, "obj_" . $subtype);
310  } elseif ($objDefinition->isSystemObject($subtype)) {
311  $translation = $this->lng->txt("obj_" . $subtype);
312  } else {
313  $translation = $this->lng->txt('objs_' . $subtype);
314  }
315 
317  $this,
318  'perm',
319  $this->ref_id,
320  $this->obj_id,
321  $subtype,
322  false
323  );
324  $tbl->setShowChangeExistingObjects(false);
325  $tbl->parse();
326 
327  $acc->addItem($translation, $tbl->getHTML());
328  }
329 
330  $this->tpl->setVariable('ACCORDION', $acc->getHTML());
331 
332  // Add options table
333  include_once './Services/AccessControl/classes/class.ilObjectRoleTemplateOptionsTableGUI.php';
335  $this,
336  'perm',
337  $this->ref_id,
338  $this->obj_id,
339  false
340  );
341  $options->setShowOptions(false);
342  $options->addMultiCommand(
343  'permSave',
344  $this->lng->txt('save')
345  );
346 
347  $options->parse();
348  $this->tpl->setVariable('OPTIONS_TABLE', $options->getHTML());
349  }
350 
351 
352 
353 
359  protected function permSaveObject()
360  {
361  global $DIC;
362 
366  $rbacsystem = $DIC->rbac()->system();
367 
371  $rbacadmin = $DIC->rbac()->admin();
372 
376  $ilErr = $DIC['ilErr'];
377 
381  $objDefinition = $DIC['objDefinition'];
382 
383 
384 
385  if (!$rbacsystem->checkAccess('write', $this->rolf_ref_id)) {
386  $ilErr->raiseError($this->lng->txt('msg_no_perm_perm'), $ilErr->MESSAGE);
387  return true;
388  }
389  // delete all existing template entries
390  $rbacadmin->deleteRolePermission($this->object->getId(), $this->ref_id);
391 
392  foreach ($_POST["template_perm"] as $key => $ops_array) {
393  $rbacadmin->setRolePermission($this->object->getId(), $key, $ops_array, $this->rolf_ref_id);
394  }
395 
396  // update object data entry (to update last modification date)
397  $this->object->update();
398 
399  ilUtil::sendSuccess($this->lng->txt("saved_successfully"), true);
400  $this->ctrl->redirect($this, "perm");
401  }
402 
408  public function adoptPermSaveObject()
409  {
410  global $rbacadmin, $rbacsystem, $rbacreview;
411 
412  if (!$rbacsystem->checkAccess('write', $this->rolf_ref_id)) {
413  $this->ilias->raiseError($this->lng->txt("msg_no_perm_perm"), $this->ilias->error_obj->WARNING);
414  } elseif ($this->obj_id == $_POST["adopt"]) {
415  ilUtil::sendFailure($this->lng->txt("msg_perm_adopted_from_itself"), true);
416  } else {
417  $rbacadmin->deleteRolePermission($this->obj_id, $this->rolf_ref_id);
418  $parentRoles = $rbacreview->getParentRoleIds($this->rolf_ref_id, true);
419  $rbacadmin->copyRoleTemplatePermissions(
420  $_POST["adopt"],
421  $parentRoles[$_POST["adopt"]]["parent"],
422  $this->rolf_ref_id,
423  $this->obj_id
424  );
425  // update object data entry (to update last modification date)
426  $this->object->update();
427 
428  // send info
429  $obj_data =&$this->ilias->obj_factory->getInstanceByObjId($_POST["adopt"]);
430  ilUtil::sendSuccess($this->lng->txt("msg_perm_adopted_from1") . " '" . $obj_data->getTitle() . "'.<br/>" . $this->lng->txt("msg_perm_adopted_from2"), true);
431  }
432 
433  $this->ctrl->redirect($this, "perm");
434  }
435 
439  public function getAdminTabs()
440  {
441  $this->getTabs();
442  }
443 
447  protected function getTabs()
448  {
449  global $DIC;
450 
451  $rbacsystem = $DIC->rbac()->system();
452 
453  if ($rbacsystem->checkAccess('write', $this->ref_id)) {
454  $this->tabs_gui->addTab(
455  'settings',
456  $this->lng->txt('settings'),
457  $this->ctrl->getLinkTarget($this, 'edit')
458  );
459  }
460  if ($rbacsystem->checkAccess('edit_permission', $this->ref_id)) {
461  $this->tabs_gui->addTab(
462  'perm',
463  $this->lng->txt('default_perm_settings'),
464  $this->ctrl->getLinkTarget($this, 'perm')
465  );
466  }
467  }
468 
473  public function cancelObject()
474  {
475  $this->ctrl->redirectByClass("ilobjrolefoldergui", "view");
476  }
477 
478 
479 
483  protected function addAdminLocatorItems($a_do_not_add_object = false)
484  {
485  global $DIC;
486 
487  $ilLocator = $DIC['ilLocator'];
488 
489  if (
490  $_GET["admin_mode"] == "settings"
491  && $_GET["ref_id"] == ROLE_FOLDER_ID) { // system settings
492  parent::addAdminLocatorItems(true);
493 
494  $ilLocator->addItem(
495  $this->lng->txt("obj_" . ilObject::_lookupType(ilObject::_lookupObjId($_GET["ref_id"]))),
496  $this->ctrl->getLinkTargetByClass("ilobjrolefoldergui", 'view')
497  );
498 
499  if ($_GET["obj_id"] > 0) {
500  $ilLocator->addItem(
501  $this->object->getTitle(),
502  $this->ctrl->getLinkTarget($this, 'perm')
503  );
504  }
505  } else {
506  parent::addAdminLocatorItems($a_do_not_add_object);
507  }
508  }
509 } // END class.ilObjRoleTemplateGUI
updateObject()
update role template object
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
addAdminLocatorItems($a_do_not_add_object=false)
static lookupTxtById($plugin_id, $lang_var)
adoptPermSaveObject()
adopting permission setting from other roles/role templates
This class represents a property form user interface.
Class ilObjRoleTemplate.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
$tbl
Definition: example_048.php:81
__construct($a_data, $a_id, $a_call_by_reference)
Constructor.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
setValue($a_value)
Set Value.
This class represents a checkbox property in a property form.
createObject()
create new object form
saveObject()
save a new role template object
getAdminTabs()
admin and normal tabs are equal for roles
setChecked($a_checked)
Set Checked.
prepareOutput($a_show_subobjects=true)
prepare output
if(isset($_POST['submit'])) $form
cancelObject()
cancelObject is called when an operation is canceled, method links back public
initFormRoleTemplate($a_mode=self::FORM_MODE_CREATE)
Init create form.
Class ilObjectGUI Basic methods of all Output classes.
static _lookupObjId($a_id)
This class represents a text property in a property form.
redirection script todo: (a better solution should control the processing via a xml file) ...
editObject()
edit object
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
This class represents a non editable value in a property form.
Create new PHPExcel object
obj_idprivate
This class represents a text area property in a property form.
$def
Definition: croninfo.php:21
Class ilObjRoleTemplateGUI.
Accordion user interface class.
$key
Definition: croninfo.php:18
$_POST["username"]
createObject(ilPropertyFormGUI $form=null)
create new role definition template
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
editObject(ilPropertyFormGUI $form=null)
Create new object.