]> git.mjollnir.org Git - moodle.git/commitdiff
Some cleanups with formatting and so on.
authormoodler <moodler>
Thu, 29 Jul 2004 06:15:54 +0000 (06:15 +0000)
committermoodler <moodler>
Thu, 29 Jul 2004 06:15:54 +0000 (06:15 +0000)
19 files changed:
mod/quiz/lib.php
mod/quiz/question.php
mod/quiz/questiontypes/description/description.html
mod/quiz/questiontypes/description/editquestion.php
mod/quiz/questiontypes/match/editquestion.php
mod/quiz/questiontypes/match/match.html
mod/quiz/questiontypes/multianswer/multianswer.html
mod/quiz/questiontypes/multichoice/editquestion.php
mod/quiz/questiontypes/multichoice/multichoice.html
mod/quiz/questiontypes/numerical/editquestion.php
mod/quiz/questiontypes/numerical/numerical.html
mod/quiz/questiontypes/random/editquestion.php
mod/quiz/questiontypes/random/random.html
mod/quiz/questiontypes/randomsamatch/editquestion.php
mod/quiz/questiontypes/randomsamatch/randomsamatch.html
mod/quiz/questiontypes/shortanswer/editquestion.php
mod/quiz/questiontypes/shortanswer/shortanswer.html
mod/quiz/questiontypes/truefalse/editquestion.php
mod/quiz/questiontypes/truefalse/truefalse.html

index 52d7e86e06fdce8c1ecb32f7c11b64c1a7cbb18a..ac805f729100e3709a44eadd95b439c76047799d 100644 (file)
@@ -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<br/>"; // Uncomment for debugging
         if (is_readable($qtypefilepath)) {
index c37982c24432366155e8068077f987d497f122bb..c5cdfa376ef562d4bf77ec624dac312d74c61260 100644 (file)
         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)) {
     }
 
     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);
     // 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 '<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) { 
+        use_html_editor('questiontext');
+    }
+
     print_footer($course);
 
 
index 38188b5bc55287a64396ff583d3811a50b901448..e07fcd534079afdd063b93a70e5d1373c187b203 100644 (file)
@@ -37,7 +37,7 @@
 \r
            print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext);\r
 \r
