<form name="theform" method="post" action="question.php">
<center>
<table cellpadding="5">
<tr valign="top">
    <td align="right"><b><?php  print_string("category", "quiz") ?>:</b></td>
    <td align="left">
    <?php   quiz_category_select_menu($course->id, true, true, $question->category); ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><b><?php  print_string("questionname", "quiz") ?>:</b></td>
    <td align="left">
        <input type="text" name="name" size="50" value="<?php  p($question->name) ?>" alt="<?php  print_string("questionname", "quiz") ?>" />
        <?php  if (isset($err["name"])) formerr($err["name"]); ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><b><?php  print_string("question", "quiz") ?>:</b>
    <br />
    <br />
    <br />
    <span class="editorhelptext">
    <?php
           if ($usehtmleditor) {
               helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
           } else {
               helpbutton("text", get_string("helptext"), "moodle", true, true);
           }
    ?>
    </span>
    </td>
    <td align="left">
        <?php  if (isset($err["questiontext"])) {
               formerr($err["questiontext"]);
               echo "<br />";
           }

           print_textarea($usehtmleditor, 20, 60, 630, 300, "questiontext", $question->questiontext);

           if ($usehtmleditor) {   /// Trying this out for a while
               echo '<input type="hidden" name="questiontextformat" value="'.FORMAT_HTML.'" />';
           } else {
               echo '<div align="right">';
               print_string("formattexttype");
               echo ":&nbsp;";
               if (!isset($question->questiontextformat)) {
                   $question->questiontextformat = FORMAT_MOODLE;
               }
               choose_from_menu(format_text_menu(), "questiontextformat", $question->questiontextformat, "");
               helpbutton("textformat", get_string("helpformatting"));
               echo "</div>";
           }
        ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><b><?php  print_string("imagedisplay", "quiz") ?>:</b></td>
    <td align="left">
    <?php   if (empty($images)) {
            print_string("noimagesyet");
        } else {
            choose_from_menu($images, "image", "$question->image", get_string("none"),"","");
        }
    ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><b><?php  print_string("penaltyfactor", "quiz") ?>:</b></td>
    <td align="left">
        <input type="text" name="penalty" size="3" value="<?php  p($question->penalty) ?>" alt="<?php  print_string("penaltyfactor", "quiz") ?>" />
        <?php helpbutton('penalty', get_string('penalty', 'quiz'), 'quiz'); ?>
        <?php  if (isset($err["penalty"])) formerr($err["penalty"]); ?>
    </td>
</tr>
<tr valign="top">
<td align="right"><b><?php  print_string("correctanswerformula", "quiz") ?>:</b></td>
    <td align="left">
    <input align="left" type="text" id="formula0" name="answers[]" size="20" value="<?php  p($answers[0]->answer) ?>" alt="<?php  print_string("correctanswerformula", "quiz") ?>" />&nbsp;&nbsp;
    <input type="hidden" name="fraction[]" value="1.0" />
    </td>
</tr>
<tr valign="top">
    <td align="right"><b><?php  print_string("tolerance", "quiz"); ?>:</b></td>
    <td align="left">
    <input align="left" type="text" id="tolerance0" name="tolerance[]" size="15" value="<?php  p($answers[0]->tolerance) ?>" alt="<?php  print_string("tolerance", "quiz"); ?>" />&plusmn;
    </td>
</tr>
<tr valign="top">
<td align="right"><b><?php  print_string("tolerancetype", "quiz"); ?>:</b></td>
    <td align="left">
    <?php choose_from_menu($qtypeobj->tolerance_types(),
            'tolerancetype[]', $answers[0]->tolerancetype, false); ?>
    </td>
