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/>.
17 // This file is part of BasicLTI4Moodle
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.
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
36 * This file defines the main lti configuration form
40 * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
42 * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
44 * @author Jordi Piguillem
45 * @author Nikolas Galanis
46 * @author Chris Scribner
47 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
50 defined('MOODLE_INTERNAL') ||
die;
52 require_once($CFG->dirroot
.'/course/moodleform_mod.php');
53 require_once($CFG->dirroot
.'/mod/lti/locallib.php');
55 class mod_lti_mod_form
extends moodleform_mod
{
57 public function definition() {
58 global $DB, $PAGE, $OUTPUT, $USER, $COURSE;
62 $mform =& $this->_form
;
63 //-------------------------------------------------------------------------------
64 // Adding the "general" fieldset, where all the common settings are shown
65 $mform->addElement('header', 'general', get_string('general', 'form'));
66 // Adding the standard "name" field
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');
70 // Adding the optional "intro" and "introformat" pair of fields
71 $this->add_intro_editor(false, get_string('basicltiintro', 'lti'));
72 $mform->setAdvanced('introeditor');
74 // Display the label to the right of the checkbox so it looks better & matches rest of the form
75 $coursedesc = $mform->getElement('showdescription');
76 if(!empty($coursedesc)){
77 $coursedesc->setText(' ' . $coursedesc->getLabel());
78 $coursedesc->setLabel(' ');
81 $mform->setAdvanced('showdescription');
83 $mform->addElement('checkbox', 'showtitlelaunch', ' ', ' ' . get_string('display_name', 'lti'));
84 $mform->setAdvanced('showtitlelaunch');
85 $mform->addHelpButton('showtitlelaunch', 'display_name', 'lti');
87 $mform->addElement('checkbox', 'showdescriptionlaunch', ' ', ' ' . get_string('display_description', 'lti'));
88 $mform->setAdvanced('showdescriptionlaunch');
89 $mform->addHelpButton('showdescriptionlaunch', 'display_description', 'lti');
92 $tooltypes = $mform->addElement('select', 'typeid', get_string('external_tool_type', 'lti'), array());
93 $mform->addHelpButton('typeid', 'external_tool_type', 'lti');
95 foreach (lti_get_types_for_add_instance() as $id => $type) {
96 if ($type->course
== $COURSE->id
) {
97 $attributes = array( 'editable' => 1, 'courseTool' => 1, 'domain' => $type->tooldomain
);
98 } else if ($id != 0) {
99 $attributes = array( 'globalTool' => 1, 'domain' => $type->tooldomain
);
101 $attributes = array();
104 $tooltypes->addOption($type->name
, $id, $attributes);
107 $mform->addElement('text', 'toolurl', get_string('launch_url', 'lti'), array('size'=>'64'));
108 $mform->setType('toolurl', PARAM_TEXT
);
109 $mform->addHelpButton('toolurl', 'launch_url', 'lti');
111 $mform->addElement('text', 'securetoolurl', get_string('secure_launch_url', 'lti'), array('size'=>'64'));
112 $mform->setType('securetoolurl', PARAM_TEXT
);
113 $mform->setAdvanced('securetoolurl');
114 $mform->addHelpButton('securetoolurl', 'secure_launch_url', 'lti');
116 $launchoptions=array();
117 $launchoptions[LTI_LAUNCH_CONTAINER_DEFAULT
] = get_string('default', 'lti');
118 $launchoptions[LTI_LAUNCH_CONTAINER_EMBED
] = get_string('embed', 'lti');
119 $launchoptions[LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS
] = get_string('embed_no_blocks', 'lti');
120 $launchoptions[LTI_LAUNCH_CONTAINER_WINDOW
] = get_string('new_window', 'lti');
122 $mform->addElement('select', 'launchcontainer', get_string('launchinpopup', 'lti'), $launchoptions);
123 $mform->setDefault('launchcontainer', LTI_LAUNCH_CONTAINER_DEFAULT
);
124 $mform->addHelpButton('launchcontainer', 'launchinpopup', 'lti');
126 $mform->addElement('text', 'resourcekey', get_string('resourcekey', 'lti'));
127 $mform->setType('resourcekey', PARAM_TEXT
);
128 $mform->setAdvanced('resourcekey');
129 $mform->addHelpButton('resourcekey', 'resourcekey', 'lti');
131 $mform->addElement('passwordunmask', 'password', get_string('password', 'lti'));
132 $mform->setType('password', PARAM_TEXT
);
133 $mform->setAdvanced('password');
134 $mform->addHelpButton('password', 'password', 'lti');
136 $mform->addElement('textarea', 'instructorcustomparameters', get_string('custom', 'lti'), array('rows'=>4, 'cols'=>60));
137 $mform->setType('instructorcustomparameters', PARAM_TEXT
);
138 $mform->setAdvanced('instructorcustomparameters');
139 $mform->addHelpButton('instructorcustomparameters', 'custom', 'lti');
141 $mform->addElement('text', 'icon', get_string('icon_url', 'lti'), array('size'=>'64'));
142 $mform->setType('icon', PARAM_TEXT
);
143 $mform->setAdvanced('icon');
144 $mform->addHelpButton('icon', 'icon_url', 'lti');
146 $mform->addElement('text', 'secureicon', get_string('secure_icon_url', 'lti'), array('size'=>'64'));
147 $mform->setType('secureicon', PARAM_TEXT
);
148 $mform->setAdvanced('secureicon');
149 $mform->addHelpButton('secureicon', 'secure_icon_url', 'lti');
151 //-------------------------------------------------------------------------------
152 // Add privacy preferences fieldset where users choose whether to send their data
153 $mform->addElement('header', 'privacy', get_string('privacy', 'lti'));
155 $mform->addElement('checkbox', 'instructorchoicesendname', ' ', ' ' . get_string('share_name', 'lti'));
156 $mform->setDefault('instructorchoicesendname', '1');
157 $mform->addHelpButton('instructorchoicesendname', 'share_name', 'lti');
159 $mform->addElement('checkbox', 'instructorchoicesendemailaddr', ' ', ' ' . get_string('share_email', 'lti'));
160 $mform->setDefault('instructorchoicesendemailaddr', '1');
161 $mform->addHelpButton('instructorchoicesendemailaddr', 'share_email', 'lti');
163 $mform->addElement('checkbox', 'instructorchoiceacceptgrades', ' ', ' ' . get_string('accept_grades', 'lti'));
164 $mform->setDefault('instructorchoiceacceptgrades', '1');
165 $mform->addHelpButton('instructorchoiceacceptgrades', 'accept_grades', 'lti');
167 //$mform->addElement('checkbox', 'instructorchoiceallowroster', ' ', ' ' . get_string('share_roster', 'lti'));
168 //$mform->setDefault('instructorchoiceallowroster', '1');
169 //$mform->addHelpButton('instructorchoiceallowroster', 'share_roster', 'lti');
171 //-------------------------------------------------------------------------------
174 $debugoptions=array();
175 $debugoptions[0] = get_string('debuglaunchoff', 'lti');
176 $debugoptions[1] = get_string('debuglaunchon', 'lti');
178 $mform->addElement('select', 'debuglaunch', get_string('debuglaunch', 'lti'), $debugoptions);
180 if (isset($this->typeconfig['debuglaunch'])) {
181 if ($this->typeconfig['debuglaunch'] == 0) {
182 $mform->setDefault('debuglaunch', '0');
183 } else if ($this->typeconfig['debuglaunch'] == 1) {
184 $mform->setDefault('debuglaunch', '1');
189 //-------------------------------------------------------------------------------
190 // add standard elements, common to all modules
191 $this->standard_coursemodule_elements();
192 $mform->setAdvanced('cmidnumber');
193 //-------------------------------------------------------------------------------
194 // add standard buttons, common to all modules
195 $this->add_action_buttons();
197 $editurl = new moodle_url("/mod/lti/instructor_edit_tool_type.php?sesskey={$USER->sesskey}&course={$COURSE->id}");
198 $ajaxurl = new moodle_url('/mod/lti/ajax.php');
200 $jsinfo = (object)array(
201 'edit_icon_url' => (string)$OUTPUT->pix_url('t/edit'),
202 'add_icon_url' => (string)$OUTPUT->pix_url('t/add'),
203 'delete_icon_url' => (string)$OUTPUT->pix_url('t/delete'),
204 'green_check_icon_url' => (string)$OUTPUT->pix_url('i/valid'),
205 'warning_icon_url' => (string)$OUTPUT->pix_url('warning', 'lti'),
206 'instructor_tool_type_edit_url' => $editurl->out(false),
207 'ajax_url' => $ajaxurl->out(true),
208 'courseId' => $COURSE->id
212 'name' => 'mod_lti_edit',
213 'fullpath' => '/mod/lti/mod_form.js',
214 'requires' => array('base', 'io', 'querystring-stringify-simple', 'node', 'event', 'json-parse'),
216 array('addtype', 'lti'),
217 array('edittype', 'lti'),
218 array('deletetype', 'lti'),
219 array('delete_confirmation', 'lti'),
220 array('cannot_edit', 'lti'),
221 array('cannot_delete', 'lti'),
222 array('global_tool_types', 'lti'),
223 array('course_tool_types', 'lti'),
224 array('using_tool_configuration', 'lti'),
225 array('domain_mismatch', 'lti'),
226 array('custom_config', 'lti'),
227 array('tool_config_not_found', 'lti'),
228 array('forced_help', 'lti')
232 $PAGE->requires
->js_init_call('M.mod_lti.editor.init', array(json_encode($jsinfo)), true, $module);
236 * Make fields editable or non-editable depending on the administrator choices
237 * @see moodleform_mod::definition_after_data()
239 public function definition_after_data() {
240 parent
::definition_after_data();
242 //$mform =& $this->_form;
246 * Function overwritten to change default values using
247 * global configuration
249 * @param array $default_values passed by reference
251 public function data_preprocessing(&$default_values) {