$app->appointmentEmail($data, true); $data['success'] = true; } header('Content-Type: application/json; charset=utf-8'); echo json_encode($data); exit; } elseif ($_GET['page'] === "cancel-booked") { $now = new \DateTime(); $date = new \DateTime($_POST['appointment_start']); $now->add(new \DateInterval("PT" . STUDENT_APPOINTMENT_MIN_HOURS_CANCELLATION . "H")); if ($now > $date) { throw new \InvalidArgumentException("Cannot cancel appointment."); } $data['appointment_start'] = $_POST['appointment_start']; $data['student'] = $SESSION->student_num; $data['emp_id'] = $app->removeEvent($data['student'], $data['appointment_start']); $data['remaining'] = $app->getAppointmentCount($_POST['appointment_type_id'], $_POST['appointment_start']); $app->appointmentEmail($data, false); header('Content-Type: application/json; charset=utf-8'); echo json_encode($data); exit; } elseif ($_GET['page'] === "fetch-open") { $openSlots = $app->getStudentAppointments($_GET['start'], $_GET['end'], $_GET['appointment_type_id'], $_GET['emp_id']); $bookedSlots = $app->getStudentAppointments($_GET['start'], $_GET['end'], $_GET['appointment_type_id'], $_GET['emp_id'], false); // map a [datetime+employee_id] to the corresponding booked slots info foreach ($bookedSlots as $slot) { $booked["{$slot['appointment_start']}{$slot['emp_id']}"] = $slot; } $ownedSlots = array(); $foundOpen = array(); $slots = array();