MDL-20534 lti: various fixes
[moodle.git] / mod / lti / typessettings.php
CommitLineData
996b0fd9 1<?php
61eb12d4
CS
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.
13//
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/>.
16//
996b0fd9
CS
17// This file is part of BasicLTI4Moodle
18//
19// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)
20// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web
21// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI
22// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS
23// are already supporting or going to support BasicLTI. This project Implements the consumer
24// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.
25// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem
26// at the GESSI research group at UPC.
27// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI
28// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a
29// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.
30//
31// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis
32// of the Universitat Politecnica de Catalunya http://www.upc.edu
33// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu
996b0fd9
CS
34
35/**
36 * This file contains the script used to clone Moodle admin setting page.
61eb12d4 37 * It is used to create a new form used to pre-configure lti activities
996b0fd9 38 *
61eb12d4
CS
39 * @package mod
40 * @subpackage lti
41 * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
996b0fd9 42 * marc.alier@upc.edu
61eb12d4
CS
43 * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
44 * @author Marc Alier
45 * @author Jordi Piguillem
46 * @author Nikolas Galanis
47 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
996b0fd9
CS
48 */
49
50require_once('../../config.php');
51require_once($CFG->libdir.'/adminlib.php');
52require_once($CFG->dirroot.'/mod/lti/edit_form.php');
53require_once($CFG->dirroot.'/mod/lti/locallib.php');
54
55$section = 'modsettinglti';
56$return = optional_param('return', '', PARAM_ALPHA);
57$adminediting = optional_param('adminedit', -1, PARAM_BOOL);
64ce589b 58$action = optional_param('action', null, PARAM_ACTION);
996b0fd9
CS
59$id = optional_param('id', null, PARAM_INT);
60$useexisting = optional_param('useexisting', null, PARAM_INT);
61$definenew = optional_param('definenew', null, PARAM_INT);
62
63/// no guest autologin
64require_login(0, false);
65$url = new moodle_url('/mod/lti/typesettings.php');
66$PAGE->set_url($url);
67
68admin_externalpage_setup('managemodules'); // Hacky solution for printing the admin page
69
70$tab = optional_param('tab', '', PARAM_ALPHAEXT);
71$redirect = "$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti&tab={$tab}";
72
73/// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
74
75$statusmsg = '';
76$errormsg = '';
77$focus = '';
78
79$data = data_submitted();
80
64ce589b
EL
81// Any posted data & any action
82if (!empty($data) || !empty($action)) {
83 require_sesskey();
84}
85
86if (isset($data->submitbutton)) {
996b0fd9 87 $type = new stdClass();
e27cb316 88
996b0fd9
CS
89 if (isset($id)) {
90 $type->id = $id;
91
92 lti_update_type($type, $data);
e27cb316 93
996b0fd9 94 redirect($redirect);
996b0fd9
CS
95 } else {
96 $type->state = LTI_TOOL_STATE_CONFIGURED;
e27cb316 97
996b0fd9 98 lti_add_type($type, $data);
e27cb316 99
996b0fd9 100 redirect($redirect);
996b0fd9 101 }
64ce589b 102
ea04a9f9 103} else if (isset($data->cancel)) {
996b0fd9 104 redirect($redirect);
996b0fd9 105
64ce589b 106} else if ($action == 'accept') {
996b0fd9
CS
107 lti_set_state_for_type($id, LTI_TOOL_STATE_CONFIGURED);
108 redirect($redirect);
996b0fd9 109
64ce589b 110} else if ($action == 'reject') {
996b0fd9
CS
111 lti_set_state_for_type($id, LTI_TOOL_STATE_REJECTED);
112 redirect($redirect);
996b0fd9 113
64ce589b 114} else if ($action == 'delete') {
996b0fd9
CS
115 lti_delete_type($id);
116 redirect($redirect);
996b0fd9
CS
117}
118
119/// print header stuff ------------------------------------------------------------
120$PAGE->set_focuscontrol($focus);
121if (empty($SITE->fullname)) {
122 $PAGE->set_title($settingspage->visiblename);
123 $PAGE->set_heading($settingspage->visiblename);
124
d8d04121 125 $PAGE->navbar->add(get_string('lti_administration', 'lti'), $CFG->wwwroot.'/admin/settings.php?section=modsettinglti');
996b0fd9
CS
126
127 echo $OUTPUT->header();
128
129 echo $OUTPUT->box(get_string('configintrosite', 'admin'));
130
131 if ($errormsg !== '') {
132 echo $OUTPUT->notification($errormsg);
133
134 } else if ($statusmsg !== '') {
135 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
136 }
137
138 // ---------------------------------------------------------------------------------------------------------------
139
140 echo '<form action="typesettings.php" method="post" id="'.$id.'" >';
141 echo '<div class="settingsform clearfix">';
142 echo html_writer::input_hidden_params($PAGE->url);
143 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
144 echo '<input type="hidden" name="return" value="'.$return.'" />';
145
146 echo $settingspage->output_html();
147
148 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges', 'admin').'" /></div>';
149
150 echo '</div>';
151 echo '</form>';
152
153} else {
154 if ($PAGE->user_allowed_editing()) {
155 $url = clone($PAGE->url);
156 if ($PAGE->user_is_editing()) {
157 $caption = get_string('blockseditoff');
158 $url->param('adminedit', 'off');
159 } else {
160 $caption = get_string('blocksediton');
161 $url->param('adminedit', 'on');
162 }
163 $buttons = $OUTPUT->single_button($url, $caption, 'get');
164 }
165
166 $PAGE->set_title("$SITE->shortname: " . get_string('toolsetup', 'lti'));
167
d8d04121 168 $PAGE->navbar->add(get_string('lti_administration', 'lti'), $CFG->wwwroot.'/admin/settings.php?section=modsettinglti');
996b0fd9
CS
169
170 echo $OUTPUT->header();
171
172 if ($errormsg !== '') {
173 echo $OUTPUT->notification($errormsg);
174
175 } else if ($statusmsg !== '') {
176 echo $OUTPUT->notification($statusmsg, 'notifysuccess');
177 }
178
179 // ---------------------------------------------------------------------------------------------------------------
180 echo $OUTPUT->heading(get_string('toolsetup', 'lti'));
181 echo $OUTPUT->box_start('generalbox');
182 if ($action == 'add') {
183 $form = new mod_lti_edit_types_form(null, (object)array('isadmin' => true));
184 $form->display();
185 } else if ($action == 'update') {
186 $form = new mod_lti_edit_types_form('typessettings.php?id='.$id, (object)array('isadmin' => true));
187 $type = lti_get_type_type_config($id);
188 $form->set_data($type);
189 $form->display();
190 }
191
192 echo $OUTPUT->box_end();
193}
194
195echo $OUTPUT->footer();