2 // Admin-only script to assign administrative rights to users
4 require_once("../config.php");
6 define("MAX_USERS_PER_PAGE", 50);
8 optional_variable($add, "");
9 optional_variable($remove, "");
10 optional_variable($search, "");
12 if (! $site = get_site()) {
13 redirect("$CFG->wwwroot/$CFG->admin/index.php");
19 error("You must be an administrator to use this page.");
22 $primaryadmin = get_admin();
24 /// If you want any administrator to have the ability to assign admin
25 /// rights, then comment out the following if statement
26 if ($primaryadmin->id
!= $USER->id
) {
27 error("You must be the primary administrator to use this page.");
30 /// assign all of the configurable language strings
31 $stringstoload = array (
47 foreach ($stringstoload as $stringtoload){
48 $strstringtoload = "str" . $stringtoload;
49 $
$strstringtoload = get_string($stringtoload);
53 $searchstring = $strsearchagain;
55 $searchstring = $strsearch;
58 print_header("$site->shortname: $strassignadmins",
60 "<a href=\"index.php\">$stradministration</a> -> <a href=\"users.php\">$strusers</a> -> $strassignadmins", "");
62 /// Add an admin if one is specified
63 if (!empty($_GET['add'])) {
64 if (! add_admin($add)) {
65 error("Could not add that admin!");
69 /// Remove an admin if one is specified.
70 if (!empty($_GET['remove'])) {
71 if (! remove_admin($remove)) {
72 error("Could not remove that admin!");
76 /// Print a help notice about this page
77 if (empty($add) and empty($remove) and empty($search)) {
78 print_simple_box("<center>".get_string("adminhelpassignadmins")."</center>", "center", "50%");
81 /// Get all existing admins
82 $admins = get_admins();
84 /// Print the lists of existing and potential admins
85 echo "<table cellpadding=2 cellspacing=10 align=center>";
86 echo "<tr><th width=50%>$strexistingadmins</th><th width=50%>$strpotentialadmins</th></tr>";
87 echo "<tr><td width=50% nowrap valign=top>";
89 /// First, show existing admins
92 echo "<p align=center>$strnoexistingadmins</p>";
96 $adminarray = array();
98 foreach ($admins as $admin) {
99 $adminarray[] = $admin->id
;
100 echo "<p align=right>$admin->firstname $admin->lastname,
101 $admin->email ";
102 if ($primaryadmin->id
== $admin->id
){
103 print_spacer(10, 9, false);
105 echo "<a href=\"{$_SERVER['PHP_SELF']}?remove=$admin->id\"
106 title=\"$strremoveadmin\"><img src=\"../pix/t/right.gif\"
112 $adminlist = implode(",",$adminarray);
116 echo "<td width=50% nowrap valign=top>";
118 /// Print list of potential admins
120 $usercount = get_users(false, $search, true, $adminlist);
122 if ($usercount == 0) {
123 echo "<p align=center>$strnopotentialadmins</p>";
125 } else if ($usercount > MAX_USERS_PER_PAGE
) {
126 echo "<p align=center>$strtoomanytoshow ($usercount) </p>";
131 echo "<p align=center>($strsearchresults : $search)</p>";
134 if (!$users = get_users(true, $search, true, $adminlist)) {
135 error("Could not get users!");
138 foreach ($users as $user) {
139 echo "<p align=left><a href=\"{$_SERVER['PHP_SELF']}?add=$user->id\"".
140 "title=\"$straddadmin\"><img src=\"../pix/t/left.gif\"".
141 "border=0></a> $user->firstname $user->lastname, $user->email";
145 if ($search or $usercount > MAX_USERS_PER_PAGE
) {
146 echo "<form action={$_SERVER['PHP_SELF']} method=post>";
147 echo "<input type=text name=search size=20>";
148 echo "<input type=submit value=\"$searchstring\">";
152 echo "</tr></table>";