membersearchresults.json.php 2.43 KB
Newer Older
1
2
3
<?php
/**
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4
5
 * Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
 *                         http://wiki.mahara.org/Contributors
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 *
 * 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.
 *
 * 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, see <http://www.gnu.org/licenses/>.
 *
 * @package    mahara
 * @subpackage core
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
24
 * @copyright  (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
25
26
27
 *
 */

28
define('PUBLIC', 1);
29
30
31
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
32
33
require_once('group.php');
require_once('searchlib.php');
34
35
36
37

$id     = param_integer('id');
$query  = trim(param_variable('query', ''));
$offset = param_integer('offset', 0);
38
$limit  = param_integer('limit', 10);
39

40
41
42
define('GROUP', $id);
$group = group_current_group();
if (!is_logged_in() && !$group->public) {
43
    throw new AccessDeniedException(get_string('accessdenied', 'error'));
44
45
}

46
$membershiptype = param_variable('membershiptype', '');
47
48
49
50
51
52
53

if (!empty($membershiptype)) {
    if (group_user_access($id) != 'admin') {
        json_reply('local', get_string('accessdenied', 'error'));
    }
}

54
55
56
57
58
59
$results = get_group_user_search_results($group->id, $query, $offset, $limit, $membershiptype);
if (!param_boolean('html', true)) {
    json_reply(false, $results);
}

list($html, $pagination, $count, $offset, $membershiptype) = group_get_membersearch_data($results, $id, $query, $membershiptype);
60

61
62
63
64
65
json_reply(false, array(
    'message' => null,
    'data' => array(
        'tablerows' => $html,
        'pagination' => $pagination['html'],
66
        'pagination_js' => $pagination['javascript'],
67
68
69
        'count' => $count,
        'results' => $count . ' ' . ($count == 1 ? get_string('result') : get_string('results')),
        'offset' => $offset,
70
        'membershiptype' => $membershiptype,
71
72
73
74
    )
));

?>