Christian's code to support time delays

This commit is contained in:
moodler 2006-03-21 09:24:47 +00:00
parent 07679347f4
commit c88369b8e3
3 changed files with 50 additions and 20 deletions

View File

@ -174,7 +174,6 @@ function quiz_update_instance($quiz) {
$quiz->timelimit = round($quiz->timelimit);
$quiz->id = $quiz->instance;
if (!update_record("quiz", $quiz)) {
return false; // some error occurred
}

View File

@ -70,11 +70,12 @@
//enforced time delay between quiz attempts add-on
//delay1: time delay between first and second attempt
//delay2: time delay between second and additional quiz attempt
if(!isset($form->delay1)) {
$form->delay1 = 0;
//enforced delay attempt between quiz
if (!isset($form->delay1)) {
$form->delay1 = $CFG->quiz_delay1;
}
if(!isset($form->delay2)) {
$form->delay2 = 0;
if (!isset($form->delay2)) {
$form->delay2 = $CFG->quiz_delay2;
}
$fix = 0; // This will later be set to 1 if some of the variables have been fixed by the admin.
@ -344,9 +345,9 @@
<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");
?>
choose_from_menu($timedelayoptions, "delay1", "$form->delay1", "");
helpbutton("timedelay1", get_string("delay1","quiz"), "quiz");
?>
</td>
</tr>
<?php } else $fix=1 ?>
@ -356,9 +357,9 @@
<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");
?>
choose_from_menu($timedelayoptions, "delay2", "$form->delay2", "");
helpbutton("timedelay2", get_string("delay2","quiz"), "quiz");
?>
</td>
</tr>
<?php } else $fix=1 ?>
@ -584,7 +585,7 @@
<td align="right"><b><?php print_string("delay1", "quiz") ?>:</b></td>
<td align="left">
<?php
choose_from_menu($timedelayoptions, "timedelay", "$form->delay1", "");
choose_from_menu($timedelayoptions, "delay1", "$form->delay1", "");
helpbutton("timedelay1", get_string("delay1","quiz"), "quiz");
?>
</td>
@ -596,7 +597,7 @@
<td align="right"><b><?php print_string("delay2", "quiz") ?>:</b></td>
<td align="left">
<?php
choose_from_menu($timedelayoptions, "timedelay", "$form->delay2", "");
choose_from_menu($timedelayoptions, "delay2", "$form->delay2", "");
helpbutton("timedelay2", get_string("delay2","quiz"), "quiz");
?>
</td>

View File

@ -10,7 +10,7 @@
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
$q = optional_param('q', 0, PARAM_INT); // quiz ID
$edit = optional_param('edit', '');
if ($id) {
if (! $cm = get_record("course_modules", "id", $id)) {
error("There is no coursemodule with id $id");
@ -160,7 +160,7 @@
$strtimetaken = get_string("timetaken", "quiz");
$strtimecompleted = get_string("timecompleted", "quiz");
$strgrade = get_string("grade");
$strmarks = get_string('marks', 'quiz');
$strmarks = get_string('marks', 'quiz');
$strbestgrade = $QUIZ_GRADE_METHOD[$quiz->grademethod];
$windowoptions = "left=0, top=0, channelmode=yes, fullscreen=yes, scrollbars=yes, resizeable=no, directories=no, toolbar=no, titlebar=no, location=no, status=no, menubar=no";
@ -311,11 +311,41 @@
echo "<br />";
echo "</p>";
echo "<div align=\"center\">";
include("view_js.php");
echo "</div>\n";
if ($quiz->delay1 or $quiz->delay2) {
//quiz enforced time delay
$lastattempt_obj = get_record_select('quiz_attempts', "quiz = $quiz->id AND attempt = $numattempts AND userid = $USER->id", 'timefinish');
if ($lastattempt_obj) {
$lastattempt = $lastattempt_obj->timefinish;
}
echo "<div align=\"center\">";
if($numattempts == 1 && $quiz->delay1) {
if ($timenow - $quiz->delay1 > $lastattempt) {
include("view_js.php");
}
else {
$notify_msg = get_string('temporaryblocked', 'quiz') . '<b>'. userdate($lastattempt + $quiz->delay1). '<b>';
print_simple_box($notify_msg, "center");
}
}
else if($numattempts > 1 && $quiz->delay2) {
if ($timenow - $quiz->delay2 > $lastattempt) {
include("view_js.php");
}
else {
$notify_msg = get_string('temporaryblocked', 'quiz') . '<b>'. userdate($lastattempt + $quiz->delay2). '<b>';
print_simple_box($notify_msg, "center");
}
}
else {
include("view_js.php");
}
echo "</div>\n";
}
else {
echo "<div align=\"center\">";
include("view_js.php");
echo "</div>\n";
}
}
} else {
print_heading(get_string("nomoreattempts", "quiz"));