]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15535 - URLs are changing from attempt.php?id=XXX to attempt.php?attempt =YYY...
authortjhunt <tjhunt>
Wed, 9 Jul 2008 17:00:26 +0000 (17:00 +0000)
committertjhunt <tjhunt>
Wed, 9 Jul 2008 17:00:26 +0000 (17:00 +0000)
mod/quiz/attempt.php
mod/quiz/reviewquestion.php
mod/quiz/startattempt.php
mod/quiz/tabs.php

index 786fec11768674ddd456af7795fddeb7dbfc2902..ed64dc35276dc9a92df820fbbf9b7e2c70492d77 100644 (file)
     require_once(dirname(__FILE__) . '/../../config.php');
     require_once($CFG->dirroot . '/mod/quiz/locallib.php');
 
-/// remember the current time as the time any responses were submitted
+/// Look for old-style URLs, such as may be in the logs, and redirect them to startattemtp.php 
+    if ($id = optional_param('id', 0, PARAM_INTEGER)) {
+        redirect($CFG->wwwroot . '/mod/quiz/startattempt.php?cmid=' . $id . '&sesskey=' . sesskey());
+    } else if ($qid = optional_param('q', 0, PARAM_INTEGER)) {
+        if (!$cm = get_coursemodule_from_instance('quiz', $qid)) {
+            print_error('invalidquizid', 'quiz');
+        }
+        redirect($CFG->wwwroot . '/mod/quiz/startattempt.php?cmid=' . $cm->id . '&sesskey=' . sesskey());
+    }
+
+/// Remember the current time as the time any responses were submitted
 /// (so as to make sure students don't get penalized for slow processing on this page)
     $timenow = time();
 
index 588a477d15c5ff67392ebf9220dd2c49713a504c..30f4d8455a6fd4095e6131ce785b04ebcc1e9458 100644 (file)
@@ -58,7 +58,7 @@
 
     if (!has_capability('mod/quiz:viewreports', $context)) {
         if (!$attempt->timefinish) {
-            redirect('attempt.php?q='.$quiz->id);
+            redirect('attempt.php?attempt='.$attempt->id);
         }
         // If not even responses are to be shown in review then we
         // don't allow any review
index 7c9f9e25e95dcdc41535e7607bf121b51df8d069..e881d75cb861102bd81f2e518066801a2935c4f7 100644 (file)
@@ -28,8 +28,11 @@ if (!$quiz = $DB->get_record('quiz', array('id' => $cm->instance))) {
 
 $quizobj = new quiz($quiz, $cm, $course);
 
-/// Check login and get contexts.
+/// Check login and sesskey.
 require_login($quizobj->get_courseid(), false, $quizobj->get_cm());
+if (!confirm_sesskey()) {
+    throw new moodle_exception('confirmsesskeybad', 'error', $quizobj->view_url());
+}
 
 /// if no questions have been set up yet redirect to edit.php
 if (!$quizobj->get_question_ids() && $quizobj->has_capability('mod/quiz:manage')) {
@@ -42,14 +45,6 @@ if ($quizobj->is_preview_user() && $forcenew) {
     $accessmanager->clear_password_access();
 }
 
-// This page should only respond to post requests, if not, redirect to the view page.
-// However, becuase 'secure' mode opens in a new window, we cannot do enforce this rule for them.
-if (!data_submitted() && !$accessmanager->securewindow_required($quizobj->is_preview_user())) {
-    $accessmanager->back_to_view_page($quizobj->is_preview_user());
-}
-if (!confirm_sesskey()) {
-    throw new moodle_exception('confirmsesskeybad', 'error', $quizobj->view_url());
-}
 
 /// Check capabilites.
 if (!$quizobj->is_preview_user()) {
@@ -109,11 +104,11 @@ if (!$attempt->id = $DB->insert_record('quiz_attempts', $attempt)) {
 
 /// Log the new attempt.
 if ($attempt->preview) {
-    add_to_log($course->id, 'quiz', 'preview', "attempt.php?id=$cm->id",
-            "$quiz->id", $cm->id);
+    add_to_log($course->id, 'quiz', 'preview', 'view.php?id=' . $quizobj->get_cmid(),
+            $quizobj->get_quizid(), $quizobj->get_cmid());
 } else {
-    add_to_log($course->id, 'quiz', 'attempt', "review.php?attempt=$attempt->id",
-            "$quiz->id", $cm->id);
+    add_to_log($course->id, 'quiz', 'attempt', 'review.php?attempt=' . $attempt->id,
+            $quizobj->get_quizid(), $quizobj->get_cmid());
 }
 
 /// Fully load all the questions in this quiz.
index 3b6a0231318638fe93c51673ffb10e6e69f6e277..456a043f0fa8ff0e9fb0b611cc7c8590cbeca3a9 100644 (file)
@@ -38,7 +38,7 @@ if (has_capability('mod/quiz:viewreports', $context)) {
     $row[] = new tabobject('reports', "$CFG->wwwroot/mod/quiz/report.php?q=$quiz->id", get_string('results', 'quiz'));
 }
 if (has_capability('mod/quiz:preview', $context)) {
-    $row[] = new tabobject('preview', "$CFG->wwwroot/mod/quiz/attempt.php?q=$quiz->id", get_string('preview', 'quiz'));
+    $row[] = new tabobject('preview', "$CFG->wwwroot/mod/quiz/startattempt.php?q=$quiz->id", get_string('preview', 'quiz'));
 }
 if (has_capability('mod/quiz:manage', $context)) {
     $row[] = new tabobject('edit', "$CFG->wwwroot/mod/quiz/edit.php?cmid=$cm->id", get_string('edit'));