From 0226a97d31f77f72ba32f662a29cf1efdace8b58 Mon Sep 17 00:00:00 2001 From: kaipe Date: Thu, 1 Jan 2004 12:47:50 +0000 Subject: [PATCH] Fixed bug that could cause duplication of attempt numbers. This bug came to the surface when the possibility to delete attempts was introduced in report/overview/report.php --- mod/quiz/attempt.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index e1567ea154..b4663c20a5 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -36,10 +36,15 @@ require_login($course->id); -/// Check number of attempts +/// Set number for next attempt: if ($attempts = quiz_get_user_attempts($quiz->id, $USER->id)) { - $numattempts = count($attempts) + 1; + $numattempts = 2; + foreach ($attempts as $attempt) { + if ($attempt->attempt >= $numattempts) { + $numattempts = $attempt->attempt + 1; + } + } } else { $numattempts = 1; } @@ -63,10 +68,8 @@ /// Check availability - if ($quiz->attempts) { - if ($numattempts > $quiz->attempts) { - error("Sorry, you've had $quiz->attempts attempts already.", "view.php?id=$cm->id"); - } + if ($quiz->attempts and count($attempts) >= $quiz->attempts) { + error("Sorry, you've had $quiz->attempts attempts already.", "view.php?id=$cm->id"); } $timenow = time(); -- 2.39.5