<?php  // $Id: config.html,v 1.32.2.5 2009/09/30 10:58:04 tjhunt Exp $
    require_once($CFG->dirroot . '/mod/quiz/locallib.php');

    if (!isset($form->timeopen)) {
        $form->timeopen = "";
    }
    if (!isset($form->timeclose)) {
        $form->timeclose = "";
    }
    if (!isset($form->attempts)) {
        $form->attempts = $CFG->quiz_attempts;
    }
    if (!isset($form->attemptonlast)) {
        $form->attemptonlast = $CFG->quiz_attemptonlast;
    }
    if (!isset($form->grademethod)) {
        $form->grademethod = $CFG->quiz_grademethod;
    }
    if (!isset($form->decimalpoints)) {
        $form->decimalpoints = $CFG->quiz_decimalpoints;
    }
    if (!isset($form->review)) {
        $form->review = $CFG->quiz_review;
    }
    if (!isset($form->questionsperpage)) {
        $form->questionsperpage = $CFG->quiz_questionsperpage;
    }
    if (!isset($form->shufflequestions)) {
        $form->shufflequestions = $CFG->quiz_shufflequestions;
    }
    if (!isset($form->shuffleanswers)) {
        $form->shuffleanswers = $CFG->quiz_shuffleanswers;
    }
    if (!isset($form->grade)) {
        $form->grade = $CFG->quiz_maximumgrade;
    }
    if (!isset($form->questions)) {
        $form->questions = "";
    }
    if (!isset($form->password)) {
        $form->quizpassword = $CFG->quiz_password;
    }
    if (!isset($form->subnet)) {
        $form->subnet = $CFG->quiz_subnet;
    }
    if (!isset($form->timelimit)) {
        $form->timelimit = $CFG->quiz_timelimit;
    }
    if (!isset($form->popup)) {
        $form->popup = $CFG->quiz_popup;
    }
    if (!isset($form->optionflags)) {
        $form->optionflags = $CFG->quiz_optionflags;
    }
    if (!isset($form->penaltyscheme)) {
        $form->penaltyscheme = $CFG->quiz_penaltyscheme;
    }
    if (!isset($form->maximumgrade)) {
        $form->maximumgrade = $CFG->quiz_maximumgrade;
    }
    //enforced delay attempt between quiz
    if (!isset($form->delay1)) {
        $form->delay1 = $CFG->quiz_delay1;
    }
    if (!isset($form->delay2)) {
        $form->delay2 = $CFG->quiz_delay2;
    }
    //enforced time delay between quiz attempts add-on
    $timedelayoptions = array();
    $timedelayoptions[0] = get_string('none');
    $timedelayoptions[1800] = get_string('numminutes', '', 30);
    $timedelayoptions[3600] = get_string('numminutes', '', 60);
    for($i=2; $i<=23; $i++) {
        $seconds  = $i*3600;
        $timedelayoptions[$seconds] = get_string('numhours', '', $i);
    }
    $timedelayoptions[86400] = get_string('numhours', '', 24);
    for($i=2; $i<=7; $i++) {
         $seconds = $i*86400;
         $timedelayoptions[$seconds] = get_string('numdays', '', $i);
    }
?>

<script type="text/javascript">
//<![CDATA[
    var timelimititems = ['timelimit'];
//]]>
</script>

<form method="post" action="module.php" id="form">
<div>
<input type="hidden" name="sesskey" value="<?php echo $USER->sesskey ?>" />

<!-- Table of default values -->

<?php
    // the following are used for drop-down menus

    $yesnooptions = array();
    $yesnooptions[0] = get_string("no");
    $yesnooptions[1] = get_string("yes");

    $attemptoptions = array();
    $attemptoptions[0] = get_string("attemptsunlimited", "quiz");
    $attemptoptions[1] = "1 ".moodle_strtolower(get_string("attempt", "quiz"));
    for ($i=2;$i<=6;$i++) {
        $attemptoptions[$i] = "$i ".moodle_strtolower(get_string("attempts", "quiz"));
    }

?>

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

<tr valign="top">
  <th align="right" scope="col">&nbsp;</th>
  <th align="left" scope="col">
    <?php print_string('sitedefault'); ?>
  </th>
  <th align="center" scope="col">
    <?php print_string('advancedsettings'); helpbutton('advancedsettings', get_string('advancedsettings')); ?>
  </th>
