staff.php 2.28 KB
Newer Older
1 2 3 4 5
<?php
/**
 *
 * @package    mahara
 * @subpackage admin
6
 * @author     Catalyst IT Ltd
7 8
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
9 10 11
 *
 */

12 13
// NOTE: This script is VERY SIMILAR to the adminusers.php script, a bug fixed
// here might need to be fixed there too.
14 15
define('INTERNAL', 1);
define('ADMIN', 1);
16
define('MENUITEM', 'configusers/staffusers');
17
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
Martyn Smith's avatar
Martyn Smith committed
18
define('TITLE', get_string('staffusers', 'admin'));
Penny Leach's avatar
Penny Leach committed
19 20 21
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'staffusers');
22
require_once('activity.php');
23 24

// Get users who are currently staff
25
$staffusers = get_column('usr', 'id', 'staff', 1, 'deleted', 0);
26

27
$form = pieform(array(
28 29 30 31 32 33
    'name' => 'staffusers',
    'elements' => array(
        'users' => array(
            'type' => 'userlist',
            'title' => get_string('staffusers', 'admin'),
            'defaultvalue' => $staffusers,
34
            'lefttitle' => get_string('potentialstaff', 'admin'),
35
            'righttitle' => get_string('currentstaff', 'admin'),
36 37
            'leftarrowlabel' => get_string('makestaffintousers', 'admin'),
            'rightarrowlabel' => get_string('makeusersintostaff', 'admin'),
38 39 40 41 42
            'searchparams' => array(
                'query' => '',
                'limit' => 250,
                'orderby' => 'lastname',
            ),
43 44
        ),
        'submit' => array(
45
            'type' => 'submit',
46
            'class' => 'btn-primary',
47
            'value' => get_string('submit')
48 49
        )
    )
50
));
51

52
function staffusers_submit(Pieform $form, $values) {
53
    global $SESSION;
Aaron Wells's avatar
Aaron Wells committed
54

55
    db_begin();
56
    execute_sql('UPDATE {usr}
57 58
        SET staff = 0
        WHERE staff = 1');
59
    if ($values['users']) {
60
        execute_sql('UPDATE {usr}
61
            SET staff = 1
62
            WHERE id IN (' . join(',', array_map('intval', $values['users'])) . ')');
63
    }
64 65
    db_commit();
    $SESSION->add_ok_msg(get_string('staffusersupdated', 'admin'));
66
    redirect('/admin/users/staff.php');
67 68
}

69
$smarty = smarty();
70
setpageicon($smarty, 'icon-user-friends');
71

72
$smarty->assign('staffusersform', $form);
73
$smarty->display('admin/users/staff.tpl');