From: moodler Date: Thu, 5 Aug 2004 05:31:40 +0000 (+0000) Subject: No checking is now done on question name and question text. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=01d11b97d95d61b4f7c13223c4bd38d18ad4cc5d;p=moodle.git No checking is now done on question name and question text. 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. --- diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 969e15728d..ad8a1c6c08 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -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, diff --git a/mod/quiz/question.php b/mod/quiz/question.php index c5cdfa376e..ad4ea871f0 100644 --- a/mod/quiz/question.php +++ b/mod/quiz/question.php @@ -156,20 +156,6 @@ $defaultformat = FORMAT_MOODLE; } - echo ''."\n\n"; - - $onsubmit = ' onSubmit="return validatequestion();" '; - require('questiontypes/'.$QUIZ_QTYPES[$qtype]->name().'/editquestion.php'); if ($usehtmleditor) { @@ -178,17 +164,4 @@ 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; -} - ?> diff --git a/mod/quiz/questiontypes/calculated/calculated.html b/mod/quiz/questiontypes/calculated/calculated.html index f3c27a406e..e454bf00be 100644 --- a/mod/quiz/questiontypes/calculated/calculated.html +++ b/mod/quiz/questiontypes/calculated/calculated.html @@ -1,4 +1,4 @@ -
action="question.php"> +
");} ?> diff --git a/mod/quiz/questiontypes/datasetdependent/questiondatasets.html b/mod/quiz/questiontypes/datasetdependent/questiondatasets.html index 3493c6b397..df30a54570 100644 --- a/mod/quiz/questiontypes/datasetdependent/questiondatasets.html +++ b/mod/quiz/questiontypes/datasetdependent/questiondatasets.html @@ -1,4 +1,4 @@ - action="question.php"> +
diff --git a/mod/quiz/questiontypes/description/description.html b/mod/quiz/questiontypes/description/description.html index e07fcd5340..5b54d0fe94 100644 --- a/mod/quiz/questiontypes/description/description.html +++ b/mod/quiz/questiontypes/description/description.html @@ -1,4 +1,4 @@ - action="question.php"> +
diff --git a/mod/quiz/questiontypes/match/match.html b/mod/quiz/questiontypes/match/match.html index ee6ec58226..7705283967 100644 --- a/mod/quiz/questiontypes/match/match.html +++ b/mod/quiz/questiontypes/match/match.html @@ -1,4 +1,4 @@ - action="question.php"> +
diff --git a/mod/quiz/questiontypes/multianswer/multianswer.html b/mod/quiz/questiontypes/multianswer/multianswer.html index 46864f2982..bf2faf0311 100644 --- a/mod/quiz/questiontypes/multianswer/multianswer.html +++ b/mod/quiz/questiontypes/multianswer/multianswer.html @@ -1,4 +1,4 @@ - action="question.php"> +
diff --git a/mod/quiz/questiontypes/multichoice/multichoice.html b/mod/quiz/questiontypes/multichoice/multichoice.html index a7a6473e24..9152438ccd 100644 --- a/mod/quiz/questiontypes/multichoice/multichoice.html +++ b/mod/quiz/questiontypes/multichoice/multichoice.html @@ -1,4 +1,4 @@ - action="question.php"> +
diff --git a/mod/quiz/questiontypes/numerical/numerical.html b/mod/quiz/questiontypes/numerical/numerical.html index 68aaa1aa38..44af895926 100644 --- a/mod/quiz/questiontypes/numerical/numerical.html +++ b/mod/quiz/questiontypes/numerical/numerical.html @@ -1,4 +1,4 @@ - action="question.php"> +
diff --git a/mod/quiz/questiontypes/random/random.html b/mod/quiz/questiontypes/random/random.html index 6daad2a5d0..8c453bc4be 100644 --- a/mod/quiz/questiontypes/random/random.html +++ b/mod/quiz/questiontypes/random/random.html @@ -1,5 +1,5 @@
- action="question.php"> +
diff --git a/mod/quiz/questiontypes/randomsamatch/randomsamatch.html b/mod/quiz/questiontypes/randomsamatch/randomsamatch.html index 5a47858fef..8601db1ab1 100644 --- a/mod/quiz/questiontypes/randomsamatch/randomsamatch.html +++ b/mod/quiz/questiontypes/randomsamatch/randomsamatch.html @@ -1,4 +1,4 @@ - action="question.php"> +
diff --git a/mod/quiz/questiontypes/shortanswer/shortanswer.html b/mod/quiz/questiontypes/shortanswer/shortanswer.html index 06b2458e66..446f4dadf0 100644 --- a/mod/quiz/questiontypes/shortanswer/shortanswer.html +++ b/mod/quiz/questiontypes/shortanswer/shortanswer.html @@ -1,4 +1,4 @@ - action="question.php"> +
diff --git a/mod/quiz/questiontypes/truefalse/truefalse.html b/mod/quiz/questiontypes/truefalse/truefalse.html index 1b5874cc31..30becfb1b5 100644 --- a/mod/quiz/questiontypes/truefalse/truefalse.html +++ b/mod/quiz/questiontypes/truefalse/truefalse.html @@ -1,4 +1,4 @@ - action="question.php"> +