Commit 2cc3ca26 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Allow site admin to use the institution users page

parent 5904e1de
......@@ -37,11 +37,11 @@ define('SECTION_PAGE', 'institutionusers');
require_once('pieforms/pieform.php');
require_once('institution.php');
$institutionelement = get_institution_selector();
$institutionelement = get_institution_selector(false);
global $USER;
$institution = param_alphanum('institution', false);
if (!$institution || !$USER->is_institutional_admin($institution)) {
if (!$institution || !$USER->can_edit_institution($institution)) {
$institution = empty($institutionelement['value']) ? $institutionelement['defaultvalue'] : $institutionelement['value'];
}
else if (!empty($institution)) {
......@@ -144,7 +144,7 @@ function institutionusers_submit(Pieform $form, $values) {
$url = '/admin/users/institutionusers.php?usertype=' . $values['usertype'];
$inst = $values['institution'];
if (empty($inst) || !$USER->is_institutional_admin($inst)) {
if (empty($inst) || !$USER->can_edit_institution($inst)) {
$SESSION->add_error_msg(get_string('notadminforinstitution', 'admin'));
redirect($url);
}
......
......@@ -379,6 +379,10 @@ class User {
return isset($a[$institution]);
}
public function can_edit_institution($institution = null) {
return $this->get('admin') || $this->is_institutional_admin($institution);
}
public function set_admin_institutions($institutions) {
$this->set('admininstitutions', array_combine($institutions, $institutions));
}
......
......@@ -318,11 +318,16 @@ class Institution {
}
}
function get_institution_selector() {
function get_institution_selector($includedefault = true) {
global $USER;
if ($USER->get('admin')) {
$institutions = get_records_array('institution');
if ($includedefault) {
$institutions = get_records_array('institution');
}
else {
$institutions = get_records_select_array('institution', "name != 'mahara'");
}
} else if ($USER->is_institutional_admin()) {
$institutions = get_records_select_array('institution', 'name IN ('
. join(',', array_map('db_quote',$USER->get('admininstitutions'))) . ')');
......
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