suspended.json.php 2.43 KB
Newer Older
Nigel McNie's avatar
Nigel McNie committed
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 core
 * @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
30
define('JSON', 1);

Nigel McNie's avatar
Nigel McNie committed
31
32
require(dirname(dirname(dirname(__FILE__))) . '/init.php');

33
34
json_headers();

Nigel McNie's avatar
Nigel McNie committed
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
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);

$dbprefix = get_config('dbprefix');

// NOTE: the check is not done on the 'active' column here, since suspended
// users are by definition not active. However deleted users are filtered out.
$count = get_field_sql('SELECT COUNT(*) FROM usr WHERE suspendedcusr IS NOT NULL AND deleted = 0');
$data = get_records_sql_array('SELECT u.id, u.firstname, u.lastname, u.studentid, u.suspendedreason AS reason,
    i.displayname AS institution, ua.firstname AS cusrfirstname, ua.lastname AS cusrlastname
    FROM ' . $dbprefix . 'usr u
    LEFT JOIN ' . $dbprefix . 'institution i ON (u.institution = i.name)
    LEFT JOIN usr ua on (ua.id = u.suspendedcusr)
    WHERE u.suspendedcusr IS NOT NULL
    AND u.deleted = 0
    ORDER BY u.suspendedctime
    LIMIT ?
    OFFSET ?', array($limit, $offset));
if (!$data) {
    $data = array();
}
else {
    foreach ($data as &$record) {
        $record->name      = full_name($record);
        $record->firstname = $record->cusrfirstname;
        $record->lastname  = $record->cusrlastname;
        $record->cusrname  = full_name($record);
        unset($record->firstname, $record->lastname);
    }
}

echo json_encode(array(
    'count'    => $count,
    'limit'    => $limit,
    'offset'   => $offset,
    'data'     => $data
));

?>