58 (isset($ilDB)) ? $this->ilDB =& $ilDB : $this->ilDB =& $ilias->db;
63 $ilErr->setErrorHandling(PEAR_ERROR_CALLBACK,array($ilErr,
'errorHandler'));
94 $ilBench->start(
"RBAC",
"system_checkAccess");
98 $ilBench->stop(
"RBAC",
"system_checkAccess");
105 global $ilUser, $rbacreview,$ilObjDataCache,$ilDB;
108 $cacheKey = $a_user_id.
':'.$a_operations.
':'.$a_ref_id.
':'.$a_type;
111 if (! is_array(self::$_checkAccessOfUserCache)) {
112 self::$_checkAccessOfUserCache = array();
116 if (array_key_exists($cacheKey, self::$_checkAccessOfUserCache)) {
117 return self::$_checkAccessOfUserCache[$cacheKey];
131 if (count(self::$_checkAccessOfUserCache) < 1000) {
132 self::$_checkAccessOfUserCache[$cacheKey] =
true;
143 if (in_array(SYSTEM_ROLE_ID, $roles))
147 if (count(self::$_checkAccessOfUserCache) < 1000) {
148 self::$_checkAccessOfUserCache[$cacheKey] =
true;
153 if (!isset($a_operations) or !isset($a_ref_id))
155 $this->ilErr->raiseError(get_class($this).
"::checkAccess(): Missing parameter! ".
156 "ref_id: ".$a_ref_id.
" operations: ".$a_operations,$this->ilErr->WARNING);
159 if (!is_string($a_operations))
161 $this->ilErr->raiseError(get_class($this).
"::checkAccess(): Wrong datatype for operations!",$this->ilErr->WARNING);
165 $paCacheKey = $a_user_id.
':'.$a_ref_id;
166 if (! is_array(self::$_paCache)) {
167 self::$_paCache = array();
170 if (array_key_exists($paCacheKey, self::$_paCache)) {
172 $ops = self::$_paCache[$paCacheKey];
175 $q =
"SELECT * FROM rbac_pa ".
176 "WHERE ref_id = ".$ilDB->quote($a_ref_id).
" ";
177 $r = $this->ilDB->query($q);
183 if (in_array($row->rol_id, $roles)) {
184 $ops = array_merge($ops,unserialize(stripslashes($row->ops_id)));
189 if (count(self::$_paCache) < 1000) {
190 self::$_paCache[$paCacheKey] = $ops;
194 $operations = explode(
",",$a_operations);
195 foreach ($operations as $operation)
197 if ($operation ==
"create")
201 $this->ilErr->raiseError(get_class($this).
"::CheckAccess(): Expect a type definition for checking a 'create' permission",
202 $this->ilErr->WARNING);
212 if (! in_array($ops_id,$ops)) {
215 if (count(self::$_checkAccessOfUserCache) < 1000) {
216 self::$_checkAccessOfUserCache[$cacheKey] =
false;
225 if (count(self::$_checkAccessOfUserCache) < 1000) {
226 self::$_checkAccessOfUserCache[$cacheKey] =
true;
245 $q =
"SELECT ops_id FROM rbac_operations ".
246 "WHERE operation = ".$ilDB->quote($a_operation).
" ";
248 $r = $this->ilDB->query($q);
252 $ops_id = $row->ops_id;
255 $q =
"SELECT * FROM rbac_pa ".
256 "WHERE rol_id = ".$ilDB->quote($a_rol_id).
" ".
257 "AND ref_id = ".$ilDB->quote($a_ref_id).
" ";
259 $r = $this->ilDB->query($q);
263 $ops = array_merge($ops,unserialize(stripslashes($row->ops_id)));
265 return in_array($ops_id,$ops);
270 global $ilObjDataCache;
272 if($a_user_id != $ilObjDataCache->lookupOwner($ilObjDataCache->lookupObjId($a_ref_id)))
274 return $a_operations;
277 foreach(explode(
",",$a_operations) as $operation)
279 if($operation !=
'cat_administrate_users' and $operation !=
'edit_permission' and !preg_match(
'/^create/',$operation))
283 if(!strlen($new_ops))
285 $new_ops = $operation;
289 $new_ops .= (
','.$operation);
305 global $ilUser,$rbacreview;
307 if(isset(self::$user_role_cache[$a_usr_id]) and is_array(self::$user_role_cache))
309 return self::$user_role_cache[$a_usr_id];
311 return self::$user_role_cache[$a_usr_id] = $rbacreview->assignedRoles($a_usr_id);