MDL-33468 css_optimiser: Improved consolidation of background styles and fixed orderi...
[moodle.git] / admin / roles / admins.php
blob1f5a8fe72174c72aedd3d7a0bef5b25d46b3c2ef
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Lets you site administrators
21 * @package core
22 * @subpackage role
23 * @copyright 2010 Petr Skoda (skodak) http://skodak.org
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require_once(dirname(__FILE__) . '/../../config.php');
28 require_once($CFG->dirroot . '/' . $CFG->admin . '/roles/lib.php');
30 $confirmadd = optional_param('confirmadd', 0, PARAM_INT);
31 $confirmdel = optional_param('confirmdel', 0, PARAM_INT);
33 $PAGE->set_url('/admin/roles/admins.php');
35 admin_externalpage_setup('admins');
36 if (!is_siteadmin()) {
37 die;
40 $admisselector = new admins_existing_selector();
41 $admisselector->set_extra_fields(array('username', 'email'));
43 $potentialadmisselector = new admins_potential_selector();
44 $potentialadmisselector->set_extra_fields(array('username', 'email'));
46 if (optional_param('add', false, PARAM_BOOL) and confirm_sesskey()) {
47 if ($userstoadd = $potentialadmisselector->get_selected_users()) {
48 $user = reset($userstoadd);
49 $username = fullname($user) . " ($user->username, $user->email)";
50 echo $OUTPUT->header();
51 echo $OUTPUT->confirm(get_string('confirmaddadmin', 'role', $username), new moodle_url('/admin/roles/admins.php', array('confirmadd'=>$user->id, 'sesskey'=>sesskey())), $PAGE->url);
52 echo $OUTPUT->footer();
53 die;
56 } else if (optional_param('remove', false, PARAM_BOOL) and confirm_sesskey()) {
57 if ($userstoremove = $admisselector->get_selected_users()) {
58 $user = reset($userstoremove);
59 if ($USER->id == $user->id) {
60 //can not remove self
61 } else {
62 $username = fullname($user) . " ($user->username, $user->email)";
63 echo $OUTPUT->header();
64 echo $OUTPUT->confirm(get_string('confirmdeladmin', 'role', $username), new moodle_url('/admin/roles/admins.php', array('confirmdel'=>$user->id, 'sesskey'=>sesskey())), $PAGE->url);
65 echo $OUTPUT->footer();
66 die;
70 } else if (optional_param('main', false, PARAM_BOOL) and confirm_sesskey()) {
71 if ($newmain = $admisselector->get_selected_users()) {
72 $newmain = reset($newmain);
73 $newmain = $newmain->id;
74 $admins = array();
75 foreach(explode(',', $CFG->siteadmins) as $admin) {
76 $admin = (int)$admin;
77 if ($admin) {
78 $admins[$admin] = $admin;
82 if (isset($admins[$newmain])) {
83 unset($admins[$newmain]);
84 array_unshift($admins, $newmain);
85 set_config('siteadmins', implode(',', $admins));
86 redirect($PAGE->url);
90 } else if ($confirmadd and confirm_sesskey()) {
91 $admins = array();
92 foreach(explode(',', $CFG->siteadmins) as $admin) {
93 $admin = (int)$admin;
94 if ($admin) {
95 $admins[$admin] = $admin;
98 $admins[$confirmadd] = $confirmadd;
99 set_config('siteadmins', implode(',', $admins));
100 redirect($PAGE->url);
102 } else if ($confirmdel and confirm_sesskey() and $confirmdel != $USER->id) {
103 $admins = array();
104 foreach(explode(',', $CFG->siteadmins) as $admin) {
105 $admin = (int)$admin;
106 if ($admin) {
107 $admins[$admin] = $admin;
110 unset($admins[$confirmdel]);
111 set_config('siteadmins', implode(',', $admins));
112 redirect($PAGE->url);
115 /// Print header
116 echo $OUTPUT->header();
119 <div id="addadmisform">
120 <h3 class="main"><?php print_string('manageadmins', 'role'); ?></h3>
122 <form id="assignform" method="post" action="<?php echo $PAGE->url ?>">
123 <div>
124 <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
126 <table class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">
127 <tr>
128 <td id='existingcell'>
130 <label for="removeselect"><?php print_string('existingadmins', 'role'); ?></label>
131 </p>
132 <?php $admisselector->display(); ?>
133 </td>
134 <td id='buttonscell'>
135 <p class="arrow_button">
136 <input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
137 <input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').'&nbsp;'.$OUTPUT->rarrow(); ?>" title="<?php print_string('remove'); ?>" />
138 <input name="main" id="main" type="submit" value="<?php echo get_string('mainadminset', 'role'); ?>" title="<?php print_string('mainadminset', 'role'); ?>" />
139 </p>
140 </td>
141 <td id='potentialcell'>
143 <label for="addselect"><?php print_string('users'); ?></label>
144 </p>
145 <?php $potentialadmisselector->display(); ?>
146 </td>
147 </tr>
148 </table>
149 </div>
150 </form>
151 </div>
153 <?php
155 //this must be after calling display() on the selectors so their setup JS executes first
156 //////$PAGE->requires->js_function_call('init_add_remove_admis_page');
158 echo $OUTPUT->footer();