Commit 61b1cf22 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Make institution admins/staff pages work if user has >1 institution

parent 89ba3f0c
...@@ -38,8 +38,8 @@ require_once('pieforms/pieform.php'); ...@@ -38,8 +38,8 @@ require_once('pieforms/pieform.php');
$smarty = smarty(); $smarty = smarty();
require_once('institution.php'); require_once('institution.php');
$institutionelement = get_institution_selector(); $institution = add_institution_selector_to_page(&$smarty, param_alphanum('institution', false),
$institution = empty($institutionelement['value']) ? $institutionelement['defaultvalue'] : $institutionelement['value']; get_config('wwwroot') . 'admin/users/institutionadmins.php');
// Get users who are currently admins // Get users who are currently admins
$adminusers = get_column('usr_institution', 'usr', 'admin', 1, 'institution', $institution); $adminusers = get_column('usr_institution', 'usr', 'admin', 1, 'institution', $institution);
...@@ -58,7 +58,10 @@ $form = array( ...@@ -58,7 +58,10 @@ $form = array(
'institution' => $institution), 'institution' => $institution),
'searchscript' => 'admin/users/search.json.php', 'searchscript' => 'admin/users/search.json.php',
), ),
'institution' => $institutionelement, 'institution' => array(
'type' => 'hidden',
'value' => $institution,
),
'submit' => array( 'submit' => array(
'type' => 'submit', 'type' => 'submit',
'value' => get_string('submit') 'value' => get_string('submit')
...@@ -86,7 +89,7 @@ function adminusers_submit(Pieform $form, $values) { ...@@ -86,7 +89,7 @@ function adminusers_submit(Pieform $form, $values) {
} }
db_commit(); db_commit();
$SESSION->add_ok_msg(get_string('adminusersupdated', 'admin')); $SESSION->add_ok_msg(get_string('adminusersupdated', 'admin'));
redirect('/admin/users/institutionadmins.php'); redirect('/admin/users/institutionadmins.php?institution=' . $inst);
} }
$smarty->assign('adminusersform', pieform($form)); $smarty->assign('adminusersform', pieform($form));
......
...@@ -38,8 +38,8 @@ require_once('pieforms/pieform.php'); ...@@ -38,8 +38,8 @@ require_once('pieforms/pieform.php');
$smarty = smarty(); $smarty = smarty();
require_once('institution.php'); require_once('institution.php');
$institutionelement = get_institution_selector(); $institution = add_institution_selector_to_page(&$smarty, param_alphanum('institution', false),
$institution = empty($institutionelement['value']) ? $institutionelement['defaultvalue'] : $institutionelement['value']; get_config('wwwroot') . 'admin/users/institutionstaff.php');
// Get users who are currently staff // Get users who are currently staff
$staffusers = get_column('usr_institution', 'usr', 'staff', 1, 'institution', $institution); $staffusers = get_column('usr_institution', 'usr', 'staff', 1, 'institution', $institution);
...@@ -58,7 +58,10 @@ $form = array( ...@@ -58,7 +58,10 @@ $form = array(
'institution' => $institution), 'institution' => $institution),
'searchscript' => 'admin/users/search.json.php', 'searchscript' => 'admin/users/search.json.php',
), ),
'institution' => $institutionelement, 'institution' => array(
'type' => 'hidden',
'value' => $institution,
),
'submit' => array( 'submit' => array(
'type' => 'submit', 'type' => 'submit',
'value' => get_string('submit') 'value' => get_string('submit')
...@@ -86,7 +89,7 @@ function staffusers_submit(Pieform $form, $values) { ...@@ -86,7 +89,7 @@ function staffusers_submit(Pieform $form, $values) {
} }
db_commit(); db_commit();
$SESSION->add_ok_msg(get_string('staffusersupdated', 'admin')); $SESSION->add_ok_msg(get_string('staffusersupdated', 'admin'));
redirect('/admin/users/institutionstaff.php'); redirect('/admin/users/institutionstaff.php?institution=' . $inst);
} }
$smarty->assign('staffusersform', pieform($form)); $smarty->assign('staffusersform', pieform($form));
......
...@@ -360,4 +360,47 @@ function get_institution_selector($includedefault = true) { ...@@ -360,4 +360,47 @@ function get_institution_selector($includedefault = true) {
return $institutionelement; return $institutionelement;
} }
/* The institution selector does exactly the same thing in both
institutionadmins.php and institutionstaff.php (in /admin/users/).
This function creates the form for the page, setting
$institutionselector and $INLINEJAVASCRIPT in the smarty object. */
function add_institution_selector_to_page($smarty, $institution, $page) {
require_once('pieforms/pieform.php');
$institutionelement = get_institution_selector(false);
global $USER;
if (empty($institution) || !$USER->can_edit_institution($institution)) {
$institution = empty($institutionelement['value']) ? $institutionelement['defaultvalue'] : $institutionelement['value'];
}
else {
$institutionelement['defaultvalue'] = $institution;
}
$institutionselector = pieform(array(
'name' => 'institutionselect',
'elements' => array(
'institution' => $institutionelement,
)
));
$js = <<< EOF
function reloadUsers() {
var inst = '';
if ($('institutionselect_institution')) {
inst = '?institution='+$('institutionselect_institution').value;
}
window.location.href = '{$page}'+inst;
}
addLoadEvent(function() {
if ($('institutionselect_institution')) {
connect($('institutionselect_institution'), 'onchange', reloadUsers);
}
});
EOF;
$smarty->assign('institutionselector', $institutionselector);
$smarty->assign('INLINEJAVASCRIPT', $js);
return $institution;
}
?> ?>
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
<p>{str tag="institutionadminuserspagedescription" section="admin"}</p> <p>{str tag="institutionadminuserspagedescription" section="admin"}</p>
{$institutionselector}
{$adminusersform} {$adminusersform}
{include file="columnfullend.tpl"} {include file="columnfullend.tpl"}
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
<p>{str tag="institutionstaffuserspagedescription" section="admin"}</p> <p>{str tag="institutionstaffuserspagedescription" section="admin"}</p>
{$institutionselector}
{$staffusersform} {$staffusersform}
{include file="columnfullend.tpl"} {include file="columnfullend.tpl"}
......
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