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);
447 if(substr($a_role_title, 0, 4) ==
'il_x')
449 include_once
'./Services/Component/classes/class.ilPlugin.php';
450 array_pop($test_str);
454 if ($test_str[0] ==
'il')
456 $test2 = (int) $test_str[3];
462 return $lng->txt(implode(
'_',$test_str));
465 return $a_role_title;
474 foreach ($a_roles as $role_id => $auth_mode)
476 $query =
"UPDATE role_data SET ".
477 "auth_mode= ".$ilDB->quote($auth_mode,
'text').
" ".
478 "WHERE role_id= ".$ilDB->quote($role_id,
'integer').
" ";
487 $query =
"SELECT auth_mode FROM role_data ".
488 "WHERE role_id= ".$ilDB->quote($a_role_id,
'integer').
" ";
492 return $row[
'auth_mode'];
506 $query =
"SELECT * FROM role_data ".
507 "WHERE auth_mode = ".$ilDB->quote($a_auth_mode,
'text');
510 while(
$row = $ilDB->fetchObject(
$res))
512 $roles[] =
$row->role_id;
529 $query =
"UPDATE role_data SET auth_mode = 'default' WHERE auth_mode = ".$ilDB->quote($a_auth_mode,
'text');
537 global
$ilDB,
$lng, $objDefinition,$rbacreview;
539 $operation_info = $rbacreview->getOperationAssignment();
540 foreach($operation_info as $info)
542 if($objDefinition->getDevMode($info[
'type']))
546 $rbac_objects[$info[
'typ_id']] = array(
"obj_id" => $info[
'typ_id'],
547 "type" => $info[
'type']);
550 $txt = $objDefinition->isPlugin($info[
'type'])
552 : $lng->txt($info[
'type'].
"_".$info[
'operation']);
553 if (substr($info[
'operation'], 0, 7) ==
"create_" &&
554 $objDefinition->isPlugin(substr($info[
'operation'], 7)))
556 $txt =
ilPlugin::lookupTxt(
"rep_robj", substr($info[
'operation'], 7), $info[
'type'].
"_".$info[
'operation']);
558 $rbac_operations[$info[
'typ_id']][$info[
'ops_id']] = array(
559 "ops_id" => $info[
'ops_id'],
560 "title" => $info[
'operation'],
564 return array($rbac_objects,$rbac_operations);
576 if(!$rbacreview->isAssignable($this->getId(), $a_role_folder_id))
581 if(substr($this->
getTitle(),0,3) ==
'il_')
603 global $tree,$rbacreview;
606 $nodes = $tree->getRbacSubtreeInfo($a_start_node);
609 $all_local_policies = $rbacreview->getObjectsWithStopedInheritance($this->
getId());
612 $local_policies = array();
613 foreach($all_local_policies as $lp)
615 if(isset($nodes[$lp]))
617 $local_policies[] = $lp;
624 case self::MODE_UNPROTECTED_DELETE_LOCAL_POLICIES:
625 case self::MODE_PROTECTED_DELETE_LOCAL_POLICIES:
627 #$local_policies = array($a_start_node == ROOT_FOLDER_ID ? SYSTEM_FOLDER_ID : $a_start_node);
630 $this->
adjustPermissions($a_mode,$nodes,$local_policies,$a_filter,$a_exclusion_filter);
632 #var_dump(memory_get_peak_usage());
633 #var_dump(memory_get_usage());
643 global $rbacreview,$rbacadmin;
645 $local_policies = array();
646 foreach($a_policies as $policy)
648 if($policy == $a_start or $policy == SYSTEM_FOLDER_ID)
650 $local_policies[] = $policy;
655 $local_policies[] = $policy;
659 if($rolf = $rbacreview->getRoleFolderIdOfObject($policy))
661 $rbacadmin->deleteLocalRole($this->
getId(),$rolf);
664 return $local_policies;
675 protected function adjustPermissions($a_mode,$a_nodes,$a_policies,$a_filter,$a_exclusion_filter = array())
677 global $rbacadmin, $rbacreview;
679 $operation_stack = array();
680 $policy_stack = array();
681 $left_stack = array();
682 $right_stack = array();
684 $start_node = current($a_nodes);
685 array_push($left_stack, $start_node[
'lft']);
686 array_push($right_stack, $start_node[
'rgt']);
690 #$GLOBALS['ilLog']->write(__METHOD__.': '.print_r($policy_stack,true));
691 #$GLOBALS['ilLog']->write(__METHOD__.': '.print_r($operation_stack,true));
693 include_once
"Services/AccessControl/classes/class.ilRbacLog.php";
696 $local_policy =
false;
697 foreach($a_nodes as $node)
699 $lft = end($left_stack);
700 $rgt = end($right_stack);
702 #echo "----STACK---- ".$lft.' - '.$rgt.'<br/>';
704 while(($node[
'lft'] < $lft) or ($node[
'rgt'] > $rgt))
706 #echo "LEFT ".$node['child'].'<br>';
707 array_pop($operation_stack);
708 array_pop($policy_stack);
709 array_pop($left_stack);
710 array_pop($right_stack);
712 $lft = end($left_stack);
713 $rgt = end($right_stack);
715 $local_policy =
false;
720 #echo "LOCAL ".$node['child'].' left:'.$node['lft'].' right: '.$node['rgt'].'<br>';
726 if($node[
'child'] == $start_node[
'child'])
732 $rbac_log_roles = $rbacreview->getParentRoleIds($node[
'child'],
false);
737 $perms = end($operation_stack);
738 $rbacadmin->grantPermission(
740 (array) $perms[$node[
'type']],
755 if(in_array($node[
'child'], $a_policies) and ($node[
'child'] != SYSTEM_FOLDER_ID))
757 #echo "POLICIES ".$node['child'].' left:'.$node['lft'].' right: '.$node['rgt'].'<br>';
758 $local_policy =
true;
761 array_push($left_stack,$node[
'lft']);
762 array_push($right_stack, $node[
'rgt']);
774 $rbac_log_roles = $rbacreview->getParentRoleIds($node[
'child'],
false);
778 #echo "MODE: ".$a_mode.'TYPE: '.$node['type'].'<br>';
780 if(($a_mode == self::MODE_UNPROTECTED_DELETE_LOCAL_POLICIES or
781 $a_mode == self::MODE_UNPROTECTED_KEEP_LOCAL_POLICIES) and ($node[
'type'] ==
'crs'))
784 #echo "CRS ".$node['child'].'<br>';
787 $perms = end($operation_stack);
791 #echo "CRS SUCCESS ".$node['child'].'<br>';
793 array_push($left_stack, $node[
'lft']);
794 array_push($right_stack, $node[
'rgt']);
799 if(($a_mode == self::MODE_UNPROTECTED_DELETE_LOCAL_POLICIES or
800 $a_mode == self::MODE_UNPROTECTED_KEEP_LOCAL_POLICIES) and ($node[
'type'] ==
'grp'))
802 #echo "GRP ".$node['child'].'<br>';
804 $perms = end($operation_stack);
808 #echo "GRP SUCCESS ".$node['child'].'<br>';
810 array_push($left_stack, $node[
'lft']);
811 array_push($right_stack, $node[
'rgt']);
815 #echo "GRANTED ".$node['child'].'<br>';
817 $perms = end($operation_stack);
818 $rbacadmin->grantPermission(
820 (array) $perms[$node[
'type']],
823 #var_dump("ALL INFO ",$this->getId(),$perms[$node['type']]);
842 if(in_array($a_type,$a_exclusion_filter))
847 if(in_array(
'all',$a_filter))
851 return in_array($a_type,$a_filter);
864 if($a_node == ROOT_FOLDER_ID)
866 $rolf = ROLE_FOLDER_ID;
870 $rolf = $rbacreview->getRoleFolderIdOfObject($a_node);
878 $a_stack[] = $rbacreview->getAllOperationsOfRole(
896 if($a_node == ROOT_FOLDER_ID)
898 $rolf = ROLE_FOLDER_ID;
902 $roles = $rbacreview->getParentRoleIds($a_node,
false,
true);
903 $rolf = $roles[$this->
getId()][
'parent'];
910 $a_stack[] = $rbacreview->getAllOperationsOfRole(
926 if($a_node == ROOT_FOLDER_ID)
928 $rolf = ROLE_FOLDER_ID;
932 $rolf = $rbacreview->getRoleFolderIdOfObject($a_node);
954 if($a_node == ROOT_FOLDER_ID)
956 $rolf = ROLE_FOLDER_ID;
960 $roles = $rbacreview->getParentRoleIds($a_node,
false,
true);
962 $GLOBALS[
'ilLog']->write(__METHOD__.
': '.print_r($roles,
true));
963 $rolf = $roles[$this->
getId()][
'parent'];
977 global
$ilDB, $rbacreview,$rbacadmin;
979 static $course_non_member_id = null;
980 static $group_non_member_id = null;
981 static $group_open_id = null;
982 static $group_closed_id = null;
989 include_once
'./Modules/Group/classes/class.ilObjGroup.php';
991 #var_dump("GROUP TYPE",$type);
995 if(!$group_closed_id)
997 $query =
"SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_closed'";
1001 $group_closed_id =
$row->obj_id;
1004 $template_id = $group_closed_id;
1005 #var_dump("GROUP CLOSED id:" . $template_id);
1012 $query =
"SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_open'";
1016 $group_open_id =
$row->obj_id;
1019 $template_id = $group_open_id;
1020 #var_dump("GROUP OPEN id:" . $template_id);
1026 if(!$course_non_member_id)
1028 $query =
"SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_crs_non_member'";
1032 $course_non_member_id =
$row->obj_id;
1035 $template_id = $course_non_member_id;
1039 $current_ops = $a_current_ops[$a_type];
1044 $rolf = $rbacreview->getRoleFolderIdOfObject($a_id);
1046 $rbacadmin->copyRolePermissionIntersection(
1047 $template_id, ROLE_FOLDER_ID,
1048 $this->
getId(), end($policy_stack),
1049 $rolf,$this->
getId()
1054 #echo "No template id for ".$a_id.' of type'.$a_type.'<br>';
1056 #echo "ROLE ASSIGN: ".$rolf.' AID'.$a_id;
1059 $rbacadmin->assignRoleToFolder($this->
getId(),$rolf,
"n");