2002-12-11 14:59:37 +00:00
|
|
|
<?PHP // $Id$
|
|
|
|
// Admin-only script to assign administrative rights to users
|
2003-05-14 15:19:04 +00:00
|
|
|
|
2005-05-16 19:38:21 +00:00
|
|
|
require_once("../config.php");
|
2003-05-14 15:58:48 +00:00
|
|
|
|
2003-08-27 13:42:01 +00:00
|
|
|
define("MAX_USERS_PER_PAGE", 50);
|
2002-12-11 14:59:37 +00:00
|
|
|
|
2005-06-15 12:31:09 +00:00
|
|
|
$add = optional_param('add', "", PARAM_ALPHA);
|
|
|
|
$remove = optional_param('remove', '', PARAM_ALPHA);
|
|
|
|
$search = optional_param('search', '', PARAM_ALPHA);
|
2002-12-11 14:59:37 +00:00
|
|
|
|
|
|
|
if (! $site = get_site()) {
|
2003-04-10 13:46:52 +00:00
|
|
|
redirect("$CFG->wwwroot/$CFG->admin/index.php");
|
2002-12-11 14:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require_login();
|
|
|
|
|
|
|
|
if (!isadmin()) {
|
|
|
|
error("You must be an administrator to use this page.");
|
|
|
|
}
|
|
|
|
|
2004-10-02 19:22:52 +00:00
|
|
|
if (!confirm_sesskey()) {
|
|
|
|
error(get_string('confirmsesskeybad', 'error'));
|
|
|
|
}
|
|
|
|
|
2002-12-11 14:59:37 +00:00
|
|
|
$primaryadmin = get_admin();
|
|
|
|
|
|
|
|
/// If you want any administrator to have the ability to assign admin
|
|
|
|
/// rights, then comment out the following if statement
|
|
|
|
if ($primaryadmin->id != $USER->id) {
|
|
|
|
error("You must be the primary administrator to use this page.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// assign all of the configurable language strings
|
|
|
|
$stringstoload = array (
|
|
|
|
"assignadmins",
|
|
|
|
"administration",
|
|
|
|
"existingadmins",
|
|
|
|
"potentialadmins",
|
|
|
|
"search",
|
2003-08-10 08:01:14 +00:00
|
|
|
"users",
|
2004-08-05 09:24:16 +00:00
|
|
|
"searchresults",
|
|
|
|
"showall"
|
2002-12-11 14:59:37 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($stringstoload as $stringtoload){
|
|
|
|
$strstringtoload = "str" . $stringtoload;
|
|
|
|
$$strstringtoload = get_string($stringtoload);
|
|
|
|
}
|
|
|
|
|
2005-05-16 19:38:21 +00:00
|
|
|
print_header("$site->shortname: $strassignadmins",
|
2002-12-11 14:59:37 +00:00
|
|
|
"$site->fullname",
|
2004-08-05 09:24:16 +00:00
|
|
|
"<a href=\"index.php\">$stradministration</a> -> <a href=\"users.php\">$strusers</a> -> $strassignadmins", "adminform.searchtext");
|
2002-12-11 14:59:37 +00:00
|
|
|
|
|
|
|
|
2004-08-05 09:24:16 +00:00
|
|
|
if (!$frm = data_submitted()) {
|
2003-08-18 03:47:49 +00:00
|
|
|
print_simple_box("<center>".get_string("adminhelpassignadmins")."</center>", "center", "50%");
|
2002-12-11 14:59:37 +00:00
|
|
|
|
2004-08-05 09:24:16 +00:00
|
|
|
/// A form was submitted so process the input
|
|
|
|
|
2002-12-11 14:59:37 +00:00
|
|
|
} else {
|
2004-08-05 09:24:16 +00:00
|
|
|
if (!empty($frm->add) and !empty($frm->addselect)) {
|
|
|
|
foreach ($frm->addselect as $addadmin) {
|
|
|
|
if (! add_admin($addadmin)) {
|
|
|
|
error("Could not add admin with user id $addadmin!");
|
|
|
|
}
|
2002-12-11 14:59:37 +00:00
|
|
|
}
|
2004-08-05 09:24:16 +00:00
|
|
|
} else if (!empty($frm->remove) and !empty($frm->removeselect)) {
|
|
|
|
$admins = get_admins();
|
|
|
|
if (count($admins) > count($frm->removeselect)) {
|
|
|
|
foreach ($frm->removeselect as $removeadmin) {
|
|
|
|
if (! remove_admin($removeadmin)) {
|
|
|
|
error("Could not remove admin with user id $removeadmin!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!empty($frm->showall)) {
|
|
|
|
unset($frm->searchtext);
|
|
|
|
$frm->previoussearch = 0;
|
2002-12-11 14:59:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-05 09:24:16 +00:00
|
|
|
/// Is there a current search?
|
|
|
|
$previoussearch = (!empty($frm->search) or ($frm->previoussearch == 1)) ;
|
2002-12-11 14:59:37 +00:00
|
|
|
|
2004-08-05 09:24:16 +00:00
|
|
|
/// Get all existing admins
|
|
|
|
$admins = get_admins();
|
2002-12-11 14:59:37 +00:00
|
|
|
|
|
|
|
|
2004-08-05 09:24:16 +00:00
|
|
|
$adminarray = array();
|
|
|
|
foreach ($admins as $admin) {
|
|
|
|
$adminarray[] = $admin->id;
|
|
|
|
}
|
|
|
|
$adminlist = implode(',', $adminarray);
|
2002-12-11 14:59:37 +00:00
|
|
|
|
2004-08-05 09:24:16 +00:00
|
|
|
unset($adminarray);
|
2002-12-11 14:59:37 +00:00
|
|
|
|
2003-05-14 15:19:04 +00:00
|
|
|
|
2004-08-05 09:24:16 +00:00
|
|
|
/// Get search results excluding any current admins
|
|
|
|
if (!empty($frm->searchtext) and $previoussearch) {
|
|
|
|
$searchusers = get_users(true, $frm->searchtext, true, $adminlist, 'firstname ASC, lastname ASC',
|
|
|
|
'', '', 0, 99999, 'id, firstname, lastname, email');
|
|
|
|
$usercount = get_users(false, '', true, $adminlist);
|
|
|
|
}
|
2003-05-14 15:19:04 +00:00
|
|
|
|
2004-08-05 09:24:16 +00:00
|
|
|
/// If no search results then get potential users excluding current admins
|
|
|
|
if (empty($searchusers)) {
|
|
|
|
if (!$users = get_users(true, '', true, $adminlist, 'firstname ASC, lastname ASC', '', '',
|
|
|
|
0, 99999, 'id, firstname, lastname, email') ) {
|
|
|
|
$users = array();
|
2002-12-11 14:59:37 +00:00
|
|
|
}
|
2004-08-05 09:24:16 +00:00
|
|
|
$usercount = count($users);
|
2002-12-11 14:59:37 +00:00
|
|
|
}
|
|
|
|
|
2004-08-05 09:24:16 +00:00
|
|
|
$searchtext = (isset($frm->searchtext)) ? $frm->searchtext : "";
|
|
|
|
$previoussearch = ($previoussearch) ? '1' : '0';
|
2003-05-14 15:19:04 +00:00
|
|
|
|
2004-08-05 09:24:16 +00:00
|
|
|
include('./admin.html');
|
2002-12-11 14:59:37 +00:00
|
|
|
|
|
|
|
print_footer();
|
|
|
|
|
|
|
|
?>
|