friendsearch.php 1.42 KB
Newer Older
1
2
3
4
5
6
<?php
/**
 *
 * @package    mahara
 * @subpackage core
 * @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
 *
 */

define('INTERNAL', 1);
define('JSON', 1);

require(dirname(dirname(__FILE__)) . '/init.php');
16
require_once('searchlib.php');
17
18
19
20

$query  = param_variable('query', '');
$offset = param_integer('offset', 0);
$limit  = param_integer('limit', 10);
21
$filter = param_alpha('filter', 'all');
22

23
$searchtype = 'myfriends';
24
25
if ($extradata = param_variable('extradata', null)) {
    $extradata = json_decode($extradata);
26
27
    if ($extradata->searchtype) {
        $searchtype = $extradata->searchtype;
28
29
30
    }
}

31
32
if ($searchtype == 'myfriends') {
    $data = search_friend($filter, $limit, $offset, $query);
33
34
35
    $data['filter'] = $filter;
}
else {
36
37
38
39
40
    $options = array('exclude' => $USER->get('id'));
    if ($filter == 'myinstitutions') {
        $options['myinstitutions'] = true;
    }
    $data = search_user($query, $limit, $offset, $options);
41
    $data['query'] = $query;
42
43
44
    if (!empty($options['myinstitutions'])) {
        $data['filter'] = $filter;
    }
45
46
}

47
48
require_once('group.php');
$admingroups = (bool) group_get_user_admintutor_groups();
49
build_userlist_html($data, $searchtype, $admingroups, $filter, $query);
50
unset($data['data']);
51
52

json_reply(false, array('data' => $data));