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 * 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.
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/edit_form.php');
32 require_once($CFG->dirroot
.'/mod/lti/locallib.php');
34 $action = optional_param('action', '', PARAM_ALPHANUMEXT
);
35 $id = optional_param('id', '', PARAM_INT
);
36 $tab = optional_param('tab', '', PARAM_ALPHAEXT
);
38 // No guest autologin.
39 require_login(0, false);
43 // Check this is for a tool created from a tool proxy.
46 $type = lti_get_type_type_config($id);
47 $err = empty($type->toolproxyid
);
50 $redirect = new moodle_url('/mod/lti/typessettings.php',
51 array('action' => $action, 'id' => $id, 'sesskey' => sesskey(), 'tab' => $tab));
55 $pageurl = new moodle_url('/mod/lti/toolssettings.php');
57 $pageurl->param('id', $id);
59 $PAGE->set_url($pageurl);
61 admin_externalpage_setup('managemodules'); // Hacky solution for printing the admin page.
63 $redirect = "$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti&tab={$tab}";
65 if ($action == 'accept') {
66 lti_set_state_for_type($id, LTI_TOOL_STATE_CONFIGURED
);
68 } else if (($action == 'reject') ||
($action == 'delete')) {
69 lti_set_state_for_type($id, LTI_TOOL_STATE_REJECTED
);
73 if (lti_request_is_using_ssl() && !empty($type->lti_secureicon
)) {
74 $type->oldicon
= $type->lti_secureicon
;
76 $type->oldicon
= $type->lti_icon
;
79 $form = new mod_lti_edit_types_form($pageurl, (object)array('isadmin' => true, 'istool' => true));
81 if ($data = $form->get_data()) {
82 $type = new stdClass();
85 lti_update_type($type, $data);
87 $type->state
= LTI_TOOL_STATE_CONFIGURED
;
88 lti_add_type($type, $data);
91 } else if ($form->is_cancelled()) {
95 $PAGE->set_title(format_string($SITE->shortname
) . ': ' . get_string('toolsetup', 'lti'));
96 $PAGE->navbar
->add(get_string('lti_administration', 'lti'), $CFG->wwwroot
.'/'.$CFG->admin
.'/settings.php?section=modsettinglti');
98 echo $OUTPUT->header();
99 echo $OUTPUT->heading(get_string('toolsetup', 'lti'));
100 echo $OUTPUT->box_start('generalbox');
102 if ($action == 'update') {
103 $form->set_data($type);
107 echo $OUTPUT->box_end();
108 echo $OUTPUT->footer();