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

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

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

54
function adminusers_submit(Pieform $form, $values) {
55
56
57
    global $SESSION;
    
    db_begin();
58
    execute_sql('UPDATE {usr}
59
60
        SET admin = 0
        WHERE admin = 1');
61
    execute_sql('UPDATE {usr}
62
        SET admin = 1
63
        WHERE id IN (' . join(',', array_map('intval', $values['users'])) . ')');
64
    activity_add_admin_defaults($values['users']);
65
66
    db_commit();
    $SESSION->add_ok_msg(get_string('adminusersupdated', 'admin'));
67
    redirect('/admin/users/admins.php');
68
69
}

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