diff --git a/mod/lti/lang/en/lti.php b/mod/lti/lang/en/lti.php index 092b2bfaab06c..34e4376676584 100644 --- a/mod/lti/lang/en/lti.php +++ b/mod/lti/lang/en/lti.php @@ -160,7 +160,6 @@ $string['viewsubmissions'] = 'View submissions and grading screen'; //New admin strings - $string['show_in_course'] = 'Show tool type when creating tool instances'; $string['delegate'] = 'Delegate to Instructor'; $string['tool_settings'] = 'Tool Settings'; @@ -210,6 +209,8 @@ $string['custom_config'] = 'Using custom tool configuration.'; $string['tool_config_not_found'] = 'Tool configuration not found for this URL.'; +$string['return_to_course'] = 'Click here to return to the course.'; + //Instance help $string['external_tool_type_help'] = <<out(); + + $launchcontainer = lti_get_launch_container($instance, $typeconfig); + + //Add the return URL. We send the launch container along to help us avoid frames-within-frames when the user returns + $url = new moodle_url('/mod/lti/return.php', array('course' => $course->id, 'launch_container' => $launchcontainer)); + $requestparams['launch_presentation_return_url'] = $url->out(false); // Concatenate the custom parameters from the administrator and the instructor // Instructor parameters are only taken into consideration if the administrator @@ -1032,4 +1038,21 @@ function lti_get_type($typeid){ global $DB; return $DB->get_record('lti_types', array('id' => $typeid)); +} + +function lti_get_launch_container($lti, $toolconfig){ + $launchcontainer = $lti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT ? + $toolconfig['launchcontainer'] : + $lti->launchcontainer; + + $devicetype = get_device_type(); + + //Scrolling within the object element doesn't work on iOS or Android + //Opening the popup window also had some issues in testing + //For mobile devices, always take up the entire screen to ensure the best experience + if($devicetype === 'mobile' || $devicetype === 'tablet' ){ + $launchcontainer = LTI_LAUNCH_CONTAINER_REPLACE_MOODLE_WINDOW; + } + + return $launchcontainer; } \ No newline at end of file diff --git a/mod/lti/return.php b/mod/lti/return.php new file mode 100644 index 0000000000000..b1c0ed81059c5 --- /dev/null +++ b/mod/lti/return.php @@ -0,0 +1,73 @@ +dirroot.'/mod/lti/lib.php'); + +$courseid = required_param('course', PARAM_INT); +$errormsg = optional_param('lti_errormsg', '', PARAM_RAW); +$launchcontainer = optional_param('launch_container', LTI_LAUNCH_CONTAINER_WINDOW, PARAM_INT); + +$course = $DB->get_record('course', array('id' => $courseid)); + +require_login($course); + +if(!empty($errormsg)){ + $url = new moodle_url('/mod/lti/return.php', array('course' => $courseid)); + $PAGE->set_url($url); + + $pagetitle = strip_tags($course->shortname); + $PAGE->set_title($pagetitle); + $PAGE->set_heading($course->fullname); + + //Avoid frame-in-frame action + if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED || $launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) { + $PAGE->set_pagelayout('embedded'); + } else { + $PAGE->set_pagelayout('incourse'); + } + + echo $OUTPUT->header(); + + //TODO: Add some help around this error message. + echo htmlspecialchars($errormsg); + + echo $OUTPUT->footer(); +} else { + $courseurl = new moodle_url('/course/view.php', array('id' => $courseid)); + $url = $courseurl->out(); + + //Avoid frame-in-frame action + if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED || $launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) { + //Output a page containing some script to break out of frames and redirect them + + echo ''; + + $script = << +SCRIPT; + + $clickhere = get_string('return_to_course', 'lti', (object)array('link' => $url)); + + $noscript = << +NOSCRIPT; + + echo $script; + echo $noscript; + + echo ''; + } else { + //If no error, take them back to the course + redirect($url); + } +} \ No newline at end of file diff --git a/mod/lti/view.php b/mod/lti/view.php index fb1759fe5cadc..3ae2098ba1a14 100644 --- a/mod/lti/view.php +++ b/mod/lti/view.php @@ -91,18 +91,7 @@ $url = new moodle_url('/mod/lti/view.php', array('id'=>$cm->id)); $PAGE->set_url($url); -$launchcontainer = $basiclti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT ? - $toolconfig['launchcontainer'] : - $basiclti->launchcontainer; - -$devicetype = get_device_type(); - -//Scrolling within the object element doesn't work on iOS or Android -//Opening the popup window also had some issues in testing -//For mobile devices, always take up the entire screen to ensure the best experience -if($devicetype === 'mobile' || $devicetype === 'tablet' ){ - $launchcontainer = LTI_LAUNCH_CONTAINER_REPLACE_MOODLE_WINDOW; -} +$launchcontainer = lti_get_launch_container($basiclti, $toolconfig); if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS){ $PAGE->set_pagelayout('frametop'); //Most frametops don't include footer, and pre-post blocks