From: poltawski Date: Sat, 26 Jan 2008 17:00:03 +0000 (+0000) Subject: MDL-13179 - avoid calling get_admin() when unecessary. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=fc4b2decc0a51b34e7befe7ff4cd980d475cc62a;p=moodle.git MDL-13179 - avoid calling get_admin() when unecessary. It uses a relatively complex query and its not needed except for a minority of users so we may as well avoid it.. merged from MOODLE_19_STABLE --- diff --git a/admin/user.php b/admin/user.php index 0b975f030d..9ae92ee2bf 100644 --- a/admin/user.php +++ b/admin/user.php @@ -63,8 +63,7 @@ error("No such user!", '', true); } - $primaryadmin = get_admin(); - if ($user->id == $primaryadmin->id) { + if (is_primary_admin($user->id)) { error("You are not allowed to delete the primary admin user!", '', true); } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index ae2ca823b7..6415a36f7b 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -7865,5 +7865,21 @@ function get_plugin_name($plugin, $type='mod') { return $plugin_name; } +/** + * Is a userid the primary administrator? + * + * @param $userid int id of user to check + * @return boolean + */ +function is_primary_admin($userid){ + $primaryadmin = get_admin(); + + if($userid == $primaryadmin->id){ + return true; + }else{ + return false; + } +} + // vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140: ?> diff --git a/user/edit.php b/user/edit.php index c79175ed05..a411236dc2 100644 --- a/user/edit.php +++ b/user/edit.php @@ -73,8 +73,7 @@ print_error('guestnoeditprofileother'); } // no editing of primary admin! - $mainadmin = get_admin(); - if ($user->id == $mainadmin->id) { + if (is_primary_admin($user->id)) { print_error('adminprimarynoedit'); } } diff --git a/user/editadvanced.php b/user/editadvanced.php index 98812c0d55..3cdb707dd0 100644 --- a/user/editadvanced.php +++ b/user/editadvanced.php @@ -44,8 +44,7 @@ redirect($CFG->wwwroot . "/user/view.php?id=$id&course={$course->id}"); } - $mainadmin = get_admin(); - if ($user->id != $USER->id and $user->id == $mainadmin->id) { // Can't edit primary admin + if ($user->id != $USER->id and is_primary_admin($user->id)) { // Can't edit primary admin print_error('adminprimarynoedit'); } diff --git a/user/tabs.php b/user/tabs.php index 1822b19e3c..7aad08a162 100644 --- a/user/tabs.php +++ b/user/tabs.php @@ -95,9 +95,8 @@ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); $personalcontext = get_context_instance(CONTEXT_USER, $user->id); - /// Can only edit profile if it belongs to user or current user is admin and not editing primary admin - $mainadmin = get_admin(); + /// Can only edit profile if it belongs to user or current user is admin and not editing primary admin if(empty($CFG->loginhttps)) { $wwwroot = $CFG->wwwroot; @@ -122,11 +121,10 @@ $edittype = 'normal'; } - } else if ($user->id != $mainadmin->id) { - //no editing of primary admin! - if (has_capability('moodle/user:update', $systemcontext)) { + } else { + if (has_capability('moodle/user:update', $systemcontext) and !is_primary_admin($user->id)){ $edittype = 'advanced'; - } else if (has_capability('moodle/user:editprofile', $personalcontext)) { + } else if (has_capability('moodle/user:editprofile', $personalcontext) and !is_primary_admin($user->id)){ //teachers, parents, etc. $edittype = 'normal'; }