</tr>

<tr valign="top">
    <td align="right"><b><?php print_string("timelimit", "quiz") ?>:</b></td>
    <td>
        <input name="timelimitenable" type="checkbox" value="1" alt="<?php print_string('timelimit', 'quiz') ?>" onclick="return lockoptions('form', 'timelimitenable', timelimititems)" <?php if ($form->timelimit) echo 'checked="checked"' ?> />
        <input type="text" name="timelimit" size="3" value="<?php p($form->timelimit ? $form->timelimit : '') ?>" />
        <?php 
            print_string('minutes');
            helpbutton("timelimit", get_string("quiztimer","quiz"), "quiz");
        ?>
        <input type="hidden" name="htimelimit"    value="0" />
    </td>
  <td align="center">
    <input type="hidden" name="fix_timelimit" value="0" />
    <input type="checkbox" name="fix_timelimit" value="1" <?php echo $CFG->quiz_fix_timelimit ? 'checked="checked"' : ''; ?> />
  </td>
</tr>

<tr valign="top">
    <td align="right"><b><?php print_string('questionsperpage', 'quiz') ?>:</b></td>
    <td>
    <?php
        $perpage= array();
        for ($i=0; $i<=50; ++$i) {
            $perpage[$i] = $i;
        }
        $perpage[0] = get_string('allinone', 'quiz');

        choose_from_menu($perpage, 'questionsperpage', $form->questionsperpage, '');
        helpbutton('questionsperpage', get_string('questionsperpage', 'quiz'), 'quiz');
     ?>
    </td>
  <td align="center">
    <input type="hidden" name="fix_questionsperpage" value="0" />
    <input type="checkbox" name="fix_questionsperpage" value="1" <?php echo $CFG->quiz_fix_questionsperpage ? 'checked="checked"' : ''; ?> />
  </td>
</tr>

<tr valign="top">
  <td align="right"><b><?php print_string("shufflequestions", "quiz") ?>:</b></td>
  <td>
    <?php
       choose_from_menu ($yesnooptions, "shufflequestions", $form->shufflequestions, "", "", "");
       helpbutton("shufflequestions", get_string("shufflequestions","quiz"), "quiz");
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="fix_shufflequestions" value="0" />
    <input type="checkbox" name="fix_shufflequestions" value="1" <?php echo $CFG->quiz_fix_shufflequestions ? 'checked="checked"' : ''; ?> />
  </td>
</tr>

<tr valign="top">
  <td align="right"><b><?php print_string("shufflewithin", "quiz") ?>:</b></td>
  <td>
    <?php
       choose_from_menu ($yesnooptions, "shuffleanswers", $form->shuffleanswers, "", "", "");
       helpbutton("shufflewithin", get_string("shufflewithin","quiz"), "quiz");
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="fix_shuffleanswers" value="0" />
    <input type="checkbox" name="fix_shuffleanswers" value="1" <?php echo $CFG->quiz_fix_shuffleanswers ? 'checked="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, "attempts", $form->attempts, "", "", "");
        helpbutton("attempts", get_string("attemptsallowed","quiz"), "quiz");
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="fix_attempts" value="0" />
    <input type="checkbox" name="fix_attempts" value="1" <?php echo $CFG->quiz_fix_attempts ? 'checked="checked"' : ''; ?> />
  </td>
</tr>

<tr valign="top">
  <td align="right"><b><?php print_string("eachattemptbuildsonthelast", "quiz") ?>:</b></td>
  <td>
    <?php
       choose_from_menu ($yesnooptions, "attemptonlast", $form->attemptonlast, "", "", "");
       helpbutton("repeatattempts", get_string("eachattemptbuildsonthelast", "quiz"), "quiz");
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="fix_attemptonlast" value="0" />
    <input type="checkbox" name="fix_attemptonlast" value="1" <?php echo $CFG->quiz_fix_attemptonlast ? 'checked="checked"' : ''; ?> />
  </td>
</tr>

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

<tr valign="top">
  <td align="right"><b><?php print_string("adaptive", "quiz") ?>:</b></td>
  <td>
    <?php
        choose_from_menu($yesnooptions, "adaptive", ($CFG->quiz_optionflags & QUESTION_ADAPTIVE) ? 1 : 0, "");
        helpbutton("adaptive", get_string("adaptive","quiz"), "quiz");
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="fix_adaptive" value="0" />
    <input type="checkbox" name="fix_adaptive" value="1" <?php echo $CFG->quiz_fix_adaptive ? 'checked="checked"' : ''; ?> />
  </td>
