MDL-10234
[moodle-linuxchix.git] / mod / lesson / mod_form.php
blob6cda0a961c04c33fecebb6ee1436d066e795f990
1 <?php // $Id$
2 /**
3 * Form to define a new instance of lesson or edit an instance.
4 * It is used from /course/modedit.php.
6 * @version $Id$
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package lesson
9 **/
11 require_once($CFG->dirroot.'/course/moodleform_mod.php');
12 require_once('locallib.php');
14 class mod_lesson_mod_form extends moodleform_mod {
16 function definition() {
17 global $LESSON_NEXTPAGE_ACTION, $COURSE;
19 $mform =& $this->_form;
21 //-------------------------------------------------------------------------------
22 $mform->addElement('header', 'general', get_string('general', 'form'));
24 $mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
25 $mform->setType('name', PARAM_TEXT);
26 $mform->addRule('name', null, 'required', null, 'client');
28 $mform->addElement('selectyesno', 'timed', get_string('timed', 'lesson'));
29 $mform->setDefault('timed', 0);
30 $mform->setHelpButton('timed', array('timed', get_string('timed', 'lesson'), 'lesson'));
32 $mform->addElement('text', 'maxtime', get_string('maxtime', 'lesson'));
33 $mform->setDefault('maxtime', 20);
34 $mform->addRule('maxtime', null, 'required', null, 'client');
35 $mform->addRule('maxtime', null, 'numeric', null, 'client');
36 $mform->setType('maxtime', PARAM_INT);
38 $numbers = array();
39 for ($i=20; $i>1; $i--) {
40 $numbers[$i] = $i;
42 $mform->addElement('select', 'maxanswers', get_string('maximumnumberofanswersbranches', 'lesson'), $numbers);
43 $mform->setDefault('maxanswers', 4);
44 $mform->setHelpButton('maxanswers', array('maxanswers', get_string('displayformat', 'lesson'), 'lesson'));
46 //-------------------------------------------------------------------------------
47 $mform->addElement('header', '', get_string('gradeoptions', 'lesson'));
49 $mform->addElement('selectyesno', 'practice', get_string('practice', 'lesson'));
50 $mform->setHelpButton('practice', array('practice', get_string('practice', 'lesson'), 'lesson'));
51 $mform->setDefault('practice', 0);
53 $mform->addElement('selectyesno', 'custom', get_string('customscoring', 'lesson'));
54 $mform->setHelpButton('custom', array('custom', get_string('customscoring', 'lesson'), 'lesson'));
55 $mform->setDefault('custom', 1);
57 $grades = array();
58 for ($i=100; $i>=0; $i--) {
59 $grades[$i] = $i;
61 $mform->addElement('select', 'grade', get_string('maximumgrade'), $grades);
62 $mform->setDefault('grade', 0);
63 $mform->setHelpButton('grade', array('grade', get_string('maximumgrade', 'lesson'), 'lesson'));
65 $mform->addElement('selectyesno', 'retake', get_string('canretake', 'lesson', $COURSE->student));
66 $mform->setHelpButton('retake', array('retake', get_string('canretake', 'lesson', $COURSE->student), 'lesson'));
67 $mform->setDefault('retake', 0);
69 $options = array();
70 $options[0] = get_string('usemean', 'lesson');
71 $options[1] = get_string('usemaximum', 'lesson');
72 $mform->addElement('select', 'usemaxgrade', get_string('handlingofretakes', 'lesson'), $options);
73 $mform->setHelpButton('usemaxgrade', array('handlingofretakes', get_string('handlingofretakes', 'lesson'), 'lesson'));
74 $mform->setDefault('usemaxgrade', 0);
76 $mform->addElement('selectyesno', 'ongoing', get_string('ongoing', 'lesson'));
77 $mform->setHelpButton('ongoing', array('ongoing', get_string('ongoing', 'lesson'), 'lesson'));
78 $mform->setDefault('ongoing', 0);
80 //-------------------------------------------------------------------------------
81 $mform->addElement('header', '', get_string('flowcontrol', 'lesson'));
83 $mform->addElement('selectyesno', 'modattempts', get_string('modattempts', 'lesson'));
84 $mform->setHelpButton('modattempts', array('modattempts', get_string('modattempts', 'lesson'), 'lesson'));
85 $mform->setDefault('modattempts', 0);
87 $mform->addElement('selectyesno', 'review', get_string('displayreview', 'lesson'));
88 $mform->setHelpButton('review', array('review', get_string('displayreview', 'lesson'), 'lesson'));
89 $mform->setDefault('review', 0);
91 $numbers = array();
92 for ($i=10; $i>0; $i--) {
93 $numbers[$i] = $i;
95 $mform->addElement('select', 'maxattempts', get_string('maximumnumberofattempts', 'lesson'), $numbers);
96 $mform->setHelpButton('maxattempts', array('maxattempts', get_string('maximumnumberofattempts', 'lesson'), 'lesson'));
97 $mform->setDefault('maxattempts', 1);
99 $mform->addElement('select', 'nextpagedefault', get_string('actionaftercorrectanswer', 'lesson'), $LESSON_NEXTPAGE_ACTION);
100 $mform->setHelpButton('nextpagedefault', array('nextpageaction', get_string('actionaftercorrectanswer', 'lesson'), 'lesson'));
101 $mform->setDefault('nextpagedefault', 0);
103 $mform->addElement('selectyesno', 'feedback', get_string('displaydefaultfeedback', 'lesson'));
104 $mform->setHelpButton('feedback', array('feedback', get_string('displaydefaultfeedback', 'lesson'), 'lesson'));
105 $mform->setDefault('feedback', 0);
107 $numbers = array();
108 for ($i = 100; $i >= 0; $i--) {
109 $numbers[$i] = $i;
111 $mform->addElement('select', 'minquestions', get_string('minimumnumberofquestions', 'lesson'), $numbers);
112 $mform->setHelpButton('minquestions', array('minquestions', get_string('minimumnumberofquestions', 'lesson'), 'lesson'));
113 $mform->setDefault('minquestions', 0);
115 $numbers = array();
116 for ($i = 100; $i >= 0; $i--) {
117 $numbers[$i] = $i;
119 $mform->addElement('select', 'maxpages', get_string('numberofpagestoshow', 'lesson'), $numbers);
120 $mform->setHelpButton('maxpages', array('maxpages', get_string('numberofpagestoshow', 'lesson'), 'lesson'));
121 $mform->setDefault('maxpages', 0);
123 //-------------------------------------------------------------------------------
124 $mform->addElement('header', '', get_string('lessonformating', 'lesson'));
126 $mform->addElement('selectyesno', 'slideshow', get_string('slideshow', 'lesson'));
127 $mform->setHelpButton('slideshow', array('slideshow', get_string('slideshow', 'lesson'), 'lesson'));
128 $mform->setDefault('slideshow', 0);
130 $mform->addElement('text', 'width', get_string('slideshowwidth', 'lesson'));
131 $mform->setDefault('width', 640);
132 $mform->addRule('width', null, 'required', null, 'client');
133 $mform->addRule('width', null, 'numeric', null, 'client');
134 $mform->setHelpButton('width', array('width', get_string('slideshowwidth', 'lesson'), 'lesson'));
135 $mform->setType('width', PARAM_INT);
137 $mform->addElement('text', 'height', get_string('slideshowheight', 'lesson'));
138 $mform->setDefault('height', 480);
139 $mform->addRule('height', null, 'required', null, 'client');
140 $mform->addRule('height', null, 'numeric', null, 'client');
141 $mform->setHelpButton('height', array('height', get_string('slideshowheight', 'lesson'), 'lesson'));
142 $mform->setType('height', PARAM_INT);
144 $mform->addElement('text', 'bgcolor', get_string('slideshowbgcolor', 'lesson'));
145 $mform->setDefault('bgcolor', '#FFFFFF');
146 $mform->addRule('bgcolor', null, 'required', null, 'client');
147 $mform->setHelpButton('bgcolor', array('bgcolor', get_string('slideshowbgcolor', 'lesson'), 'lesson'));
148 $mform->setType('bgcolor', PARAM_TEXT);
150 $mform->addElement('selectyesno', 'displayleft', get_string('displayleftmenu', 'lesson'));
151 $mform->setHelpButton('displayleft', array('displayleft', get_string('displayleftmenu', 'lesson'), 'lesson'));
152 $mform->setDefault('displayleft', 0);
154 $options = array();
155 for($i = 100; $i >= 0; $i--) {
156 $options[$i] = $i.'%';
158 $mform->addElement('select', 'displayleftif', get_string('displayleftif', 'lesson'), $options);
159 $mform->setDefault('displayleftif', 0);
161 $mform->addElement('selectyesno', 'progressbar', get_string('progressbar', 'lesson'));
162 $mform->setHelpButton('progressbar', array('progressbar', get_string('progressbar', 'lesson'), 'lesson'));
163 $mform->setDefault('progressbar', 0);
166 //-------------------------------------------------------------------------------
167 $mform->addElement('header', '', get_string('accesscontrol', 'lesson'));
169 $mform->addElement('selectyesno', 'usepassword', get_string('usepassword', 'lesson'));
170 $mform->setHelpButton('usepassword', array('usepassword', get_string('usepassword', 'lesson'), 'lesson'));
171 $mform->setDefault('usepassword', 0);
173 $mform->addElement('text', 'password', get_string('password', 'lesson'));
174 $mform->setHelpButton('password', array('password', get_string('password', 'lesson'), 'lesson'));
175 $mform->setDefault('password', '');
176 //never displayed converted to md5
177 $mform->setType('password', PARAM_RAW);
179 $mform->addElement('date_time_selector', 'available', get_string('available', 'lesson'));
180 $mform->setDefault('available', 0);
182 $mform->addElement('date_time_selector', 'deadline', get_string('deadline', 'lesson'));
183 $mform->setDefault('deadline', 0);
185 //-------------------------------------------------------------------------------
186 $mform->addElement('header', '', get_string('dependencyon', 'lesson'));
188 $options = array(0=>get_string('none'));
189 if ($lessons = get_all_instances_in_course('lesson', $COURSE)) {
190 foreach($lessons as $lesson) {
191 if ($lesson->id != $this->_instance){
192 $options[$lesson->id] = format_string($lesson->name, true);
197 $mform->addElement('select', 'dependency', get_string('dependencyon', 'lesson'), $options);
198 $mform->setHelpButton('dependency', array('dependency', get_string('dependency', 'lesson'), 'lesson'));
199 $mform->setDefault('dependency', 0);
201 $mform->addElement('text', 'timespent', get_string('timespentminutes', 'lesson'));
202 $mform->setDefault('timespent', 0);
203 $mform->setType('timespent', PARAM_INT);
205 $mform->addElement('checkbox', 'completed', get_string('completed', 'lesson'));
206 $mform->setDefault('completed', 0);
208 $mform->addElement('text', 'gradebetterthan', get_string('gradebetterthan', 'lesson'));
209 $mform->setDefault('gradebetterthan', 0);
210 $mform->setType('gradebetterthan', PARAM_INT);
212 //-------------------------------------------------------------------------------
213 $mform->addElement('header', '', get_string('mediafile', 'lesson'));
215 $mform->addElement('choosecoursefile', 'mediafile', get_string('mediafile', 'lesson'), array('courseid'=>$COURSE->id));
216 $mform->setHelpButton('mediafile', array('mediafile', get_string('mediafile', 'lesson'), 'lesson'));
217 $mform->setDefault('mediafile', '');
218 $mform->setType('mediafile', PARAM_RAW);
220 $mform->addElement('selectyesno', 'mediaclose', get_string('mediaclose', 'lesson'));
221 $mform->setDefault('mediaclose', 0);
223 $mform->addElement('text', 'mediaheight', get_string('mediaheight', 'lesson'));
224 $mform->setHelpButton('mediaheight', array('mediaheight', get_string('mediaheight', 'lesson'), 'lesson'));
225 $mform->setDefault('mediaheight', 100);
226 $mform->addRule('mediaheight', null, 'required', null, 'client');
227 $mform->addRule('mediaheight', null, 'numeric', null, 'client');
228 $mform->setType('mediaheight', PARAM_INT);
230 $mform->addElement('text', 'mediawidth', get_string('mediawidth', 'lesson'));
231 $mform->setHelpButton('mediawidth', array('mediawidth', get_string('mediawidth', 'lesson'), 'lesson'));
232 $mform->setDefault('mediawidth', 650);
233 $mform->addRule('mediawidth', null, 'required', null, 'client');
234 $mform->addRule('mediawidth', null, 'numeric', null, 'client');
235 $mform->setType('mediawidth', PARAM_INT);
237 //-------------------------------------------------------------------------------
238 $mform->addElement('header', '', get_string('other', 'lesson'));
240 // get the modules
241 if ($mods = get_course_mods($COURSE->id)) {
242 $modinstances = array();
243 foreach ($mods as $mod) {
245 // get the module name and then store it in a new array
246 if ($module = get_coursemodule_from_instance($mod->modname, $mod->instance, $COURSE->id)) {
247 if (isset($this->_cm->id) and $this->_cm->id != $mod->id){
248 $modinstances[$mod->id] = $mod->modname.' - '.$module->name;
252 asort($modinstances); // sort by module name
253 $modinstances=array(0=>get_string('none'))+$modinstances;
255 $mform->addElement('select', 'activitylink', get_string('activitylink', 'lesson'), $modinstances);
256 $mform->setHelpButton('activitylink', array('activitylink', get_string('activitylink', 'lesson'), 'lesson'));
257 $mform->setDefault('activitylink', 0);
261 $mform->addElement('text', 'maxhighscores', get_string('maxhighscores', 'lesson'));
262 $mform->setHelpButton('maxhighscores', array('maxhighscores', get_string('maxhighscores', 'lesson'), 'lesson'));
263 $mform->setDefault('maxhighscores', 10);
264 $mform->addRule('maxhighscores', null, 'required', null, 'client');
265 $mform->addRule('maxhighscores', null, 'numeric', null, 'client');
266 $mform->setType('maxhighscores', PARAM_INT);
268 $mform->addElement('selectyesno', 'lessondefault', get_string('lessondefault', 'lesson'));
269 $mform->setHelpButton('lessondefault', array('lessondefault', get_string('lessondefault', 'lesson'), 'lesson'));
270 $mform->setDefault('lessondefault', 0);
272 //-------------------------------------------------------------------------------
273 $this->standard_coursemodule_elements(false);
274 //-------------------------------------------------------------------------------
275 // buttons
276 $this->add_action_buttons();
280 * Enforce defaults here
282 * @param array $default_values Form defaults
283 * @return void
285 function data_preprocessing(&$default_values) {
286 if (isset($default_values['conditions'])) {
287 $conditions = unserialize($default_values['conditions']);
288 $default_values['timespent'] = $conditions->timespent;
289 $default_values['completed'] = $conditions->completed;
290 $default_values['gradebetterthan'] = $conditions->gradebetterthan;
292 if (isset($default_values['password'])) {
293 unset($default_values['password']);
295 if (isset($default_values['add']) and $defaults = get_record('lesson_default', 'course', $default_values['course'])) {
296 foreach ($defaults as $fieldname => $default) {
297 switch ($fieldname) {
298 case 'conditions':
299 $conditions = unserialize($default);
300 $default_values['timespent'] = $conditions->timespent;
301 $default_values['completed'] = $conditions->completed;
302 $default_values['gradebetterthan'] = $conditions->gradebetterthan;
303 break;
304 default:
305 $default_values[$fieldname] = $default;
306 break;