49 (isset($ilDB)) ? $this->
ilDB =& $ilDB : $this->
ilDB =& $ilias->db;
73 if (!isset($a_usr_id))
75 $message = get_class($this).
"::removeUser(): No usr_id given!";
76 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
79 $query =
"DELETE FROM rbac_ua WHERE usr_id = ".$ilDB->quote($a_usr_id,
'integer');
96 if (!isset($a_rol_id) or !isset($a_ref_id))
98 $message = get_class($this).
"::deleteRole(): Missing parameter! role_id: ".$a_rol_id.
" ref_id of role folder: ".$a_ref_id;
99 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
103 if ($a_rol_id == SYSTEM_ROLE_ID)
105 $this->ilErr->raiseError($lng->txt(
"msg_sysrole_not_deletable"),$this->ilErr->MESSAGE);
108 include_once(
'Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
110 $mapping->deleteRole($a_rol_id);
117 $query =
"DELETE FROM rbac_ua ".
118 "WHERE rol_id = ".$ilDB->quote($a_rol_id,
'integer');
122 $query =
"DELETE FROM rbac_pa ".
123 "WHERE rol_id = ".$ilDB->quote($a_rol_id,
'integer').
" ";
142 if (!isset($a_obj_id))
144 $message = get_class($this).
"::deleteTemplate(): No obj_id given!";
145 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
148 $query =
'DELETE FROM rbac_templates '.
149 'WHERE rol_id = '.$ilDB->quote($a_obj_id,
'integer');
152 $query =
'DELETE FROM rbac_fa '.
153 'WHERE rol_id = '.$ilDB->quote($a_obj_id,
'integer');
170 if (!isset($a_rol_id))
172 $message = get_class($this).
"::deleteLocalRole(): Missing parameter! role_id: '".$a_rol_id.
"'";
173 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
177 if ($a_rol_id == SYSTEM_ROLE_ID)
184 $clause =
'AND parent = '.$ilDB->quote($a_ref_id,
'integer').
' ';
187 $query =
'DELETE FROM rbac_fa '.
188 'WHERE rol_id = '.$ilDB->quote($a_rol_id,
'integer').
' '.
192 $query =
'DELETE FROM rbac_templates '.
193 'WHERE rol_id = '.$ilDB->quote($a_rol_id,
'integer').
' '.
211 global
$ilDB,$rbacreview;
213 if (!isset($a_rol_id) or !isset($a_usr_id))
215 $message = get_class($this).
"::assignUser(): Missing parameter! role_id: ".$a_rol_id.
" usr_id: ".$a_usr_id;
216 #$this->ilErr->raiseError($message,$this->ilErr->WARNING);
220 $alreadyAssigned = $rbacreview->isAssigned($a_usr_id,$a_rol_id);
223 if (!$alreadyAssigned)
225 $query =
"INSERT INTO rbac_ua (usr_id, rol_id) ".
226 "VALUES (".$ilDB->quote($a_usr_id,
'integer').
",".$ilDB->quote($a_rol_id,
'integer').
")";
229 include_once
'./classes/class.ilRoleDesktopItem.php';
235 foreach($role_desk_item_obj->getAll() as $item_data)
237 if(!$tmp_user->isDesktopItem($item_data[
'item_id'],$item_data[
'item_type']))
239 $tmp_user->addDesktopItem($item_data[
'item_id'],$item_data[
'item_type']);
245 include_once(
'Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
247 $mapping->assign($a_rol_id,$a_usr_id);
263 if (!isset($a_rol_id) or !isset($a_usr_id))
265 $message = get_class($this).
"::deassignUser(): Missing parameter! role_id: ".$a_rol_id.
" usr_id: ".$a_usr_id;
266 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
269 $query =
"DELETE FROM rbac_ua ".
270 "WHERE usr_id = ".$ilDB->quote($a_usr_id,
'integer').
" ".
271 "AND rol_id = ".$ilDB->quote($a_rol_id,
'integer').
" ";
274 include_once(
'Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
276 $mapping->deassign($a_rol_id,$a_usr_id);
293 if (!isset($a_rol_id) or !isset($a_ops) or !isset($a_ref_id))
295 $this->ilErr->raiseError(get_class($this).
"::grantPermission(): Missing parameter! ".
296 "role_id: ".$a_rol_id.
" ref_id: ".$a_ref_id.
" operations: ",$this->ilErr->WARNING);
299 if (!is_array($a_ops))
301 $this->ilErr->raiseError(get_class($this).
"::grantPermission(): Wrong datatype for operations!",
302 $this->ilErr->WARNING);
312 if ($a_rol_id == SYSTEM_ROLE_ID)
318 foreach ($a_ops as
$key => $operation)
320 $a_ops[
$key] = (int) $operation;
324 $ops_ids = serialize($a_ops);
326 $query =
'DELETE FROM rbac_pa '.
327 'WHERE rol_id = %s '.
329 $res = $ilDB->queryF(
$query,array(
'integer',
'integer'),
330 array($a_rol_id,$a_ref_id));
337 $query =
"INSERT INTO rbac_pa (rol_id,ops_id,ref_id) ".
339 "(".$ilDB->quote($a_rol_id,
'integer').
",".$ilDB->quote($ops_ids,
'text').
",".$ilDB->quote($a_ref_id,
'integer').
")";
358 if (!isset($a_ref_id))
360 $message = get_class($this).
"::revokePermission(): Missing parameter! ref_id: ".$a_ref_id;
361 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
363 #$log->write("ilRBACadmin::revokePermission(), 0");
366 if ($a_keep_protected !=
true)
369 if ($a_rol_id == SYSTEM_ROLE_ID)
376 $and1 =
" AND rol_id = ".$ilDB->quote($a_rol_id,
'integer').
" ";
383 $query =
"DELETE FROM rbac_pa ".
384 "WHERE ref_id = ".$ilDB->quote($a_ref_id,
'integer').
395 $roles_in_scope = $rbacreview->getParentRoleIds($a_ref_id);
399 #$log->write("ilRBACadmin::revokePermission(), 1");
403 foreach ($roles_in_scope as $role)
405 if ($role[
'protected'] ==
true)
410 $role_ids[] = $role[
'obj_id'];
419 $query =
'DELETE FROM rbac_pa '.
420 'WHERE '.$ilDB->in(
'rol_id',$role_ids,
false,
'integer').
' '.
421 'AND ref_id = '.$ilDB->quote($a_ref_id,
'integer');
426 #$log->write("ilRBACadmin::revokePermission(), 2");
428 if ($a_rol_id == SYSTEM_ROLE_ID)
434 if ($roles_in_scope[$a_rol_id][
'protected'] ==
true)
439 $query =
"DELETE FROM rbac_pa ".
440 "WHERE ref_id = ".$ilDB->quote($a_ref_id,
'integer').
" ".
441 "AND rol_id = ".$ilDB->quote($a_rol_id,
'integer').
" ";
459 if (!isset($a_ref_ids) or !is_array($a_ref_ids))
461 $message = get_class($this).
"::revokePermissionList(): Missing parameter or parameter is not an array! reference_list: ".var_dump($a_ref_ids);
462 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
465 if (!isset($a_rol_id))
467 $message = get_class($this).
"::revokePermissionList(): Missing parameter! rol_id: ".$a_rol_id;
468 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
472 if ($a_rol_id == SYSTEM_ROLE_ID)
477 $query =
"DELETE FROM rbac_pa ".
478 "WHERE ".$ilDB->in(
'ref_id',$a_ref_ids,
false,
'integer').
' '.
479 "AND rol_id = ".$ilDB->quote($a_rol_id,
'integer');
495 public function copyRolePermissions($a_source_id,$a_source_parent,$a_dest_parent,$a_dest_id,$a_consider_protected =
true)
497 global $tree,$rbacreview;
502 $source_obj = $tree->getParentId($a_source_parent);
503 $target_obj = $tree->getParentId($a_dest_parent);
504 $ops = $rbacreview->getRoleOperationsOnObject($a_source_id,$source_obj);
523 global $rbacreview,
$ilDB;
525 if (!isset($a_source_id) or !isset($a_source_parent) or !isset($a_dest_id) or !isset($a_dest_parent))
527 $message = __METHOD__.
": Missing parameter! source_id: ".$a_source_id.
528 " source_parent_id: ".$a_source_parent.
529 " dest_id : ".$a_dest_id.
530 " dest_parent_id: ".$a_dest_parent;
531 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
535 if ($a_dest_id == SYSTEM_ROLE_ID)
540 $query =
'DELETE FROM rbac_templates WHERE rol_id = '.$ilDB->quote($a_dest_id,
'integer').
' '.
541 'AND parent = '.$ilDB->quote($a_dest_parent,
'integer');
544 $query =
'SELECT * FROM rbac_templates '.
545 'WHERE rol_id = '.$ilDB->quote($a_source_id,
'integer').
' '.
546 'AND parent = '.$ilDB->quote($a_source_parent,
'integer');
548 while (
$row = $ilDB->fetchObject(
$res))
550 $query =
'INSERT INTO rbac_templates (rol_id,type,ops_id,parent) '.
552 $ilDB->quote($a_dest_id,
'integer').
",".
553 $ilDB->quote(
$row->type,
'text').
",".
554 $ilDB->quote(
$row->ops_id,
'integer').
",".
555 $ilDB->quote($a_dest_parent,
'integer').
")";
556 $ilDB->manipulate(
$query);
560 if ($a_consider_protected ==
true)
562 if ($rbacreview->isProtected($a_source_parent,$a_source_id))
585 global $rbacreview,
$ilDB;
587 if (!isset($a_source1_id) or !isset($a_source1_parent)
588 or !isset($a_source2_id) or !isset($a_source2_parent)
589 or !isset($a_dest_id) or !isset($a_dest_parent))
591 $message = get_class($this).
"::copyRolePermissionIntersection(): Missing parameter! source1_id: ".$a_source1_id.
592 " source1_parent: ".$a_source1_parent.
593 " source2_id: ".$a_source2_id.
594 " source2_parent: ".$a_source2_parent.
595 " dest_id: ".$a_dest_id.
596 " dest_parent_id: ".$a_dest_parent;
597 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
601 if ($a_dest_id == SYSTEM_ROLE_ID)
606 if ($rbacreview->isProtected($a_source2_parent,$a_source2_id))
611 $query =
"SELECT s1.type, s1.ops_id ".
612 "FROM rbac_templates s1, rbac_templates s2 ".
613 "WHERE s1.rol_id = ".$ilDB->quote($a_source1_id,
'integer').
" ".
614 "AND s1.parent = ".$ilDB->quote($a_source1_parent,
'integer').
" ".
615 "AND s2.rol_id = ".$ilDB->quote($a_source2_id,
'integer').
" ".
616 "AND s2.parent = ".$ilDB->quote($a_source2_parent,
'integer').
" ".
617 "AND s1.type = s2.type ".
618 "AND s1.ops_id = s2.ops_id";
621 $query =
'INSERT INTO rbac_templates (rol_id,type,ops_id,parent) '.
623 $sta = $ilDB->prepareManip(
$query,array(
'integer',
'text',
'integer',
'integer'));
624 while(
$row = $ilDB->fetchObject(
$res))
626 $ilDB->execute($sta,array(
650 if (!isset($a_rol_id) or !isset($a_ref_id))
652 $message = get_class($this).
"::deleteRolePermission(): Missing parameter! role_id: ".$a_rol_id.
" ref_id: ".$a_ref_id;
653 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
657 if ($a_rol_id == SYSTEM_ROLE_ID)
662 if ($a_type !==
false)
664 $and_type =
" AND type=".$ilDB->quote($a_type,
'text').
" ";
667 $query =
'DELETE FROM rbac_templates '.
668 'WHERE rol_id = '.$ilDB->quote($a_rol_id,
'integer').
' '.
669 'AND parent = '.$ilDB->quote($a_ref_id,
'integer').
' '.
690 if (!isset($a_rol_id) or !isset($a_type) or !isset($a_ops) or !isset($a_ref_id))
692 $message = get_class($this).
"::setRolePermission(): Missing parameter!".
693 " role_id: ".$a_rol_id.
695 " operations: ".$a_ops.
696 " ref_id: ".$a_ref_id;
697 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
700 if (!is_string($a_type) or empty($a_type))
702 $message = get_class($this).
"::setRolePermission(): a_type is no string or empty!";
703 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
706 if (!is_array($a_ops) or empty($a_ops))
708 $message = get_class($this).
"::setRolePermission(): a_ops is no array or empty!";
709 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
713 if ($a_rol_id == SYSTEM_ROLE_ID)
718 $query =
'INSERT INTO rbac_templates (rol_id,type,ops_id,parent) '.
720 $sta = $ilDB->prepareManip(
$query,array(
'integer',
'text',
'integer',
'integer'));
721 foreach ($a_ops as $op)
723 $res = $ilDB->execute($sta,array(
751 if (!isset($a_rol_id) or !isset($a_parent))
753 $message = get_class($this).
"::assignRoleToFolder(): Missing Parameter!".
754 " role_id: ".$a_rol_id.
755 " parent_id: ".$a_parent.
756 " assign: ".$a_assign;
757 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
761 if ($a_rol_id == SYSTEM_ROLE_ID)
767 if ($a_assign !=
"y")
772 $query = sprintf(
'INSERT INTO rbac_fa (rol_id, parent, assign, protected) '.
773 'VALUES (%s,%s,%s,%s)',
774 $ilDB->quote($a_rol_id,
'integer'),
775 $ilDB->quote($a_parent,
'integer'),
776 $ilDB->quote($a_assign,
'text'),
777 $ilDB->quote(
'n',
'text'));
795 if (!isset($a_type_id) or !isset($a_ops_id))
797 $message = get_class($this).
"::assignOperationToObject(): Missing parameter!".
798 "type_id: ".$a_type_id.
799 "ops_id: ".$a_ops_id;
800 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
803 $query =
"INSERT INTO rbac_ta (typ_id, ops_id) ".
804 "VALUES(".$ilDB->quote($a_type_id,
'integer').
",".$ilDB->quote($a_ops_id,
'integer').
")";
821 if (!isset($a_type_id) or !isset($a_ops_id))
823 $message = get_class($this).
"::deassignPermissionFromObject(): Missing parameter!".
824 "type_id: ".$a_type_id.
825 "ops_id: ".$a_ops_id;
826 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
829 $query =
"DELETE FROM rbac_ta ".
830 "WHERE typ_id = ".$ilDB->quote($a_type_id,
'integer').
" ".
831 "AND ops_id = ".$ilDB->quote($a_ops_id,
'integer');
843 $query =
'UPDATE rbac_fa '.
844 'SET protected = '.$ilDB->quote($a_value,
'text').
' '.
845 'WHERE rol_id = '.$ilDB->quote($a_role_id,
'integer');
862 global $rbacreview,
$ilLog,$ilObjDataCache;
864 $source_rolf = $rbacreview->getRoleFolderIdOfObject($a_source_id);
865 $target_rolf = $rbacreview->getRoleFolderIdOfObject($a_target_id);
872 $real_local = array();
873 foreach($rbacreview->getRolesOfRoleFolder($source_rolf,
false) as $role_data)
875 $title = $ilObjDataCache->lookupTitle($role_data);
876 if(substr(
$title,0,3) ==
'il_')
880 $real_local[] = $role_data;
882 if(!count($real_local))
890 if(!is_object($tmp_obj))
894 $rolf = $tmp_obj->createRoleFolder();
895 $target_rolf = $rolf->getRefId();
896 $ilLog->write(__METHOD__.
': Created new role folder with id '.$rolf->getRefId());
898 foreach($real_local as $role)
900 include_once (
"./Services/AccessControl/classes/class.ilObjRole.php");
904 $ilLog->write(__METHOD__.
': Start copying of role '.$orig->getTitle());
906 $roleObj->setTitle($orig->getTitle());
907 $roleObj->setDescription($orig->getDescription());
908 $roleObj->setImportId($orig->getImportId());
913 $ilLog->write(__METHOD__.
': Added new local role, id '.$roleObj->getId());
931 global $rbacreview,$tree,
$ilLog;
933 $new_parent = $tree->getParentId($a_ref_id);
934 $old_context_roles = $rbacreview->getParentRoleIds($a_old_parent,
false);
935 $new_context_roles = $rbacreview->getParentRoleIds($new_parent,
false);
937 $for_addition = $for_deletion = array();
938 foreach($new_context_roles as $new_role_id => $new_role)
940 if(!isset($old_context_roles[$new_role_id]))
942 $for_addition[$new_role_id] = $new_role;
944 elseif($new_role[
'parent'] != $old_context_roles[$new_role_id][
'parent'])
947 $for_deletion[$new_role_id] = $new_role;
948 $for_addition[$new_role_id] = $new_role;
951 foreach($old_context_roles as $old_role_id => $old_role)
953 if(!isset($new_context_roles[$old_role_id]))
955 $for_deletion[$old_role_id] = $old_role;
959 if(!count($for_deletion) and !count($for_addition))
963 foreach($nodes = $tree->getSubTree($node_data = $tree->getNodeData($a_ref_id),
true) as $node_data)
965 $node_id = $node_data[
'child'];
970 if(!$node_data[
'type'])
972 $ilLog->write(__METHOD__.
': No type give. Choosing next tree entry.');
978 $ilLog->write(__METHOD__.
': Missing subtree node_id');
982 foreach($for_deletion as $role_id => $role_data)
984 if($rolf_id = $rbacreview->getRoleFolderIdOfObject($node_id))
991 foreach($for_addition as $role_id => $role_data)
995 $ops = $rbacreview->getOperationsOfRole($role_id,$node_data[
'type'],$role_data[
'parent']),