admins.php 2.41 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 staffusers.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/adminusers');
17
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
Martyn Smith's avatar
Martyn Smith committed
18
define('TITLE', get_string('adminusers', 'admin'));
Penny Leach's avatar
Penny Leach committed
19
20
21
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'adminusers');
22
require_once('activity.php');
23
24
25

// Get users who are currently administrators
// @todo later, exclude the user with uid 1
26
$adminusers = get_column('usr', 'id', 'admin', 1, 'deleted', 0);
27

28
$form = pieform(array(
29
30
31
32
33
34
    'name' => 'adminusers',
    'elements' => array(
        'users' => array(
            'type' => 'userlist',
            'title' => get_string('adminusers', 'admin'),
            'defaultvalue' => $adminusers,
35
36
            'lefttitle' => get_string('potentialadmins', 'admin'),
            'righttitle' => get_string('currentadmins', 'admin'),
37
38
            'leftarrowlabel' => get_string('makeadminsintousers', 'admin'),
            'rightarrowlabel' => get_string('makeusersintoadmins', 'admin'),
39
40
41
42
43
            'searchparams' => array(
                'query' => '',
                'limit' => 250,
                'orderby' => 'lastname',
            ),
44
45
46
            'rules' => array(
                'required' => true
            )
47
48
        ),
        'submit' => array(
49
            'class' => 'btn-primary',
50
51
            'type' => 'submit',
            'value' => get_string('submit')
52
53
        )
    )
54
));
55

56
function adminusers_submit(Pieform $form, $values) {
57
    global $SESSION;
Aaron Wells's avatar
Aaron Wells committed
58

59
    db_begin();
60
    execute_sql('UPDATE {usr}
61
62
        SET "admin" = 0
        WHERE "admin" = 1');
63
    execute_sql('UPDATE {usr}
64
        SET "admin" = 1
65
        WHERE id IN (' . join(',', array_map('intval', $values['users'])) . ')');
66
    activity_add_admin_defaults($values['users']);
67
68
    db_commit();
    $SESSION->add_ok_msg(get_string('adminusersupdated', 'admin'));
69
    redirect('/admin/users/admins.php');
70
71
}

72
$smarty = smarty();
73
74
setpageicon($smarty, 'icon-user');

75
$smarty->assign('adminusersform', $form);
76
$smarty->display('admin/users/admin.tpl');