</tr>
<tr valign="top">
<td align="right"><b><?php  print_string("correctanswershows", "quiz"); ?>:</b></td>
    <td align="left">
    <?php choose_from_menu(array('0' => ' 0 ',
                                 '1' => ' 1 ', '2' => ' 2 ', '3' => ' 3 ',
                                 '4' => ' 4 ', '5' => ' 5 ', '6' => ' 6 ',
                                 '7' => ' 7 ', '8' => ' 8 ', '9' => ' 9 '),
                           'correctanswerlength[]',
                           $answers[0]->correctanswerlength, false); ?>
    <?php choose_from_menu(array('1' => get_string('decimalformat', 'quiz'),
                                 '2' => get_string('significantfiguresformat', 'quiz')),
                           'correctanswerformat[]',
                           $answers[0]->correctanswerformat, false); ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><b><?php  print_string("feedback", "quiz") ?>:</b></td>
    <td align="left">
        <textarea name="feedback[]" rows="2" cols="50"><?php  p($answers[0]->feedback) ?></textarea>
    </td>
</tr>
<tr valign="top">
<td align="right"><b><?php  print_string("unit", "quiz") ?>:</b></td>
    <td align="left">
        <input type="hidden" name="multiplier[]" value="1.0" />
        <input align="left" type="text" id="defaultunit" name="unit[]"
                size="5" value="<?php  p($units[0]->unit) ?>"
                alt="<?php  print_string("unit", "quiz") ?>" />
        <b>(<?php  print_string("optional", "quiz") ?>)</b>
    </td>
</tr>
<tr valign="top">
<td align="left"></td>
<td align="left"><b><?php  print_string("alternativeunits", "quiz") ?>:</b></td>
<td align="left"></td>
</tr>
<?php
for ($i=1; $i<count($units); $i++) {
    $unit=$units[$i];
?>
<tr valign="top">
<td></td>
    <td align="left">
        <b><?php  print_string("multiplier", "quiz") ?>:</b>
        <input type="text" id="<?php  p("multiplier$i") ?>" size="10"
                align="right" name="multiplier[]"
                value="<?php  p($unit->multiplier) ?>"
                alt="<?php  print_string("multiplier", "quiz") ?>" />
        <b>&nbsp;&nbsp;&nbsp;<?php  print_string("unit", "quiz") ?>:</b>
        <input align="left" type="text" id="<?php  p("unit$i") ?>"
                name="unit[]"
                size="5" value="<?php  p($unit->unit) ?>"
                alt="<?php  print_string("unit", "quiz") ?>" />
    </td>
</tr>
<?php
} /// END for
?>
</table>
<input type="hidden" name="sesskey" value="<?php echo $USER->sesskey; ?>" />
<input type="hidden" name="id" value="<?php  p($question->id) ?>" />
<input type="hidden" name="qtype" value="<?php  p($question->qtype) ?>" />
<input type="hidden" name="wizardpage" value="question" />
<input type="submit" onclick="return determineMinAndMax();"  value="<?php  print_string("savechanges") ?>" />
</center>
</form>
<script language="javascript" type="text/javascript">
function determineMinAndMax() {
    // This client-side script will determine the values for min and max
    // based on the input for answer and acceptederror.
    with(document.theform) {
        if (formula0.value=='') {
            alert('<?php  print_string("missingformula","quiz") ?>');
            return false;
            /* It could perhaps be an idea to parse the formula here
             * but as it is necessary at the server anyway, we can
             * it leave like this for the moment. */

        } else if (''!=defaultunit.value && !isNaN(defaultunit.value)) {
            alert('<?php  print_string("unitmustnotbenumeric","quiz") ?>');
            return false;
        } else if (isNaN(tolerance0.value)) {
            alert('<?php  print_string("tolerancemustbenumeric","quiz") ?>');
            return false;
        } else if ('2' == document.theform['correctanswerformat[]'].value
                && '0' == document.theform['correctanswerlength[]'].value) {
            alert('<?php  print_string("zerosignificantfiguresnotallowed","quiz") ?>');
            return false;
        } else {
            return true;
        }
    }
}
</script>
