ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  public function __construct($a_parent_obj, $a_parent_cmd, $a_ref_id)
25  {
26  global $DIC;
27 
28  $ilCtrl = $DIC['ilCtrl'];
29  $lng = $DIC['lng'];
30  $ilAccess = $DIC['ilAccess'];
31  $lng = $DIC['lng'];
32 
33  $this->setId("rbaclog");
34  $this->ref_id = $a_ref_id;
35 
36  parent::__construct($a_parent_obj, $a_parent_cmd);
37  $this->setTitle($lng->txt("rbac_log"));
38  $this->setLimit(5);
39 
40  $this->addColumn($this->lng->txt("date"), "", "15%");
41  $this->addColumn($this->lng->txt("name"), "", "10%");
42  $this->addColumn($this->lng->txt("login"), "", "10%");
43  $this->addColumn($this->lng->txt("action"), "", "15%");
44  $this->addColumn($this->lng->txt("rbac_changes"), "", "50%");
45 
46  $this->setExternalSegmentation(true);
47  $this->setEnableHeader(true);
48  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
49  $this->setRowTemplate("tpl.rbac_log_row.html", "Services/AccessControl");
50  $this->setFilterCommand("applyLogFilter");
51  $this->setResetCommand("resetLogFilter");
52 
53  $this->action_map = array(ilRbacLog::EDIT_PERMISSIONS => $this->lng->txt("rbac_log_edit_permissions"),
54  ilRbacLog::MOVE_OBJECT => $this->lng->txt("rbac_log_move_object"),
55  ilRbacLog::LINK_OBJECT => $this->lng->txt("rbac_log_link_object"),
56  ilRbacLog::COPY_OBJECT => $this->lng->txt("rbac_log_copy_object"),
57  ilRbacLog::CREATE_OBJECT => $this->lng->txt("rbac_log_create_object"),
58  ilRbacLog::EDIT_TEMPLATE => $this->lng->txt("rbac_log_edit_template"),
59  ilRbacLog::EDIT_TEMPLATE_EXISTING => $this->lng->txt("rbac_log_edit_template_existing"),
60  ilRbacLog::CHANGE_OWNER => $this->lng->txt("rbac_log_change_owner"));
61 
62  $this->initFilter();
63 
64  $this->getItems($this->ref_id, $this->filter);
65  }
66 
67  public function initFilter()
68  {
69  $item = $this->addFilterItemByMetaType("action", ilTable2GUI::FILTER_SELECT);
70  $item->setOptions(array("" => $this->lng->txt("all")) + $this->action_map);
71  $this->filter["action"] = $item->getValue();
72 
74  $this->filter["date"] = $item->getDate();
75  }
76 
77  protected function getItems($a_ref_id, array $a_current_filter = null)
78  {
79  global $DIC;
80 
81  $rbacreview = $DIC['rbacreview'];
82 
83  $this->determineOffsetAndOrder();
84 
85  foreach ($rbacreview->getOperations() as $op) {
86  $this->operations[$op["ops_id"]] = $op["operation"];
87  }
88 
89  // special case: role folder should display root folder entries
90  if ($a_ref_id == ROLE_FOLDER_ID) {
91  $a_ref_id = ROOT_FOLDER_ID;
92  }
93 
94  $data = ilRbacLog::getLogItems($a_ref_id, $this->getLimit(), $this->getOffset(), $a_current_filter);
95 
96  $this->setData($data["set"]);
97  $this->setMaxCount($data["cnt"]);
98  }
99 
100  protected function fillRow($a_set)
101  {
102  $this->tpl->setVariable("DATE", ilDatePresentation::formatDate(new ilDateTime($a_set["created"], IL_CAL_UNIX)));
103  $name = ilObjUser::_lookupName($a_set["user_id"]);
104  $this->tpl->setVariable("LASTNAME", $name["lastname"]);
105  $this->tpl->setVariable("FIRSTNAME", $name["firstname"]);
106  $this->tpl->setVariable("LOGIN", $name["login"]);
107  $this->tpl->setVariable("ACTION", $this->action_map[$a_set["action"]]);
108 
109  if ($a_set["action"] == ilRbacLog::CHANGE_OWNER) {
110  $user = ilObjUser::_lookupFullname($a_set["data"][0]);
111  $changes = array(array("action" => $this->lng->txt("rbac_log_changed_owner"), "operation" => $user));
112  } elseif ($a_set["action"] == ilRbacLog::EDIT_TEMPLATE) {
113  $changes = $this->parseChangesTemplate($a_set["data"]);
114  } else {
115  $changes = $this->parseChangesFaPa($a_set["data"]);
116  }
117 
118  $this->tpl->setCurrentBlock("changes");
119  foreach ($changes as $change) {
120  $this->tpl->setVariable("CHANGE_ACTION", $change["action"]);
121  $this->tpl->setVariable("CHANGE_OPERATION", $change["operation"]);
122  $this->tpl->parseCurrentBlock();
123  }
124  }
125 
126  protected function parseChangesFaPa(array $raw)
127  {
128  $result = array();
129 
130  $type = ilObject::_lookupType($this->ref_id, true);
131 
132  if (isset($raw["src"])) {
133  $obj_id = ilObject::_lookupObjectId($raw["src"]);
134  if ($obj_id) {
135  include_once "./Services/Link/classes/class.ilLink.php";
136  $result[] = array("action" => $this->lng->txt("rbac_log_source_object"),
137  "operation" => "<a href=\"" . ilLink::_getLink($raw["src"]) . "\">" . ilObject::_lookupTitle($obj_id) . "</a>");
138  }
139 
140  // added only
141  foreach ($raw["ops"] as $role_id => $ops) {
142  foreach ($ops as $op) {
143  $result[] = array("action" => sprintf($this->lng->txt("rbac_log_operation_add"), ilObject::_lookupTitle($role_id)),
144  "operation" => $this->getOPCaption($type, $op));
145  }
146  }
147  } elseif (isset($raw["ops"])) {
148  foreach ($raw["ops"] as $role_id => $actions) {
149  foreach ($actions as $action => $ops) {
150  foreach ((array) $ops as $op) {
151  $result[] = array("action" => sprintf($this->lng->txt("rbac_log_operation_" . $action), ilObject::_lookupTitle($role_id)),
152  "operation" => $this->getOPCaption($type, $op));
153  }
154  }
155  }
156  }
157 
158  if (isset($raw["inht"])) {
159  foreach ($raw["inht"] as $action => $role_ids) {
160  foreach ((array) $role_ids as $role_id) {
161  $result[] = array("action" => sprintf($this->lng->txt("rbac_log_inheritance_" . $action), ilObject::_lookupTitle($role_id)));
162  }
163  }
164  }
165 
166  return $result;
167  }
168 
169  protected function parseChangesTemplate(array $raw)
170  {
171  $result = array();
172  foreach ($raw as $type => $actions) {
173  foreach ($actions as $action => $ops) {
174  foreach ($ops as $op) {
175  $result[] = array("action" => sprintf($this->lng->txt("rbac_log_operation_" . $action), $this->lng->txt("obj_" . $type)),
176  "operation" => $this->getOPCaption($type, $op));
177  }
178  }
179  }
180  return $result;
181  }
182 
183  // #10946
184  protected function getOPCaption($a_type, $a_op)
185  {
186  // #11717
187  if (is_array($a_op)) {
188  $res = array();
189  foreach ($a_op as $op) {
190  $res[] = $this->getOPCaption($a_type, $op);
191  }
192  return implode(", ", $res);
193  }
194 
195  if (is_numeric($a_op) && isset($this->operations[$a_op])) {
196  $op_id = $this->operations[$a_op];
197  if (substr($op_id, 0, 7) != "create_") {
198  $perm = $this->getTranslationFromPlugin($a_type, $op_id);
199 
200  if ($this->notTranslated($perm, $op_id)) {
201  if ($this->lng->exists($a_type . '_' . $op_id . '_short')) {
202  $perm = $this->lng->txt($a_type . '_' . $op_id . '_short');
203  } else {
204  $perm = $this->lng->txt($op_id);
205  }
206  }
207 
208  return $perm;
209  } else {
210  $type = substr($op_id, 7, strlen($op_id));
211  $perm = $this->getTranslationFromPlugin($type, $op_id);
212 
213  if ($this->notTranslated($perm, $op_id)) {
214  $perm = $this->lng->txt("rbac_" . $op_id);
215  }
216 
217  return $perm;
218  }
219  }
220  }
221 
229  protected function getTranslationFromPlugin($type, $op_id)
230  {
231  global $objDefinition;
232 
233  if ($objDefinition->isPlugin($type)) {
234  return ilObjectPlugin::lookupTxtById($type, $op_id);
235  }
236 
237  return null;
238  }
239 
247  protected function notTranslated($perm, $op_id)
248  {
249  return is_null($perm) || (strpos($perm, $op_id) !== false);
250  }
251 }
static _lookupName($a_user_id)
lookup user name
static lookupTxtById($plugin_id, $lang_var)
$result
$action
$type
global $DIC
Definition: saml.php:7
getItems($a_ref_id, array $a_current_filter=null)
static _lookupFullname($a_user_id)
Lookup Full Name.
setExternalSegmentation($a_val)
Set external segmentation.
const CHANGE_OWNER
addFilterItemByMetaType($id, $type=self::FILTER_TEXT, $a_optional=false, $caption=null)
Add filter by standard type.
static _lookupTitle($a_id)
lookup object title
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
setId($a_val)
Set id.
static _lookupObjectId($a_ref_id)
lookup object id
global $ilCtrl
Definition: ilias.php:18
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
const EDIT_PERMISSIONS
$a_type
Definition: workflow.php:92
const CREATE_OBJECT
Class ilTable2GUI.
setResetCommand($a_val, $a_caption=null)
Set reset filter command.
foreach($_POST as $key=> $value) $res
getOffset()
Get offset.
Date and time handling
const COPY_OBJECT
const LINK_OBJECT
$user
Definition: migrateto20.php:57
setRowTemplate($a_template, $a_template_dir="")
Set row template.
static _lookupType($a_id, $a_reference=false)
lookup object type
static getLogItems($a_ref_id, $a_limit, $a_offset, array $a_filter=null)
Class ilRbacLogTableGUI.
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
const EDIT_TEMPLATE_EXISTING
notTranslated($perm, $op_id)
Check the op is translated correctly.
const EDIT_TEMPLATE
setEnableHeader($a_enableheader)
Set Enable Header.
const MOVE_OBJECT
getLimit()
Get limit.
setMaxCount($a_max_count)
set max.
getTranslationFromPlugin($type, $op_id)
Check the type for plugin and get the translation for op_id.
setLimit($a_limit=0, $a_default_limit=0)
__construct($a_parent_obj, $a_parent_cmd, $a_ref_id)
setFilterCommand($a_val, $a_caption=null)
Set filter command.