MDL-49609 mod_lti: Add Content-Item message
[moodle.git] / mod / lti / mod_form.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
e3f69b58 33// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu.
996b0fd9
CS
34
35/**
61eb12d4 36 * This file defines the main lti configuration form
996b0fd9 37 *
2b17ec3d 38 * @package mod_lti
61eb12d4 39 * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
996b0fd9 40 * marc.alier@upc.edu
61eb12d4
CS
41 * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
42 * @author Marc Alier
43 * @author Jordi Piguillem
44 * @author Nikolas Galanis
8f45215d 45 * @author Chris Scribner
d8f9109a 46 * @copyright 2015 Vital Source Technologies http://vitalsource.com
47 * @author Stephen Vickers
61eb12d4 48 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
996b0fd9
CS
49 */
50
51defined('MOODLE_INTERNAL') || die;
52
53require_once($CFG->dirroot.'/course/moodleform_mod.php');
54require_once($CFG->dirroot.'/mod/lti/locallib.php');
55
b1e9a121 56class mod_lti_mod_form extends moodleform_mod {
996b0fd9 57
ea04a9f9 58 public function definition() {
d8f9109a 59 global $DB, $PAGE, $OUTPUT, $USER, $COURSE, $sesskey, $section;
996b0fd9 60
976b5bca
CS
61 if ($type = optional_param('type', false, PARAM_ALPHA)) {
62 component_callback("ltisource_$type", 'add_instance_hook');
63 }
d8f9109a 64 $sectionreturn = optional_param('sr', 0, PARAM_INT);
8cf7670e 65
996b0fd9 66 $this->typeid = 0;
e27cb316 67
996b0fd9 68 $mform =& $this->_form;
e3f69b58 69 // Adding the "general" fieldset, where all the common settings are shown.
996b0fd9 70 $mform->addElement('header', 'general', get_string('general', 'form'));
e3f69b58 71 // Adding the standard "name" field.
72 $mform->addElement('text', 'name', get_string('basicltiname', 'lti'), array('size' => '64'));
996b0fd9
CS
73 $mform->setType('name', PARAM_TEXT);
74 $mform->addRule('name', null, 'required', null, 'client');
a74cd331 75 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
e3f69b58 76 // Adding the optional "intro" and "introformat" pair of fields.
6398ff53 77 $this->standard_intro_elements(get_string('basicltiintro', 'lti'));
996b0fd9 78 $mform->setAdvanced('introeditor');
194f2c60 79
e3f69b58 80 // Display the label to the right of the checkbox so it looks better & matches rest of the form.
8b40604a 81 if ($mform->elementExists('showdescription')) {
7046798f
DM
82 $coursedesc = $mform->getElement('showdescription');
83 if (!empty($coursedesc)) {
84 $coursedesc->setText(' ' . $coursedesc->getLabel());
85 $coursedesc->setLabel('&nbsp');
86 }
b07878ec 87 }
194f2c60 88
b07878ec 89 $mform->setAdvanced('showdescription');
996b0fd9 90
b07878ec
CS
91 $mform->addElement('checkbox', 'showtitlelaunch', '&nbsp;', ' ' . get_string('display_name', 'lti'));
92 $mform->setAdvanced('showtitlelaunch');
80fd0072 93 $mform->setDefault('showtitlelaunch', true);
b07878ec 94 $mform->addHelpButton('showtitlelaunch', 'display_name', 'lti');
e27cb316 95
b07878ec
CS
96 $mform->addElement('checkbox', 'showdescriptionlaunch', '&nbsp;', ' ' . get_string('display_description', 'lti'));
97 $mform->setAdvanced('showdescriptionlaunch');
98 $mform->addHelpButton('showdescriptionlaunch', 'display_description', 'lti');
e27cb316 99
e3f69b58 100 // Tool settings.
d8f9109a 101 $attributes = array();
102 if ($update = optional_param('update', false, PARAM_INT)) {
103 $attributes['disabled'] = 'disabled';
104 }
105 $attributes['class'] = 'lti_contentitem';
106 $tooltypes = $mform->addElement('select', 'typeid', get_string('external_tool_type', 'lti'), array(), $attributes);
01e8bfd7
JO
107 $typeid = optional_param('typeid', false, PARAM_INT);
108 $mform->getElement('typeid')->setValue($typeid);
b26dc53c 109 $mform->addHelpButton('typeid', 'external_tool_type', 'lti');
e3f69b58 110 $toolproxy = array();
e27cb316 111
ea04a9f9 112 foreach (lti_get_types_for_add_instance() as $id => $type) {
e3f69b58 113 if (!empty($type->toolproxyid)) {
114 $toolproxy[] = $type->id;
115 $attributes = array( 'globalTool' => 1, 'toolproxy' => 1);
116 $enabledcapabilities = explode("\n", $type->enabledcapability);
117 if (!in_array('Result.autocreate', $enabledcapabilities)) {
118 $attributes['nogrades'] = 1;
119 }
120 if (!in_array('Person.name.full', $enabledcapabilities) && !in_array('Person.name.family', $enabledcapabilities) &&
121 !in_array('Person.name.given', $enabledcapabilities)) {
122 $attributes['noname'] = 1;
123 }
124 if (!in_array('Person.email.primary', $enabledcapabilities)) {
125 $attributes['noemail'] = 1;
126 }
127 } else if ($type->course == $COURSE->id) {
16e8f130 128 $attributes = array( 'editable' => 1, 'courseTool' => 1, 'domain' => $type->tooldomain );
ea04a9f9 129 } else if ($id != 0) {
16e8f130 130 $attributes = array( 'globalTool' => 1, 'domain' => $type->tooldomain);
996b0fd9
CS
131 } else {
132 $attributes = array();
133 }
d8f9109a 134 if (!$update && $id) {
135 $config = lti_get_type_config($id);
136 if (isset($config['contentitem']) && $config['contentitem']) {
137 $contentitemurl = new moodle_url('/mod/lti/contentitem2.php',
138 array('course' => $COURSE->id, 'section' => $section, 'id' => $id, 'sr' => $sectionreturn));
139 $attributes['contentitem'] = 1;
140 $attributes['contentitemurl'] = $contentitemurl->out(false);
141 }
142 }
e27cb316 143
996b0fd9
CS
144 $tooltypes->addOption($type->name, $id, $attributes);
145 }
e27cb316 146
e3f69b58 147 $mform->addElement('text', 'toolurl', get_string('launch_url', 'lti'), array('size' => '64'));
af9d3a92 148 $mform->setType('toolurl', PARAM_URL);
b26dc53c 149 $mform->addHelpButton('toolurl', 'launch_url', 'lti');
e3f69b58 150 $mform->disabledIf('toolurl', 'typeid', 'neq', '0');
e27cb316 151
e3f69b58 152 $mform->addElement('text', 'securetoolurl', get_string('secure_launch_url', 'lti'), array('size' => '64'));
af9d3a92 153 $mform->setType('securetoolurl', PARAM_URL);
d8d04121
CS
154 $mform->setAdvanced('securetoolurl');
155 $mform->addHelpButton('securetoolurl', 'secure_launch_url', 'lti');
e3f69b58 156 $mform->disabledIf('securetoolurl', 'typeid', 'neq', '0');
e27cb316 157
ea5d0515
AF
158 $mform->addElement('hidden', 'urlmatchedtypeid', '', array( 'id' => 'id_urlmatchedtypeid' ));
159 $mform->setType('urlmatchedtypeid', PARAM_INT);
160
e3f69b58 161 $launchoptions = array();
996b0fd9
CS
162 $launchoptions[LTI_LAUNCH_CONTAINER_DEFAULT] = get_string('default', 'lti');
163 $launchoptions[LTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'lti');
164 $launchoptions[LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'lti');
8fa50fdd 165 $launchoptions[LTI_LAUNCH_CONTAINER_REPLACE_MOODLE_WINDOW] = get_string('existing_window', 'lti');
996b0fd9
CS
166 $launchoptions[LTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'lti');
167
168 $mform->addElement('select', 'launchcontainer', get_string('launchinpopup', 'lti'), $launchoptions);
169 $mform->setDefault('launchcontainer', LTI_LAUNCH_CONTAINER_DEFAULT);
b26dc53c 170 $mform->addHelpButton('launchcontainer', 'launchinpopup', 'lti');
01e8bfd7 171 $mform->setAdvanced('launchcontainer');
e27cb316 172
996b0fd9
CS
173 $mform->addElement('text', 'resourcekey', get_string('resourcekey', 'lti'));
174 $mform->setType('resourcekey', PARAM_TEXT);
175 $mform->setAdvanced('resourcekey');
b26dc53c 176 $mform->addHelpButton('resourcekey', 'resourcekey', 'lti');
e3f69b58 177 $mform->disabledIf('resourcekey', 'typeid', 'neq', '0');
e27cb316 178
996b0fd9
CS
179 $mform->addElement('passwordunmask', 'password', get_string('password', 'lti'));
180 $mform->setType('password', PARAM_TEXT);
181 $mform->setAdvanced('password');
b26dc53c 182 $mform->addHelpButton('password', 'password', 'lti');
e3f69b58 183 $mform->disabledIf('password', 'typeid', 'neq', '0');
e27cb316 184
e3f69b58 185 $mform->addElement('textarea', 'instructorcustomparameters', get_string('custom', 'lti'), array('rows' => 4, 'cols' => 60));
996b0fd9
CS
186 $mform->setType('instructorcustomparameters', PARAM_TEXT);
187 $mform->setAdvanced('instructorcustomparameters');
b26dc53c 188 $mform->addHelpButton('instructorcustomparameters', 'custom', 'lti');
e27cb316 189
e3f69b58 190 $mform->addElement('text', 'icon', get_string('icon_url', 'lti'), array('size' => '64'));
3f358828 191 $mform->setType('icon', PARAM_URL);
6d462df8 192 $mform->setAdvanced('icon');
d8d04121 193 $mform->addHelpButton('icon', 'icon_url', 'lti');
e3f69b58 194 $mform->disabledIf('icon', 'typeid', 'neq', '0');
e27cb316 195
e3f69b58 196 $mform->addElement('text', 'secureicon', get_string('secure_icon_url', 'lti'), array('size' => '64'));
3f358828 197 $mform->setType('secureicon', PARAM_URL);
d8d04121
CS
198 $mform->setAdvanced('secureicon');
199 $mform->addHelpButton('secureicon', 'secure_icon_url', 'lti');
e3f69b58 200 $mform->disabledIf('secureicon', 'typeid', 'neq', '0');
e27cb316 201
e3f69b58 202 // Add privacy preferences fieldset where users choose whether to send their data.
996b0fd9
CS
203 $mform->addElement('header', 'privacy', get_string('privacy', 'lti'));
204
aa74cccb 205 $mform->addElement('advcheckbox', 'instructorchoicesendname', '&nbsp;', ' ' . get_string('share_name', 'lti'));
996b0fd9 206 $mform->setDefault('instructorchoicesendname', '1');
b26dc53c 207 $mform->addHelpButton('instructorchoicesendname', 'share_name', 'lti');
e3f69b58 208 $mform->disabledIf('instructorchoicesendname', 'typeid', 'in', $toolproxy);
e27cb316 209
aa74cccb 210 $mform->addElement('advcheckbox', 'instructorchoicesendemailaddr', '&nbsp;', ' ' . get_string('share_email', 'lti'));
996b0fd9 211 $mform->setDefault('instructorchoicesendemailaddr', '1');
b26dc53c 212 $mform->addHelpButton('instructorchoicesendemailaddr', 'share_email', 'lti');
e3f69b58 213 $mform->disabledIf('instructorchoicesendemailaddr', 'typeid', 'in', $toolproxy);
e27cb316 214
aa74cccb 215 $mform->addElement('advcheckbox', 'instructorchoiceacceptgrades', '&nbsp;', ' ' . get_string('accept_grades', 'lti'));
996b0fd9 216 $mform->setDefault('instructorchoiceacceptgrades', '1');
b26dc53c 217 $mform->addHelpButton('instructorchoiceacceptgrades', 'accept_grades', 'lti');
e3f69b58 218 $mform->disabledIf('instructorchoiceacceptgrades', 'typeid', 'in', $toolproxy);
996b0fd9 219
8fa50fdd
MN
220 // Add standard course module grading elements.
221 $this->standard_grading_coursemodule_elements();
222
e3f69b58 223 // Add standard elements, common to all modules.
996b0fd9 224 $this->standard_coursemodule_elements();
996b0fd9 225 $mform->setAdvanced('cmidnumber');
e3f69b58 226
227 // Add standard buttons, common to all modules.
996b0fd9
CS
228 $this->add_action_buttons();
229
7302fbf6
TH
230 $editurl = new moodle_url('/mod/lti/instructor_edit_tool_type.php',
231 array('sesskey' => sesskey(), 'course' => $COURSE->id));
6831c7cd 232 $ajaxurl = new moodle_url('/mod/lti/ajax.php');
e27cb316 233
996b0fd9
CS
234 $jsinfo = (object)array(
235 'edit_icon_url' => (string)$OUTPUT->pix_url('t/edit'),
236 'add_icon_url' => (string)$OUTPUT->pix_url('t/add'),
237 'delete_icon_url' => (string)$OUTPUT->pix_url('t/delete'),
c3847443 238 'green_check_icon_url' => (string)$OUTPUT->pix_url('i/valid'),
16e8f130 239 'warning_icon_url' => (string)$OUTPUT->pix_url('warning', 'lti'),
6831c7cd
CS
240 'instructor_tool_type_edit_url' => $editurl->out(false),
241 'ajax_url' => $ajaxurl->out(true),
242 'courseId' => $COURSE->id
996b0fd9 243 );
e27cb316 244
996b0fd9 245 $module = array(
e3f69b58 246 'name' => 'mod_lti_edit',
247 'fullpath' => '/mod/lti/mod_form.js',
248 'requires' => array('base', 'io', 'querystring-stringify-simple', 'node', 'event', 'json-parse'),
249 'strings' => array(
6831c7cd
CS
250 array('addtype', 'lti'),
251 array('edittype', 'lti'),
252 array('deletetype', 'lti'),
253 array('delete_confirmation', 'lti'),
254 array('cannot_edit', 'lti'),
255 array('cannot_delete', 'lti'),
256 array('global_tool_types', 'lti'),
16e8f130
CS
257 array('course_tool_types', 'lti'),
258 array('using_tool_configuration', 'lti'),
af9d3a92 259 array('using_tool_cartridge', 'lti'),
16e8f130
CS
260 array('domain_mismatch', 'lti'),
261 array('custom_config', 'lti'),
4c598b13 262 array('tool_config_not_found', 'lti'),
af9d3a92
JO
263 array('tooltypeadded', 'lti'),
264 array('tooltypedeleted', 'lti'),
265 array('tooltypenotdeleted', 'lti'),
266 array('tooltypeupdated', 'lti'),
d8f9109a 267 array('forced_help', 'lti'),
268 array('configure_item', 'lti')
6831c7cd 269 ),
996b0fd9 270 );
e27cb316 271
01e8bfd7
JO
272 if (!empty($typeid)) {
273 $mform->setAdvanced('typeid');
274 $mform->setAdvanced('toolurl');
275 }
276
996b0fd9
CS
277 $PAGE->requires->js_init_call('M.mod_lti.editor.init', array(json_encode($jsinfo)), true, $module);
278 }
279
996b0fd9
CS
280}
281