[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/mod/quiz/ -> comment.php (source)

   1  <?php  // $Id: comment.php,v 1.6.2.3 2008/05/15 16:02:15 tjhunt Exp $
   2  /**
   3   * This page prints a review of a particular question attempt
   4   *
   5   * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
   6   * @package quiz
   7   */
   8  
   9      require_once('../../config.php');
  10      require_once ('locallib.php');
  11  
  12      $attemptid =required_param('attempt', PARAM_INT); // attempt id
  13      $questionid =required_param('question', PARAM_INT); // question id
  14  
  15      if (! $attempt = get_record('quiz_attempts', 'uniqueid', $attemptid)) {
  16          error('No such attempt ID exists');
  17      }
  18      if (! $quiz = get_record('quiz', 'id', $attempt->quiz)) {
  19          error('Course module is incorrect');
  20      }
  21      if (! $course = get_record('course', 'id', $quiz->course)) {
  22          error('Course is misconfigured');
  23      }
  24  
  25      // Teachers are only allowed to comment and grade on closed attempts
  26      if (!($attempt->timefinish > 0)) {
  27          error('Attempt has not closed yet');
  28      }
  29  
  30      $cm = get_coursemodule_from_instance('quiz', $quiz->id);
  31      require_login($course, true, $cm);
  32  
  33      $context = get_context_instance(CONTEXT_MODULE, $cm->id);
  34      
  35      require_capability('mod/quiz:grade', $context);
  36  
  37      // Load question
  38      if (! $question = get_record('question', 'id', $questionid)) {
  39          error('Question for this session is missing');
  40      }
  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");
  49      }
  50  
  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];
  56  
  57      print_header();
  58      print_heading(format_string($question->name));
  59  
  60      //add_to_log($course->id, 'quiz', 'review', "review.php?id=$cm->id&amp;attempt=$attempt->id", "$quiz->id", "$cm->id");
  61  
  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);
  72              }
  73  
  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>";
  77  
  78              print_footer();
  79              exit;
  80          }
  81      }
  82  
  83      question_print_comment_box($question, $state, $attempt, $CFG->wwwroot.'/mod/quiz/comment.php');
  84  
  85      print_footer();
  86  
  87  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7