admins.php 2.87 KB
Newer Older
1
2
<?php
/**
Francois Marier's avatar
Francois Marier committed
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4
 * Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
5
 *
Francois Marier's avatar
Francois Marier committed
6
7
8
9
 * 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.
10
 *
Francois Marier's avatar
Francois Marier committed
11
12
13
14
 * 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.
15
 *
Francois Marier's avatar
Francois Marier committed
16
17
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19
20
 *
 * @package    mahara
 * @subpackage admin
21
 * @author     Catalyst IT Ltd
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
23
 * @copyright  (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
24
25
26
 *
 */

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/adminusers');
32
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
Martyn Smith's avatar
Martyn Smith committed
33
define('TITLE', get_string('adminusers', 'admin'));
Penny Leach's avatar
Penny Leach committed
34
35
36
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'adminusers');
37
require_once('pieforms/pieform.php');
38
require_once('activity.php');
39
$smarty = smarty();
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
46
47
48
49
50
51

$form = array(
    '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
            'rules' => array(
                'required' => true
            )
58
59
        ),
        'submit' => array(
60
61
            'type' => 'submit',
            'value' => get_string('submit')
62
63
64
65
        )
    )
);

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

82
$smarty->assign('adminusersform', pieform($form));
83
$smarty->assign('heading', get_string('adminusers', 'admin'));
84
$smarty->display('admin/users/admin.tpl');
85
86

?>