ILIAS  Release_4_1_x_branch Revision 61804
 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  $this->type = "rolf";
54  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference, false);
55  }
56 
57  function &executeCommand()
58  {
59  $next_class = $this->ctrl->getNextClass($this);
60  $cmd = $this->ctrl->getCmd();
61  $this->prepareOutput();
62 
63  switch($next_class)
64  {
65  case 'ilpermissiongui':
66  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
67  $perm_gui =& new ilPermissionGUI($this);
68  $ret =& $this->ctrl->forwardCommand($perm_gui);
69  break;
70 
71  default:
72  if(!$cmd)
73  {
74  $cmd = "view";
75  }
76  $cmd .= "Object";
77  $this->$cmd();
78 
79  break;
80  }
81  return true;
82  }
83 
89  function viewObject ()
90  {
91  global $rbacreview,$rbacsystem;
92 
93  if (!$rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
94  {
95  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
96  }
97 
98  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.usr_role_assignment.html');
99 
100  $assignable = false;
101 
102  if ($this->object->getId() == ROLE_FOLDER_ID)
103  {
104  $assignable = true;
105 
106  $_SESSION['filtered_roles'] = isset($_POST['filter']) ? $_POST['filter'] : $_SESSION['filtered_roles'];
107 
108  if ($_SESSION['filtered_roles'] == 0)
109  {
110  $_SESSION['filtered_roles'] = 2;
111  }
112 
113  $this->tpl->setCurrentBlock("filter");
114  $this->tpl->setVariable("FILTER_TXT_FILTER",$this->lng->txt('filter'));
115  $this->tpl->setVariable("SELECT_FILTER",$this->__buildFilterSelect());
116  $this->tpl->setVariable("FILTER_ACTION",$this->ctrl->getFormAction($this));
117  $this->tpl->setVariable("FILTER_NAME",'view');
118  $this->tpl->setVariable("FILTER_VALUE",$this->lng->txt('apply_filter'));
119  $this->tpl->parseCurrentBlock();
120 
121 
122  // now get roles depending on filter settings
123  $role_list = $rbacreview->getRolesByFilter($_SESSION["filtered_roles"],$this->object->getId());
124  }
125  else
126  {
127  $role_list = $rbacreview->getRoleListByObject($_GET["ref_id"],true);
128  }
129 
130  $counter = 0;
131 
132  include_once ('./Services/AccessControl/classes/class.ilObjRole.php');
133 
134  foreach ($role_list as $role)
135  {
136  // exclude templates
137  if ($role["type"] == "rolt")
138  {
139  $path = $this->lng->txt("obj_rolt");
140  $rolf = ROLE_FOLDER_ID;
141  }
142  else
143  {
144  // fetch context path of role
145  $rolf_list = $rbacreview->getFoldersAssignedToRole($role["obj_id"],$assignable);
146 
147  if ($this->object->getId() != ROLE_FOLDER_ID)
148  {
149  $rolf = $this->object->getRefId();
150  }
151  else
152  {
153  $rolf = $rolf_list[0];
154  }
155 
156  // only list roles that are not set to status "deleted"
157  if ($rbacreview->isDeleted($rolf))
158  {
159  continue;
160  }
161 
162  // build context path
163  $path = "";
164 
165  if ($this->tree->isInTree($rolf))
166  {
167  if ($rolf[0] == ROLE_FOLDER_ID)
168  {
169  $path = $this->lng->txt("global");
170  }
171  else
172  {
173  $tmpPath = $this->tree->getPathFull($rolf);
174  $path = $tmpPath[count($tmpPath)-2]["title"];
175  }
176  }
177  else
178  {
179  $path = "<b>Rolefolder ".$rolf." not found in tree! (Role ".$role["obj_id"].")</b>";
180  }
181  }
182 
183  $disabled = false;
184  $checkbox = ilUtil::formCheckBox(0,"role_id[]",$role["obj_id"],$disabled);
185 
186  // disable checkbox for system role for the system user
187  if ($role["role_type"] != 'linked'
188  && ($role["obj_id"] == SYSTEM_ROLE_ID
189  or $role["obj_id"] == ANONYMOUS_ROLE_ID
190  or substr($role["title"],0,3) == "il_"))
191  {
192  $disabled = true;
193  $checkbox = "";
194  }
195 
196  if ($_SESSION["filtered_roles"] != 4)
197  {
198  $result_set[$counter][] = $checkbox ? $checkbox : '';
199  $role_ids[$counter] = $role["obj_id"];
200  }
201 
202  if (substr($role["title"],0,3) == "il_" and $role['type'] != "rolt")
203  {
204  if (!$assignable)
205  {
206  $rolf_arr = $rbacreview->getFoldersAssignedToRole($role["obj_id"],true);
207  $rolf2 = $rolf_arr[0];
208  }
209  else
210  {
211  $rolf2 = $rolf;
212  }
213 
214  $parent_node = $this->tree->getParentNodeData($rolf2);
215 
216  $role["description"] = $this->lng->txt("obj_".$parent_node["type"])."&nbsp;(#".$parent_node["obj_id"].")";
217  }
218 
219  if ($role["type"] == "rolt" and (substr($role["title"],0,3) == "il_"))
220  {
221  $role["description"] .= "<br/><i>".$this->lng->txt("predefined_template")." (".$role["title"].")</i>";
222  }
223 
224  $result_set[$counter][] = "<img src=\"".ilUtil::getImagePath("icon_".$role["type"].".gif")."\" alt=\"".$this->lng->txt("obj_".$role["type"])."\" title=\"".$this->lng->txt("obj_".$role["type"])."\" border=\"0\" vspace=\"0\"/>";
225  if ($role["type"] == "role")
226  {
227  if (($this->object->getId() == ROLE_FOLDER_ID) &&
228  ($role["role_type"] == "local"))
229  {
230  $this->ctrl->setParameterByClass("ilobjrolegui", "rolf_ref_id", $rolf);
231  }
232  $this->ctrl->setParameterByClass("ilobjrolegui", "obj_id", $role["obj_id"]);
233  $link = $this->ctrl->getLinkTargetByClass("ilobjrolegui", "perm");
234  $this->ctrl->setParameterByClass("ilobjrolegui", "rolf_ref_id", "");
235  }
236  else
237  {
238  $this->ctrl->setParameterByClass("ilobjroletemplategui", "obj_id", $role["obj_id"]);
239  $link = $this->ctrl->getLinkTargetByClass("ilobjroletemplategui", "perm");
240  }
241  $result_set[$counter][] = "<a title=\"".ilObjRole::_getTranslation($role["title"])."\" href=\"$link\">".ilObjRole::_getTranslation($role["title"])."</a>";
242  $result_set[$counter][] = $role["description"] ? $role['description'] : '';
243  $result_set[$counter][] = $path." (".$role["role_type"].")";;
244 
245  ++$counter;
246  }
247 
248  return $this->__showRolesTable($result_set,$role_ids);
249  }
250 
251 
259  {
260  global $rbacsystem,$rbacreview;
261 
262  // FOR NON_REF_OBJECTS WE CHECK ACCESS ONLY OF PARENT OBJECT ONCE
263  if (!$rbacsystem->checkAccess('delete',$this->object->getRefId()))
264  {
265  $perform_delete = false;
266  $this->ilias->raiseError($this->lng->txt("msg_no_perm_delete")." ".
267  $not_deletable,$this->ilias->error_obj->MESSAGE);
268  }
269 
270  $return_loc = $this->tree->getParentId($this->object->getRefId());
271 
272  $feedback["count"] = count($_SESSION["saved_post"]);
273 
274  // FOR ALL SELECTED OBJECTS
275  foreach ($_SESSION["saved_post"] as $id)
276  {
277  // instatiate correct object class (role or rolt)
278  $obj =& $this->ilias->obj_factory->getInstanceByObjId($id);
279 
280  if ($obj->getType() == "role")
281  {
282  $rolf_arr = $rbacreview->getFoldersAssignedToRole($obj->getId(),true);
283  $obj->setParent($rolf_arr[0]);
284 
285  $feedback["role"] = true;
286  }
287  else
288  {
289  $feedback["rolt"] = true;
290  }
291 
292  $obj->delete();
293  unset($obj);
294  }
295 
296  // set correct return location if rolefolder is removed
297  $return_loc = ilObject::_exists($this->object->getId()) ? $_GET["ref_id"] : $return_loc;
298 
299  // Compose correct feedback
300  if ($feedback["count"] > 1)
301  {
302  if ($feedback["role"] === true)
303  {
304  if ($feedback["rolt"] === true)
305  {
306  ilUtil::sendSuccess($this->lng->txt("msg_deleted_roles_rolts"),true);
307  }
308  else
309  {
310  ilUtil::sendSuccess($this->lng->txt("msg_deleted_roles"),true);
311  }
312  }
313  else
314  {
315  ilUtil::sendSuccess($this->lng->txt("msg_deleted_rolts"),true);
316  }
317  }
318  else
319  {
320  if ($feedback["role"] === true)
321  {
322  ilUtil::sendSuccess($this->lng->txt("msg_deleted_role"),true);
323  }
324  else
325  {
326  ilUtil::sendSuccess($this->lng->txt("msg_deleted_rolt"),true);
327  }
328  }
329 
330  //$this->ctrl->setParameter($this, "ref_id", $return_loc);
331  //$this->ctrl->redirect($this, "view");
332 
333  // fixed for admin view
334  #$this->redirectToRefId($return_loc, "view");
335  $obj_type = ilObject::_lookupType($return_loc,true);
336  $class_name = $this->objDefinition->getClassName($obj_type);
337  $class = strtolower("ilObj".$class_name."GUI");
338  $this->ctrl->setParameterByClass($class,'ref_id',$return_loc);
339  $this->ctrl->redirectByClass($class,'view');
340  }
341 
347  function createObject()
348  {
349  $this->object->setTitle($this->lng->txt("obj_".$this->object->getType()."_local"));
350  $this->object->setDescription("obj_".$this->object->getType()."_local_desc");
351 
352  $this->saveObject();
353  }
354 
360  function deleteObject()
361  {
362  if (!isset($_POST["role_id"]))
363  {
364  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
365  }
366 
367  // SAVE POST VALUES
368  $_SESSION["saved_post"] = $_POST["role_id"];
369 
370  unset($this->data);
371  $this->data["cols"] = array("type", "title", "description", "last_change");
372 
373  foreach($_POST["role_id"] as $id)
374  {
375  $obj_data =& $this->ilias->obj_factory->getInstanceByObjId($id);
376 
377  $this->data["data"]["$id"] = array(
378  "type" => $obj_data->getType(),
379  "title" => $obj_data->getTitle(),
380  "desc" => $obj_data->getDescription(),
381  "last_update" => $obj_data->getLastUpdateDate());
382  }
383 
384  $this->data["buttons"] = array( "cancelDelete" => $this->lng->txt("cancel"),
385  "confirmedDelete" => $this->lng->txt("confirm"));
386 
387  $this->getTemplateFile("confirm");
388 
389  ilUtil::sendQuestion($this->lng->txt("info_delete_sure"));
390 
391  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
392 
393  // BEGIN TABLE HEADER
394  foreach ($this->data["cols"] as $key)
395  {
396  $this->tpl->setCurrentBlock("table_header");
397  $this->tpl->setVariable("TEXT",$this->lng->txt($key));
398  $this->tpl->parseCurrentBlock();
399  }
400  // END TABLE HEADER
401 
402  // BEGIN TABLE DATA
403  $counter = 0;
404 
405  foreach ($this->data["data"] as $key => $value)
406  {
407  // BEGIN TABLE CELL
408  foreach ($value as $key => $cell_data)
409  {
410  $this->tpl->setCurrentBlock("table_cell");
411 
412  // CREATE TEXT STRING
413  if ($key == "type")
414  {
415  $this->tpl->setVariable("TEXT_CONTENT",ilUtil::getImageTagByType($cell_data,$this->tpl->tplPath));
416  }
417  else
418  {
419  $this->tpl->setVariable("TEXT_CONTENT",$cell_data);
420  }
421 
422  $this->tpl->parseCurrentBlock();
423  }
424 
425  $this->tpl->setCurrentBlock("table_row");
426  $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
427  $this->tpl->parseCurrentBlock();
428  // END TABLE CELL
429  }
430  // END TABLE DATA
431 
432  // BEGIN OPERATION_BTN
433  foreach ($this->data["buttons"] as $name => $value)
434  {
435  $this->tpl->setCurrentBlock("operation_btn");
436  $this->tpl->setVariable("BTN_NAME",$name);
437  $this->tpl->setVariable("BTN_VALUE",$value);
438  $this->tpl->parseCurrentBlock();
439  }
440  }
441 
448  {
449  ilUtil::sendSuccess($this->lng->txt("saved_successfully"),true);
450 
451  $this->ctrl->redirect($this, "view");
452  }
453 
460  function showPossibleSubObjects($a_tpl)
461  {
462  global $rbacsystem;
463 
464  $d = $this->objDefinition->getCreatableSubObjects($this->object->getType());
465 
466  if ($this->object->getRefId() != ROLE_FOLDER_ID or !$rbacsystem->checkAccess('create_rolt',ROLE_FOLDER_ID))
467  {
468  unset($d["rolt"]);
469  }
470 
471  if (!$rbacsystem->checkAccess('create_role',$this->object->getRefId()))
472  {
473  unset($d["role"]);
474  }
475 
476  if (count($d) > 0)
477  {
478  foreach ($d as $row)
479  {
480  $count = 0;
481  if ($row["max"] > 0)
482  {
483  //how many elements are present?
484  for ($i=0; $i<count($this->data["ctrl"]); $i++)
485  {
486  if ($this->data["ctrl"][$i]["type"] == $row["name"])
487  {
488  $count++;
489  }
490  }
491  }
492  if ($row["max"] == "" || $count < $row["max"])
493  {
494  $subobj[] = $row["name"];
495  }
496  }
497  }
498 
499  if (is_array($subobj))
500  {
501  //build form
502  $opts = ilUtil::formSelect(12,"new_type",$subobj);
503  $a_tpl->setCurrentBlock("add_object");
504  $a_tpl->setVariable("SELECT_OBJTYPE", $opts);
505  $a_tpl->setVariable("BTN_NAME", "create");
506  $a_tpl->setVariable("TXT_ADD", $this->lng->txt("add"));
507  $a_tpl->parseCurrentBlock();
508  }
509 
510  return $a_tpl;
511  }
512 
517  function saveObject()
518  {
519  global $rbacadmin;
520 
521  // role folders are created automatically
522  $_GET["new_type"] = $this->object->getType();
523  $_POST["Fobject"]["title"] = $this->object->getTitle();
524  $_POST["Fobject"]["desc"] = $this->object->getDescription();
525 
526  // always call parent method first to create an object_data entry & a reference
527  $newObj = parent::saveObject();
528 
529  // put here your object specific stuff
530 
531  // always send a message
532  ilUtil::sendSuccess($this->lng->txt("rolf_added"),true);
533 
534  $this->ctrl->redirect($this, "view");
535  }
536 
537  function __showRolesTable($a_result_set,$a_role_ids)
538  {
539  global $rbacsystem;
540 
541  $actions = array("delete" => $this->lng->txt("delete"));
542 
543  $tbl =& $this->__initTableGUI();
544  $tpl =& $tbl->getTemplateObject();
545 
546  $tpl->setCurrentBlock("tbl_form_header");
547  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
548  $tpl->parseCurrentBlock();
549 
550  $tpl = $this->showPossibleSubObjects($tpl);
551 
552  $tpl->setCurrentBlock("tbl_action_row");
553 
554  $tpl->setVariable("COLUMN_COUNTS",($_SESSION["filtered_roles"] == 4) ? 4 : 5);
555 
556  if ($_SESSION["filtered_roles"] != 4)
557  {
558  $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
559 
560  foreach ($actions as $name => $value)
561  {
562  $tpl->setCurrentBlock("tbl_action_btn");
563  $tpl->setVariable("BTN_NAME",$name);
564  $tpl->setVariable("BTN_VALUE",$value);
565  $tpl->parseCurrentBlock();
566  }
567 
568  if (!empty($a_role_ids))
569  {
570 
571  // set checkbox toggles
572  $tpl->setCurrentBlock("tbl_action_toggle_checkboxes");
573  $tpl->setVariable("JS_VARNAME","role_id");
574  $tpl->setVariable("JS_ONCLICK",ilUtil::array_php2js($a_role_ids));
575  $tpl->setVariable("TXT_CHECKALL", $this->lng->txt("check_all"));
576  $tpl->setVariable("TXT_UNCHECKALL", $this->lng->txt("uncheck_all"));
577  $tpl->parseCurrentBlock();
578  }
579  }
580 
581  $tpl->setVariable("TPLPATH",$this->tpl->tplPath);
582 
583 
584  $this->ctrl->setParameter($this,"cmd","view");
585 
586  // title & header columns
587  $tbl->setTitle($this->lng->txt("roles"),"icon_role.gif",$this->lng->txt("roles"));
588 
589  if ($_SESSION["filtered_roles"] == 4)
590  {
591  $tbl->setHeaderNames(array($this->lng->txt("type"),$this->lng->txt("role"),
592  $this->lng->txt("description"),$this->lng->txt("context")));
593  $tbl->setHeaderVars(array("type","title","description","context"),$this->ctrl->getParameterArray($this,"",false));
594  $tbl->setColumnWidth(array("","30%","40%","30%"));
595  }
596  else
597  {
598  $tbl->setHeaderNames(array("",$this->lng->txt("type"),
599  $this->lng->txt("role"),
600  $this->lng->txt("description"),
601  $this->lng->txt("context")));
602  $tbl->setHeaderVars(array("","type","title","description","context"),$this->ctrl->getParameterArray($this,"",false));
603  $tbl->setColumnWidth(array("","","30%","40%","30%"));
604  }
605  $this->__setTableGUIBasicData($tbl,$a_result_set,"view");
606  $tbl->render();
607  $this->tpl->setVariable("ROLES_TABLE",$tbl->tpl->get());
608 
609  return true;
610  }
611 
612  function &__initTableGUI()
613  {
614  include_once "./Services/Table/classes/class.ilTableGUI.php";
615 
616  return new ilTableGUI(0,false);
617  }
618 
619  function __setTableGUIBasicData(&$tbl,&$result_set,$from = "")
620  {
621  switch($from)
622  {
623  default:
624  if (!$_GET["sort_by"] or $_GET["sort_by"] == "name")
625  {
626  $_GET["sort_by"] = "title";
627  }
628 
629  $order = $_GET["sort_by"];
630  break;
631  }
632 
633  //$tbl->enable("hits");
634  $tbl->setOrderColumn($order);
635  $tbl->setOrderDirection($_GET["sort_order"]);
636  $tbl->setOffset($_GET["offset"]);
637  $tbl->setLimit($_GET["limit"]);
638  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
639  $tbl->setData($result_set);
640  }
641 
643  {
644  // empty
645  }
646 
648  {
649  $action[1] = $this->lng->txt('all_roles');
650  $action[2] = $this->lng->txt('all_global_roles');
651  $action[3] = $this->lng->txt('all_local_roles');
652  $action[4] = $this->lng->txt('internal_local_roles_only');
653  $action[5] = $this->lng->txt('non_internal_local_roles_only');
654  $action[6] = $this->lng->txt('role_templates_only');
655 
656  return ilUtil::formSelect($_SESSION['filtered_roles'],"filter",$action,false,true);
657  }
658 
659  function hitsperpageObject()
660  {
662  $this->viewObject();
663  }
664 
670  function getTabs(&$tabs_gui)
671  {
672  // METHOD NOT USED????
673 
674 
675  global $rbacsystem, $tree;
676 
677  // for role administration check visible,write of global role folder
678  if ($this->object->getRefId() == ROLE_FOLDER_ID)
679  {
680  $access = $rbacsystem->checkAccess('visible,write',$this->object->getRefId());
681  }
682  else // for local roles check 'edit permission' of parent object of the local role folder
683  {
684  $access = $rbacsystem->checkAccess('edit_permission',$tree->getParentId($this->object->getRefId()));
685  }
686 
687  if ($access)
688  {
689  $tabs_gui->addTarget("obj_rolf",
690  $this->ctrl->getLinkTarget($this, "view"), array("view","delete",""), "", "");
691  }
692 
693  if ($this->object->getRefId() == ROLE_FOLDER_ID and $rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
694  {
695  $tabs_gui->addTarget("perm_settings",
696  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
697  }
698  }
699 
700 } // END class.ilObjRoleFolderGUI
701 ?>