ILIAS  release_4-3 Revision
 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  $ilToolbar->addButton(
114  $this->lng->txt('rbac_import_role'),
115  $this->ctrl->getLinkTargetByClass('ilPermissionGUI','displayImportRoleForm')
116  );
117 
118 
119  $this->ctrl->setParameter($this,'new_type','rolt');
120  $ilToolbar->addButton(
121  $this->lng->txt('rolf_create_rolt'),
122  $this->ctrl->getLinkTarget($this,'create')
123  );
124  $this->ctrl->clearParameters($this);
125 
126  include_once './Services/AccessControl/classes/class.ilRoleTableGUI.php';
127  $table = new ilRoleTableGUI($this,'view');
128  $table->init();
129  $table->parse($this->object->getId());
130 
131  $this->tpl->setContent($table->getHTML());
132  }
133 
137  protected function roleSearchObject()
138  {
139  global $rbacsystem, $ilCtrl, $ilTabs;
140 
141  $ilTabs->clearTargets();
142  $ilTabs->setBackTarget(
143  $this->lng->txt('rbac_back_to_overview'),
144  $this->ctrl->getLinkTarget($this,'view')
145  );
146 
147  if(!$rbacsystem->checkAccess('visible,read',$this->object->getRefId()))
148  {
149  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
150  }
151 
152  $ilCtrl->setParameter($this,'copy_source',(int) $_REQUEST['copy_source']);
153  ilUtil::sendInfo($this->lng->txt('rbac_choose_copy_targets'));
154 
155  $form = $this->initRoleSearchForm();
156  $this->tpl->setContent($form->getHTML());
157  }
158 
162  protected function initRoleSearchForm()
163  {
164  global $ilCtrl;
165 
166  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
167  $form = new ilPropertyFormGUI();
168  $form->setTitle($this->lng->txt('rbac_role_title'));
169  $form->setFormAction($ilCtrl->getFormAction($this,'view'));
170 
171  $search = new ilTextInputGUI($this->lng->txt('title'), 'title');
172  $search->setRequired(true);
173  $search->setSize(30);
174  $search->setMaxLength(255);
175  $form->addItem($search);
176 
177  $form->addCommandButton('roleSearchList', $this->lng->txt('search'));
178  return $form;
179  }
180 
184  protected function roleSearchListObject()
185  {
186  global $ilTabs, $ilCtrl;
187 
188  $ilTabs->clearTargets();
189  $ilTabs->setBackTarget(
190  $this->lng->txt('rbac_back_to_overview'),
191  $this->ctrl->getLinkTarget($this,'roleSearchList')
192  );
193 
194  $ilCtrl->setParameter($this,'copy_source',(int) $_REQUEST['copy_source']);
195 
196  $form = $this->initRoleSearchForm();
197  if($form->checkInput())
198  {
199  ilUtil::sendInfo($this->lng->txt('rbac_select_copy_targets'));
200 
201  include_once './Services/AccessControl/classes/class.ilRoleTableGUI.php';
202  $table = new ilRoleTableGUI($this,'roleSearchList');
203  $table->setType(ilRoleTableGUI::TYPE_SEARCH);
204  $table->setRoleTitleFilter($form->getInput('title'));
205  $table->init();
206  $table->parse($this->object->getId());
207  return $this->tpl->setContent($table->getHTML());
208  }
209 
210  ilUtil::sendFailure($this->lng->txt('msg_no_search_string'), true);
211  $form->setValuesByPost();
212  $ilCtrl->redirect($this,'roleSearch');
213  }
214 
219  protected function chooseCopyBehaviourObject()
220  {
221  global $ilCtrl, $ilTabs;
222 
223  $ilTabs->clearTargets();
224  $ilTabs->setBackTarget(
225  $this->lng->txt('rbac_back_to_overview'),
226  $this->ctrl->getLinkTarget($this,'roleSearchList')
227  );
228 
229  $ilCtrl->setParameter($this,'copy_source',(int) $_REQUEST['copy_source']);
230 
231  $form = $this->initCopyBehaviourForm();
232  $this->tpl->setContent($form->getHTML());
233  }
234 
238  protected function initCopyBehaviourForm()
239  {
240  global $ilCtrl;
241 
242  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
243  $form = new ilPropertyFormGUI();
244  $form->setTitle($this->lng->txt('rbac_copy_behaviour'));
245  $form->setFormAction($ilCtrl->getFormAction($this,'chooseCopyBehaviour'));
246 
247  $ce = new ilRadioGroupInputGUI($this->lng->txt('change_existing_objects'), 'change_existing');
248  $ce->setRequired(true);
249  $ce->setValue(1);
250  $form->addItem($ce);
251 
252  $ceo = new ilRadioOption($this->lng->txt('change_existing_objects'),1);
253  $ce->addOption($ceo);
254 
255  $cne = new ilRadioOption($this->lng->txt('rbac_not_change_existing_objects'), 0);
256  $ce->addOption($cne);
257 
258  $roles = new ilHiddenInputGUI('roles');
259  $roles->setValue(implode(',',(array) $_POST['roles']));
260  $form->addItem($roles);
261 
262  $form->addCommandButton('copyRole', $this->lng->txt('rbac_copy_role'));
263  return $form;
264  }
265 
269  protected function copyRoleObject()
270  {
271  global $ilCtrl;
272 
273  // Finally copy role/rolt
274  $roles = explode(',',$_POST['roles']);
275  $source = (int) $_REQUEST['copy_source'];
276 
277  $form = $this->initCopyBehaviourForm();
278  if($form->checkInput())
279  {
280  foreach((array) $roles as $role_id)
281  {
282  if($role_id != $source)
283  {
284  $this->doCopyRole($source,$role_id,$form->getInput('change_existing'));
285  }
286  }
287 
288  ilUtil::sendSuccess($this->lng->txt('rbac_copy_finished'),true);
289  $ilCtrl->redirect($this,'view');
290  }
291  }
292 
303  protected function doCopyRole($source, $target, $change_existing)
304  {
305  global $tree, $rbacadmin, $rbacreview;
306 
307  $srolf = $rbacreview->getRoleFolderOfRole($source);
308  $trolf = $rbacreview->getRoleFolderOfRole($target);
309 
310  // Copy role template permissions
311  $rbacadmin->copyRoleTemplatePermissions(
312  $source,
313  $srolf,
314  $trolf,
315  $target
316  );
317 
318  if(!$change_existing)
319  {
320  return true;
321  }
322 
323  $start = (($trolf == ROLE_FOLDER_ID) ?
324  ROOT_FOLDER_ID :
325  $tree->getParentId($trolf));
326 
327  include_once './Services/AccessControl/classes/class.ilObjRole.php';
328  if($rbacreview->isProtected($this->object->getRefId(),$source))
329  {
331  }
332  else
333  {
335  }
336 
337  if($start)
338  {
339  $role = new ilObjRole($target);
340  $role->changeExistingObjects(
341  $start,
342  $mode,
343  array('all')
344  );
345  }
346  }
347 
351  protected function applyFilterObject()
352  {
353  include_once './Services/AccessControl/classes/class.ilRoleTableGUI.php';
354  $table = new ilRoleTableGUI($this,'view');
355  $table->init();
356  $table->resetOffset();
357  $table->writeFilterToSession();
358 
359  $this->viewObject();
360  }
361 
365  function resetFilterObject()
366  {
367  include_once './Services/AccessControl/classes/class.ilRoleTableGUI.php';
368  $table = new ilRoleTableGUI($this,'view');
369  $table->init();
370  $table->resetOffset();
371  $table->resetFilter();
372 
373  $this->viewObject();
374  }
375 
379  protected function confirmDeleteObject()
380  {
381  global $ilCtrl;
382 
383  if(!count($_POST['roles']))
384  {
385  ilUtil::sendFailure($this->lng->txt('select_one'),true);
386  $ilCtrl->redirect($this,'view');
387  }
388 
389  $question = $this->lng->txt('rbac_role_delete_qst');
390 
391  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
392  $confirm = new ilConfirmationGUI();
393  $confirm->setHeaderText($question);
394  $confirm->setFormAction($ilCtrl->getFormAction($this));
395  $confirm->setHeaderText($this->lng->txt("info_delete_sure"));
396  $confirm->setConfirm($this->lng->txt('delete'), 'deleteRole');
397  $confirm->setCancel($this->lng->txt('cancel'), 'cancel');
398 
399 
400  include_once './Services/AccessControl/classes/class.ilObjRole.php';
401  foreach($_POST['roles'] as $role_id)
402  {
403  $confirm->addItem(
404  'roles[]',
405  $role_id,
407  );
408  }
409  $this->tpl->setContent($confirm->getHTML());
410  }
411 
415  protected function deleteRoleObject()
416  {
417  global $rbacsystem,$ilErr,$rbacreview,$ilCtrl;
418 
419  if(!$rbacsystem->checkAccess('delete',$this->object->getRefId()))
420  {
421  $ilErr->raiseError(
422  $this->lng->txt('msg_no_perm_delete'),
423  $ilErr->MESSAGE
424  );
425  }
426 
427  foreach((array) $_POST['roles'] as $id)
428  {
429  // instatiate correct object class (role or rolt)
430  $obj = ilObjectFactory::getInstanceByObjId($id,false);
431 
432  if ($obj->getType() == "role")
433  {
434  $rolf_arr = $rbacreview->getFoldersAssignedToRole($obj->getId(),true);
435  $obj->setParent($rolf_arr[0]);
436  }
437 
438  $obj->delete();
439  }
440 
441  // set correct return location if rolefolder is removed
442  ilUtil::sendSuccess($this->lng->txt("msg_deleted_roles_rolts"),true);
443  $ilCtrl->redirect($this,'view');
444  }
445 
446 
447 
448 
449 
455  function createObject()
456  {
457  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
458 
459  /*
460  $this->object->setTitle($this->lng->txt("obj_".$this->object->getType()."_local"));
461  $this->object->setDescription("obj_".$this->object->getType()."_local_desc");
462 
463  $this->saveObject();
464  */
465  }
466 
472  function deleteObject()
473  {
474  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
475  }
476 
483  {
484  ilUtil::sendSuccess($this->lng->txt("saved_successfully"),true);
485 
486  $this->ctrl->redirect($this, "view");
487  }
488 
495  function showPossibleSubObjects($a_tpl)
496  {
497  global $rbacsystem;
498 
499  $d = $this->objDefinition->getCreatableSubObjects($this->object->getType());
500 
501  if ($this->object->getRefId() != ROLE_FOLDER_ID or !$rbacsystem->checkAccess('create_rolt',ROLE_FOLDER_ID))
502  {
503  unset($d["rolt"]);
504  }
505 
506  if (!$rbacsystem->checkAccess('create_role',$this->object->getRefId()))
507  {
508  unset($d["role"]);
509  }
510 
511  if (count($d) > 0)
512  {
513  foreach ($d as $row)
514  {
515  $count = 0;
516  if ($row["max"] > 0)
517  {
518  //how many elements are present?
519  for ($i=0; $i<count($this->data["ctrl"]); $i++)
520  {
521  if ($this->data["ctrl"][$i]["type"] == $row["name"])
522  {
523  $count++;
524  }
525  }
526  }
527  if ($row["max"] == "" || $count < $row["max"])
528  {
529  $subobj[] = $row["name"];
530  }
531  }
532  }
533 
534  if (is_array($subobj))
535  {
536  //build form
537  $opts = ilUtil::formSelect(12,"new_type",$subobj);
538  $a_tpl->setCurrentBlock("add_object");
539  $a_tpl->setVariable("SELECT_OBJTYPE", $opts);
540  $a_tpl->setVariable("BTN_NAME", "create");
541  $a_tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
542  $a_tpl->parseCurrentBlock();
543  }
544 
545  return $a_tpl;
546  }
547 
552  function saveObject()
553  {
554  global $rbacadmin;
555 
556  // role folders are created automatically
557  $_GET["new_type"] = $this->object->getType();
558  $_POST["Fobject"]["title"] = $this->object->getTitle();
559  $_POST["Fobject"]["desc"] = $this->object->getDescription();
560 
561  // always call parent method first to create an object_data entry & a reference
562  $newObj = parent::saveObject();
563 
564  // put here your object specific stuff
565 
566  // always send a message
567  ilUtil::sendSuccess($this->lng->txt("rolf_added"),true);
568 
569  $this->ctrl->redirect($this, "view");
570  }
571 
578  function getAdminTabs(&$tabs_gui)
579  {
580  global $tree,$lng;
581 
582  if ($this->checkPermissionBool("visible,read"))
583  {
584  $tabs_gui->addTarget(
585  "view",
586  $this->ctrl->getLinkTarget($this, "view"),
587  array("", "view"),
588  get_class($this)
589  );
590 
591  }
592 
593  if($this->checkPermissionBool("edit_permission"))
594  {
595  $tabs_gui->addTarget("perm_settings",
596  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'),
597  "perm"),
598  "",
599  "ilpermissiongui");
600  }
601 
602  }
603 
604 
605 
606 } // END class.ilObjRoleFolderGUI
607 ?>