roles interface: MDL-16965 make a view that explains the has_capability calculation...
[moodle.git] / user / selector / search.php
CommitLineData
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
33require_once(dirname(__FILE__) . '/../../config.php');
34require_once($CFG->dirroot . '/user/selector/lib.php');
35
36// Check access.
37require_login();
38if (!confirm_sesskey()) {
39 print_error('invalidsesskey');
40}
41
42// Get the search parameter.
43$search = required_param('search', PARAM_RAW);
44
45// Get and validate the selectorid parameter.
46$selectorhash = required_param('selectorid', PARAM_ALPHANUM);
47if (!isset($USER->userselectors[$selectorhash])) {
48 print_error('unknownuserselector');
49}
50
51// Create the appropriate userselector.
52$options = $USER->userselectors[$selectorhash];
53$classname = $options['class'];
54unset($options['class']);
55$name = $options['name'];
56unset($options['name']);
57if (isset($options['file'])) {
58 require_once($CFG->dirroot . '/' . $options['file']);
59 unset($options['file']);
60}
61$userselector = new $classname($name, $options);
62
63// Do the search and output the results.
64$users = $userselector->find_users($search);
65echo json_encode(array('results' => $users));
66?>