Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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 all necessary code to launch a Tool Proxy registration
  19   *
  20   * @package mod_lti
  21   * @copyright  2014 Vital Source Technologies http://vitalsource.com
  22   * @author     Stephen Vickers
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require_once('../../config.php');
  27  require_once($CFG->libdir.'/adminlib.php');
  28  require_once($CFG->dirroot.'/mod/lti/locallib.php');
  29  
  30  $id = required_param('id', PARAM_INT);
  31  $tab = optional_param('tab', '', PARAM_ALPHAEXT);
  32  
  33  require_login(0, false);
  34  
  35  $redirect = new moodle_url('/mod/lti/toolproxies.php', array('tab' => $tab));
  36  $redirect = $redirect->out();
  37  
  38  require_sesskey();
  39  
  40  $toolproxies = $DB->get_records('lti_tool_proxies');
  41  
  42  $duplicate = false;
  43  foreach ($toolproxies as $key => $toolproxy) {
  44      if (($toolproxy->state == LTI_TOOL_PROXY_STATE_PENDING) || ($toolproxy->state == LTI_TOOL_PROXY_STATE_ACCEPTED)) {
  45          if ($toolproxy->regurl == $toolproxies[$id]->regurl) {
  46              $duplicate = true;
  47              break;
  48          }
  49      }
  50  }
  51  
  52  $redirect = new moodle_url('/mod/lti/toolproxies.php');
  53  if ($duplicate) {
  54      redirect($redirect,  get_string('duplicateregurl', 'lti'));
  55  }
  56  
  57  
  58  $profileservice = lti_get_service_by_name('profile');
  59  if (empty($profileservice)) {
  60      redirect($redirect,  get_string('noprofileservice', 'lti'));
  61  }
  62  
  63  $url = new moodle_url('/mod/lti/register.php', array('id' => $id));
  64  $PAGE->set_url($url);
  65  
  66  admin_externalpage_setup('ltitoolproxies');
  67  
  68  
  69  $PAGE->set_heading(get_string('toolproxyregistration', 'lti'));
  70  $PAGE->set_title("{$SITE->shortname}: " . get_string('toolproxyregistration', 'lti'));
  71  
  72  // Print the page header.
  73  echo $OUTPUT->header();
  74  
  75  echo $OUTPUT->heading(get_string('toolproxyregistration', 'lti'));
  76  
  77  echo $OUTPUT->box_start('generalbox');
  78  
  79  // Request the registration request content with an object tag.
  80  $registration = new moodle_url('/mod/lti/registration.php',
  81      array('id' => $id, 'sesskey' => sesskey()));
  82  
  83  echo "<p id=\"id_warning\" style=\"display: none; color: red; font-weight: bold; margin-top: 1em; padding-top: 1em;\">\n";
  84  echo get_string('register_warning', 'lti');
  85  echo "\n</p>\n";
  86  
  87  echo '<iframe id="contentframe" height="600px" width="100%" src="' . $registration->out() . '" onload="doOnload()"></iframe>';
  88  
  89  // Output script to make the object tag be as large as possible.
  90  $resize = '
  91          <script type="text/javascript">
  92          //<![CDATA[
  93              function doReveal() {
  94                var el = document.getElementById(\'id_warning\');
  95                el.style.display = \'block\';
  96              }
  97              function doOnload() {
  98                  window.clearTimeout(mod_lti_timer);
  99              }
 100              var mod_lti_timer = window.setTimeout(doReveal, 20000);
 101              YUI().use("node", "event", function(Y) {
 102                  //Take scrollbars off the outer document to prevent double scroll bar effect
 103                  var doc = Y.one("body");
 104                  doc.setStyle("overflow", "hidden");
 105  
 106                  var frame = Y.one("#contentframe");
 107                  var padding = 15; //The bottom of the iframe wasn\'t visible on some themes. Probably because of border widths, etc.
 108                  var lastHeight;
 109                  var resize = function(e) {
 110                      var viewportHeight = doc.get("winHeight");
 111                      if(lastHeight !== Math.min(doc.get("docHeight"), viewportHeight)){
 112                          frame.setStyle("height", viewportHeight - frame.getY() - padding + "px");
 113                          lastHeight = Math.min(doc.get("docHeight"), doc.get("winHeight"));
 114                      }
 115                  };
 116  
 117                  resize();
 118  
 119                  Y.on("windowresize", resize);
 120              });
 121          //]]
 122          </script>
 123  ';
 124  
 125  echo $resize;
 126  
 127  // Finish the page.
 128  echo $OUTPUT->box_end();
 129  echo $OUTPUT->footer();