ILIAS  Release_4_2_x_branch Revision 61807
 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 "./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  $this->ctrl->setParameter($this,'new_type','rolt');
113  $ilToolbar->addButton(
114  $this->lng->txt('rolf_create_rolt'),
115  $this->ctrl->getLinkTarget($this,'create')
116  );
117  $this->ctrl->clearParameters($this);
118 
119  include_once './Services/AccessControl/classes/class.ilRoleTableGUI.php';
120  $table = new ilRoleTableGUI($this,'view');
121  $table->init();
122  $table->parse($this->object->getId());
123 
124  $this->tpl->setContent($table->getHTML());
125  }
126 
130  protected function roleSearchObject()
131  {
132  global $rbacsystem, $ilCtrl, $ilTabs;
133 
134  $ilTabs->clearTargets();
135  $ilTabs->setBackTarget(
136  $this->lng->txt('rbac_back_to_overview'),
137  $this->ctrl->getLinkTarget($this,'view')
138  );
139 
140  if(!$rbacsystem->checkAccess('visible,read',$this->object->getRefId()))
141  {
142  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
143  }
144 
145  $ilCtrl->setParameter($this,'copy_source',(int) $_REQUEST['copy_source']);
146  ilUtil::sendInfo($this->lng->txt('rbac_choose_copy_targets'));
147 
148  $form = $this->initRoleSearchForm();
149  $this->tpl->setContent($form->getHTML());
150  }
151 
155  protected function initRoleSearchForm()
156  {
157  global $ilCtrl;
158 
159  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
160  $form = new ilPropertyFormGUI();
161  $form->setTitle($this->lng->txt('rbac_role_title'));
162  $form->setFormAction($ilCtrl->getFormAction($this,'view'));
163 
164  $search = new ilTextInputGUI($this->lng->txt('title'), 'title');
165  $search->setRequired(true);
166  $search->setSize(30);
167  $search->setMaxLength(255);
168  $form->addItem($search);
169 
170  $form->addCommandButton('roleSearchList', $this->lng->txt('search'));
171  return $form;
172  }
173 
177  protected function roleSearchListObject()
178  {
179  global $ilTabs, $ilCtrl;
180 
181  $ilTabs->clearTargets();
182  $ilTabs->setBackTarget(
183  $this->lng->txt('rbac_back_to_overview'),
184  $this->ctrl->getLinkTarget($this,'roleSearchList')
185  );
186 
187  $ilCtrl->setParameter($this,'copy_source',(int) $_REQUEST['copy_source']);
188 
189  $form = $this->initRoleSearchForm();
190  if($form->checkInput())
191  {
192  ilUtil::sendInfo($this->lng->txt('rbac_select_copy_targets'));
193 
194  include_once './Services/AccessControl/classes/class.ilRoleTableGUI.php';
195  $table = new ilRoleTableGUI($this,'view');
196  $table->setType(ilRoleTableGUI::TYPE_SEARCH);
197  $table->setRoleTitleFilter($form->getInput('title'));
198  $table->init();
199  $table->parse($this->object->getId());
200  return $this->tpl->setContent($table->getHTML());
201  }
202 
203  ilUtil::sendFailure($this->lng->txt('msg_no_search_string'), true);
204  $form->setValuesByPost();
205  $ilCtrl->redirect($this,'roleSearch');
206  }
207 
212  protected function chooseCopyBehaviourObject()
213  {
214  global $ilCtrl, $ilTabs;
215 
216  $ilTabs->clearTargets();
217  $ilTabs->setBackTarget(
218  $this->lng->txt('rbac_back_to_overview'),
219  $this->ctrl->getLinkTarget($this,'roleSearchList')
220  );
221 
222  $ilCtrl->setParameter($this,'copy_source',(int) $_REQUEST['copy_source']);
223 
224  $form = $this->initCopyBehaviourForm();
225  $this->tpl->setContent($form->getHTML());
226  }
227 
231  protected function initCopyBehaviourForm()
232  {
233  global $ilCtrl;
234 
235  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
236  $form = new ilPropertyFormGUI();
237  $form->setTitle($this->lng->txt('rbac_copy_behaviour'));
238  $form->setFormAction($ilCtrl->getFormAction($this,'chooseCopyBehaviour'));
239 
240  $ce = new ilRadioGroupInputGUI($this->lng->txt('change_existing_objects'), 'change_existing');
241  $ce->setRequired(true);
242  $ce->setValue(1);
243  $form->addItem($ce);
244 
245  $ceo = new ilRadioOption($this->lng->txt('change_existing_objects'),1);
246  $ce->addOption($ceo);
247 
248  $cne = new ilRadioOption($this->lng->txt('rbac_not_change_existing_objects'), 0);
249  $ce->addOption($cne);
250 
251  $roles = new ilHiddenInputGUI('roles');
252  $roles->setValue(implode(',',(array) $_POST['roles']));
253  $form->addItem($roles);
254 
255  $form->addCommandButton('copyRole', $this->lng->txt('rbac_copy_role'));
256  return $form;
257  }
258 
262  protected function copyRoleObject()
263  {
264  global $ilCtrl;
265 
266  // Finally copy role/rolt
267  $roles = explode(',',$_POST['roles']);
268  $source = (int) $_REQUEST['copy_source'];
269 
270  $form = $this->initCopyBehaviourForm();
271  if($form->checkInput())
272  {
273  foreach((array) $roles as $role_id)
274  {
275  if($role_id != $source)
276  {
277  $this->doCopyRole($source,$role_id,$form->getInput('change_existing'));
278  }
279  }
280 
281  ilUtil::sendSuccess($this->lng->txt('rbac_copy_finished'),true);
282  $ilCtrl->redirect($this,'view');
283  }
284  }
285 
296  protected function doCopyRole($source, $target, $change_existing)
297  {
298  global $tree, $rbacadmin, $rbacreview;
299 
300 
301 
302  // Copy role template permissions
303  $rbacadmin->copyRoleTemplatePermissions(
304  $source,
305  $this->object->getRefId(),
306  $rbacreview->getRoleFolderOfRole($target),
307  $target
308  );
309 
310  if(!$change_existing)
311  {
312  return true;
313  }
314 
315  $start = ($this->object->getRefId() == ROLE_FOLDER_ID) ?
316  ROOT_FOLDER_ID :
317  $tree->getParentId($this->object->getRefId());
318 
319 
320 
321  include_once './Services/AccessControl/classes/class.ilObjRole.php';
322  if($rbacreview->isProtected($this->object->getRefId(),$source))
323  {
325  }
326  else
327  {
329  }
330 
331  $role = new ilObjRole($target);
332  $role->changeExistingObjects(
333  $start,
334  $mode,
335  array('all')
336  );
337  }
338 
342  protected function applyFilterObject()
343  {
344  include_once './Services/AccessControl/classes/class.ilRoleTableGUI.php';
345  $table = new ilRoleTableGUI($this,'view');
346  $table->init();
347  $table->resetOffset();
348  $table->writeFilterToSession();
349 
350  $this->viewObject();
351  }
352 
356  function resetFilterObject()
357  {
358  include_once './Services/AccessControl/classes/class.ilRoleTableGUI.php';
359  $table = new ilRoleTableGUI($this,'view');
360  $table->init();
361  $table->resetOffset();
362  $table->resetFilter();
363 
364  $this->viewObject();
365  }
366 
370  protected function confirmDeleteObject()
371  {
372  global $ilCtrl;
373 
374  if(!count($_POST['roles']))
375  {
376  ilUtil::sendFailure($this->lng->txt('select_one'),true);
377  $ilCtrl->redirect($this,'view');
378  }
379 
380  $question = $this->lng->txt('rbac_role_delete_qst');
381 
382  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
383  $confirm = new ilConfirmationGUI();
384  $confirm->setHeaderText($question);
385  $confirm->setFormAction($ilCtrl->getFormAction($this));
386  $confirm->setConfirm($this->lng->txt('delete'), 'deleteRole');
387  $confirm->setCancel($this->lng->txt('cancel'), 'cancel');
388 
389 
390  include_once './Services/AccessControl/classes/class.ilObjRole.php';
391  foreach($_POST['roles'] as $role_id)
392  {
393  $confirm->addItem(
394  'roles[]',
395  $role_id,
397  );
398  }
399  $this->tpl->setContent($confirm->getHTML());
400  }
401 
405  protected function deleteRoleObject()
406  {
407  global $rbacsystem,$ilErr,$rbacreview,$ilCtrl;
408 
409  if(!$rbacsystem->checkAccess('delete',$this->object->getRefId()))
410  {
411  $ilErr->raiseError(
412  $this->lng->txt('msg_no_perm_delete'),
413  $ilErr->MESSAGE
414  );
415  }
416 
417  foreach((array) $_POST['roles'] as $id)
418  {
419  // instatiate correct object class (role or rolt)
420  $obj = ilObjectFactory::getInstanceByObjId($id,false);
421 
422  if ($obj->getType() == "role")
423  {
424  $rolf_arr = $rbacreview->getFoldersAssignedToRole($obj->getId(),true);
425  $obj->setParent($rolf_arr[0]);
426  }
427 
428  $obj->delete();
429  }
430 
431  // set correct return location if rolefolder is removed
432  ilUtil::sendSuccess($this->lng->txt("msg_deleted_roles_rolts"),true);
433  $ilCtrl->redirect($this,'view');
434  }
435 
436 
437 
438 
439 
445  function createObject()
446  {
447  $this->object->setTitle($this->lng->txt("obj_".$this->object->getType()."_local"));
448  $this->object->setDescription("obj_".$this->object->getType()."_local_desc");
449 
450  $this->saveObject();
451  }
452 
458  function deleteObject()
459  {
460  if (!isset($_POST["role_id"]))
461  {
462  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
463  }
464 
465  // SAVE POST VALUES
466  $_SESSION["saved_post"] = $_POST["role_id"];
467 
468  unset($this->data);
469  $this->data["cols"] = array("type", "title", "description", "last_change");
470 
471  foreach($_POST["role_id"] as $id)
472  {
473  $obj_data =& $this->ilias->obj_factory->getInstanceByObjId($id);
474 
475  $this->data["data"]["$id"] = array(
476  "type" => $obj_data->getType(),
477  "title" => $obj_data->getTitle(),
478  "desc" => $obj_data->getDescription(),
479  "last_update" => $obj_data->getLastUpdateDate());
480  }
481 
482  $this->data["buttons"] = array( "cancelDelete" => $this->lng->txt("cancel"),
483  "confirmedDelete" => $this->lng->txt("confirm"));
484 
485  $this->getTemplateFile("confirm");
486 
487  ilUtil::sendQuestion($this->lng->txt("info_delete_sure"));
488 
489  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
490 
491  // BEGIN TABLE HEADER
492  foreach ($this->data["cols"] as $key)
493  {
494  $this->tpl->setCurrentBlock("table_header");
495  $this->tpl->setVariable("TEXT",$this->lng->txt($key));
496  $this->tpl->parseCurrentBlock();
497  }
498  // END TABLE HEADER
499 
500  // BEGIN TABLE DATA
501  $counter = 0;
502 
503  foreach ($this->data["data"] as $key => $value)
504  {
505  // BEGIN TABLE CELL
506  foreach ($value as $key => $cell_data)
507  {
508  $this->tpl->setCurrentBlock("table_cell");
509 
510  // CREATE TEXT STRING
511  if ($key == "type")
512  {
513  $this->tpl->setVariable("TEXT_CONTENT",ilUtil::getImageTagByType($cell_data,$this->tpl->tplPath));
514  }
515  else
516  {
517  $this->tpl->setVariable("TEXT_CONTENT",$cell_data);
518  }
519 
520  $this->tpl->parseCurrentBlock();
521  }
522 
523  $this->tpl->setCurrentBlock("table_row");
524  $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
525  $this->tpl->parseCurrentBlock();
526  // END TABLE CELL
527  }
528  // END TABLE DATA
529 
530  // BEGIN OPERATION_BTN
531  foreach ($this->data["buttons"] as $name => $value)
532  {
533  $this->tpl->setCurrentBlock("operation_btn");
534  $this->tpl->setVariable("BTN_NAME",$name);
535  $this->tpl->setVariable("BTN_VALUE",$value);
536  $this->tpl->parseCurrentBlock();
537  }
538  }
539 
546  {
547  ilUtil::sendSuccess($this->lng->txt("saved_successfully"),true);
548 
549  $this->ctrl->redirect($this, "view");
550  }
551 
558  function showPossibleSubObjects($a_tpl)
559  {
560  global $rbacsystem;
561 
562  $d = $this->objDefinition->getCreatableSubObjects($this->object->getType());
563 
564  if ($this->object->getRefId() != ROLE_FOLDER_ID or !$rbacsystem->checkAccess('create_rolt',ROLE_FOLDER_ID))
565  {
566  unset($d["rolt"]);
567  }
568 
569  if (!$rbacsystem->checkAccess('create_role',$this->object->getRefId()))
570  {
571  unset($d["role"]);
572  }
573 
574  if (count($d) > 0)
575  {
576  foreach ($d as $row)
577  {
578  $count = 0;
579  if ($row["max"] > 0)
580  {
581  //how many elements are present?
582  for ($i=0; $i<count($this->data["ctrl"]); $i++)
583  {
584  if ($this->data["ctrl"][$i]["type"] == $row["name"])
585  {
586  $count++;
587  }
588  }
589  }
590  if ($row["max"] == "" || $count < $row["max"])
591  {
592  $subobj[] = $row["name"];
593  }
594  }
595  }
596 
597  if (is_array($subobj))
598  {
599  //build form
600  $opts = ilUtil::formSelect(12,"new_type",$subobj);
601  $a_tpl->setCurrentBlock("add_object");
602  $a_tpl->setVariable("SELECT_OBJTYPE", $opts);
603  $a_tpl->setVariable("BTN_NAME", "create");
604  $a_tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
605  $a_tpl->parseCurrentBlock();
606  }
607 
608  return $a_tpl;
609  }
610 
615  function saveObject()
616  {
617  global $rbacadmin;
618 
619  // role folders are created automatically
620  $_GET["new_type"] = $this->object->getType();
621  $_POST["Fobject"]["title"] = $this->object->getTitle();
622  $_POST["Fobject"]["desc"] = $this->object->getDescription();
623 
624  // always call parent method first to create an object_data entry & a reference
625  $newObj = parent::saveObject();
626 
627  // put here your object specific stuff
628 
629  // always send a message
630  ilUtil::sendSuccess($this->lng->txt("rolf_added"),true);
631 
632  $this->ctrl->redirect($this, "view");
633  }
634 
641  function getAdminTabs(&$tabs_gui)
642  {
643  global $tree,$lng;
644 
645  if ($this->checkPermissionBool("visible,read"))
646  {
647  $tabs_gui->addTarget(
648  "view",
649  $this->ctrl->getLinkTarget($this, "view"),
650  array("", "view"),
651  get_class($this)
652  );
653 
654  }
655 
656  if($this->checkPermissionBool("edit_permission"))
657  {
658  $tabs_gui->addTarget("perm_settings",
659  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'),
660  "perm"),
661  "",
662  "ilpermissiongui");
663  }
664 
665  }
666 
667 
668 
669 } // END class.ilObjRoleFolderGUI
670 ?>