From: moodler Date: Wed, 11 Dec 2002 14:59:37 +0000 (+0000) Subject: Modifications from Greg Barnett at Crown College to add more admins. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d7facad81e66a8a1cb6d126ef3c27e92ed4a17de;p=moodle.git Modifications from Greg Barnett at Crown College to add more admins. See http://bugs.moodle.org/bug.php?op=show&bugid=202 --- diff --git a/admin/admin.php b/admin/admin.php new file mode 100644 index 0000000000..d2d32b345e --- /dev/null +++ b/admin/admin.php @@ -0,0 +1,184 @@ +wwwroot/admin/"); + } + + 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", + ); + + foreach ($stringstoload as $stringtoload){ + $strstringtoload = "str" . $stringtoload; + $$strstringtoload = get_string($stringtoload); + } + + print_header("$site->shortname: $course->shortname: $strassignadmins", + "$site->fullname", + "wwwroot/admin\">$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->user = $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_records_sql("SELECT * from user WHERE confirmed = 1 AND deleted = 0 + AND (firstname LIKE '%$search%' OR + lastname LIKE '%$search%' OR + email LIKE '%$search%') + AND username <> 'guest' AND username <> 'changeme'"); + } else { + $users = get_records_sql("SELECT * from user WHERE confirmed = 1 AND deleted = 0 + AND username <> 'guest' AND username <> 'changeme'"); + } + + + 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(); + +?> diff --git a/admin/index.php b/admin/index.php index e1649a3a05..d093276378 100644 --- a/admin/index.php +++ b/admin/index.php @@ -252,6 +252,7 @@ "

".get_string("categories")."

"; $table->data[0][2] = "

".get_string("addnewuser")."

". "

".get_string("edituser")."

". + "

".get_string("assignadmins")."

". "

".get_string("authentication")."

"; print_table($table); diff --git a/course/lib.php b/course/lib.php index 9bee070e1f..2aa0eae400 100644 --- a/course/lib.php +++ b/course/lib.php @@ -625,6 +625,8 @@ function print_admin_links ($siteid, $width=180) { $modicon[]=$icon; $moddata[]="wwwroot/admin/user.php\">".get_string("edituser").""; $modicon[]=$icon; + $moddata[]="wwwroot/admin/admin.php\">".get_string("assignadmins").""; + $modicon[]=$icon; $moddata[]="wwwroot/admin/auth.php\">".get_string("authentication").""; $modicon[]=$icon; $fulladmin = "

wwwroot/admin/\">".get_string("admin")."..."; diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 08ad13e964..8e0ada0bd8 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -14,6 +14,7 @@ $string['addinganewto'] = "Adding a new \$a->what to \$a->to"; $string['addnewcourse'] = "Add a new course"; $string['addnewuser'] = "Add a new user"; $string['address'] = "Address"; +$string['addadmin'] = "Add admin"; $string['addteacher'] = "Add teacher"; $string['admin'] = "Admin"; $string['administration'] = "Administration"; @@ -30,6 +31,7 @@ $string['alphanumerical'] = "Can only contain alphabetical letters or numbers"; $string['alreadyconfirmed'] = "Registration has already been confirmed"; $string['answer'] = "Answer"; $string['assessment'] = "Assessment"; +$string['assignadmins'] = "Assign admins"; $string['assignteachers'] = "Assign teachers"; $string['authentication'] = "Authentication"; $string['availablecourses'] = "Available Courses"; @@ -159,6 +161,7 @@ $string['enrolmentkeyhint'] = "That enrolment key was incorrect, please try agai $string['entercourse'] = "Click to enter this course"; $string['enteremailaddress'] = "Enter in your email address to reset your password and have the new password sent to you via email."; +$string['existingadmins'] = "Existing admins"; $string['existingteachers'] = "Existing teachers"; $string['error'] = "Error"; $string['feedback'] = "Feedback"; @@ -355,11 +358,13 @@ $string['newsitemsnumber'] = "News items to show"; $string['never'] = "Never"; $string['no'] = "No"; $string['nocoursesyet'] = "No courses in this category"; +$string['noexistingadmins'] = "No existing admins, this is a serious error and you should never have seen this message."; $string['noexistingteachers'] = "No existing teachers"; $string['nofilesyet'] = "No files have been uploaded to your course yet"; $string['nograde'] = "No grade"; $string['noimagesyet'] = "No images have been uploaded to your course yet"; $string['none'] = "None"; +$string['nopotentialadmins'] = "No potential admins"; $string['nopotentialteachers'] = "No potential teachers"; $string['normal'] = "Normal"; $string['nostudentsyet'] = "No students enrolled in this course yet"; @@ -395,6 +400,7 @@ $string['passwordsenttext'] = " $string['people'] = "People"; $string['personalprofile'] = "Personal profile"; $string['phone'] = "Phone"; +$string['potentialadmins'] = "Potential admins"; $string['potentialteachers'] = "Potential teachers"; $string['preferredlanguage'] = "Preferred language"; $string['preview'] = "Preview"; @@ -402,6 +408,7 @@ $string['previeworchoose'] = "Preview or choose a theme"; $string['question'] = "Question"; $string['readme'] = "README"; // This is a file name $string['recentactivity'] = "Recent activity"; +$string['removeadmin'] = "Remove admin"; $string['removeteacher'] = "Remove teacher"; $string['rename'] = "Rename"; $string['resources'] = "Resources"; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index a1a90bbc2b..afaf74c6c4 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1339,7 +1339,7 @@ function isadmin($userid=0) { global $USER; if (!$userid) { - return $USER->admin; + return record_exists_sql("SELECT * FROM user_admins WHERE user='{$USER->id}'"); } return record_exists_sql("SELECT * FROM user_admins WHERE user='$userid'"); @@ -1519,6 +1519,13 @@ function get_admin () { } } +function get_admins() { + return get_records_sql("SELECT u.* FROM user u, user_admins a + WHERE a.user = u.id + ORDER BY u.id ASC"); +} + + function get_teacher($courseid) { // Returns $user object of the main teacher for a course if ( $teachers = get_records_sql("SELECT u.* FROM user u, user_teachers t