Merge branch 'MDL-42775-master' of git://github.com/danpoltawski/moodle
[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
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 *
61eb12d4
CS
38 * @package mod
39 * @subpackage lti
40 * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
996b0fd9 41 * marc.alier@upc.edu
61eb12d4
CS
42 * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
43 * @author Marc Alier
44 * @author Jordi Piguillem
45 * @author Nikolas Galanis
8f45215d 46 * @author Chris Scribner
61eb12d4 47 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
996b0fd9
CS
48 */
49
50defined('MOODLE_INTERNAL') || die;
51
52require_once($CFG->dirroot.'/course/moodleform_mod.php');
53require_once($CFG->dirroot.'/mod/lti/locallib.php');
54
b1e9a121 55class mod_lti_mod_form extends moodleform_mod {
996b0fd9 56
ea04a9f9 57 public function definition() {
996b0fd9
CS
58 global $DB, $PAGE, $OUTPUT, $USER, $COURSE;
59
60 $this->typeid = 0;
e27cb316 61
996b0fd9 62 $mform =& $this->_form;
ea04a9f9
EL
63 //-------------------------------------------------------------------------------
64 // Adding the "general" fieldset, where all the common settings are shown
996b0fd9 65 $mform->addElement('header', 'general', get_string('general', 'form'));
ea04a9f9 66 // Adding the standard "name" field
996b0fd9
CS
67 $mform->addElement('text', 'name', get_string('basicltiname', 'lti'), array('size'=>'64'));
68 $mform->setType('name', PARAM_TEXT);
69 $mform->addRule('name', null, 'required', null, 'client');
a74cd331 70 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
ea04a9f9 71 // Adding the optional "intro" and "introformat" pair of fields
996b0fd9
CS
72 $this->add_intro_editor(false, get_string('basicltiintro', 'lti'));
73 $mform->setAdvanced('introeditor');
194f2c60
EL
74
75 // Display the label to the right of the checkbox so it looks better & matches rest of the form
b07878ec
CS
76 $coursedesc = $mform->getElement('showdescription');
77 if(!empty($coursedesc)){
78 $coursedesc->setText(' ' . $coursedesc->getLabel());
79 $coursedesc->setLabel('&nbsp');
80 }
194f2c60 81
b07878ec 82 $mform->setAdvanced('showdescription');
996b0fd9 83
b07878ec
CS
84 $mform->addElement('checkbox', 'showtitlelaunch', '&nbsp;', ' ' . get_string('display_name', 'lti'));
85 $mform->setAdvanced('showtitlelaunch');
86 $mform->addHelpButton('showtitlelaunch', 'display_name', 'lti');
e27cb316 87
b07878ec
CS
88 $mform->addElement('checkbox', 'showdescriptionlaunch', '&nbsp;', ' ' . get_string('display_description', 'lti'));
89 $mform->setAdvanced('showdescriptionlaunch');
90 $mform->addHelpButton('showdescriptionlaunch', 'display_description', 'lti');
e27cb316 91
ea04a9f9 92 // Tool settings
996b0fd9 93 $tooltypes = $mform->addElement('select', 'typeid', get_string('external_tool_type', 'lti'), array());
b26dc53c 94 $mform->addHelpButton('typeid', 'external_tool_type', 'lti');
e27cb316 95
ea04a9f9
EL
96 foreach (lti_get_types_for_add_instance() as $id => $type) {
97 if ($type->course == $COURSE->id) {
16e8f130 98 $attributes = array( 'editable' => 1, 'courseTool' => 1, 'domain' => $type->tooldomain );
ea04a9f9 99 } else if ($id != 0) {
16e8f130 100 $attributes = array( 'globalTool' => 1, 'domain' => $type->tooldomain);
996b0fd9
CS
101 } else {
102 $attributes = array();
103 }
e27cb316 104
996b0fd9
CS
105 $tooltypes->addOption($type->name, $id, $attributes);
106 }
e27cb316 107
996b0fd9
CS
108 $mform->addElement('text', 'toolurl', get_string('launch_url', 'lti'), array('size'=>'64'));
109 $mform->setType('toolurl', PARAM_TEXT);
b26dc53c 110 $mform->addHelpButton('toolurl', 'launch_url', 'lti');
e27cb316 111
d8d04121
CS
112 $mform->addElement('text', 'securetoolurl', get_string('secure_launch_url', 'lti'), array('size'=>'64'));
113 $mform->setType('securetoolurl', PARAM_TEXT);
114 $mform->setAdvanced('securetoolurl');
115 $mform->addHelpButton('securetoolurl', 'secure_launch_url', 'lti');
e27cb316 116
996b0fd9
CS
117 $launchoptions=array();
118 $launchoptions[LTI_LAUNCH_CONTAINER_DEFAULT] = get_string('default', 'lti');
119 $launchoptions[LTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'lti');
120 $launchoptions[LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'lti');
121 $launchoptions[LTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'lti');
122
123 $mform->addElement('select', 'launchcontainer', get_string('launchinpopup', 'lti'), $launchoptions);
124 $mform->setDefault('launchcontainer', LTI_LAUNCH_CONTAINER_DEFAULT);
b26dc53c 125 $mform->addHelpButton('launchcontainer', 'launchinpopup', 'lti');
e27cb316 126
996b0fd9
CS
127 $mform->addElement('text', 'resourcekey', get_string('resourcekey', 'lti'));
128 $mform->setType('resourcekey', PARAM_TEXT);
129 $mform->setAdvanced('resourcekey');
b26dc53c 130 $mform->addHelpButton('resourcekey', 'resourcekey', 'lti');
e27cb316 131
996b0fd9
CS
132 $mform->addElement('passwordunmask', 'password', get_string('password', 'lti'));
133 $mform->setType('password', PARAM_TEXT);
134 $mform->setAdvanced('password');
b26dc53c 135 $mform->addHelpButton('password', 'password', 'lti');
e27cb316 136
996b0fd9
CS
137 $mform->addElement('textarea', 'instructorcustomparameters', get_string('custom', 'lti'), array('rows'=>4, 'cols'=>60));
138 $mform->setType('instructorcustomparameters', PARAM_TEXT);
139 $mform->setAdvanced('instructorcustomparameters');
b26dc53c 140 $mform->addHelpButton('instructorcustomparameters', 'custom', 'lti');
e27cb316 141
6d462df8
CS
142 $mform->addElement('text', 'icon', get_string('icon_url', 'lti'), array('size'=>'64'));
143 $mform->setType('icon', PARAM_TEXT);
144 $mform->setAdvanced('icon');
d8d04121 145 $mform->addHelpButton('icon', 'icon_url', 'lti');
e27cb316 146
d8d04121
CS
147 $mform->addElement('text', 'secureicon', get_string('secure_icon_url', 'lti'), array('size'=>'64'));
148 $mform->setType('secureicon', PARAM_TEXT);
149 $mform->setAdvanced('secureicon');
150 $mform->addHelpButton('secureicon', 'secure_icon_url', 'lti');
e27cb316 151
ea04a9f9 152 //-------------------------------------------------------------------------------
996b0fd9
CS
153 // Add privacy preferences fieldset where users choose whether to send their data
154 $mform->addElement('header', 'privacy', get_string('privacy', 'lti'));
155
aa74cccb 156 $mform->addElement('advcheckbox', 'instructorchoicesendname', '&nbsp;', ' ' . get_string('share_name', 'lti'));
996b0fd9 157 $mform->setDefault('instructorchoicesendname', '1');
b26dc53c 158 $mform->addHelpButton('instructorchoicesendname', 'share_name', 'lti');
e27cb316 159
aa74cccb 160 $mform->addElement('advcheckbox', 'instructorchoicesendemailaddr', '&nbsp;', ' ' . get_string('share_email', 'lti'));
996b0fd9 161 $mform->setDefault('instructorchoicesendemailaddr', '1');
b26dc53c 162 $mform->addHelpButton('instructorchoicesendemailaddr', 'share_email', 'lti');
e27cb316 163
aa74cccb 164 $mform->addElement('advcheckbox', 'instructorchoiceacceptgrades', '&nbsp;', ' ' . get_string('accept_grades', 'lti'));
996b0fd9 165 $mform->setDefault('instructorchoiceacceptgrades', '1');
b26dc53c 166 $mform->addHelpButton('instructorchoiceacceptgrades', 'accept_grades', 'lti');
e27cb316 167
59fc5c54
CS
168 //$mform->addElement('checkbox', 'instructorchoiceallowroster', '&nbsp;', ' ' . get_string('share_roster', 'lti'));
169 //$mform->setDefault('instructorchoiceallowroster', '1');
170 //$mform->addHelpButton('instructorchoiceallowroster', 'share_roster', 'lti');
e27cb316 171
ea04a9f9 172 //-------------------------------------------------------------------------------
996b0fd9 173
ea04a9f9
EL
174 /**
175 $debugoptions=array();
996b0fd9
CS
176 $debugoptions[0] = get_string('debuglaunchoff', 'lti');
177 $debugoptions[1] = get_string('debuglaunchon', 'lti');
178
179 $mform->addElement('select', 'debuglaunch', get_string('debuglaunch', 'lti'), $debugoptions);
180
181 if (isset($this->typeconfig['debuglaunch'])) {
182 if ($this->typeconfig['debuglaunch'] == 0) {
183 $mform->setDefault('debuglaunch', '0');
184 } else if ($this->typeconfig['debuglaunch'] == 1) {
185 $mform->setDefault('debuglaunch', '1');
186 }
187 }
ea04a9f9 188 */
996b0fd9 189
ea04a9f9 190 //-------------------------------------------------------------------------------
996b0fd9
CS
191 // add standard elements, common to all modules
192 $this->standard_coursemodule_elements();
996b0fd9 193 $mform->setAdvanced('cmidnumber');
ea04a9f9 194 //-------------------------------------------------------------------------------
996b0fd9
CS
195 // add standard buttons, common to all modules
196 $this->add_action_buttons();
197
7302fbf6
TH
198 $editurl = new moodle_url('/mod/lti/instructor_edit_tool_type.php',
199 array('sesskey' => sesskey(), 'course' => $COURSE->id));
6831c7cd 200 $ajaxurl = new moodle_url('/mod/lti/ajax.php');
e27cb316 201
996b0fd9
CS
202 $jsinfo = (object)array(
203 'edit_icon_url' => (string)$OUTPUT->pix_url('t/edit'),
204 'add_icon_url' => (string)$OUTPUT->pix_url('t/add'),
205 'delete_icon_url' => (string)$OUTPUT->pix_url('t/delete'),
c3847443 206 'green_check_icon_url' => (string)$OUTPUT->pix_url('i/valid'),
16e8f130 207 'warning_icon_url' => (string)$OUTPUT->pix_url('warning', 'lti'),
6831c7cd
CS
208 'instructor_tool_type_edit_url' => $editurl->out(false),
209 'ajax_url' => $ajaxurl->out(true),
210 'courseId' => $COURSE->id
996b0fd9 211 );
e27cb316 212
996b0fd9
CS
213 $module = array(
214 'name' => 'mod_lti_edit',
215 'fullpath' => '/mod/lti/mod_form.js',
6831c7cd
CS
216 'requires' => array('base', 'io', 'querystring-stringify-simple', 'node', 'event', 'json-parse'),
217 'strings' => array(
218 array('addtype', 'lti'),
219 array('edittype', 'lti'),
220 array('deletetype', 'lti'),
221 array('delete_confirmation', 'lti'),
222 array('cannot_edit', 'lti'),
223 array('cannot_delete', 'lti'),
224 array('global_tool_types', 'lti'),
16e8f130
CS
225 array('course_tool_types', 'lti'),
226 array('using_tool_configuration', 'lti'),
227 array('domain_mismatch', 'lti'),
228 array('custom_config', 'lti'),
4c598b13
CS
229 array('tool_config_not_found', 'lti'),
230 array('forced_help', 'lti')
6831c7cd 231 ),
996b0fd9 232 );
e27cb316 233
996b0fd9
CS
234 $PAGE->requires->js_init_call('M.mod_lti.editor.init', array(json_encode($jsinfo)), true, $module);
235 }
236
237 /**
238 * Make fields editable or non-editable depending on the administrator choices
239 * @see moodleform_mod::definition_after_data()
240 */
ea04a9f9 241 public function definition_after_data() {
996b0fd9 242 parent::definition_after_data();
e27cb316 243
d8d04121 244 //$mform =& $this->_form;
996b0fd9
CS
245 }
246
247 /**
248 * Function overwritten to change default values using
249 * global configuration
250 *
251 * @param array $default_values passed by reference
252 */
b1e9a121 253 public function data_preprocessing(&$default_values) {
996b0fd9
CS
254
255 }
256}
257