require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/' . $CFG->admin . '/roles/lib.php');
- admin_externalpage_setup('defineroles', '', array(), $CFG->wwwroot . '/' . $CFG->admin . '/roles/allowassign.php');
+ $mode = required_param('mode', PARAM_ACTION);
+ $classformode = array(
+ 'assign' => 'role_allow_assign_page',
+ 'override' => 'role_allow_override_page',
+ 'switch' => 'role_allow_switch_page'
+ );
+ if (!isset($classformode[$mode])) {
+ print_error('invalidmode', '', '', $mode);
+ }
+
+ $baseurl = $CFG->wwwroot . '/' . $CFG->admin . '/roles/allow.php?mode=' . $mode;
+ admin_externalpage_setup('defineroles', '', array(), $baseurl);
require_login();
- $controller = new role_allow_assign_page();
- require_capability('moodle/role:manage', $controller->get_context());
+ $syscontext = get_context_instance(CONTEXT_SYSTEM);
+ require_capability('moodle/role:manage', $syscontext);
+
+ $controller = new $classformode[$mode]();
if (optional_param('submit', false, PARAM_BOOL) && data_submitted() && confirm_sesskey()) {
$controller->process_submission();
- mark_context_dirty($this->systemcontext->path);
- add_to_log(SITEID, 'role', 'edit allow assign', 'admin/roles/allowassign.php', '', '', $USER->id);
- redirect($CFG->wwwroot . '/' . $CFG->admin . '/roles/allowassign.php');
+ mark_context_dirty($syscontext->path);
+ add_to_log(SITEID, 'role', 'edit allow ' . $mode, str_replace($CFG->wwwroot . '/', '', $baseurl), '', '', $USER->id);
+ redirect($baseurl);
}
$controller->load_current_settings();
/// Display the editing form.
admin_externalpage_print_header();
- $currenttab='allowassign';
+ $currenttab = $mode;
require_once('managetabs.php');
$table = $controller->get_table();
- print_simple_box(get_string('configallowassign', 'admin'), 'center');
+ print_simple_box($controller->get_intro_text(), 'center');
- echo '<form action="allowassign.php" method="post">';
+ echo '<form action="' . $baseurl . '" method="post">';
echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
print_table($table);
echo '<div class="buttons"><input type="submit" name="submit" value="'.get_string('savechanges').'"/>';
+++ /dev/null
-<?php // $Id$
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.org //
-// //
-// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-/**
- * this page defines what roles can override (override roles in different context. For example,
- * we can say that Admin can override teacher roles in a course
- * To be able to override roles. If a user has moodle/role:override at context level
- * and be in the roles_allow_override table.
- *
- * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
- * @package roles
- *//** */
-
- require_once('../../config.php');
- require_once($CFG->libdir.'/adminlib.php');
-
- require_login();
- $systemcontext = get_context_instance(CONTEXT_SYSTEM);
- require_capability('moodle/role:manage', $systemcontext);
-
-/// Get all roles
- $roles = get_all_roles();
- role_fix_names($roles, $systemcontext, ROLENAME_ORIGINAL);
-
-/// Process form submission
- if (optional_param('submit', false, PARAM_BOOL) && data_submitted() && confirm_sesskey()) {
- /// Delete all records, then add back the ones that should be allowed.
- $DB->delete_records('role_allow_override');
- foreach ($roles as $fromroleid => $notused) {
- foreach ($roles as $targetroleid => $alsonotused) {
- if (optional_param('s_' . $fromroleid . '_' . $targetroleid, false, PARAM_BOOL)) {
- allow_override($fromroleid, $targetroleid);
- }
- }
- }
-
- /// Updated allowoverrides sitewide, so force a premissions refresh, and redirect.
- mark_context_dirty($systemcontext->path);
- add_to_log(SITEID, 'role', 'edit allow override', 'admin/roles/allowoverride.php', '', '', $USER->id);
- redirect($CFG->wwwroot . '/' . $CFG->admin . '/roles/allowoverride.php');
- }
-
-/// Load the current settings
- $allowed = array();
- foreach ($roles as $role) {
- // Make an array $role->id => false. This is probalby too clever for its own good.1
- $allowed[$role->id] = array_combine(array_keys($roles), array_fill(0, count($roles), false));
- }
- $raas = $DB->get_recordset('role_allow_override');
- foreach ($raas as $raa) {
- $allowed[$raa->roleid][$raa->allowoverride] = true;
- }
-
-/// Display the editing form.
- admin_externalpage_setup('defineroles', '', array(), $CFG->wwwroot . '/' . $CFG->admin . '/roles/allowoverride.php');
- admin_externalpage_print_header();
-
- $currenttab='allowoverride';
- require_once('managetabs.php');
-
- $table->tablealign = 'center';
- $table->cellpadding = 5;
- $table->cellspacing = 0;
- $table->width = '90%';
- $table->align[] = 'left';
- $table->rotateheaders = true;
- $table->head = array(' ');
-
-/// Add role name headers.
- foreach ($roles as $targetrole) {
- $table->head[] = $targetrole->localname;
- $table->align[] = 'left';
- }
-
-/// Now the rest of the table.
- foreach ($roles as $fromrole) {
- $row = array($fromrole->localname);
- $a = new stdClass;
- $a->fromrole = $fromrole->localname;
- foreach ($roles as $targetrole) {
- if ($allowed[$fromrole->id][$targetrole->id]) {
- $checked = ' checked="checked"';
- } else {
- $checked = '';
- }
- $a->targetrole = $targetrole->localname;
- $name = 's_' . $fromrole->id . '_' . $targetrole->id;
- $tooltip = get_string('allowroletooverride', 'role', $a);
- $row[] = '<input type="checkbox" name="' . $name . '" id="' . $name . '" title="' . $tooltip . '" value="1"' . $checked . ' />' .
- '<label for="' . $name . '" class="accesshide">' . $tooltip . '</label>';
- }
- $table->data[] = $row;
- }
-
- print_simple_box(get_string('configallowoverride2', 'admin'), 'center');
-
- echo '<form action="allowoverride.php" method="post">';
- echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
- print_table($table);
- echo '<div class="buttons"><input type="submit" name="submit" value="'.get_string('savechanges').'"/>';
- echo '</div></form>';
-
- admin_externalpage_print_footer();
-?>
abstract class role_allow_role_page {
protected $tablename;
protected $targetcolname;
- protected $systemcontext;
protected $roles;
protected $allowed = null;
public function __construct($tablename, $targetcolname) {
$this->tablename = $tablename;
$this->targetcolname = $targetcolname;
- $this->systemcontext = get_context_instance(CONTEXT_SYSTEM);
$this->load_required_roles();
}
- /**
- * @return object the context we need. (The system context.)
- */
- public function get_context() {
- return $this->systemcontext;
- }
-
/**
* Load all the roles we will need information about.
*/
protected function load_required_roles() {
/// Get all roles
$this->roles = get_all_roles();
- role_fix_names($this->roles, $this->systemcontext, ROLENAME_ORIGINAL);
+ role_fix_names($this->roles, get_context_instance(CONTEXT_SYSTEM), ROLENAME_ORIGINAL);
}
/**
return $table;
}
+
+ public abstract function get_intro_text();
}
class role_allow_assign_page extends role_allow_role_page {
$a->targetrole = $targetrole->localname;
return get_string('allowroletoassign', 'role', $a);
}
+
+ public function get_intro_text() {
+ return get_string('configallowassign', 'admin');
+ }
+}
+
+class role_allow_override_page extends role_allow_role_page {
+ public function __construct() {
+ parent::__construct('role_allow_override', 'allowoverride');
+ }
+
+ protected function set_allow($fromroleid, $targetroleid) {
+ allow_override($fromroleid, $targetroleid);
+ }
+
+ protected function get_cell_tooltip($fromrole, $targetrole) {
+ $a = new stdClass;
+ $a->fromrole = $fromrole->localname;
+ $a->targetrole = $targetrole->localname;
+ return get_string('allowroletooverride', 'role', $a);
+ }
+
+ public function get_intro_text() {
+ return get_string('configallowoverride2', 'admin');
+ }
}
?>
\ No newline at end of file
}
$toprow = array();
-
$toprow[] = new tabobject('manage', $CFG->wwwroot.'/'.$CFG->admin.'/roles/manage.php', get_string('manageroles', 'role'));
-
- $toprow[] = new tabobject('allowassign', $CFG->wwwroot.'/'.$CFG->admin.'/roles/allowassign.php', get_string('allowassign', 'role'));
-
- $toprow[] = new tabobject('allowoverride', $CFG->wwwroot.'/'.$CFG->admin.'/roles/allowoverride.php', get_string('allowoverride', 'role'));
-
+ $toprow[] = new tabobject('assign', $CFG->wwwroot.'/'.$CFG->admin.'/roles/allow.php?mode=assign', get_string('allowassign', 'role'));
+ $toprow[] = new tabobject('override', $CFG->wwwroot.'/'.$CFG->admin.'/roles/allow.php?mode=override', get_string('allowoverride', 'role'));
+ $toprow[] = new tabobject('switch', $CFG->wwwroot.'/'.$CFG->admin.'/roles/allow.php?mode=switch', get_string('allowswitch', 'role'));
$tabs = array($toprow);
print_tabs($tabs, $currenttab);
$string['invalidlegacy'] = 'Incorrect legacy role definition for type: $a';
$string['invalidkey'] = 'Incorrect key';
$string['invalidmd5'] = 'Invalid md5';
+$string['invalidmode'] = 'Invalid mode ($a)';
$string['invalidmodule'] = 'Invalid module';
$string['invalidmoduleid'] = 'Invalid module ID: $a';
$string['invalidmodulename'] = 'Invalid module name: $a';
$string['allowoverride'] = 'Allow role overrides';
$string['allowroletoassign'] = 'Allow users with role $a->fromrole to assign the role $a->targetrole';
$string['allowroletooverride'] = 'Allow users with role $a->fromrole to override the role $a->targetrole';
+$string['allowswitch'] = 'Allow role switches';
$string['allsiteusers'] = 'All site users';
$string['assignanotherrole'] = 'Assign another role';
$string['assignerror'] = 'Error while assigning the role $a->role to user $a->user.';
#admin-qtypes #qtypes img.spacer {
width: 16px;
}
-#admin-roles-allowassign .buttons,
-#admin-roles-allowoverride .buttons,
+#admin-roles-allow .buttons,
#admin-roles-manage .buttons,
#admin-roles-define .buttons,
#admin-roles-override .buttons {