Added sesskey checking (SC #113)
[moodle.git] / mod / quiz / review.php
CommitLineData
d1290cec 1<?php // $Id$
29d5d0b4 2
3// This page prints a review of a particular quiz attempt
4
5 require_once("../../config.php");
76cacec8 6 require_once("locallib.php");
29d5d0b4 7
8 optional_variable($id); // Course Module ID, or
9 optional_variable($q); // quiz ID
10
11 require_variable($attempt); // A particular attempt ID for review
12
13 if ($id) {
14 if (! $cm = get_record("course_modules", "id", $id)) {
15 error("Course Module ID was incorrect");
16 }
ec81373f 17
29d5d0b4 18 if (! $course = get_record("course", "id", $cm->course)) {
19 error("Course is misconfigured");
20 }
ec81373f 21
29d5d0b4 22 if (! $quiz = get_record("quiz", "id", $cm->instance)) {
23 error("Course module is incorrect");
24 }
25
26 } else {
27 if (! $quiz = get_record("quiz", "id", $q)) {
28 error("Course module is incorrect");
29 }
30 if (! $course = get_record("course", "id", $quiz->course)) {
31 error("Course is misconfigured");
32 }
33 if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
34 error("Course Module ID was incorrect");
35 }
36 }
37
38 if (! $attempt = get_record("quiz_attempts", "id", $attempt)) {
39 error("No such attempt ID exists");
40 }
41
42
ec81373f 43 require_login($course->id, false, $cm);
29d5d0b4 44
45 if (!isteacher($course->id)) {
46 if (!$quiz->review) {
47 error(get_string("noreview", "quiz"));
48 }
34283aa8 49 if (time() < $quiz->timeclose and $quiz->review == QUIZ_REVIEW_AFTER) {
29d5d0b4 50 error(get_string("noreviewuntil", "quiz", userdate($quiz->timeclose)));
51 }
34283aa8 52 if (time() > $quiz->timeclose and $quiz->review == QUIZ_REVIEW_BEFORE) {
53 error(get_string("noreview", "quiz"));
54 }
29d5d0b4 55 if ($attempt->userid != $USER->id) {
56 error("This is not your attempt!");
57 }
58 }
59
839f2456 60 add_to_log($course->id, "quiz", "review", "review.php?id=$cm->id&amp;attempt=$attempt->id", "$quiz->id", "$cm->id");
29d5d0b4 61
62
63// Print the page header
64
29d5d0b4 65 $strquizzes = get_string("modulenameplural", "quiz");
66 $strquiz = get_string("modulename", "quiz");
67 $strreport = get_string("report", "quiz");
68 $strreview = get_string("review", "quiz");
69 $strname = get_string("name");
70 $strattempts = get_string("attempts", "quiz");
71 $strscore = get_string("score", "quiz");
72 $strgrade = get_string("grade");
73 $strbestgrade = get_string("bestgrade", "quiz");
74 $strtimetaken = get_string("timetaken", "quiz");
75 $strtimecompleted = get_string("timecompleted", "quiz");
d4961620 76 $stroverdue = get_string("overdue", "quiz");
29d5d0b4 77
b6810004 78 print_header_simple(format_string($quiz->name), "",
ec81373f 79 "<a href=\"index.php?id=$course->id\">$strquizzes</a>
b6810004 80 -> <a href=\"view.php?id=$cm->id\">".format_string($quiz->name,true)."</a> -> $strreview",
29d5d0b4 81 "", "", true);
82
b7f35820 83 echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
84
b6810004 85 print_heading(format_string($quiz->name));
29d5d0b4 86
87
ad1a74e0 88/// Include Javascript protection for this page if required
89
90 if (!empty($quiz->popup)) {
91 include("protect_js.php");
92 }
93
8966a111 94 if (!($questions = quiz_get_attempt_questions($quiz, $attempt))) {
95 error("Unable to get questions from database for quiz $quiz->id attempt $attempt->id number $attempt->attempt");
29d5d0b4 96 }
97
8966a111 98 if (!$result = quiz_grade_responses($quiz, $questions)) {
29d5d0b4 99 error("Could not re-grade this quiz attempt!");
100 }
101
3a00dbfd 102 $timelimit = (int)$quiz->timelimit * 60;
235987c5 103 $overtime = 0;
d4961620 104
29d5d0b4 105 if ($timetaken = ($attempt->timefinish - $attempt->timestart)) {
d4961620 106 if($timelimit && $timetaken > ($timelimit + 60)) {
107 $overtime = $timetaken - $timelimit;
108 $overtime = format_time($overtime);
109 }
29d5d0b4 110 $timetaken = format_time($timetaken);
111 } else {
112 $timetaken = "-";
113 }
114
115 $table->align = array("right", "left");
76cacec8 116 if ($attempt->userid <> $USER->id) {
117 $student = get_record('user', 'id', $attempt->userid);
118 $picture = print_user_picture($student->id, $course->id, $student->picture, false, true);
119 $table->data[] = array($picture, fullname($student, true));
120 }
29d5d0b4 121 $table->data[] = array("$strtimetaken:", $timetaken);
122 $table->data[] = array("$strtimecompleted:", userdate($attempt->timefinish));
3a00dbfd 123 if (!empty($overtime)) {
d4961620 124 $table->data[] = array("$stroverdue:", $overtime);
125 }
ed1daaa9 126 if ($quiz->grade) {
d4961620 127 if($overtime) {
128 $result->sumgrades = "0";
129 $result->percentage = "0";
130 $result->grade = "0.0";
131 }
081bf74f 132 $table->data[] = array("$strscore:", "$result->sumgrades/$quiz->sumgrades ($result->percentage %)");
ed1daaa9 133 $table->data[] = array("$strgrade:", "$result->grade/$quiz->grade");
134 }
29d5d0b4 135
136 print_table($table);
137
138 if (isteacher($course->id)) {
139 print_continue("report.php?q=$quiz->id");
140 } else {
141 print_continue("view.php?q=$quiz->id");
142 }
143
144 $quiz->feedback = true;
145 $quiz->correctanswers = true;
146 $quiz->shuffleanswers = false;
147 $quiz->shufflequestions = false;
8966a111 148 quiz_print_quiz_questions($quiz, $questions, $result);
29d5d0b4 149
150 if (isteacher($course->id)) {
151 print_continue("report.php?q=$quiz->id");
152 } else {
153 print_continue("view.php?q=$quiz->id");
154 }
155
156 print_footer($course);
157
158?>