<?php
    require_once($CFG->dirroot . '/mod/quiz/locallib.php');
?>
<form method="post" action="module.php" name="form">
<input type="hidden" name="sesskey" value="<?php echo $USER->sesskey ?>">


<!-- Table of config options -->
<?php
    $table_created = false; // used to make sure that table is only created when needed
    $submitbutton = false;
    // Include the options from each question type
    foreach ($QUIZ_QTYPES as $type) {
        $options = $type->get_config_options();
        if ($options) {
            // Temporary code
            if (!$table_created) {
                echo "<table cellpadding=\"9\" cellspacing=\"0\" align=\"center\">\n";
                echo '<tr><th colspan="3">';
                print_heading(get_string('questiontypesetupoptions', 'quiz'));
                echo "</th></tr>\n";
                $table_created = true;
            }
            $typename = $type->name();
            $strtype = get_string($typename, 'quiz');
            echo "<tr valign=\"top\">\n";
            echo '<td colspan="3" align="center"><b>' . $strtype . "</b></td>\n";
            echo "</tr>\n";
            foreach ($options as $option) {
                if (!isset($option->name)) {
                    continue;
                }
                echo "<tr valign=\"top\">\n";
                if (!empty($option->link)) {
                    echo '<td colspan="3" align="center"><a href="' . s($CFG->wwwroot) . '/mod/quiz/questiontypes/' . s($typename) . '/' . s($option->link) . '?sesskey=' . s(rawurlencode($USER->sesskey)) . '">' . get_string($option->name, 'quiz') . "</a></td>\n";
                }
                else {
                    if (!isset($option->code)) {
                        $option->code = '';
                    }
                    echo '<td align="right"><b>';
                    print_string($option->name, 'quiz');
                    echo ":</b></td>\n";
                    echo '<td>' . $option->code . "</td>\n";
                    if (empty($option->help)) {
                        echo "<td></td>\n";
                    }
                    else {
                        echo '<td align="left">' . get_string($option->help, 'quiz') . "</td>\n";
                    }
                    $submitbutton = 'true';
                }
                echo "</tr>\n";
            }
        }
    }
    if ($submitbutton) {
?>
<tr>
  <td colspan="3" align="center">
    <input type="submit" value="<?php print_string("savechanges") ?>" />
  </td>
</tr>
</table>
<?php
    }
    if ($table_created) {
        echo '</table>';
        print_simple_box_end();
        echo '<br />';
        print_simple_box_start('center');
    }
?>


<!-- Table of default values -->

<table cellpadding="9" cellspacing="0" align="center">

<tr valign="top">
  <th align="right">&nbsp;</th>
  <th align="left">
    <?php print_string('sitedefault'); ?>
  </th>
  <th align="center">
    <?php print_string('hide'); helpbutton("hideoptions"); ?>
  </th>
</tr>    

<tr valign="top">
  <td align="right"><b><?php print_string("timelimit", "quiz") ?>:</b></td>
  <td>
    <?php 
      print_timer_selector($CFG->quiz_timelimit, get_string("minutes","quiz"), 'quiz_timelimit');
      helpbutton("timelimit", get_string("quiztimer","quiz"), "quiz");
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="quiz_fix_timelimit" value="0">
    <input type="checkbox" name="quiz_fix_timelimit" value="1" <?php p($CFG->quiz_fix_timelimit ? "checked" : "") ?> />
  </td>
</tr>

<tr valign="top">
  <td align="right"><b><?php print_string("shufflequestions", "quiz") ?>:</b></td>
  <td>
    <?php
       unset($options);
       $options[0] = get_string("no");
       $options[1] = get_string("yes");
       choose_from_menu ($options, "quiz_shufflequestions", $CFG->quiz_shufflequestions, "", "", "");
       helpbutton("shufflequestions", get_string("shufflequestions","quiz"), "quiz");
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="quiz_fix_shufflequestions" value="0">
    <input type="checkbox" name="quiz_fix_shufflequestions" value="1" <?php p($CFG->quiz_fix_shufflequestions ? "checked" : "") ?> />
  </td>
</tr>

