diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php new file mode 100644 index 00000000000..cb3ab1b4fff --- /dev/null +++ b/mod/quiz/attempt.php @@ -0,0 +1,109 @@ +course)) { + error("Course is misconfigured"); + } + + if (! $quiz = get_record("quiz", "id", $cm->instance)) { + error("Course module is incorrect"); + } + + } else { + if (! $quiz = get_record("quiz", "id", $q)) { + error("Course module is incorrect"); + } + if (! $course = get_record("course", "id", $quiz->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) { + error("Course Module ID was incorrect"); + } + } + + require_login($course->id); + + add_to_log($course->id, "quiz", "attempt", "attempt.php?id=$cm->id", "$quiz->id"); + + if ($course->format == "weeks" and $quiz->days) { + $timenow = time(); + $timestart = $course->startdate + (($cw->section - 1) * 608400); + $timefinish = $timestart + (3600 * 24 * $quiz->days); + $available = ($timestart < $timenow and $timenow < $timefinish); + } else { + $available = true; + } + +// Print the page header + + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } + + $strquizzes = get_string("modulenameplural", "quiz"); + $strquiz = get_string("modulename", "quiz"); + + print_header("$course->shortname: $quiz->name", "$course->fullname", + "$navigation id>$strquizzes -> $quiz->name", + "", "", true, update_module_icon($cm->id, $course->id)); + +/// Print the headings and so on + + print_heading($quiz->name); + + if (!$available) { + error("Sorry, this quiz is not available", "view.php?id=$cm->id"); + } + + if ($attempts = quiz_get_user_attempts($quiz->id, $USER->id)) { + $numattempts = count($attempts) + 1; + } else { + $numattempts = 1; + } + + if ($numattempts > $quiz->attempts) { + error("Sorry, you've had $quiz->attempts attempts already.", "view.php?id=$cm->id"); + } + + print_heading("Attempt $numattempts out of $quiz->attempts"); + + print_simple_box($quiz->intro, "CENTER"); + + +/// Print all the questions + + echo "
"; + print_simple_box_start("CENTER"); + + if (!$quiz->questions) { + error("No questions have bee defined!", "view.php?id=$cm->id"); + } + + $questions = explode(",", $quiz->questions); + + echo "
"; + echo "id\">"; + foreach ($questions as $key => $questionid) { + quiz_print_question($key+1, $questionid); + } + echo "
"; + echo "
"; + + print_simple_box_end(); + +// Finish the page + print_footer($course); + +?>