Moodle release 1.9.16
[moodle.git] / mod / quiz / comment.php
blob04eec8c135a17074ad7c9148dd97ff565cdb8e63
1 <?php // $Id$
2 /**
3 * This page prints a review of a particular question attempt
5 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
6 * @package quiz
7 */
9 require_once('../../config.php');
10 require_once('locallib.php');
12 $attemptid =required_param('attempt', PARAM_INT); // attempt id
13 $questionid =required_param('question', PARAM_INT); // question id
15 if (! $attempt = get_record('quiz_attempts', 'uniqueid', $attemptid)) {
16 error('No such attempt ID exists');
18 if (! $quiz = get_record('quiz', 'id', $attempt->quiz)) {
19 error('Course module is incorrect');
21 if (! $course = get_record('course', 'id', $quiz->course)) {
22 error('Course is misconfigured');
25 // Teachers are only allowed to comment and grade on closed attempts
26 if (!($attempt->timefinish > 0)) {
27 error('Attempt has not closed yet');
30 $cm = get_coursemodule_from_instance('quiz', $quiz->id);
31 require_login($course, true, $cm);
33 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
35 require_capability('mod/quiz:grade', $context);
37 // Load question
38 if (! $question = get_record('question', 'id', $questionid)) {
39 error('Question for this session is missing');
41 $question->maxgrade = get_field('quiz_question_instances', 'grade', 'quiz', $quiz->id, 'question', $question->id);
42 // Some of the questions code is optimised to work with several questions
43 // at once so it wants the question to be in an array.
44 $key = $question->id;
45 $questions[$key] = &$question;
46 // Add additional questiontype specific information to the question objects.
47 if (!get_question_options($questions)) {
48 error("Unable to load questiontype specific question information");
51 // Load state
52 $states = get_question_states($questions, $quiz, $attempt);
53 // The $states array is indexed by question id but because we are dealing
54 // with only one question there is only one entry in this array
55 $state = &$states[$question->id];
57 print_header();
58 print_heading(format_string($question->name));
60 //add_to_log($course->id, 'quiz', 'review', "review.php?id=$cm->id&amp;attempt=$attempt->id", "$quiz->id", "$cm->id");
62 if ($data = data_submitted() and confirm_sesskey()) {
63 // the following will update the state and attempt
64 $error = question_process_comment($question, $state, $attempt, $data->response['comment'], $data->response['grade']);
65 if (is_string($error)) {
66 notify($error);
67 } else {
68 // If the state has changed save it and update the quiz grade
69 if ($state->changed) {
70 save_question_session($question, $state);
71 quiz_save_best_grade($quiz, $attempt->userid);
74 notify(get_string('changessaved'));
75 echo '<div class="boxaligncenter"><input type="button" onclick="window.opener.location.reload(1); self.close();return false;" value="' .
76 get_string('closewindow') . "\" /></div>";
78 print_footer('empty');
79 exit;
83 question_print_comment_box($question, $state, $attempt, $CFG->wwwroot.'/mod/quiz/comment.php');
85 print_footer('empty');