]> git.mjollnir.org Git - moodle.git/commitdiff
Caters for the case when nothing was selected
authormoodler <moodler>
Wed, 4 Feb 2004 13:40:20 +0000 (13:40 +0000)
committermoodler <moodler>
Wed, 4 Feb 2004 13:40:20 +0000 (13:40 +0000)
lang/en/choice.php
mod/choice/view.php

index 9937c5ca23022aed88ae863f5e5a13a871afcfe1..662a22815c194cfa9c12ecef184f5b3438f474eb 100644 (file)
@@ -8,6 +8,7 @@ $string['choicename'] = 'Choice name';
 $string['choicetext'] = 'Choice text';
 $string['modulename'] = 'Choice';
 $string['modulenameplural'] = 'Choices';
+$string['mustchooseone'] = 'You must choose an answer before saving.  Nothing was saved.';
 $string['notanswered'] = 'Not answered yet';
 $string['publish'] = 'Publish results';
 $string['publishanonymous'] = 'Publish anonymous results, do not show student names';
index 9bc612b923dd6055f25ee953e820638816cc27fb..d6ec67249e8560c647c49fb0751ab13d8c596c28 100644 (file)
     }
 
     for ($i=1; $i <= $CHOICE_MAX_NUMBER; $i++) {
-        $answerchecked[$i] = "";
+        $answerchecked[$i] = '';
     }
     if ($current = get_record("choice_answers", "choice", $choice->id, "userid", $USER->id)) {
-        $answerchecked[$current->answer] = "CHECKED";
+        $answerchecked[$current->answer] = 'CHECKED';
     }
 
     if ($form = data_submitted()) {
         $timenow = time();
-        if ($current) {
-            $newanswer = $current;
-            $newanswer->answer = $form->answer;
-            $newanswer->timemodified = $timenow;
-            if (! update_record("choice_answers", $newanswer)) {
-                error("Could not update your choice");
-            }
-            add_to_log($course->id, "choice", "update", "view.php?id=$cm->id", $choice->id, $cm->id);
+
+        if (empty($form->answer)) {
+            redirect("view.php?id=$cm->id", get_string('mustchooseone', 'choice'));
+
         } else {
-            $newanswer->choice = $choice->id;
-            $newanswer->userid = $USER->id;
-            $newanswer->answer = $form->answer;
-            $newanswer->timemodified = $timenow;
-            if (! insert_record("choice_answers", $newanswer)) {
-                error("Could not save your choice");
+            if ($current) {
+                $newanswer = $current;
+                $newanswer->answer = $form->answer;
+                $newanswer->timemodified = $timenow;
+                if (! update_record("choice_answers", $newanswer)) {
+                    error("Could not update your choice");
+                }
+                add_to_log($course->id, "choice", "update", "view.php?id=$cm->id", $choice->id, $cm->id);
+            } else {
+                $newanswer->choice = $choice->id;
+                $newanswer->userid = $USER->id;
+                $newanswer->answer = $form->answer;
+                $newanswer->timemodified = $timenow;
+                if (! insert_record("choice_answers", $newanswer)) {
+                    error("Could not save your choice");
+                }
+                add_to_log($course->id, "choice", "add", "view.php?id=$cm->id", $choice->id, $cm->id);
             }
-            add_to_log($course->id, "choice", "add", "view.php?id=$cm->id", $choice->id, $cm->id);
         }
         redirect("$CFG->wwwroot/course/view.php?id=$course->id");
         exit;