admins.php 2.93 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'));
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
$smarty = smarty();
40
41
42
43
44
45
46
47
48
49
50
51

// 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,
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
77
78
    execute_sql('DELETE FROM {usr_activity_preference}
        WHERE activity IN (SELECT name FROM {activity_type}
            WHERE admin = 1)
79
        AND usr NOT IN (' . join(',', $values['users']) . ')');
80
81
    db_commit();
    $SESSION->add_ok_msg(get_string('adminusersupdated', 'admin'));
82
    redirect('/admin/users/admins.php');
83
84
}

85
$smarty->assign('adminusersform', pieform($form));
86
$smarty->display('admin/users/admin.tpl');
87
88

?>