Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
/mod/lti/ -> return.php (source)

Differences Between: [Versions 310 and 403]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   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.
   8  //
   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.
  13  //
  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/>.
  16  
  17  /**
  18   * Handle the return back to Moodle from the tool provider
  19   *
  20   * @package mod_lti
  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
  24   */
  25  
  26  require_once('../../config.php');
  27  require_once($CFG->dirroot.'/mod/lti/lib.php');
  28  require_once($CFG->dirroot.'/mod/lti/locallib.php');
  29  
  30  $courseid = required_param('course', PARAM_INT);
  31  $instanceid = optional_param('instanceid', 0, PARAM_INT);
  32  
  33  $errormsg = optional_param('lti_errormsg', '', PARAM_TEXT);
  34  $msg = optional_param('lti_msg', '', PARAM_TEXT);
  35  $unsigned = optional_param('unsigned', '0', PARAM_INT);
  36  
  37  $launchcontainer = optional_param('launch_container', LTI_LAUNCH_CONTAINER_WINDOW, PARAM_INT);
  38  
  39  $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
  40  $lti = null;
  41  $context = null;
  42  if (!empty($instanceid)) {
  43      $lti = $DB->get_record('lti', array('id' => $instanceid), '*', MUST_EXIST);
  44      $cm = get_coursemodule_from_instance('lti', $lti->id, $lti->course, false, MUST_EXIST);
  45      $context = context_module::instance($cm->id);
  46  }
  47  
  48  
  49  require_login($course);
  50  require_sesskey();
  51  
  52  if (!empty($errormsg) || !empty($msg)) {
  53      $url = new moodle_url('/mod/lti/return.php', array('course' => $courseid));
  54      $PAGE->set_url($url);
  55  
  56      $pagetitle = strip_tags($course->shortname);
  57      $PAGE->set_title($pagetitle);
  58      $PAGE->set_heading($course->fullname);
  59  
  60      // Avoid frame-in-frame action.
  61      if ($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED || $launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) {
  62          $PAGE->set_pagelayout('embedded');
  63      } else {
  64          $PAGE->set_pagelayout('incourse');
  65      }
  66  
  67      echo $OUTPUT->header();
  68      if (!empty($lti) and !empty($context)) {
  69          echo $OUTPUT->heading(format_string($lti->name, true, array('context' => $context)));
  70      }
  71  }
  72  
  73  if (!empty($errormsg)) {
  74      echo get_string('lti_launch_error', 'lti');
  75  
  76      p($errormsg);
  77  
  78      if ($unsigned == 1) {
  79  
  80          $contextcourse = context_course::instance($courseid);
  81          echo '<br /><br />';
  82          $links = new stdClass();
  83  
  84          if (has_capability('mod/lti:addcoursetool', $contextcourse)) {
  85              $coursetooleditor = new moodle_url('/mod/lti/instructor_edit_tool_type.php',
  86                  array('course' => $courseid, 'action' => 'add', 'sesskey' => sesskey()));
  87              $links->course_tool_editor = $coursetooleditor->out(false);
  88  
  89              echo get_string('lti_launch_error_unsigned_help', 'lti', $links);
  90          }
  91  
  92          if (!empty($lti) && has_capability('mod/lti:requesttooladd', $contextcourse)) {
  93              $adminrequesturl = new moodle_url('/mod/lti/request_tool.php', array('instanceid' => $lti->id, 'sesskey' => sesskey()));
  94              $links->admin_request_url = $adminrequesturl->out(false);
  95  
  96              echo get_string('lti_launch_error_tool_request', 'lti', $links);
  97          }
  98      }
  99  
 100      echo $OUTPUT->footer();
 101  } else if (!empty($msg)) {
 102  
 103      p($msg);
 104  
 105      echo $OUTPUT->footer();
 106  
 107  } else {
 108      $courseurl = new moodle_url('/course/view.php', array('id' => $courseid));
 109      $url = $courseurl->out();
 110  
 111      // Avoid frame-in-frame action.
 112      if ($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED || $launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS) {
 113          // Output a page containing some script to break out of frames and redirect them.
 114  
 115          echo '<html><body>';
 116  
 117          $script = "
 118              <script type=\"text/javascript\">
 119              //<![CDATA[
 120                  if(window != top){
 121                      top.location.href = '{$url}';
 122                  } else {
 123                      window.location.href = '{$url}';
 124                  }
 125              //]]
 126              </script>
 127          ";
 128  
 129          $clickhere = get_string('return_to_course', 'lti', (object)array('link' => $url));
 130  
 131          $noscript = "
 132              <noscript>
 133                  {$clickhere}
 134              </noscript>
 135          ";
 136  
 137          echo $script;
 138          echo $noscript;
 139  
 140          echo '</body></html>';
 141      } else {
 142          // If no error, take them back to the course.
 143          redirect($url);
 144      }
 145  }