2 require_once("../../config.php");
3 require_once("lib.php");
8 $attemptid = required_param("attemptid");
9 if (is_numeric($attemptid)) {
11 if (! $attempt = get_record("hotpot_attempts", "id", $attemptid)) {
12 error("Hot Potatoes attempt record $attemptid could not be accessed: ".$db->ErrorMsg());
15 // Check this is the right user
16 if ($attempt->userid
!= $USER->id
) {
17 error("Incorrect user id");
20 // get hotpot, course and course_module records
21 if (! $hotpot = get_record("hotpot", "id", $attempt->hotpot
)) {
22 error("Hot Potatoes ID is incorrect (attempt id = $attempt->id)");
24 if (! $course = get_record("course", "id", $hotpot->course
)) {
25 error("Course ID is incorrect (hotpot id = $hotpot->id)");
27 if (! $cm = get_coursemodule_from_instance("hotpot", $hotpot->id
, $course->id
)) {
28 error("Course Module ID is incorrect");
31 $next_url = "$CFG->wwwroot/course/view.php?id=$course->id";
33 // make sure this user is enrolled in this course
34 require_login($course->id
);
36 if ($attempt->timefinish
&& false) {
38 $msg = 'This attempt has already been submitted';
42 $msg = get_string('resultssaved', 'hotpot');
44 $attempt->score
= isset($_POST['mark']) ?
$_POST['mark'] : NULL;
45 $attempt->details
= isset($_POST['detail']) ?
$_POST['detail'] : NULL;
46 $attempt->endtime
= isset($_POST['endtime']) ?
strtotime($_POST['endtime']) : NULL;
47 $attempt->starttime
= isset($_POST['starttime']) ?
strtotime($_POST['starttime']) : NULL;
48 $attempt->timefinish
= $time;
50 // for the rare case where a quiz was "in progress" during an update from hotpot v1 to v2
51 if (empty($attempt->timestart
) && !empty($attempt->starttime
)) {
52 $attempt->timestart
= $attempt->starttime
;
55 // remove slashes added by lib/setup.php
56 $attempt->details
= stripslashes($attempt->details
);
58 // add details of this attempt
59 hotpot_add_attempt_details($attempt);
61 // add slashes again, so the details can be added to the database
62 $attempt->details
= addslashes($attempt->details
);
64 if (! update_record("hotpot_attempts", $attempt)) {
65 error("Could not update attempt record: ".$db->ErrorMsg(), $next_url);
68 // set previously unfinished attempts of this quiz by this user to "finished"
69 hotpot_close_previous_attempts($hotpot->id
, $USER->id
, $time);
71 add_to_log($course->id
, "hotpot", "submit", "review.php?id=$cm->id&attempt=$attempt->id", "$hotpot->id", "$cm->id");
73 if ($hotpot->shownextquiz
==HOTPOT_YES
&& is_numeric($next_cm = hotpot_get_next_cm($cm))) {
74 $next_url = "$CFG->wwwroot/mod/hotpot/view.php?id=$next_cm";
78 // redirect to the next quiz or the course page
79 redirect($next_url, $msg);
86 function hotpot_get_next_cm(&$cm) {
87 // gets the next module in this section of the course
88 // that is the same type of module as the current module
92 // get a list of $ids of modules in this section
93 if ($ids = get_field('course_sections', 'sequence', 'id', $cm->section
)) {
95 $ids = explode(',', $ids);
97 foreach ($ids as $id) {
98 if ($found && ($cm->module
==get_field('course_modules', 'module', 'id', $id))) {
101 } else if ($cm->id
==$id) {