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