on-demand release 3.8dev+
[moodle.git] / mod / lti / register.php
blob20a460fae90209e3adc5e434a279d90ca90b3a64
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.
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/>.
17 /**
18 * This file contains all necessary code to launch a Tool Proxy registration
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
26 require_once('../../config.php');
27 require_once($CFG->libdir.'/adminlib.php');
28 require_once($CFG->dirroot.'/mod/lti/locallib.php');
30 $id = required_param('id', PARAM_INT);
31 $tab = optional_param('tab', '', PARAM_ALPHAEXT);
33 require_login(0, false);
35 $redirect = new moodle_url('/mod/lti/toolproxies.php', array('tab' => $tab));
36 $redirect = $redirect->out();
38 require_sesskey();
40 $toolproxies = $DB->get_records('lti_tool_proxies');
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;
52 $redirect = new moodle_url('/mod/lti/toolproxies.php');
53 if ($duplicate) {
54 redirect($redirect, get_string('duplicateregurl', 'lti'));
58 $profileservice = lti_get_service_by_name('profile');
59 if (empty($profileservice)) {
60 redirect($redirect, get_string('noprofileservice', 'lti'));
63 $url = new moodle_url('/mod/lti/register.php', array('id' => $id));
64 $PAGE->set_url($url);
66 admin_externalpage_setup('ltitoolproxies');
69 $PAGE->set_heading(get_string('toolproxyregistration', 'lti'));
70 $PAGE->set_title("{$SITE->shortname}: " . get_string('toolproxyregistration', 'lti'));
72 // Print the page header.
73 echo $OUTPUT->header();
75 echo $OUTPUT->heading(get_string('toolproxyregistration', 'lti'));
77 echo $OUTPUT->box_start('generalbox');
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()));
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";
87 echo '<iframe id="contentframe" height="600px" width="100%" src="' . $registration->out() . '" onload="doOnload()"></iframe>';
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\';
97 function doOnload() {
98 window.clearTimeout(mod_lti_timer);
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");
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"));
117 resize();
119 Y.on("windowresize", resize);
121 //]]
122 </script>
125 echo $resize;
127 // Finish the page.
128 echo $OUTPUT->box_end();
129 echo $OUTPUT->footer();