if (has_capability('mod/scheduler:manageallappointments', $context) && $subpage == 'allappointments') {
        $delbuttons[] = $commandbar->action_link(new moodle_url($actionurl, array('what' => 'deleteall')), 'deleteallslots', 't/delete', 'confirmdelete');
        $delbuttons[] = $commandbar->action_link(new moodle_url($actionurl, array('what' => 'deleteallunused')), 'deleteallunusedslots', 't/delete', 'confirmdelete');
    }
    $delbuttons[] = $commandbar->action_link(new moodle_url($actionurl, array('what' => 'deleteunused')), 'deleteunusedslots', 't/delete', 'confirmdelete');
    $delbuttons[] = $commandbar->action_link(new moodle_url($actionurl, array('what' => 'deleteonlymine')), 'deletemyslots', 't/delete', 'confirmdelete');
    $commandbar->add_group(get_string('deletecommands', 'scheduler'), $delbuttons);
}
echo $output->render($commandbar);
// Some slots already exist - prepare the table of slots.
if ($slots) {
    $slotman = new scheduler_slot_manager($scheduler, $actionurl);
    $slotman->showteacher = $subpage == 'allappointments';
    foreach ($slots as $slot) {
        $editable = $USER->id == $slot->teacherid || has_capability('mod/scheduler:manageallappointments', $context);
        $studlist = new scheduler_student_list($slotman->scheduler);
        $studlist->expandable = false;
        $studlist->expanded = true;
        $studlist->editable = $editable;
        $studlist->linkappointment = true;
        $studlist->checkboxname = 'seen[]';
        $studlist->buttontext = get_string('saveseen', 'scheduler');
        $studlist->actionurl = new moodle_url($actionurl, array('what' => 'saveseen', 'slotid' => $slot->id));
        foreach ($slot->get_appointments() as $app) {
            $studlist->add_student($app, false, $app->is_attended());
        }
        $slotman->add_slot($slot, $studlist, $editable);
    }
    echo $output->render($slotman);
    if ($sqlcount > $pagesize) {
        echo $output->paging_bar($sqlcount, $offset, $pagesize, $actionurl, 'offset');
     echo html_writer::div($noslots, 'studentbookingmessage');
 } else {
     // The student can book further appointments, and slots are available.
     // Show the booking form.
     $booker = new scheduler_slot_booker($scheduler, $USER->id, $actionurl, $bookablecnt);
     $pagesize = 25;
     $total = count($bookableslots);
     $start = $offset >= 0 ? $offset * $pagesize : 0;
     $end = $start + $pagesize;
     if ($end > $total) {
         $end = $total;
     }
     for ($idx = $start; $idx < $end; $idx++) {
         $slot = $bookableslots[$idx];
         if ($slot->is_groupslot() && has_capability('mod/scheduler:seeotherstudentsbooking', $context)) {
             $others = new scheduler_student_list($scheduler, false);
             foreach ($slot->get_appointments() as $otherapp) {
                 $others->add_student($otherapp, $otherapp->studentid == $USER->id);
             }
             $others->expandable = true;
             $others->expanded = false;
         } else {
             $others = null;
         }
         // Check what to print as group information...
         if ($slot->exclusivity == 0) {
             $groupinfo = get_string('yes');
         } else {
             if ($slot->exclusivity == 1) {
                 $groupinfo = get_string('no');
             } else {