]> git.mjollnir.org Git - moodle.git/commitdiff
More robust adding/removing of admins
authormoodler <moodler>
Sun, 17 Aug 2003 10:17:57 +0000 (10:17 +0000)
committermoodler <moodler>
Sun, 17 Aug 2003 10:17:57 +0000 (10:17 +0000)
admin/admin.php

index daea0c42a66c59e333291b9528f20974f5708c44..91d7a56f2709a14ad19dc278ae738f370744f7e6 100644 (file)
                  "$site->fullname", 
                  "<a href=\"index.php\">$stradministration</a> -> <a href=\"users.php\">$strusers</a> -> $strassignadmins", "");
 
-/// Get all existing admins
-    $admins = get_admins();
-
 /// Add an admin if one is specified
-    if ($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;
+    if (!empty($_GET['add'])) {
+        if (! add_admin($add)) {
+            error("Could not add that admin!");
+        }
     }
 
 /// Remove an admin if one is specified.
-    if ($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]);
-                    }
-                } 
-            }
+
+    if (!empty($_GET['remove'])) {
+        if (! remove_admin($remove)) {
+            error("Could not remove that admin!");
         }
     }
 
+/// Get all existing admins
+    $admins = get_admins();
 
 /// Print the lists of existing and potential admins
     echo "<table cellpadding=2 cellspacing=10 align=center>";
 /// First, show existing admins
 
     if (! $admins) { 
-        echo "<p align=center>$strnoexistingadmins</a>";
-
+        echo "<p align=center>$strnoexistingadmins</p>";
         $adminlist = "";
 
     } else {