<?php
    require_once("$CFG->dirroot/mod/workshop/lib.php");  // for parameter arrays
    require_once("$CFG->dirroot/mod/workshop/locallib.php");  // for parameter arrays

    // ...and fill the form if needed
    if (empty($form->name)) {
        $form->name = "";
    }
    if (empty($form->description)) {
        $form->description = "";
    }
    if (empty($form->format)) {
        $form->format = "";
    }
    if (!isset($form->gradinggrade)) {
        $form->gradinggrade = 100;
    }
    if (!isset($form->grade)) {
        $form->grade = 100;
    }
    if (!isset($form->gradingstrategy)) {
       $form->gradingstrategy = 1;  // default is accumulative
    }
    if (!isset($form->nelements)) {
        $form->nelements = 1;
    }
    if (!isset($form->nattachments)) {
        $form->nattachments = 0;
    }
    if (empty($form->resubmit)) {
        $form->resubmit = "";
    }
    if (!isset($form->ntassessments)) {
        $form->ntassessments = 0;
    }
    if (!isset($form->assessmentcomps)) {
        $form->assessmentcomps = 2;
    }
    if (!isset($form->nsassessments)) {
        $form->nsassessments = 0;
    }
    if (!isset($form->teacherweight)) {
        $form->teacherweight = 1;
    }
    if (!isset($form->overallocation)) {
        $form->overallocation = 0;
    }
    if (empty($form->includeself)) {
        $form->includeself = "";
    }
    if (empty($form->agreeassessments)) {
        $form->agreeassessments = "";
    }
    if (empty($form->hidegrades)) {
        $form->hidegrades = "";
    }
    if (empty($form->showleaguetable)) {
        $form->showleaguetable = 0;
    }
    if (empty($form->anonymous)) {
        $form->anonymous = 0;
    }
    if (empty($form->usepassword)) {
        $form->usepassword = 0;
    }
    if (empty($form->maxbytes)) {
        $form->maxbytes = "";
    }
    if (empty($form->submissionstart)) {
        $form->submissionstart = time();
    }
    if (empty($form->assessmentstart)) {
        $form->assessmentstart = time();
    }
    if (empty($form->submissionend)) {
        $form->submissionend = time();
    }
    if (empty($form->assessmentend)) {
        $form->assessmentend = time();
    }
    if (empty($form->releasegrades)) {
        $form->releasegrades = time();
    }
?>

<form id="form" method="post" action="mod.php">
<table cellpadding="5">
<tr valign="top">
    <td align="right"><b><?php  print_string("title", "workshop") ?>:</b></td>
    <td>
        <input type="text" name="name" size="60" value="<?php  p($form->name) ?>" alt="<?php  print_string("title", "workshop") ?>" />
    </td>
</tr>
<tr valign="top">
    <td align="right"><b><?php  print_string("description", "workshop") ?>:</b><br />
     <?php
        helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
        echo "<br />";
        if ($usehtmleditor) {
           helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
        } else {
           helpbutton("text", get_string("helptext"), "moodle", true, true);
           echo "<br />";
           emoticonhelpbutton("form", "description", "moodle", true, true);
           echo "<br />";
        }
      ?>
      <br />
    </td>
    <td>
    <?php
       print_textarea($usehtmleditor, 20, 60, 595, 400, "description", $form->description);

       if ($usehtmleditor) {
           echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
       } else {
           echo '<p style="text-align:right">';
           helpbutton("textformat", get_string("formattexttype"));
           print_string("formattexttype");
           echo ':&nbsp;';
           if (!$form->format) {
               $form->format = $defaultformat;
           }
           choose_from_menu(format_text_menu(), "format", $form->format, "");
           echo '</p>';
       }
    ?>
    </td>
</tr>

