After saving new question, sanity checks are made to make sure the
authormoodler <moodler>
Wed, 23 Oct 2002 12:10:38 +0000 (12:10 +0000)
committermoodler <moodler>
Wed, 23 Oct 2002 12:10:38 +0000 (12:10 +0000)
fractional grades are correct.

Icons now have tooltips and are also a shortcut to editing page.

lang/en/quiz.php
mod/forum/lib.php
mod/quiz/lib.php
mod/quiz/question.php

index 453a363..1407f01 100644 (file)
@@ -47,6 +47,12 @@ $string['false'] = "False";
 $string['feedback'] = "Feedback";
 $string['filloutoneanswer'] = "You must fill out at least one possible answer.  Answers left blank will not be used.";
 $string['fillouttwochoices'] = "You must fill out at least two choices.  Choices left blank will not be used.";
+$string['fractionsaddwrong'] = "The positive grades you have chosen do not add up to 100%%
+<BR>Instead, they add up to \$a%%
+<BR>Do you want to go back and fix this question?";
+$string['fractionsnomax'] = "One of the answers should be 100%%, so that it is
+<BR>possible to get a full grade for this question.
+<BR>Do you want to go back and fix this question?";
 $string['gradeaverage'] = "Average grade";
 $string['gradehighest'] = "Highest grade";
 $string['grademethod'] = "Grading method";
index cda277c..f75f142 100644 (file)
@@ -569,7 +569,7 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link
         echo "</DIV>";
     }
 
-    if ($link && (strlen($post->message) > $FORUM_LONG_POST)) {
+    if ($link && (strlen(strip_tags($post->message)) > $FORUM_LONG_POST)) {
         // Print shortened version
         echo format_text(forum_shorten_post($post->message), $post->format);
         $numwords = count_words($post->message);
@@ -687,8 +687,9 @@ function forum_print_post_header(&$post, $courseid, $ownpost=false, $reply=false
 function forum_shorten_post($message) {
     global $FORUM_LONG_POST, $FORUM_SHORT_POST;
 
-    if (strlen($message) > $FORUM_LONG_POST) {
+    if (strlen(strip_tags($message)) > $FORUM_LONG_POST) {
         // Look for the first return between $FORUM_SHORT_POST and $FORUM_LONG_POST
+        // XXXX
         $shortmessage = substr($message, $FORUM_SHORT_POST, $FORUM_LONG_POST);
         if ($pos = strpos($shortmessage, "\n")) {
             return substr($message, 0, $FORUM_SHORT_POST + $pos);
index dd61b9a..e788b20 100644 (file)
@@ -222,20 +222,25 @@ function quiz_print_correctanswer($text) {
 
 function quiz_print_question_icon($question) {
 // Prints a question icon
+
+    global $QUIZ_QUESTION_TYPE;
+
+    echo "<A HREF=\"question.php?id=$question->id\" TITLE=\"".$QUIZ_QUESTION_TYPE[$question->type]."\">";
     switch ($question->type) {
         case SHORTANSWER:
-            echo "<IMG HEIGHT=16 WIDTH=16 SRC=\"pix/sa.gif\">";
+            echo "<IMG BORDER=0 HEIGHT=16 WIDTH=16 SRC=\"pix/sa.gif\">";
             break;
         case TRUEFALSE:
-            echo "<IMG HEIGHT=16 WIDTH=16 SRC=\"pix/tf.gif\">";
+            echo "<IMG BORDER=0 HEIGHT=16 WIDTH=16 SRC=\"pix/tf.gif\">";
             break;
         case MULTICHOICE:
-            echo "<IMG HEIGHT=16 WIDTH=16 SRC=\"pix/mc.gif\">";
+            echo "<IMG BORDER=0 HEIGHT=16 WIDTH=16 SRC=\"pix/mc.gif\">";
             break;
         case RANDOM:
-            echo "<IMG HEIGHT=16 WIDTH=16 SRC=\"pix/rs.gif\">";
+            echo "<IMG BORDER=0 HEIGHT=16 WIDTH=16 SRC=\"pix/rs.gif\">";
             break;
     }
+    echo "</A>\n";
 }
 
 function quiz_print_question($number, $questionid, $grade, $courseid, 
index 1533c84..14b594e 100644 (file)
                 delete_records("quiz_shortanswer", "question", $question->id);
 
                 $answers = array();
+                $maxfraction = -1;
 
                 // Insert all the new answers
                 foreach ($form->answer as $key => $formanswer) {
                             error("Could not insert quiz answer!");
                         }
                         $answers[] = $answer->id;
+                        if ($fraction[$key] > $maxfraction) {
+                            $maxfraction = $fraction[$key];
+                        }
                     }
                 }
 
                 if (!insert_record("quiz_shortanswer", $options)) {
                     error("Could not insert quiz shortanswer options!");
                 }
+
+                /// Perform sanity checks on fractional grades
+                if ($maxfraction != 1) {
+                    $maxfraction = $maxfraction * 100;
+                    notice_yesno(get_string("fractionsnomax", "quiz", $maxfraction), "question.php?id=$question->id", "edit.php");
+                    print_footer($course);
+                    exit;
+                }
             break;
             case TRUEFALSE:
                 delete_records("quiz_answers", "question", $question->id);
                 delete_records("quiz_answers", "question", $question->id);
                 delete_records("quiz_multichoice", "question", $question->id);
 
+                $totalfraction = 0;
+                $maxfraction = -1;
+
                 $answers = array();
 
                 // Insert all the new answers
                             error("Could not insert quiz answer!");
                         }
                         $answers[] = $answer->id;
+
+                        if ($fraction[$key] > 0) {                 // Sanity checks
+                            $totalfraction += $fraction[$key];
+                        }
+                        if ($fraction[$key] > $maxfraction) {
+                            $maxfraction = $fraction[$key];
+                        }
                     }
                 }
 
                 if (!insert_record("quiz_multichoice", $options)) {
                     error("Could not insert quiz multichoice options!");
                 }
+
+                /// Perform sanity checks on fractional grades
+                if ($options->single) {
+                    if ($maxfraction != 1) {
+                        $maxfraction = $maxfraction * 100;
+                        notice_yesno(get_string("fractionsnomax", "quiz", $maxfraction), "question.php?id=$question->id", "edit.php");
+                        print_footer($course);
+                        exit;
+                    }
+                } else {
+                    if ($totalfraction != 1) {
+                        $totalfraction = $totalfraction * 100;
+                        notice_yesno(get_string("fractionsaddwrong", "quiz", $totalfraction), "question.php?id=$question->id", "edit.php");
+                        print_footer($course);
+                        exit;
+                    }
+                }
             break;
             case RANDOM:
                 echo "<P>Not supported yet</P>";