MDL-20534 lti: Updating privacy settings dynamically based on matched Launch URL.
[moodle.git] / mod / lti / ajax.php
CommitLineData
6831c7cd 1<?php
61eb12d4
CS
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.
13//
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/>.
16
17/**
8f45215d
CS
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.
61eb12d4
CS
20 *
21 * @package mod
22 * @subpackage xml
8f45215d 23 * @copyright Copyright (c) 2011 Moodlerooms Inc. (http://www.moodlerooms.com)
61eb12d4 24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
8f45215d 25 * @author Chris Scribner
61eb12d4 26 */
6831c7cd
CS
27
28require_once(dirname(__FILE__) . "/../../config.php");
29require_once($CFG->dirroot . '/mod/lti/locallib.php');
30
31$courseid = required_param('course', PARAM_INT);
32
33require_login($courseid, false);
34
35$action = required_param('action', PARAM_TEXT);
36
37$response = new stdClass();
38
ea04a9f9 39switch ($action) {
6831c7cd
CS
40 case 'find_tool_config':
41 $toolurl = required_param('toolurl', PARAM_RAW);
e27cb316 42
6831c7cd 43 $tool = lti_get_tool_by_url_match($toolurl, $courseid);
e27cb316 44
ea04a9f9 45 if (!empty($tool)) {
6831c7cd
CS
46 $response->toolid = $tool->id;
47 $response->toolname = htmlspecialchars($tool->name);
16e8f130 48 $response->tooldomain = htmlspecialchars($tool->tooldomain);
4c598b13
CS
49
50 //Look up privacy settings
51 $query =
52 '
53 SELECT name, value
54 FROM {lti_types_config}
55 WHERE
56 typeid = :typeid
57 AND name IN (\'sendname\', \'sendemailaddr\', \'acceptgrades\', \'allowroster\')
58 ';
59
60 $privacyconfigs = $DB->get_records_sql($query, array('typeid' => $tool->id));
61 foreach($privacyconfigs as $config){
62 $configname = $config->name;
63 $response->$configname = $config->value;
64 }
6831c7cd 65 }
6831c7cd
CS
66 break;
67}
68
69echo json_encode($response);
70
61eb12d4 71die;