<tr valign="top">
    <td align="right"><b><?php  print_string("gradeforassessments", "workshop") ?>:</b></td>
    <td>
        <?php
        for ($i=100; $i>=0; $i--) {
            $grades[$i] = $i;
        }
        choose_from_menu($grades, "gradinggrade", "$form->gradinggrade", "");
        helpbutton("gradinggrade", get_string("gradeforassessments", "workshop"), "workshop");
        ?>
    </td>
</tr>

<tr valign="top">
    <td align="right"><b><?php  print_string("gradeforsubmission", "workshop") ?>:</b></td>
    <td>
        <?php
        choose_from_menu($grades, "grade", "$form->grade", "");
        helpbutton("grade", get_string("gradeforsubmission", "workshop"), "workshop");
        ?>
    </td>
</tr>

<tr valign="top">
    <td align="right"><b><?php  print_string("gradingstrategy", "workshop") ?>:</b></td>
    <td>
    <?php
       choose_from_menu($WORKSHOP_TYPE, "gradingstrategy", $form->gradingstrategy, "");
       helpbutton("gradingstrategy", get_string("gradingstrategy", "workshop"), "workshop");
    ?>
    </td>
</tr>

<tr valign="top">
    <td align="right"><b><?php  print_string("numberofassessmentelements", "workshop") ?>:</b></td>
    <td valign="middle">
        <?php
        for ($i=20; $i>=0; $i--) {
            $numbers[$i] = $i;
        }
        choose_from_menu($numbers, "nelements", "$form->nelements", "");
       helpbutton("nelements", get_string("numberofassessmentelements", "workshop"), "workshop");
        ?>
    </td>
</tr>

<tr valign="top">
    <td align="right"><b><?php  print_string("numberofattachments", "workshop") ?>:</b></td>
    <td valign="middle">
        <?php
        unset($numbers);
        for ($i=5; $i>=0; $i--) {
            $numbers[$i] = $i;
        }
        choose_from_menu($numbers, "nattachments", "$form->nattachments", "");
       helpbutton("nattachments", get_string("numberofattachments", "workshop"), "workshop");
        ?>
    </td>
</tr>

<tr>
    <td align="right"><b><?php  print_string("allowresubmit", "workshop") ?>:</b></td>
    <td>
    <?php
        $options[0] = get_string("no"); $options[1] = get_string("yes");
        choose_from_menu($options, "resubmit", $form->resubmit, "");
        helpbutton("resubmit", get_string("allowresubmit", "workshop"), "workshop");
    ?>
    </td>
</tr>

<tr valign="top">
    <td align="right"><b><?php  print_string("numberofassessmentsofteachersexamples", "workshop") ?>:</b></td>
    <td>
        <?php
        unset($numbers);
        for ($i=20; $i>=0; $i--) {
            $numbers[$i] = $i;
        }
        choose_from_menu($numbers, "ntassessments", $form->ntassessments, "");
       helpbutton("nassessmentsofteachersexamples", get_string("numberofassessmentsofteachersexamples", "workshop"), "workshop");
        ?>
    </td>
</tr>

<tr>
    <td align="right"><b><?php print_string("comparisonofassessments", "workshop") ?>:</b></td>
    <td>
        <?php
        // set up comparison names
        foreach ($WORKSHOP_ASSESSMENT_COMPS as $KEY => $COMPARISON) {
            $COMPARISONS[] = $COMPARISON['name'];
        }
        choose_from_menu($COMPARISONS, "assessmentcomps", $form->assessmentcomps, "");
        helpbutton("comparisonofassessments", get_string("comparisonofassessments", "workshop"), "workshop");
    ?>
    </td>
</tr>

<tr valign="top">
    <td align="right"><b><?php  print_string("numberofassessmentsofstudentsubmissions", "workshop") ?>:</b></td>
    <td>
        <?php
        unset($numbers);
        for ($i=20; $i>=0; $i--) {
            $numbers[$i] = $i;
        }
        choose_from_menu($numbers, "nsassessments", $form->nsassessments, "");
       helpbutton("nassessmentsofstudentsubmissions", get_string("numberofassessmentsofstudentsubmissions", "workshop"), "workshop");
        ?>
    </td>
