2 require_once ('moodleform_mod.php');
3 require_once ($CFG->dirroot
.'/mod/hotpot/lib.php');
5 $HOTPOT_TEXTSOURCE = array(
6 HOTPOT_TEXTSOURCE_QUIZ
=> get_string('textsourcequiz', 'hotpot'),
7 HOTPOT_TEXTSOURCE_FILENAME
=> get_string('textsourcefilename', 'hotpot'),
8 HOTPOT_TEXTSOURCE_FILEPATH
=> get_string('textsourcefilepath', 'hotpot'),
9 HOTPOT_TEXTSOURCE_SPECIFIC
=> get_string('textsourcespecific', 'hotpot')
12 class mod_hotpot_mod_form
extends moodleform_mod
{
13 // documentation on formslib.php here:
14 // http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition
16 function definition() {
19 // $mform->setType('name', PARAM_xxx);
20 // $mform->setDefault('name', array('elementhelpfilename', get_string('helpicontitlestring', 'hotpot'), 'hotpot'));
23 global $HOTPOT_FEEDBACK, $HOTPOT_GRADEMETHOD, $HOTPOT_LOCATION;
24 global $HOTPOT_NAVIGATION, $HOTPOT_OUTPUTFORMAT, $HOTPOT_TEXTSOURCE;
26 $mform =&$this->_form
;
28 // initialize values for $hours, $minutes and $seconds
32 for ($i=0; $i<60; $i++
) {
33 $str = sprintf('%02d', $i);
41 //-----------------------------------------------------------------------------------------------
42 $mform->addElement('header', 'general', get_string('general', 'form'));
43 //-----------------------------------------------------------------------------------------------
47 if (isset($form->add
)) {
50 $elements[] = &$mform->createElement('select', 'namesource', '', $HOTPOT_TEXTSOURCE);
51 $elements[] = &$mform->createElement('text', 'name', '', array('size' => '40'));
52 $mform->addGroup($elements, 'name_elements', get_string('name'), array(' '), false);
53 $mform->disabledIf('name_elements', 'namesource', 'ne', HOTPOT_TEXTSOURCE_SPECIFIC
);
54 // $mform->setAdvanced('name_elements');
57 $mform->addElement('hidden', 'namesource', HOTPOT_TEXTSOURCE_SPECIFIC
);
58 $mform->addElement('text', 'name', get_string('name'), array('size' => '40'));
60 $mform->setType('namesource', PARAM_INT
);
61 $mform->setType('name', PARAM_TEXT
);
64 $sitecontext = get_context_instance(CONTEXT_SYSTEM
, SITEID
);
65 if (has_capability('moodle/course:managefiles', $sitecontext)) {
67 if ($course->id
==$site->id
) {
69 $location = HOTPOT_LOCATION_SITEFILES
;
71 $id = "'+(getObjValue(this.form.location)==".HOTPOT_LOCATION_SITEFILES
."?".$site->id
.":".$COURSE->id
.")+'";
74 } else { // ordinary teacher or content creator
76 $location = HOTPOT_LOCATION_COURSEFILES
;
78 if (array_key_exists($location, $HOTPOT_LOCATION)) {
79 $mform->addElement('hidden', 'location', $location);
80 } else { // admin can select from "site" or "course" files
81 $mform->addElement('select', 'location', get_string('location', 'hotpot'), $HOTPOT_LOCATION);
83 $mform->setType('location', PARAM_INT
);
86 // create "Choose file" button
87 $choosefile_button = $mform->createElement('button', 'popup', get_string('chooseafile', 'resource') .' ...');
89 // create a 'reference' group of form elements, comprising text box + buttons
91 $elements[] = $mform->createElement('text', 'reference', '', array('size'=>'60'));
92 $elements[] = &$choosefile_button;
93 $mform->addGroup($elements, 'reference_elements', get_string('filename', 'resource'), ' ' , false);
95 // set attributes on the button
96 if ($choosefile_button) {
97 $wdir = "'+getDir(this.form.reference.value)+'";
98 $url="/files/index.php?id=$id&wdir=$wdir&choose=id_reference";
99 $options = 'menubar=0,location=0,scrollbars,resizable,width=750,height=500';
101 'title'=>get_string('chooseafile', 'resource'),
102 'onclick'=>"return openpopup('$url', '".$choosefile_button->getName()."', '$options', 0);"
104 $choosefile_button->updateAttributes($attributes);
106 $mform->setType('reference', PARAM_TEXT
);
109 if (isset($form->add
)) {
112 $elements[] = &$mform->createElement('select', 'summarysource', '', $HOTPOT_TEXTSOURCE);
113 $elements[] = &$mform->createElement('htmleditor', 'summary', '');
114 $mform->addGroup($elements, 'summary_elements', get_string('summary'), array(' '), false);
115 $mform->setAdvanced('summary_elements');
118 $mform->addElement('htmleditor', 'summary', get_string('summary'));
119 $mform->setType('summary', PARAM_RAW
);
120 $mform->setHelpButton('summary', array('writing', 'questions', 'richtext'), false, 'editorhelpbutton');
121 $mform->setAdvanced('summary');
123 $mform->setType('summarysource', PARAM_INT
);
124 $mform->setType('summary', PARAM_RAW
);
126 // Add/Update quiz chain?
127 if (isset($form->add
)) {
128 $quizchain = 'addquizchain';
130 $quizchain = 'updatequizchain';
132 $mform->addElement('selectyesno', 'quizchain', get_string($quizchain, 'hotpot'));
133 $mform->setDefault('quizchain', get_user_preferences("hotpot_$quizchain", HOTPOT_NO
));
134 $mform->setHelpButton('quizchain', array($quizchain, get_string($quizchain, 'hotpot'), 'hotpot'));
135 // $mform->setAdvanced('quizchain');
137 //-----------------------------------------------------------------------------------------------
138 $mform->addElement('header', 'displayhdr', get_string('display', 'form'));
139 //-----------------------------------------------------------------------------------------------
142 $mform->addElement('select', 'outputformat', get_string('outputformat', 'hotpot'), $HOTPOT_OUTPUTFORMAT);
143 $mform->setDefault('outputformat', get_user_preferences('hotpot_outputformat', HOTPOT_OUTPUTFORMAT_BEST
));
144 $mform->setHelpButton('outputformat', array('outputformat', get_string('outputformat', 'hotpot'), 'hotpot'));
147 $mform->addElement('select', 'navigation', get_string('navigation', 'hotpot'), $HOTPOT_NAVIGATION);
148 $mform->setDefault('navigation', get_user_preferences('hotpot_navigation', HOTPOT_NAVIGATION_BAR
));
149 $mform->setHelpButton('navigation', array('navigation', get_string('navigation', 'hotpot'), 'hotpot'));
151 // Use Moode player ?
152 $mform->addElement('selectyesno', 'forceplugins', get_string('forceplugins', 'hotpot'));
153 $mform->setDefault('forceplugins', get_user_preferences('hotpot_forceplugins', HOTPOT_NO
));
154 $mform->setHelpButton('forceplugins', array('forceplugins', get_string('forceplugins', 'hotpot'), 'hotpot'));
155 // $mform->setAdvanced('forceplugins');
159 $elements[] = &$mform->createElement('select', 'studentfeedback', '', $HOTPOT_FEEDBACK);
160 $elements[] = &$mform->createElement('text', 'studentfeedbackurl', '', array('size'=>'50'));
161 $mform->addGroup($elements, 'studentfeedback_elements', get_string('studentfeedback', 'hotpot'), array(' '), false);
162 $mform->setHelpButton('studentfeedback_elements', array('studentfeedback', get_string('studentfeedback', 'hotpot'), 'hotpot'));
163 $mform->disabledIf('studentfeedback_elements', 'studentfeedback', 'eq', HOTPOT_FEEDBACK_NONE
);
164 $mform->disabledIf('studentfeedback_elements', 'studentfeedback', 'eq', HOTPOT_FEEDBACK_MOODLEFORUM
);
165 $mform->disabledIf('studentfeedback_elements', 'studentfeedback', 'eq', HOTPOT_FEEDBACK_MOODLEMESSAGING
);
166 // $mform->setAdvanced('studentfeedback_elements');
167 $mform->setType('studentfeedbackurl', PARAM_URL
);
170 $mform->addElement('selectyesno', 'shownextquiz', get_string('shownextquiz', 'hotpot'));
171 $mform->setDefault('shownextquiz', get_user_preferences('hotpot_shownextquiz', HOTPOT_NO
));
172 $mform->setHelpButton('shownextquiz', array('shownextquiz', get_string('shownextquiz', 'hotpot'), 'hotpot'));
173 // $mform->setAdvanced('forceplugins');
175 //-----------------------------------------------------------------------------------------------
176 $mform->addElement('header', 'accesscontrolhdr', get_string('accesscontrol', 'lesson'));
177 //-----------------------------------------------------------------------------------------------
180 $mform->addElement('date_time_selector', 'timeopen', get_string('quizopen', 'quiz'), array('optional'=>true));
181 $mform->setHelpButton('timeopen', array('timeopen', get_string('quizopen', 'quiz'), 'quiz'));
184 $mform->addElement('date_time_selector', 'timeclose', get_string('quizclose', 'quiz'), array('optional'=>true));
185 $mform->setHelpButton('timeclose', array('timeopen', get_string('quizclose', 'quiz'), 'quiz'));
188 $mform->addElement('text', 'password', get_string('requirepassword', 'quiz'));
189 $mform->setType('password', PARAM_TEXT
);
190 $mform->setHelpButton('password', array('requirepassword', get_string('requirepassword', 'quiz'), 'quiz'));
191 // $mform->setAdvanced('password');
194 $mform->addElement('text', 'subnet', get_string('requiresubnet', 'quiz'));
195 $mform->setType('subnet', PARAM_TEXT
);
196 $mform->setHelpButton('subnet', array('requiresubnet', get_string('requiresubnet', 'quiz'), 'quiz'));
197 $mform->setDefault('subnet', get_user_preferences('hotpot_subnet'));
198 // $mform->setAdvanced('subnet');
201 $mform->addElement('selectyesno', 'review', get_string('allowreview', 'quiz'));
202 $mform->setDefault('review', get_user_preferences('hotpot_review', HOTPOT_YES
));
203 $mform->setHelpButton('review', array('review', get_string('allowreview', 'quiz'), 'quiz'));
204 // $mform->setAdvanced('forceplugins');
206 // Maximum number of attempts
208 0 => get_string("attemptsunlimited", "quiz"),
209 1 => '1 '.strtolower(get_string("attempt", "quiz"))
211 for ($i=2; $i<=10; $i++
) {
212 $options[$i] = "$i ".strtolower(get_string("attempts", "quiz"));
214 $mform->addElement('select', 'attempts', get_string('attemptsallowed', 'quiz'), $options);
215 $mform->setDefault('attempts', get_user_preferences('hotpot_attempts', 0)); // 0=unlimited
216 $mform->setHelpButton('attempts', array('attempts', get_string('attemptsallowed', 'quiz'), 'quiz'));
217 // $mform->setAdvanced('forceplugins');
219 //-----------------------------------------------------------------------------------------------
220 $mform->addElement('header', 'gradeshdr', get_string('grades', 'grades'));
221 //-----------------------------------------------------------------------------------------------
225 for ($i=100; $i>=1; $i--) {
228 $options[0] = get_string("nograde");
229 $mform->addElement('select', 'grade', get_string('maximumgrade'), $options);
230 $mform->setDefault('grade', get_user_preferences('hotpot_grade', 100));
231 $mform->setHelpButton('grade', array('maxgrade', get_string('maximumgrade'), 'quiz'));
232 // $mform->setAdvanced('forceplugins');
234 // Maximum grading method
235 $mform->addElement('select', 'grademethod', get_string('grademethod', 'quiz'), $HOTPOT_GRADEMETHOD);
236 $mform->setDefault('grademethod', get_user_preferences('hotpot_grademethod', HOTPOT_GRADEMETHOD_HIGHEST
));
237 $mform->setHelpButton('grademethod', array('grademethod', get_string('grademethod', 'quiz'), 'quiz'));
238 // $mform->setAdvanced('forceplugins');
240 //-----------------------------------------------------------------------------------------------
241 $mform->addElement('header', 'reportshdr', get_string('reports'));
242 //-----------------------------------------------------------------------------------------------
244 // Enable click reporting?
245 $mform->addElement('selectyesno', 'clickreporting', get_string('clickreporting', 'hotpot'));
246 $mform->setDefault('clickreporting', get_user_preferences('hotpot_clickreporting', HOTPOT_NO
));
247 $mform->setHelpButton('clickreporting', array('clickreporting', get_string('clickreporting', 'hotpot'), 'hotpot'));
248 // $mform->setAdvanced('forceplugins');
250 //----------------------------------------------
251 $this->standard_coursemodule_elements();
252 //----------------------------------------------
254 $this->add_action_buttons();
256 $js = '<script type="text/javascript" src="'.$CFG->wwwroot
.'/mod/hotpot/mod_form.js"></script>';
257 $mform->addElement('static', 'hotpot_mod_form_js', '', $js);
260 function data_preprocessing(&$defaults){
263 function validation(&$data) {
264 // http://docs.moodle.org/en/Development:lib/formslib.php_Validation
265 global $CFG, $COURSE;
269 if (empty($data['location'])) {
270 // this shouldn't happen
271 $data['location'] = $COURSE->id
;
273 if ($data['location']==$COURSE->id
) {
275 } else if ($data['location']==SITEID
&& has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_SYSTEM
, SITEID
))) {
276 // admin can access site files
278 // location is invalid or missing, so set to default
279 $data['location'] = $COURSE->id
;
284 if (isset($data['reference'])) {
285 $data['reference'] = trim($data['reference']);
287 if (empty($data['reference'])) {
288 $errors['reference_elements'] = get_string('error_nofilename', 'hotpot');
290 if (preg_match('|^https?://|', $data['reference'])) {
292 $errors['reference_elements'] = 'Sorry, handling of URLs is not implemented yet';
295 $filepath = $CFG->dataroot
.'/'.$data['location'].'/'.$data['reference'];
296 if (! file_exists($filepath)) {
297 $errors['reference_elements'] = get_string('error_pathdoesnotexist', 'hotpot', $filepath);
298 } else if (! $data['quizchain'] && ! is_file($filepath)) {
299 $errors['reference_elements'] = get_string('error_folderwithoutquizchain', 'hotpot');
304 // studentfeedbackurl
305 if ($data['studentfeedbackurl']=='http://') {
306 $data['studentfeedbackurl'] = '';
308 if (empty($data['studentfeedbackurl'])) {
310 if ($data['studentfeedback']==HOTPOT_FEEDBACK_WEBPAGE
) {
313 if ($data['studentfeedback']==HOTPOT_FEEDBACK_FORMMAIL
) {
317 $errors['studentfeedback_elements']= get_string('error_nofeedbackurlformmail', 'hotpot');