ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilRbacLogTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/Table/classes/class.ilTable2GUI.php';
5 include_once "Services/AccessControl/classes/class.ilRbacLog.php";
6 
19 {
20  protected $operations = array();
21  protected $filter = array();
22  protected $action_map = array();
23 
24  function __construct($a_parent_obj, $a_parent_cmd, $a_ref_id)
25  {
26  global $ilCtrl, $lng, $ilAccess, $lng;
27 
28  $this->setId("rbaclog");
29  $this->ref_id = $a_ref_id;
30 
31  parent::__construct($a_parent_obj, $a_parent_cmd);
32  $this->setTitle($lng->txt("rbac_log"));
33  $this->setLimit(5);
34 
35  $this->addColumn($this->lng->txt("date"), "", "15%");
36  $this->addColumn($this->lng->txt("name"), "", "10%");
37  $this->addColumn($this->lng->txt("login"), "", "10%");
38  $this->addColumn($this->lng->txt("action"), "", "15%");
39  $this->addColumn($this->lng->txt("rbac_changes"), "", "50%");
40 
41  $this->setExternalSegmentation(true);
42  $this->setEnableHeader(true);
43  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
44  $this->setRowTemplate("tpl.rbac_log_row.html", "Services/AccessControl");
45  $this->setFilterCommand("applyLogFilter");
46  $this->setResetCommand("resetLogFilter");
47 
48  $this->action_map = array(ilRbacLog::EDIT_PERMISSIONS => $this->lng->txt("rbac_log_edit_permissions"),
49  ilRbacLog::MOVE_OBJECT => $this->lng->txt("rbac_log_move_object"),
50  ilRbacLog::LINK_OBJECT => $this->lng->txt("rbac_log_link_object"),
51  ilRbacLog::COPY_OBJECT => $this->lng->txt("rbac_log_copy_object"),
52  ilRbacLog::CREATE_OBJECT => $this->lng->txt("rbac_log_create_object"),
53  ilRbacLog::EDIT_TEMPLATE => $this->lng->txt("rbac_log_edit_template"),
54  ilRbacLog::EDIT_TEMPLATE_EXISTING=> $this->lng->txt("rbac_log_edit_template_existing"),
55  ilRbacLog::CHANGE_OWNER=> $this->lng->txt("rbac_log_change_owner"));
56 
57  $this->initFilter();
58 
59  $this->getItems($this->ref_id, $this->filter);
60  }
61 
62  public function initFilter()
63  {
64  $item = $this->addFilterItemByMetaType("action", ilTable2GUI::FILTER_SELECT);
65  $item->setOptions(array("" => $this->lng->txt("all"))+$this->action_map);
66  $this->filter["action"] = $item->getValue();
67 
69  $this->filter["date"] = $item->getDate();
70  }
71 
72  protected function getItems($a_ref_id, array $a_current_filter = NULL)
73  {
74  global $rbacreview;
75 
76  $this->determineOffsetAndOrder();
77 
78  foreach($rbacreview->getOperations() as $op)
79  {
80  $this->operations[$op["ops_id"]] = $op["operation"];
81  }
82 
83  // special case: role folder should display root folder entries
84  if($a_ref_id == ROLE_FOLDER_ID)
85  {
86  $a_ref_id = ROOT_FOLDER_ID;
87  }
88 
89  $data = ilRbacLog::getLogItems($a_ref_id, $this->getLimit(), $this->getOffset(), $a_current_filter);
90 
91  $this->setData($data["set"]);
92  $this->setMaxCount($data["cnt"]);
93  }
94 
95  protected function fillRow($a_set)
96  {
97  $this->tpl->setVariable("DATE", ilDatePresentation::formatDate(new ilDateTime($a_set["created"], IL_CAL_UNIX)));
98  $name = ilObjUser::_lookupName($a_set["user_id"]);
99  $this->tpl->setVariable("LASTNAME", $name["lastname"]);
100  $this->tpl->setVariable("FIRSTNAME",$name["firstname"]);
101  $this->tpl->setVariable("LOGIN", $name["login"]);
102  $this->tpl->setVariable("ACTION", $this->action_map[$a_set["action"]]);
103 
104  if($a_set["action"] == ilRbacLog::CHANGE_OWNER)
105  {
106  $user = ilObjUser::_lookupFullname($a_set["data"][0]);
107  $changes = array(array("action"=>$this->lng->txt("rbac_log_changed_owner"), "operation"=>$user));
108  }
109  else if($a_set["action"] == ilRbacLog::EDIT_TEMPLATE)
110  {
111  $changes = $this->parseChangesTemplate($a_set["data"]);
112  }
113  else
114  {
115  $changes = $this->parseChangesFaPa($a_set["data"]);
116  }
117 
118  $this->tpl->setCurrentBlock("changes");
119  foreach($changes as $change)
120  {
121  $this->tpl->setVariable("CHANGE_ACTION", $change["action"]);
122  $this->tpl->setVariable("CHANGE_OPERATION", $change["operation"]);
123  $this->tpl->parseCurrentBlock();
124  }
125  }
126 
127  protected function parseChangesFaPa(array $raw)
128  {
129  $result = array();
130 
131  $type = ilObject::_lookupType($this->ref_id, true);
132 
133  if(isset($raw["src"]))
134  {
135  $obj_id = ilObject::_lookupObjectId($raw["src"]);
136  if($obj_id)
137  {
138  include_once "./Services/Link/classes/class.ilLink.php";
139  $result[] = array("action"=>$this->lng->txt("rbac_log_source_object"),
140  "operation"=>"<a href=\"".ilLink::_getLink($raw["src"])."\">".ilObject::_lookupTitle($obj_id)."</a>");
141  }
142 
143  // added only
144  foreach($raw["ops"] as $role_id => $ops)
145  {
146  foreach($ops as $op)
147  {
148  $result[] = array("action"=>sprintf($this->lng->txt("rbac_log_operation_add"), ilObject::_lookupTitle($role_id)),
149  "operation"=>$this->getOPCaption($type, $op));
150  }
151  }
152  }
153  else if(isset($raw["ops"]))
154  {
155  foreach($raw["ops"] as $role_id => $actions)
156  {
157  foreach($actions as $action => $ops)
158  {
159  foreach((array) $ops as $op)
160  {
161  $result[] = array("action"=>sprintf($this->lng->txt("rbac_log_operation_".$action), ilObject::_lookupTitle($role_id)),
162  "operation"=>$this->getOPCaption($type, $op));
163  }
164  }
165  }
166  }
167 
168  if(isset($raw["inht"]))
169  {
170  foreach($raw["inht"] as $action => $role_ids)
171  {
172  foreach((array) $role_ids as $role_id)
173  {
174  $result[] = array("action"=>sprintf($this->lng->txt("rbac_log_inheritance_".$action), ilObject::_lookupTitle($role_id)));
175  }
176  }
177  }
178 
179  return $result;
180  }
181 
182  protected function parseChangesTemplate(array $raw)
183  {
184  $result = array();
185  foreach($raw as $type => $actions)
186  {
187  foreach($actions as $action => $ops)
188  {
189  foreach($ops as $op)
190  {
191  $result[] = array("action"=>sprintf($this->lng->txt("rbac_log_operation_".$action), $this->lng->txt("obj_".$type)),
192  "operation"=>$this->getOPCaption($type, $op));
193  }
194  }
195  }
196  return $result;
197  }
198 
199  // #10946
200  protected function getOPCaption($a_type, $a_op)
201  {
202  // #11717
203  if(is_array($a_op))
204  {
205  $res = array();
206  foreach($a_op as $op)
207  {
208  $res[] = $this->getOPCaption($a_type, $op);
209  }
210  return implode(", ", $res);
211  }
212 
213  if(is_numeric($a_op) && isset($this->operations[$a_op]))
214  {
215  $op_id = $this->operations[$a_op];
216  if(substr($op_id, 0, 7) != "create_")
217  {
218  return $this->lng->txt($a_type."_".$this->operations[$a_op]);
219  }
220  else
221  {
222  return $this->lng->txt("rbac_".$this->operations[$a_op]);
223  }
224  }
225  }
226 }
227 
228 ?>