]> git.mjollnir.org Git - moodle.git/commitdiff
No checking is now done on question name and question text.
authormoodler <moodler>
Thu, 5 Aug 2004 05:31:40 +0000 (05:31 +0000)
committermoodler <moodler>
Thu, 5 Aug 2004 05:31:40 +0000 (05:31 +0000)
If question name is empty, then it's assigned to be same as the question text.

The question text can now be empty if people want that.

13 files changed:
mod/quiz/lib.php
mod/quiz/question.php
mod/quiz/questiontypes/calculated/calculated.html
mod/quiz/questiontypes/datasetdependent/questiondatasets.html
mod/quiz/questiontypes/description/description.html
mod/quiz/questiontypes/match/match.html
mod/quiz/questiontypes/multianswer/multianswer.html
mod/quiz/questiontypes/multichoice/multichoice.html
mod/quiz/questiontypes/numerical/numerical.html
mod/quiz/questiontypes/random/random.html
mod/quiz/questiontypes/randomsamatch/randomsamatch.html
mod/quiz/questiontypes/shortanswer/shortanswer.html
mod/quiz/questiontypes/truefalse/truefalse.html

index 969e15728ddc0f5d96ea5417e5fa4f4d200fd0a2..ad8a1c6c0821619ab0785d0a3f7eba7b5622b5f8 100644 (file)
@@ -81,16 +81,13 @@ class quiz_default_questiontype {
     }
 
     function save_question($question, $form, $course) {
-        // As this function uses formcheck, it can only be used by
-        // question.php
-        
         // This default implementation is suitable for most
         // question types.
         
         // First, save the basic question itself
 
-        $question->name               = $form->name;
-        $question->questiontext       = $form->questiontext;
+        $question->name               = trim($form->name);
+        $question->questiontext       = trim($form->questiontext);
         $question->questiontextformat = $form->questiontextformat;
 
         if (empty($form->image)) {
@@ -99,52 +96,53 @@ class quiz_default_questiontype {
             $question->image = $form->image;
         }
 
+        if (empty($question->name)) {
+            $question->name = strip_tags($question->questiontext);
+            if (empty($question->name)) {
+                $question->name = '-';
+            }
+        }
+
         if (isset($form->defaultgrade)) {
             $question->defaultgrade = $form->defaultgrade;
         }
 
-        if ($err = formcheck($question)) {
-            notify(get_string("someerrorswerefound"));
-
-        } else {
-
-            if (!empty($question->id)) { // Question already exists
-                $question->version ++;    // Update version number of question
-                if (!update_record("quiz_questions", $question)) {
-                    error("Could not update question!");
-                }
-            } else {         // Question is a new one
-                $question->stamp = make_unique_id_code();  // Set the unique code (not to be changed)
-                $question->version = 1;
-                if (!$question->id = insert_record("quiz_questions", $question)) {
-                    error("Could not insert new question!");
-                }
+        if (!empty($question->id)) { // Question already exists
+            $question->version ++;    // Update version number of question
+            if (!update_record("quiz_questions", $question)) {
+                error("Could not update question!");
             }
-    
-            // Now to save all the answers and type-specific options
+        } else {         // Question is a new one
+            $question->stamp = make_unique_id_code();  // Set the unique code (not to be changed)
+            $question->version = 1;
+            if (!$question->id = insert_record("quiz_questions", $question)) {
+                error("Could not insert new question!");
+            }
+        }
+   
+        // Now to save all the answers and type-specific options
 
-            $form->id       = $question->id;
-            $form->qtype    = $question->qtype;
-            $form->category = $question->category;
+        $form->id       = $question->id;
+        $form->qtype    = $question->qtype;
+        $form->category = $question->category;
 
-            $result = $this->save_question_options($form);
+        $result = $this->save_question_options($form);
 
-            if (!empty($result->error)) {
-                error($result->error);
-            }
+        if (!empty($result->error)) {
+            error($result->error);
+        }
 
-            if (!empty($result->notice)) {
-                notice($result->notice, "question.php?id=$question->id");
-            }
+        if (!empty($result->notice)) {
+            notice($result->notice, "question.php?id=$question->id");
+        }
 
-            if (!empty($result->noticeyesno)) {
-                notice_yesno($result->noticeyesno, "question.php?id=$question->id", "edit.php");
-                print_footer($course);
-                exit;
-            }
-    
-            redirect("edit.php");
+        if (!empty($result->noticeyesno)) {
+            notice_yesno($result->noticeyesno, "question.php?id=$question->id", "edit.php");
+            print_footer($course);
+            exit;
         }
+    
+        redirect("edit.php");
     }
     
     /// Convenience function that is used within the question types only
@@ -250,7 +248,7 @@ class quiz_default_questiontype {
                 ($currentnumber,
                  $quiz->grade ? $question->maxgrade : false,
                  empty($resultdetails) ? false : $resultdetails->grade,
-                 $question->recentlyadded);
+                 isset($question->recentlyadded) ? $question->recentlyadded : false);
         
         $this->print_question_formulation_and_controls(
                 $question, $quiz, $readonly, $resultdetails->answers,
index c5cdfa376ef562d4bf77ec624dac312d74c61260..ad4ea871f0cd2eee925769376b170db9af07e072 100644 (file)
         $defaultformat = FORMAT_MOODLE;
     }
 
-    echo '<script lang="Javascript">';
-    echo 'function validatequestion() {';
-    echo '  if (document.theform.name.value == "") {';
-    echo '    alert("'.get_string('specifyname').'");';
-    echo '    focus(document.theform.name.value);';
-    echo '    return false;';
-    echo '  } else {';
-    echo '    return true; ';
-    echo '  }';
-    echo '}';
-    echo '</script>'."\n\n";
-
-    $onsubmit = ' onSubmit="return validatequestion();" ';
-
     require('questiontypes/'.$QUIZ_QTYPES[$qtype]->name().'/editquestion.php');
 
     if ($usehtmleditor) { 
 
     print_footer($course);
 
-
-function formcheck($question) {
-   $err = array();
-
-   if (empty($question->name)) {
-       $err["name"] = get_string("missingname", "quiz");
-   }
-   if (empty($question->questiontext)) {
-       $err["questiontext"] = get_string("missingquestiontext", "quiz");
-   }
-   return $err;
-}
-
 ?>
index f3c27a406ea92b11b3821482bcd9d3c7dc5d230e..e454bf00be2ad9357c747d593743d452395c791b 100644 (file)
@@ -1,4 +1,4 @@
-<FORM name="theform" method="post" <?php echo $onsubmit ?> action="question.php">
+<FORM name="theform" method="post" action="question.php">
 <CENTER>
 <INPUT type="hidden" name="nextwizardpage" value="<?php p($nextwizardpage)?>"/>
 <?php foreach ($calculatedmessages as $message) {formerr("$message<br/>");} ?>
index 3493c6b39752f5c141f874b6c7d38153623cb175..df30a545702daafea0daec3ed626ffb5656b0899 100644 (file)
@@ -1,4 +1,4 @@
-<FORM name="theform" method="post" <?php echo $onsubmit ?> action="question.php">
+<FORM name="theform" method="post" action="question.php">
 <CENTER>
 <INPUT type="hidden" name="nextwizardpage" value="calculated.html"/>
 <TABLE cellpadding=5>
index e07fcd534079afdd063b93a70e5d1373c187b203..5b54d0fe94ed22f14bfa3d58e30388f8ddd61a18 100644 (file)
@@ -1,4 +1,4 @@
-<FORM name="theform" method="post" <?php echo $onsubmit ?> action="question.php">\r
+<FORM name="theform" method="post" action="question.php">\r
 <CENTER>\r
 <TABLE cellpadding=5>\r
 <TR valign=top>\r
index ee6ec58226e6dddb061dbe9ad765c37ff25ec22c..770528396717fdc893119953bc4a1a6fcb8dcf08 100644 (file)
@@ -1,4 +1,4 @@
-<FORM name="theform" method="post" <?php echo $onsubmit ?> action="question.php">\r
+<FORM name="theform" method="post" action="question.php">\r
 <CENTER>\r
 <TABLE cellpadding=5>\r
 <TR valign=top>\r
index 46864f29823a0391269c023f6da4e82c15c9ddd7..bf2faf03119e1d9248a1e763e731a14cfacf4ac5 100644 (file)
@@ -1,4 +1,4 @@
-<FORM name="theform" method="post" <?php echo $onsubmit ?> action="question.php">
+<FORM name="theform" method="post"  action="question.php">
 
 <CENTER>
 
index a7a6473e241b2d7be9e85bc0678cb06704ed9916..9152438ccd737bef65498acbee1d83116e416190 100644 (file)
@@ -1,4 +1,4 @@
-<FORM name="theform" method="post" <?php echo $onsubmit ?> action="question.php">\r
+<FORM name="theform" method="post" action="question.php">\r
 <CENTER>\r
 <TABLE cellpadding=5>\r
 <TR valign=top>\r
index 68aaa1aa383b7408fbf7b62f1919bd0276a1e89e..44af8959267f7b0096e6097d0b0890dd87f634bb 100644 (file)
@@ -1,4 +1,4 @@
-<FORM name="theform" method="post" <?php echo $onsubmit ?> action="question.php">
+<FORM name="theform" method="post" action="question.php">
 <CENTER>
 <TABLE cellpadding=5>
 <TR valign=top>
index 6daad2a5d0b889c33bd3a705565d411a3da1e56d..8c453bc4bea04041285fc257a9edd40a8974a02e 100644 (file)
@@ -1,5 +1,5 @@
 <center>\r
-<form name="theform" method="post" <?php echo $onsubmit ?> action="question.php">\r
+<form name="theform" method="post" action="question.php">\r
 \r
 <table cellpadding=5>\r
 <tr valign=top>\r
index 5a47858fef78596af2944f2d6c874d6e21007638..8601db1ab1aa8544a6e2f46650e5266dd9844c1c 100644 (file)
@@ -1,4 +1,4 @@
-<FORM name="theform" method="post" <?php echo $onsubmit ?> action="question.php">\r
+<FORM name="theform" method="post" action="question.php">\r
 <CENTER>\r
 <TABLE cellpadding=5>\r
 <TR valign=top>\r
index 06b2458e6640eda94326b82898a8a634ff13c20a..446f4dadf0b4cb39cbec993dbc0edf8a4eee03da 100644 (file)
@@ -1,4 +1,4 @@
-<FORM name="theform" method="post" <?php echo $onsubmit ?> action="question.php">\r
+<FORM name="theform" method="post" action="question.php">\r
 <CENTER>\r
 <TABLE cellpadding=5>\r
 <TR valign=top>\r
index 1b5874cc31222fa31479e9abe48a72d0cd9f28c1..30becfb1b5e3c75e58044383e594c1aac513b6b0 100644 (file)
@@ -1,4 +1,4 @@
-<FORM name="theform" method="post" <?php echo $onsubmit ?> action="question.php">\r
+<FORM name="theform" method="post" action="question.php">\r
 <CENTER>\r
 <TABLE cellpadding=5>\r
 <TR valign=top>\r