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 * Handle the return back to Moodle from the tool provider
22 * @copyright 2011 onwards MRTODO
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once('../../config.php');
27 require_once($CFG->dirroot.'/mod/lti/lib.php');
28 require_once($CFG->dirroot.'/mod/lti/locallib.php');
30 $courseid = required_param('course', PARAM_INT);
31 $instanceid = required_param('instanceid', PARAM_INT);
33 $errormsg = optional_param('lti_errormsg', '', PARAM_RAW);
34 $unsigned = optional_param('unsigned', '0', PARAM_INT);
36 $launchcontainer = optional_param('launch_container', LTI_LAUNCH_CONTAINER_WINDOW, PARAM_INT);
38 $course = $DB->get_record('course', array('id' => $courseid));
40 require_login($course);
42 if (!empty($errormsg)) {
43 $url = new moodle_url('/mod/lti/return.php', array('course' => $courseid));
46 $pagetitle = strip_tags($course->shortname);
47 $PAGE->set_title($pagetitle);
48 $PAGE->set_heading($course->fullname);
50 //Avoid frame-in-frame action
51 if ($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED || $launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) {
52 $PAGE->set_pagelayout('embedded');
54 $PAGE->set_pagelayout('incourse');
57 echo $OUTPUT->header();
59 echo get_string('lti_launch_error', 'lti');
61 echo htmlspecialchars($errormsg);
63 $canaddtools = has_capability('mod/lti:addcoursetool', get_context_instance(CONTEXT_COURSE, $courseid));
65 if ($unsigned == 1 && $canaddtools) {
68 $links = new stdClass();
69 $coursetooleditor = new moodle_url('/mod/lti/instructor_edit_tool_type.php', array('course' => $courseid, 'action' => 'add'));
70 $links->course_tool_editor = $coursetooleditor->out(false);
72 $adminrequesturl = new moodle_url('/mod/lti/request_tool.php', array('instanceid' => $instanceid));
73 $links->admin_request_url = $adminrequesturl->out(false);
75 echo get_string('lti_launch_error_unsigned_help', 'lti', $links);
77 echo get_string('lti_launch_error_tool_request', 'lti', $links);
80 echo $OUTPUT->footer();
82 $courseurl = new moodle_url('/course/view.php', array('id' => $courseid));
83 $url = $courseurl->out();
85 //Avoid frame-in-frame action
86 if ($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED || $launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) {
87 //Output a page containing some script to break out of frames and redirect them
92 <script type=\"text/javascript\">
95 top.location.href = '{$url}';
101 $clickhere = get_string('return_to_course', 'lti', (object)array('link' => $url));
112 echo '</body></html>';
114 //If no error, take them back to the course