]> git.mjollnir.org Git - moodle.git/commitdiff
FIxed line feeds
authormoodler <moodler>
Tue, 19 Aug 2003 14:27:49 +0000 (14:27 +0000)
committermoodler <moodler>
Tue, 19 Aug 2003 14:27:49 +0000 (14:27 +0000)
mod/quiz/editmultianswer.php

index da16220c8ec4b283c0957a89f1b8ceacf3fd24dc..dc589129ef7da30e44635c73933b794f50a84af4 100644 (file)
@@ -1 +1,234 @@
-<?PHP // $Id$\r\r    require_once("../../config.php");\r    require_once("lib.php");\r    require_once("format/default.php");\r    require_once("format/multianswer.php");\r    require_once("../../files/mimetypes.php");\r\r    if ($form = data_submitted("nomatch")) {\r\r        // Standard checks\r        if (! $category = get_record("quiz_categories", "id", $form->category)) {\r            error("This question doesn't belong to a valid category!");\r        }\r        if (! $course = get_record("course", "id", $category->course)) {\r            error("This question category doesn't belong to a valid course!");\r        }\r        require_login($course->id);\r        if (!isteacher($course->id)) {\r            error("You can't modify these questions!");\r        }\r\r        $question = extractMultiAnswerQuestion($form->questiontext);\r        $question->id = $form->id;\r        $question->qtype = $form->qtype;\r        $question->name = $form->name;\r        $question->category = $form->category;\r\r        if (empty($form->image)) {\r            $question->image = "";\r        } else {\r            $question->image = $form->image;\r        }\r\r        // Formcheck\r        $err = array();\r        if (empty($question->name)) {\r            $err["name"] = get_string("missingname", "quiz");\r        }\r        if (empty($question->questiontext)) {\r            $err["questiontext"] = get_string("missingquestiontext", "quiz");\r        }\r        if ($err) { // Formcheck failed\r            $category = $form->category;\r            notify(get_string("someerrorswerefound"));\r            unset($_POST);\r            require('question.php');\r            exit;\r\r        } else {\r\r            if (!empty($question->id)) { // Question already exists\r                if (!update_record("quiz_questions", $question)) {\r                    error("Could not update question!");\r                }\r            } else {         // Question is a new one\r                if (!$question->id = insert_record("quiz_questions", $question)) {\r                    error("Could not insert new question!");\r                }\r            }\r    \r            // Now to save all the answers and type-specific options\r            $result = quiz_save_question_options($question);\r\r            if (!empty($result->error)) {\r                error($result->error);\r            }\r\r            if (!empty($result->notice)) {\r                notice_yesno($result->notice, "question.php?id=$question->id", "edit.php");\r                print_footer($course);\r                exit;\r            }\r    \r            redirect("edit.php");\r        }\r\r    } else if ($question->questiontext and $question->id) {\r        $answers = quiz_get_answers($question);\r\r        foreach ($answers as $multianswer) {\r            $parsableanswerdef = '{' . $multianswer->norm . ':';\r            switch ($multianswer->answertype) {\r                case MULTICHOICE:\r                    $parsableanswerdef .= 'MULTICHOICE:';\r                    break;\r                case SHORTANSWER:\r                    $parsableanswerdef .= 'SHORTANSWER:';\r                    break;\r                case NUMERICAL:\r                    $parsableanswerdef .= 'NUMERICAL:';\r                    break;\r                default:\r                    error("answertype $multianswer->answertype not recognized");\r            }\r            $separator= '';\r            foreach ($multianswer->subanswers as $subanswer) {\r                $parsableanswerdef .= $separator\r                        . '%' . round(100*$subanswer->fraction) . '%';\r                $parsableanswerdef .= $subanswer->answer;\r                if ($subanswer->min || $subanswer->max) {\r                    // Special for numerical answers:\r                    $errormargin = $subanswer->answer - $subanswer->min;\r                    $parsableanswerdef .= ":$errormargin";\r                }\r                if ($subanswer->feedback) {\r                    $parsableanswerdef .= "#$subanswer->feedback";\r                }\r                $separator = '~';\r            }\r            $parsableanswerdef .= '}';\r            $question->questiontext = str_replace\r                    ("{#$multianswer->positionkey}", $parsableanswerdef,\r                     $question->questiontext);\r        }\r    }\r\r\r?>\r\r<FORM name="theform" method="post" <?=$onsubmit ?> action="editmultianswer.php">\r\r<CENTER>\r\r<TABLE cellpadding=5>\r\r<TR valign=top>\r\r    <TD align=right><P><B><? print_string("category", "quiz") ?>:</B></P></TD>\r\r    <TD>\r\r    <?  choose_from_menu($categories, "category", "$question->category", ""); ?>\r\r    </TD>\r\r</TR>\r\r<TR valign=top>\r\r    <TD align=right><P><B><? print_string("questionname", "quiz") ?>:</B></P></TD>\r\r    <TD>\r\r        <INPUT type="text" name="name" size=40 value="<? p($question->name) ?>">\r\r        <? if (isset($err["name"])) formerr($err["name"]); ?>\r\r    </TD>\r\r</TR>\r\r<TR valign=top>\r\r    <TD align=right><P><B><? print_string("question", "quiz") ?>:</B></P></TD>\r\r    <TD>\r\r        <? if (isset($err["questiontext"])) {\r\r               formerr($err["questiontext"]); \r\r               echo "<BR \>";\r\r           }\r\r           print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext);\r\r           if ($usehtmleditor) {\r\r               helpbutton("richtext", get_string("helprichtext"), "moodle");\r\r           } else {\r\r               helpbutton("text", get_string("helptext"), "moodle");\r\r           }\r\r        ?>\r\r    </TD>\r\r</TR>\r\r<TR valign=top>\r\r    <TD align=right><P><B><? print_string("imagedisplay", "quiz") ?>:</B></P></TD>\r\r    <TD>\r\r    <?  if (empty($images)) {\r\r            print_string("noimagesyet");\r\r        } else {\r\r            choose_from_menu($images, "image", "$question->image", get_string("none"),"","");\r\r        }\r\r    ?>\r\r    </TD>\r\r</TR>\r\r</TABLE>\r\r\r\r<INPUT type="hidden" name=id value="<? p($question->id) ?>">\r\r<INPUT type="hidden" name=qtype value="<? p($question->qtype) ?>">\r\r<INPUT type="hidden" name=defaultgrade value="<? p($question->defaultgrade) ?>">\r\r<INPUT type="submit" value="<? print_string("savechanges") ?>">\r\r\r\r</CENTER>\r\r</FORM>\r\r<? \r\r   if ($usehtmleditor) { \r\r       print_richedit_javascript("theform", "questiontext", "no");\r\r   }\r\r?>\r
\ No newline at end of file
+<?PHP // $Id$
+
+    require_once("../../config.php");
+    require_once("lib.php");
+    require_once("format/default.php");
+    require_once("format/multianswer.php");
+    require_once("../../files/mimetypes.php");
+
+    if ($form = data_submitted("nomatch")) {
+
+        // Standard checks
+        if (! $category = get_record("quiz_categories", "id", $form->category)) {
+            error("This question doesn't belong to a valid category!");
+        }
+        if (! $course = get_record("course", "id", $category->course)) {
+            error("This question category doesn't belong to a valid course!");
+        }
+        require_login($course->id);
+        if (!isteacher($course->id)) {
+            error("You can't modify these questions!");
+        }
+
+        $question = extractMultiAnswerQuestion($form->questiontext);
+        $question->id = $form->id;
+        $question->qtype = $form->qtype;
+        $question->name = $form->name;
+        $question->category = $form->category;
+
+        if (empty($form->image)) {
+            $question->image = "";
+        } else {
+            $question->image = $form->image;
+        }
+
+        // Formcheck
+        $err = array();
+        if (empty($question->name)) {
+            $err["name"] = get_string("missingname", "quiz");
+        }
+        if (empty($question->questiontext)) {
+            $err["questiontext"] = get_string("missingquestiontext", "quiz");
+        }
+        if ($err) { // Formcheck failed
+            $category = $form->category;
+            notify(get_string("someerrorswerefound"));
+            unset($_POST);
+            require('question.php');
+            exit;
+
+        } else {
+
+            if (!empty($question->id)) { // Question already exists
+                if (!update_record("quiz_questions", $question)) {
+                    error("Could not update question!");
+                }
+            } else {         // Question is a new one
+                if (!$question->id = insert_record("quiz_questions", $question)) {
+                    error("Could not insert new question!");
+                }
+            }
+    
+            // Now to save all the answers and type-specific options
+            $result = quiz_save_question_options($question);
+
+            if (!empty($result->error)) {
+                error($result->error);
+            }
+
+            if (!empty($result->notice)) {
+                notice_yesno($result->notice, "question.php?id=$question->id", "edit.php");
+                print_footer($course);
+                exit;
+            }
+    
+            redirect("edit.php");
+        }
+
+    } else if ($question->questiontext and $question->id) {
+        $answers = quiz_get_answers($question);
+
+        foreach ($answers as $multianswer) {
+            $parsableanswerdef = '{' . $multianswer->norm . ':';
+            switch ($multianswer->answertype) {
+                case MULTICHOICE:
+                    $parsableanswerdef .= 'MULTICHOICE:';
+                    break;
+                case SHORTANSWER:
+                    $parsableanswerdef .= 'SHORTANSWER:';
+                    break;
+                case NUMERICAL:
+                    $parsableanswerdef .= 'NUMERICAL:';
+                    break;
+                default:
+                    error("answertype $multianswer->answertype not recognized");
+            }
+            $separator= '';
+            foreach ($multianswer->subanswers as $subanswer) {
+                $parsableanswerdef .= $separator
+                        . '%' . round(100*$subanswer->fraction) . '%';
+                $parsableanswerdef .= $subanswer->answer;
+                if ($subanswer->min || $subanswer->max) {
+                    // Special for numerical answers:
+                    $errormargin = $subanswer->answer - $subanswer->min;
+                    $parsableanswerdef .= ":$errormargin";
+                }
+                if ($subanswer->feedback) {
+                    $parsableanswerdef .= "#$subanswer->feedback";
+                }
+                $separator = '~';
+            }
+            $parsableanswerdef .= '}';
+            $question->questiontext = str_replace
+                    ("{#$multianswer->positionkey}", $parsableanswerdef,
+                     $question->questiontext);
+        }
+    }
+
+
+?>
+
+<FORM name="theform" method="post" <?=$onsubmit ?> action="editmultianswer.php">
+
+<CENTER>
+
+<TABLE cellpadding=5>
+
+<TR valign=top>
+
+    <TD align=right><P><B><? print_string("category", "quiz") ?>:</B></P></TD>
+
+    <TD>
+
+    <?  choose_from_menu($categories, "category", "$question->category", ""); ?>
+
+    </TD>
+
+</TR>
+
+<TR valign=top>
+
+    <TD align=right><P><B><? print_string("questionname", "quiz") ?>:</B></P></TD>
+
+    <TD>
+
+        <INPUT type="text" name="name" size=40 value="<? p($question->name) ?>">
+
+        <? if (isset($err["name"])) formerr($err["name"]); ?>
+
+    </TD>
+
+</TR>
+
+<TR valign=top>
+
+    <TD align=right><P><B><? print_string("question", "quiz") ?>:</B></P></TD>
+
+    <TD>
+
+        <? if (isset($err["questiontext"])) {
+
+               formerr($err["questiontext"]); 
+
+               echo "<BR \>";
+
+           }
+
+           print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext);
+
+           if ($usehtmleditor) {
+
+               helpbutton("richtext", get_string("helprichtext"), "moodle");
+
+           } else {
+
+               helpbutton("text", get_string("helptext"), "moodle");
+
+           }
+
+        ?>
+
+    </TD>
+
+</TR>
+
+<TR valign=top>
+
+    <TD align=right><P><B><? print_string("imagedisplay", "quiz") ?>:</B></P></TD>
+
+    <TD>
+
+    <?  if (empty($images)) {
+
+            print_string("noimagesyet");
+
+        } else {
+
+            choose_from_menu($images, "image", "$question->image", get_string("none"),"","");
+
+        }
+
+    ?>
+
+    </TD>
+
+</TR>
+
+</TABLE>
+
+
+
+<INPUT type="hidden" name=id value="<? p($question->id) ?>">
+
+<INPUT type="hidden" name=qtype value="<? p($question->qtype) ?>">
+
+<INPUT type="hidden" name=defaultgrade value="<? p($question->defaultgrade) ?>">
+
+<INPUT type="submit" value="<? print_string("savechanges") ?>">
+
+
+
+</CENTER>
+
+</FORM>
+
+<? 
+
+   if ($usehtmleditor) { 
+
+       print_richedit_javascript("theform", "questiontext", "no");
+
+   }
+
+?>
+