<?php
    // Make sure all variables are defined
    if (!isset($form->showreports)) {
        $form->showreports = 0;
    }
    if (!isset($form->maxbytes)) {
        $form->maxbytes = 0;
    }
    if (!isset($form->hiddensections)) {
        $form->hiddensections = 0;
    }
    if (!isset($form->lang)) {
        $form->lang = '';
    }
    if (!isset($form->theme)) {
        $form->theme = '';
    }
    if (!isset($form->enrol)) {
        $form->enrol = '';
    }
    if (!isset($form->enrollable)) {
        $form->enrollable = 1;
    }
    if (!isset($form->enrolstartdate)) {
        $form->enrolstartdate = 0;
    }
    if (!$form->enrolstartdate) {
        $form->enrolstartdisabled = 1;
    }
    if (!isset($form->enrolenddate)) {
        $form->enrolenddate = 0;
    }
    if (!$form->enrolenddate) {
        $form->enrolenddisabled = 1;
    }
    if (!isset($form->enrolperiod)) {
        $form->enrolperiod = 0;
    }
    if (!isset($form->expirynotify)) {
        $form->expirynotify = 0;
    }
    if (!isset($form->notifystudents)) {
        $form->notifystudents = 0;
    }
    if (!isset($form->expirythreshold)) {
        $form->expirythreshold = 10 * 86400;
    }
    if (!isset($form->metacourse)) {
        $form->metacourse = 0;
    }
    if(!isset($form->restrictmodules)) {
        $form->restrictmodules = 0;
    }
?>
<form method="post" action="edit.php" name="form">
<table cellpadding="9" cellspacing="0" >
<?php if (iscreator()) { ?>
<tr valign="top">
    <td align="right"><?php  print_string("category") ?>:</td>
    <td><?php
           $displaylist = array();
           $parentlist = array();
           make_categories_list($displaylist, $parentlist);
           choose_from_menu($displaylist, "category", "$form->category", "");
           helpbutton("coursecategory", get_string("category"));
        ?>
    </td>
</tr>
<?php } ?>
<tr valign="top">
    <td align="right"><?php  print_string("fullname") ?>:</td>
    <td><input type="text" name="fullname" maxlength="254" size="50" value="<?php  p($form->fullname) ?>" alt="<?php  print_string("fullname") ?>" />
    <?php  helpbutton("coursefullname", get_string("fullname")) ?>
    <?php  if (isset($err["fullname"])) formerr($err["fullname"]); ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("shortname") ?>:</td>
    <td><input type="text" name="shortname" maxlength="15"  size="10" value="<?php  p($form->shortname) ?>" alt="<?php  print_string("shortname") ?>" />
    <?php  helpbutton("courseshortname", get_string("shortname")) ?>
    <?php  if (isset($err["shortname"])) formerr($err["shortname"]); ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("idnumber") ?>:</td>
    <td><input type="text" name="idnumber" maxlength="100"  size="10" value="<?php  p($form->idnumber) ?>" alt="><?php  print_string("idnumber") ?>" />
    <?php  helpbutton("courseidnumber", get_string("idnumber")) ?>
    <?php  if (isset($err["idnumber"])) formerr($err["idnumber"]); ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("summary") ?>:</td>
    <td><?php
        print_textarea($usehtmleditor, 10, 50, 660, 200, "summary", $form->summary);
        helpbutton("text", get_string("helptext"));
        if (isset($err["summary"])) formerr($err["summary"]);
    ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("format") ?>:</td>
    <td><?php
           choose_from_menu ($form->courseformats, "format", "$form->format", "");
           helpbutton("courseformats", get_string("courseformats"));
        ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("startdate") ?>:</td>
    <td><?php
           print_date_selector("startday", "startmonth", "startyear", $form->startdate);
           helpbutton("coursestartdate", get_string("startdate"));
    ?></td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("enrolmentplugins") ?>:</td>
    <td><?php
            unset($choices);
            $modules = explode(',', $CFG->enrol_plugins_enabled);
            foreach ($modules as $module) {
                $name = get_string("enrolname", "enrol_$module");
                $plugin = enrolment_factory::factory($module);
                if (method_exists($plugin, 'print_entry')) {
                    $choices[$name] = $module;
                }
            }
            asort($choices);
            $choices = array_flip($choices);
            $choices = array_merge(array('' => get_string('sitedefault').' ('.get_string("enrolname", "enrol_$CFG->enrol").')'), $choices);
            choose_from_menu ($choices, "enrol", "$form->enrol", "");
            helpbutton("courseenrolmentplugins", get_string("enrolmentplugins"));
    ?></td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("enrollable") ?>:</td>
    <td><?php
            unset($choices);
            $choices["0"] = get_string("no");
            $choices["1"] = get_string("yes");
            $choices["2"] = get_string("enroldate");
            choose_from_radio ($choices, "enrollable", "$form->enrollable", "");
            helpbutton("courseenrollable", get_string("enrollable"));
    ?></td>
