staff.php 2.2 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('pieforms/pieform.php');
23
require_once('activity.php');
24
25

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

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

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

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

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

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