admins.php 3.06 KB
Newer Older
1
2
<?php
/**
Francois Marier's avatar
Francois Marier committed
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
 *
Francois Marier's avatar
Francois Marier committed
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
 *
Francois Marier's avatar
Francois Marier committed
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
 *
Francois Marier's avatar
Francois Marier committed
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
// NOTE: This script is VERY SIMILAR to the staffusers.php script, a bug fixed
// here might need to be fixed there too.
30
31
define('INTERNAL', 1);
define('ADMIN', 1);
32
define('MENUITEM', 'configusers/adminusers');
33
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
Martyn Smith's avatar
Martyn Smith committed
34
define('TITLE', get_string('adminusers', 'admin'));
Penny Leach's avatar
Penny Leach committed
35
36
37
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'adminusers');
38
require_once('pieforms/pieform.php');
39
require_once('activity.php');
40
41
42

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

45
$form = pieform(array(
46
47
48
49
50
51
    'name' => 'adminusers',
    'elements' => array(
        'users' => array(
            'type' => 'userlist',
            'title' => get_string('adminusers', 'admin'),
            'defaultvalue' => $adminusers,
52
            'filter' => false,
53
54
            'lefttitle' => get_string('potentialadmins', 'admin'),
            'righttitle' => get_string('currentadmins', 'admin'),
55
56
57
58
59
            'searchparams' => array(
                'query' => '',
                'limit' => 250,
                'orderby' => 'lastname',
            ),
60
61
62
            'rules' => array(
                'required' => true
            )
63
64
        ),
        'submit' => array(
65
66
            'type' => 'submit',
            'value' => get_string('submit')
67
68
        )
    )
69
));
70

71
function adminusers_submit(Pieform $form, $values) {
72
73
74
    global $SESSION;
    
    db_begin();
75
    execute_sql('UPDATE {usr}
76
77
        SET admin = 0
        WHERE admin = 1');
78
    execute_sql('UPDATE {usr}
79
        SET admin = 1
80
        WHERE id IN (' . join(',', array_map('intval', $values['users'])) . ')');
81
    activity_add_admin_defaults($values['users']);
82
83
    db_commit();
    $SESSION->add_ok_msg(get_string('adminusersupdated', 'admin'));
84
    redirect('/admin/users/admins.php');
85
86
}

87
88
$smarty = smarty();
$smarty->assign('adminusersform', $form);
89
$smarty->assign('PAGEHEADING', TITLE);
90
$smarty->display('admin/users/admin.tpl');