</tr>
<tr valign="top" id="daterange">
    <td align="right"><?php  print_string("enroldate") ?>:</td>
    <td>
        <table cellpadding="0" cellspacing="0">
            <tr>
                <td align="right"><?php print_string('enrolstartdate') ?>: </td>
                <td><?php
                    print_date_selector("enrolstartday", "enrolstartmonth", "enrolstartyear", $form->enrolstartdate);
                    print_string('disable');
                    echo ': ';
                    print_checkbox('enrolstartdisabled', 1, "$form->enrolstartdisabled");
                    ?></td>
            </tr>
            <tr>
                <td height="18" colspan="2"> </td>
            </tr>
            <tr>
                <td align="right"><?php print_string('enrolenddate') ?>: </td>
                <td><?php
                    print_date_selector("enrolendday", "enrolendmonth", "enrolendyear", $form->enrolenddate);
                    print_string('disable');
                    echo ': ';
                    print_checkbox('enrolenddisabled', 1, "$form->enrolenddisabled");
                    if (isset($err["enroldate"])) formerr($err["enroldate"]);
                    ?></td>
            </tr>
        </table>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("enrolperiod") ?>:</td>
    <td>
        <?php
            $periodmenu[0] = get_string('unlimited');
            for ($i=1; $i<=365; $i++) {
                $seconds = $i * 86400;
                $periodmenu[$seconds] = get_string('numdays', '', $i);
            }
            choose_from_menu ($periodmenu, "enrolperiod", "$form->enrolperiod", "");
            helpbutton("enrolperiod", get_string("enrolperiod"));
        ?>
    </td>
</tr><tr valign="top">
    <td align="right"><?php  print_string("expirynotify") ?>:</td>
    <td>
        <?php
            unset($choices);
            $choices["0"] = get_string("no");
            $choices["1"] = get_string("yes");
            choose_from_menu ($choices, "expirynotify", "$form->expirynotify", "");
            helpbutton("expirynotify", get_string("expirynotify"));

            echo '&nbsp;&nbsp;&nbsp;&nbsp;';
            print_string('expirynotifystudents');
            echo ': ';
            choose_from_menu ($choices, "notifystudents", "$form->notifystudents", "");
            helpbutton("expirynotifystudents", get_string("expirynotifystudents"));

            echo '&nbsp;&nbsp;&nbsp;&nbsp;';
            print_string('expirythreshold');
            echo ': ';
            for ($i=1; $i<=30; $i++) {
                $seconds = $i * 86400;
                $thresholdmenu[$seconds] = get_string('numdays', '', $i);
            }
            choose_from_menu ($thresholdmenu, "expirythreshold", "$form->expirythreshold", "");
            helpbutton("expirythreshold", get_string("expirythreshold"));
        ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("numberweeks") ?>:</td>
    <td><?php
           for ($i=1; $i<=52; $i++) {
              $sectionmenu[$i] = "$i";
           }
           choose_from_menu ($sectionmenu, "numsections", "$form->numsections", "");
           helpbutton("coursenumsections", get_string("numberweeks"));
    ?></td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("groupmode") ?>:</td>
    <td><?php
    unset($choices);
    $choices[NOGROUPS] = get_string("groupsnone");
    $choices[SEPARATEGROUPS] = get_string("groupsseparate");
    $choices[VISIBLEGROUPS] = get_string("groupsvisible");
    choose_from_menu ($choices, "groupmode", $form->groupmode, "");
    helpbutton("groupmode", get_string("groupmode"));

    echo '&nbsp;&nbsp;&nbsp;&nbsp;';
    print_string('force');
    echo ': ';
    unset($choices);
    $choices["0"] = get_string("no");
    $choices["1"] = get_string("yes");
    choose_from_menu ($choices, "groupmodeforce", $form->groupmodeforce, "");
    helpbutton("groupmodeforce", get_string("groupmodeforce")); ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("availability") ?>:</td>
    <td><?php
    unset($choices);
    $choices["0"] = get_string("courseavailablenot");
    $choices["1"] = get_string("courseavailable");
    choose_from_menu ($choices, "visible", $form->visible, "");
    helpbutton("courseavailability", get_string("availability")); ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("enrolmentkey") ?>:</td>
    <td><input type="text" name="password" size="25" value="<?php  p($form->password) ?>" alt="<?php  print_string("enrolmentkey") ?>" />
    <?php  helpbutton("enrolmentkey", get_string("enrolmentkey")) ?>
    <?php  if (isset($err["password"])) formerr($err["password"]); ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("opentoguests") ?>:</td>
    <td><?php
    unset($choices);
    $choices["0"] = get_string("guestsno");
    $choices["1"] = get_string("guestsyes");
    $choices["2"] = get_string("guestskey");
    choose_from_menu ($choices, "guest", $form->guest, "");
    helpbutton("guestaccess", get_string("opentoguests")); ?>
    </td>
