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
21 * @copyright Copyright (c) 2011 Moodlerooms Inc. (http://www.moodlerooms.com)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @author Chris Scribner
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), '*', MUST_EXIST
);
39 $lti = $DB->get_record('lti', array('id' => $instanceid), '*', MUST_EXIST
);
40 $cm = get_coursemodule_from_instance('lti', $lti->id
, $lti->course
, false, MUST_EXIST
);
41 $context = context_module
::instance($cm->id
);
43 require_login($course);
45 if (!empty($errormsg)) {
46 $url = new moodle_url('/mod/lti/return.php', array('course' => $courseid));
49 $pagetitle = strip_tags($course->shortname
);
50 $PAGE->set_title($pagetitle);
51 $PAGE->set_heading($course->fullname
);
53 //Avoid frame-in-frame action
54 if ($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED ||
$launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS
) {
55 $PAGE->set_pagelayout('embedded');
57 $PAGE->set_pagelayout('incourse');
60 echo $OUTPUT->header();
61 echo $OUTPUT->heading(format_string($lti->name
, true, array('context' => $context)));
63 echo get_string('lti_launch_error', 'lti');
65 echo htmlspecialchars($errormsg);
67 $canaddtools = has_capability('mod/lti:addcoursetool', context_course
::instance($courseid));
69 if ($unsigned == 1 && $canaddtools) {
72 $links = new stdClass();
73 $coursetooleditor = new moodle_url('/mod/lti/instructor_edit_tool_type.php', array('course' => $courseid, 'action' => 'add'));
74 $links->course_tool_editor
= $coursetooleditor->out(false);
76 $adminrequesturl = new moodle_url('/mod/lti/request_tool.php', array('instanceid' => $instanceid));
77 $links->admin_request_url
= $adminrequesturl->out(false);
79 echo get_string('lti_launch_error_unsigned_help', 'lti', $links);
81 echo get_string('lti_launch_error_tool_request', 'lti', $links);
84 echo $OUTPUT->footer();
86 $courseurl = new moodle_url('/course/view.php', array('id' => $courseid));
87 $url = $courseurl->out();
89 //Avoid frame-in-frame action
90 if ($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED ||
$launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS
) {
91 //Output a page containing some script to break out of frames and redirect them
96 <script type=\"text/javascript\">
99 top.location.href = '{$url}';
105 $clickhere = get_string('return_to_course', 'lti', (object)array('link' => $url));
116 echo '</body></html>';
118 //If no error, take them back to the course