Differences Between: [Versions 311 and 402] [Versions 311 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 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. 8 // 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. 13 // 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/>. 16 17 /** 18 * Select site administrators. 19 * 20 * @package core_role 21 * @copyright 2010 Petr Skoda {@link http://skodak.org} 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 require_once(__DIR__ . '/../../config.php'); 26 require_once($CFG->libdir.'/adminlib.php'); 27 28 $confirmadd = optional_param('confirmadd', 0, PARAM_INT); 29 $confirmdel = optional_param('confirmdel', 0, PARAM_INT); 30 31 $PAGE->set_url('/admin/roles/admins.php'); 32 33 admin_externalpage_setup('admins'); 34 if (!is_siteadmin()) { 35 die; 36 } 37 38 $admisselector = new core_role_admins_existing_selector(); 39 $potentialadmisselector = new core_role_admins_potential_selector(); 40 41 if (optional_param('add', false, PARAM_BOOL) and confirm_sesskey()) { 42 if ($userstoadd = $potentialadmisselector->get_selected_users()) { 43 $user = reset($userstoadd); 44 $username = $potentialadmisselector->output_user($user); 45 echo $OUTPUT->header(); 46 $yesurl = new moodle_url('/admin/roles/admins.php', array('confirmadd'=>$user->id, 'sesskey'=>sesskey())); 47 echo $OUTPUT->confirm(get_string('confirmaddadmin', 'core_role', $username), $yesurl, $PAGE->url); 48 echo $OUTPUT->footer(); 49 die; 50 } 51 52 } else if (optional_param('remove', false, PARAM_BOOL) and confirm_sesskey()) { 53 if ($userstoremove = $admisselector->get_selected_users()) { 54 $user = reset($userstoremove); 55 if ($USER->id == $user->id) { 56 // Can not remove self. 57 } else { 58 $username = $admisselector->output_user($user); 59 echo $OUTPUT->header(); 60 $yesurl = new moodle_url('/admin/roles/admins.php', array('confirmdel'=>$user->id, 'sesskey'=>sesskey())); 61 echo $OUTPUT->confirm(get_string('confirmdeladmin', 'core_role', $username), $yesurl, $PAGE->url); 62 echo $OUTPUT->footer(); 63 die; 64 } 65 } 66 67 } else if (optional_param('main', false, PARAM_BOOL) and confirm_sesskey()) { 68 if ($newmain = $admisselector->get_selected_users()) { 69 $newmain = reset($newmain); 70 $newmain = $newmain->id; 71 $admins = array(); 72 foreach (explode(',', $CFG->siteadmins) as $admin) { 73 $admin = (int)$admin; 74 if ($admin) { 75 $admins[$admin] = $admin; 76 } 77 } 78 79 if (isset($admins[$newmain])) { 80 $logstringold = implode(', ', $admins); 81 82 unset($admins[$newmain]); 83 array_unshift($admins, $newmain); 84 85 $logstringnew = implode(', ', $admins); 86 87 set_config('siteadmins', implode(',', $admins)); 88 add_to_config_log('siteadmins', $logstringold, $logstringnew, null); 89 90 redirect($PAGE->url); 91 } 92 } 93 94 } else if ($confirmadd and confirm_sesskey()) { 95 $admins = array(); 96 foreach (explode(',', $CFG->siteadmins) as $admin) { 97 $admin = (int)$admin; 98 if ($admin) { 99 $admins[$admin] = $admin; 100 } 101 } 102 103 $logstringold = implode(', ', $admins); 104 105 $admins[$confirmadd] = $confirmadd; 106 107 $logstringnew = implode(', ', $admins); 108 109 set_config('siteadmins', implode(',', $admins)); 110 add_to_config_log('siteadmins', $logstringold, $logstringnew, 'core'); 111 112 redirect($PAGE->url); 113 114 } else if ($confirmdel and confirm_sesskey() and $confirmdel != $USER->id) { 115 $admins = array(); 116 foreach (explode(',', $CFG->siteadmins) as $admin) { 117 $admin = (int)$admin; 118 if ($admin) { 119 $admins[$admin] = $admin; 120 } 121 } 122 123 $logstringold = implode(', ', $admins); 124 125 unset($admins[$confirmdel]); 126 127 $logstringnew = implode(', ', $admins); 128 129 set_config('siteadmins', implode(',', $admins)); 130 add_to_config_log('siteadmins', $logstringold, $logstringnew, 'core'); 131 132 redirect($PAGE->url); 133 } 134 135 // Print header. 136 echo $OUTPUT->header(); 137 ?> 138 139 <div id="addadmisform"> 140 <h3 class="main"><?php print_string('manageadmins', 'core_role'); ?></h3> 141 142 <form id="assignform" method="post" action="<?php echo $PAGE->url ?>"> 143 <div> 144 <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" /> 145 146 <table class="generaltable generalbox groupmanagementtable boxaligncenter" summary=""> 147 <tr> 148 <td id='existingcell'> 149 <p> 150 <label for="removeselect"><?php print_string('existingadmins', 'core_role'); ?></label> 151 </p> 152 <?php $admisselector->display(); ?> 153 </td> 154 <td id="buttonscell"> 155 <p class="arrow_button"> 156 <input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().' '.get_string('add'); ?>" 157 title="<?php print_string('add'); ?>" class="btn btn-secondary"/><br /> 158 <input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').' '.$OUTPUT->rarrow(); ?>" 159 title="<?php print_string('remove'); ?>" class="btn btn-secondary"/><br /> 160 <input name="main" id="main" type="submit" value="<?php echo get_string('mainadminset', 'core_role'); ?>" 161 title="<?php print_string('mainadminset', 'core_role'); ?>" class="btn btn-secondary"/> 162 </p> 163 </td> 164 <td id="potentialcell"> 165 <p> 166 <label for="addselect"><?php print_string('users'); ?></label> 167 </p> 168 <?php $potentialadmisselector->display(); ?> 169 </td> 170 </tr> 171 </table> 172 </div> 173 </form> 174 </div> 175 176 <?php 177 178 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body