2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Select site administrators.
21 * @copyright 2010 Petr Skoda {@link http://skodak.org}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once(__DIR__
. '/../../config.php');
26 require_once($CFG->libdir
.'/adminlib.php');
28 $confirmadd = optional_param('confirmadd', 0, PARAM_INT
);
29 $confirmdel = optional_param('confirmdel', 0, PARAM_INT
);
31 $PAGE->set_url('/admin/roles/admins.php');
33 admin_externalpage_setup('admins');
34 if (!is_siteadmin()) {
38 $admisselector = new core_role_admins_existing_selector();
39 $admisselector->set_extra_fields(array('username', 'email'));
41 $potentialadmisselector = new core_role_admins_potential_selector();
42 $potentialadmisselector->set_extra_fields(array('username', 'email'));
44 if (optional_param('add', false, PARAM_BOOL
) and confirm_sesskey()) {
45 if ($userstoadd = $potentialadmisselector->get_selected_users()) {
46 $user = reset($userstoadd);
47 $username = fullname($user) . " ($user->username, $user->email)";
48 echo $OUTPUT->header();
49 $yesurl = new moodle_url('/admin/roles/admins.php', array('confirmadd'=>$user->id
, 'sesskey'=>sesskey()));
50 echo $OUTPUT->confirm(get_string('confirmaddadmin', 'core_role', $username), $yesurl, $PAGE->url
);
51 echo $OUTPUT->footer();
55 } else if (optional_param('remove', false, PARAM_BOOL
) and confirm_sesskey()) {
56 if ($userstoremove = $admisselector->get_selected_users()) {
57 $user = reset($userstoremove);
58 if ($USER->id
== $user->id
) {
59 // Can not remove self.
61 $username = fullname($user) . " ($user->username, $user->email)";
62 echo $OUTPUT->header();
63 $yesurl = new moodle_url('/admin/roles/admins.php', array('confirmdel'=>$user->id
, 'sesskey'=>sesskey()));
64 echo $OUTPUT->confirm(get_string('confirmdeladmin', 'core_role', $username), $yesurl, $PAGE->url
);
65 echo $OUTPUT->footer();
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
;
75 foreach (explode(',', $CFG->siteadmins
) as $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));
90 } else if ($confirmadd and confirm_sesskey()) {
92 foreach (explode(',', $CFG->siteadmins
) as $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
) {
104 foreach (explode(',', $CFG->siteadmins
) as $admin) {
105 $admin = (int)$admin;
107 $admins[$admin] = $admin;
110 unset($admins[$confirmdel]);
111 set_config('siteadmins', implode(',', $admins));
112 redirect($PAGE->url
);
116 echo $OUTPUT->header();
119 <div id
="addadmisform">
120 <h3
class="main"><?php
print_string('manageadmins', 'core_role'); ?
></h3
>
122 <form id
="assignform" method
="post" action
="<?php echo $PAGE->url ?>">
124 <input type
="hidden" name
="sesskey" value
="<?php p(sesskey()); ?>" />
126 <table
class="generaltable generalbox groupmanagementtable boxaligncenter" summary
="">
128 <td id
='existingcell'>
130 <label
for="removeselect"><?php
print_string('existingadmins', 'core_role'); ?
></label
>
132 <?php
$admisselector->display(); ?
>
134 <td id
="buttonscell">
135 <p
class="arrow_button">
136 <input name
="add" id
="add" type
="submit" value
="<?php echo $OUTPUT->larrow().' '.get_string('add'); ?>" title
="<?php print_string('add'); ?>" /><br
/>
137 <input name
="remove" id
="remove" type
="submit" value
="<?php echo get_string('remove').' '.$OUTPUT->rarrow(); ?>" title
="<?php print_string('remove'); ?>" />
138 <input name
="main" id
="main" type
="submit" value
="<?php echo get_string('mainadminset', 'core_role'); ?>" title
="<?php print_string('mainadminset', 'core_role'); ?>" />
141 <td id
="potentialcell">
143 <label
for="addselect"><?php
print_string('users'); ?
></label
>
145 <?php
$potentialadmisselector->display(); ?
>
155 echo $OUTPUT->footer();