2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
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.
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();
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);
50 $response->toolid = $tool->id;
51 $response->toolname = htmlspecialchars($tool->name);
52 $response->tooldomain = htmlspecialchars($tool->tooldomain);
55 $response->toolid = $toolid;
58 if (!empty($toolid)) {
59 //Look up privacy settings
63 FROM {lti_types_config}
66 AND name IN (\'sendname\', \'sendemailaddr\', \'acceptgrades\', \'allowroster\')
69 $privacyconfigs = $DB->get_records_sql($query, array('typeid' => $toolid));
70 foreach($privacyconfigs as $config){
71 $configname = $config->name;
72 $response->$configname = $config->value;
78 echo json_encode($response);