MDL-30344 lti - Fix issue with privacy settings not working for a course level tool...
[moodle.git] / mod / lti / ajax.php
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.
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/>.
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.
20  *
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
26  */
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);
46             
47             if(!empty($tool)){
48                 $toolid = $tool->id;
49             
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)) {
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                         
69             $privacyconfigs = $DB->get_records_sql($query, array('typeid' => $toolid));
70             foreach($privacyconfigs as $config){
71                 $configname = $config->name;
72                 $response->$configname = $config->value;
73             }
74         }
75         break;
76 }
78 echo json_encode($response);
80 die;