3 * this page defines what roles can access (grant user that role and override that roles'
4 * capabilities in different context. For example, we can say that Teachers can only grant
5 * student role or modify student role's capabilities. Note that you need both the right
6 * capability moodle/role:assign or moodle/role:manage and this database table roles_deny_grant
7 * to be able to grant roles. If a user has moodle/role:manage at site level assignment
8 * then he can modify the roles_allow_assign table via this interface.
10 require_once('../../config.php');
11 require_once($CFG->libdir
.'/adminlib.php');
13 admin_externalpage_setup('defineroles', '', array(), $CFG->wwwroot
. '/' . $CFG->admin
. '/roles/allowassign.php');
15 $sitecontext = get_context_instance(CONTEXT_SYSTEM
);
16 require_capability('moodle/role:manage', $sitecontext);
18 /// form processiong here
22 $roles = get_all_roles();
24 if ($grant = data_submitted() and confirm_sesskey()) {
26 foreach ($grant as $grole => $val) {
27 if ($grole == 'dummy' or !strpos($grole, '_')) {
31 $string = explode('_', $grole);
32 $temp[$string[1]][$string[2]] = 1; // if set, means can access
35 // if current assignment is in data_submitted, ignore, else, write deny into db
36 foreach ($roles as $srole) {
37 foreach ($roles as $trole) {
38 if (isset($temp[$srole->id
][$trole->id
])) { // if set, need to write to db
39 if (!$record = get_record('role_allow_assign', 'roleid', $srole->id
, 'allowassign', $trole->id
)) {
40 allow_assign($srole->id
, $trole->id
);
42 } else { //if set, means can access, attempt to remove it from db
43 delete_records('role_allow_assign', 'roleid', $srole->id
, 'allowassign', $trole->id
);
47 // updated allowassigns sitewide...
48 mark_context_dirty($sitecontext->path
);
50 /// displaying form here
52 admin_externalpage_print_header();
54 $currenttab='allowassign';
55 require_once('managetabs.php');
57 $table->tablealign
= 'center';
58 $table->cellpadding
= 5;
59 $table->cellspacing
= 0;
60 $table->width
= '90%';
61 $table->align
[] = 'right';
63 /// get all the roles identifier
64 foreach ($roles as $role) {
65 $rolesname[] = format_string($role->name
);
66 $roleids[] = $role->id
;
67 $table->align
[] = 'center';
68 $table->wrap
[] = 'nowrap';
71 $table->head
= array_merge(array(''), $rolesname);
73 foreach ($roles as $role) {
74 $beta = get_box_list($role->id
, $roleids);
75 $table->data
[] = array_merge(array(format_string($role->name
)), $beta);
78 print_simple_box(get_string('configallowassign', 'admin'), 'center');
80 echo '<form action="allowassign.php" method="post">';
82 echo '<div class="buttons"><input type="submit" value="'.get_string('savechanges').'"/>';
83 echo '<input type="hidden" name="dummy" value="1" />'; // this is needed otherwise we do not know a form has been submitted
84 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
87 admin_externalpage_print_footer();
91 function get_box_list($roleid, $arraylist){
93 foreach ($arraylist as $targetid) {
94 if (get_record('role_allow_assign', 'roleid', $roleid, 'allowassign', $targetid)) {
95 $array[] = '<input type="checkbox" name="s_'.$roleid.'_'.$targetid.'" value="1" checked="checked"/>';
97 $array[] = '<input type="checkbox" name="s_'.$roleid.'_'.$targetid.'" value="1" />';