]> git.mjollnir.org Git - moodle.git/commitdiff
[Removed] the Delete user attempts option in the Lesson settings (changes to mod...
authormark-nielsen <mark-nielsen>
Sat, 29 Apr 2006 01:37:50 +0000 (01:37 +0000)
committermark-nielsen <mark-nielsen>
Sat, 29 Apr 2006 01:37:50 +0000 (01:37 +0000)
[Added] new functionality to report.php to delete individual student attempts
[Fixed] High scores text in view.php when no high scores were recorded needed to be centered

mod/lesson/lib.php
mod/lesson/mod.html
mod/lesson/report.php
mod/lesson/view.php

index 5ce4586f154f2235227e145cef411d7d80ee518f..9b028be215d71debaeb9dd34f7a89b4439c9ea65 100644 (file)
@@ -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!<br />";
-            } else {
-                // email couldnt delete
-                $message .= "Failed to delete attempts from \"".format_string($lesson->name)."\" lesson!<br />";
-            }
-            if (delete_records("lesson_grades", "lessonid", $lesson->id, "userid", $userid)) {
-                // email good
-                $message .= "Successfully deleted grades from \"".format_string($lesson->name)."\" lesson!<br />";
-            } else {
-                // email couldnt delete
-                $message .= "Failed to delete grades from \"".format_string($lesson->name)."\" lesson!<br />";
-            }
-            if (delete_records("lesson_timer", "lessonid", $lesson->id, "userid", $userid)) {
-                // email good
-                $message .= "Successfully deleted time records from \"".format_string($lesson->name)."\" lesson!<br />";
-            } else {
-                // email couldnt delete
-                $message .= "Failed to delete time records from \"".format_string($lesson->name)."\" lesson!<br />";
-            }
-
-        } else {
-            // email couldnt find user
-            $message .= "Could not find user in database.<br />";
-        }
-        $message .= "<br /> User ID used: $lesson->deleteattempts <br />";
-        
-        $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);
 }
index 120f6ce6f6b9ee2c7250dec31e8568c2061c26a7..0e4a061b3e1212767693426b637a3eff31ce1734 100644 (file)
@@ -626,20 +626,6 @@ if ($form->mode == "add") {
     ?>
     </td>
 </tr>
-<?php 
-    if ($form->mode != "add") {
-?>
-<tr>
-    <td align="right"><b><?php  print_string("deleteattempts", "lesson"); ?>:</b></td>
-    <td>
-        <input type="text" name="deleteattempts" size="7" value="" />
-        <?php helpbutton("deleteattempts", get_string("deleteattempts", "lesson"), "lesson"); ?>
-        <input type="hidden" name="deleteattemptsid" value="<?php echo $USER->id; ?>" />
-    </td>
-</tr>
-<?php
-    }  // end if statement  if ($form->mode != "add") {
-?>
 <?php print_visible_setting($form); ?>
 </table>
 <!-- These hidden variables are always the same -->
index 00d1f3a35ead0b85e7d698c5185268c0ec22f36f..43ed19737311374fe237ec62459c1276160a6025 100644 (file)
         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
         $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();
                 $tries = $studentdata[$student->id];
                 $studentname = "{$student->lastname},&nbsp;$student->firstname";
                 foreach ($tries as $try) {
-                // start to build up the link
-                    $temp = "<a href=\"report.php?id=$cm->id&amp;action=detail&amp;userid=".$try["userid"]."&amp;try=".$try["try"]."\">";
+                // start to build up the checkbox and link
+                    $temp = '<input type="checkbox" id="attempts" name="attempts['.$try['userid'].']['.$try['try'].']" /> '.
+                            "<a href=\"report.php?id=$cm->id&amp;action=detail&amp;userid=".$try['userid'].'&amp;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"];
             }
         }
         // print it all out !
+        echo  "<form id=\"theform\" name=\"theform\" method=\"post\" action=\"report.php\">\n
+               <input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />\n
+               <input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n
+               <input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
+        
         print_table($table);
+        
+        echo '<br /><table width="90%" align="center"><tr><td>'.
+             '<a href="javascript: checkall();">'.get_string('selectall').'</a> / '.
+             '<a href="javascript: checknone();">'.get_string('deselectall').'</a> ';
+             
+        $options = array();
+        $options['delete'] = get_string('deleteselected');
+        choose_from_menu($options, 'attemptaction', 0, 'choose', 'submitFormById(\'theform\')');
+        
+        echo '</td></tr></table></form>';
 
         // some stat calculations
         if ($numofattempts == 0) {
index 6431b0a7a13f31c4b6aa32a49ddd058ae2f229a5..68f9a792e0c2cbbb9991570eaef494cdf91f2294 100644 (file)
         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")."<br>";
+            print_heading(get_string("nohighscores", "lesson"), 'center', 3);
         } else {
             foreach ($highscores as $highscore) {
                 $grade = $grades[$highscore->gradeid]->grade;