2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * Handle the return from the Tool Provider after registering a tool proxy.
21 * @copyright 2015 Ryan Wyllie
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once('../../config.php');
26 require_once($CFG->dirroot
.'/mod/lti/lib.php');
27 require_once($CFG->dirroot
.'/mod/lti/locallib.php');
29 $status = optional_param('status', '', PARAM_TEXT
);
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.
36 require_login(0, false);
38 $systemcontext = context_system
::instance();
39 require_capability('moodle/site:config', $systemcontext);
41 $pageurl = new moodle_url('/mod/lti/externalregistrationreturn.php');
42 $PAGE->set_context($systemcontext);
43 $PAGE->set_url($pageurl);
44 $PAGE->set_pagelayout('maintenance');
45 $output = $PAGE->get_renderer('mod_lti');
46 echo $output->header();
48 // Check status and lti_errormsg.
49 if ($status !== 'success' && empty($err)) {
50 // We have a failed status and an empty lti_errormsg. Check if we can use lti_msg.
52 // The lti_msg attribute is set, use this as the error message.
55 // Otherwise, use our generic error message.
56 $err = get_string('failedtocreatetooltype', 'mod_lti');
59 $params = array('message' => s($msg), 'error' => s($err), 'id' => $id, 'status' => s($status));
61 $page = new \mod_lti\output\
external_registration_return_page();
62 echo $output->render($page);
64 $PAGE->requires
->js_call_amd('mod_lti/external_registration_return', 'init', $params);
65 echo $output->footer();