access.json.php 1.56 KB
Newer Older
1
2
3
4
5
<?php
/**
 *
 * @package    mahara
 * @subpackage core
6
 * @author     Catalyst IT Ltd
7
8
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
9
10
11
12
13
14
15
16
17
18
 *
 */

// NOTE: this JSON script is used by the 'viewacl' element. It could probably
// be moved elsewhere without harm if necessary (e.g. if the 'viewacl' element
// was used in more places
define('INTERNAL', 1);
define('JSON', 1);

require(dirname(dirname(__FILE__)) . '/init.php');
19
require_once('searchlib.php');
20
21
22
23
24
25
26

$type   = param_variable('type');
$query  = param_variable('query', '');
$limit  = param_integer('limit', 10);
$offset = param_integer('offset', 0);

switch ($type) {
27
28
29
    case 'friend':
        $data = search_user($query, $limit, $offset,  array('exclude' => $USER->get('id'), 'friends' => true));
        break;
30
    case 'user':
31
        $data = search_user($query, $limit, $offset, array('exclude' => $USER->get('id')));
32
33
        break;
    case 'group':
34
        require_once('group.php');
35
        $data = search_group($query, $limit, $offset, '');
36
37
38
        $roles = get_records_array('grouptype_roles');
        $data['roles'] = array();
        foreach ($roles as $r) {
39
            $data['roles'][$r->grouptype][] = array('name' => $r->role, 'display' => get_string($r->role, 'grouptype.'.$r->grouptype));
40
        }
41
42
43
        foreach ($data['data'] as &$r) {
            $r->url = group_homepage_url($r);
        }
44
45
46
47
48
        break;
}

$data['error'] = false;
$data['message'] = '';
49
json_reply(false, $data);