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