<tr valign="top">
  <td align="right"><b><?php print_string("shuffleanswers", "quiz") ?>:</b></td>
  <td>
    <?php
       unset($options);
       $options[0] = get_string("no");
       $options[1] = get_string("yes");
       choose_from_menu ($options, "quiz_shuffleanswers", $CFG->quiz_shuffleanswers, "", "", "");
       helpbutton("attempts", get_string("attemptsallowed","quiz"), "quiz");
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="quiz_fix_shuffleanswers" value="0">
    <input type="checkbox" name="quiz_fix_shuffleanswers" value="1" <?php p($CFG->quiz_fix_shuffleanswers ? "checked" : "") ?> />
  </td>
</tr>

<tr valign="top">
  <td align="right"><b><?php print_string("attemptsallowed", "quiz") ?>:</b></td>
  <td>
    <?php
        unset($options);
        $options[0] = get_string("attemptsunlimited", "quiz");
        $options[1] = "1 ".strtolower(get_string("attempt", "quiz"));
        for ($i=2;$i<=6;$i++) {
            $options[$i] = "$i ".strtolower(get_string("attempts", "quiz"));
        }
        choose_from_menu ($options, "quiz_attempts", $CFG->quiz_attempts, "", "", "");
        helpbutton("attempts", get_string("attemptsallowed","quiz"), "quiz");
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="quiz_fix_attempts" value="0">
    <input type="checkbox" name="quiz_fix_attempts" value="1" <?php p($CFG->quiz_fix_attempts ? "checked" : "") ?> />
  </td>
</tr>

<tr valign="top">
  <td align="right"><b><?php print_string("eachattemptbuildsonthelast", "quiz") ?>:</b></td>
  <td>
    <?php
       unset($options);
       $options[0] = get_string("no");
       $options[1] = get_string("yes");
       choose_from_menu ($options, "quiz_attemptonlast", $CFG->quiz_attemptonlast, "", "", "");
       helpbutton("repeatattempts", get_string("eachattemptbuildsonthelast", "quiz"), "quiz");
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="quiz_fix_attemptonlast" value="0">
    <input type="checkbox" name="quiz_fix_attemptonlast" value="1" <?php p($CFG->quiz_fix_attemptonlast ? "checked" : "") ?> />
  </td>
</tr>

<tr valign="top">
  <td align="right"><b><?php print_string("grademethod", "quiz") ?>:</b></td>
  <td>
    <?php
       choose_from_menu ($QUIZ_GRADE_METHOD, "quiz_grademethod", $CFG->quiz_grademethod, "", "", "");
       helpbutton("grademethod", get_string("grademethod","quiz"), "quiz");
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="quiz_fix_grademethod" value="0">
    <input type="checkbox" name="quiz_fix_grademethod" value="1" <?php p($CFG->quiz_fix_grademethod ? "checked" : "") ?> />
  </td>
</tr>

<tr valign="top">
  <td align="right"><b><?php print_string("decimalpoints", "quiz") ?>:</b></td>
  <td>
    <?php
       unset($options);
       $options[0] = '0';
       $options[1] = '1';
       $options[2] = '2';
       $options[3] = '3';
       choose_from_menu ($options, "quiz_decimalpoints", $CFG->quiz_decimalpoints, "", "", "");
       helpbutton("decimalpoints", get_string("decimalpoints","quiz"), "quiz");
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="quiz_fix_decimalpoints" value="0">
    <input type="checkbox" name="quiz_fix_decimalpoints" value="1" <?php p($CFG->quiz_fix_decimalpoints ? "checked" : "") ?> />
  </td>
</tr>

<tr valign="top">
  <td align="right"><b><?php print_string("showfeedback", "quiz") ?>:</b></td>
  <td>
    <?php
       unset($options);
       $options[0] = get_string("no");
       $options[1] = get_string("yes");
       choose_from_menu ($options, "quiz_showfeedback", $CFG->quiz_showfeedback, "", "", "");
       helpbutton("feedback", get_string("showfeedback","quiz"), "quiz");
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="quiz_fix_showfeedback" value="0">
    <input type="checkbox" name="quiz_fix_showfeedback" value="1" <?php p($CFG->quiz_fix_showfeedback ? "checked" : "") ?> />
  </td>
</tr>

