mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-30625 full support for main admin
This commit is contained in:
parent
42f6b3f1d7
commit
bb6ccfa53d
@ -67,6 +67,26 @@ if (optional_param('add', false, PARAM_BOOL) and confirm_sesskey()) {
|
||||
}
|
||||
}
|
||||
|
||||
} else if (optional_param('main', false, PARAM_BOOL) and confirm_sesskey()) {
|
||||
if ($newmain = $admisselector->get_selected_users()) {
|
||||
$newmain = reset($newmain);
|
||||
$newmain = $newmain->id;
|
||||
$admins = array();
|
||||
foreach(explode(',', $CFG->siteadmins) as $admin) {
|
||||
$admin = (int)$admin;
|
||||
if ($admin) {
|
||||
$admins[$admin] = $admin;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($admins[$newmain])) {
|
||||
unset($admins[$newmain]);
|
||||
array_unshift($admins, $newmain);
|
||||
set_config('siteadmins', implode(',', $admins));
|
||||
redirect($PAGE->url);
|
||||
}
|
||||
}
|
||||
|
||||
} else if ($confirmadd and confirm_sesskey()) {
|
||||
$admins = array();
|
||||
foreach(explode(',', $CFG->siteadmins) as $admin) {
|
||||
@ -115,6 +135,7 @@ echo $OUTPUT->header();
|
||||
<p class="arrow_button">
|
||||
<input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().' '.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
|
||||
<input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').' '.$OUTPUT->rarrow(); ?>" title="<?php print_string('remove'); ?>" />
|
||||
<input name="main" id="main" type="submit" value="<?php echo get_string('mainadminset', 'role'); ?>" title="<?php print_string('mainadminset', 'role'); ?>" />
|
||||
</p>
|
||||
</td>
|
||||
<td id='potentialcell'>
|
||||
|
@ -1584,13 +1584,31 @@ class admins_existing_selector extends user_selector_base {
|
||||
return array();
|
||||
}
|
||||
|
||||
if ($search) {
|
||||
$groupname = get_string('extusersmatching', 'role', $search);
|
||||
} else {
|
||||
$groupname = get_string('extusers', 'role');
|
||||
$mainadmin = array();
|
||||
$adminids = explode(',', $CFG->siteadmins);
|
||||
foreach ($adminids as $id) {
|
||||
if (isset($availableusers[$id])) {
|
||||
$mainadmin = array($id=>$availableusers[$id]);
|
||||
unset($availableusers[$id]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return array($groupname => $availableusers);
|
||||
$result = array();
|
||||
if ($mainadmin) {
|
||||
$result[get_string('mainadmin', 'role')] = $mainadmin;
|
||||
}
|
||||
|
||||
if ($availableusers) {
|
||||
if ($search) {
|
||||
$groupname = get_string('extusersmatching', 'role', $search);
|
||||
} else {
|
||||
$groupname = get_string('extusers', 'role');
|
||||
}
|
||||
$result[$groupname] = $availableusers;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function get_options() {
|
||||
|
@ -212,6 +212,8 @@ $string['legacytype'] = 'Legacy role type';
|
||||
$string['legacy:user'] = 'LEGACY ROLE: Authenticated user';
|
||||
$string['listallroles'] = 'List all roles';
|
||||
$string['localroles'] = 'Locally assigned roles';
|
||||
$string['mainadmin'] = 'Main administrator';
|
||||
$string['mainadminset'] = 'Set main admin';
|
||||
$string['manageadmins'] = 'Manage site administrators';
|
||||
$string['manager'] = 'Manager';
|
||||
$string['managerdescription'] = 'Managers can access course and modify them, they usually do not participate in courses.';
|
||||
|
@ -49,24 +49,32 @@ define('LASTACCESS_UPDATE_SECS', 60);
|
||||
|
||||
/**
|
||||
* Returns $user object of the main admin user
|
||||
* primary admin = admin with lowest role_assignment id among admins
|
||||
*
|
||||
* @static stdClass $mainadmin
|
||||
* @return stdClass {@link $USER} record from DB, false if not found
|
||||
*/
|
||||
function get_admin() {
|
||||
global $CFG, $DB;
|
||||
|
||||
static $mainadmin = null;
|
||||
|
||||
if (!isset($mainadmin)) {
|
||||
if (! $admins = get_admins()) {
|
||||
return false;
|
||||
}
|
||||
//TODO: add some admin setting for specifying of THE main admin
|
||||
// for now return the first assigned admin
|
||||
$mainadmin = reset($admins);
|
||||
if (isset($mainadmin)) {
|
||||
return clone($mainadmin);
|
||||
}
|
||||
|
||||
foreach (explode(',', $CFG->siteadmins) as $id) {
|
||||
if ($user = $DB->get_record('user', array('id'=>$id, 'deleted'=>0))) {
|
||||
$mainadmin = $user;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($mainadmin) {
|
||||
return clone($mainadmin);
|
||||
} else {
|
||||
// this should not happen
|
||||
return false;
|
||||
}
|
||||
// we must clone this otherwise code outside can break the static var
|
||||
return clone($mainadmin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user