Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/roles/admins.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 require_once(dirname(__FILE__) . '/../../config.php');
00028 require_once($CFG->dirroot . '/' . $CFG->admin . '/roles/lib.php');
00029 
00030 $confirmadd = optional_param('confirmadd', 0, PARAM_INT);
00031 $confirmdel = optional_param('confirmdel', 0, PARAM_INT);
00032 
00033 $PAGE->set_url('/admin/roles/admins.php');
00034 
00035 admin_externalpage_setup('admins');
00036 if (!is_siteadmin()) {
00037     die;
00038 }
00039 
00040 $admisselector = new admins_existing_selector();
00041 $admisselector->set_extra_fields(array('username', 'email'));
00042 
00043 $potentialadmisselector = new admins_potential_selector();
00044 $potentialadmisselector->set_extra_fields(array('username', 'email'));
00045 
00046 if (optional_param('add', false, PARAM_BOOL) and confirm_sesskey()) {
00047     if ($userstoadd = $potentialadmisselector->get_selected_users()) {
00048         $user = reset($userstoadd);
00049         $username = fullname($user) . " ($user->username, $user->email)";
00050         echo $OUTPUT->header();
00051         echo $OUTPUT->confirm(get_string('confirmaddadmin', 'role', $username), new moodle_url('/admin/roles/admins.php', array('confirmadd'=>$user->id, 'sesskey'=>sesskey())), $PAGE->url);
00052         echo $OUTPUT->footer();
00053         die;
00054     }
00055 
00056 } else if (optional_param('remove', false, PARAM_BOOL) and confirm_sesskey()) {
00057     if ($userstoremove = $admisselector->get_selected_users()) {
00058         $user = reset($userstoremove);
00059         if ($USER->id == $user->id) {
00060             //can not remove self
00061         } else {
00062             $username = fullname($user) . " ($user->username, $user->email)";
00063             echo $OUTPUT->header();
00064             echo $OUTPUT->confirm(get_string('confirmdeladmin', 'role', $username), new moodle_url('/admin/roles/admins.php', array('confirmdel'=>$user->id, 'sesskey'=>sesskey())), $PAGE->url);
00065             echo $OUTPUT->footer();
00066             die;
00067         }
00068     }
00069 
00070 } else if (optional_param('main', false, PARAM_BOOL) and confirm_sesskey()) {
00071     if ($newmain = $admisselector->get_selected_users()) {
00072         $newmain = reset($newmain);
00073         $newmain = $newmain->id;
00074         $admins = array();
00075         foreach(explode(',', $CFG->siteadmins) as $admin) {
00076             $admin = (int)$admin;
00077             if ($admin) {
00078                 $admins[$admin] = $admin;
00079             }
00080         }
00081 
00082         if (isset($admins[$newmain])) {
00083             unset($admins[$newmain]);
00084             array_unshift($admins, $newmain);
00085             set_config('siteadmins', implode(',', $admins));
00086             redirect($PAGE->url);
00087         }
00088     }
00089 
00090 } else if ($confirmadd and confirm_sesskey()) {
00091     $admins = array();
00092     foreach(explode(',', $CFG->siteadmins) as $admin) {
00093         $admin = (int)$admin;
00094         if ($admin) {
00095             $admins[$admin] = $admin;
00096         }
00097     }
00098     $admins[$confirmadd] = $confirmadd;
00099     set_config('siteadmins', implode(',', $admins));
00100     redirect($PAGE->url);
00101 
00102 } else if ($confirmdel and confirm_sesskey() and $confirmdel != $USER->id) {
00103     $admins = array();
00104     foreach(explode(',', $CFG->siteadmins) as $admin) {
00105         $admin = (int)$admin;
00106         if ($admin) {
00107             $admins[$admin] = $admin;
00108         }
00109     }
00110     unset($admins[$confirmdel]);
00111     set_config('siteadmins', implode(',', $admins));
00112     redirect($PAGE->url);
00113 }
00114 
00116 echo $OUTPUT->header();
00117 ?>
00118 
00119 <div id="addadmisform">
00120     <h3 class="main"><?php print_string('manageadmins', 'role'); ?></h3>
00121 
00122     <form id="assignform" method="post" action="<?php echo $PAGE->url ?>">
00123     <div>
00124     <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
00125 
00126     <table class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">
00127     <tr>
00128       <td id='existingcell'>
00129           <p>
00130             <label for="removeselect"><?php print_string('existingadmins', 'role'); ?></label>
00131           </p>
00132           <?php $admisselector->display(); ?>
00133           </td>
00134       <td id='buttonscell'>
00135         <p class="arrow_button">
00136             <input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
00137             <input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').'&nbsp;'.$OUTPUT->rarrow(); ?>" title="<?php print_string('remove'); ?>" />
00138             <input name="main" id="main" type="submit" value="<?php echo get_string('mainadminset', 'role'); ?>" title="<?php print_string('mainadminset', 'role'); ?>" />
00139         </p>
00140       </td>
00141       <td id='potentialcell'>
00142           <p>
00143             <label for="addselect"><?php print_string('users'); ?></label>
00144           </p>
00145           <?php $potentialadmisselector->display(); ?>
00146       </td>
00147     </tr>
00148     </table>
00149     </div>
00150     </form>
00151 </div>
00152 
00153 <?php
00154 
00155 //this must be after calling display() on the selectors so their setup JS executes first
00157 
00158 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations