<!-- This page defines the form to choose an appointed student within an appointment list -->

<?php
$usehtmleditor = can_use_html_editor();
?>

<form name="appoint" method="post" action="view.php" method="POST">
<input type="hidden" name="what" value="<?php p($form->what) ?>" />
<input type="hidden" name="subaction" value="doaddappointed" />
<input type="hidden" name="id" value="<?php p($cm->id) ?>" />
<input type="hidden" name="page" value="<?php p($page) ?>" />
<input type="hidden" name="offset" value="<?php p($offset) ?>" />
<?php 
if ($form->what == 'updateslot' || $form->what == 'schedule'){
?>
<input type="hidden" name="slotid" value="<?php p($form->slotid) ?>" />
<input type="hidden" name="studentid" value="<?php p($form->studentid) ?>" />
<?php
}
?>
<input type="hidden" name="appointments" value="<?php p(serialize($form->appointments)) ?>" />
<input type="hidden" name="appointmentssaved" value="<?php p(serialize($form->appointmentssaved)) ?>" />
<input type="hidden" name="teacherid" value="<?php p($form->teacherid) ?>" />
<input type="hidden" name="exclusivity" value="<?php p($form->exclusivity) ?>" />
<input type="hidden" name="reuse" value="<?php p($form->reuse) ?>" />
<input type="hidden" name="starttime" value="<?php p($form->starttime) ?>" />
<input type="hidden" name="duration" value="<?php p($form->duration) ?>" />
<input type="hidden" name="appointmentlocation" value="<?php p($form->appointmentlocation) ?>" />
<input type="hidden" name="notes" value="<?php p($form->notes) ?>" />
<input type="hidden" name="hideuntil" value="<?php p($form->hideuntil) ?>" />
<center>
<table cellpadding="5">
<tr valign="top">
    <td align="right"><b><?php print_string('student', 'scheduler') ?>:</b></td>
    <td align="left">
<?php
        $students = get_users_by_capability($context, 'mod/scheduler:appoint', 'u.id, firstname, lastname', 'lastname');
        if ($students){
            $studentsmenu = array();
            foreach ($students as $aStudent) {
                if ($scheduler->schedulermode == 'oneonly' AND scheduler_has_slot($aStudent->id, $scheduler, true, false, $form->slotid)) continue;
                if ($scheduler->schedulermode == 'onetime' AND scheduler_has_slot($aStudent->id, $scheduler, true, true, $form->slotid)) continue;
                if ($form->appointments and $subaction == 'addappointed'){
                    if (in_array($aStudent->id, array_keys($form->appointments))) continue; // is already added 
                }
                $studentsmenu[$aStudent->id] = fullname($aStudent);
            }
            if (!empty($studentsmenu)){
                choose_from_menu($studentsmenu, 'studenttoadd', $form->studentid);
                if ($action == 'update'){
                    $addstudenttogroupstr = get_string('addstudenttogroup', 'scheduler');
                    echo "&nbsp;<input type=\"button\" value=\"{$addstudenttogroupstr}\" onclick=\"addToGroup()\" />";
                    helpbutton('addscheduled', get_string('addscheduled', 'scheduler'), 'scheduler');
                }
            }
            else{
                print_string('nostudenttobook', 'scheduler');            
            }
        }
        else{
           print_string('nostudenttobook', 'scheduler');            
        }
?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><b><?php print_string('seen', 'scheduler') ?>:</b></td>
    <td align="left">
        <input type="radio" name="attended" value="1" <?php if ($form->attended == 1){ echo 'checked';} ?> />
        <?php print_string('yes') ?>
        <input type="radio" name="attended" value="0" <?php if ($form->attended == 0){ echo 'checked';} ?> />
        <?php print_string('no') ?>
    </td>
</tr>
<tr valign="top">
    <td align="right"><b><?php print_string('appointmentnotes', 'scheduler') ?>:</b></td>
    <td align="left">
        <?php
            if (!isset($form->appointmentnote)) {
                $form->appointmentnote = '';
            }
            print_textarea($usehtmleditor, 20, 60, 680, 400, 'appointmentnote', $form->appointmentnote);
            if ($usehtmleditor) {
                echo '<input type="hidden" name="appointmentformat" value="'.FORMAT_HTML.'" />';
            } 
            else {
                echo '<p align="right">';
                helpbutton('textformat', get_string('formattexttype'));
                print_string('formattexttype');
                echo ':&nbsp;';
                if (empty($form->appointmentformat)) {
                    $form->appointmentformat = "MOODLE";
                }
                choose_from_menu(format_text_menu(), 'appointmentformat', $form->appointmentformat, ""); 
                echo '</p>';
            }
        ?>
    </td>
</tr>
<?php
if ($scheduler->scale != 0){
?>
<tr>
    <td align="right"><b><?php print_string('grade') ?>:</b></td>
    <td align="left">
        <?php scheduler_make_grading_menu($scheduler, 'grade', $form->grade, false); ?>
    </td>
</tr>
<?php
}
$onsubmitcall = ($usehtmleditor) ? "javascript:document.forms['appoint'].onsubmit();" : '' ;
?>
</table>
<input type="button" value="<?php  print_string('confirm') ?>" onclick="<?php echo $onsubmitcall ?>document.forms['appoint'].submit();" />
<input type="button" value="<?php  print_string('cancel') ?>" onclick="document.forms['appoint'].subaction.value = 'cancel'; document.forms['appoint'].submit();" />
</center>
</form>
