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

Add institution settings page for institutional admins

parent d6971c81
......@@ -24,7 +24,7 @@
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('INSTITUTIONALADMIN', 1);
define('MENUITEM', 'configusers/institutions');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('institutions', 'admin'));
......@@ -39,6 +39,22 @@ $add = param_boolean('add');
$edit = param_boolean('edit');
$delete = param_boolean('delete');
global $USER;
if (!$USER->get('admin')) {
// Institutional admins with only 1 institution go straight to the edit page for that institution
// They cannot add or delete institutions, or edit an institution they don't administer
$add = false;
$delete = false;
if (!empty($institution) && !$USER->is_institutional_admin($institution)) {
$institution = '';
$edit = false;
}
if (empty($institution) && count($USER->get('admininstitutions')) == 1) {
redirect(get_config('wwwroot') . 'admin/users/institutions.php?i='
. key($USER->get('institutions')));
}
}
if ($institution || $add) {
$authinstances = auth_get_auth_instances_for_institution($institution);
......@@ -241,9 +257,17 @@ if ($institution || $add) {
}
else {
// Get a list of institutions
if (!$USER->get('admin')) { // Filter the list for institutional admins
$where = '
WHERE i.name IN (' . join(',', array_map('db_quote', $USER->get('admininstitutions'))) . ')';
}
else {
$where = '';
$smarty->assign('siteadmin', true);
}
$institutions = get_records_sql_array('SELECT i.name, i.displayname, i.registerallowed, COUNT(u.usr) AS hasmembers
FROM {institution} i
LEFT OUTER JOIN {usr_institution} u ON (u.institution = i.name)
LEFT OUTER JOIN {usr_institution} u ON (u.institution = i.name) ' . $where . '
GROUP BY 1, 2, 3
ORDER BY i.name', array());
$smarty->assign('institutions', $institutions);
......
......@@ -1321,22 +1321,28 @@ function admin_nav() {
'weight' => 30,
),
array(
'path' => 'configusers/admins',
'path' => 'configusers/admin',
'url' => 'admin/users/institutionadmins.php',
'title' => get_string('adminusers', 'admin'),
'weight' => 40,
),
array(
'path' => 'configusers/institutions',
'url' => 'admin/users/institutions.php',
'title' => get_string('institutionsettings', 'admin'),
'weight' => 50,
),
array(
'path' => 'configusers/adminnotifications',
'url' => 'admin/users/notifications.php',
'title' => get_string('adminnotifications', 'admin'),
'weight' => 50,
'weight' => 60,
),
array(
'path' => 'configusers/uploadcsv',
'url' => 'admin/users/uploadcsv.php',
'title' => get_string('uploadcsv', 'admin'),
'weight' => 60,
'weight' => 70,
),
);
}
......
......@@ -36,7 +36,7 @@
<form action="" method="post">
<input type="hidden" name="i" value="{$institution->name}">
<input type="submit" class="submit" name="edit" value="{str tag="edit"}" id="admininstitution_edit">
{if !$institution->hasmembers && $institution->name != 'mahara'}<input type="submit" class="submit" name="delete" value="{str tag="delete"}" id="admininstitution_delete">{/if}
{if $siteadmin && !$institution->hasmembers && $institution->name != 'mahara'}<input type="submit" class="submit" name="delete" value="{str tag="delete"}" id="admininstitution_delete">{/if}
</form>
</td>
</tr>
......@@ -44,9 +44,11 @@
<tr>
</tbody>
</table>
{if $siteadmin}
<form action="" method="post">
<input type="submit" class="submit" name="add" value="{str tag="addinstitution" section="admin"}" id="admininstitution_add">
</form>
{/if}
{/if}
{/if}
......
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