Merge branch 'MDL-51445_m30v1' of https://github.com/sbourget/moodle into MOODLE_30_S...
[moodle.git] / mod / lti / toolssettings.php
blob3c7c3481acf9990767b36b3c4f3d608b8b24a4d1
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/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);
41 require_sesskey();
43 // Check this is for a tool created from a tool proxy.
44 $err = empty($id);
45 if (!$err) {
46 $type = lti_get_type_type_config($id);
47 $err = empty($type->toolproxyid);
49 if ($err) {
50 $redirect = new moodle_url('/mod/lti/typessettings.php',
51 array('action' => $action, 'id' => $id, 'sesskey' => sesskey(), 'tab' => $tab));
52 redirect($redirect);
55 $pageurl = new moodle_url('/mod/lti/toolssettings.php');
56 if (!empty($id)) {
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);
67 redirect($redirect);
68 } else if (($action == 'reject') || ($action == 'delete')) {
69 lti_set_state_for_type($id, LTI_TOOL_STATE_REJECTED);
70 redirect($redirect);
73 if (lti_request_is_using_ssl() && !empty($type->lti_secureicon)) {
74 $type->oldicon = $type->lti_secureicon;
75 } else {
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();
83 if (!empty($id)) {
84 $type->id = $id;
85 lti_update_type($type, $data);
86 } else {
87 $type->state = LTI_TOOL_STATE_CONFIGURED;
88 lti_add_type($type, $data);
90 redirect($redirect);
91 } else if ($form->is_cancelled()) {
92 redirect($redirect);
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);
106 $form->display();
107 echo $OUTPUT->box_end();
108 echo $OUTPUT->footer();