admins.php 2.56 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
/**
 * This program is part of Mahara
 *
 *  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 2 of the License, or
 *  (at your option) any later version.
 *
 *  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.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 *
 * @package    mahara
 * @subpackage admin
 * @author     Nigel McNie <nigel@catalyst.net.nz>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
 *
 */

27
28
// NOTE: This script is VERY SIMILAR to the staffusers.php script, a bug fixed
// here might need to be fixed there too.
29
30
define('INTERNAL', 1);
define('ADMIN', 1);
31
define('MENUITEM', 'configusers');
32
33
define('SUBMENUITEM', 'adminusers');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
Martyn Smith's avatar
Martyn Smith committed
34
define('TITLE', get_string('adminusers', 'admin'));
35
require_once('pieforms/pieform.php');
36
$smarty = smarty();
37
38
39
40
41
42
43
44
45
46
47
48

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

$form = array(
    'name' => 'adminusers',
    'elements' => array(
        'users' => array(
            'type' => 'userlist',
            'title' => get_string('adminusers', 'admin'),
            'defaultvalue' => $adminusers,
49
50
51
52
            'filter' => false,
            'rules' => array(
                'required' => true
            )
53
54
        ),
        'submit' => array(
55
56
            'type' => 'submit',
            'value' => get_string('submit')
57
58
59
60
        )
    )
);

61
function adminusers_submit(Pieform $form, $values) {
62
    global $SESSION;
63
    $table = get_config('dbprefix') . 'usr';
64
65
    
    db_begin();
66
67
68
69
70
71
    execute_sql('UPDATE ' . $table . '
        SET admin = 0
        WHERE admin = 1');
    execute_sql('UPDATE ' . $table . '
        SET admin = 1
        WHERE id IN (' . join(',', $values['users']) . ')');
72
73
    db_commit();
    $SESSION->add_ok_msg(get_string('adminusersupdated', 'admin'));
74
    redirect(get_config('wwwroot') . 'admin/users/admins.php');
75
76
}

77
$smarty->assign('adminusersform', pieform($form));
78
$smarty->display('admin/users/admin.tpl');
79
80

?>