</tr>

<tr valign="top">
  <td align="right"><b><?php print_string("penaltyscheme", "quiz") ?>:</b></td>
  <td>
    <?php
        choose_from_menu($yesnooptions, "penaltyscheme", "$form->penaltyscheme", "");
        helpbutton("penaltyscheme", get_string("penaltyscheme","quiz"), "quiz");
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="fix_penaltyscheme" value="0" />
    <input type="checkbox" name="fix_penaltyscheme" value="1" <?php echo $CFG->quiz_fix_penaltyscheme ? 'checked="checked"' : ''; ?> />
  </td>
</tr>

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


<tr valign="top">
  <?php include($CFG->dirroot . '/mod/quiz/reviewoptions.html'); ?>
  <td align="center">
    <input type="hidden" name="fix_review" value="0" />
    <input type="checkbox" name="fix_review" value="1" <?php echo $CFG->quiz_fix_review ? 'checked="checked"' : ''; ?> />
  </td>
</tr>

<tr valign="top">
  <td align="right"><b><?php print_string('browsersecurity', 'quiz') ?>:</b></td>
  <td>
    <?php
        $browseroptions = array(
                0 => get_string('none', 'quiz'),
                1 => get_string('popupwithjavascriptsupport', 'quiz'));
        if ($CFG->enablesafebrowserintegration) { 
            $browseroptions[2] = get_string('requiresafeexambrowser', 'quiz');
        }
        choose_from_menu ($browseroptions, 'popup', $form->popup, '', '', '');
        helpbutton('browsersecurity', get_string('browsersecurity', 'quiz'), 'quiz');
    ?>
  </td>
  <td align="center">
    <input type="hidden" name="fix_popup" value="0" />
    <input type="checkbox" name="fix_popup" value="1" <?php echo $CFG->quiz_fix_popup ? 'checked="checked"' : ''; ?> />
  </td>
</tr>

<tr valign="top">
    <td align="right"><b><?php print_string('delay1', 'quiz') ?>:</b></td>
    <td align="left">
    <?php
         choose_from_menu($timedelayoptions, 'delay1', $form->delay1, "", "", "" );
         helpbutton('timedelay1', get_string('delay1','quiz'), 'quiz');
    ?>
    </td>
    <td align="center">
        <input type="hidden" name="fix_delay1" value="0" />
        <input type="checkbox" name="fix_delay1" value="1" <?php echo $CFG->quiz_fix_delay1 ? 'checked="checked"' : ''; ?> />
    </td>
</tr>

<tr valign="top">
    <td align="right"><b><?php print_string('delay2', 'quiz') ?>:</b></td>
    <td align="left">
    <?php
        choose_from_menu($timedelayoptions, 'delay2', $form->delay2, "", "", "");
        helpbutton('timedelay2', get_string('delay2','quiz'), 'quiz');
    ?>
    </td>
    <td align="center">
         <input type="hidden" name="fix_delay2" value="0" />
         <input type="checkbox" name="fix_delay2" value="1" <?php echo $CFG->quiz_fix_delay2 ? 'checked="checked"' : ''; ?> />        
    </td>
</tr>

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

<tr valign="top">
  <td align="right"><b><?php print_string("requiresubnet", "quiz") ?>:</b></td>
  <td>
    <input type="text" name="subnet" size="20" value="<?php p($form->subnet) ?>" />
    <?php helpbutton("requiresubnet", get_string("requiresubnet", "quiz"), "quiz"); ?>
  </td>
  <td align="center">
    <input type="hidden" name="fix_subnet" value="0" />
    <input type="checkbox" name="fix_subnet" value="1" <?php echo $CFG->quiz_fix_subnet ? 'checked="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, "maximumgrade", $form->maximumgrade, "", "", "");
       helpbutton("maxgrade", get_string("maximumgrade"), "quiz");
    ?>
  </td>
</tr>

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

</table>
</div>
</form>

<script type="text/javascript">
<?php 
    if (!$form->timelimit) echo "lockoptions('form','timelimitenable', timelimititems);";
?>
</script>
