ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjectStatusGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
14 {
15  var $lng;
16  var $ilias;
17  var $tpl;
18  var $tree;
21  var $cmd;
22  var $mode;
23  var $ctrl;
24 
29  function ilObjectStatusGUI(&$a_obj)
30  {
31  global $ilUser,$ilCtrl,$ilias,$ilErr,$lng,$rbacreview;
32 
33  $this->ctrl =& $ilCtrl;
34  $this->object =& $a_obj;
35 
36  $this->tpl = new ilTemplate("tpl.info_layout.html", false, false,
37  "Services/AccessControl");
38  $this->tpl->setVariable("INFO_REMARK_INTERRUPTED",$lng->txt('info_remark_interrupted'));
39 
40  if (empty($_POST['Fuserid']))
41  {
42  $this->user =& $ilUser;
43  }
44  else
45  {
46  if ($_POST['Fselect_type'] == "id")
47  {
48  $this->user = $ilias->obj_factory->getInstanceByObjId($_POST['Fuserid'],false);
49  }
50  else
51  {
52  include_once('Services/User/classes/class.ilObjUser.php');
53  $user_id = ilObjUser::_lookupId($_POST['Fuserid']);
54  $this->user = $ilias->obj_factory->getInstanceByObjId($user_id,false);
55  }
56 
57  if ($this->user === false or $this->user->getType() != 'usr')
58  {
59  $this->user =& $ilUser;
60  ilUtil::sendFailure($lng->txt('info_err_user_not_exist'));
61  }
62  else
63  {
64  ilUtil::sendInfo($lng->txt('info_user_view_changed'));
65  }
66  }
67 
68  // get all user roles and all valid roles in scope
69  $this->user_roles = $rbacreview->assignedRoles($this->user->getId());
70  $this->global_roles = $rbacreview->getGlobalRoles();
71  $this->valid_roles = $rbacreview->getParentRoleIds($this->object->getRefId());
72  $this->assigned_valid_roles = $this->getAssignedValidRoles();
73 
74  $this->getPermissionInfo();
75 
76  $this->getRoleAssignmentInfo();
77 
78  $this->getObjectSummary();
79 
80  }
81 
85  function &executeCommand()
86  {
87  $next_class = $this->ctrl->getNextClass($this);
88  $this->ctrl->setCmd("");
89  }
90 
91  function &__initTableGUI()
92  {
93  include_once "./Services/Table/classes/class.ilTableGUI.php";
94 
95  return new ilTableGUI(0,false);
96  }
97 
98  function __setTableGUIBasicData(&$tbl,&$result_set,$from = "")
99  {
100  global $lng;
101 
102  $tbl->disable('footer');
103  $tbl->disable('linkbar');
104  $tbl->disable('hits');
105  $tbl->disable('sort');
106 
107  $tbl->setLimit(0);
108  $tbl->setData($result_set);
109  }
110 
111  function __showPermissionsTable($a_result_set)
112  {
113  global $lng;
114 
115  $tbl =& $this->__initTableGUI();
116  $tpl =& $tbl->getTemplateObject();
117 
118  // title & header columns
119  $tbl->setTitle($lng->txt("info_access_permissions"),"icon_perm.png",$lng->txt("info_access_permissions"));
120 
121  //user must be member
122  $tbl->setHeaderNames(array("",$lng->txt("operation"),$lng->txt("info_from_role")));
123  //$tbl->setHeaderVars(array("operation","granted"),$this->ctrl->getParameterArray($this->object,"",false));
124  $tbl->setHeaderVars(array("","operation","role"),"");
125  $tbl->setColumnWidth(array("1%","39%","60%"));
126 
127 
128  $this->__setTableGUIBasicData($tbl,$a_result_set);
129  $tbl->setStyle('table','std');
130  $tbl->render();
131  $this->tpl->setVariable('INFO_PERMISSIONS',$tbl->tpl->get());
132 
133  return $tbl->tpl->get();
134  }
135 
136  function __showRolesTable($a_result_set)
137  {
138  global $lng;
139 
140  $tbl =& $this->__initTableGUI();
141  $tpl =& $tbl->getTemplateObject();
142 
143  // title & header columns
144  $tbl->setTitle($lng->txt("info_available_roles"),"icon_rolf.png",$lng->txt("info_available_roles"));
145 
146  $tbl->setHeaderNames(array("",$lng->txt("role"),str_replace(" ","&nbsp;",$lng->txt("info_permission_source")),str_replace(" ","&nbsp;",$lng->txt("info_permission_origin"))));
147  $tbl->setColumnWidth(array("1%","19%","40%","40%"));
148  $this->__setTableGUIBasicData($tbl,$a_result_set);
149  $tbl->setStyle('table','std');
150  $tbl->render();
151  $this->tpl->setVariable('INFO_ROLES',$tbl->tpl->get());
152 
153  return $tbl->tpl->get();
154  }
155 
156  function __showObjectSummaryTable($a_result_set)
157  {
158  global $lng;
159 
160  $tbl =& $this->__initTableGUI();
161  $tpl =& $tbl->getTemplateObject();
162 
163  $tpl->setCurrentBlock("tbl_form_header");
164  $tpl->setVariable("FORMACTION",$this->ctrl->getFormActionByClass("ilpermissiongui","info"));
165  $tpl->parseCurrentBlock();
166 
167  $tpl->setCurrentBlock("tbl_action_row");
168 
169  $tpl->setCurrentBlock("plain_button");
170  $tpl->setVariable("PBTN_NAME","info");
171  $tpl->setVariable("PBTN_VALUE",$lng->txt("info_change_user_view"));
172  $tpl->parseCurrentBlock();
173  $tpl->setCurrentBlock("plain_buttons");
174  $tpl->parseCurrentBlock();
175 
176  $tpl->setVariable("COLUMN_COUNTS",7);
177  $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("spacer.png"));
178 
179  $tpl->setVariable("TPLPATH",$this->tpl->tplPath);
180 
181  // title & header columns
182  $tbl->setTitle($lng->txt("info_access_and_status_info"));
183 
184  //user must be member
185  $tbl->setHeaderNames(array("&nbsp;",$lng->txt("info_enter_login_or_id")));
186  //$tbl->setHeaderVars(array("operation","granted"),$this->ctrl->getParameterArray($this->object,"",false));
187  $tbl->setHeaderVars(array("",""),"");
188  $tbl->setColumnWidth(array("15%","85%"));
189 
190 
191  $this->__setTableGUIBasicData($tbl,$a_result_set);
192  //$tbl->setStyle('table','std');
193  $tbl->render();
194  $this->tpl->setVariable('INFO_SUMMARY',$tbl->tpl->get());
195 
196  return $tbl->tpl->get();
197  }
198 
199  function getHTML()
200  {
201  return $this->tpl->get();
202  }
203 
205  {
206  global $rbacreview;
207 
208  include_once ('./Services/AccessControl/classes/class.ilObjRole.php');
209  $assigned_valid_roles = array();
210 
211  foreach ($this->valid_roles as $role)
212  {
213  if (in_array($role['obj_id'],$this->user_roles))
214  {
215  if ($role["obj_id"] == SYSTEM_ROLE_ID)
216  {
217  // get all possible operation of current object
218  $ops_list = ilRbacReview::_getOperationList($this->object->getType());
219 
220  foreach ($ops_list as $ops_data)
221  {
222  $ops[] = (int) $ops_data['ops_id'];
223  }
224 
225  $role['ops'] = $ops;
226  }
227  else
228  {
229  $role['ops'] = $rbacreview->getRoleOperationsOnObject($role["obj_id"],$this->object->getRefId());
230  }
231 
232  include_once('./Services/AccessControl/classes/class.ilObjRole.php');
233  $role['translation'] = str_replace(" ","&nbsp;",ilObjRole::_getTranslation($role["title"]));
234  $assigned_valid_roles[] = $role;
235  }
236  }
237 
238  return $assigned_valid_roles;
239  }
240 
241  function getPermissionInfo()
242  {
243  global $ilAccess,$lng,$rbacreview,$ilUser,$ilObjDataCache,$objDefinition;
244 
245  // icon handlers
246  $icon_ok = "<img src=\"".ilUtil::getImagePath("icon_ok.png")."\" alt=\"".$lng->txt("info_assigned")."\" title=\"".$lng->txt("info_assigned")."\" border=\"0\" vspace=\"0\"/>";
247  $icon_not_ok = "<img src=\"".ilUtil::getImagePath("icon_not_ok.png")."\" alt=\"".$lng->txt("info_not_assigned")."\" title=\"".$lng->txt("info_not_assigned")."\" border=\"0\" vspace=\"0\"/>";
248 
249  // get all possible operation of current object
250  $ops_list = ilRbacReview::_getOperationList($this->object->getType());
251 
252  $counter = 0;
253 
254  // check permissions of user
255  foreach ($ops_list as $ops)
256  {
257  $access = $ilAccess->doRBACCheck($ops['operation'],"info",$this->object->getRefId(),$this->user->getId(),$this->object->getType());
258 
259  $result_set[$counter][] = $access ? $icon_ok : $icon_not_ok;
260 
261  if (substr($ops['operation'], 0, 7) == "create_" &&
262  $objDefinition->isPlugin(substr($ops['operation'], 7)))
263  {
264  $result_set[$counter][] = ilPlugin::lookupTxt("rep_robj", substr($ops['operation'],7),
265  #$this->object->getType()."_".$ops['operation']);
266  'rbac_'.$ops['operation']);
267  }
268  else if ($objDefinition->isPlugin($this->object->getType()))
269  {
270  $result_set[$counter][] = ilPlugin::lookupTxt("rep_robj", $this->object->getType(),
271  $this->object->getType()."_".$ops['operation']);
272  }
273  elseif(substr($ops['operation'],0,7) == 'create_')
274  {
275  $result_set[$counter][] = $lng->txt('rbac_'.$ops['operation']);
276  }
277  else
278  {
279  $result_set[$counter][] = $lng->txt($this->object->getType()."_".$ops['operation']);
280  }
281 
282  $list_role = "";
283 
284  // Check ownership
285  if($this->user->getId() == $ilObjDataCache->lookupOwner($this->object->getId()))
286  {
287  if(
288  (substr($ops['operation'],0,7) != 'create_') and
289  ($ops['operation'] != 'edit_permission') and
290  ($ops['operation'] != 'edit_leanring_progress')
291  )
292  {
293  $list_role[] = $lng->txt('info_owner_of_object');
294  }
295  }
296  // get operations on object for each assigned role to user
297  foreach ($this->assigned_valid_roles as $role)
298  {
299  if (in_array($ops['ops_id'],$role['ops']))
300  {
301  $list_role[] = $role['translation'];
302  }
303  }
304 
305  if (empty($list_role))
306  {
307  $roles_formatted = $lng->txt('none');
308  }
309  else
310  {
311  $roles_formatted = implode("<br/>",$list_role);
312  }
313 
314  $result_set[$counter][] = $roles_formatted;
315 
316  ++$counter;
317  }
318 
319  return $this->__showPermissionsTable($result_set);
320  }
321 
323  {
324  global $lng,$rbacreview,$tree;
325 
326  include_once('./Services/AccessControl/classes/class.ilObjRole.php');
327 
328  // icon handlers
329  $icon_ok = "<img src=\"".ilUtil::getImagePath("icon_ok.png")."\" alt=\"".$lng->txt("info_assigned")."\" title=\"".$lng->txt("info_assigned")."\" border=\"0\" vspace=\"0\"/>";
330  $icon_not_ok = "<img src=\"".ilUtil::getImagePath("icon_not_ok.png")."\" alt=\"".$lng->txt("info_not_assigned")."\" title=\"".$lng->txt("info_not_assigned")."\" border=\"0\" vspace=\"0\"/>";
331 
332  $path = array_reverse($tree->getPathId($this->object->getRefId()));
333 
334  include_once ('./Services/AccessControl/classes/class.ilObjRole.php');
335  $counter = 0;
336  foreach ($this->valid_roles as $role)
337  {
338  $result_set[$counter][] = in_array($role['obj_id'],$this->user_roles) ? $icon_ok : $icon_not_ok;
339  $result_set[$counter][] = str_replace(" ","&nbsp;",ilObjRole::_getTranslation($role["title"]));
340 
341  if ($role['role_type'] != "linked")
342  {
343  $result_set[$counter][] = "";
344  }
345  else
346  {
347  $rolfs = $rbacreview->getFoldersAssignedToRole($role["obj_id"]);
348 
349  // ok, try to match the next rolf in path
350  foreach ($path as $node)
351  {
352  if ($node == 1)
353  {
354  break;
355  }
356 
357  $rolf = $rbacreview->getRoleFolderOfObject($node);
358 
359  if (in_array($rolf['ref_id'],$rolfs))
360  {
361  $nodedata = $tree->getNodeData($node);
362  $result_set[$counter][] = $nodedata["title"];
363  break;
364  }
365  }
366  }
367 
368  if (in_array($role['obj_id'],$this->global_roles))
369  {
370  $result_set[$counter][] = $lng->txt("global");
371  }
372  else
373  {
374  $rolf = $rbacreview->getFoldersAssignedToRole($role["obj_id"],true);
375  $parent_node = $tree->getParentNodeData($rolf[0]);
376  $result_set[$counter][] = $parent_node["title"];
377  }
378 
379  ++$counter;
380  }
381 
382  return $this->__showRolesTable($result_set);
383  }
384 
385  function getObjectSummary()
386  {
387  global $lng,$rbacreview,$ilAccess,$ilias;
388  $infos = array();
389 
390  $input_field = "<input class=\"std\" type=\"input\" name=\"Fuserid\" value=\"".$this->user->getLogin()."\"/>";
391  $input_radio_login = "<input class=\"std\" id=\"select_type_login\" type=\"radio\" name=\"Fselect_type\" value=\"login\" checked=\"checked\" />";
392  $input_radio_id = "<input class=\"std\" id=\"select_type_id\" type=\"radio\" name=\"Fselect_type\" value=\"id\" />";
393 
394  $result_set[0][] = "&nbsp;";
395  $result_set[0][] = $input_field."&nbsp;".$input_radio_login."<label for=\"select_type_login\">".$lng->txt('login')."</label>".$input_radio_id."<label for=\"select_type_id\">".$lng->txt('id')."</label>";
396 
397  $result_set[1][] = "<b>".$lng->txt("info_view_of_user")."</b>";
398  $result_set[1][] = $this->user->getFullname()." (#".$this->user->getId().")";
399 
400  $assigned_valid_roles = array();
401 
402  foreach ($this->assigned_valid_roles as $role)
403  {
404  $assigned_valid_roles[] = $role["translation"];
405  }
406 
407  $roles_str = implode(", ",$assigned_valid_roles);
408 
409  $result_set[2][] = "<b>".$lng->txt("roles")."</b>";
410  $result_set[2][] = $roles_str;
411 
412  $result_set[4][] = "<b>".$lng->txt("status")."</b>";
413 
414  /*
415  $ilAccess->clear();
416  $ilAccess->doTreeCheck("visible","info",$this->object->getRefId(),$this->user->getId());
417  $infos = array_merge($infos,$ilAccess->getInfo());
418 
419  $ilAccess->clear();
420  $ilAccess->doPathCheck("visible","info",$this->object->getRefId(),$this->user->getId(),true);
421  $infos = array_merge($infos,$ilAccess->getInfo());
422 
423  $ilAccess->clear();
424  $ilAccess->doConditionCheck("read","info",$this->object->getRefId(),$this->user->getId(),$this->object->getId(),$this->object->getType());
425  $infos = array_merge($infos,$ilAccess->getInfo());
426  */
427 
428  $ilAccess->clear();
429  $ilAccess->checkAccessOfUser(
430  $this->user->getId(),
431  'read',
432  '',
433  $this->object->getRefId(),
434  $this->object->getType(),
435  $this->object->getId()
436  );
437 
438  $infos = array_merge($infos,$ilAccess->getInfo());
439 
440  $cmds = $this->getCommands($this->object->getType());
441 
442  foreach ($cmds as $cmd)
443  {
444  $ilAccess->clear();
445  $ilAccess->doStatusCheck($cmd['permission'],$cmd['cmd'],$this->object->getRefId(),$this->user->getId(),$this->object->getId(),$this->object->getType());
446  $infos = array_merge($infos,$ilAccess->getInfo());
447  }
448 
449  $alert = "il_ItemAlertProperty";
450  $okay = "il_ItemOkayProperty";
451 
452  if (!$infos)
453  {
454  $text = "<span class=\"".$okay."\">".$lng->txt("access")."</span><br/> ";
455  }
456  else
457  {
458  foreach ($infos as $info)
459  {
460  switch ($info['type'])
461  {
462  case IL_STATUS_MESSAGE:
463  $text .= "<span class=\"".$okay."\">".$info['text']."</span><br/> ";
464  break;
465 
466  case IL_NO_PARENT_ACCESS:
467  $obj = $ilias->obj_factory->getInstanceByRefId($info['data']);
468  $text .= "<span class=\"".$alert."\">".$info['text']." (".$lng->txt("obj_".$obj->getType())." #".$obj->getId().": ".$obj->getTitle().")</span><br/> ";
469  break;
470 
471 
472  default:
473  $text .= "<span class=\"".$alert."\">".$info['text']."</span><br/> ";
474  break;
475 
476  }
477  }
478  }
479 
480  $result_set[4][] = $text;
481 
482  return $this->__showObjectSummaryTable($result_set);
483  }
484 
485  function getCommands($a_type)
486  {
487  global $objDefinition;
488 
489  $class = $objDefinition->getClassName($a_type);
490  $location = $objDefinition->getLocation($a_type);
491  $full_class = "ilObj".$class."Access";
492  include_once($location."/class.".$full_class.".php");
493 
494  $cmds = call_user_func(array($full_class, "_getCommands"));
495 
496  array_push($cmds,array('permission' => 'visible','cmd' => 'info'));
497 
498  return $cmds;
499  }
500 } // END class.ilObjectStatus
501 
502 ?>