Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 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   * This file contains the script used to register a new external tool.
  19   *
  20   * It is used to create a new form used to configure the capabilities
  21   * and services to be offered to the tool provider.
  22   *
  23   * @package mod_lti
  24   * @copyright  2014 Vital Source Technologies http://vitalsource.com
  25   * @author     Stephen Vickers
  26   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27   */
  28  
  29  require_once('../../config.php');
  30  require_once($CFG->libdir.'/adminlib.php');
  31  require_once($CFG->dirroot.'/mod/lti/register_form.php');
  32  require_once($CFG->dirroot.'/mod/lti/locallib.php');
  33  
  34  $action       = optional_param('action', null, PARAM_ALPHANUMEXT);
  35  $id           = optional_param('id', null, PARAM_INT);
  36  $tab          = optional_param('tab', '', PARAM_ALPHAEXT);
  37  $returnto     = optional_param('returnto', '', PARAM_ALPHA);
  38  
  39  if ($returnto == 'toolconfigure') {
  40      $returnurl = new moodle_url($CFG->wwwroot . '/mod/lti/toolconfigure.php');
  41  }
  42  
  43  // No guest autologin.
  44  require_login(0, false);
  45  
  46  $isupdate = !empty($id);
  47  $pageurl = new moodle_url('/mod/lti/registersettings.php');
  48  if ($isupdate) {
  49      $pageurl->param('id', $id);
  50  }
  51  if (!empty($returnto)) {
  52      $pageurl->param('returnto', $returnto);
  53  }
  54  $PAGE->set_url($pageurl);
  55  
  56  admin_externalpage_setup('ltitoolproxies');
  57  
  58  $redirect = new moodle_url('/mod/lti/toolproxies.php', array('tab' => $tab));
  59  $redirect = $redirect->out();
  60  if (!empty($returnurl)) {
  61      $redirect = $returnurl;
  62  }
  63  
  64  require_sesskey();
  65  
  66  if ($action == 'delete') {
  67      lti_delete_tool_proxy($id);
  68      redirect($redirect);
  69  }
  70  
  71  $data = array();
  72  if ($isupdate) {
  73      $data['isupdate'] = true;
  74  }
  75  
  76  $form = new mod_lti_register_types_form($pageurl, (object)$data);
  77  
  78  if ($form->is_cancelled()) {
  79      redirect($redirect);
  80  } else if ($data = $form->get_data()) {
  81      $id = lti_add_tool_proxy($data);
  82      redirect($redirect);
  83  } else {
  84      $PAGE->set_title("{$SITE->shortname}: " . get_string('toolregistration', 'lti'));
  85      $PAGE->navbar->add(get_string('lti_administration', 'lti'), $redirect);
  86  
  87      echo $OUTPUT->header();
  88      echo $OUTPUT->heading(get_string('toolregistration', 'lti'));
  89      echo $OUTPUT->box_start('generalbox');
  90      if ($action == 'update') {
  91          $toolproxy = lti_get_tool_proxy_config($id);
  92          $form->set_data($toolproxy);
  93          if ($toolproxy->state == LTI_TOOL_PROXY_STATE_ACCEPTED) {
  94              $form->disable_fields();
  95          }
  96      }
  97      $form->display();
  98  
  99      echo $OUTPUT->box_end();
 100      echo $OUTPUT->footer();
 101  }