From 4fe8e0d27d21556e4be9254ee8c7b8895497965f Mon Sep 17 00:00:00 2001 From: moodler Date: Sun, 17 Aug 2003 10:17:57 +0000 Subject: [PATCH] More robust adding/removing of admins --- admin/admin.php | 48 +++++++++++------------------------------------- 1 file changed, 11 insertions(+), 37 deletions(-) diff --git a/admin/admin.php b/admin/admin.php index daea0c42a6..91d7a56f27 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -59,49 +59,24 @@ "$site->fullname", "$stradministration -> $strusers -> $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 ""; @@ -111,8 +86,7 @@ /// First, show existing admins if (! $admins) { - echo "

$strnoexistingadmins"; - + echo "

$strnoexistingadmins

"; $adminlist = ""; } else { -- 2.39.5