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

// 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,
51
            'filter' => false,
52
53
            'lefttitle' => get_string('potentialadmins', 'admin'),
            'righttitle' => get_string('currentadmins', 'admin'),
54
55
56
            'rules' => array(
                'required' => true
            )
57
58
        ),
        'submit' => array(
59
60
            'type' => 'submit',
            'value' => get_string('submit')
61
62
63
64
        )
    )
);

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

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

?>