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