Commit 0084b2e5 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Institutional admin page

parent 34c58397
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage admin
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
// NOTE: This script is VERY SIMILAR to the adminusers.php script, a bug fixed
// here might need to be fixed there too.
define('INTERNAL', 1);
define('INSTITUTIONALADMIN', 1);
define('MENUITEM', 'configusers/adminusers');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('adminusers', 'admin'));
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'adminusers');
require_once('pieforms/pieform.php');
$smarty = smarty();
require_once('institution.php');
$institutionelement = get_institution_selector();
$institution = empty($institutionelement['value']) ? $institutionelement['defaultvalue'] : $institutionelement['value'];
// Get users who are currently admins
$adminusers = get_column('usr_institution', 'usr', 'admin', 1, 'institution', $institution);
$form = array(
'name' => 'adminusers',
'elements' => array(
'users' => array(
'type' => 'userlist',
'title' => get_string('adminusers', 'admin'),
'defaultvalue' => $adminusers,
'filter' => false,
'lefttitle' => get_string('institutionmembers', 'admin'),
'righttitle' => get_string('currentadmins', 'admin'),
'searchparams' => array('limit' => 100, 'query' => '', 'raw' => true, 'action' => 'search',
'institution' => $institution),
'searchscript' => 'admin/users/search.json.php',
),
'institution' => $institutionelement,
'submit' => array(
'type' => 'submit',
'value' => get_string('submit')
)
)
);
function adminusers_submit(Pieform $form, $values) {
global $SESSION, $USER;
$inst = $values['institution'];
if (empty($inst) || !$USER->is_institutional_admin($inst)) {
$SESSION->add_error_msg(get_string('notadminforinstitution', 'admin'));
redirect('/admin/users/institutionadmins.php');
}
db_begin();
execute_sql('UPDATE {usr_institution}
SET admin = 0
WHERE admin = 1 AND institution = ' . db_quote($inst));
if ($values['users']) {
execute_sql('UPDATE {usr_institution}
SET admin = 1
WHERE usr IN (' . join(',', $values['users']) . ') AND institution = ' . db_quote($inst));
}
db_commit();
$SESSION->add_ok_msg(get_string('adminusersupdated', 'admin'));
redirect('/admin/users/institutionadmins.php');
}
$smarty->assign('adminusersform', pieform($form));
$smarty->display('admin/users/institutionadmins.tpl');
?>
......@@ -37,29 +37,9 @@ define('SECTION_PAGE', 'staffusers');
require_once('pieforms/pieform.php');
$smarty = smarty();
global $USER;
$institutions = get_records_select_array('institution', 'name IN (' . join(',', array_map('db_quote',$USER->get('admininstitutions'))) . ')');
if (count($institutions) > 1) {
$options = array();
foreach ($institutions as $i) {
$options[$i->name] = $i->displayname;
}
$institution = key($options);
$institutionelement = array(
'type' => 'select',
'title' => get_string('institution'),
'defaultvalue' => $institution,
'options' => $options
);
} else {
$institution = $institutions[0]->name;
$institutionelement = array(
'type' => 'hidden',
'value' => $institution,
);
}
require_once('institution.php');
$institutionelement = get_institution_selector();
$institution = empty($institutionelement['value']) ? $institutionelement['defaultvalue'] : $institutionelement['value'];
// Get users who are currently staff
$staffusers = get_column('usr_institution', 'usr', 'staff', 1, 'institution', $institution);
......
......@@ -211,6 +211,7 @@ $string['uploadcsvusersaddedsuccessfully'] = 'The users in the file have been ad
// Admin Users
$string['adminuserspagedescription'] = '<p>Here you can choose which users are administrators for the site. The current administrators are listed on the right, and potential administrators are on the left.</p><p>The system must have at least one administrator.</p>';
$string['institutionadminuserspagedescription'] = 'Here you can choose which users are administrators for the institution. The current administrators are listed on the right, and potential administrators are on the left.';
$string['potentialadmins'] = 'Potential Admins';
$string['currentadmins'] = 'Current Admins';
$string['adminusersupdated'] = 'Admin users updated';
......@@ -282,6 +283,7 @@ $string['authenticatedby'] = 'Authentication Method';
$string['institutionsettings'] = 'Institution Settings';
$string['changeinstitution'] = 'Change Institution';
$string['institutionstaff'] = 'Institution Staff';
$string['institutionadmins'] = 'Institution Administrators';
$string['institutionadmin'] = 'Institution Admin';
$string['settingsfor'] = 'Settings for:';
$string['institutionadministration'] = 'Institution Administration';
......
......@@ -215,4 +215,40 @@ class Institution {
}
}
function get_institution_selector() {
global $USER;
if ($USER->get('admin')) {
$institutions = get_records_array('institution');
} else if ($USER->is_institutional_admin()) {
$institutions = get_records_select_array('institution', 'name IN ('
. join(',', array_map('db_quote',$USER->get('admininstitutions'))) . ')');
} else {
return null;
}
if (count($institutions) > 1) {
$options = array();
foreach ($institutions as $i) {
$options[$i->name] = $i->displayname;
}
$institution = key($options);
$institutionelement = array(
'type' => 'select',
'title' => get_string('institution'),
'defaultvalue' => $institution,
'options' => $options
);
} else {
$institution = $institutions[0]->name;
$institutionelement = array(
'type' => 'hidden',
'value' => $institution,
);
}
return $institutionelement;
}
?>
......@@ -1322,7 +1322,7 @@ function admin_nav() {
),
array(
'path' => 'configusers/admins',
'url' => 'admin/users/admins.php',
'url' => 'admin/users/institutionadmins.php',
'title' => get_string('adminusers', 'admin'),
'weight' => 40,
),
......
{include file="header.tpl"}
{include file="columnfullstart.tpl"}
<h2>{str tag="institutionadmins" section="admin"}</h2>
<p>{str tag="institutionadminuserspagedescription" section="admin"}</p>
{$adminusersform}
{include file="columnfullend.tpl"}
{include file="footer.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