Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

   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  $PAGE->set_primary_active_tab('siteadminnode');
  77  $PAGE->set_secondary_active_tab('modules');
  78  
  79  $form = new mod_lti_register_types_form($pageurl, (object)$data);
  80  
  81  if ($form->is_cancelled()) {
  82      redirect($redirect);
  83  } else if ($data = $form->get_data()) {
  84      $id = lti_add_tool_proxy($data);
  85      redirect($redirect);
  86  } else {
  87      $PAGE->set_title(get_string('toolregistration', 'lti'));
  88      $PAGE->navbar->add(get_string('lti_administration', 'lti'), $redirect);
  89  
  90      echo $OUTPUT->header();
  91      echo $OUTPUT->heading(get_string('toolregistration', 'lti'));
  92      echo $OUTPUT->box_start('generalbox');
  93      if ($action == 'update') {
  94          $toolproxy = lti_get_tool_proxy_config($id);
  95          $form->set_data($toolproxy);
  96          if ($toolproxy->state == LTI_TOOL_PROXY_STATE_ACCEPTED) {
  97              $form->disable_fields();
  98          }
  99      }
 100      $form->display();
 101  
 102      echo $OUTPUT->box_end();
 103      echo $OUTPUT->footer();
 104  }