wwwroot/$CFG->admin/index.php"); } require_login(); if (!isadmin()) { error("You must be an administrator to use this page."); } $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", "noexistingadmins", "potentialadmins", "nopotentialadmins", "addadmin", "removeadmin", "search", "searchagain", "toomanytoshow", "searchresults" ); foreach ($stringstoload as $stringtoload){ $strstringtoload = "str" . $stringtoload; $$strstringtoload = get_string($stringtoload); } print_header("$site->shortname: $course->shortname: $strassignadmins", "$site->fullname", "$stradministration -> $strassignadmins", ""); /// Get all existing admins $admins = get_admins(); /// Add an admin if one is specified if ($_REQUEST['add']) { $user = @get_record("user", "id", $_REQUEST['add']) or error("That account (id = {$_REQUEST['add']}) doesn't exist"); if ($admins) { foreach ($admins as $aa) { if ($aa->id == $user->id) { error("That user is already an admin."); } } } $admin->userid = $user->id; $admin->id = insert_record("user_admins", $admin); $admins[] = $user; } /// Remove an admin if one is specified. if ($_REQUEST['remove']) { $user = @get_record("user", "id", $_REQUEST['remove']) or error("That account (id = {$_REQUEST['remove']}) doesn't exist"); if ($admins) { foreach ($admins as $key => $aa) { if ($aa->id == $user->id) { /// make sure that we don't delete the primary admin /// account, so that there is always at least on admin if ($aa->id == $primaryadmin->id) { error("That user is the primary admin, and shouldn't be removed."); } else { remove_admin($user->id); unset($admins[$key]); } } } } } /// Print the lists of existing and potential admins echo ""; echo ""; echo "
$strexistingadmins$strpotentialadmins
"; /// First, show existing admins if (! $admins) { echo "

$strnoexistingadmins"; } else { foreach ($admins as $admin) { echo "

$admin->firstname $admin->lastname, $admin->email    "; if ($primaryadmin->id == $admin->id){ print_spacer(10, 9, false); } else { echo "id\" TITLE=\"$strremoveadmin\">"; } echo "

"; } } echo "
"; /// Print list of potential admins if ($search) { $users = get_users_search($search); } else { $users = get_users_confirmed(); } if ($users) { foreach ($users as $user) { // Remove users who are already admins if ($admins) { foreach ($admins as $admin) { if ($admin->id == $user->id) { continue 2; } } } $potential[] = $user; } } if (! $potential) { echo "

$strnopotentialadmins"; if ($search) { echo "

"; echo ""; echo ""; echo "
"; } } else { if ($search) { echo "

($strsearchresults)

"; } if (count($potential) <= 20) { foreach ($potential as $user) { echo "

id\" TITLE=\"$straddadmin\">  $user->firstname $user->lastname, $user->email"; } } else { echo "

There are too many users to show.
"; echo "Enter a search word here."; echo "

"; echo ""; echo ""; echo "
"; } } echo "
"; print_footer(); ?>