$slots = get_records('scheduler_slots', 'schedulerid', $scheduler->id, 'starttime', 'id, starttime, duration, exclusivity, teacherid, hideuntil');
 if ($subaction == 'slots') {
     /// Making title line
     $stream .= get_string('date', 'scheduler') . $csvfieldseparator;
     $stream .= get_string('starttime', 'scheduler') . $csvfieldseparator;
     $stream .= get_string('endtime', 'scheduler') . $csvfieldseparator;
     $stream .= get_string('slottype', 'scheduler') . $csvfieldseparator;
     $stream .= get_string('students', 'scheduler') . $csvrecordseparator;
     /// Print all the lines of data.
     if (!empty($slots)) {
         foreach ($slots as $slot) {
             $appointments = get_records('scheduler_appointment', 'slotid', $slot->id);
             /// fill slot data
             $datestart = scheduler_userdate($slot->starttime, 1);
             $timestart = scheduler_usertime($slot->starttime, 1);
             $timeend = scheduler_usertime($slot->starttime + $slot->duration * 60, 1);
             $stream .= $datestart . $csvfieldseparator;
             $stream .= $timestart . $csvfieldseparator;
             $stream .= $timeend . $csvfieldseparator;
             switch ($slot->exclusivity) {
                 case 0:
                     $stream .= get_string('unlimited', 'scheduler') . $csvfieldseparator;
                     break;
                 case 1:
                     $stream .= get_string('exclusive', 'scheduler') . $csvfieldseparator;
                     break;
                 default:
                     $stream .= get_string('limited', 'scheduler') . ' ' . ($slot->exclusivity - count($appointments)) . $csvfieldseparator;
             }
             if (!empty($appointments)) {
                 $appointedlist = '';
     print_table($table);
 }
 /// prepare appointable slot table
 print_heading(get_string('slots', 'scheduler'));
 unset($table);
 $table->head = array($strdate, $strstart, $strend, get_string('choice', 'scheduler'), format_string($scheduler->staffrolename), get_string('groupsession', 'scheduler'));
 $table->align = array('LEFT', 'LEFT', 'CENTER', 'CENTER', 'LEFT');
 $table->data = array();
 $previousdate = '';
 $previoustime = 0;
 $previousendtime = 0;
 $canappoint = false;
 foreach ($studentSlots as $key => $aSlot) {
     $startdate = scheduler_userdate($aSlot->starttime, 1);
     $starttime = scheduler_usertime($aSlot->starttime, 1);
     $endtime = scheduler_usertime($aSlot->starttime + $aSlot->duration * 60, 1);
     $startdatestr = $startdate == $previousdate ? '' : $startdate;
     $starttimestr = $starttime == $previoustime ? '' : $starttime;
     $endtimestr = $endtime == $previousendtime ? '' : $endtime;
     if ($aSlot->appointedbyme and !$aSlot->attended) {
         $radio = "<input type=\"radio\" name=\"slotid\" value=\"{$aSlot->id}\" checked=\"checked\" />\n";
         $table->data[] = array("<b>{$startdatestr}</b>", "<b>{$starttime}</b>", "<b>{$endtime}</b>", $radio, "<b>" . "<a href=\"../../user/view.php?id={$aSlot->teacherid}&amp;course={$scheduler->course}\">" . fullname(get_record('user', 'id', $aSlot->teacherid)) . '</a></b>', '<b>' . $aSlot->groupsession . '</b>');
     } else {
         if ($aSlot->appointed and has_capability('mod/scheduler:seeotherstudentsbooking', $context)) {
             $appointments = scheduler_get_appointments($aSlot->id);
             $collegues = "<div style=\"visibility:hidden; display:none\" id=\"collegues{$aSlot->id}\"><br/>";
             foreach ($appointments as $appstudent) {
                 $student = get_record('user', 'id', $appstudent->studentid);
                 $picture = print_user_picture($appstudent->studentid, $course->id, $student->picture, 0, true, true);
                 $name = "<a href=\"view.php?what=viewstudent&amp;id={$cm->id}&amp;studentid={$student->id}&amp;course={$scheduler->course}&amp;order=DESC\">" . fullname($student) . '</a>';
                 $collegues .= " {$picture} {$name}<br/>";