1 <!-- This page defines the form to create or edit an instance of this module -->
2 <!-- It is used from /course/mod.php.The whole instance is available as $form. -->
6 require_once("$CFG->dirroot/mod/hotpot/lib.php");
8 // set default values in form fields, if necessary
9 set_form_fields($form);
11 // commonly used array of <select> options
12 $yes_no_options = array(
13 HOTPOT_NO
=> get_string("no"),
14 HOTPOT_YES
=> get_string("yes")
16 $text_source_options = array(
17 HOTPOT_TEXTSOURCE_QUIZ
=> get_string("textsourcequiz", "hotpot"),
18 HOTPOT_TEXTSOURCE_FILENAME
=> get_string("textsourcefilename", "hotpot"),
19 HOTPOT_TEXTSOURCE_FILEPATH
=> get_string("textsourcefilepath", "hotpot"),
20 HOTPOT_TEXTSOURCE_SPECIFIC
=> get_string("textsourcespecific", "hotpot")
23 <script type=
"text/javascript">
25 var nameoffvalues
= new Array(0,1,2);
26 var namelockitems
= new Array('name');
28 var timeoffvalues
= new Array('0'); // needs to be '0', not just 0
29 var timeopenlockitems
= new Array('openday','openmonth','openyear','openhour', 'openminute');
30 var timecloselockitems
= new Array('closeday','closemonth','closeyear','closehour','closeminute');
32 var feedbackoffvalues
= new Array(0,3,4,5);
33 var feedbacklockitems
= new Array('studentfeedbackurl');
35 function hotpot_lockoptions(form
, master
, subitems
, offvalues
) {
37 var obj
= eval("document."+form
+"."+master
);
40 if (obj
.type
=='select-one') {
41 var v
= obj
.options
[obj
.selectedIndex
].value
;
42 for (i
=0; i
<offvalues
.length
; i
++) {
43 if (v
==offvalues
[i
]) {
47 } else if (obj
.type
=='checkbox') {
48 if (obj
.checked
==false) {
53 if (document
.getElementById
) {
54 for (i
=0; i
<subitems
.length
; i
++) {
55 eval("document."+form
+"."+subitems
[i
]+".disabled="+disabled
);
63 <form id=
"form" method=
"post" action=
"mod.php">
64 <table cellpadding=
"5">
66 <td align=
"right"><b><?php print_string("name") ?>:
</b></td>
67 <td align=
"left"><?php
68 if ($form->mode
=='add') {
70 $text_source_options, "namesource", "$form->namesource", "",
71 "return hotpot_lockoptions('form', 'namesource', namelockitems, nameoffvalues)"
74 print '<input type="hidden" name="namesource" value="'.HOTPOT_TEXTSOURCE_SPECIFIC
.'" />';
76 print '<input type="text" name="name" size=40 value="'.$form->name
.'">';
82 print_string("summary")
85 helpbutton("summary", get_string("summary"), "resource", true, true);
87 helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
89 if (isset($usehtmleditor) && $usehtmleditor) {
90 helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
93 helpbutton("text", get_string("helptext"), "moodle", true, true);
95 emoticonhelpbutton("form", "description");
100 <td align=
"left"><?php
101 if ($form->mode
=='add') {
102 choose_from_menu($text_source_options, "summarysource", "$form->summarysource", "");
105 print '<input type="hidden" name="summarysource" value="'.HOTPOT_TEXTSOURCE_SPECIFIC
.'" />';
107 if (function_exists("print_textarea") && isset($usehtmleditor)) {
108 print_textarea($usehtmleditor, 10, 65, 680, 400, "summary", $form->summary
);
110 // Moodle 1.1.1 (original size was rows="5" cols="50")
111 print '<textarea name="summary" rows="10" cols="65" wrap="virtual">'.$form->summary
.'</textarea>';
116 <td align=
"right"><b><?php print_string("quizopen", "quiz") ?>:
</b></td>
117 <td align=
"left"><?php
118 if (!$form->timeopen
&& $course->format
== "weeks") {
119 $form->timeopen
= $course->startdate +
(($form->section
- 1) * 608400);
121 print '<input name="enabletimeopen" type="checkbox" value="1" alt="'.get_string("quizopen", "quiz").'" onclick="'."return hotpot_lockoptions('form', 'enabletimeopen', timeopenlockitems)".'" '.(empty($form->timeopen
) ?
'' : 'checked="checked"').' />';
122 print_date_selector("openday", "openmonth", "openyear", $form->timeopen
);
124 print_time_selector("openhour", "openminute", $form->timeopen
);
125 helpbutton("timeopen", get_string("quizopen","quiz"), "quiz");
129 <td align=
"right"><b><?php print_string("quizclose", "quiz") ?>:
</b></td>
130 <td align=
"left"><?php
131 if (!$form->timeclose
&& $course->format
== "weeks") {
132 $form->timeclose
= $course->startdate +
(($form->section
) * 608400);
134 print '<input name="enabletimeclose" type="checkbox" value="1" alt="'.get_string("quizclose", "quiz").'" onclick="'."return hotpot_lockoptions('form', 'enabletimeclose', timecloselockitems)".'" '.(empty($form->timeclose
) ?
'' : 'checked="checked"').' />';
135 print_date_selector("closeday", "closemonth", "closeyear", $form->timeclose
);
137 print_time_selector("closehour", "closeminute", $form->timeclose
);
138 helpbutton("timeopen", get_string("quizclose","quiz"), "quiz");
142 <td align=
"right" nowrap
>
143 <b><?php print get_string("location","hotpot") ?>:
</b>
145 <td align=
"left"><?php
147 if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_SYSTEM
, SITEID
))) {
149 if ($course->id
==$site->id
) {
151 $location = HOTPOT_LOCATION_SITEFILES
;
153 $id = "'+(getObjValue(this.form.location)==".HOTPOT_LOCATION_SITEFILES
."?".$site->id
.":".$course->id
.")+'";
156 } else { // ordinary teacher or content creator
158 $location = HOTPOT_LOCATION_COURSEFILES
;
161 if (array_key_exists($location, $HOTPOT_LOCATION)) {
162 print '<input type="hidden" name="location" value="'.$location.'" />';
163 print '<i><font size="-1">'.$HOTPOT_LOCATION[$location].'</font></i> ';
165 } else { // admin can select from "site" or "course" files
166 choose_from_menu($HOTPOT_LOCATION, "location", "$form->location", "");
170 if (function_exists("button_to_popup_window")) {
172 // use javascript to extract wdir from the reference field
173 $wdir = "'+getDir(getObjValue(this.form.reference))+'";
175 // set button url depending on Moodle version
176 if ($CFG->version
< 2004083125) { // version may need refining
177 // up to and including Moodle 1.4.1
178 $url = "/mod/resource/coursefiles.php?id=$id&wdir=$wdir";
180 // Moodle 1.4.2 and beyond
181 $url = "/files/index.php?id=$id&wdir=$wdir&choose=form.reference";
184 $strchooseafile = get_string("chooseafile", "resource");
185 button_to_popup_window ($url, 'coursefiles', $strchooseafile, 500, 750, $strchooseafile);
190 <td align=
"right" nowrap
>
191 <b><?php print_string("filename", "resource") ?>:
</b>
193 <td align=
"left"><?php
194 if (function_exists("button_to_popup_window")) {
195 print '<input name="reference" size="50" value="'.$form->reference
.'"> ';
197 } else if (function_exists("get_directory_list")) {
198 // Moodle 1.1 (and perhaps some others)
199 $dirs = get_directory_list("$CFG->dataroot/$course->id");
201 foreach ($dirs as $dir) {
202 $options["$dir"] = $dir;
204 choose_from_menu ($options, "reference", $form->reference
);
207 // a very old Moodle (may be none left :-)
208 print '<input name="reference" size="50" value="'.$form->reference
.'"> ';
211 hotpot_print_show_links($form->course
, $form->location
, $form->reference
, '', ' ', true);
215 <td align=
"right"><b><?php
216 $quizchain = "{$form->mode}quizchain";
217 print_string($quizchain, "hotpot");
219 <td align=
"left"><?php
220 choose_from_menu($yes_no_options, "quizchain", $form->quizchain
, "");
221 helpbutton($quizchain, get_string($quizchain,"hotpot"), "hotpot");
225 <td align=
"right"><b><?php print_string("outputformat", "hotpot") ?>:
</b></td>
226 <td align=
"left"><?php
227 choose_from_menu($HOTPOT_OUTPUTFORMAT, "outputformat", "$form->outputformat", "");
228 helpbutton("outputformat", get_string("outputformat","hotpot"), "hotpot");
232 <td align=
"right"><b><?php print_string("navigation", "hotpot") ?>:
</b></td>
233 <td align=
"left"><?php
234 choose_from_menu($HOTPOT_NAVIGATION, "navigation", "$form->navigation", "");
235 helpbutton("navigation", get_string("navigation","hotpot"), "hotpot");
239 <td align=
"right"><b><?php print_string("studentfeedback", "hotpot") ?>:
</b></td>
240 <td align=
"left"><?php
242 $HOTPOT_FEEDBACK, "studentfeedback", "$form->studentfeedback", "",
243 "return hotpot_lockoptions('form', 'studentfeedback', feedbacklockitems, feedbackoffvalues)"
245 print '<span id="studentfeedbackurlSPAN">';
246 print "<input name=\"studentfeedbackurl\" size=\"50\" value=\"$form->studentfeedbackurl\">";
248 helpbutton("studentfeedback", get_string("studentfeedback","hotpot"), "hotpot");
252 <td align=
"right"><b><?php print_string("forceplugins", "hotpot") ?>:
</b></td>
253 <td align=
"left"><?php
254 choose_from_menu($yes_no_options, "forceplugins", "$form->forceplugins", "");
255 helpbutton("forceplugins", get_string("forceplugins","hotpot"), "hotpot");
259 <td align=
"right"><b><?php print_string("shownextquiz", "hotpot") ?>:
</b></td>
260 <td align=
"left"><?php
261 choose_from_menu($yes_no_options, "shownextquiz", "$form->shownextquiz", "");
262 helpbutton("shownextquiz", get_string("shownextquiz","hotpot"), "hotpot");
266 <td align=
"right"><b><?php print_string("allowreview", "quiz") ?>:
</b></td>
267 <td align=
"left"><?php
268 choose_from_menu($yes_no_options, "review", "$form->review", "");
269 helpbutton("review", get_string("allowreview","quiz"), "quiz");
273 <td align=
"right"><b><?php print_string("maximumgrade") ?>:
</b></td>
274 <td align=
"left"><?php
276 for ($i=100; $i>=1; $i--) {
279 $options[0] = get_string("nograde");
281 choose_from_menu($options, "grade", "$form->grade", "");
282 helpbutton("maxgrade", get_string("maximumgrade"), "quiz");
286 <td align=
"right"><b><?php print_string("grademethod", "quiz") ?>:
</b></td>
287 <td align=
"left"><?php
288 choose_from_menu($HOTPOT_GRADEMETHOD, "grademethod", "$form->grademethod", "");
289 helpbutton("grademethod", get_string("grademethod","quiz"), "quiz");
293 <td align=
"right"><b><?php print_string("attemptsallowed", "quiz") ?>:
</b></td>
294 <td align=
"left"><?php
296 0 => get_string("attemptsunlimited", "quiz"),
297 1 => '1 '.strtolower(get_string("attempt", "quiz"))
299 for ($i=2; $i<=10; $i++
) {
300 $options[$i] = "$i ".strtolower(get_string("attempts", "quiz"));
302 choose_from_menu($options, "attempts", "$form->attempts", "");
303 helpbutton("attempts", get_string("attemptsallowed","quiz"), "quiz");
307 <td align=
"right"><b><?php print_string("requirepassword", "quiz") ?>:
</b></td>
309 <input type=
"text" name=
"password" size=
40 value=
"<?php p($form->password) ?>">
310 <?php
helpbutton("requirepassword", get_string("requirepassword", "quiz"), "quiz"); ?>
314 <td align=
"right"><b><?php print_string("requiresubnet", "quiz") ?>:
</b></td>
316 <input type=
"text" name=
"subnet" size=
40 value=
"<?php p($form->subnet) ?>">
317 <?php
helpbutton("requiresubnet", get_string("requiresubnet", "quiz"), "quiz"); ?>
321 <td align=
"right"><b><?php print_string("clickreporting", "hotpot") ?>:
</b></td>
322 <td align=
"left"><?php
323 choose_from_menu($yes_no_options, "clickreporting", "$form->clickreporting", "");
324 helpbutton("clickreporting", get_string("clickreporting","hotpot"), "hotpot");
328 print_standard_coursemodule_settings($form);
331 <td align=
"right"> </td>
334 <input type=
"submit" value=
"<?php print_string("savechanges
") ?>">  
;  
;
335 <input type
="submit" name
="cancel" value
="<?php print_string("cancel
") ?>" /><br
/>
337 if (isset($CFG->release
) && substr($CFG->release
, 0, 3)>=1.5) {
339 HOTPOT_DISPLAYNEXT_QUIZ
=> get_string("displayhotpotnext", "hotpot"),
340 HOTPOT_DISPLAYNEXT_COURSE
=> get_string("displaycoursenext", "hotpot"),
341 HOTPOT_DISPLAYNEXT_INDEX
=> get_string("displayindexnext", "hotpot")
343 choose_from_menu($options, "displaynext", "$form->displaynext", "");
345 print '<input type="hidden" name="displaynext" value="'.HOTPOT_NO
.'" />'."\n";
350 <!-- hidden fields -->
351 <input type=
"hidden" name=
"course" value=
"<?php p($form->course) ?>">
352 <input type
="hidden" name
="coursemodule" value
="<?php p($form->coursemodule) ?>">
353 <input type
="hidden" name
="section" value
="<?php p($form->section) ?>">
354 <input type
="hidden" name
="module" value
="<?php p($form->module) ?>">
355 <input type
="hidden" name
="modulename" value
="<?php p($form->modulename) ?>">
356 <input type
="hidden" name
="instance" value
="<?php p($form->instance) ?>">
357 <input type
="hidden" name
="mode" value
="<?php p($form->mode) ?>">
358 <?php
if (isset($USER->sesskey
)) { ?>
359 <input type=
"hidden" name=
"sesskey" value=
"<?php p($USER->sesskey) ?>">
364 <script type=
"text/javascript">
366 hotpot_lockoptions('form', 'namesource', namelockitems
, nameoffvalues
);
367 hotpot_lockoptions('form', 'enabletimeopen', timeopenlockitems
, timeoffvalues
);
368 hotpot_lockoptions('form', 'enabletimeclose', timecloselockitems
, timeoffvalues
);
369 hotpot_lockoptions('form', 'studentfeedback', feedbacklockitems
, feedbackoffvalues
);
371 // override the standard Moodle "setfocus" function,
372 // which gives a js error if the "name" field is hidden
373 function setfocus() {
374 var f
= getElementById('form');
376 if (canfocus(f
, 'namesource')) {
377 f
.namesource
.focus();
378 } else if (canfocus(f
, 'name')) {
383 function canfocus(f
, name
) {
384 var obj
= eval('f.'+name
);
385 return (obj
==null || obj
.type
=='hidden' || obj
.focus
==null || (obj
.style
&& obj
.style
.display
=='none')) ? false : true;
391 // ======================
393 // ======================
395 function set_form_fields(&$form) {
396 set_form_field($form, 'name');
397 set_form_field($form, 'summary');
398 set_form_field($form, 'timeopen', get_user_preferences('hotpot_timeopen', 0));
399 set_form_field($form, 'enabletimeopen', empty($form->timeopen
) ? HOTPOT_NO
: HOTPOT_YES
);
400 set_form_field($form, 'timeclose', get_user_preferences('hotpot_timeclose', 0));
401 set_form_field($form, 'enabletimeclose', empty($form->timeclose
) ? HOTPOT_NO
: HOTPOT_YES
);
402 set_form_field($form, 'location', HOTPOT_LOCATION_COURSEFILES
);
403 set_form_field($form, 'reference');
404 set_form_field($form, 'navigation', get_user_preferences('hotpot_navigation', HOTPOT_NAVIGATION_BAR
));
405 set_form_field($form, 'outputformat', get_user_preferences('hotpot_outputformat', HOTPOT_OUTPUTFORMAT_BEST
));
406 set_form_field($form, 'studentfeedback', get_user_preferences('hotpot_studentfeedback', HOTPOT_FEEDBACK_NONE
));
407 set_form_field($form, 'studentfeedbackurl', get_user_preferences('hotpot_studentfeedbackurl', 'http://'));
408 set_form_field($form, 'forceplugins', get_user_preferences('hotpot_forceplugins', HOTPOT_NO
));
409 if ($form->mode
=='add') {
410 set_form_field($form, 'namesource', get_user_preferences('hotpot_namesource', HOTPOT_TEXTSOURCE_QUIZ
));
411 set_form_field($form, 'summarysource', get_user_preferences('hotpot_summarysource', HOTPOT_TEXTSOURCE_QUIZ
));
412 $quizchain = get_user_preferences('hotpot_quizchain', HOTPOT_NO
);
414 $quizchain = empty($form->quizchain
) ? HOTPOT_NO
: HOTPOT_YES
;
416 set_form_field($form, 'quizchain', $quizchain);
417 set_form_field($form, 'shownextquiz', get_user_preferences('hotpot_shownextquiz', HOTPOT_NO
));
418 set_form_field($form, 'review', get_user_preferences('hotpot_review', HOTPOT_YES
));
419 set_form_field($form, 'grade', get_user_preferences('hotpot_grade', 100));
420 set_form_field($form, 'grademethod', get_user_preferences('hotpot_grademethod', HOTPOT_GRADEMETHOD_HIGHEST
));
421 set_form_field($form, 'attempts', get_user_preferences('hotpot_attempts', 0)); // 0=unlimited
422 set_form_field($form, 'password');
423 set_form_field($form, 'subnet', get_user_preferences('hotpot_subnet'));
424 set_form_field($form, 'clickreporting', HOTPOT_NO
);
425 set_form_field($form, 'displaynext', get_user_preferences('hotpot_displaynext', HOTPOT_DISPLAYNEXT_QUIZ
));
427 function set_form_field(&$form, $fieldname, $defaultvalue='') {
428 if (!isset($form->$fieldname)) {
429 $form->$fieldname = $defaultvalue;