f05c20fb |
1 | <?php // $Id$ |
2 | |
3 | /////////////////////////////////////////////////////////////////////////// |
4 | // // |
5 | // NOTICE OF COPYRIGHT // |
6 | // // |
7 | // Moodle - Modular Object-Oriented Dynamic Learning Environment // |
8 | // http://moodle.org // |
9 | // // |
10 | // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com // |
11 | // // |
12 | // This program is free software; you can redistribute it and/or modify // |
13 | // it under the terms of the GNU General Public License as published by // |
14 | // the Free Software Foundation; either version 2 of the License, or // |
15 | // (at your option) any later version. // |
16 | // // |
17 | // This program is distributed in the hope that it will be useful, // |
18 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
19 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
20 | // GNU General Public License for more details: // |
21 | // // |
22 | // http://www.gnu.org/copyleft/gpl.html // |
23 | // // |
24 | /////////////////////////////////////////////////////////////////////////// |
25 | |
26 | /** |
27 | * Code to search for users in response to an ajax call from a user selector. |
28 | * |
29 | * @license http://www.gnu.org/copyleft/gpl.html GNU Public License |
30 | * @package userselector |
31 | */ |
32 | |
33 | require_once(dirname(__FILE__) . '/../../config.php'); |
34 | require_once($CFG->dirroot . '/user/selector/lib.php'); |
35 | |
36 | // Check access. |
d56f9e65 |
37 | if (!isloggedin()) {; |
38 | print_error('mustbeloggedin'); |
39 | } |
f05c20fb |
40 | if (!confirm_sesskey()) { |
41 | print_error('invalidsesskey'); |
42 | } |
43 | |
44 | // Get the search parameter. |
45 | $search = required_param('search', PARAM_RAW); |
46 | |
47 | // Get and validate the selectorid parameter. |
48 | $selectorhash = required_param('selectorid', PARAM_ALPHANUM); |
49 | if (!isset($USER->userselectors[$selectorhash])) { |
50 | print_error('unknownuserselector'); |
51 | } |
52 | |
53 | // Create the appropriate userselector. |
54 | $options = $USER->userselectors[$selectorhash]; |
55 | $classname = $options['class']; |
56 | unset($options['class']); |
57 | $name = $options['name']; |
58 | unset($options['name']); |
59 | if (isset($options['file'])) { |
60 | require_once($CFG->dirroot . '/' . $options['file']); |
61 | unset($options['file']); |
62 | } |
63 | $userselector = new $classname($name, $options); |
64 | |
65 | // Do the search and output the results. |
66 | $users = $userselector->find_users($search); |
d56f9e65 |
67 | foreach ($users as &$group) { |
68 | foreach ($group as &$user) { |
69 | $user->fullname = fullname($user); |
70 | } |
71 | } |
72 | |
73 | |
74 | header('Content-type: application/json'); |
f05c20fb |
75 | echo json_encode(array('results' => $users)); |
76 | ?> |