weekly release 3.3dev
[moodle.git] / mod / lti / registersettings.php
blob797f2ada2485bd4363e473de1ae8f05833a149a8
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 the script used to register a new external tool.
20 * It is used to create a new form used to configure the capabilities
21 * and services to be offered to the tool provider.
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
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');
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);
39 if ($returnto == 'toolconfigure') {
40 $returnurl = new moodle_url($CFG->wwwroot . '/mod/lti/toolconfigure.php');
43 // No guest autologin.
44 require_login(0, false);
46 $isupdate = !empty($id);
47 $pageurl = new moodle_url('/mod/lti/registersettings.php');
48 if ($isupdate) {
49 $pageurl->param('id', $id);
51 if (!empty($returnto)) {
52 $pageurl->param('returnto', $returnto);
54 $PAGE->set_url($pageurl);
56 admin_externalpage_setup('ltitoolproxies');
58 $redirect = new moodle_url('/mod/lti/toolproxies.php', array('tab' => $tab));
59 $redirect = $redirect->out();
60 if (!empty($returnurl)) {
61 $redirect = $returnurl;
64 require_sesskey();
66 if ($action == 'delete') {
67 lti_delete_tool_proxy($id);
68 redirect($redirect);
71 $data = array();
72 if ($isupdate) {
73 $data['isupdate'] = true;
76 $form = new mod_lti_register_types_form($pageurl, (object)$data);
78 if ($form->is_cancelled()) {
79 redirect($redirect);
80 } else if ($data = $form->get_data()) {
81 $id = lti_add_tool_proxy($data);
82 redirect($redirect);
83 } else {
84 $PAGE->set_title("{$SITE->shortname}: " . get_string('toolregistration', 'lti'));
85 $PAGE->navbar->add(get_string('lti_administration', 'lti'), $redirect);
87 echo $OUTPUT->header();
88 echo $OUTPUT->heading(get_string('toolregistration', 'lti'));
89 echo $OUTPUT->box_start('generalbox');
90 if ($action == 'update') {
91 $toolproxy = lti_get_tool_proxy_config($id);
92 $form->set_data($toolproxy);
93 if ($toolproxy->state == LTI_TOOL_PROXY_STATE_ACCEPTED) {
94 $form->disable_fields();
97 $form->display();
99 echo $OUTPUT->box_end();
100 echo $OUTPUT->footer();