27 include_once
"Services/PrivacySecurity/classes/class.ilPrivacySettings.php";
29 if($settings->enabledRbacLog())
36 static public function gatherFaPa($a_ref_id, array $a_role_ids)
43 foreach($a_role_ids as $role_id)
45 if ($role_id != SYSTEM_ROLE_ID)
47 $result[
"ops"][$role_id] = $rbacreview->getRoleOperationsOnObject($role_id, $a_ref_id);
52 $rolf_data = $rbacreview->getRoleFolderOfObject($a_ref_id);
53 $rolf_id = $rolf_data[
"child"];
54 if($rolf_id && $rolf_id != ROLE_FOLDER_ID)
56 $result[
"inht"] = $rbacreview->getRolesOfRoleFolder($rolf_id);
62 static public function diffFaPa(array $a_old, array $a_new)
67 foreach((array) $a_old[
"ops"] as $role_id => $ops)
69 $diff = array_diff($ops, $a_new[
"ops"][$role_id]);
72 $result[
"ops"][$role_id][
"rmv"] = array_values($diff);
74 $diff = array_diff($a_new[
"ops"][$role_id], $ops);
77 $result[
"ops"][$role_id][
"add"] = array_values($diff);
81 if(isset($a_old[
"int"]) || isset($a_new[
"inht"]))
83 if(isset($a_old[
"inht"]) && !isset($a_new[
"inht"]))
85 $result[
"inht"][
"rmv"] = $a_old[
"inht"];
87 else if(!isset($a_old[
"inht"]) && isset($a_new[
"inht"]))
89 $result[
"inht"][
"add"] = $a_new[
"inht"];
93 $diff = array_diff($a_old[
"inht"], $a_new[
"inht"]);
96 $result[
"inht"][
"rmv"] = array_values($diff);
98 $diff = array_diff($a_new[
"inht"], $a_old[
"inht"]);
101 $result[
"inht"][
"add"] = array_values($diff);
113 return $rbacreview->getAllOperationsOfRole($a_role_id, $a_role_folder_ref_id);
119 $types = array_unique(array_merge(array_keys($a_old), array_keys($a_new)));
120 foreach($types as $type)
122 if(!isset($a_old[$type]))
124 $result[$type][
"add"] = $a_new[$type];
126 else if(!isset($a_new[$type]))
128 $result[$type][
"rmv"] = $a_old[$type];
132 $diff = array_diff($a_old[$type], $a_new[$type]);
135 $result[$type][
"rmv"] = array_values($diff);
137 $diff = array_diff($a_new[$type], $a_old[$type]);
140 $result[$type][
"add"] = array_values($diff);
147 static public function add($a_action, $a_ref_id, array $a_diff, $a_source_ref_id =
false)
149 global $ilUser,
$ilDB;
151 if(self::isValidAction($a_action) &&
sizeof($a_diff))
155 $a_diff[
"src"] = $a_source_ref_id;
158 $ilDB->query(
"INSERT INTO rbac_log (user_id, created, ref_id, action, data)".
159 " VALUES (".$ilDB->quote($ilUser->getId(),
"integer").
",".$ilDB->quote(time(),
"integer").
160 ",".$ilDB->quote($a_ref_id,
"integer").
",".$ilDB->quote($a_action,
"integer").
161 ",".$ilDB->quote(serialize($a_diff),
"text").
")");
169 if(in_array($a_action, array(self::EDIT_PERMISSIONS, self::MOVE_OBJECT, self::LINK_OBJECT,
170 self::COPY_OBJECT, self::CREATE_OBJECT, self::EDIT_TEMPLATE, self::EDIT_TEMPLATE_EXISTING,
171 self::CHANGE_OWNER)))
178 static public function getLogItems($a_ref_id, $a_limit, $a_offset, array $a_filter = NULL)
180 global
$ilDB, $rbacreview;
185 if($a_filter[
"action"])
187 $where[] =
"action = ".$ilDB->quote($a_filter[
"action"],
"integer");
189 if($a_filter[
"date"][
"from"])
191 $from = $a_filter[
"date"][
"from"]->get(
IL_CAL_UNIX);
192 $from = strtotime(
"00:00:00", $from);
193 $where[] =
"created >= ".$ilDB->quote($from,
"integer");
195 if($a_filter[
"date"][
"to"])
198 $to = strtotime(
"23:59:59", $to);
199 $where[] =
"created <= ".$ilDB->quote($to,
"integer");
203 $where =
" AND ".implode(
" AND ", $where);
207 $set = $ilDB->query(
"SELECT COUNT(*) FROM rbac_log WHERE ref_id = ".$ilDB->quote($a_ref_id,
"integer").$where);
208 $count = array_pop($ilDB->fetchAssoc($set));
210 $ilDB->setLimit($a_limit, $a_offset);
211 $set = $ilDB->query(
"SELECT * FROM rbac_log WHERE ref_id = ".$ilDB->quote($a_ref_id,
"integer").
212 $where.
" ORDER BY created DESC");
214 while(
$row = $ilDB->fetchAssoc($set))
216 $row[
"data"] = unserialize(
$row[
"data"]);
219 return array(
"cnt"=>$count,
"set"=>
$result);
222 static function delete($a_ref_id)
226 $ilDB->query(
"DELETE FROM rbac_log WHERE ref_id = ".$ilDB->quote($a_ref_id,
"integer"));
235 include_once
"Services/PrivacySecurity/classes/class.ilPrivacySettings.php";
237 $max = $settings->getRbacLogAge();
239 $ilDB->query(
"DELETE FROM rbac_log WHERE created < ".$ilDB->quote(strtotime(
"-".$max.
"months"),
"integer"));