]> git.mjollnir.org Git - moodle.git/commitdiff
switch roles: MDL-18132 Convert allow override page to use the shared code.
authortjhunt <tjhunt>
Wed, 25 Mar 2009 02:17:14 +0000 (02:17 +0000)
committertjhunt <tjhunt>
Wed, 25 Mar 2009 02:17:14 +0000 (02:17 +0000)
admin/roles/allow.php [moved from admin/roles/allowassign.php with 76% similarity]
admin/roles/allowoverride.php [deleted file]
admin/roles/lib.php
admin/roles/managetabs.php
lang/en_utf8/error.php
lang/en_utf8/role.php
theme/standard/styles_layout.css

similarity index 76%
rename from admin/roles/allowassign.php
rename to admin/roles/allow.php
index 26206975079c73505c4cb4b597a55b1872a67b4a..d870e74fd988a0144d5cc803a206e7d3be535e8c 100755 (executable)
     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').'"/>';
diff --git a/admin/roles/allowoverride.php b/admin/roles/allowoverride.php
deleted file mode 100755 (executable)
index 1d1dd2f..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-<?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('&#xa0;');
-
-/// 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();
-?>
index a32ddba6833a682e463e8f11b52d1dc04b63bcd0..911f6b67b7354f9650efe2b32871d5a15c434406 100644 (file)
@@ -1257,31 +1257,22 @@ class existing_role_holders_site_admin extends existing_role_holders {
 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);
     }
 
     /**
@@ -1354,6 +1345,8 @@ abstract class role_allow_role_page {
 
         return $table;
     }
+
+    public abstract function get_intro_text();
 }
 
 class role_allow_assign_page extends role_allow_role_page {
@@ -1371,6 +1364,31 @@ 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
index efe8de986fdf59189f30d587f9808256b58a6e5e..bb969c67046a5d8062e3c567a102adef7f3ee6af 100755 (executable)
     }
 
     $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);
index fc423af5de6a1016bdef6f680aa87e4c44e9d5fb..023f984183e9eef60f4115d6c7bfdbe33f7e4716 100644 (file)
@@ -277,6 +277,7 @@ $string['invalidipformat'] = 'Invalid IP address format';
 $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';
index c778666282dfd2d652eb5c5314fdb8b4308ceb14..d5d2c9442fdf1639dc6e81b37a623b7f9e0c6172 100644 (file)
@@ -11,6 +11,7 @@ $string['allowed'] = 'Allowed';
 $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.';
index 5caa061c4d806a5555678b073e4f950bf46dc572..b9f930e542fb8fdb5a5ab687b5cbfbf9ba4e56b2 100644 (file)
@@ -1115,8 +1115,7 @@ body#admin-modules table.generaltable td.c0
 #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 {