diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php
index 5ce4586f154..9b028be215d 100644
--- a/mod/lesson/lib.php
+++ b/mod/lesson/lib.php
@@ -207,49 +207,6 @@ function lesson_update_instance($lesson) {
}
add_event($event);
-
- if (!empty($lesson->deleteattempts)) {
- $subject = "Delete User Attempts";
- $message = "";
-
- if ($userid = get_field("user", "id", "username", $lesson->deleteattempts)) {
- if (delete_records("lesson_attempts", "lessonid", $lesson->id, "userid", $userid)) {
- // email good
- $message .= "Successfully deleted attempts from \"".format_string($lesson->name)."\" lesson!
";
- } else {
- // email couldnt delete
- $message .= "Failed to delete attempts from \"".format_string($lesson->name)."\" lesson!
";
- }
- if (delete_records("lesson_grades", "lessonid", $lesson->id, "userid", $userid)) {
- // email good
- $message .= "Successfully deleted grades from \"".format_string($lesson->name)."\" lesson!
";
- } else {
- // email couldnt delete
- $message .= "Failed to delete grades from \"".format_string($lesson->name)."\" lesson!
";
- }
- if (delete_records("lesson_timer", "lessonid", $lesson->id, "userid", $userid)) {
- // email good
- $message .= "Successfully deleted time records from \"".format_string($lesson->name)."\" lesson!
";
- } else {
- // email couldnt delete
- $message .= "Failed to delete time records from \"".format_string($lesson->name)."\" lesson!
";
- }
-
- } else {
- // email couldnt find user
- $message .= "Could not find user in database.
";
- }
- $message .= "
User ID used: $lesson->deleteattempts
";
-
- $txt = format_text_email($message, FORMAT_HTML);
-
- if ($currentuser = get_record("user", "id", $lesson->deleteattemptsid)) {
- email_to_user($currentuser, $currentuser, $subject, $txt, $message);
- }
- // unset lessondefault
- }
- unset($lesson->deleteattempts);
- unset($lesson->deleteattemptsid);
return update_record("lesson", $lesson);
}
diff --git a/mod/lesson/mod.html b/mod/lesson/mod.html
index 120f6ce6f6b..0e4a061b3e1 100644
--- a/mod/lesson/mod.html
+++ b/mod/lesson/mod.html
@@ -626,20 +626,6 @@ if ($form->mode == "add") {
?>
-mode != "add") {
-?>
-
- | : |
-
-
-
-
- |
-
-mode != "add") {
-?>
diff --git a/mod/lesson/report.php b/mod/lesson/report.php
index 00d1f3a35ea..43ed1973731 100644
--- a/mod/lesson/report.php
+++ b/mod/lesson/report.php
@@ -24,10 +24,6 @@
error('Course module is incorrect');
}
- if (! $attempts = get_records('lesson_attempts', 'lessonid', $lesson->id, 'timeseen')) {
- $nothingtodisplay = true;
- }
-
if (! $students = get_records_sql("SELECT DISTINCT u.*
FROM {$CFG->prefix}user u,
{$CFG->prefix}lesson_attempts a
@@ -37,6 +33,54 @@
$nothingtodisplay = true;
}
+/// Process any form data before fetching attempts, grades and times
+ if ($form = data_submitted()) {
+ confirm_sesskey();
+
+ /// Cycle through array of userids with nested arrays of tries
+ foreach ($form->attempts as $userid => $tries) {
+ // Modifier IS VERY IMPORTANT! What does it do?
+ // Well, it is for when you delete multiple attempts for the same user.
+ // If you delete try 1 and 3 for a user, then after deleting try 1, try 3 then
+ // becomes try 2 (because try 1 is gone and all tries after try 1 get decremented).
+ // So, the modifier makes sure that the submitted try refers to the current try in the
+ // database - hope this all makes sense :)
+ $modifier = 0;
+
+ foreach ($tries as $try => $junk) {
+ $try -= $modifier;
+
+ /// Clean up the timer table
+ $timeid = get_field_sql("SELECT id FROM {$CFG->prefix}lesson_timer
+ WHERE userid = $userid AND lessonid = $lesson->id
+ ORDER BY starttime ".sql_paging_limit($try, 1));
+
+ delete_records('lesson_timer', 'id', $timeid);
+
+ /// Remove the grade from the grades and high_scores tables
+ $gradeid = get_field_sql("SELECT id FROM {$CFG->prefix}lesson_grades
+ WHERE userid = $userid AND lessonid = $lesson->id
+ ORDER BY completed ".sql_paging_limit($try, 1));
+
+ delete_records('lesson_grades', 'id', $gradeid);
+ delete_records('lesson_high_scores', 'gradeid', $gradeid, 'lessonid', $lesson->id, 'userid', $userid);
+
+ /// Remove attempts and update the retry number
+ delete_records('lesson_attempts', 'userid', $userid, 'lessonid', $lesson->id, 'retry', $try);
+ execute_sql("UPDATE {$CFG->prefix}lesson_attempts SET retry = retry - 1 WHERE userid = $userid AND lessonid = $lesson->id AND retry > $try", false);
+
+ /// Remove seen branches and update the retry number
+ delete_records('lesson_branch', 'userid', $userid, 'lessonid', $lesson->id, 'retry', $try);
+ execute_sql("UPDATE {$CFG->prefix}lesson_branch SET retry = retry - 1 WHERE userid = $userid AND lessonid = $lesson->id AND retry > $try", false);
+
+ $modifier++;
+ }
+ }
+ }
+
+ if (! $attempts = get_records('lesson_attempts', 'lessonid', $lesson->id, 'timeseen')) {
+ $nothingtodisplay = true;
+ }
if (! $grades = get_records('lesson_grades', 'lessonid', $lesson->id, 'completed')) {
$grades = array();
@@ -177,8 +221,9 @@
$tries = $studentdata[$student->id];
$studentname = "{$student->lastname}, $student->firstname";
foreach ($tries as $try) {
- // start to build up the link
- $temp = "id&action=detail&userid=".$try["userid"]."&try=".$try["try"]."\">";
+ // start to build up the checkbox and link
+ $temp = ' '.
+ "id&action=detail&userid=".$try['userid'].'&try='.$try['try'].'">';
if ($try["grade"] !== NULL) { // if NULL then not done yet
// this is what the link does when the user has completed the try
$timetotake = $try["timeend"] - $try["timestart"];
@@ -225,7 +270,22 @@
}
}
// print it all out !
+ echo "';
// some stat calculations
if ($numofattempts == 0) {
diff --git a/mod/lesson/view.php b/mod/lesson/view.php
index 6431b0a7a13..68f9a792e0c 100644
--- a/mod/lesson/view.php
+++ b/mod/lesson/view.php
@@ -1927,7 +1927,7 @@
print_heading(get_string("topscorestitle", "lesson", $lesson->maxhighscores), 'center', 4);
if (!$highscores = get_records_select("lesson_high_scores", "lessonid = $lesson->id")) {
- echo get_string("nohighscores", "lesson")."
";
+ print_heading(get_string("nohighscores", "lesson"), 'center', 3);
} else {
foreach ($highscores as $highscore) {
$grade = $grades[$highscore->gradeid]->grade;