New translation added.
[moodle.git] / admin / admin.php
blob53e8a1a38f781887bb4a5dad3d8fd7365d2ffbec
1 <?PHP // $Id$
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");
16 require_login();
18 if (!isadmin()) {
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 (
32 "assignadmins",
33 "administration",
34 "existingadmins",
35 "noexistingadmins",
36 "potentialadmins",
37 "nopotentialadmins",
38 "addadmin",
39 "removeadmin",
40 "search",
41 "searchagain",
42 "toomanytoshow",
43 "users",
44 "searchresults"
47 foreach ($stringstoload as $stringtoload){
48 $strstringtoload = "str" . $stringtoload;
49 $$strstringtoload = get_string($stringtoload);
52 if ($search) {
53 $searchstring = $strsearchagain;
54 } else {
55 $searchstring = $strsearch;
58 print_header("$site->shortname: $strassignadmins",
59 "$site->fullname",
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
91 if (! $admins) {
92 echo "<p align=center>$strnoexistingadmins</p>";
93 $adminlist = "";
95 } else {
96 $adminarray = array();
98 foreach ($admins as $admin) {
99 $adminarray[] = $admin->id;
100 echo "<p align=right>$admin->firstname $admin->lastname,
101 $admin->email &nbsp;&nbsp; ";
102 if ($primaryadmin->id == $admin->id){
103 print_spacer(10, 9, false);
104 } else {
105 echo "<a href=\"{$_SERVER['PHP_SELF']}?remove=$admin->id\"
106 title=\"$strremoveadmin\"><img src=\"../pix/t/right.gif\"
107 border=0></A>";
109 echo "</p>";
112 $adminlist = implode(",",$adminarray);
113 unset($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>";
128 } else {
130 if ($search) {
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>&nbsp;&nbsp;$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\">";
149 echo "</form>";
152 echo "</tr></table>";
154 print_footer();