From 11c6232781173d39f057c3e2055b6d58d6dabd43 Mon Sep 17 00:00:00 2001 From: moodler Date: Thu, 29 Jul 2004 06:15:54 +0000 Subject: [PATCH] Some cleanups with formatting and so on. --- mod/quiz/lib.php | 2 +- mod/quiz/question.php | 29 ++++++++++-- .../description/description.html | 7 +-- .../description/editquestion.php | 4 +- mod/quiz/questiontypes/match/editquestion.php | 43 +++++++++--------- mod/quiz/questiontypes/match/match.html | 7 +-- .../multianswer/multianswer.html | 11 ----- .../multichoice/editquestion.php | 43 +++++++++--------- .../multichoice/multichoice.html | 7 +-- .../questiontypes/numerical/editquestion.php | 42 +++++++++--------- .../questiontypes/numerical/numerical.html | 8 +--- .../questiontypes/random/editquestion.php | 4 +- mod/quiz/questiontypes/random/random.html | 2 +- .../randomsamatch/editquestion.php | 16 +++---- .../randomsamatch/randomsamatch.html | 7 +-- .../shortanswer/editquestion.php | 40 ++++++++--------- .../shortanswer/shortanswer.html | 7 +-- .../questiontypes/truefalse/editquestion.php | 44 +++++++++---------- .../questiontypes/truefalse/truefalse.html | 7 +-- 19 files changed, 153 insertions(+), 177 deletions(-) diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 52d7e86e06..ac805f7291 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -284,7 +284,7 @@ function quiz_load_questiontypes() { $qtypenames= get_list_of_plugins('mod/quiz/questiontypes'); foreach($qtypenames as $qtypename) { // Instanciates all plug-in question types - $qtypefilepath= "questiontypes/$qtypename/questiontype.php"; + $qtypefilepath= "$CFG->dirroot/mod/quiz/questiontypes/$qtypename/questiontype.php"; // echo "Loading $qtypename
"; // Uncomment for debugging if (is_readable($qtypefilepath)) { diff --git a/mod/quiz/question.php b/mod/quiz/question.php index c37982c244..c5cdfa376e 100644 --- a/mod/quiz/question.php +++ b/mod/quiz/question.php @@ -42,6 +42,12 @@ error("Must specify question id or category"); } + if (empty($qtype)) { + error("No question type was specified!"); + } else if (!isset($QUIZ_QTYPES[$qtype])) { + error("Could not find question type: '$qtype'"); + } + require_login($course->id); if (!isteacheredit($course->id)) { @@ -99,8 +105,7 @@ } if ($form = data_submitted()) { - $question = $QUIZ_QTYPES[$qtype]->save_question($question, - $form, $course); + $question = $QUIZ_QTYPES[$qtype]->save_question($question, $form, $course); } $grades = array(1,0.9,0.8,0.75,0.70,0.66666,0.60,0.50,0.40,0.33333,0.30,0.25,0.20,0.16666,0.10,0.05,0); @@ -147,14 +152,30 @@ // Set up some Richtext editing if necessary if ($usehtmleditor = can_use_richtext_editor()) { $defaultformat = FORMAT_HTML; - $onsubmit = "onsubmit=\"copyrichtext(theform.questiontext);\""; } else { $defaultformat = FORMAT_MOODLE; - $onsubmit = ""; } + echo ''."\n\n"; + + $onsubmit = ' onSubmit="return validatequestion();" '; + require('questiontypes/'.$QUIZ_QTYPES[$qtype]->name().'/editquestion.php'); + if ($usehtmleditor) { + use_html_editor('questiontext'); + } + print_footer($course); diff --git a/mod/quiz/questiontypes/description/description.html b/mod/quiz/questiontypes/description/description.html index 38188b5bc5..e07fcd5340 100644 --- a/mod/quiz/questiontypes/description/description.html +++ b/mod/quiz/questiontypes/description/description.html @@ -37,7 +37,7 @@ print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext); - if ($usehtmleditor) { /// Trying this out for a while + if ($usehtmleditor) { echo ''; } else { echo "
"; @@ -73,8 +73,3 @@ - diff --git a/mod/quiz/questiontypes/description/editquestion.php b/mod/quiz/questiontypes/description/editquestion.php index cd5a89c1b0..4d7a67ee5f 100644 --- a/mod/quiz/questiontypes/description/editquestion.php +++ b/mod/quiz/questiontypes/description/editquestion.php @@ -1,6 +1,6 @@ diff --git a/mod/quiz/questiontypes/match/editquestion.php b/mod/quiz/questiontypes/match/editquestion.php index c10475181f..d6204f03a4 100644 --- a/mod/quiz/questiontypes/match/editquestion.php +++ b/mod/quiz/questiontypes/match/editquestion.php @@ -1,25 +1,26 @@ id)) { - $options = get_record("quiz_match", "question", $question->id); - if (!empty($options->subquestions)) { - $oldsubquestions = get_records_list("quiz_match_sub", "id", $options->subquestions); - } - } - if (empty($subquestions) and empty($subanswers)) { - for ($i=0; $iquestiontext; // insert questions into slots - $subanswers[$i] = $oldsubquestion->answertext; // insert answers into slots - $i++; - } - } + + if (!empty($question->id)) { + $options = get_record("quiz_match", "question", $question->id); + if (!empty($options->subquestions)) { + $oldsubquestions = get_records_list("quiz_match_sub", "id", $options->subquestions); + } + } + if (empty($subquestions) and empty($subanswers)) { + for ($i=0; $iquestiontext; // insert questions into slots + $subanswers[$i] = $oldsubquestion->answertext; // insert answers into slots + $i++; } - print_heading_with_help(get_string("editingmatch", "quiz"), "match", "quiz"); - require("match.html"); + } + } + print_heading_with_help(get_string("editingmatch", "quiz"), "match", "quiz"); + require("match.html"); ?> diff --git a/mod/quiz/questiontypes/match/match.html b/mod/quiz/questiontypes/match/match.html index 37327f015c..ee6ec58226 100644 --- a/mod/quiz/questiontypes/match/match.html +++ b/mod/quiz/questiontypes/match/match.html @@ -37,7 +37,7 @@ print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext); - if ($usehtmleditor) { /// Trying this out for a while + if ($usehtmleditor) { echo ''; } else { echo "
"; @@ -97,8 +97,3 @@ - diff --git a/mod/quiz/questiontypes/multianswer/multianswer.html b/mod/quiz/questiontypes/multianswer/multianswer.html index 4c3da4bbd2..46864f2982 100644 --- a/mod/quiz/questiontypes/multianswer/multianswer.html +++ b/mod/quiz/questiontypes/multianswer/multianswer.html @@ -101,14 +101,3 @@ - - - diff --git a/mod/quiz/questiontypes/multichoice/editquestion.php b/mod/quiz/questiontypes/multichoice/editquestion.php index d313938c03..224607002d 100644 --- a/mod/quiz/questiontypes/multichoice/editquestion.php +++ b/mod/quiz/questiontypes/multichoice/editquestion.php @@ -1,23 +1,24 @@ -id)) { - $options = get_record("quiz_multichoice", "question", $question->id); - } else { - $options->single = 1; - } - if (!empty($options->answers)) { - $answersraw = get_records_list("quiz_answers", "id", $options->answers); - } - for ($i=0; $iid)) { + $options = get_record("quiz_multichoice", "question", $question->id); + } else { + $options->single = 1; + } + if (!empty($options->answers)) { + $answersraw = get_records_list("quiz_answers", "id", $options->answers); + } + for ($i=0; $i diff --git a/mod/quiz/questiontypes/multichoice/multichoice.html b/mod/quiz/questiontypes/multichoice/multichoice.html index 5afb2566ba..a7a6473e24 100644 --- a/mod/quiz/questiontypes/multichoice/multichoice.html +++ b/mod/quiz/questiontypes/multichoice/multichoice.html @@ -37,7 +37,7 @@ print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext); - if ($usehtmleditor) { /// Trying this out for a while + if ($usehtmleditor) { echo ''; } else { echo "
"; @@ -117,8 +117,3 @@ - diff --git a/mod/quiz/questiontypes/numerical/editquestion.php b/mod/quiz/questiontypes/numerical/editquestion.php index 6d1ace119a..527b06f3e4 100644 --- a/mod/quiz/questiontypes/numerical/editquestion.php +++ b/mod/quiz/questiontypes/numerical/editquestion.php @@ -1,25 +1,25 @@ id)) { - $answersraw= quiz_get_answers($question); - } - $answers= array(); - for ($i=0; $i<6; $i++) { - $answers[$i]->answer = ""; // Make answer slots, default as blank... - $answers[$i]->min = ""; - $answers[$i]->max = ""; - $answers[$i]->feedback = ""; - } - if (!empty($answersraw)) { - $i=0; - foreach ($answersraw as $answer) { - $answers[$i] = $answer; - $i++; - } - } - print_heading_with_help(get_string("editingnumerical", "quiz"), "numerical", "quiz"); - require("numerical.html"); + // This will only support one answer of the type NUMERICAL + // However, lib.php has support for multiple answers + if (!empty($question->id)) { + $answersraw= quiz_get_answers($question); + } + $answers= array(); + for ($i=0; $i<6; $i++) { + $answers[$i]->answer = ""; // Make answer slots, default as blank... + $answers[$i]->min = ""; + $answers[$i]->max = ""; + $answers[$i]->feedback = ""; + } + if (!empty($answersraw)) { + $i=0; + foreach ($answersraw as $answer) { + $answers[$i] = $answer; + $i++; + } + } + print_heading_with_help(get_string("editingnumerical", "quiz"), "numerical", "quiz"); + require("numerical.html"); ?> diff --git a/mod/quiz/questiontypes/numerical/numerical.html b/mod/quiz/questiontypes/numerical/numerical.html index 2488599453..31daec18fd 100644 --- a/mod/quiz/questiontypes/numerical/numerical.html +++ b/mod/quiz/questiontypes/numerical/numerical.html @@ -37,7 +37,7 @@ print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext); - if ($usehtmleditor) { /// Trying this out for a while + if ($usehtmleditor) { echo ''; } else { echo "
"; @@ -133,9 +133,3 @@ function determineMinAndMax() { } } - - diff --git a/mod/quiz/questiontypes/random/editquestion.php b/mod/quiz/questiontypes/random/editquestion.php index b6737f31b3..1c67423c64 100644 --- a/mod/quiz/questiontypes/random/editquestion.php +++ b/mod/quiz/questiontypes/random/editquestion.php @@ -1,6 +1,6 @@ diff --git a/mod/quiz/questiontypes/random/random.html b/mod/quiz/questiontypes/random/random.html index 8c453bc4be..6daad2a5d0 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/editquestion.php b/mod/quiz/questiontypes/randomsamatch/editquestion.php index 4e89551b49..87045a9cab 100644 --- a/mod/quiz/questiontypes/randomsamatch/editquestion.php +++ b/mod/quiz/questiontypes/randomsamatch/editquestion.php @@ -1,11 +1,11 @@ id)) { - $options = get_record("quiz_randomsamatch", "question", $question->id); - } else { - $options->choose = ""; - } - $numberavailable = count_records("quiz_questions", "category", $category->id, "qtype", SHORTANSWER); - print_heading_with_help(get_string("editingrandomsamatch", "quiz"), "randomsamatch", "quiz"); - require("randomsamatch.html"); + if (!empty($question->id)) { + $options = get_record("quiz_randomsamatch", "question", $question->id); + } else { + $options->choose = ""; + } + $numberavailable = count_records("quiz_questions", "category", $category->id, "qtype", SHORTANSWER); + print_heading_with_help(get_string("editingrandomsamatch", "quiz"), "randomsamatch", "quiz"); + require("randomsamatch.html"); ?> diff --git a/mod/quiz/questiontypes/randomsamatch/randomsamatch.html b/mod/quiz/questiontypes/randomsamatch/randomsamatch.html index 197f78a39f..5a47858fef 100644 --- a/mod/quiz/questiontypes/randomsamatch/randomsamatch.html +++ b/mod/quiz/questiontypes/randomsamatch/randomsamatch.html @@ -44,7 +44,7 @@ } print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext); - if ($usehtmleditor) { /// Trying this out for a while + if ($usehtmleditor) { echo ''; } else { echo "
"; @@ -89,8 +89,3 @@ - diff --git a/mod/quiz/questiontypes/shortanswer/editquestion.php b/mod/quiz/questiontypes/shortanswer/editquestion.php index 3635b73ee1..670830ce32 100644 --- a/mod/quiz/questiontypes/shortanswer/editquestion.php +++ b/mod/quiz/questiontypes/shortanswer/editquestion.php @@ -1,23 +1,23 @@ id)) { - $options = get_record("quiz_shortanswer", "question", $question->id); - } else { - $options->usecase = 0; - } - if (!empty($options->answers)) { - $answersraw = get_records_list("quiz_answers", "id", $options->answers); - } - for ($i=0; $iid)) { + $options = get_record("quiz_shortanswer", "question", $question->id); + } else { + $options->usecase = 0; + } + if (!empty($options->answers)) { + $answersraw = get_records_list("quiz_answers", "id", $options->answers); + } + for ($i=0; $i diff --git a/mod/quiz/questiontypes/shortanswer/shortanswer.html b/mod/quiz/questiontypes/shortanswer/shortanswer.html index ce621449dc..06b2458e66 100644 --- a/mod/quiz/questiontypes/shortanswer/shortanswer.html +++ b/mod/quiz/questiontypes/shortanswer/shortanswer.html @@ -37,7 +37,7 @@ print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext); - if ($usehtmleditor) { /// Trying this out for a while + if ($usehtmleditor) { echo ''; } else { echo "
"; @@ -119,8 +119,3 @@ - diff --git a/mod/quiz/questiontypes/truefalse/editquestion.php b/mod/quiz/questiontypes/truefalse/editquestion.php index c98f55e2ac..e113ffbed3 100644 --- a/mod/quiz/questiontypes/truefalse/editquestion.php +++ b/mod/quiz/questiontypes/truefalse/editquestion.php @@ -1,28 +1,28 @@ id)) { - $options = get_record("quiz_truefalse", "question", "$question->id"); - } - if (!empty($options->trueanswer)) { - $true = get_record("quiz_answers", "id", $options->trueanswer); - } else { - $true->fraction = 1; - $true->feedback = ""; - } - if (!empty($options->falseanswer)) { - $false = get_record("quiz_answers", "id", "$options->falseanswer"); - } else { - $false->fraction = 0; - $false->feedback = ""; - } + if (!empty($question->id)) { + $options = get_record("quiz_truefalse", "question", "$question->id"); + } + if (!empty($options->trueanswer)) { + $true = get_record("quiz_answers", "id", $options->trueanswer); + } else { + $true->fraction = 1; + $true->feedback = ""; + } + if (!empty($options->falseanswer)) { + $false = get_record("quiz_answers", "id", "$options->falseanswer"); + } else { + $false->fraction = 0; + $false->feedback = ""; + } - if ($true->fraction > $false->fraction) { - $question->answer = 1; - } else { - $question->answer = 0; - } + if ($true->fraction > $false->fraction) { + $question->answer = 1; + } else { + $question->answer = 0; + } - print_heading_with_help(get_string("editingtruefalse", "quiz"), "truefalse", "quiz"); - require("truefalse.html"); + print_heading_with_help(get_string("editingtruefalse", "quiz"), "truefalse", "quiz"); + require("truefalse.html"); ?> diff --git a/mod/quiz/questiontypes/truefalse/truefalse.html b/mod/quiz/questiontypes/truefalse/truefalse.html index 3b11eb0dbd..1b5874cc31 100644 --- a/mod/quiz/questiontypes/truefalse/truefalse.html +++ b/mod/quiz/questiontypes/truefalse/truefalse.html @@ -39,7 +39,7 @@ print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext); - if ($usehtmleditor) { /// Trying this out for a while + if ($usehtmleditor) { echo ''; } else { echo "
"; @@ -96,8 +96,3 @@ - -- 2.39.5