MDL-30344 lti - Fix issue with privacy settings not working for a course level tool...
[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);
038d8e30 42 $toolid = optional_param('toolid', 0, PARAM_INT);
e27cb316 43
038d8e30
CS
44 if(empty($toolid) && !empty($toolurl)){
45 $tool = lti_get_tool_by_url_match($toolurl, $courseid);
46
47 if(!empty($tool)){
48 $toolid = $tool->id;
4c598b13 49
038d8e30
CS
50 $response->toolid = $tool->id;
51 $response->toolname = htmlspecialchars($tool->name);
52 $response->tooldomain = htmlspecialchars($tool->tooldomain);
53 }
54 } else {
55 $response->toolid = $toolid;
56 }
57
58 if (!empty($toolid)) {
4c598b13
CS
59 //Look up privacy settings
60 $query =
61 '
62 SELECT name, value
63 FROM {lti_types_config}
64 WHERE
65 typeid = :typeid
66 AND name IN (\'sendname\', \'sendemailaddr\', \'acceptgrades\', \'allowroster\')
67 ';
68
038d8e30 69 $privacyconfigs = $DB->get_records_sql($query, array('typeid' => $toolid));
4c598b13
CS
70 foreach($privacyconfigs as $config){
71 $configname = $config->name;
72 $response->$configname = $config->value;
73 }
6831c7cd 74 }
6831c7cd
CS
75 break;
76}
77
78echo json_encode($response);
79
61eb12d4 80die;