ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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';
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($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 $this->object->setTitle($form->getInput('title'));
207 $this->object->setDescription($form->getInput('desc'));
208 $rbacadmin->setProtected(
209 $this->rolf_ref_id,
210 $this->object->getId(),
211 $form->getInput('protected') ? 'y' : 'n'
212 );
213 $this->object->update();
214 ilUtil::sendSuccess($this->lng->txt("saved_successfully"), true);
215 $this->ctrl->returnToParent($this);
216 }
217
218 $form->setValuesByPost();
219 $this->editObject($form);
220 }
221
222
223
229 public function saveObject()
230 {
231 global $DIC;
232
233 $rbacsystem = $DIC['rbacsystem'];
234 $rbacadmin = $DIC['rbacadmin'];
235 $rbacreview = $DIC['rbacreview'];
236
237 if (!$rbacsystem->checkAccess("create_rolt", $this->rolf_ref_id)) {
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 include_once("./Services/AccessControl/classes/class.ilObjRoleTemplate.php");
243 $roltObj = new ilObjRoleTemplate();
244 $roltObj->setTitle($form->getInput('title'));
245 $roltObj->setDescription($form->getInput('desc'));
246 $roltObj->create();
247 $rbacadmin->assignRoleToFolder($roltObj->getId(), $this->rolf_ref_id, 'n');
248 $rbacadmin->setProtected(
249 $this->rolf_ref_id,
250 $roltObj->getId(),
251 $form->getInput('protected') ? 'y' : 'n'
252 );
253
254 ilUtil::sendSuccess($this->lng->txt("rolt_added"), true);
255 // redirect to permission screen
256 $this->ctrl->setParameter($this, 'obj_id', $roltObj->getId());
257 $this->ctrl->redirect($this, 'perm');
258 }
259 $form->setValuesByPost();
260 $this->createObject($form);
261 }
262
263
267 protected function permObject()
268 {
269 global $DIC;
270
274 $rbacsystem = $DIC->rbac()->system();
275
279 $ilErr = $DIC['ilErr'];
280
284 $objDefinition = $DIC['objDefinition'];
285
286 if (!$rbacsystem->checkAccess('edit_permission', $this->ref_id)) {
287 $ilErr->raiseError($this->lng->txt('msg_no_perm_perm'), $ilErr->MESSAGE);
288 return true;
289 }
290 $this->tabs_gui->activateTab('perm');
291
292 $this->tpl->addBlockFile(
293 'ADM_CONTENT',
294 'adm_content',
295 'tpl.rbac_template_permissions.html',
296 'Services/AccessControl'
297 );
298
299 $this->tpl->setVariable('PERM_ACTION', $this->ctrl->getFormAction($this));
300
301 include_once './Services/Accordion/classes/class.ilAccordionGUI.php';
302 $acc = new ilAccordionGUI();
303 $acc->setBehaviour(ilAccordionGUI::FORCE_ALL_OPEN);
304 $acc->setId('template_perm_' . $this->ref_id);
305
306 $subs = ilObjRole::getSubObjects('root', false);
307
308 foreach ($subs as $subtype => $def) {
310 $this,
311 'perm',
312 $this->ref_id,
313 $this->obj_id,
314 $subtype,
315 false
316 );
317 $tbl->setShowChangeExistingObjects(false);
318 $tbl->parse();
319
320 $acc->addItem($def['translation'], $tbl->getHTML());
321 }
322
323 $this->tpl->setVariable('ACCORDION', $acc->getHTML());
324
325 // Add options table
326 include_once './Services/AccessControl/classes/class.ilObjectRoleTemplateOptionsTableGUI.php';
328 $this,
329 'perm',
330 $this->ref_id,
331 $this->obj_id,
332 false
333 );
334 $options->setShowOptions(false);
335 $options->addMultiCommand(
336 'permSave',
337 $this->lng->txt('save')
338 );
339
340 $options->parse();
341 $this->tpl->setVariable('OPTIONS_TABLE', $options->getHTML());
342 }
343
344
350 protected function permSaveObject()
351 {
352 global $DIC;
353
357 $rbacsystem = $DIC->rbac()->system();
358
362 $rbacadmin = $DIC->rbac()->admin();
363
367 $ilErr = $DIC['ilErr'];
368
372 $objDefinition = $DIC['objDefinition'];
373
374
375 if (!$rbacsystem->checkAccess('write', $this->rolf_ref_id)) {
376 $ilErr->raiseError($this->lng->txt('msg_no_perm_perm'), $ilErr->MESSAGE);
377 return true;
378 }
379 // delete all existing template entries
380 //$rbacadmin->deleteRolePermission($this->object->getId(), $this->ref_id);
381 $subs = ilObjRole::getSubObjects('root', false);
382
383 foreach ($subs as $subtype => $def) {
384 // Delete per object type
385 $rbacadmin->deleteRolePermission($this->object->getId(), $this->ref_id, $subtype);
386 }
387
388 foreach ($_POST["template_perm"] as $key => $ops_array) {
389 $rbacadmin->setRolePermission($this->object->getId(), $key, $ops_array, $this->rolf_ref_id);
390 }
391
392 // update object data entry (to update last modification date)
393 $this->object->update();
394
395 ilUtil::sendSuccess($this->lng->txt("saved_successfully"), true);
396 $this->ctrl->redirect($this, "perm");
397 }
398
404 public function adoptPermSaveObject()
405 {
406 global $DIC;
407
408 $rbacadmin = $DIC['rbacadmin'];
409 $rbacsystem = $DIC['rbacsystem'];
410 $rbacreview = $DIC['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 $this->tabs_gui->setBackTarget($this->lng->txt('btn_back'), $this->ctrl->getParentReturn($this));
453
454 if ($rbacsystem->checkAccess('write', $this->ref_id)) {
455 $this->tabs_gui->addTab(
456 'settings',
457 $this->lng->txt('settings'),
458 $this->ctrl->getLinkTarget($this, 'edit')
459 );
460 }
461 if ($rbacsystem->checkAccess('edit_permission', $this->ref_id)) {
462 $this->tabs_gui->addTab(
463 'perm',
464 $this->lng->txt('default_perm_settings'),
465 $this->ctrl->getLinkTarget($this, 'perm')
466 );
467 }
468 }
469
474 public function cancelObject()
475 {
476 $this->ctrl->redirectByClass("ilobjrolefoldergui", "view");
477 }
478
479
480
484 protected function addAdminLocatorItems($a_do_not_add_object = false)
485 {
486 global $DIC;
487
488 $ilLocator = $DIC['ilLocator'];
489
490 parent::addAdminLocatorItems(true);
491
492 $ilLocator->addItem(
495 ),
496 $this->ctrl->getLinkTargetByClass("ilobjrolefoldergui", "view")
497 );
498 }
499} // END class.ilObjRoleTemplateGUI
$_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.
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 _lookupTitle($a_id)
lookup object title
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.
$def
Definition: croninfo.php:21
$key
Definition: croninfo.php:18
$tbl
Definition: example_048.php:81
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
redirection script todo: (a better solution should control the processing via a xml file)
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7