moodle/mod/quiz/mod.html
2006-08-22 19:00:18 +00:00

570 lines
21 KiB
HTML

<?php
// This page defines the form to create or edit an instance of this module -->
// It is used from /course/mod.php. The whole instance is available as $form. -->
require_once("$CFG->dirroot/mod/quiz/locallib.php");
// Set any form variables that have not been initialized to their default value.
if (!isset($form->name)) {
$form->name = "";
}
if (!isset($form->intro)) {
$form->intro = "";
}
if (!isset($form->timeopen)) {
$form->timeopen = "";
}
if (!isset($form->timeclose)) {
$form->timeclose = "";
}
if (!isset($form->attempts)) {
$form->attempts = $CFG->quiz_attempts;
}
if (!isset($form->attemptonlast)) {
$form->attemptonlast = $CFG->quiz_attemptonlast;
}
if (!isset($form->grademethod)) {
$form->grademethod = $CFG->quiz_grademethod;
}
if (!isset($form->decimalpoints)) {
$form->decimalpoints = $CFG->quiz_decimalpoints;
}
if (!isset($form->review)) {
$form->review = $CFG->quiz_review;
}
if (!isset($form->questionsperpage)) {
$form->questionsperpage = $CFG->quiz_questionsperpage;
}
if (!isset($form->shufflequestions)) {
$form->shufflequestions = $CFG->quiz_shufflequestions;
}
if (!isset($form->shuffleanswers)) {
$form->shuffleanswers = $CFG->quiz_shuffleanswers;
}
if (!isset($form->grade)) {
$form->grade = $CFG->quiz_maximumgrade;
}
if (!isset($form->questions)) {
$form->questions = "";
}
if (!isset($form->password)) {
$form->password = $CFG->quiz_password;
}
if (!isset($form->subnet)) {
$form->subnet = $CFG->quiz_subnet;
}
if (!isset($form->timelimit)) {
$form->timelimit = $CFG->quiz_timelimit;
}
if (!isset($form->popup)) {
$form->popup = $CFG->quiz_popup;
}
if (!isset($form->optionflags)) {
$form->optionflags = $CFG->quiz_optionflags;
}
if (!isset($form->penaltyscheme)) {
$form->penaltyscheme = $CFG->quiz_penaltyscheme;
}
if (empty($form->timedue)) {
$form->timedue = "";
}
//enforced time delay between quiz attempts
//delay1: time delay between first and second attempt
//delay2: time delay between second and additional quiz attempt
if (!isset($form->delay1)) {
$form->delay1 = $CFG->quiz_delay1;
}
if (!isset($form->delay2)) {
$form->delay2 = $CFG->quiz_delay2;
}
// Get any existing feedback text out of the database.
if (!empty($form->id)) {
$feedbacks = get_records('quiz_feedback', 'quizid', $form->id, 'mingrade DESC');
} else {
$feedbacks = array();
}
$form->feedbacktext = array();
$form->feedbackboundaries = array();
foreach ($feedbacks as $feedback) {
$form->feedbacktext[] = $feedback->feedbacktext;
if ($feedback->mingrade > 0) {
$form->feedbackboundaries[] = (100.0 * $feedback->mingrade / $form->grade) . '%';
}
}
// Make sure there are at least 5 feedbacktexts, or a bit more than the current nubmer.
$numfeedbacks = max(
count($form->feedbacktext) * 1.5,
count($form->feedbackboundaries) * 1.5,
5
);
for ($i = 0; $i < $numfeedbacks; $i += 1) {
if (!array_key_exists($i, $form->feedbacktext)) {
$form->feedbacktext[$i] = '';
}
if (!array_key_exists($i, $form->feedbackboundaries)) {
$form->feedbackboundaries[$i] = '';
}
}
// The following are used for drop-down menus
$yesnooptions = array(get_string("no"), get_string("yes"));
$attemptoptions = array();
$attemptoptions[0] = get_string("attemptsunlimited", "quiz");
$attemptoptions[1] = "1 ".strtolower(get_string("attempt", "quiz"));
for ($i=2;$i<=6;$i++) {
$attemptoptions[$i] = "$i ".strtolower(get_string("attempts", "quiz"));
}
//enforced time delay between quiz attempts add-on
$timedelayoptions = array();
$timedelayoptions[0] = get_string('none');
$timedelayoptions[1800] = get_string('numminutes', '', 30);
$timedelayoptions[3600] = get_string('numminutes', '', 60);
for($i=2; $i<=23; $i++) {
$seconds = $i*3600;
$timedelayoptions[$seconds] = get_string('numhours', '', $i);
}
$timedelayoptions[86400] = get_string('numhours', '', 24);
for($i=2; $i<=7; $i++) {
$seconds = $i*86400;
$timedelayoptions[$seconds] = get_string('numdays', '', $i);
}
?>
<script type="text/javascript" language="javascript">
var dueitems = ['dueday','duemonth','dueyear','duehour', 'dueminute'];
var availableitems = ['availableday','availablemonth','availableyear','availablehour', 'availableminute'];
var timelimititems = ['timelimit'];
</script>
<form name="form" method="post" action="mod.php">
<center>
<!-- Now comes a table with all the options that have not been fixed by the admin -->
<table cellpadding="5">
<tr valign="top">
<td align="right"><b><?php print_string("name") ?>:</b></td>
<td align="left">
<input type="text" name="name" size="40" value="<?php p($form->name) ?>" />
</td>
</tr>
<tr valign="top">
<td align="right"><b><?php print_string("introduction", "quiz") ?>:</b><br /><br />
<?php
if ($usehtmleditor) {
helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
} else {
helpbutton("text", get_string("helptext"), "moodle", true, true);
echo '<br />';
emoticonhelpbutton("form", "description");
echo '<br />';
}
?>
</td>
<td align="left">
<?php
print_textarea($usehtmleditor, 20, 50, 680, 400, "intro", $form->intro);
?>
</td>
</tr>
<tr valign="top">
<td align="right"><b><?php print_string("quizopen", "quiz") ?>:</b></td>
<td align="left">
<input name="availableenable" type="checkbox" value="1" alt="<?php print_string("quizopen", "quiz") ?>" onclick="return lockoptions('form', 'availableenable', availableitems)" <?php if ($form->timeopen) echo 'checked="checked"' ?> />
<?php
print_date_selector("availableday", "availablemonth", "availableyear", $form->timeopen);
echo "&nbsp;-&nbsp;";
print_time_selector("availablehour", "availableminute", $form->timeopen);
helpbutton('timeopen', get_string('quizopens', 'quiz'), 'quiz');
?>
<input type="hidden" name="havailableday" value="0" />
<input type="hidden" name="havailablemonth" value="0" />
<input type="hidden" name="havailableyear" value="0" />
<input type="hidden" name="havailablehour" value="0" />
<input type="hidden" name="havailableminute" value="0" />
</td>
</tr>
<tr valign="top">
<td align="right"><b><?php print_string("quizclose", "quiz") ?>:</b></td>
<td align="left">
<input name="dueenable" type="checkbox" value="1" alt="<?php print_string("quizclose", "quiz") ?>" onclick="return lockoptions('form', 'dueenable', dueitems)" <?php if ($form->timeclose) echo 'checked="checked"' ?> />
<?php
print_date_selector("dueday", "duemonth", "dueyear", $form->timeclose);
echo "&nbsp;-&nbsp;";
print_time_selector("duehour", "dueminute", $form->timeclose);
helpbutton('timeopen', get_string('quizcloses', 'quiz'), 'quiz');
?>
<input type="hidden" name="hdueday" value="0" />
<input type="hidden" name="hduemonth" value="0" />
<input type="hidden" name="hdueyear" value="0" />
<input type="hidden" name="hduehour" value="0" />
<input type="hidden" name="hdueminute" value="0" />
</td>
</tr>
<?php
// Output all the options that may, or may not, have been fixed by the admin.
// This time out put the ones that were not fixed.
$fix = output_quiz_options_fields($form, 0);
// Output standard module settings.
print_standard_coursemodule_settings($form);
// Output the boxes for typing feedback depending on overall quiz score.
?>
<tr><td colspan="2">
<?php print_heading_with_help(get_string('overallfeedback', 'quiz'), 'overallfeedback', 'quiz'); ?>
</td></tr>
<tr valign="top">
<td align="right"><b><?php print_string('gradeboundary', 'quiz') ?>:</b></td>
<td align="left">100%</td>
</tr>
<?php for ($i = 0; $i < count($form->feedbacktext); $i = $i + 1) { ?>
<tr valign="top">
<td align="right"><b><?php print_string('feedback', 'quiz') ?>:</b></td>
<td align="left">
<input type="text" name="feedbacktext[]" size="60" value="<?php p($form->feedbacktext[$i]) ?>" />
</td>
</tr>
<?php if ($i < count($form->feedbacktext) - 1) { ?>
<tr valign="top">
<td align="right"><b><?php print_string('gradeboundary', 'quiz') ?>:</b></td>
<td align="left">
<input type="text" name="feedbackboundaries[]" size="20" value="<?php p($form->feedbackboundaries[$i]) ?>" />
</td>
</tr>
<?php } ?>
<?php } ?>
<tr valign="top">
<td align="right"><b><?php print_string('gradeboundary', 'quiz') ?>:</b></td>
<td align="left">0%</td>
</tr>
<?php
if ($fix) {
// Some options were fixed by the admin. Show them, but hidden behind an Advanced button.
?>
<tr>
<td align="right"><b><?php print_string('advancedsettings') ?>:</b>
<!-- Some javascript to allow for the hiding of advanced options
This code was derived from mod.html in the resource module -->
<script language="javascript" type="text/javascript">
function showhide (id, set) {
divobj = document.getElementById(id);
butobj = document.getElementById(id+'button');
prefobj = document.getElementById(id+'pref');
if (set == true) {
if (prefobj.value == '1') {
divobj.style.display = 'block';
butobj.value = '<?php print_string("hideadvancedsettings") ?>';
} else {
divobj.style.display = 'none';
butobj.value = '<?php print_string("showadvancedsettings") ?>...';
}
} else {
if (prefobj.value == '1') {
divobj.style.display = 'none';
butobj.value = '<?php print_string("showadvancedsettings") ?>...';
prefobj.value = '0';
} else {
divobj.style.display = 'block';
butobj.value = '<?php print_string("hideadvancedsettings") ?>';
prefobj.value = '1';
}
}
}
</script>
</td>
<td align="left">
<input type="button" value="hide settings" id="optionsettingsbutton" onclick="javascript: return showhide('optionsettings');" />
<input type="hidden" name="optionsettingspref" id="optionsettingspref" value="<?php echo get_user_preferences('quiz_optionsettingspref', 0); ?>" />
<br />
</td>
</tr>
<!-- Now comes a copy of the options fields in a div with id optionsettings and with
the conditions reversed, so that it shows exactly the options that are usually hidden.
The visibility of this div is controlled by javascript. -->
<tr><td colspan="2">
<div id="optionsettings">
<table align="center">
<?php
// Output all the options that may, or may not, have been fixed by the admin.
// This time out put the ones that were fixed.
output_quiz_options_fields($form, 1);
?>
</table>
<script language="javascript" type="text/javascript">
showhide('optionsettings', true);
</script>
</div></td></tr>
<?php } ?>
</table>
<br />
<input type="hidden" name="grade" value="<?php echo $form->grade; ?>" />
<!-- these hidden variables are always the same -->
<input type="hidden" name="course" value="<?php p($form->course) ?>" />
<input type="hidden" name="sesskey" value="<?php p($form->sesskey) ?>" />
<input type="hidden" name="coursemodule" value="<?php p($form->coursemodule) ?>" />
<input type="hidden" name="section" value="<?php p($form->section) ?>" />
<input type="hidden" name="module" value="<?php p($form->module) ?>" />
<input type="hidden" name="modulename" value="<?php p($form->modulename) ?>" />
<input type="hidden" name="instance" value="<?php p($form->instance) ?>" />
<input type="hidden" name="mode" value="<?php p($form->mode) ?>" />
<!-- provide an additional button to edit questions -->
<?php if ($form->instance) { ?>
<input type="hidden" name="redirecturl" value="<?php p("$CFG->wwwroot/mod/quiz/edit.php?quizid=$form->instance") ?>" />
<input type="submit" name="redirect" value="<?php print_string("savechanges") ?>" />
<?php } else { ?>
<input type="submit" value="<?php print_string("savechanges") ?>" />
<?php } ?>
<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
</center>
</form>
<script type="text/javascript">
<?php
if (!$form->timeclose) echo "lockoptions('form','dueenable', dueitems);";
if (!$form->timeopen) echo "lockoptions('form','availableenable', availableitems);";
if (!$form->timelimit) echo "lockoptions('form','timelimitenable', timelimititems);";
?>
</script>
<?php
/**
* This function outputs all the quiz options that may, or may not, have been
* locked by admin. Whether the locked or unlocked fields are shown depends on
* $showfixed.
*
* @param object $form the data being used to initialise the form.
* @param integer $showfixed if 0, output the unlocked fields, if 1 output the locked fields.
* @return boolean true if some filds were not output with this setting of $showfixed
*/
function output_quiz_options_fields($form, $showfixed) {
global $CFG, $QUIZ_GRADE_METHOD, $yesnooptions, $attemptoptions, $timedelayoptions;
$hidden = false;
?>
<?php if ($CFG->quiz_fix_timelimit == $showfixed) { ?>
<tr valign="top">
<td align="right"><b><?php print_string("timelimit", "quiz") ?>:</b></td>
<td align="left">
<input name="timelimitenable" type="checkbox" value="1" alt="<?php print_string('timelimit', 'quiz') ?>" onclick="return lockoptions('form', 'timelimitenable', timelimititems)" <?php if ($form->timelimit) echo 'checked="checked"' ?> />
<input type="text" name="timelimit" size="3" value="<?php p($form->timelimit ? $form->timelimit : '') ?>" />
<?php
print_string('minutes');
helpbutton("timelimit", get_string("quiztimer","quiz"), "quiz");
?>
<input type="hidden" name="htimelimit" value="0" />
</td>
</tr>
<?php } else { $hidden = true; } ?>
<?php if ($CFG->quiz_fix_questionsperpage == $showfixed) { ?>
<tr valign="top">
<td align="right"><b><?php print_string('questionsperpage', 'quiz') ?>:</b></td>
<td align="left">
<?php
$perpage= array();
for ($i=0; $i<=50; ++$i) {
$perpage[$i] = $i;
}
$perpage[0] = get_string('allinone', 'quiz');
choose_from_menu($perpage, 'questionsperpage', $form->questionsperpage, '');
helpbutton('questionsperpage', get_string('questionsperpage', 'quiz'), 'quiz');
?>
</td>
</tr>
<?php } else { $hidden = true; } ?>
<?php if ($CFG->quiz_fix_shufflequestions == $showfixed) { ?>
<tr valign="top">
<td align="right"><b><?php print_string("shufflequestions", "quiz") ?>:</b></td>
<td align="left">
<?php
choose_from_menu($yesnooptions, "shufflequestions", "$form->shufflequestions", "");
helpbutton("shufflequestions", get_string("shufflequestions","quiz"), "quiz");
?>
</td>
</tr>
<?php } else { $hidden = true; } ?>
<?php if ($CFG->quiz_fix_shuffleanswers == $showfixed) { ?>
<tr valign="top">
<td align="right"><b><?php print_string("shufflewithin", "quiz") ?>:</b></td>
<td align="left">
<?php
choose_from_menu($yesnooptions, "shuffleanswers", "$form->shuffleanswers", "");
helpbutton("shufflewithin", get_string("shufflewithin","quiz"), "quiz");
?>
</td>
</tr>
<?php } else { $hidden = true; } ?>
<?php if ($CFG->quiz_fix_attempts == $showfixed) { ?>
<tr valign="top">
<td align="right"><b><?php print_string("attemptsallowed", "quiz") ?>:</b></td>
<td align="left">
<?php
choose_from_menu($attemptoptions, "attempts", "$form->attempts", "");
helpbutton("attempts", get_string("attemptsallowed","quiz"), "quiz");
?>
</td>
</tr>
<?php } else { $hidden = true; } ?>
<?php if ($CFG->quiz_fix_attemptonlast == $showfixed) { ?>
<tr valign="top">
<td align="right"><b><?php print_string("eachattemptbuildsonthelast", "quiz") ?>:</b></td>
<td align="left">
<?php
choose_from_menu($yesnooptions, "attemptonlast",
"$form->attemptonlast", "");
helpbutton("repeatattempts",
get_string("eachattemptbuildsonthelast", "quiz"),
"quiz");
?>
</td>
</tr>
<?php } else { $hidden = true; } ?>
<?php if ($CFG->quiz_fix_grademethod == $showfixed) { ?>
<tr valign="top">
<td align="right"><b><?php print_string("grademethod", "quiz") ?>:</b></td>
<td align="left">
<?php
choose_from_menu($QUIZ_GRADE_METHOD, "grademethod", "$form->grademethod", "");
helpbutton("grademethod", get_string("grademethod","quiz"), "quiz");
?>
</td>
</tr>
<?php } else { $hidden = true; } ?>
<?php if ($CFG->quiz_fix_adaptive == $showfixed) { ?>
<tr valign="top">
<td align="right"><b><?php print_string("adaptive", "quiz") ?>:</b></td>
<td align="left">
<?php
choose_from_menu($yesnooptions, "adaptive", ($form->optionflags & QUESTION_ADAPTIVE) ? 1 : 0, "");
helpbutton("adaptive", get_string("adaptive","quiz"), "quiz");
?>
</td>
</tr>
<?php } else { $hidden = true; } ?>
<?php if ($CFG->quiz_fix_penaltyscheme == $showfixed) { ?>
<tr valign="top">
<td align="right"><b><?php print_string("penaltyscheme", "quiz") ?>:</b></td>
<td align="left">
<?php
choose_from_menu($yesnooptions, "penaltyscheme", "$form->penaltyscheme", "");
helpbutton("penaltyscheme", get_string("penaltyscheme","quiz"), "quiz");
?>
</td>
</tr>
<?php } else { $hidden = true; } ?>
<?php if ($CFG->quiz_fix_decimalpoints == $showfixed) { ?>
<tr valign="top">
<td align="right"><b><?php print_string("decimaldigits", "quiz") ?>:</b></td>
<td align="left">
<?php
$options = array(
0 => '0',
1 => '1',
2 => '2',
3 => '3'
);
choose_from_menu($options, "decimalpoints", "$form->decimalpoints", "");
helpbutton("decimalpoints", get_string("decimaldigits","quiz"), "quiz");
?>
</td>
</tr>
<?php } else { $hidden = true; } ?>
<?php if ($CFG->quiz_fix_review == $showfixed) {
echo '<tr valign="top">';
include($CFG->dirroot . '/mod/quiz/reviewoptions.html');
echo '</tr>';
$output = true;
} ?>
<?php if ($CFG->quiz_fix_delay1 == $showfixed) { ?>
<tr valign="top">
<td align="right"><b><?php print_string("delay1", "quiz") ?>:</b></td>
<td align="left">
<?php
choose_from_menu($timedelayoptions, "delay1", "$form->delay1", "");
helpbutton("timedelay1", get_string("delay1","quiz"), "quiz");
?>
</td>
</tr>
<?php } else { $hidden = true; } ?>
<?php if ($CFG->quiz_fix_delay2 == $showfixed) { ?>
<tr valign="top">
<td align="right"><b><?php print_string("delay2", "quiz") ?>:</b></td>
<td align="left">
<?php
choose_from_menu($timedelayoptions, "delay2", "$form->delay2", "");
helpbutton("timedelay2", get_string("delay2","quiz"), "quiz");
?>
</td>
</tr>
<?php } else { $hidden = true; } ?>
<?php if ($CFG->quiz_fix_popup == $showfixed) { ?>
<tr valign="top">
<td align="right"><b><?php print_string("popup", "quiz") ?>:</b></td>
<td align="left">
<?php
choose_from_menu($yesnooptions, "popup", "$form->popup", "");
helpbutton("popup", get_string("popup","quiz"), "quiz");
?>
</td>
</tr>
<?php } else { $hidden = true; } ?>
<?php if ($CFG->quiz_fix_password == $showfixed) { ?>
<tr valign="top">
<td align="right"><b><?php print_string("requirepassword", "quiz") ?>:</b></td>
<td align="left">
<input type="text" name="password" size="40" value="<?php p($form->password) ?>" />
<?php helpbutton("requirepassword", get_string("requirepassword", "quiz"), "quiz"); ?>
</td>
</tr>
<?php } else { $hidden = true; } ?>
<?php if ($CFG->quiz_fix_subnet == $showfixed) { ?>
<tr valign="top">
<td align="right"><b><?php print_string("requiresubnet", "quiz") ?>:</b></td>
<td align="left">
<input type="text" name="subnet" size="40" value="<?php p($form->subnet) ?>" />
<?php helpbutton("requiresubnet", get_string("requiresubnet", "quiz"), "quiz"); ?>
</td>
</tr>
<?php } else { $hidden = true; } ?>
<?php
return $hidden;
}
?>