</tr>

<tr valign="top">
    <td align="right"><b><?php  print_string("weightforteacherassessments", "workshop") ?>:</b></td>
    <td>
        <?php
        unset($numbers);
        for ($i=10; $i>=0; $i--) {
            $numbers[$i] = $i;
        }
        choose_from_menu($numbers, "teacherweight", $form->teacherweight, "");
       helpbutton("teacherweight", get_string("weightforteacherassessments", "workshop"), "workshop");
        ?>
    </td>
</tr>

<tr valign="top">
    <td align="right"><b><?php print_string("overallocation", "workshop") ?>:</b></td>
    <td>
        <?php
        unset($numbers);
        for ($i=2; $i>=0; $i--) {
            $numbers[$i] = $i;
        }
        choose_from_menu($numbers, "overallocation", "$form->overallocation", "");
        helpbutton("overallocation", get_string("overallocation", "workshop"), "workshop");
        ?>
    </td>
</tr>

<tr>
    <td align="right"><b><?php  print_string("selfassessment", "workshop") ?>:</b></td>
    <td>
    <?php
        $options[0] = get_string("no"); $options[1] = get_string("yes");
        choose_from_menu($options, "includeself", $form->includeself, "");
        helpbutton("selfassessment", get_string("selfassessment", "workshop"), "workshop");
    ?>
    </td>
</tr>

<tr>
    <td align="right"><b><?php  print_string("assessmentsmustbeagreed", "workshop") ?>:</b></td>
    <td>
    <?php
        choose_from_menu($options, "agreeassessments", $form->agreeassessments, "");
        helpbutton("agreeassessments", get_string("assessmentsmustbeagreed", "workshop"), "workshop");
    ?>
    </td>
</tr>

<tr>
    <td align="right"><b><?php  print_string("hidegradesbeforeagreement", "workshop") ?>:</b></td>
    <td>
    <?php
        choose_from_menu($options, "hidegrades", $form->hidegrades, "");
        helpbutton("showinggrades", get_string("hidegradesbeforeagreement", "workshop"), "workshop");
    ?>
    </td>
</tr>

<tr>
    <td align="right"><b><?php print_string("leaguetable", "workshop"); ?>:</b></td>
    <td>
    <?php
        unset($numbers);
        $numbers[22] = '100';
        $numbers[21] = 50;
        for ($i=20; $i>=0; $i--) {
            $numbers[$i] = $i;
        }
        choose_from_menu($numbers, "showleaguetable", $form->showleaguetable, "");
        helpbutton("leaguetable", get_string("leaguetable", "workshop"), "workshop");
    ?>
    </td>
</tr>

<tr>
    <td align="right"><b><?php print_string("hidenamesfromstudents", "workshop", $course->students) ?>:</b></td>
    <td>
    <?php
        choose_from_menu($options, "anonymous", $form->anonymous, "");
        helpbutton("anonymous", get_string("hidenamesfromstudents", "workshop", $course->students), "workshop");
    ?>
    </td>
</tr>

<tr>
    <td align="right"><b><?php  print_string("usepassword", "workshop"); ?>:</b></td>
    <td>
    <?php
        $options[0] = get_string("no"); $options[1] = get_string("yes");
        choose_from_menu($options, "usepassword", $form->usepassword, "");
        helpbutton("password", get_string("usepassword", "workshop"), "workshop");
    ?>
    </td>
</tr>

<tr>
    <td align="right"><b><?php  print_string("password"); ?>:</b></td>
    <td>
        <input type="text" name="password" size="10" value="" alt="<?php  print_string("password"); ?>" /> <?php echo " (".get_string("leavetokeep").")"; ?>
        <?php helpbutton("password", get_string("password"), "workshop"); ?>
    </td>
