<!-- This page defines the form to add an appointment session -->
<!-- it is used from view.php -->

<form name="add" method="post" action="view.php">
<input type="hidden" name="what" value="doaddsession" />
<input type="hidden" name="id" value="<?php p($cm->id) ?>" />
<input type="hidden" name="page" value="<?php p($page) ?>" />
<?php 
if (!has_capability('mod/scheduler:canscheduletootherteachers', $context)){
?>
<input type="hidden" name="teacherid" value="<?php p($form->teacherid) ?>" />
<?php
}
?>
<center>
<table cellpadding="5">
    <tr>
        <td align="right"><b><?php print_string('date', 'scheduler') ?>:</b></td>
        <td align="left" <?php print_error_class(@$errors, 'rangestart,range') ?> >
            <?php print_date_selector('startday', 'startmonth', 'startyear', $form->rangestart); ?>
        </td>
    </tr>
    <tr valign="top">
        <td align="right"><b><?php print_string('enddate', 'scheduler') ?>:</b></td>
        <td align="left" <?php print_error_class(@$errors, 'rangeend,range') ?> >
            <?php print_date_selector('endday', 'endmonth', 'endyear', $form->rangeend); ?>
        </td>
    </tr>
    <div id="advanced" name="advanced" style="visibility:visible;">
    <tr valign="top">
        <td align="right"><b><?php print_string('addondays', 'scheduler') ?>:</b></td>
        <td align="left" <?php print_error_class(@$errors, 'days,range') ?> >
            <input type="checkbox" <?php echo ($form->monday) ? 'checked="checked"' : '' ; ?> name="monday" value="1" /> <?php print_string('monday', 'scheduler') ; ?><br>
            <input type="checkbox" <?php echo ($form->tuesday) ? 'checked="checked"' : '' ; ?> name="tuesday" value="1" /> <?php print_string('tuesday', 'scheduler');  ?><br>
            <input type="checkbox" <?php echo ($form->wednesday) ? 'checked="checked"' : '' ; ?> name="wednesday" value="1" /> <?php print_string('wednesday', 'scheduler');  ?><br>
            <input type="checkbox" <?php echo ($form->thursday) ? 'checked="checked"' : '' ; ?> name="thursday" value="1" /> <?php print_string('thursday', 'scheduler')  ?><br>
            <input type="checkbox" <?php echo ($form->friday) ? 'checked="checked"' : '' ; ?> name="friday" value="1" /> <?php print_string('friday', 'scheduler')  ?><br>
            <input type="checkbox" <?php echo ($form->saturday) ? 'checked="checked"' : '' ; ?> name="saturday" value="1" /> <?php print_string('saturday', 'scheduler')  ?><br>
            <input type="checkbox" <?php echo ($form->sunday) ? 'checked="checked"' : '' ; ?> name="sunday" value="1" /> <?php print_string('sunday', 'scheduler')  ?>
        </td>
    </tr>
    <tr valign="top">
        <td align="right"><b><?php print_string('starttime', 'scheduler') ?>:</b></td>
        <td align="left">
            <?php print_time_selector('starthour', 'startminute', $form->timestart, 5); ?>
        </td>
    </tr>
    <tr valign="top">
        <td align="right"><b><?php print_string('endtime', 'scheduler') ?>:</b></td>
        <td align="left">
            <?php print_time_selector('endhour', 'endminute', $form->timeend, 5); ?>
        </td>
    </tr>
    <tr valign="top">
        <td align="right"><b><?php print_string('forcewhenoverlap', 'scheduler') ?>:</b></td>
        <td align="left">
            <input type="radio" name="forcewhenoverlap" value="1" <?php echo ($form->forcewhenoverlap) ? 'checked="checked"' : '' ; ?> />
            <?php print_string('yes') ?>
            <input type="radio" name="forcewhenoverlap" value="0" <?php echo (!$form->forcewhenoverlap) ? 'checked="checked"' : '' ; ?> />
            <?php print_string('no') ?>
            <?php helpbutton('forcewhenoverlap', get_string('forcewhenoverlap', 'scheduler'), 'scheduler'); ?>
        </td>
    </tr>
    <tr valign="top">
        <td align="right"><b><?php print_string('location', 'scheduler') ?>:</b></td>
        <td align="left">
            <input type="text" size="30" maxlength="50" name="appointmentlocation" value="" />
        </td>
    </tr>
