public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     // Check number of appointments vs exclusivity
     $numappointments = 0;
     for ($i = 0; $i < $data['appointment_repeats']; $i++) {
         if ($data['studentid'][$i] > 0) {
             $numappointments++;
         }
     }
     if ($data['exclusivityenable'] && $data['exclusivity'] <= 0) {
         $errors['exclusivitygroup'] = get_string('exclusivitypositive', 'scheduler');
     } else {
         if ($data['exclusivityenable'] && $numappointments > $data['exclusivity']) {
             $errors['exclusivitygroup'] = get_string('exclusivityoverload', 'scheduler', $numappointments);
         }
     }
     // Avoid empty slots starting in the past
     if ($numappointments == 0 && $data['starttime'] < time()) {
         $errors['starttime'] = get_string('startpast', 'scheduler');
     }
     // Check whether students have been selected several times
     for ($i = 0; $i < $data['appointment_repeats']; $i++) {
         for ($j = 0; $j < $i; $j++) {
             if ($data['studentid'][$i] > 0 && $data['studentid'][$i] == $data['studentid'][$j]) {
                 $errors['studgroup[' . $i . ']'] = get_string('studentmultiselect', 'scheduler');
                 $errors['studgroup[' . $j . ']'] = get_string('studentmultiselect', 'scheduler');
             }
         }
     }
     if (!isset($data['ignoreconflicts'])) {
         // Avoid overlapping slots, by asking the user if they'd like to overwrite the existing ones...
         // for other scheduler, we check independently of exclusivity. Any slot here conflicts
         // for this scheduler, we check against exclusivity. Any complete slot here conflicts
         $conflicts_remote = scheduler_get_conflicts($this->scheduler->id, $data['starttime'], $data['starttime'] + $data['duration'] * 60, $data['teacherid'], 0, SCHEDULER_OTHERS, false);
         $conflicts_local = scheduler_get_conflicts($this->scheduler->id, $data['starttime'], $data['starttime'] + $data['duration'] * 60, $data['teacherid'], 0, SCHEDULER_SELF, true);
         if (!$conflicts_remote) {
             $conflicts_remote = array();
         }
         if (!$conflicts_local) {
             $conflicts_local = array();
         }
         $conflicts = $conflicts_remote + $conflicts_local;
         // remove itself from conflicts when updating
         if (array_key_exists($this->slotid, $conflicts)) {
             unset($conflicts[$this->slotid]);
         }
         if (count($conflicts)) {
             $msg = get_string('slotwarning', 'scheduler');
             foreach ($conflicts as $conflict) {
                 $students = scheduler_get_appointed($conflict->id);
                 $slotmsg = userdate($conflict->starttime);
                 $slotmsg .= ' [';
                 $slotmsg .= $conflict->duration . ' ' . get_string('minutes');
                 $slotmsg .= ']';
                 if ($students) {
                     $slotmsg .= ' (';
                     $appointed = array();
                     foreach ($students as $astudent) {
                         $appointed[] = fullname($astudent);
                     }
                     if (count($appointed)) {
                         $slotmsg .= implode(', ', $appointed);
                     }
                     unset($appointed);
                     $slotmsg .= ')';
                     $slotmsg = html_writer::tag('b', $slotmsg);
                 }
                 $msg .= html_writer::div($slotmsg);
             }
             $errors['starttime'] = $msg;
         }
     }
     return $errors;
 }
 }
 if (count($conflicts)) {
     if ($subaction == 'confirmdelete' && confirm_sesskey()) {
         foreach ($conflicts as $conflict) {
             if ($conflict->id != @$slotid) {
                 delete_records('scheduler_slots', 'id', $conflict->id);
                 delete_records('scheduler_appointment', 'slotid', $conflict->id);
                 scheduler_delete_calendar_events($conflict);
             }
         }
     } else {
         echo "<br/><br/>";
         print_simple_box_start('center', '', '');
         echo get_string('slotwarning', 'scheduler') . '<br/><br/>';
         foreach ($conflicts as $conflict) {
             $students = scheduler_get_appointed($conflict->id);
             echo !empty($students) ? '<b>' : '';
             echo userdate($conflict->starttime);
             echo ' [';
             echo $conflict->duration . ' ' . get_string('minutes');
             echo ']<br/>';
             if ($students) {
                 $appointed = array();
                 foreach ($students as $aStudent) {
                     $appointed[] = fullname($aStudent);
                 }
                 if (count($appointed)) {
                     echo '<span style="font-size : smaller">';
                     echo implode(', ', $appointed);
                     echo '</span>';
                 }