<tr valign="top">
  <td align="right"><b><?php print_string("showcorrectanswer", "quiz") ?>:</b></td>
  <td>
    <?php
       unset($options);
       $options[0] = get_string("no");
       $options[1] = get_string("yes");
       choose_from_menu ($options, "quiz_showanswer", $CFG->quiz_showanswer, "", "", "");
       helpbutton("correctanswers", get_string("showcorrectanswer","quiz"), "quiz");
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="quiz_fix_showanswer" value="0">
    <input type="checkbox" name="quiz_fix_showanswer" value="1" <?php p($CFG->quiz_fix_showanswer ? "checked" : "") ?> />
  </td>
</tr>

<tr valign="top">
  <td align="right"><b><?php print_string("allowreview", "quiz") ?>:</b></td>
  <td>
    <?php
       $reviewoptions = array();
       $reviewoptions[0] = get_string('reviewnever', 'quiz');
       $reviewoptions[1] = get_string('reviewafter', 'quiz');
       $reviewoptions[2] = get_string('reviewbefore', 'quiz');
       $reviewoptions[3] = get_string('reviewalways', 'quiz');
       choose_from_menu ($reviewoptions, "quiz_allowreview", $CFG->quiz_allowreview, "", "", "");
       helpbutton("review2", get_string("allowreview","quiz"), "quiz");
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="quiz_fix_allowreview" value="0">
    <input type="checkbox" name="quiz_fix_allowreview" value="1" <?php p($CFG->quiz_fix_allowreview ? "checked" : "") ?> />
  </td>
</tr>

<tr valign="top">
  <td align="right"><b><?php print_string("maximumgrade") ?>:</b></td>
  <td>
    <?php
       unset($grades);
        for ($i=100; $i>=1; $i--) {
            $grades[$i] = $i;
        }
        $grades[0] = get_string("nograde");
       choose_from_menu ($grades, "quiz_maximumgrade", $CFG->quiz_maximumgrade, "", "", "");
       helpbutton("maxgrade", get_string("maximumgrade"), "quiz");
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="quiz_fix_maximumgrade" value="0">
    <input type="checkbox" name="quiz_fix_maximumgrade" value="1" <?php p($CFG->quiz_fix_maximumgrade ? "checked" : "") ?> />
  </td>
</tr>

<tr valign="top">
  <td align="right"><b><?php print_string("popup", "quiz") ?>:</b></td>
  <td>
    <?php
       unset($options);
       $options[0] = get_string("no");
       $options[1] = get_string("yes");
       choose_from_menu ($options, "quiz_popup", $CFG->quiz_popup, "", "", "");
       helpbutton("popup", get_string("popup","quiz"), "quiz");
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="quiz_fix_popup" value="0">
    <input type="checkbox" name="quiz_fix_popup" value="1" <?php p($CFG->quiz_fix_popup ? "checked" : "") ?> />
  </td>
</tr>

<tr valign="top">
  <td align="right"><b><?php print_string("requirepassword", "quiz") ?>:</b></td>
  <td>
    <input type="text" name="quiz_password" size="20" value="<?php p($CFG->quiz_password) ?>" />
    <?php helpbutton("requirepassword", get_string("requirepassword", "quiz"), "quiz"); ?>
  </td>
  <td align="center">
    <input type="hidden" name="quiz_fix_password" value="0">
    <input type="checkbox" name="quiz_fix_password" value="1" <?php p($CFG->quiz_fix_password ? "checked" : "") ?> />
  </td>
</tr>

<tr valign="top">
  <td align="right"><b><?php print_string("requiresubnet", "quiz") ?>:</b></td>
  <td>
    <input type="text" name="quiz_subnet" size="20" value="<?php p($CFG->quiz_subnet) ?>" />
    <?php helpbutton("requiresubnet", get_string("requiresubnet", "quiz"), "quiz"); ?>
  </td>
  <td align="center">
    <input type="hidden" name="quiz_fix_subnet" value="0">
    <input type="checkbox" name="quiz_fix_subnet" value="1" <?php p($CFG->quiz_fix_subnet ? "checked" : "") ?> />
  </td>
</tr>

<tr>
  <td colspan="3" align="center">
    <input type="submit" value="<?php print_string("savechanges") ?>" />
  </td>
</tr>
</table>

</form>
