5 require_once
"./classes/class.ilObject.php";
43 function ilObjRole($a_id = 0,$a_call_by_reference =
false)
46 $this->disk_quota = 0;
47 $this->
ilObject($a_id,$a_call_by_reference);
58 if(substr($this->
getTitle(),0,3) ==
'il_')
60 $ilErr->setMessage(
'msg_role_reserved_prefix');
77 $this->assign_users = (int) $a_assign_users;
81 return $this->assign_users ? $this->assign_users : 0;
88 $query =
"SELECT assign_users FROM role_data WHERE role_id = ".$ilDB->quote($a_role_id,
'integer').
" ";
90 while(
$row = $ilDB->fetchObject(
$res))
92 return $row->assign_users ?
true :
false;
105 $query =
"SELECT * FROM role_data WHERE role_id= ".$ilDB->quote($this->
id,
'integer').
" ";
108 if (
$res->numRows() > 0)
117 $this->ilias->raiseError(
"<b>Error: There is no dataset with id ".$this->
id.
"!</b><br />class: ".get_class($this).
"<br />Script: ".__FILE__.
"<br />Line: ".__LINE__, $this->ilias->FATAL);
145 $query =
"UPDATE role_data SET ".
146 "allow_register= ".$ilDB->quote($this->allow_register,
'integer').
", ".
148 "disk_quota = ".$ilDB->quote($this->
getDiskQuota(),
'integer').
" ".
149 "WHERE role_id= ".$ilDB->quote($this->
id,
'integer').
" ";
172 $query =
"INSERT INTO role_data ".
173 "(role_id,allow_register,assign_users,disk_quota) ".
175 "(".$ilDB->quote($this->
id,
'integer').
",".
193 if (empty($a_allow_register))
195 $a_allow_register == 0;
198 $this->allow_register = (int) $a_allow_register;
209 return $this->allow_register ? $this->allow_register :
false;
222 $this->disk_quota = $a_disk_quota;
248 $query =
"SELECT * FROM role_data ".
249 "JOIN object_data ON object_data.obj_id = role_data.role_id ".
250 "WHERE allow_register = 1";
254 while($role = $ilDB->fetchAssoc(
$res))
256 $roles[] = array(
"id" => $role[
"obj_id"],
257 "title" => $role[
"title"],
258 "auth_mode" => $role[
'auth_mode']);
274 $query =
"SELECT * FROM role_data ".
275 " WHERE role_id =".$ilDB->quote($a_role_id,
'integer');
278 if ($role_rec = $ilDB->fetchAssoc(
$res))
280 if ($role_rec[
"allow_register"])
297 $this->parent = $a_parent_ref;
320 global $rbacadmin, $rbacreview,
$ilDB;
322 $role_folders = $rbacreview->getFoldersAssignedToRole($this->
getId());
325 if($rbacreview->hasMultipleAssignments($this->getId()))
327 $GLOBALS[
'ilLog']->write(__METHOD__.
': Found role with multiple assignments: '.$this->getId());
331 if ($rbacreview->isAssignable($this->getId(),$this->
getParent()))
340 $last_role_user_ids = array();
341 if ($this->
getParent() == ROLE_FOLDER_ID)
346 $user_ids = $rbacreview->assignedUsers($this->
getId());
348 foreach ($user_ids as $user_id)
351 $role_ids = $rbacreview->assignedRoles($user_id);
354 if (count($role_ids) == 1)
356 $last_role_user_ids[] = $user_id;
362 if (count($last_role_user_ids) > 0)
364 foreach ($last_role_user_ids as $user_id)
368 $tmp_obj = $this->ilias->obj_factory->getInstanceByObjId($user_id);
369 $user_names[] = $tmp_obj->getFullname();
376 $users = implode(
', ',$user_names);
377 $this->ilias->raiseError($this->lng->txt(
"msg_user_last_role1").
" ".
378 $users.
"<br/>".$this->lng->txt(
"msg_user_last_role2"),$this->ilias->error_obj->WARNING);
386 include_once(
'./Services/LDAP/classes/class.ilLDAPRoleGroupMappingSettings.php');
393 $query =
"DELETE FROM role_data WHERE role_id = ".$ilDB->quote($this->
getId(),
'integer');
396 include_once
'Services/AccessControl/classes/class.ilRoleDesktopItem.php';
398 $role_desk_item_obj->deleteAll();
416 $non_empty_role_folders = $rbacreview->filterEmptyRoleFolders($role_folders);
417 $role_folders = array_diff($role_folders,$non_empty_role_folders);
420 foreach ($role_folders as $rolf)
424 $rolfObj = $this->ilias->obj_factory->getInstanceByRefId($rolf);
437 return count($rbacreview->assignedUsers($this->getId()));
444 $test_str = explode(
'_',$a_role_title);
446 if ($test_str[0] ==
'il')
448 $test2 = (int) $test_str[3];
454 return $lng->txt(implode(
'_',$test_str));
457 return $a_role_title;
466 foreach ($a_roles as $role_id => $auth_mode)
468 $query =
"UPDATE role_data SET ".
469 "auth_mode= ".$ilDB->quote($auth_mode,
'text').
" ".
470 "WHERE role_id= ".$ilDB->quote($role_id,
'integer').
" ";
479 $query =
"SELECT auth_mode FROM role_data ".
480 "WHERE role_id= ".$ilDB->quote($a_role_id,
'integer').
" ";
484 return $row[
'auth_mode'];
498 $query =
"SELECT * FROM role_data ".
499 "WHERE auth_mode = ".$ilDB->quote($a_auth_mode,
'text');
502 while(
$row = $ilDB->fetchObject(
$res))
504 $roles[] =
$row->role_id;
521 $query =
"UPDATE role_data SET auth_mode = 'default' WHERE auth_mode = ".$ilDB->quote($a_auth_mode,
'text');
529 global
$ilDB,
$lng, $objDefinition,$rbacreview;
531 $operation_info = $rbacreview->getOperationAssignment();
532 foreach($operation_info as $info)
534 if($objDefinition->getDevMode($info[
'type']))
538 $rbac_objects[$info[
'typ_id']] = array(
"obj_id" => $info[
'typ_id'],
539 "type" => $info[
'type']);
542 $txt = $objDefinition->isPlugin($info[
'type'])
544 : $lng->txt($info[
'type'].
"_".$info[
'operation']);
545 if (substr($info[
'operation'], 0, 7) ==
"create_" &&
546 $objDefinition->isPlugin(substr($info[
'operation'], 7)))
548 $txt =
ilPlugin::lookupTxt(
"rep_robj", substr($info[
'operation'], 7), $info[
'type'].
"_".$info[
'operation']);
550 $rbac_operations[$info[
'typ_id']][$info[
'ops_id']] = array(
551 "ops_id" => $info[
'ops_id'],
552 "title" => $info[
'operation'],
556 return array($rbac_objects,$rbac_operations);
568 if(!$rbacreview->isAssignable($this->getId(), $a_role_folder_id))
573 if(substr($this->
getTitle(),0,3) ==
'il_')
595 global $tree,$rbacreview;
598 $nodes = $tree->getRbacSubtreeInfo($a_start_node);
603 $all_local_policies = $rbacreview->getObjectsWithStopedInheritance($this->
getId());
607 $local_policies = array();
608 foreach($all_local_policies as $lp)
610 if(isset($nodes[$lp]))
612 $local_policies[] = $lp;
619 case self::MODE_UNPROTECTED_DELETE_LOCAL_POLICIES:
620 case self::MODE_PROTECTED_DELETE_LOCAL_POLICIES:
622 #$local_policies = array($a_start_node == ROOT_FOLDER_ID ? SYSTEM_FOLDER_ID : $a_start_node);
625 $this->
adjustPermissions($a_mode,$nodes,$local_policies,$a_filter,$a_exclusion_filter);
627 #var_dump(memory_get_peak_usage());
628 #var_dump(memory_get_usage());
638 global $rbacreview,$rbacadmin;
640 $local_policies = array();
641 foreach($a_policies as $policy)
643 if($policy == $a_start or $policy == SYSTEM_FOLDER_ID)
645 $local_policies[] = $policy;
650 $local_policies[] = $policy;
654 if($rolf = $rbacreview->getRoleFolderIdOfObject($policy))
656 $rbacadmin->deleteLocalRole($this->
getId(),$rolf);
659 return $local_policies;
670 protected function adjustPermissions($a_mode,$a_nodes,$a_policies,$a_filter,$a_exclusion_filter = array())
672 global $rbacadmin, $rbacreview;
674 $operation_stack = array();
675 $policy_stack = array();
676 $left_stack = array();
677 $right_stack = array();
679 $start_node = current($a_nodes);
680 array_push($left_stack, $start_node[
'lft']);
681 array_push($right_stack, $start_node[
'rgt']);
685 include_once
"Services/AccessControl/classes/class.ilRbacLog.php";
688 $local_policy =
false;
689 foreach($a_nodes as $node)
691 $lft = end($left_stack);
692 $rgt = end($right_stack);
694 #echo "----STACK---- ".$lft.' - '.$rgt.'<br/>';
696 if(($node[
'lft'] < $lft) or ($node[
'rgt'] > $rgt))
698 #echo "LEFT ".$node['child'].'<br>';
699 array_pop($operation_stack);
700 array_pop($policy_stack);
701 array_pop($left_stack);
702 array_pop($right_stack);
703 $local_policy =
false;
708 #echo "LOCAL ".$node['child'].' left:'.$node['lft'].' right: '.$node['rgt'].'<br>';
714 if($node[
'child'] == $start_node[
'child'])
720 $rbac_log_roles = $rbacreview->getParentRoleIds($node[
'child'],
false);
725 $perms = end($operation_stack);
726 $rbacadmin->grantPermission(
728 (array) $perms[$node[
'type']],
743 if(in_array($node[
'child'], $a_policies) and ($node[
'child'] != SYSTEM_FOLDER_ID))
745 #echo "POLICIES ".$node['child'].' left:'.$node['lft'].' right: '.$node['rgt'].'<br>';
746 $local_policy =
true;
749 array_push($left_stack,$node[
'lft']);
750 array_push($right_stack, $node[
'rgt']);
762 $rbac_log_roles = $rbacreview->getParentRoleIds($node[
'child'],
false);
766 #echo "MODE: ".$a_mode.'TYPE: '.$node['type'].'<br>';
768 if(($a_mode == self::MODE_UNPROTECTED_DELETE_LOCAL_POLICIES or
769 $a_mode == self::MODE_UNPROTECTED_KEEP_LOCAL_POLICIES) and ($node[
'type'] ==
'crs'))
772 #echo "CRS ".$node['child'].'<br>';
775 $perms = end($operation_stack);
779 #echo "CRS SUCCESS ".$node['child'].'<br>';
781 array_push($left_stack, $node[
'lft']);
782 array_push($right_stack, $node[
'rgt']);
787 if(($a_mode == self::MODE_UNPROTECTED_DELETE_LOCAL_POLICIES or
788 $a_mode == self::MODE_UNPROTECTED_KEEP_LOCAL_POLICIES) and ($node[
'type'] ==
'grp'))
790 #echo "GRP ".$node['child'].'<br>';
792 $perms = end($operation_stack);
796 #echo "GRP SUCCESS ".$node['child'].'<br>';
798 array_push($left_stack, $node[
'lft']);
799 array_push($right_stack, $node[
'rgt']);
803 #echo "GRANTED ".$node['child'].'<br>';
805 $perms = end($operation_stack);
806 $rbacadmin->grantPermission(
808 (array) $perms[$node[
'type']],
811 #var_dump("ALL INFO ",$this->getId(),$perms[$node['type']]);
830 if(in_array($a_type,$a_exclusion_filter))
835 if(in_array(
'all',$a_filter))
839 return in_array($a_type,$a_filter);
852 if($a_node == ROOT_FOLDER_ID)
854 $rolf = ROLE_FOLDER_ID;
858 $rolf = $rbacreview->getRoleFolderIdOfObject($a_node);
866 $a_stack[] = $rbacreview->getAllOperationsOfRole(
882 if($a_node == ROOT_FOLDER_ID)
884 $rolf = ROLE_FOLDER_ID;
888 $rolf = $rbacreview->getRoleFolderIdOfObject($a_node);
909 global
$ilDB, $rbacreview,$rbacadmin;
911 static $course_non_member_id = null;
912 static $group_non_member_id = null;
913 static $group_open_id = null;
914 static $group_closed_id = null;
921 include_once
'./Modules/Group/classes/class.ilObjGroup.php';
923 #var_dump("GROUP TYPE",$type);
927 if(!$group_closed_id)
929 $query =
"SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_closed'";
933 $group_closed_id =
$row->obj_id;
936 $template_id = $group_closed_id;
937 #var_dump("GROUP CLOSED id:" . $template_id);
944 $query =
"SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_open'";
948 $group_open_id =
$row->obj_id;
951 $template_id = $group_open_id;
952 #var_dump("GROUP OPEN id:" . $template_id);
958 if(!$course_non_member_id)
960 $query =
"SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_crs_non_member'";
964 $course_non_member_id =
$row->obj_id;
967 $template_id = $course_non_member_id;
971 $current_ops = $a_current_ops[$a_type];
976 $rolf = $rbacreview->getRoleFolderIdOfObject($a_id);
978 $rbacadmin->copyRolePermissionIntersection(
979 $template_id, ROLE_FOLDER_ID,
980 $this->
getId(), end($policy_stack),
986 #echo "No template id for ".$a_id.' of type'.$a_type.'<br>';
988 #echo "ROLE ASSIGN: ".$rolf.' AID'.$a_id;
991 $rbacadmin->assignRoleToFolder($this->
getId(),$rolf,
"n");