29 (isset($ilDB)) ? $this->
ilDB =& $ilDB : $this->
ilDB =& $ilias->db;
53 if (!isset($a_usr_id))
55 $message = get_class($this).
"::removeUser(): No usr_id given!";
56 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
59 $query =
"DELETE FROM rbac_ua WHERE usr_id = ".$ilDB->quote($a_usr_id,
'integer');
76 if (!isset($a_rol_id) or !isset($a_ref_id))
78 $message = get_class($this).
"::deleteRole(): Missing parameter! role_id: ".$a_rol_id.
" ref_id of role folder: ".$a_ref_id;
79 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
83 if ($a_rol_id == SYSTEM_ROLE_ID)
85 $this->ilErr->raiseError($lng->txt(
"msg_sysrole_not_deletable"),$this->ilErr->MESSAGE);
88 include_once(
'Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
90 $mapping->deleteRole($a_rol_id);
97 $query =
"DELETE FROM rbac_ua ".
98 "WHERE rol_id = ".$ilDB->quote($a_rol_id,
'integer');
102 $query =
"DELETE FROM rbac_pa ".
103 "WHERE rol_id = ".$ilDB->quote($a_rol_id,
'integer').
" ";
122 if (!isset($a_obj_id))
124 $message = get_class($this).
"::deleteTemplate(): No obj_id given!";
125 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
128 $query =
'DELETE FROM rbac_templates '.
129 'WHERE rol_id = '.$ilDB->quote($a_obj_id,
'integer');
132 $query =
'DELETE FROM rbac_fa '.
133 'WHERE rol_id = '.$ilDB->quote($a_obj_id,
'integer');
150 if (!isset($a_rol_id))
152 $message = get_class($this).
"::deleteLocalRole(): Missing parameter! role_id: '".$a_rol_id.
"'";
153 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
157 if ($a_rol_id == SYSTEM_ROLE_ID)
164 $clause =
'AND parent = '.$ilDB->quote($a_ref_id,
'integer').
' ';
167 $query =
'DELETE FROM rbac_fa '.
168 'WHERE rol_id = '.$ilDB->quote($a_rol_id,
'integer').
' '.
172 $query =
'DELETE FROM rbac_templates '.
173 'WHERE rol_id = '.$ilDB->quote($a_rol_id,
'integer').
' '.
195 $limit_query =
'SELECT COUNT(*) num FROM rbac_ua '.
196 'WHERE '.$GLOBALS[
'ilDB']->in(
'rol_id',(array) $a_limited_roles,FALSE,
'integer');
199 if(
$row->num >= $a_limit)
205 $query =
"INSERT INTO rbac_ua (usr_id, rol_id) ".
207 $ilDB->quote($a_usr_id,
'integer').
",".$ilDB->quote($a_role_id,
'integer').
212 $GLOBALS[
'rbacreview']->setAssignedCacheEntry($a_role_id,$a_usr_id,TRUE);
216 include_once(
'Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
218 $mapping->assign($a_role_id,$a_usr_id);
229 include_once
'Services/AccessControl/classes/class.ilRoleDesktopItem.php';
231 foreach($role_desk_item_obj->getAll() as $item_data)
233 include_once
'./Services/User/classes/class.ilObjUser.php';
250 global
$ilDB,$rbacreview;
252 if (!isset($a_rol_id) or !isset($a_usr_id))
254 $message = get_class($this).
"::assignUser(): Missing parameter! role_id: ".$a_rol_id.
" usr_id: ".$a_usr_id;
255 #$this->ilErr->raiseError($message,$this->ilErr->WARNING);
259 $alreadyAssigned = $rbacreview->isAssigned($a_usr_id,$a_rol_id);
262 if (!$alreadyAssigned)
264 $query =
"INSERT INTO rbac_ua (usr_id, rol_id) ".
265 "VALUES (".$ilDB->quote($a_usr_id,
'integer').
",".$ilDB->quote($a_rol_id,
'integer').
")";
270 $rbacreview->setAssignedCacheEntry($a_rol_id,$a_usr_id,
true);
273 include_once(
'Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
275 $mapping->assign($a_rol_id,$a_usr_id);
289 global
$ilDB, $rbacreview;
291 if (!isset($a_rol_id) or !isset($a_usr_id))
293 $message = get_class($this).
"::deassignUser(): Missing parameter! role_id: ".$a_rol_id.
" usr_id: ".$a_usr_id;
294 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
297 $query =
"DELETE FROM rbac_ua ".
298 "WHERE usr_id = ".$ilDB->quote($a_usr_id,
'integer').
" ".
299 "AND rol_id = ".$ilDB->quote($a_rol_id,
'integer').
" ";
302 $rbacreview->setAssignedCacheEntry($a_rol_id,$a_usr_id,
false);
304 include_once(
'Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
306 $mapping->deassign($a_rol_id,$a_usr_id);
323 if (!isset($a_rol_id) or !isset($a_ops) or !isset($a_ref_id))
325 $this->ilErr->raiseError(get_class($this).
"::grantPermission(): Missing parameter! ".
326 "role_id: ".$a_rol_id.
" ref_id: ".$a_ref_id.
" operations: ",$this->ilErr->WARNING);
329 if (!is_array($a_ops))
331 $this->ilErr->raiseError(get_class($this).
"::grantPermission(): Wrong datatype for operations!",
332 $this->ilErr->WARNING);
342 if ($a_rol_id == SYSTEM_ROLE_ID)
348 foreach ($a_ops as $key => $operation)
350 $a_ops[$key] = (int) $operation;
354 $ops_ids = serialize($a_ops);
356 $query =
'DELETE FROM rbac_pa '.
357 'WHERE rol_id = %s '.
359 $res = $ilDB->queryF(
$query,array(
'integer',
'integer'),
360 array($a_rol_id,$a_ref_id));
367 $query =
"INSERT INTO rbac_pa (rol_id,ops_id,ref_id) ".
369 "(".$ilDB->quote($a_rol_id,
'integer').
",".$ilDB->quote($ops_ids,
'text').
",".$ilDB->quote($a_ref_id,
'integer').
")";
388 if (!isset($a_ref_id))
391 $message = get_class($this).
"::revokePermission(): Missing parameter! ref_id: ".$a_ref_id;
392 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
394 #$log->write("ilRBACadmin::revokePermission(), 0");
397 if ($a_keep_protected !=
true)
400 if ($a_rol_id == SYSTEM_ROLE_ID)
407 $and1 =
" AND rol_id = ".$ilDB->quote($a_rol_id,
'integer').
" ";
414 $query =
"DELETE FROM rbac_pa ".
415 "WHERE ref_id = ".$ilDB->quote($a_ref_id,
'integer').
426 $roles_in_scope = $rbacreview->getParentRoleIds($a_ref_id);
430 #$log->write("ilRBACadmin::revokePermission(), 1");
434 foreach ($roles_in_scope as $role)
436 if ($role[
'protected'] ==
true)
441 $role_ids[] = $role[
'obj_id'];
450 $query =
'DELETE FROM rbac_pa '.
451 'WHERE '.$ilDB->in(
'rol_id',$role_ids,
false,
'integer').
' '.
452 'AND ref_id = '.$ilDB->quote($a_ref_id,
'integer');
457 #$log->write("ilRBACadmin::revokePermission(), 2");
459 if ($a_rol_id == SYSTEM_ROLE_ID)
465 if ($roles_in_scope[$a_rol_id][
'protected'] ==
true)
470 $query =
"DELETE FROM rbac_pa ".
471 "WHERE ref_id = ".$ilDB->quote($a_ref_id,
'integer').
" ".
472 "AND rol_id = ".$ilDB->quote($a_rol_id,
'integer').
" ";
489 $query =
'DELETE FROM rbac_pa '.
491 '( '.$GLOBALS[
'tree']->getSubTreeQuery($a_ref_id,array(
'child')).
' ) '.
492 'AND rol_id = '.$ilDB->quote($a_role_id,
'integer');
494 $ilDB->manipulate(
$query);
508 $query =
'DELETE FROM rbac_templates '.
509 'WHERE parent IN ( '.
510 $GLOBALS[
'tree']->getSubTreeQuery($a_ref_id, array(
'child')).
' ) '.
511 'AND rol_id = '.$ilDB->quote($a_rol_id,
'integer');
513 $ilDB->manipulate(
$query);
515 $query =
'DELETE FROM rbac_fa '.
516 'WHERE parent IN ( '.
517 $GLOBALS[
'tree']->getSubTreeQuery($a_ref_id,array(
'child')).
' ) '.
518 'AND rol_id = '.$ilDB->quote($a_rol_id,
'integer');
520 $ilDB->manipulate(
$query);
536 if (!isset($a_ref_ids) or !is_array($a_ref_ids))
538 $message = get_class($this).
"::revokePermissionList(): Missing parameter or parameter is not an array! reference_list: ".var_dump($a_ref_ids);
539 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
542 if (!isset($a_rol_id))
544 $message = get_class($this).
"::revokePermissionList(): Missing parameter! rol_id: ".$a_rol_id;
545 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
549 if ($a_rol_id == SYSTEM_ROLE_ID)
554 $query =
"DELETE FROM rbac_pa ".
555 "WHERE ".$ilDB->in(
'ref_id',$a_ref_ids,
false,
'integer').
' '.
556 "AND rol_id = ".$ilDB->quote($a_rol_id,
'integer');
572 public function copyRolePermissions($a_source_id,$a_source_parent,$a_dest_parent,$a_dest_id,$a_consider_protected =
true)
574 global $tree,$rbacreview;
579 $ops = $rbacreview->getRoleOperationsOnObject($a_source_id,$a_source_parent);
598 global $rbacreview,
$ilDB;
600 if (!isset($a_source_id) or !isset($a_source_parent) or !isset($a_dest_id) or !isset($a_dest_parent))
602 $message = __METHOD__.
": Missing parameter! source_id: ".$a_source_id.
603 " source_parent_id: ".$a_source_parent.
604 " dest_id : ".$a_dest_id.
605 " dest_parent_id: ".$a_dest_parent;
606 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
610 if ($a_dest_id == SYSTEM_ROLE_ID)
616 $query =
'SELECT * FROM rbac_templates '.
617 'WHERE rol_id = '.$ilDB->quote($a_source_id,
'integer').
' '.
618 'AND parent = '.$ilDB->quote($a_source_parent,
'integer');
620 $operations = array();
622 while (
$row = $ilDB->fetchObject(
$res))
624 $operations[$rownum][
'type'] =
$row->type;
625 $operations[$rownum][
'ops_id'] =
$row->ops_id;
630 $query =
'DELETE FROM rbac_templates WHERE rol_id = '.$ilDB->quote($a_dest_id,
'integer').
' '.
631 'AND parent = '.$ilDB->quote($a_dest_parent,
'integer');
634 foreach($operations as
$row => $op)
636 $query =
'INSERT INTO rbac_templates (rol_id,type,ops_id,parent) '.
638 $ilDB->quote($a_dest_id,
'integer').
",".
639 $ilDB->quote($op[
'type'],
'text').
",".
640 $ilDB->quote($op[
'ops_id'],
'integer').
",".
641 $ilDB->quote($a_dest_parent,
'integer').
")";
642 $ilDB->manipulate(
$query);
646 if ($a_consider_protected ==
true)
648 if ($rbacreview->isProtected($a_source_parent,$a_source_id))
671 global $rbacreview,
$ilDB;
673 if (!isset($a_source1_id) or !isset($a_source1_parent)
674 or !isset($a_source2_id) or !isset($a_source2_parent)
675 or !isset($a_dest_id) or !isset($a_dest_parent))
677 $message = get_class($this).
"::copyRolePermissionIntersection(): Missing parameter! source1_id: ".$a_source1_id.
678 " source1_parent: ".$a_source1_parent.
679 " source2_id: ".$a_source2_id.
680 " source2_parent: ".$a_source2_parent.
681 " dest_id: ".$a_dest_id.
682 " dest_parent_id: ".$a_dest_parent;
683 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
687 if ($a_dest_id == SYSTEM_ROLE_ID)
692 if ($rbacreview->isProtected($a_source2_parent,$a_source2_id))
694 $GLOBALS[
'ilLog']->write(__METHOD__.
': Role is protected');
698 $query =
"SELECT s1.type, s1.ops_id ".
699 "FROM rbac_templates s1, rbac_templates s2 ".
700 "WHERE s1.rol_id = ".$ilDB->quote($a_source1_id,
'integer').
" ".
701 "AND s1.parent = ".$ilDB->quote($a_source1_parent,
'integer').
" ".
702 "AND s2.rol_id = ".$ilDB->quote($a_source2_id,
'integer').
" ".
703 "AND s2.parent = ".$ilDB->quote($a_source2_parent,
'integer').
" ".
704 "AND s1.type = s2.type ".
705 "AND s1.ops_id = s2.ops_id";
707 $operations = array();
711 $operations[$rowNum][
'type'] =
$row->type;
712 $operations[$rowNum][
'ops_id'] =
$row->ops_id;
718 $query =
'DELETE FROM rbac_templates WHERE rol_id = '.$ilDB->quote($a_dest_id,
'integer').
' '.
719 'AND parent = '.$ilDB->quote($a_dest_parent,
'integer');
722 $query =
'INSERT INTO rbac_templates (rol_id,type,ops_id,parent) '.
724 $sta = $ilDB->prepareManip(
$query,array(
'integer',
'text',
'integer',
'integer'));
725 foreach($operations as $key => $set)
727 $ilDB->execute($sta,array(
755 global
$ilDB, $rbacreview;
758 $s1_ops = $rbacreview->getAllOperationsOfRole($a_source1_id,$a_source1_parent);
759 $s2_ops = $rbacreview->getAlloperationsOfRole($a_source2_id,$a_source2_parent);
763 $GLOBALS[
'ilLog']->write(__METHOD__.
': '.print_r($s1_ops,TRUE));
764 $GLOBALS[
'ilLog']->write(__METHOD__.
': '.print_r($s2_ops,TRUE));
766 foreach($s1_ops as $type => $ops)
772 $query =
'INSERT INTO rbac_templates (rol_id,type,ops_id,parent) '.
774 $ilDB->quote($a_dest_id,
'integer').
', '.
775 $ilDB->quote($type,
'text').
', '.
776 $ilDB->quote($op,
'integer').
', '.
777 $ilDB->quote($a_dest_parent,
'integer').
' '.
779 $ilDB->manipulate(
$query);
784 foreach($s2_ops as $type => $ops)
788 if(!isset($s1_ops[$type]) or !in_array($op, $s1_ops[$type]))
790 $query =
'INSERT INTO rbac_templates (rol_id,type,ops_id,parent) '.
792 $ilDB->quote($a_dest_id,
'integer').
', '.
793 $ilDB->quote($type,
'text').
', '.
794 $ilDB->quote($op,
'integer').
', '.
795 $ilDB->quote($a_dest_parent,
'integer').
' '.
797 $ilDB->manipulate(
$query);
814 global $rbacreview,
$ilDB;
816 $s1_ops = $rbacreview->getAllOperationsOfRole($a_source_id,$a_source_parent);
817 $d_ops = $rbacreview->getAllOperationsOfRole($a_dest_id,$a_dest_parent);
819 foreach($s1_ops as $type => $ops)
823 if(isset($d_ops[$type]) and in_array($op, $d_ops[$type]))
825 $query =
'DELETE FROM rbac_templates '.
826 'WHERE rol_id = '.$ilDB->quote($a_dest_id,
'integer').
' '.
827 'AND type = '.$ilDB->quote($type,
'text').
' '.
828 'AND ops_id = '.$ilDB->quote($op,
'integer').
' '.
829 'AND parent = '.$ilDB->quote($a_dest_parent,
'integer');
830 $ilDB->manipulate(
$query);
852 if (!isset($a_rol_id) or !isset($a_ref_id))
854 $message = get_class($this).
"::deleteRolePermission(): Missing parameter! role_id: ".$a_rol_id.
" ref_id: ".$a_ref_id;
855 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
859 if ($a_rol_id == SYSTEM_ROLE_ID)
864 if ($a_type !==
false)
866 $and_type =
" AND type=".$ilDB->quote($a_type,
'text').
" ";
869 $query =
'DELETE FROM rbac_templates '.
870 'WHERE rol_id = '.$ilDB->quote($a_rol_id,
'integer').
' '.
871 'AND parent = '.$ilDB->quote($a_ref_id,
'integer').
' '.
893 if (!isset($a_rol_id) or !isset($a_type) or !isset($a_ops) or !isset($a_ref_id))
895 $message = get_class($this).
"::setRolePermission(): Missing parameter!".
896 " role_id: ".$a_rol_id.
898 " operations: ".$a_ops.
899 " ref_id: ".$a_ref_id;
900 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
903 if (!is_string($a_type) or empty($a_type))
905 $message = get_class($this).
"::setRolePermission(): a_type is no string or empty!";
906 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
909 if (!is_array($a_ops) or empty($a_ops))
911 $message = get_class($this).
"::setRolePermission(): a_ops is no array or empty!";
912 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
916 if ($a_rol_id == SYSTEM_ROLE_ID)
921 $query =
'INSERT INTO rbac_templates (rol_id,type,ops_id,parent) '.
923 $sta = $ilDB->prepareManip(
$query,array(
'integer',
'text',
'integer',
'integer'));
924 foreach ($a_ops as $op)
926 $res = $ilDB->execute($sta,array(
952 global
$ilDB,$rbacreview;
954 if (!isset($a_rol_id) or !isset($a_parent))
956 $message = get_class($this).
"::assignRoleToFolder(): Missing Parameter!".
957 " role_id: ".$a_rol_id.
958 " parent_id: ".$a_parent.
959 " assign: ".$a_assign;
960 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
964 if ($a_rol_id == SYSTEM_ROLE_ID)
970 if ($a_assign !=
"y")
975 $query = sprintf(
'INSERT INTO rbac_fa (rol_id, parent, assign, protected) '.
976 'VALUES (%s,%s,%s,%s)',
977 $ilDB->quote($a_rol_id,
'integer'),
978 $ilDB->quote($a_parent,
'integer'),
979 $ilDB->quote($a_assign,
'text'),
980 $ilDB->quote(
'n',
'text'));
998 if (!isset($a_type_id) or !isset($a_ops_id))
1000 $message = get_class($this).
"::assignOperationToObject(): Missing parameter!".
1001 "type_id: ".$a_type_id.
1002 "ops_id: ".$a_ops_id;
1003 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
1006 $query =
"INSERT INTO rbac_ta (typ_id, ops_id) ".
1007 "VALUES(".$ilDB->quote($a_type_id,
'integer').
",".$ilDB->quote($a_ops_id,
'integer').
")";
1024 if (!isset($a_type_id) or !isset($a_ops_id))
1026 $message = get_class($this).
"::deassignPermissionFromObject(): Missing parameter!".
1027 "type_id: ".$a_type_id.
1028 "ops_id: ".$a_ops_id;
1029 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
1032 $query =
"DELETE FROM rbac_ta ".
1033 "WHERE typ_id = ".$ilDB->quote($a_type_id,
'integer').
" ".
1034 "AND ops_id = ".$ilDB->quote($a_ops_id,
'integer');
1054 $query =
'UPDATE rbac_fa '.
1055 'SET protected = '.$ilDB->quote($a_value,
'text').
' '.
1056 'WHERE rol_id = '.$ilDB->quote($a_role_id,
'integer');
1073 global $rbacreview,
$ilLog,$ilObjDataCache;
1075 $real_local = array();
1076 foreach($rbacreview->getRolesOfRoleFolder($a_source_id,
false) as $role_data)
1078 $title = $ilObjDataCache->lookupTitle($role_data);
1079 if(substr($title,0,3) ==
'il_')
1083 $real_local[] = $role_data;
1085 if(!count($real_local))
1090 foreach($real_local as $role)
1092 include_once (
"./Services/AccessControl/classes/class.ilObjRole.php");
1096 $ilLog->write(__METHOD__.
': Start copying of role '.$orig->getTitle());
1098 $roleObj->setTitle($orig->getTitle());
1099 $roleObj->setDescription($orig->getDescription());
1100 $roleObj->setImportId($orig->getImportId());
1105 $ilLog->write(__METHOD__.
': Added new local role, id '.$roleObj->getId());
1124 if($rbacreview->isProtected($a_role_parent, $a_role_id))
1127 $new_ops = $rbacreview->getOperationsOfRole(
1163 $new_ops = $rbacreview->getOperationsOfRole(
1192 global $rbacreview,$tree,
$ilLog;
1194 $new_parent = $tree->getParentId($a_ref_id);
1195 $old_context_roles = $rbacreview->getParentRoleIds($a_old_parent,
false);
1196 $new_context_roles = $rbacreview->getParentRoleIds($new_parent,
false);
1198 $for_addition = $for_deletion = array();
1199 foreach($new_context_roles as $new_role_id => $new_role)
1201 if(!isset($old_context_roles[$new_role_id]))
1203 $for_addition[$new_role_id] = $new_role;
1205 elseif($new_role[
'parent'] != $old_context_roles[$new_role_id][
'parent'])
1208 $for_deletion[$new_role_id] = $new_role;
1209 $for_addition[$new_role_id] = $new_role;
1212 foreach($old_context_roles as $old_role_id => $old_role)
1214 if(!isset($new_context_roles[$old_role_id]))
1216 $for_deletion[$old_role_id] = $old_role;
1220 if(!count($for_deletion) and !count($for_addition))
1225 include_once
"Services/AccessControl/classes/class.ilRbacLog.php";
1227 if($rbac_log_active)
1229 $role_ids = array_unique(array_merge(array_keys($for_deletion), array_keys($for_addition)));
1232 foreach($nodes = $tree->getSubTree($tree->getNodeData($a_ref_id),
true) as $node_data)
1234 $node_id = $node_data[
'child'];
1236 if($rbac_log_active)
1244 if(!$node_data[
'type'])
1246 $ilLog->write(__METHOD__.
': No type give. Choosing next tree entry.');
1252 $ilLog->write(__METHOD__.
': Missing subtree node_id');
1256 foreach($for_deletion as $role_id => $role_data)
1262 foreach($for_addition as $role_id => $role_data)
1264 switch($node_data[
'type'])
1267 include_once
'./Modules/Group/classes/class.ilObjGroup.php';
1270 $node_data[
'child'],
1272 $role_data[
'parent'],
1279 include_once
'./Modules/Course/classes/class.ilObjCourse.php';
1282 $node_data[
'child'],
1284 $role_data[
'parent'],
1294 $ops = $rbacreview->getOperationsOfRole($role_id,$node_data[
'type'],$role_data[
'parent']),
1305 if($rbac_log_active)
1326 $parent_roles = $rbacreview->getParentRoleIds($a_source_ref_id, FALSE);
1327 $GLOBALS[
'ilLog']->write(__METHOD__.
': '. print_r($parent_roles,TRUE));