Commit 34c58397 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Institution staff users page

parent ffc5f1af
<?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/staffusers');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('staffusers', 'admin'));
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
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,
);
}
// Get users who are currently staff
$staffusers = get_column('usr_institution', 'usr', 'staff', 1, 'institution', $institution);
$form = array(
'name' => 'staffusers',
'elements' => array(
'users' => array(
'type' => 'userlist',
'title' => get_string('staffusers', 'admin'),
'defaultvalue' => $staffusers,
'filter' => false,
'lefttitle' => get_string('institutionmembers', 'admin'),
'righttitle' => get_string('institutionstaff', '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 staffusers_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/institutionstaff.php');
}
db_begin();
execute_sql('UPDATE {usr_institution}
SET staff = 0
WHERE staff = 1 AND institution = ' . db_quote($inst));
if ($values['users']) {
execute_sql('UPDATE {usr_institution}
SET staff = 1
WHERE usr IN (' . join(',', $values['users']) . ') AND institution = ' . db_quote($inst));
}
db_commit();
$SESSION->add_ok_msg(get_string('staffusersupdated', 'admin'));
redirect('/admin/users/institutionstaff.php');
}
$smarty->assign('staffusersform', pieform($form));
$smarty->display('admin/users/institutionstaff.tpl');
?>
......@@ -53,6 +53,7 @@ if ($action == 'search') {
$params->institution = param_alphanum('institution', null);
$params->f = param_alpha('f', null);
$params->l = param_alpha('l', null);
$params->institution_requested = param_alphanum('institution_requested', null);
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
......@@ -60,7 +61,11 @@ if ($action == 'search') {
$sortdir = param_alpha('sortdir', 'asc');
json_headers();
$data['data'] = build_admin_user_search_results($params, $offset, $limit, $sortby, $sortdir);
if (param_boolean('raw', false)) {
$data = get_admin_user_search_results($params, $offset, $limit, $sortby, $sortdir);
} else {
$data['data'] = build_admin_user_search_results($params, $offset, $limit, $sortby, $sortdir);
}
$data['error'] = false;
$data['message'] = null;
echo json_encode($data);
......
......@@ -36,7 +36,6 @@ require('searchlib.php');
$search = (object) array(
'query' => trim(param_variable('query', '')),
'institution' => param_alphanum('institution', 'all'),
'f' => param_alpha('f', null), // first initial
'l' => param_alpha('l', null), // last initial
);
......@@ -48,8 +47,10 @@ $limit = param_integer('limit', 10);
if ($USER->get('admin')) {
$institutions = get_records_array('institution');
$search->institution = param_alphanum('institution', 'all');
} else {
$institutions = get_records_select_array('institution', "name IN ('" . join("','", array_keys($USER->get('admininstitutions'))) . "')");
$search->institution_requested = param_alphanum('institution_requested', 'all');
}
$smarty = smarty(array('adminusersearch'));
......
......@@ -100,6 +100,7 @@ function UserSearch() {
self.resetInitials();
self.params.query = $('query').value;
self.params.institution = $('institution').value;
self.params.institution_requested = $('institution_requested').value;
self.doSearch();
e.stop();
}
......
......@@ -217,6 +217,7 @@ $string['adminusersupdated'] = 'Admin users updated';
// Staff Users
$string['staffuserspagedescription'] = 'Here you can choose which users are staff for the site. The current staff are on the right, and potential staff are on the left.';
$string['institutionstaffuserspagedescription'] = 'Here you can choose which users are staff for your institution. The current staff are on the right, and potential staff are on the left.';
$string['potentialstaff'] = 'Potential Staff';
$string['currentstaff'] = 'Current Staff';
$string['staffusersupdated'] = 'Staff users updated';
......
......@@ -150,32 +150,36 @@ function get_admin_user_search_results($search, $offset, $limit, $sortby, $sortd
global $USER;
if (!$USER->get('admin')) {
$allowed = $USER->get('admininstitutions');
if ($search->institution == 'all' || !isset($allowed[$search->institution])) {
$constraints[] = array('field' => 'institution_requested',
'type' => 'in',
'list' => $allowed);
} else {
$constraints[] = array('field' => 'institution_requested',
'type' => 'equals',
'string' => $search->institution);
foreach (array('institution', 'institution_requested') as $p) {
if (isset($search->{$p})) {
if ($search->{$p} == 'all' || !isset($allowed[$p])) {
$constraints[] = array('field' => $p,
'type' => 'in',
'list' => $allowed);
} else {
$constraints[] = array('field' => $p,
'type' => 'equals',
'string' => $search->{$p});
}
}
}
} else if ($search->institution != 'all') {
$constraints[] = array('field' => 'institution',
'type' => 'equals',
'string' => $search->institution);
}
return admin_user_search($queries, $constraints, $offset, $limit, $sortby, $sortdir);
$results = admin_user_search($queries, $constraints, $offset, $limit, $sortby, $sortdir);
foreach ($results['data'] as &$result) {
$result['name'] = display_name($result);
}
return $results;
}
function build_admin_user_search_results($search, $offset, $limit, $sortby, $sortdir) {
global $USER;
if (empty($search->institution)) {
$search->institution = 'all';
}
$results = get_admin_user_search_results($search, $offset, $limit, $sortby, $sortdir);
$params = array();
......
......@@ -1316,7 +1316,7 @@ function admin_nav() {
),
array(
'path' => 'configusers/staff',
'url' => 'admin/users/staff.php',
'url' => 'admin/users/institutionstaff.php',
'title' => get_string('staffusers', 'admin'),
'weight' => 30,
),
......
{include file="header.tpl"}
{include file="columnfullstart.tpl"}
<h2>{str tag="institutionstaff" section="admin"}</h2>
<p>{str tag="institutionstaffuserspagedescription" section="admin"}</p>
{$staffusersform}
{include file="columnfullend.tpl"}
{include file="footer.tpl"}
......@@ -40,7 +40,11 @@
{if count($institutions) > 1}
<span class="institutions">
<label>Institution:
{if $USER->get('admin')}
<select name="institution" id="institution">
{else}
<select name="institution_requested" id="institution">
{/if}
<option value="all" selected>{str tag=all}</option>
{foreach from=$institutions item=i}
<option value="{$i->name}">{$i->displayname}</option>
......
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