3 * this page defines what roles can override (override roles in different context. For example,
4 * we can say that Admin can override teacher roles in a course
5 * To be able to override roles. If a user has moodle/role:override at context level
6 * and be in the roles_allow_override table.
8 require_once('../../config.php');
9 require_once($CFG->libdir
.'/adminlib.php');
11 admin_externalpage_setup('defineroles');
14 $sitecontext = get_context_instance(CONTEXT_SYSTEM
, SITEID
);
15 require_capability('moodle/role:manage', $sitecontext);
17 /// form processiong here
21 $roles = get_all_roles();
23 if ($grant = data_submitted()) {
25 foreach ($grant as $grole => $val) {
26 if ($grole == 'dummy') {
30 $string = explode('_', $grole);
31 $temp[$string[1]][$string[2]] = 1; // if set, means can access
34 // if current assignment is in data_submitted, ignore, else, write deny into db
35 foreach ($roles as $srole) {
36 foreach ($roles as $trole) {
37 if (isset($temp[$srole->id
][$trole->id
])) { // if set, need to write to db
38 if (!$record = get_record('role_allow_override', 'roleid', $srole->id
, 'allowoverride', $trole->id
)) {
39 allow_override($srole->id
, $trole->id
);
41 } else { //if set, means can access, attempt to remove it from db
42 delete_records('role_allow_override', 'roleid', $srole->id
, 'allowoverride', $trole->id
);
47 /// displaying form here
49 admin_externalpage_print_header();
51 $currenttab='allowoverride';
52 require_once('managetabs.php');
54 $table->tablealign
= 'center';
55 $table->cellpadding
= 5;
56 $table->cellspacing
= 0;
57 $table->width
= '90%';
58 $table->align
[] = 'right';
60 /// get all the roles identifier
61 foreach ($roles as $role) {
62 $rolesname[] = format_string($role->name
);
63 $roleids[] = $role->id
;
64 $table->align
[] = 'center';
65 $table->wrap
[] = 'nowrap';
68 $table->head
= array_merge(array(''), $rolesname);
70 foreach ($roles as $role) {
71 $beta = get_box_list($role->id
, $roleids);
72 $table->data
[] = array_merge(array(format_string($role->name
)), $beta);
75 print_simple_box(get_string('configallowoverride', 'admin'), 'center');
77 echo '<form action="allowoverride.php" method="post">';
79 echo '<div class="buttons"><input type="submit" value="'.get_string('savechanges').'"/>';
80 echo '<input type="hidden" name="dummy" value="1" />'; // this is needed otherwise we do not know a form has been submitted
83 admin_externalpage_print_footer();
86 function get_box_list($roleid, $arraylist){
88 foreach ($arraylist as $targetid) {
89 if (get_record('role_allow_override', 'roleid', $roleid, 'allowoverride', $targetid)) {
90 $array[] = '<input type="checkbox" name="s_'.$roleid.'_'.$targetid.'" value="1" checked="checked"/>';
92 $array[] = '<input type="checkbox" name="s_'.$roleid.'_'.$targetid.'" value="1" />';