MDL-16043: manage case when administrator set enrol_remotecoursefield or enrol_remote...
[moodle-linuxchix.git] / admin / roles / allowoverride.php
blobaffc4ee0aeeb3552b8a400e6136de4ca89dca259
1 <?php
2 /**
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.
7 */
8 require_once('../../config.php');
9 require_once($CFG->libdir.'/adminlib.php');
11 admin_externalpage_setup('defineroles');
14 $sitecontext = get_context_instance(CONTEXT_SYSTEM);
15 require_capability('moodle/role:manage', $sitecontext);
17 /// form processiong here
19 /// get all roles
21 $roles = get_all_roles();
23 if ($grant = data_submitted()) {
25 foreach ($grant as $grole => $val) {
26 if ($grole == 'dummy') {
27 continue;
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);
46 // updated allowoverride sitewide...
47 mark_context_dirty($sitecontext->path);
49 /// displaying form here
51 admin_externalpage_print_header();
53 $currenttab='allowoverride';
54 require_once('managetabs.php');
56 $table->tablealign = 'center';
57 $table->cellpadding = 5;
58 $table->cellspacing = 0;
59 $table->width = '90%';
60 $table->align[] = 'right';
62 /// get all the roles identifier
63 foreach ($roles as $role) {
64 $rolesname[] = format_string($role->name);
65 $roleids[] = $role->id;
66 $table->align[] = 'center';
67 $table->wrap[] = 'nowrap';
70 $table->head = array_merge(array(''), $rolesname);
72 foreach ($roles as $role) {
73 $beta = get_box_list($role->id, $roleids);
74 $table->data[] = array_merge(array(format_string($role->name)), $beta);
77 print_simple_box(get_string('configallowoverride2', 'admin'), 'center');
79 echo '<form action="allowoverride.php" method="post">';
80 print_table($table);
81 echo '<div class="buttons"><input type="submit" value="'.get_string('savechanges').'"/>';
82 echo '<input type="hidden" name="dummy" value="1" />'; // this is needed otherwise we do not know a form has been submitted
83 echo '</div></form>';
85 admin_externalpage_print_footer();
87 // returns array
88 function get_box_list($roleid, $arraylist){
90 foreach ($arraylist as $targetid) {
91 if (get_record('role_allow_override', 'roleid', $roleid, 'allowoverride', $targetid)) {
92 $array[] = '<input type="checkbox" name="s_'.$roleid.'_'.$targetid.'" value="1" checked="checked"/>';
93 } else {
94 $array[] = '<input type="checkbox" name="s_'.$roleid.'_'.$targetid.'" value="1" />';
97 return $array;