"MDL-12304, fix double text"
[moodle-linuxchix.git] / mod / quiz / reviewquestion.php
blob54cdca52b46fbe224633de3e811b03eb67912824
1 <?php // $Id$
2 /**
3 * This page prints a review of a particular question attempt
5 * @author Martin Dougiamas and many others. This has recently been completely
6 * rewritten by Alex Smith, Julian Sedding and Gustav Delius as part of
7 * the Serving Mathematics project
8 * {@link http://maths.york.ac.uk/serving_maths}
9 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
10 * @package quiz
13 require_once('../../config.php');
14 require_once('locallib.php');
16 // Either stateid or (attemptid AND questionid) must be given
17 $stateid = optional_param('state', 0, PARAM_INT); // state id
18 $attemptid = optional_param('attempt', 0, PARAM_INT); // attempt id
19 $questionid = optional_param('question', 0, PARAM_INT); // attempt id
20 $number = optional_param('number', 0, PARAM_INT); // question number
22 if ($stateid) {
23 if (! $state = get_record('question_states', 'id', $stateid)) {
24 error('Invalid state id');
26 if (! $attempt = get_record('quiz_attempts', 'uniqueid', $state->attempt)) {
27 error('No such attempt ID exists');
29 } elseif ($attemptid) {
30 if (! $attempt = get_record('quiz_attempts', 'id', $attemptid)) {
31 error('No such attempt ID exists');
33 if (! $neweststateid = get_field('question_sessions', 'newest', 'attemptid', $attempt->uniqueid, 'questionid', $questionid)) {
34 // newest_state not set, probably because this is an old attempt from the old quiz module code
35 if (! $state = get_record('question_states', 'question', $questionid, 'attempt', $attempt->uniqueid)) {
36 error('Invalid question id');
38 } else {
39 if (! $state = get_record('question_states', 'id', $neweststateid)) {
40 error('Invalid state id');
43 } else {
44 error('Parameter missing');
46 if (! $question = get_record('question', 'id', $state->question)) {
47 error('Question for this state is missing');
49 if (! $quiz = get_record('quiz', 'id', $attempt->quiz)) {
50 error('Course module is incorrect');
52 if (! $course = get_record('course', 'id', $quiz->course)) {
53 error('Course is misconfigured');
55 if (! $cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id)) {
56 error('Course Module ID was incorrect');
59 require_login($course->id, false, $cm);
60 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
62 if (!has_capability('mod/quiz:viewreports', $context)) {
63 if (!$attempt->timefinish) {
64 redirect('attempt.php?q='.$quiz->id);
66 // If not even responses are to be shown in review then we
67 // don't allow any review
68 if (!($quiz->review & QUIZ_REVIEW_RESPONSES)) {
69 print_error("noreview", "quiz");
71 if ((time() - $attempt->timefinish) > 120) { // always allow review right after attempt
72 if ((!$quiz->timeclose or time() < $quiz->timeclose) and !($quiz->review & QUIZ_REVIEW_OPEN)) {
73 print_error("noreviewuntil", "quiz", '', userdate($quiz->timeclose));
75 if ($quiz->timeclose and time() >= $quiz->timeclose and !($quiz->review & QUIZ_REVIEW_CLOSED)) {
76 print_error("noreview", "quiz");
79 if ($attempt->userid != $USER->id) {
80 error('This is not your attempt!');
84 //add_to_log($course->id, 'quiz', 'review', "review.php?id=$cm->id&amp;attempt=$attempt->id", "$quiz->id", "$cm->id");
86 /// Print the page header
88 $strquizzes = get_string('modulenameplural', 'quiz');
90 print_header();
92 echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
94 /// Print heading
95 print_heading(format_string($question->name));
97 $question->maxgrade = get_field('quiz_question_instances', 'grade', 'quiz', $quiz->id, 'question', $question->id);
98 // Some of the questions code is optimised to work with several questions
99 // at once so it wants the question to be in an array.
100 $key = $question->id;
101 $questions[$key] = &$question;
102 // Add additional questiontype specific information to the question objects.
103 if (!get_question_options($questions)) {
104 error("Unable to load questiontype specific question information");
107 $session = get_record('question_sessions', 'attemptid', $attempt->uniqueid, 'questionid', $question->id);
108 $state->sumpenalty = $session->sumpenalty;
109 $state->manualcomment = $session->manualcomment;
110 restore_question_state($question, $state);
111 $state->last_graded = $state;
113 $options = quiz_get_reviewoptions($quiz, $attempt, $context);
114 $options->validation = ($state->event == QUESTION_EVENTVALIDATE);
115 $options->history = (has_capability('mod/quiz:viewreports', $context) and !$attempt->preview) ? 'all' : 'graded';
117 /// Print infobox
118 $table->align = array("right", "left");
119 if ($attempt->userid <> $USER->id) {
120 // Print user picture and name
121 $student = get_record('user', 'id', $attempt->userid);
122 $picture = print_user_picture($student, $course->id, $student->picture, false, true);
123 $table->data[] = array($picture, fullname($student, true));
125 // print quiz name
126 $table->data[] = array(get_string('modulename', 'quiz').':', format_string($quiz->name));
127 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) {
128 // print list of attempts
129 $attemptlist = '';
130 foreach ($attempts as $at) {
131 $attemptlist .= ($at->id == $attempt->id)
132 ? '<b>'.$at->attempt.'</b>, '
133 : '<a href="reviewquestion.php?attempt='.$at->id.'&amp;question='.$question->id.'&amp;number='.$number.'">'.$at->attempt.'</a>, ';
135 $table->data[] = array(get_string('attempts', 'quiz').':', trim($attemptlist, ' ,'));
137 if ($state->timestamp) {
138 // print time stamp
139 $table->data[] = array(get_string("completedon", "quiz").':', userdate($state->timestamp));
141 // Print info box unless it is empty
142 if ($table->data) {
143 print_table($table);
146 print_question($question, $state, $number, $quiz, $options);
148 print_footer();