<?php
if (has_capability('mod/scheduler:canscheduletootherteachers', $context)){
?>
    <tr valign="top">
        <td align="right"><b><?php echo format_string($scheduler->staffrolename) ?>:</b></td>
        <td align="left" <?php print_error_class(@$errors, 'teacherid') ?> >
            <?php
                $coursecontext = get_context_instance(CONTEXT_COURSE, $COURSE->id);
                if (has_capability('moodle/legacy:teacher', $coursecontext) && !has_capability('mod/scheduler:attend', $context)){
                    $teachers = get_record('user', 'id', $USER->id, 'lastname', 'id,lastname,firstname,email,picture');
                } else {
                    $teachers = array();
                }
                $teachers = array_merge($teachers, get_users_by_capability ($context, 'mod/scheduler:attend', 'u.id,lastname,firstname,email,picture', 'lastname'));
                $teachersmenu = array();
                if ($teachers){
                    foreach($teachers as $aTeacher){
                        $teachersmenu[$aTeacher->id] = fullname($aTeacher);
                    }
                    choose_from_menu($teachersmenu, 'teacherid', $form->teacherid);
                } else {
                   print_string('noteachershere', 'scheduler', format_string($scheduler->staffrolename));
                }
                helpbutton('bookwithteacher', get_string('bookwithteacher', 'scheduler'), 'scheduler'); 
            ?>
        </td>
    </tr>
<?php
}
?>
    <tr valign="top">
        <td align="right"><b><?php print_string('divide', 'scheduler') ?>:</b></td>
        <td align="left">
            <input type="radio" name="hasslots" value="1" checked="checked" />
            <?php print_string('yes') ?>
            <input type="radio" name="hasslots" value="0" />
            <?php print_string('no') ?>
        </td>
    </tr>
    <tr valign="top">
        <td align="right"><b><?php print_string('duration', 'scheduler') ?>:</b></td>
        <td align="left">
            <input type="text" size="3" maxlength="3" name="duration" value="<?php echo $form->duration ?>" />
            <?php print_string('minutesperslot', 'scheduler') ?>
        </td>
    </tr>
    <tr valign="top">
        <td align="right"><b><?php print_string('multiplestudents', 'scheduler') ?>:</b></td>
        <td align="left">
            <?php
                $exclusivemenu['0'] = get_string('unlimited', 'scheduler');
                for($i = 1 ; $i < 10 ; $i++){
                    $exclusivemenu[(string)$i] = $i;
                }
                choose_from_menu($exclusivemenu, 'exclusivity', $form->exclusivity, '');
            ?>
        </td>
    </tr>
    <tr valign="top">
        <td align="right"><b><?php  print_string('reuse', 'scheduler') ?>:</b></td>
        <td align="left">
            <?php
                $reusemenu[0] = get_string('no');
                $reusemenu[1] = get_string('yes');
                choose_from_menu($reusemenu, 'reuse', $form->reuse, '');
                helpbutton('reuse', get_string('reuse', 'scheduler'), 'scheduler');
            ?>
        </td>
    </tr>
    <tr valign="top">
        <td align="right"><b><?php print_string('displayfrom', 'scheduler') ?>:</b></td>
        <td align="left">
            <select name="displayfrom" size="1">
                <option selected value="now"><?php print_string('now', 'scheduler') ?></option>
                <option value="86400"><?php print_string('1daybefore', 'scheduler') ?></option>
<?php
for ($i = 2; $i < 7; $i++){
?>
                <option value="<?php echo (86400*$i); ?>"><?php echo $i; print_string('xdaysbefore', 'scheduler') ?></option>
<?php
}
?>
                <option value="<?php echo (86400*7); ?>"><?php  print_string('1weekbefore', 'scheduler') ?></option>
<?php
for ($i = 2; $i < 7; $i++){
?>
                <option value="<?php echo (86400*$i*7); ?>"><?php echo $i; print_string('xweeksbefore', 'scheduler') ?></option>
<?php
}
?>
            </select>
        </td>
    </tr>
    <tr valign="top">
        <td align="right"><b><?php print_string('emailreminder', 'scheduler') ?>:</b></td>
        <td align="left">
            <select name="emailfrom" size="1">
                <option selected value="never"><?php  print_string('never', 'scheduler') ?></option>
                <option value="0"><?php print_string('onthemorningofappointment', 'scheduler') ?></option>
                <option value="86400"><?php print_string('1daybefore', 'scheduler') ?></option>
<?php
for ($i = 2; $i < 7; $i++){
?>
                <option value="<?php echo (DAYSECS * $i); ?>"><?php echo $i; print_string('xdaysbefore', 'scheduler') ?></option>
<?php
}
?>
                <option value="<?php echo (DAYSECS * 7); ?>"><?php  print_string('1weekbefore', 'scheduler') ?></option>
<?php
for ($i = 2; $i < 7; $i++){
?>
                <option value="<?php echo (DAYSECS * $i * 7); ?>"><?php echo $i; print_string('xweeksbefore', 'scheduler') ?></option>
<?php
}
?>
            </select>
        </td>
    </tr>
</table>
<input type="submit" value="<?php print_string('savechanges') ?>" />
<input type="button" value="<?php print_string('cancel') ?>" onclick="self.location.href='view.php?id=<?php p($cm->id) ?>'" />
</center>
</form>