]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13794 - Reordering tool does not work if you type the same number into two boxes.
authortjhunt <tjhunt>
Wed, 5 Mar 2008 10:16:18 +0000 (10:16 +0000)
committertjhunt <tjhunt>
Wed, 5 Mar 2008 10:16:18 +0000 (10:16 +0000)
Also, fix some javascript that did not work in IE7.

mod/quiz/edit.php
mod/quiz/editlib.php

index d50dd2fc3fdfd982b5b4b7831b15d468688a3982..76f2384c2f6290314f5d14180132736d6b361fb4 100644 (file)
         $questions = array(); // for questions in the new order
         $rawgrades = $_POST;
         unset($quiz->grades);
-        foreach ($rawgrades as $key => $value) {    // Parse input for question -> grades
+        foreach ($rawgrades as $key => $value) {
+        /// Parse input for question -> grades
             if (preg_match('!^q([0-9]+)$!', $key, $matches)) {
                 $key = $matches[1];
                 $quiz->grades[$key] = $value;
                 quiz_update_question_instance($quiz->grades[$key], $key, $quiz->instance);
-            } elseif (preg_match('!^o([0-9]+)$!', $key, $matches)) {   // Parse input for ordering info
+
+            /// Parse input for ordering info
+            } elseif (preg_match('!^o([0-9]+)$!', $key, $matches)) {
                 $key = $matches[1];
+                // Make sure two questions don't overwrite each other. If we get a second
+                // question with the same position, shift the second one along to the next gap.
+                while (array_key_exists($value, $questions)) {
+                    $value++;
+                }
                 $questions[$value] = $oldquestions[$key];
             }
         }
index 693c166fb29a9a8c71489fc24c3844f276426549..3598117835eb17e95211f6888c9dce473f3829c9 100644 (file)
@@ -331,7 +331,7 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete=true, $showbreak
     if ($showbreaks) {
         echo ' checked="checked"';
     }
-    echo ' onchange="getElementById(\'showbreaks\').submit(); return true;" />';
+    echo ' onclick="form.submit(); return true;" />';
     print_string('showbreaks', 'quiz');
 
     if ($showbreaks) {
@@ -350,7 +350,7 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete=true, $showbreak
     if ($reordertool) {
         echo ' checked="checked"';
     }
-    echo ' onchange="getElementById(\'showbreaks\').submit(); return true;" />';
+    echo ' onclick="form.submit(); return true;" />';
     print_string('reordertool', 'quiz');
     echo ' ';
     helpbutton('reorderingtool', get_string('reordertool', 'quiz'), 'quiz');