Moodle release 2.6.4
[moodle.git] / mod / lti / ajax.php
blobab75cd3e678730e0c4d82c45a429630802c2f8fc
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * AJAX service used when adding an External Tool to provide immediate feedback
19 * of which tool provider is to be used based on the Launch URL.
21 * @package mod
22 * @subpackage xml
23 * @copyright Copyright (c) 2011 Moodlerooms Inc. (http://www.moodlerooms.com)
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 * @author Chris Scribner
28 require_once(dirname(__FILE__) . "/../../config.php");
29 require_once($CFG->dirroot . '/mod/lti/locallib.php');
31 $courseid = required_param('course', PARAM_INT);
33 require_login($courseid, false);
35 $action = required_param('action', PARAM_TEXT);
37 $response = new stdClass();
39 switch ($action) {
40 case 'find_tool_config':
41 $toolurl = required_param('toolurl', PARAM_RAW);
42 $toolid = optional_param('toolid', 0, PARAM_INT);
44 if(empty($toolid) && !empty($toolurl)){
45 $tool = lti_get_tool_by_url_match($toolurl, $courseid);
47 if(!empty($tool)){
48 $toolid = $tool->id;
50 $response->toolid = $tool->id;
51 $response->toolname = htmlspecialchars($tool->name);
52 $response->tooldomain = htmlspecialchars($tool->tooldomain);
54 } else {
55 $response->toolid = $toolid;
58 if (!empty($toolid)) {
59 // Look up privacy settings
60 $query = '
61 SELECT name, value
62 FROM {lti_types_config}
63 WHERE
64 typeid = :typeid
65 AND name IN (\'sendname\', \'sendemailaddr\', \'acceptgrades\')
68 $privacyconfigs = $DB->get_records_sql($query, array('typeid' => $toolid));
69 foreach($privacyconfigs as $config){
70 $configname = $config->name;
71 $response->$configname = $config->value;
74 break;
77 echo json_encode($response);
79 die;