From 2bf31fc6a69e756069ea0fe66cfdad01125899ed Mon Sep 17 00:00:00 2001 From: moodler Date: Tue, 19 Aug 2003 14:27:49 +0000 Subject: [PATCH] FIxed line feeds --- mod/quiz/editmultianswer.php | 235 ++++++++++++++++++++++++++++++++++- 1 file changed, 234 insertions(+), 1 deletion(-) diff --git a/mod/quiz/editmultianswer.php b/mod/quiz/editmultianswer.php index da16220c8e..dc589129ef 100644 --- a/mod/quiz/editmultianswer.php +++ b/mod/quiz/editmultianswer.php @@ -1 +1,234 @@ -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); } } ?>
action="editmultianswer.php">

:

category", ""); ?>

:

:

"; } 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"); } ?>

:

image", get_string("none"),"",""); } ?>
">
\ No newline at end of file +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); + } + } + + +?> + +
action="editmultianswer.php"> + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

:

+ + category", ""); ?> + +

:

+ + + + + +

:

+ + "; + + } + + 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"); + + } + + ?> + +

:

+ + image", get_string("none"),"",""); + + } + + ?> + +
+ + + + + + + + + +"> + + + +
+ +
+ + + -- 2.39.5