From: tjhunt Date: Wed, 5 Mar 2008 10:16:18 +0000 (+0000) Subject: MDL-13794 - Reordering tool does not work if you type the same number into two boxes. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=758c50b1cdeebcba9bc7cc437fdcfd35c9804916;p=moodle.git MDL-13794 - Reordering tool does not work if you type the same number into two boxes. Also, fix some javascript that did not work in IE7. --- diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index d50dd2fc3f..76f2384c2f 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -238,13 +238,21 @@ $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]; } } diff --git a/mod/quiz/editlib.php b/mod/quiz/editlib.php index 693c166fb2..3598117835 100644 --- a/mod/quiz/editlib.php +++ b/mod/quiz/editlib.php @@ -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');