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.
20 * It is used to provide immediate feedback
21 * of which tool provider is to be used based on the Launch URL.
25 * @copyright Copyright (c) 2011 Moodlerooms Inc. (http://www.moodlerooms.com)
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 * @author Chris Scribner
29 define('AJAX_SCRIPT', true);
31 require_once(__DIR__
. "/../../config.php");
32 require_once($CFG->dirroot
. '/mod/lti/locallib.php');
34 $courseid = required_param('course', PARAM_INT
);
35 $context = context_course
::instance($courseid);
37 require_login($courseid, false);
39 $action = required_param('action', PARAM_TEXT
);
41 $response = new stdClass();
44 case 'find_tool_config':
45 $toolurl = required_param('toolurl', PARAM_RAW
);
46 $toolid = optional_param('toolid', 0, PARAM_INT
);
48 require_capability('moodle/course:manageactivities', $context);
49 require_capability('mod/lti:addinstance', $context);
51 if (!empty($toolurl) && lti_is_cartridge($toolurl)) {
52 $response->cartridge
= true;
54 if (empty($toolid) && !empty($toolurl)) {
55 $tool = lti_get_tool_by_url_match($toolurl, $courseid);
60 $response->toolid
= $tool->id
;
61 $response->toolname
= s($tool->name
);
62 $response->tooldomain
= s($tool->tooldomain
);
65 $response->toolid
= $toolid;
68 if (!empty($toolid)) {
69 // Look up privacy settings.
72 FROM {lti_types_config}
75 AND name IN (\'sendname\', \'sendemailaddr\', \'acceptgrades\')
78 $privacyconfigs = $DB->get_records_sql($query, array('typeid' => $toolid));
79 $success = count($privacyconfigs) > 0;
80 foreach ($privacyconfigs as $config) {
81 $configname = $config->name
;
82 $response->$configname = $config->value
;
85 $response->error
= s(get_string('tool_config_not_found', 'mod_lti'));
92 echo $OUTPUT->header();
93 echo json_encode($response);