ILIAS  release_7 Revision v7.30-3-g800a261c036
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
5require_once "./Services/Object/classes/class.ilObjectGUI.php";
6require_once('./Services/Repository/classes/class.ilObjectPlugin.php');
7
19{
20 const FORM_MODE_EDIT = 1;
22
28 public $type;
29
41 public function __construct($a_data, $a_id, $a_call_by_reference)
42 {
43 global $DIC;
44
45 $lng = $DIC['lng'];
46
47 $lng->loadLanguageModule('rbac');
48
49 $this->type = "rolt";
50 parent::__construct($a_data, $a_id, $a_call_by_reference, false);
51 $this->rolf_ref_id = &$this->ref_id;
52 $this->ctrl->saveParameter($this, "obj_id");
53 }
54
55 public function executeCommand()
56 {
57 global $DIC;
58
59 $rbacsystem = $DIC['rbacsystem'];
60
61 $this->prepareOutput();
62
63 $next_class = $this->ctrl->getNextClass($this);
64 $cmd = $this->ctrl->getCmd();
65
66 switch ($next_class) {
67 default:
68 if (!$cmd) {
69 $cmd = "perm";
70 }
71 $cmd .= "Object";
72 $this->$cmd();
73
74 break;
75 }
76
77 return true;
78 }
79
85 protected function initFormRoleTemplate($a_mode = self::FORM_MODE_CREATE)
86 {
87 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
88 $form = new ilPropertyFormGUI();
89
90 if ($this->creation_mode) {
91 $this->ctrl->setParameter($this, "new_type", 'rolt');
92 }
93
94 $form->setFormAction($this->ctrl->getFormAction($this));
95
96 if ($a_mode == self::FORM_MODE_CREATE) {
97 $form->setTitle($this->lng->txt('rolt_new'));
98 $form->addCommandButton('save', $this->lng->txt('rolt_new'));
99 } else {
100 $form->setTitle($this->lng->txt('rolt_edit'));
101 $form->addCommandButton('update', $this->lng->txt('save'));
102 }
103 $form->addCommandButton('cancel', $this->lng->txt('cancel'));
104
105 $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
106 if ($a_mode != self::FORM_MODE_CREATE) {
107 if ($this->object->isInternalTemplate()) {
108 $title->setDisabled(true);
109 }
110 $title->setValue(ilObjRole::_getTranslation($this->object->getTitle()));
111 }
112 $title->setSize(40);
113 $title->setMaxLength(70);
114 $title->setRequired(true);
115 $form->addItem($title);
116
117 $desc = new ilTextAreaInputGUI($this->lng->txt('description'), 'desc');
118
119 if ($a_mode != self::FORM_MODE_CREATE) {
120 $desc->setValue($this->object->getDescription());
121 }
122 $desc->setCols(40);
123 $desc->setRows(3);
124 $form->addItem($desc);
125
126 if ($a_mode != self::FORM_MODE_CREATE) {
127 $ilias_id = new ilNonEditableValueGUI($this->lng->txt("ilias_id"), "ilias_id");
128 $ilias_id->setValue('il_' . IL_INST_ID . '_' . ilObject::_lookupType($this->object->getId()) . '_' . $this->object->getId());
129 $form->addItem($ilias_id);
130 }
131
132 $pro = new ilCheckboxInputGUI($this->lng->txt('role_protect_permissions'), 'protected');
133 $pro->setChecked($GLOBALS['DIC']['rbacreview']->isProtected(
134 $this->rolf_ref_id,
135 $this->object->getId()
136 ));
137 $pro->setValue(1);
138 $form->addItem($pro);
139
140 return $form;
141 }
142
143
149 public function createObject(ilPropertyFormGUI $form = null)
150 {
151 global $DIC;
152
153 $rbacsystem = $DIC['rbacsystem'];
154
155 if (!$rbacsystem->checkAccess("create_rolt", $this->rolf_ref_id)) {
156 $this->ilias->raiseError($this->lng->txt("permission_denied"), $this->ilias->error_obj->MESSAGE);
157 }
158 if (!$form) {
159 $form = $this->initFormRoleTemplate(self::FORM_MODE_CREATE);
160 }
161 $this->tpl->setContent($form->getHTML());
162 return true;
163 }
164
168 public function editObject(ilPropertyFormGUI $form = null)
169 {
170 global $DIC;
171
172 $rbacsystem = $DIC['rbacsystem'];
173
174 $this->tabs_gui->activateTab('settings');
175
176 if (!$rbacsystem->checkAccess("write", $this->rolf_ref_id)) {
177 $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"), $this->ilias->error_obj->MESSAGE);
178 }
179
180 if (!$form) {
181 $form = $this->initFormRoleTemplate(self::FORM_MODE_EDIT);
182 }
183 $GLOBALS['DIC']['tpl']->setContent($form->getHTML());
184 }
185
191 public function updateObject()
192 {
193 global $DIC;
194
195 $rbacsystem = $DIC['rbacsystem'];
196 $rbacadmin = $DIC['rbacadmin'];
197 $rbacreview = $DIC['rbacreview'];
198
199 // check write access
200 if (!$rbacsystem->checkAccess("write", $this->rolf_ref_id)) {
201 $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_rolt"), $this->ilias->error_obj->WARNING);
202 }
203
204 $form = $this->initFormRoleTemplate(self::FORM_MODE_EDIT);
205 if ($form->checkInput()) {
206 if (!$this->object->isInternalTemplate()) {
207 $this->object->setTitle($form->getInput('title'));
208 }
209 $this->object->setDescription($form->getInput('desc'));
210 $rbacadmin->setProtected(
211 $this->rolf_ref_id,
212 $this->object->getId(),
213 $form->getInput('protected') ? 'y' : 'n'
214 );
215 $this->object->update();
216 ilUtil::sendSuccess($this->lng->txt("saved_successfully"), true);
217 $this->ctrl->returnToParent($this);
218 }
219
220 $form->setValuesByPost();
221 $this->editObject($form);
222 }
223
224
225
231 public function saveObject()
232 {
233 global $DIC;
234
235 $rbacsystem = $DIC['rbacsystem'];
236 $rbacadmin = $DIC['rbacadmin'];
237 $rbacreview = $DIC['rbacreview'];
238
239 if (!$rbacsystem->checkAccess("create_rolt", $this->rolf_ref_id)) {
240 $this->ilias->raiseError($this->lng->txt("msg_no_perm_create_rolt"), $this->ilias->error_obj->WARNING);
241 }
242 $form = $this->initFormRoleTemplate();
243 if ($form->checkInput()) {
244 include_once("./Services/AccessControl/classes/class.ilObjRoleTemplate.php");
245 $roltObj = new ilObjRoleTemplate();
246 $roltObj->setTitle($form->getInput('title'));
247 $roltObj->setDescription($form->getInput('desc'));
248 $roltObj->create();
249 $rbacadmin->assignRoleToFolder($roltObj->getId(), $this->rolf_ref_id, 'n');
250 $rbacadmin->setProtected(
251 $this->rolf_ref_id,
252 $roltObj->getId(),
253 $form->getInput('protected') ? 'y' : 'n'
254 );
255
256 ilUtil::sendSuccess($this->lng->txt("rolt_added"), true);
257 // redirect to permission screen
258 $this->ctrl->setParameter($this, 'obj_id', $roltObj->getId());
259 $this->ctrl->redirect($this, 'perm');
260 }
261 $form->setValuesByPost();
262 $this->createObject($form);
263 }
264
265
269 protected function permObject()
270 {
271 global $DIC;
272
276 $rbacsystem = $DIC->rbac()->system();
277
281 $ilErr = $DIC['ilErr'];
282
286 $objDefinition = $DIC['objDefinition'];
287
288 if (!$rbacsystem->checkAccess('edit_permission', $this->ref_id)) {
289 $ilErr->raiseError($this->lng->txt('msg_no_perm_perm'), $ilErr->MESSAGE);
290 return true;
291 }
292 $this->tabs_gui->activateTab('perm');
293
294 $this->tpl->addBlockFile(
295 'ADM_CONTENT',
296 'adm_content',
297 'tpl.rbac_template_permissions.html',
298 'Services/AccessControl'
299 );
300
301 $this->tpl->setVariable('PERM_ACTION', $this->ctrl->getFormAction($this));
302
303 include_once './Services/Accordion/classes/class.ilAccordionGUI.php';
304 $acc = new ilAccordionGUI();
305 $acc->setBehaviour(ilAccordionGUI::FORCE_ALL_OPEN);
306 $acc->setId('template_perm_' . $this->ref_id);
307
308 $subs = ilObjRole::getSubObjects('root', false);
309
310 foreach ($subs as $subtype => $def) {
312 $this,
313 'perm',
314 $this->ref_id,
315 $this->obj_id,
316 $subtype,
317 false
318 );
319 $tbl->setShowChangeExistingObjects(false);
320 $tbl->parse();
321
322 $acc->addItem($def['translation'], $tbl->getHTML());
323 }
324
325 $this->tpl->setVariable('ACCORDION', $acc->getHTML());
326
327 // Add options table
328 include_once './Services/AccessControl/classes/class.ilObjectRoleTemplateOptionsTableGUI.php';
330 $this,
331 'perm',
332 $this->ref_id,
333 $this->obj_id,
334 false
335 );
336 $options->setShowOptions(false);
337 $options->addMultiCommand(
338 'permSave',
339 $this->lng->txt('save')
340 );
341
342 $options->parse();
343 $this->tpl->setVariable('OPTIONS_TABLE', $options->getHTML());
344 }
345
346
352 protected function permSaveObject()
353 {
354 global $DIC;
355
359 $rbacsystem = $DIC->rbac()->system();
360
364 $rbacadmin = $DIC->rbac()->admin();
365
369 $ilErr = $DIC['ilErr'];
370
374 $objDefinition = $DIC['objDefinition'];
375
376
377 if (!$rbacsystem->checkAccess('write', $this->rolf_ref_id)) {
378 $ilErr->raiseError($this->lng->txt('msg_no_perm_perm'), $ilErr->MESSAGE);
379 return true;
380 }
381 // delete all existing template entries
382 //$rbacadmin->deleteRolePermission($this->object->getId(), $this->ref_id);
383 $subs = ilObjRole::getSubObjects('root', false);
384
385 foreach ($subs as $subtype => $def) {
386 // Delete per object type
387 $rbacadmin->deleteRolePermission($this->object->getId(), $this->ref_id, $subtype);
388 }
389
390 foreach ($_POST["template_perm"] as $key => $ops_array) {
391 $rbacadmin->setRolePermission($this->object->getId(), $key, $ops_array, $this->rolf_ref_id);
392 }
393
394 // update object data entry (to update last modification date)
395 $this->object->update();
396
397 ilUtil::sendSuccess($this->lng->txt("saved_successfully"), true);
398 $this->ctrl->redirect($this, "perm");
399 }
400
406 public function adoptPermSaveObject()
407 {
408 global $DIC;
409
410 $rbacadmin = $DIC['rbacadmin'];
411 $rbacsystem = $DIC['rbacsystem'];
412 $rbacreview = $DIC['rbacreview'];
413
414 if (!$rbacsystem->checkAccess('write', $this->rolf_ref_id)) {
415 $this->ilias->raiseError($this->lng->txt("msg_no_perm_perm"), $this->ilias->error_obj->WARNING);
416 } elseif ($this->obj_id == $_POST["adopt"]) {
417 ilUtil::sendFailure($this->lng->txt("msg_perm_adopted_from_itself"), true);
418 } else {
419 $rbacadmin->deleteRolePermission($this->obj_id, $this->rolf_ref_id);
420 $parentRoles = $rbacreview->getParentRoleIds($this->rolf_ref_id, true);
421 $rbacadmin->copyRoleTemplatePermissions(
422 $_POST["adopt"],
423 $parentRoles[$_POST["adopt"]]["parent"],
424 $this->rolf_ref_id,
425 $this->obj_id
426 );
427 // update object data entry (to update last modification date)
428 $this->object->update();
429
430 // send info
431 $obj_data = &$this->ilias->obj_factory->getInstanceByObjId($_POST["adopt"]);
432 ilUtil::sendSuccess($this->lng->txt("msg_perm_adopted_from1") . " '" . $obj_data->getTitle() . "'.<br/>" . $this->lng->txt("msg_perm_adopted_from2"), true);
433 }
434
435 $this->ctrl->redirect($this, "perm");
436 }
437
441 public function getAdminTabs()
442 {
443 $this->getTabs();
444 }
445
449 protected function getTabs()
450 {
451 global $DIC;
452
453 $rbacsystem = $DIC->rbac()->system();
454 $this->tabs_gui->setBackTarget($this->lng->txt('btn_back'), $this->ctrl->getParentReturn($this));
455
456 if ($rbacsystem->checkAccess('write', $this->ref_id)) {
457 $this->tabs_gui->addTab(
458 'settings',
459 $this->lng->txt('settings'),
460 $this->ctrl->getLinkTarget($this, 'edit')
461 );
462 }
463 if ($rbacsystem->checkAccess('edit_permission', $this->ref_id)) {
464 $this->tabs_gui->addTab(
465 'perm',
466 $this->lng->txt('default_perm_settings'),
467 $this->ctrl->getLinkTarget($this, 'perm')
468 );
469 }
470 }
471
476 public function cancelObject()
477 {
478 $this->ctrl->redirectByClass("ilobjrolefoldergui", "view");
479 }
480
481
482
486 protected function addAdminLocatorItems($a_do_not_add_object = false)
487 {
488 global $DIC;
489 $ilLocator = $DIC['ilLocator'];
490
491 parent::addAdminLocatorItems(true);
492
493 $ilLocator->addItem(
494 $this->lng->txt("obj_" . ilObject::_lookupType(
496 )),
497 $this->ctrl->getLinkTargetByClass("ilobjrolefoldergui", "view")
498 );
499
500 if ($_GET["obj_id"] > 0) {
501 $ilLocator->addItem(
502 ilObjRole::_getTranslation($this->object->getTitle()),
503 $this->ctrl->getLinkTarget($this, 'perm')
504 );
505 }
506 }
507} // END class.ilObjRoleTemplateGUI
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Accordion user interface class.
This class represents a checkbox property in a property form.
This class represents a non editable value in a property form.
Class ilObjRoleTemplateGUI.
createObject(ilPropertyFormGUI $form=null)
create new role definition template
adoptPermSaveObject()
adopting permission setting from other roles/role templates
cancelObject()
cancelObject is called when an operation is canceled, method links back @access public
getAdminTabs()
admin and normal tabs are equal for roles
__construct($a_data, $a_id, $a_call_by_reference)
Constructor.
addAdminLocatorItems($a_do_not_add_object=false)
should be overwritten to add object specific items (repository items are preloaded)
saveObject()
save a new role template object
updateObject()
update role template object
editObject(ilPropertyFormGUI $form=null)
Create new object.
getTabs()
get tabs abstract method.@abstract overwrite in derived GUI class of your object type @access public
initFormRoleTemplate($a_mode=self::FORM_MODE_CREATE)
Init create form.
Class ilObjRoleTemplate.
static _getTranslation($a_role_title)
Class ilObjectGUI Basic methods of all Output classes.
prepareOutput($a_show_subobjects=true)
prepare output
editObject()
edit object
createObject()
create new object form
static _lookupObjId($a_id)
static _lookupType($a_id, $a_reference=false)
lookup object type
This class represents a property form user interface.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
const IL_INST_ID
Definition: constants.php:38
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
redirection script todo: (a better solution should control the processing via a xml file)