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