</tr>

<tr valign="top">
    <td align="right"><b><?php  print_string("maximumsize", "workshop") ?>:</b></td>
    <td>
        <?php
        $choices = get_max_upload_sizes($CFG->maxbytes, $course->maxbytes);
        choose_from_menu($choices, "maxbytes", "$form->maxbytes","" );
        ?>
    </td>
</tr>

<tr valign="top">
    <td align="right"><b><?php  print_string("submissionstart", "workshop") ?>:</b></td>
    <td><?php
            print_date_selector("submissionstartday", "submissionstartmonth", "submissionstartyear", $form->submissionstart);
            echo "&nbsp;-&nbsp;";
            print_time_selector("submissionstarthour", "submissionstartminute", $form->submissionstart);
            helpbutton("submissionstart", get_string("submissionstart", "workshop"), "workshop");
    ?></td>
</tr>

<tr valign="top">
    <td align="right"><b><?php  print_string("assessmentstart", "workshop") ?>:</b></td>
    <td><?php
            print_date_selector("assessmentstartday", "assessmentstartmonth", "assessmentstartyear", $form->assessmentstart);
            echo "&nbsp;-&nbsp;";
            print_time_selector("assessmentstarthour", "assessmentstartminute", $form->assessmentstart);
            helpbutton("assessmentstart", get_string("assessmentstart", "workshop"), "workshop");
    ?></td>
</tr>

<tr valign="top">
    <td align="right"><b><?php  print_string("submissionend", "workshop") ?>:</b></td>
    <td><?php
            print_date_selector("submissionendday", "submissionendmonth", "submissionendyear", $form->submissionend);
            echo "&nbsp;-&nbsp;";
            print_time_selector("submissionendhour", "submissionendminute", $form->submissionend);
            helpbutton("submissionend", get_string("submissionend", "workshop"), "workshop");
    ?></td>
</tr>

<tr valign="top">
    <td align="right"><b><?php  print_string("assessmentend", "workshop") ?>:</b></td>
    <td><?php
            print_date_selector("assessmentendday", "assessmentendmonth", "assessmentendyear", $form->assessmentend);
            echo "&nbsp;-&nbsp;";
            print_time_selector("assessmentendhour", "assessmentendminute", $form->assessmentend);
            helpbutton("assessmentend", get_string("assessmentend", "workshop"), "workshop");
    ?></td>
</tr>
<tr valign="top">
    <td align="right"><b><?php  print_string("releaseteachergrades", "workshop") ?>:</b></td>
    <td><?php
            print_date_selector("releaseday", "releasemonth", "releaseyear", $form->releasegrades);
            echo "&nbsp;-&nbsp;";
            print_time_selector("releasehour", "releaseminute", $form->releasegrades);
            helpbutton("releasegrades", get_string("releaseteachergrades", "workshop"), "workshop");
    ?></td>
</tr>
<?php 
$features = new stdClass;
$features->groupings = true;
print_standard_coursemodule_settings($form, $features); 
?>
</table>
<br />
<div class="boxaligncenter">
<input type="hidden" name="course"     value="<?php  p($form->course) ?>" />
<input type="hidden" name="sesskey"    value="<?php  p($form->sesskey) ?>" />
<input type="hidden" name="coursemodule"  value="<?php  p($form->coursemodule) ?>" />
<input type="hidden" name="section"    value="<?php  p($form->section) ?>" />
<input type="hidden" name="module"     value="<?php  p($form->module) ?>" />
<input type="hidden" name="modulename" value="<?php  p($form->modulename) ?>" />
<input type="hidden" name="instance"   value="<?php  p($form->instance) ?>" />
<input type="hidden" name="mode"       value="<?php  p($form->mode) ?>" />
<input type="submit" value="<?php  print_string("savechanges") ?>" />
<input type="submit" name="cancel" value="<?php  print_string("cancel") ?>" />
</div>
</form>
