Some bug fixing & mostly done with help message when an unsigned request doesn't...
[moodle.git] / mod / lti / return.php
1 <?php
3 //This page is used to handle the return back to Moodle from the tool provider
5 require_once('../../config.php');
6 require_once($CFG->dirroot.'/mod/lti/lib.php');
8 $courseid = required_param('course', PARAM_INT);
9 $errormsg = optional_param('lti_errormsg', '', PARAM_RAW);
10 $unsigned = optional_param('unsigned', '0', PARAM_INT);
11 $launchcontainer = optional_param('launch_container', LTI_LAUNCH_CONTAINER_WINDOW, PARAM_INT);
13 $course = $DB->get_record('course', array('id' => $courseid));
15 require_login($course);
17 if(!empty($errormsg)){
18     $url = new moodle_url('/mod/lti/return.php', array('course' => $courseid));
19     $PAGE->set_url($url);
20     
21     $pagetitle = strip_tags($course->shortname);
22     $PAGE->set_title($pagetitle);
23     $PAGE->set_heading($course->fullname);
24     
25     //Avoid frame-in-frame action
26     if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED || $launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) {
27         $PAGE->set_pagelayout('embedded');
28     } else {
29         $PAGE->set_pagelayout('incourse');
30     }
31             
32     echo $OUTPUT->header();
33     
34     echo get_string('lti_launch_error', 'lti');
35     
36     //TODO: Add some help around this error message.
37     echo htmlspecialchars($errormsg);
39     if($unsigned == 1){
40         echo '<br /><br />';
41         echo get_string('lti_launch_error_unsigned_help', 'lti');
42     }
43     
44     echo $OUTPUT->footer();
45 } else {
46     $courseurl = new moodle_url('/course/view.php', array('id' => $courseid));
47     $url = $courseurl->out();
48     
49     //Avoid frame-in-frame action
50     if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED || $launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) {
51         //Output a page containing some script to break out of frames and redirect them
52         
53         echo '<html><body>';
54         
55         $script = <<<SCRIPT
56             <script type='text/javascript'>
57             //<![CDATA[
58                 if(window != top){
59                     top.location.href = '{$url}';
60                 }
61             //]]
62             </script>
63 SCRIPT;
64         
65         $clickhere = get_string('return_to_course', 'lti', (object)array('link' => $url));
67         $noscript = <<<NOSCRIPT
68             <noscript>
69                 {$clickhere}
70             </noscript>
71 NOSCRIPT;
72                     
73         echo $script;
74         echo $noscript;
75                     
76         echo '</body></html>';
77     } else {
78         //If no error, take them back to the course
79         redirect($url);
80     }
81 }