27 include_once
"Services/PrivacySecurity/classes/class.ilPrivacySettings.php";
29 if ($settings->enabledRbacLog()) {
35 public static function gatherFaPa($a_ref_id,
array $a_role_ids, $a_add_action =
false)
45 foreach ($a_role_ids as $role_id) {
46 if ($role_id != SYSTEM_ROLE_ID) {
48 $result[
"ops"][$role_id][
"add"] = $rbacreview->getRoleOperationsOnObject($role_id, $a_ref_id);
50 $result[
"ops"][$role_id] = $rbacreview->getRoleOperationsOnObject($role_id, $a_ref_id);
56 if ($a_ref_id && $a_ref_id != ROLE_FOLDER_ID) {
58 $result[
"inht"][
"add"] = $rbacreview->getRolesOfRoleFolder($a_ref_id);
60 $result[
"inht"] = $rbacreview->getRolesOfRoleFolder($a_ref_id);
72 foreach ((
array) $a_old[
"ops"] as $role_id => $ops) {
73 $diff = array_diff($ops, $a_new[
"ops"][$role_id]);
75 $result[
"ops"][$role_id][
"rmv"] = array_values($diff);
77 $diff = array_diff($a_new[
"ops"][$role_id], $ops);
79 $result[
"ops"][$role_id][
"add"] = array_values($diff);
83 if (isset($a_old[
"inht"]) || isset($a_new[
"inht"])) {
84 if (isset($a_old[
"inht"]) && !isset($a_new[
"inht"])) {
85 $result[
"inht"][
"rmv"] = $a_old[
"inht"];
86 } elseif (!isset($a_old[
"inht"]) && isset($a_new[
"inht"])) {
87 $result[
"inht"][
"add"] = $a_new[
"inht"];
89 $diff = array_diff($a_old[
"inht"], $a_new[
"inht"]);
91 $result[
"inht"][
"rmv"] = array_values($diff);
93 $diff = array_diff($a_new[
"inht"], $a_old[
"inht"]);
95 $result[
"inht"][
"add"] = array_values($diff);
107 return $rbacreview->getAllOperationsOfRole($a_role_id, $a_role_ref_id);
113 $types = array_unique(array_merge(array_keys($a_old), array_keys($a_new)));
114 foreach ($types as
$type) {
115 if (!isset($a_old[$type])) {
117 } elseif (!isset($a_new[$type])) {
120 $diff = array_diff($a_old[$type], $a_new[$type]);
124 $diff = array_diff($a_new[$type], $a_old[$type]);
133 public static function add($a_action, $a_ref_id,
array $a_diff, $a_source_ref_id =
false)
137 if (self::isValidAction($a_action) &&
sizeof($a_diff)) {
138 if ($a_source_ref_id) {
139 $a_diff[
"src"] = $a_source_ref_id;
141 $id = $ilDB->nextId(
'rbac_log');
143 $ilDB->query(
"INSERT INTO rbac_log (log_id, user_id, created, ref_id, action, data)" .
144 " VALUES (" . $ilDB->quote(
$id,
"integer") .
"," . $ilDB->quote($ilUser->getId(),
"integer") .
145 "," . $ilDB->quote(
time(),
"integer") .
146 "," . $ilDB->quote($a_ref_id,
"integer") .
"," . $ilDB->quote($a_action,
"integer") .
147 "," . $ilDB->quote(serialize($a_diff),
"text") .
")");
155 if (in_array($a_action,
array(self::EDIT_PERMISSIONS, self::MOVE_OBJECT, self::LINK_OBJECT,
156 self::COPY_OBJECT, self::CREATE_OBJECT, self::EDIT_TEMPLATE, self::EDIT_TEMPLATE_EXISTING,
157 self::CHANGE_OWNER))) {
165 global
$ilDB, $rbacreview;
169 if ($a_filter[
"action"]) {
170 $where[] =
"action = " . $ilDB->quote($a_filter[
"action"],
"integer");
172 if ($a_filter[
"date"][
"from"]) {
175 $where[] =
"created >= " . $ilDB->quote(
$from,
"integer");
177 if ($a_filter[
"date"][
"to"]) {
179 $to = strtotime(
"23:59:59", $to);
180 $where[] =
"created <= " . $ilDB->quote($to,
"integer");
183 if (count($where) > 0) {
184 $where = array_merge([
' AND '], [implode(
' AND ', $where)]);
188 $set = $ilDB->query(
"SELECT COUNT(*) FROM rbac_log WHERE ref_id = " . $ilDB->quote($a_ref_id,
"integer") . implode(
'', $where));
189 $count = array_pop($ilDB->fetchAssoc($set));
191 $ilDB->setLimit($a_limit, $a_offset);
192 $set = $ilDB->query(
"SELECT * FROM rbac_log WHERE ref_id = " . $ilDB->quote($a_ref_id,
"integer") .
193 implode(
'', $where) .
" ORDER BY created DESC");
195 while (
$row = $ilDB->fetchAssoc($set)) {
196 $row[
"data"] = unserialize(
$row[
"data"]);
202 public static function delete($a_ref_id)
206 $ilDB->query(
"DELETE FROM rbac_log WHERE ref_id = " . $ilDB->quote($a_ref_id,
"integer"));
208 self::garbageCollection();
215 include_once
"Services/PrivacySecurity/classes/class.ilPrivacySettings.php";
217 $max = $settings->getRbacLogAge();
219 $ilDB->query(
"DELETE FROM rbac_log WHERE created < " . $ilDB->quote(strtotime(
"-" . $max .
"months"),
"integer"));
static garbageCollection()
if(!array_key_exists('StateId', $_REQUEST)) $id
static gatherFaPa($a_ref_id, array $a_role_ids, $a_add_action=false)
static diffFaPa(array $a_old, array $a_new)
Create styles array
The data for the language used.
static getLogItems($a_ref_id, $a_limit, $a_offset, array $a_filter=null)
static gatherTemplate($a_role_ref_id, $a_role_id)
static add($a_action, $a_ref_id, array $a_diff, $a_source_ref_id=false)
static diffTemplate(array $a_old, array $a_new)
const EDIT_TEMPLATE_EXISTING
static _getInstance()
Get instance of ilPrivacySettings.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static isValidAction($a_action)
class ilRbacLog Log changes in Rbac-related settings