Commit e2de1055 authored by Richard Mansfield's avatar Richard Mansfield

Show studentids on institution admins/staff pages

parent e2e4b64b
......@@ -38,15 +38,8 @@ $user = new User;
$user->find_by_id($id);
global $USER;
if (!$USER->get('admin')) {
// Institutional admins must share an institution with the displayed user
$shared = false;
foreach ($user->get('institutions') as $i) {
$shared = $shared || $USER->is_institutional_admin($i->institution);
}
if (!$shared) {
redirect(get_config('wwwroot').'user/view.php?id='.$id);
}
if (!$USER->is_admin_for_user($user)) {
redirect(get_config('wwwroot').'user/view.php?id='.$id);
}
$suspended = $user->get('suspendedcusr');
......
......@@ -55,9 +55,9 @@ $form = array(
'filter' => false,
'lefttitle' => get_string('institutionmembers', 'admin'),
'righttitle' => get_string('currentadmins', 'admin'),
'searchparams' => array('limit' => 100, 'query' => '', 'raw' => true, 'action' => 'search',
'searchparams' => array('limit' => 100, 'query' => '', 'member' => 1,
'institution' => $institution),
'searchscript' => 'admin/users/search.json.php',
'searchscript' => 'admin/users/userinstitutionsearch.json.php',
),
'institution' => array(
'type' => 'hidden',
......
......@@ -55,9 +55,9 @@ $form = array(
'filter' => false,
'lefttitle' => get_string('institutionmembers', 'admin'),
'righttitle' => get_string('institutionstaff', 'admin'),
'searchparams' => array('limit' => 100, 'query' => '', 'raw' => true, 'action' => 'search',
'searchparams' => array('limit' => 100, 'query' => '', 'member' => 1,
'institution' => $institution),
'searchscript' => 'admin/users/search.json.php',
'searchscript' => 'admin/users/userinstitutionsearch.json.php',
),
'institution' => array(
'type' => 'hidden',
......
......@@ -383,6 +383,18 @@ class User {
return $this->get('admin') || $this->is_institutional_admin($institution);
}
public function is_admin_for_user($user) {
if ($this->get('admin')) {
return true;
}
foreach ($user->get('institutions') as $i) {
if ($this->is_institutional_admin($i->institution)) {
return true;
}
}
return false;
}
public function set_admin_institutions($institutions) {
$this->set('admininstitutions', array_combine($institutions, $institutions));
}
......
......@@ -135,10 +135,10 @@ function get_institutional_admin_search_results($search, $limit) {
}
$results = institutional_admin_user_search($search->query, $institution, $limit);
if ($results['count']) {
foreach ($results['data'] as &$result) {
$result['name'] = display_name($result);
if (!empty($result['studentid'])) {
$result['name'] .= ' (' . $result['studentid'] . ')';
foreach ($results['data'] as &$r) {
$r['name'] = $r['firstname'] . ' ' . $r['lastname'] . ' (' . $r['username'] . ')';
if (!empty($r['studentid'])) {
$r['name'] .= ' (' . $r['studentid'] . ')';
}
}
}
......
......@@ -312,7 +312,7 @@ function display_name($user, $userto=null) {
$userto->preferredname = $USER->get('preferredname');
$userto->firstname = $USER->get('firstname');
$userto->lastname = $USER->get('lastname');
$userto->admin = $USER->get('admin');
$userto->admin = $USER->get('admin') || $USER->is_institutional_admin();
$userto->staff = $USER->get('staff');
}
if (is_array($user)) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment