suspended.php 3.52 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
27
28
<?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
 *
 */

define('INTERNAL', 1);
define('ADMIN', 1);
29
define('MENUITEM', 'configusers');
30
31
define('SUBMENUITEM', 'suspendedusers');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
Nigel McNie's avatar
Nigel McNie committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require_once('pieforms/pieform.php');

$smarty = smarty(array('tablerenderer'));

$smarty->assign('INLINEJAVASCRIPT', <<<EOF
var suspendedlist = new TableRenderer(
    'suspendedlist',
    'suspended.json.php',
    [
        'name',
        'studentid',
        'institution',
        'cusrname',
        'reason',
        function (rowdata) { return INPUT({'type': 'checkbox', 'name': 'usr_' + rowdata.id}); }
    ]
);
suspendedlist.updateOnLoad();

EOF
);

$form = new Pieform(array(
    'name' => 'buttons',
    'renderer' => 'oneline',
    'elements' => array(
        'unsuspend' => array(
            'type' => 'submit',
            'name' => 'unsuspend',
            'value' => get_string('unsuspendusers')
        ),
        'export' => array(
            'type' => 'submit',
            'name' => 'export',
            'value' => get_string('exportuserprofiles')
        ),
        'delete' => array(
            'type' => 'submit',
            'name' => 'delete',
            'value' => get_string('deleteusers')
        )
    )
));
$smarty->assign('buttonformopen', $form->get_form_tag());
$smarty->assign('buttonform', $form->build(false));
77

78
$smarty->display('admin/users/suspended.tpl');
79

80
function buttons_submit_unsuspend(Pieform $form, $values) {
Nigel McNie's avatar
Nigel McNie committed
81
82
83
84
85
86
87
88
    global $SESSION;

    $ids = get_user_ids_from_post();
    foreach ($ids as $userid) {
        unsuspend_user($userid);
    }

    $SESSION->add_ok_msg(get_string('usersunsuspendedsuccessfully'));
89
    redirect('admin/users/suspended.php');
Nigel McNie's avatar
Nigel McNie committed
90
91
}

92
function buttons_submit_export(Pieform $form, $values) {
Nigel McNie's avatar
Nigel McNie committed
93
94
95
    global $SESSION;
    $ids = get_user_ids_from_post();
    $SESSION->add_info_msg(get_string('exportingnotsupportedyet'));
96
    redirect('admin/users/suspended.php');
Nigel McNie's avatar
Nigel McNie committed
97
98
}

99
function buttons_submit_delete(Pieform $form, $values) {
Nigel McNie's avatar
Nigel McNie committed
100
101
102
103
104
105
106
107
    global $SESSION;

    $ids = get_user_ids_from_post();
    foreach ($ids as $userid) {
        delete_user($userid);
    }

    $SESSION->add_ok_msg(get_string('usersdeletedsuccessfully'));
108
    redirect('admin/users/suspended.php');
Nigel McNie's avatar
Nigel McNie committed
109
110
111
112
113
114
115
116
117
118
119
120
121
}

function get_user_ids_from_post() {
    $ids = array();
    foreach ($_POST as $key => $value) {
        if (substr($key, 0, 4) == 'usr_') {
            $ids[] = intval(substr($key, 4));
        }
    }

    if (!$ids) {
        global $SESSION;
        $SESSION->add_info_msg(get_string('nousersselected'));
122
        redirect('admin/users/suspended.php');
Nigel McNie's avatar
Nigel McNie committed
123
124
125
126
127
    }

    return $ids;
}

128
?>