MDL-69240 tool_moodlenet: Clean MoodleNet profile field
[moodle.git] / mod / lti / registrationreturn.php
blob184949b3b1d6029b78feb049ee3b6dd4a8a36da5
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 * Handle the return from the Tool Provider after registering a tool proxy.
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->dirroot.'/mod/lti/locallib.php');
29 $top = optional_param('top', 0, PARAM_INT);
30 $msg = optional_param('lti_msg', '', PARAM_TEXT);
31 $err = optional_param('lti_errormsg', '', PARAM_TEXT);
32 $id = optional_param('id', 0, PARAM_INT);
34 // No guest autologin.
35 require_sesskey();
36 require_login(0, false);
38 $systemcontext = context_system::instance();
39 require_capability('moodle/site:config', $systemcontext);
41 if (empty($top)) {
43 $params = array();
44 $params['sesskey'] = sesskey();
45 $params['top'] = '1';
46 if (!empty($msg)) {
47 $params['lti_msg'] = $msg;
49 if (!empty($err)) {
50 $params['lti_errormsg'] = $err;
52 if (!empty($id)) {
53 $params['id'] = $id;
55 $redirect = new moodle_url('/mod/lti/registrationreturn.php', $params);
56 $redirect = $redirect->out(false);
58 $clickhere = get_string('click_to_continue', 'lti', (object)array('link' => $redirect));
59 $html = <<< EOD
60 <html>
61 <head>
62 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
63 <script type="text/javascript">
64 //<![CDATA[
65 top.location.href = '{$redirect}';
66 //]]
67 </script>
68 </head>
69 <body>
70 <noscript>
71 {$clickhere}
72 </noscript>
73 </body>
74 </html>
75 EOD;
77 // We always send the headers because they set the encoding.
78 send_headers('text/html; charset=utf-8', false);
79 echo $html;
81 } else if (!empty($msg) && !empty($err)) {
83 $params = array();
84 $params['sesskey'] = sesskey();
85 $params['top'] = '1';
86 if (!empty($err)) {
87 $params['lti_errormsg'] = $err;
89 if (!empty($id)) {
90 $params['id'] = $id;
92 $redirect = new moodle_url('/mod/lti/registrationreturn.php', $params);
93 $redirect = $redirect->out(false);
94 redirect($redirect, $err);
96 } else {
98 $redirect = new moodle_url('/mod/lti/toolproxies.php');
99 if (!empty($id)) {
100 $toolproxy = $DB->get_record('lti_tool_proxies', array('id' => $id));
101 switch($toolproxy->state) {
102 case LTI_TOOL_PROXY_STATE_ACCEPTED:
103 $redirect->param('tab', 'tp_accepted');
104 break;
105 case LTI_TOOL_PROXY_STATE_REJECTED:
106 $redirect->param('tab', 'tp_rejected');
107 break;
108 case LTI_TOOL_PROXY_STATE_PENDING:
109 // Change the status to configured.
110 $toolproxy->state = LTI_TOOL_PROXY_STATE_CONFIGURED;
111 lti_update_tool_proxy($toolproxy);
115 $redirect = $redirect->out();
117 if (empty($msg)) {
118 $msg = $err;
120 redirect($redirect, $msg);