-           if ($usehtmleditor) {   /// Trying this out for a while\r
+           if ($usehtmleditor) {\r
                echo '<input type="hidden" name="questiontextformat" value="'.FORMAT_HTML.'">';\r
            } else {\r
                echo "<div align=right>";\r
@@ -73,8 +73,3 @@
 \r
 </CENTER>\r
 </FORM>\r
-<?php  \r
-   if ($usehtmleditor) { \r
-       print_richedit_javascript("theform", "questiontext", "no");\r
-   }\r
-?>\r
index cd5a89c1b0147031876cafc55d706df2580b0427..4d7a67ee5f5cb9468da9396fe11e4a8ed536b9b4 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP // $Id$
 
-            print_heading_with_help(get_string("editingdescription", "quiz"), "description", "quiz");
-            require("description.html");
+    print_heading_with_help(get_string("editingdescription", "quiz"), "description", "quiz");
+    require("description.html");
 
 ?>
index c10475181f96bf6b606f8ee381211ad9b4aedcdb..d6204f03a4a53b242a73e9f119e972abe28fdf12 100644 (file)
@@ -1,25 +1,26 @@
 <?PHP // $Id$
-            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; $i<QUIZ_MAX_NUMBER_ANSWERS; $i++) {
-                    $subquestions[] = "";   // Make question slots, default as blank
-                    $subanswers[] = "";     // Make answer slots, default as blank
-                }
-                if (!empty($oldsubquestions)) {
-                    $i=0;
-                    foreach ($oldsubquestions as $oldsubquestion) {
-                        $subquestions[$i] = $oldsubquestion->questiontext;   // 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; $i<QUIZ_MAX_NUMBER_ANSWERS; $i++) {
+            $subquestions[] = "";   // Make question slots, default as blank
+            $subanswers[] = "";     // Make answer slots, default as blank
+        }
+        if (!empty($oldsubquestions)) {
+            $i=0;
+            foreach ($oldsubquestions as $oldsubquestion) {
+                $subquestions[$i] = $oldsubquestion->questiontext;   // 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");
 
 ?>
index 37327f015c04821be369afb8e0c8f5eea2c3ca46..ee6ec58226e6dddb061dbe9ad765c37ff25ec22c 100644 (file)
@@ -37,7 +37,7 @@
 \r
            print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext);\r
 \r
-           if ($usehtmleditor) {   /// Trying this out for a while\r
+           if ($usehtmleditor) { \r
                echo '<input type="hidden" name="questiontextformat" value="'.FORMAT_HTML.'">';\r
            } else {\r
                echo "<div align=right>";\r
@@ -97,8 +97,3 @@
 \r
 </CENTER>\r
 </FORM>\r
-<?php  \r
-   if ($usehtmleditor) { \r
-       print_richedit_javascript("theform", "questiontext", "no");\r
-   }\r
-?>\r
index 4c3da4bbd23df855d4a5566c3b422b7ee4f46f82..46864f29823a0391269c023f6da4e82c15c9ddd7 100644 (file)
 </CENTER>
 
 </FORM>
-
-<?php  
-
-   if ($usehtmleditor) { 
-
-       print_richedit_javascript("theform", "questiontext", "no");
-
-   }
-
-?>
-
index d313938c03ddf72ea567d074b4df7408a7ce8867..224607002d19a97b08a7909f14aa7768678609ae 100644 (file)
@@ -1,23 +1,24 @@
-<?PHP // $Id$
-            if (!empty($question->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; $i<QUIZ_MAX_NUMBER_ANSWERS; $i++) {
-                $answers[] = "";   // Make answer slots, default as blank
-            }
-            if (!empty($answersraw)) {
-                $i=0;
-                foreach ($answersraw as $answer) {
-                    $answers[$i] = $answer;   // insert answers into slots
-                    $i++;
-                }
-            }
-            print_heading_with_help(get_string("editingmultichoice", "quiz"), "multichoice", "quiz");
-            require("multichoice.html");
+<?php // $Id$
+
+    if (!empty($question->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; $i<QUIZ_MAX_NUMBER_ANSWERS; $i++) {
+        $answers[] = "";   // Make answer slots, default as blank
+    }
+    if (!empty($answersraw)) {
+        $i=0;
+        foreach ($answersraw as $answer) {
+            $answers[$i] = $answer;   // insert answers into slots
+            $i++;
+        }
+    }
+    print_heading_with_help(get_string("editingmultichoice", "quiz"), "multichoice", "quiz");
+    require("multichoice.html");
 
 ?>
index 5afb2566ba6db3872484238f29fa75c01eecf556..a7a6473e241b2d7be9e85bc0678cb06704ed9916 100644 (file)
@@ -37,7 +37,7 @@
 \r
            print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext);\r
 \r
-           if ($usehtmleditor) {   /// Trying this out for a while\r
+           if ($usehtmleditor) {\r
                echo '<input type="hidden" name="questiontextformat" value="'.FORMAT_HTML.'">';\r
            } else {\r
                echo "<div align=right>";\r
 \r
 </CENTER>\r
 </FORM>\r
-<?php  \r
-   if ($usehtmleditor) { \r
-       print_richedit_javascript("theform", "questiontext", "no");\r
-   }\r
-?>\r
index 6d1ace119a6463c3435e29578b54546b8457da3f..527b06f3e4cce2402762144b17c721183ff5dd48 100644 (file)
@@ -1,25 +1,25 @@
 <?PHP // $Id$
 
-            // 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");
+    // 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");
 
 ?>
index 2488599453af921d0f5288d07e3bd5f0f193f0a5..31daec18fd9b23471a884ec44df0d836626ff19f 100644 (file)
@@ -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 '<input type="hidden" name="questiontextformat" value="'.FORMAT_HTML.'">';
            } else {
                echo "<div align=right>";
@@ -133,9 +133,3 @@ function determineMinAndMax() {
     }
 }
 </SCRIPT>
-<?php  
-   if ($usehtmleditor) { 
-       print_richedit_javascript("theform", "questiontext", "no");
-   }
-?>
-
index b6737f31b3661ca21b94a78c6abed1231c1adb57..1c67423c649ec13897fbae780f2a41262001e964 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP // $Id$
 
-            print_heading_with_help(get_string("editingrandom", "quiz"), "random", "quiz");
-            require("random.html");
+    print_heading_with_help(get_string("editingrandom", "quiz"), "random", "quiz");
+    require("random.html");
 
 ?>
index 8c453bc4bea04041285fc257a9edd40a8974a02e..6daad2a5d0b889c33bd3a705565d411a3da1e56d 100644 (file)
@@ -1,5 +1,5 @@
 <center>\r
-<form name="theform" method="post" action="question.php">\r
+<form name="theform" method="post" <?php echo $onsubmit ?> action="question.php">\r
 \r
 <table cellpadding=5>\r
 <tr valign=top>\r
index 4e89551b49a2143973a452c961fdeb40d02286de..87045a9cab2e65a3dad6a4d68e719f2e4d312e22 100644 (file)
@@ -1,11 +1,11 @@
 <?PHP // $Id$
-            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");
+    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");
 
 ?>
index 197f78a39fcb400810dc8306d4306db8abf92d1a..5a47858fef78596af2944f2d6c874d6e21007638 100644 (file)
@@ -44,7 +44,7 @@
            }\r
            print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext);\r
 \r
-           if ($usehtmleditor) {   /// Trying this out for a while\r
+           if ($usehtmleditor) {\r
                echo '<input type="hidden" name="questiontextformat" value="'.FORMAT_HTML.'">';\r
            } else {\r
                echo "<div align=right>";\r
@@ -89,8 +89,3 @@
 \r
 </CENTER>\r
 </FORM>\r
-<?php  \r
-   if ($usehtmleditor) { \r
-       print_richedit_javascript("theform", "questiontext", "no");\r
-   }\r
-?>\r
index 3635b73ee1ba47f9cb5dadf1229516bda9beb91d..670830ce323bc58e69493476e517d7d021cfc27b 100644 (file)
@@ -1,23 +1,23 @@
 <?PHP // $Id$
-            if (!empty($question->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; $i<QUIZ_MAX_NUMBER_ANSWERS; $i++) {
-                $answers[] = "";   // Make answer slots, default as blank
-            }
-            if (!empty($answersraw)) {
-                $i=0;
-                foreach ($answersraw as $answer) {
-                    $answers[$i] = $answer;   // insert answers into slots
-                    $i++;
-                }
-            }
-            print_heading_with_help(get_string("editingshortanswer", "quiz"), "shortanswer", "quiz");
-            require("shortanswer.html");
+    if (!empty($question->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; $i<QUIZ_MAX_NUMBER_ANSWERS; $i++) {
+        $answers[] = "";   // Make answer slots, default as blank
+    }
+    if (!empty($answersraw)) {
+        $i=0;
+        foreach ($answersraw as $answer) {
+            $answers[$i] = $answer;   // insert answers into slots
+            $i++;
+        }
+    }
+    print_heading_with_help(get_string("editingshortanswer", "quiz"), "shortanswer", "quiz");
+    require("shortanswer.html");
 
 ?>
index ce621449dcb1b1de418b1bb205489954b0d928d4..06b2458e6640eda94326b82898a8a634ff13c20a 100644 (file)
@@ -37,7 +37,7 @@
 \r
            print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext);\r
 \r
-           if ($usehtmleditor) {   /// Trying this out for a while\r
+           if ($usehtmleditor) {\r
                echo '<input type="hidden" name="questiontextformat" value="'.FORMAT_HTML.'">';\r
            } else {\r
                echo "<div align=right>";\r
 \r
 </CENTER>\r
 </FORM>\r
-<?php  \r
-   if ($usehtmleditor) { \r
-       print_richedit_javascript("theform", "questiontext", "no");\r
-   }\r
-?>\r
index c98f55e2ac08a2057e9cdd776693619e513bf99a..e113ffbed317cab1a9f7df5de83a3e9596518a39 100644 (file)
@@ -1,28 +1,28 @@
 <?PHP // $Id$
 
-            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 (!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");
 
 ?>
index 3b11eb0dbde69ffdecaf53471cf16ab4b3f7f7c4..1b5874cc31222fa31479e9abe48a72d0cd9f28c1 100644 (file)
@@ -39,7 +39,7 @@
 \r
            print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext);\r
 \r
-           if ($usehtmleditor) {   /// Trying this out for a while\r
+           if ($usehtmleditor) { \r
                echo '<input type="hidden" name="questiontextformat" value="'.FORMAT_HTML.'">';\r
            } else {\r
                echo "<div align=right>";\r
@@ -96,8 +96,3 @@
 \r
 </CENTER>\r
 </FORM>\r
-<?php  \r
-   if ($usehtmleditor) { \r
-       print_richedit_javascript("theform", "questiontext", "no");\r
-   }\r
-?>\r