]> git.mjollnir.org Git - moodle.git/commitdiff
Fixed bug that could cause duplication of attempt numbers.
authorkaipe <kaipe>
Thu, 1 Jan 2004 12:47:50 +0000 (12:47 +0000)
committerkaipe <kaipe>
Thu, 1 Jan 2004 12:47:50 +0000 (12:47 +0000)
This bug came to the surface when the possibility to delete attempts was introduced in report/overview/report.php

mod/quiz/attempt.php

index e1567ea1548673de9a6d01f0ab47fadad8e78a85..b4663c20a50927a9cdbd3db490fbbda66199e904 100644 (file)
     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;
     }
 
 /// 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();