</tr>
<?php
    if (method_exists(enrolment_factory::factory($course->enrol), 'print_entry') && $course->enrol != 'manual') {
?>
<tr valign="top">
    <td align="right"><?php  print_string("cost") ?>:</td>
    <td><input type="text" name="cost" maxlength="6" size="6" value="<?php  p($form->cost) ?>" alt="<?php  print_string("cost") ?>" />
    <?php
        $currencies = get_list_of_currencies();
        choose_from_menu($currencies, 'currency', $form->currency, '');
        helpbutton("cost", get_string("cost"));
    ?>
    </td>
</tr>
<?php
    }
?>
<tr valign="top">
    <td align="right"><?php  print_string("hiddensections") ?>:</td>
    <td><?php
    unset($choices);
    $choices["0"] = get_string("hiddensectionscollapsed");
    $choices["1"] = get_string("hiddensectionsinvisible");
    choose_from_menu ($choices, "hiddensections", $form->hiddensections, "");
    helpbutton("coursehiddensections", get_string("hiddensections")); ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("newsitemsnumber") ?>:</td>
    <td><?php
       $newsitem = get_string("newsitem");
       $newsitems = get_string("newsitems");

       $options = array("0" => "0 $newsitems",
                        "1" => "1 $newsitem",
                        "2" => "2 $newsitems",
                        "3" => "3 $newsitems",
                        "4" => "4 $newsitems",
                        "5" => "5 $newsitems",
                        "6" => "6 $newsitems",
                        "7" => "7 $newsitems",
                        "8" => "8 $newsitems",
                        "9" => "9 $newsitems",
                        "10" => "10 $newsitems");
       choose_from_menu ($options, "newsitems", "$form->newsitems", "");
       helpbutton("coursenewsitems", get_string("newsitemsnumber"));
    ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("showgrades") ?>:</td>
    <td><?php
    unset($choices);
    $choices["0"] = get_string("no");
    $choices["1"] = get_string("yes");
    choose_from_menu ($choices, "showgrades", $form->showgrades, "");
    helpbutton("coursegrades", get_string("grades")); ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("showreports") ?>:</td>
    <td><?php
    unset($choices);
    $choices["0"] = get_string("no");
    $choices["1"] = get_string("yes");
    choose_from_menu ($choices, "showreports", $form->showreports, "");
    helpbutton("coursereports", get_string("activityreport")); ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("maximumupload") ?>:</td>
    <td><?php
    $choices = get_max_upload_sizes($CFG->maxbytes);
    choose_from_menu ($choices, "maxbytes", $form->maxbytes, "");
    helpbutton("courseuploadsize", get_string("maximumupload")); ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("wordforteacher") ?>:</td>
    <td><input type="text" name="teacher" maxlength="100" size="25" value="<?php  p($form->teacher) ?>" alt="<?php  print_string("wordforteacher") ?>" />
    (<?php  print_string("wordforteachereg") ?>)
    <?php  if (isset($err["teacher"])) formerr($err["teacher"]); ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("wordforteachers") ?>:</td>
    <td><input type="text" name="teachers" maxlength="100" size="25" value="<?php  p($form->teachers) ?>" alt="<?php  print_string("wordforteachers") ?>" />
    (<?php  print_string("wordforteacherseg") ?>)
    <?php  if (isset($err["teachers"])) formerr($err["teachers"]); ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("wordforstudent") ?>:</td>
    <td><input type="text" name="student" maxlength="100" size="25" value="<?php  p($form->student) ?>" alt="<?php  print_string("wordforstudent") ?>" />
    (<?php  print_string("wordforstudenteg") ?>)
    <?php  if (isset($err["student"])) formerr($err["student"]); ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("wordforstudents") ?>:</td>
    <td><input type="text" name="students" maxlength="100" size="25" value="<?php  p($form->students) ?>" alt="<?php  print_string("wordforstudents") ?>" />
    (<?php  print_string("wordforstudentseg") ?>)
    <?php  if (isset($err["students"])) formerr($err["students"]); ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><?php  print_string("forcelanguage") ?>:</td>
  <td>
    <?php
        $languages[''] = get_string("forceno");
        $languages += get_list_of_languages();
        choose_from_menu ($languages, "lang", $form->lang, "", "", "");
    ?>
    </td>
