institutionstaff.php 3.98 KB
Newer Older
1 2
<?php
/**
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4 5
 * Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
 *                         http://wiki.mahara.org/Contributors
6
 *
7 8 9 10
 * 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 3 of the License, or
 * (at your option) any later version.
11
 *
12 13 14 15
 * 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.
16
 *
17 18
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 20 21
 *
 * @package    mahara
 * @subpackage admin
22
 * @author     Catalyst IT Ltd
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
24
 * @copyright  (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
25 26 27 28 29 30 31 32
 *
 */

// 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);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
Richard Mansfield's avatar
Richard Mansfield committed
33
define('TITLE', get_string('institutionstaff', 'admin'));
34
require_once('pieforms/pieform.php');
35
define('MENUITEM', 'manageinstitutions/institutionstaff');
36

Richard Mansfield's avatar
Richard Mansfield committed
37
require_once('institution.php');
Richard Mansfield's avatar
Richard Mansfield committed
38 39 40
$s = institution_selector_for_page(param_alphanum('institution', false),
                                   get_config('wwwroot') . 'admin/users/institutionstaff.php');
$institution = $s['institution'];
41

Richard Mansfield's avatar
Richard Mansfield committed
42
$smarty = smarty();
43 44 45 46 47
if ($institution === false) {
    $smarty->display('admin/users/noinstitutions.tpl');
    exit;
}

48
// Get users who are currently staff
49 50 51 52 53 54
$staffusers = get_column_sql('SELECT ui.usr
    FROM {usr_institution} ui
    LEFT JOIN  {usr} u ON ui.usr = u.id
    WHERE ui.staff = 1
    AND ui.institution = ?
    AND u.deleted = 0', array($institution));
55 56 57 58 59 60 61 62 63 64 65

$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'),
66
            'searchparams' => array('limit' => 100, 'query' => '', 'member' => 1, 
67
                                    'institution' => $institution),
68
            'searchscript' => 'admin/users/userinstitutionsearch.json.php',
69
        ),
70 71 72 73
        'institution' => array(
            'type' => 'hidden',
            'value' => $institution,
        ),
74 75 76 77 78 79 80 81 82 83 84
        'submit' => array(
            'type' => 'submit',
            'value' => get_string('submit')
        )
    )
);

function staffusers_submit(Pieform $form, $values) {
    global $SESSION, $USER;

    $inst = $values['institution'];
85
    if (empty($inst) || !$USER->can_edit_institution($inst)) {
86 87 88 89 90 91 92 93 94 95 96
        $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
97
            WHERE usr IN (' . join(',', array_map('intval', $values['users'])) . ') AND institution = ' . db_quote($inst));
98 99 100
    }
    db_commit();
    $SESSION->add_ok_msg(get_string('staffusersupdated', 'admin'));
101
    redirect('/admin/users/institutionstaff.php?institution=' . $inst);
102 103
}

Richard Mansfield's avatar
Richard Mansfield committed
104 105
$smarty->assign('institutionselector', $s['institutionselector']);
$smarty->assign('INLINEJAVASCRIPT', $s['institutionselectorjs']);
106
$smarty->assign('staffusersform', pieform($form));
107
$smarty->assign('PAGEHEADING', TITLE);
108 109 110
$smarty->display('admin/users/institutionstaff.tpl');

?>