b1c0ed81059c50e040c3ca65c8e13c75bbbfc39a
[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 $launchcontainer = optional_param('launch_container', LTI_LAUNCH_CONTAINER_WINDOW, PARAM_INT);
12 $course = $DB->get_record('course', array('id' => $courseid));
14 require_login($course);
16 if(!empty($errormsg)){
17     $url = new moodle_url('/mod/lti/return.php', array('course' => $courseid));
18     $PAGE->set_url($url);
19     
20     $pagetitle = strip_tags($course->shortname);
21     $PAGE->set_title($pagetitle);
22     $PAGE->set_heading($course->fullname);
23     
24     //Avoid frame-in-frame action
25     if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED || $launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) {
26         $PAGE->set_pagelayout('embedded');
27     } else {
28         $PAGE->set_pagelayout('incourse');
29     }
30             
31     echo $OUTPUT->header();
32     
33     //TODO: Add some help around this error message.
34     echo htmlspecialchars($errormsg);
35     
36     echo $OUTPUT->footer();
37 } else {
38     $courseurl = new moodle_url('/course/view.php', array('id' => $courseid));
39     $url = $courseurl->out();
40     
41     //Avoid frame-in-frame action
42     if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED || $launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) {
43         //Output a page containing some script to break out of frames and redirect them
44         
45         echo '<html><body>';
46         
47         $script = <<<SCRIPT
48             <script type='text/javascript'>
49             //<![CDATA[
50                 if(window != top){
51                     top.location.href = '{$url}';
52                 }
53             //]]
54             </script>
55 SCRIPT;
56         
57         $clickhere = get_string('return_to_course', 'lti', (object)array('link' => $url));
59         $noscript = <<<NOSCRIPT
60             <noscript>
61                 {$clickhere}
62             </noscript>
63 NOSCRIPT;
64                     
65         echo $script;
66         echo $noscript;
67                     
68         echo '</body></html>';
69     } else {
70         //If no error, take them back to the course
71         redirect($url);
72     }
73 }