</tr>
<?php if (!empty($CFG->allowcoursethemes)) { ?>
<tr valign="top">
    <td align="right"> <?php print_string("forcetheme") ?>: </td>
    <td>
      <?php
         $themes[''] = get_string("forceno");
         $themes += get_list_of_themes();
         choose_from_menu($themes, 'theme', $form->theme, "", "", "");
      ?>
    </td>
</tr>
<?php } ?>
<tr valign="top">
  <td align="right"><?php print_string("managemeta") ?>:</td>
    <td>
      <?php
      if (empty($disable_meta)) {
          $meta[0] = get_string('no');
          $meta[1] = get_string('yes');
          choose_from_menu($meta,"metacourse",$form->metacourse,"","","");
      } else {
          echo ((empty($form->metacourse)) ? get_string("no") : get_string("yes"));
          echo " - $disable_meta ";
      }
      helpbutton("metacourse", get_string("metacourse"));?>
    </td>
</tr>
<?php if (isadmin() && ((!empty($course->requested) && $CFG->restrictmodulesfor == 'requested') || $CFG->restrictmodulesfor == 'all')) { ?>
<tr valign="top">
    <td align="right"><?php print_string("restrictmodules") ?>:</td>
    <td valign="top"><table cellpadding="0" border="0"><tr valign="top"><td>
    <script language="JavaScript">
    function togglemodules(index) {
        if (index == 0) {
            document.getElementById('allowedmods').disabled=true;
        }
        else {
            document.getElementById('allowedmods').disabled=false;
        }
    }
    </script>
    <?php
    unset($options);
    $options[0] = get_string("no");
    $options[1] = get_string("yes");
    choose_from_menu($options,"restrictmodules",$form->restrictmodules,"","togglemodules(this.selectedIndex);","");
?>&nbsp;</td><td>&nbsp;<?php p(strtolower(get_string('to'))); ?>&nbsp;</td><td>&nbsp;
    <select name="allowedmods[]" id="allowedmods" multiple="multiple" size="10" <?php echo ((empty($form->restrictmodules)) ? "disabled=\"disabled\"" : ""); ?>>
    <?php
    $mods = get_records("modules");
    $s = "selected=\"selected\"";
    echo '<option value="0" '.((empty($allowedmods)) ? $s : '').'>'.get_string('allownone').'</option>'."\n";
    foreach ($mods as $mod) {
        $selected = "";
        if (in_array($mod->id,$allowedmods)) 
            $selected = $s;
        echo '<option '.$selected.' value="'.$mod->id.'">'.$mod->name.'</option>'."\n";
    }  
    ?>
    </select></td></tr></table></td>
</tr>
<?php } else { ?>
   <input type="hidden" name="restrictmodules" value="<?php p($form->restrictmodules); ?>" />
<?php } ?>
<tr>
    <td></td>
    <td><input type="submit" value="<?php  print_string("savechanges") ?>" /></td>
</tr>
</table>
<?php if(!iscreator()) { ?>
<input type="hidden" name="category" value="<?php echo $form->category ?>" />
<?php } ?>
<input type="hidden" name="id" value="<?php echo $form->id ?>" />
<input type="hidden" name="sesskey" value="<?php echo $form->sesskey ?>" />
</form>
