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();
$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')) {
$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()) {
/// 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.
$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'));