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 Frm = document.forms[form];
39
var obj = Frm.elements[master];
42
if (obj.type=='select-one') {
43
var v = obj.options[obj.selectedIndex].value;
44
for (i=0; i<offvalues.length; i++) {
45
if (v==offvalues[i]) {
49
} else if (obj.type=='checkbox') {
50
if (obj.checked==false) {
55
for (i=0; i<subitems.length; i++) {
56
var obj = Frm.elements[subitems[i]];
58
obj.disabled = disabled;
67
<form id="form" method="post" action="mod.php">
68
<table cellpadding="5">
70
<td align="right"><b><?php print_string("name") ?>:</b></td>
71
<td align="left"><?php
72
if ($form->mode=='add') {
74
$text_source_options, "namesource", "$form->namesource", "",
75
"return hotpot_lockoptions('form', 'namesource', namelockitems, nameoffvalues)"
78
print '<input type="hidden" name="namesource" value="'.HOTPOT_TEXTSOURCE_SPECIFIC.'" />';
80
print '<input type="text" name="name" size=40 value="'.$form->name.'">';
86
print_string("summary")
89
helpbutton("summary", get_string("summary"), "resource", true, true);
91
helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
93
if (isset($usehtmleditor) && $usehtmleditor) {
94
helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
97
helpbutton("text", get_string("helptext"), "moodle", true, true);
99
emoticonhelpbutton("form", "description");
104
<td align="left"><?php
105
if ($form->mode=='add') {
106
choose_from_menu($text_source_options, "summarysource", "$form->summarysource", "");
109
print '<input type="hidden" name="summarysource" value="'.HOTPOT_TEXTSOURCE_SPECIFIC.'" />';
111
if (function_exists("print_textarea") && isset($usehtmleditor)) {
112
print_textarea($usehtmleditor, 10, 65, 680, 400, "summary", $form->summary);
114
// Moodle 1.1.1 (original size was rows="5" cols="50")
115
print '<textarea name="summary" rows="10" cols="65" wrap="virtual">'.$form->summary.'</textarea>';
120
<td align="right"><b><?php print_string("quizopen", "quiz") ?>:</b></td>
121
<td align="left"><?php
122
if (!$form->timeopen && $course->format == "weeks") {
123
$form->timeopen = $course->startdate + (($form->section - 1) * 608400);
125
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"').' />';
126
print_date_selector("openday", "openmonth", "openyear", $form->timeopen);
128
print_time_selector("openhour", "openminute", $form->timeopen);
129
helpbutton("timeopen", get_string("quizopen","quiz"), "quiz");
133
<td align="right"><b><?php print_string("quizclose", "quiz") ?>:</b></td>
134
<td align="left"><?php
135
if (!$form->timeclose && $course->format == "weeks") {
136
$form->timeclose= $course->startdate + (($form->section) * 608400);
138
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"').' />';
139
print_date_selector("closeday", "closemonth", "closeyear", $form->timeclose);
141
print_time_selector("closehour", "closeminute", $form->timeclose);
142
helpbutton("timeopen", get_string("quizclose","quiz"), "quiz");
146
<td align="right" nowrap>
147
<b><?php print get_string("location","hotpot") ?>:</b>
149
<td align="left"><?php
151
if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
153
if ($course->id==$site->id) {
155
$location = HOTPOT_LOCATION_SITEFILES;
157
$id = "'+(getObjValue(this.form.location)==".HOTPOT_LOCATION_SITEFILES."?".$site->id.":".$course->id.")+'";
160
} else { // ordinary teacher or content creator
162
$location = HOTPOT_LOCATION_COURSEFILES;
165
if (array_key_exists($location, $HOTPOT_LOCATION)) {
166
print '<input type="hidden" name="location" value="'.$location.'" />';
167
print '<i><font size="-1">'.$HOTPOT_LOCATION[$location].'</font></i> ';
169
} else { // admin can select from "site" or "course" files
170
choose_from_menu($HOTPOT_LOCATION, "location", "$form->location", "");
174
if (function_exists("button_to_popup_window")) {
176
// use javascript to extract wdir from the reference field
177
$wdir = "'+getDir(getObjValue(this.form.reference))+'";
179
// set button url depending on Moodle version
180
if ($CFG->version < 2004083125) { // version may need refining
181
// up to and including Moodle 1.4.1
182
$url = "/mod/resource/coursefiles.php?id=$id&wdir=$wdir";
184
// Moodle 1.4.2 and beyond
185
$url = "/files/index.php?id=$id&wdir=$wdir&choose=form.reference";
188
$strchooseafile = get_string("chooseafile", "resource");
189
button_to_popup_window ($url, 'coursefiles', $strchooseafile, 500, 750, $strchooseafile);
194
<td align="right" nowrap>
195
<b><?php print_string("filename", "resource") ?>:</b>
197
<td align="left"><?php
198
if (function_exists("button_to_popup_window")) {
199
print '<input name="reference" size="50" value="'.$form->reference.'"> ';
201
} else if (function_exists("get_directory_list")) {
202
// Moodle 1.1 (and perhaps some others)
203
$dirs = get_directory_list("$CFG->dataroot/$course->id");
205
foreach ($dirs as $dir) {
206
$options["$dir"] = $dir;
208
choose_from_menu ($options, "reference", $form->reference);
211
// a very old Moodle (may be none left :-)
212
print '<input name="reference" size="50" value="'.$form->reference.'"> ';
215
hotpot_print_show_links($form->course, $form->location, $form->reference, '', ' ', true);
219
<td align="right"><b><?php
220
$quizchain = "{$form->mode}quizchain";
221
print_string($quizchain, "hotpot");
223
<td align="left"><?php
224
choose_from_menu($yes_no_options, "quizchain", $form->quizchain, "");
225
helpbutton($quizchain, get_string($quizchain,"hotpot"), "hotpot");
229
<td align="right"><b><?php print_string("outputformat", "hotpot") ?>:</b></td>
230
<td align="left"><?php
231
choose_from_menu($HOTPOT_OUTPUTFORMAT, "outputformat", "$form->outputformat", "");
232
helpbutton("outputformat", get_string("outputformat","hotpot"), "hotpot");
236
<td align="right"><b><?php print_string("navigation", "hotpot") ?>:</b></td>
237
<td align="left"><?php
238
choose_from_menu($HOTPOT_NAVIGATION, "navigation", "$form->navigation", "");
239
helpbutton("navigation", get_string("navigation","hotpot"), "hotpot");
243
<td align="right"><b><?php print_string("studentfeedback", "hotpot") ?>:</b></td>
244
<td align="left"><?php
246
$HOTPOT_FEEDBACK, "studentfeedback", "$form->studentfeedback", "",
247
"return hotpot_lockoptions('form', 'studentfeedback', feedbacklockitems, feedbackoffvalues)"
249
print '<span id="studentfeedbackurlSPAN">';
250
print "<input name=\"studentfeedbackurl\" size=\"50\" value=\"$form->studentfeedbackurl\">";
252
helpbutton("studentfeedback", get_string("studentfeedback","hotpot"), "hotpot");
256
<td align="right"><b><?php print_string("forceplugins", "hotpot") ?>:</b></td>
257
<td align="left"><?php
258
choose_from_menu($yes_no_options, "forceplugins", "$form->forceplugins", "");
259
helpbutton("forceplugins", get_string("forceplugins","hotpot"), "hotpot");
263
<td align="right"><b><?php print_string("shownextquiz", "hotpot") ?>:</b></td>
264
<td align="left"><?php
265
choose_from_menu($yes_no_options, "shownextquiz", "$form->shownextquiz", "");
266
helpbutton("shownextquiz", get_string("shownextquiz","hotpot"), "hotpot");
270
<td align="right"><b><?php print_string("allowreview", "quiz") ?>:</b></td>
271
<td align="left"><?php
272
choose_from_menu($yes_no_options, "review", "$form->review", "");
273
helpbutton("review", get_string("allowreview","quiz"), "quiz");
277
<td align="right"><b><?php print_string("maximumgrade") ?>:</b></td>
278
<td align="left"><?php
280
for ($i=100; $i>=1; $i--) {
283
$options[0] = get_string("nograde");
285
choose_from_menu($options, "grade", "$form->grade", "");
286
helpbutton("maxgrade", get_string("maximumgrade"), "quiz");
290
<td align="right"><b><?php print_string("grademethod", "quiz") ?>:</b></td>
291
<td align="left"><?php
292
choose_from_menu($HOTPOT_GRADEMETHOD, "grademethod", "$form->grademethod", "");
293
helpbutton("grademethod", get_string("grademethod","quiz"), "quiz");
297
<td align="right"><b><?php print_string("attemptsallowed", "quiz") ?>:</b></td>
298
<td align="left"><?php
300
0 => get_string("attemptsunlimited", "quiz"),
301
1 => '1 '.strtolower(get_string("attempt", "quiz"))
303
for ($i=2; $i<=10; $i++) {
304
$options[$i] = "$i ".strtolower(get_string("attempts", "quiz"));
306
choose_from_menu($options, "attempts", "$form->attempts", "");
307
helpbutton("attempts", get_string("attemptsallowed","quiz"), "quiz");
311
<td align="right"><b><?php print_string("requirepassword", "quiz") ?>:</b></td>
313
<input type="text" name="password" size=40 value="<?php p($form->password) ?>">
314
<?php helpbutton("requirepassword", get_string("requirepassword", "quiz"), "quiz"); ?>
318
<td align="right"><b><?php print_string("requiresubnet", "quiz") ?>:</b></td>
320
<input type="text" name="subnet" size=40 value="<?php p($form->subnet) ?>">
321
<?php helpbutton("requiresubnet", get_string("requiresubnet", "quiz"), "quiz"); ?>
325
<td align="right"><b><?php print_string("clickreporting", "hotpot") ?>:</b></td>
326
<td align="left"><?php
327
choose_from_menu($yes_no_options, "clickreporting", "$form->clickreporting", "");
328
helpbutton("clickreporting", get_string("clickreporting","hotpot"), "hotpot");
332
print_standard_coursemodule_settings($form);
335
<td align="right"> </td>
338
<input type="submit" value="<?php print_string("savechanges") ?>">
339
<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" /><br />
341
if (isset($CFG->release) && substr($CFG->release, 0, 3)>=1.5) {
343
HOTPOT_DISPLAYNEXT_QUIZ => get_string("displayhotpotnext", "hotpot"),
344
HOTPOT_DISPLAYNEXT_COURSE => get_string("displaycoursenext", "hotpot"),
345
HOTPOT_DISPLAYNEXT_INDEX => get_string("displayindexnext", "hotpot")
347
choose_from_menu($options, "displaynext", "$form->displaynext", "");
349
print '<input type="hidden" name="displaynext" value="'.HOTPOT_NO.'" />'."\n";
354
<!-- hidden fields -->
355
<input type="hidden" name="course" value="<?php p($form->course) ?>">
356
<input type="hidden" name="coursemodule" value="<?php p($form->coursemodule) ?>">
357
<input type="hidden" name="section" value="<?php p($form->section) ?>">
358
<input type="hidden" name="module" value="<?php p($form->module) ?>">
359
<input type="hidden" name="modulename" value="<?php p($form->modulename) ?>">
360
<input type="hidden" name="instance" value="<?php p($form->instance) ?>">
361
<input type="hidden" name="mode" value="<?php p($form->mode) ?>">
362
<?php if (isset($USER->sesskey)) { ?>
363
<input type="hidden" name="sesskey" value="<?php p($USER->sesskey) ?>">
368
<script type="text/javascript">
370
hotpot_lockoptions('form', 'namesource', namelockitems, nameoffvalues);
371
hotpot_lockoptions('form', 'enabletimeopen', timeopenlockitems, timeoffvalues);
372
hotpot_lockoptions('form', 'enabletimeclose', timecloselockitems, timeoffvalues);
373
hotpot_lockoptions('form', 'studentfeedback', feedbacklockitems, feedbackoffvalues);
375
// override the standard Moodle "setfocus" function,
376
// which gives a js error if the "name" field is hidden
377
function setfocus() {
378
var Frm = document.getElementById('form');
380
if (canfocus(Frm, 'namesource')) {
381
Frm.namesource.focus();
382
} else if (canfocus(Frm, 'name')) {
387
function canfocus(Frm, name) {
388
var obj = eval('Frm.' + name);
389
return (obj==null || obj.type=='hidden' || obj.focus==null || (obj.style && obj.style.display=='none')) ? false : true;
395
// ======================
397
// ======================
399
function set_form_fields(&$form) {
400
set_form_field($form, 'name');
401
set_form_field($form, 'summary');
402
set_form_field($form, 'timeopen', get_user_preferences('hotpot_timeopen', 0));
403
set_form_field($form, 'enabletimeopen', empty($form->timeopen) ? HOTPOT_NO : HOTPOT_YES);
404
set_form_field($form, 'timeclose', get_user_preferences('hotpot_timeclose', 0));
405
set_form_field($form, 'enabletimeclose', empty($form->timeclose) ? HOTPOT_NO : HOTPOT_YES);
406
set_form_field($form, 'location', HOTPOT_LOCATION_COURSEFILES);
407
set_form_field($form, 'reference');
408
set_form_field($form, 'navigation', get_user_preferences('hotpot_navigation', HOTPOT_NAVIGATION_BAR));
409
set_form_field($form, 'outputformat', get_user_preferences('hotpot_outputformat', HOTPOT_OUTPUTFORMAT_BEST));
410
set_form_field($form, 'studentfeedback', get_user_preferences('hotpot_studentfeedback', HOTPOT_FEEDBACK_NONE));
411
set_form_field($form, 'studentfeedbackurl', get_user_preferences('hotpot_studentfeedbackurl', 'http://'));
412
set_form_field($form, 'forceplugins', get_user_preferences('hotpot_forceplugins', HOTPOT_NO));
413
if ($form->mode=='add') {
414
set_form_field($form, 'namesource', get_user_preferences('hotpot_namesource', HOTPOT_TEXTSOURCE_QUIZ));
415
set_form_field($form, 'summarysource', get_user_preferences('hotpot_summarysource', HOTPOT_TEXTSOURCE_QUIZ));
416
$quizchain = get_user_preferences('hotpot_quizchain', HOTPOT_NO);
418
$quizchain = empty($form->quizchain) ? HOTPOT_NO : HOTPOT_YES;
420
set_form_field($form, 'quizchain', $quizchain);
421
set_form_field($form, 'shownextquiz', get_user_preferences('hotpot_shownextquiz', HOTPOT_NO));
422
set_form_field($form, 'review', get_user_preferences('hotpot_review', HOTPOT_YES));
423
set_form_field($form, 'grade', get_user_preferences('hotpot_grade', 100));
424
set_form_field($form, 'grademethod', get_user_preferences('hotpot_grademethod', HOTPOT_GRADEMETHOD_HIGHEST));
425
set_form_field($form, 'attempts', get_user_preferences('hotpot_attempts', 0)); // 0=unlimited
426
set_form_field($form, 'password');
427
set_form_field($form, 'subnet', get_user_preferences('hotpot_subnet'));
428
set_form_field($form, 'clickreporting', HOTPOT_NO);
429
set_form_field($form, 'displaynext', get_user_preferences('hotpot_displaynext', HOTPOT_DISPLAYNEXT_QUIZ));
431
function set_form_field(&$form, $fieldname, $defaultvalue='') {
432
if (!isset($form->$fieldname)) {
433
$form->$fieldname = $defaultvalue;