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);
}
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:
?>
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');
}
}
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');
}
$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;
$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';
}