3 * This page prints a review of a particular question attempt
6 * @author Martin Dougiamas and many others. This has recently been completely
7 * rewritten by Alex Smith, Julian Sedding and Gustav Delius as part of
8 * the Serving Mathematics project
9 * {@link http://maths.york.ac.uk/serving_maths}
10 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
14 require_once('../../config.php');
15 require_once('locallib.php');
17 // Either stateid or (attemptid AND questionid) must be given
18 $stateid = optional_param('state', 0, PARAM_INT
); // state id
19 $attemptid = optional_param('attempt', 0, PARAM_INT
); // attempt id
20 $questionid = optional_param('question', 0, PARAM_INT
); // attempt id
21 $number = optional_param('number', 0, PARAM_INT
); // question number
24 if (! $state = get_record('question_states', 'id', $stateid)) {
25 error('Invalid state id');
27 if (! $attempt = get_record('quiz_attempts', 'uniqueid', $state->attempt
)) {
28 error('No such attempt ID exists');
30 } elseif ($attemptid) {
31 if (! $attempt = get_record('quiz_attempts', 'id', $attemptid)) {
32 error('No such attempt ID exists');
34 if (! $neweststateid = get_field('question_sessions', 'newest', 'attemptid', $attempt->uniqueid
, 'questionid', $questionid)) {
35 // newest_state not set, probably because this is an old attempt from the old quiz module code
36 if (! $state = get_record('question_states', 'question', $questionid, 'attempt', $attempt->uniqueid
)) {
37 error('Invalid question id');
40 if (! $state = get_record('question_states', 'id', $neweststateid)) {
41 error('Invalid state id');
45 error('Parameter missing');
47 if (! $question = get_record('question', 'id', $state->question
)) {
48 error('Question for this state is missing');
50 if (! $quiz = get_record('quiz', 'id', $attempt->quiz
)) {
51 error('Course module is incorrect');
53 if (! $course = get_record('course', 'id', $quiz->course
)) {
54 error('Course is misconfigured');
56 if (! $cm = get_coursemodule_from_instance('quiz', $quiz->id
, $course->id
)) {
57 error('Course Module ID was incorrect');
60 require_login($course->id
, false, $cm);
61 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
63 if (!has_capability('mod/quiz:viewreports', $context)) {
64 if (!$attempt->timefinish
) {
65 redirect('attempt.php?q='.$quiz->id
);
67 // If not even responses are to be shown in review then we
68 // don't allow any review
69 if (!($quiz->review
& QUIZ_REVIEW_RESPONSES
)) {
70 error(get_string("noreview", "quiz"));
72 if ((time() - $attempt->timefinish
) > 120) { // always allow review right after attempt
73 if ((!$quiz->timeclose
or time() < $quiz->timeclose
) and !($quiz->review
& QUIZ_REVIEW_OPEN
)) {
74 error(get_string("noreviewuntil", "quiz", userdate($quiz->timeclose
)));
76 if ($quiz->timeclose
and time() >= $quiz->timeclose
and !($quiz->review
& QUIZ_REVIEW_CLOSED
)) {
77 error(get_string("noreview", "quiz"));
80 if ($attempt->userid
!= $USER->id
) {
81 error('This is not your attempt!');
85 //add_to_log($course->id, 'quiz', 'review', "review.php?id=$cm->id&attempt=$attempt->id", "$quiz->id", "$cm->id");
87 /// Print the page header
89 $strquizzes = get_string('modulenameplural', 'quiz');
90 $strreviewquestion = get_string('reviewquestion', 'quiz');
94 echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
97 print_heading(format_string($question->name
));
99 $question->maxgrade
= get_field('quiz_question_instances', 'grade', 'quiz', $quiz->id
, 'question', $question->id
);
100 // Some of the questions code is optimised to work with several questions
101 // at once so it wants the question to be in an array.
102 $key = $question->id
;
103 $questions[$key] = &$question;
104 // Add additional questiontype specific information to the question objects.
105 if (!get_question_options($questions)) {
106 error("Unable to load questiontype specific question information");
109 $session = get_record('question_sessions', 'attemptid', $attempt->uniqueid
, 'questionid', $question->id
);
110 $state->sumpenalty
= $session->sumpenalty
;
111 $state->manualcomment
= $session->manualcomment
;
112 restore_question_state($question, $state);
113 $state->last_graded
= $state;
115 $options = quiz_get_reviewoptions($quiz, $attempt, $context);
116 $options->validation
= ($state->event
== QUESTION_EVENTVALIDATE
);
117 $options->history
= (has_capability('mod/quiz:viewreports', $context) and !$attempt->preview
) ?
'all' : 'graded';
120 $table->align
= array("right", "left");
121 if ($attempt->userid
<> $USER->id
) {
122 // Print user picture and name
123 $student = get_record('user', 'id', $attempt->userid
);
124 $picture = print_user_picture($student->id
, $course->id
, $student->picture
, false, true);
125 $table->data
[] = array($picture, fullname($student, true));
128 $table->data
[] = array(get_string('modulename', 'quiz').':', format_string($quiz->name
));
129 if (has_capability('mod/quiz:viewreports', $context) and count($attempts = get_records_select('quiz_attempts', "quiz = '$quiz->id' AND userid = '$attempt->userid'", 'attempt ASC')) > 1) {
130 // print list of attempts
132 foreach ($attempts as $at) {
133 $attemptlist .= ($at->id
== $attempt->id
)
134 ?
'<b>'.$at->attempt
.'</b>, '
135 : '<a href="reviewquestion.php?attempt='.$at->id
.'&question='.$question->id
.'&number='.$number.'">'.$at->attempt
.'</a>, ';
137 $table->data
[] = array(get_string('attempts', 'quiz').':', trim($attemptlist, ' ,'));
139 if ($state->timestamp
) {
141 $table->data
[] = array(get_string("completedon", "quiz").':', userdate($state->timestamp
));
143 // Print info box unless it is empty
148 print_question($question, $state, $number, $quiz, $options);