Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 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.

Differences Between: [Versions 39 and 401] [Versions 39 and 402] [Versions 39 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   * Generates an XML IMS Cartridge with the details for the given tool
  19   *
  20   * @package    enrol_lti
  21   * @copyright  2016 John Okely <john@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once(dirname(__FILE__) . '/../../config.php');
  26  require_once($CFG->dirroot . '/lib/weblib.php');
  27  
  28  $toolid = null;
  29  $token = null;
  30  
  31  $filearguments = get_file_argument();
  32  $arguments = explode('/', trim($filearguments, '/'));
  33  if (count($arguments) >= 2) { // Can put cartridge.xml at the end, or anything really.
  34      list($toolid, $token) = $arguments;
  35  }
  36  
  37  $toolid = optional_param('id', $toolid, PARAM_INT);
  38  $token = optional_param('token', $token, PARAM_ALPHANUM);
  39  
  40  // Only show the cartridge if the token parameter is correct.
  41  // If we do not compare with a shared secret, someone could very easily
  42  // guess an id for the enrolment.
  43  if (!\enrol_lti\helper::verify_cartridge_token($toolid, $token)) {
  44      throw new \moodle_exception('incorrecttoken', 'enrol_lti');
  45  }
  46  
  47  $tool = \enrol_lti\helper::get_lti_tool($toolid);
  48  
  49  if (!is_enabled_auth('lti')) {
  50      print_error('pluginnotenabled', 'auth', '', get_string('pluginname', 'auth_lti'));
  51  
  52  } else if (!enrol_is_enabled('lti')) {
  53      print_error('enrolisdisabled', 'enrol_lti');
  54  
  55  } else if ($tool->status != ENROL_INSTANCE_ENABLED) {
  56      print_error('enrolisdisabled', 'enrol_lti');
  57  
  58  } else {
  59      header('Content-Type: text/xml; charset=utf-8');
  60      echo \enrol_lti\helper::create_cartridge($toolid);
  61  }