Skip to content
Browse files

MDL-30625 full support for main admin

  • Loading branch information...
1 parent e0745be commit db48cf080da8384b916c5261eccaeb7c048a03b8 @skodak skodak committed with stronk7 Dec 7, 2011
Showing with 63 additions and 14 deletions.
  1. +21 −0 admin/roles/admins.php
  2. +23 −5 admin/roles/lib.php
  3. +2 −0 lang/en/role.php
  4. +17 −9 lib/datalib.php
View
21 admin/roles/admins.php
@@ -67,6 +67,26 @@
}
}
+} 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 @@
<p class="arrow_button">
<input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
<input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').'&nbsp;'.$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'>
View
28 admin/roles/lib.php
@@ -1584,13 +1584,31 @@ public function find_users($search) {
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() {
View
2 lang/en/role.php
@@ -212,6 +212,8 @@
$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.';
View
26 lib/datalib.php
@@ -49,24 +49,32 @@
/**
* 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;
+ 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;
}
- //TODO: add some admin setting for specifying of THE main admin
- // for now return the first assigned admin
- $mainadmin = reset($admins);
}
- // we must clone this otherwise code outside can break the static var
- return clone($mainadmin);
+
+ if ($mainadmin) {
+ return clone($mainadmin);
+ } else {
+ // this should not happen
+ return false;
+ }
}
/**

0 comments on commit db48cf0

Please sign in to comment.
Something went wrong with that request. Please try again.