From 5e776c9e2b38d439fa3ebab9c928d3a557e654c6 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sat, 21 Mar 2026 18:53:48 +0000 Subject: [PATCH] updating appointments --- includes/pages/appointments.php | 81 +++++++++++++++++++-------------- lang.php | 2 + 2 files changed, 50 insertions(+), 33 deletions(-) diff --git a/includes/pages/appointments.php b/includes/pages/appointments.php index e884eb5..853b940 100644 --- a/includes/pages/appointments.php +++ b/includes/pages/appointments.php @@ -193,11 +193,7 @@ function toggleAddressField() { } function validateHolidayFrontend() { - if (!calendar) return; // Calendar not initialized yet - var btnSave = document.getElementById('btnSaveApt'); - - // Reset state first to avoid getting stuck $('#holidayWarning').remove(); if (btnSave) btnSave.disabled = false; @@ -208,38 +204,49 @@ function validateHolidayFrontend() { var startTimeStr = $('#apt_start_time').val(); if (!docId || !startTimeStr) return; + + // Use API to check for holiday definitively (independent of calendar view) + if (btnSave) btnSave.disabled = true; // Disable while checking - var datePrefix = startTimeStr.split('T')[0]; - var events = calendar.getEvents(); - var isHoliday = false; - - for (var i = 0; i < events.length; i++) { - var ev = events[i]; - // Check for doctor holiday events matching the selected doctor - if (ev.extendedProps && ev.extendedProps.type === 'doctor_holiday' && ev.extendedProps.doctor_id == docId) { - var evStartStr = ev.startStr ? ev.startStr.split('T')[0] : ''; - var evEndStr = ev.end ? ev.endStr.split('T')[0] : evStartStr; - - if (ev.allDay) { - // All day event: check if datePrefix is within range [start, end) - if (datePrefix >= evStartStr && datePrefix < evEndStr) { - isHoliday = true; - break; + fetch('api/doctor_holidays.php?doctor_id=' + docId) + .then(response => response.json()) + .then(data => { + // Re-check current values to ensure they haven't changed while fetching + var currentDocId = $('#apt_doctor_id').val(); + var currentStartTimeStr = $('#apt_start_time').val(); + if (currentDocId != docId || currentStartTimeStr != startTimeStr) return; + + // Remove any existing warning to prevent duplication (especially from rapid successive calls) + $('#holidayWarning').remove(); + + if (data.success && data.holidays) { + var isHoliday = false; + var datePrefix = startTimeStr.split('T')[0]; + + // Check if date is in any holiday range + for (var i = 0; i < data.holidays.length; i++) { + var h = data.holidays[i]; + // h.start_date and h.end_date are YYYY-MM-DD + if (datePrefix >= h.start_date && datePrefix <= h.end_date) { + isHoliday = true; + break; + } + } + + if (isHoliday) { + $('
Selected doctor is on holiday on this date.
').appendTo('#appointmentDetailsModal .modal-body'); + if (btnSave) btnSave.disabled = true; + } else { + if (btnSave) btnSave.disabled = false; } } else { - // Daily block or single time point - if (datePrefix === evStartStr) { - isHoliday = true; - break; - } + if (btnSave) btnSave.disabled = false; } - } - } - - if (isHoliday) { - $('
Selected doctor is on holiday on this date.
').appendTo('#appointmentDetailsModal .modal-body'); - if (btnSave) btnSave.disabled = true; - } + }) + .catch(err => { + console.error('Error checking holiday:', err); + if (btnSave) btnSave.disabled = false; + }); } function toggleProviderField() { @@ -388,8 +395,16 @@ document.addEventListener('DOMContentLoaded', function() { calendar = new FullCalendar.Calendar(calendarEl, { initialView: 'timeGridWeek', + customButtons: { + customToday: { + text: '', + click: function() { + calendar.today(); + } + } + }, headerToolbar: { - left: 'prev,next today', + left: 'prev,next customToday', center: 'title', right: 'dayGridMonth,timeGridWeek,timeGridDay' }, diff --git a/lang.php b/lang.php index 05922e4..63c9dc5 100644 --- a/lang.php +++ b/lang.php @@ -197,6 +197,7 @@ $translations = [ // Dashboard & Common Missing Keys 'total_patients' => 'Total Patients', 'today_appointments' => 'Today\'s Appointments', + 'today' => 'Today', 'revenue' => 'Revenue', 'pending' => 'Pending', 'add_patient' => 'Add Patient', @@ -425,6 +426,7 @@ $translations = [ // Dashboard & Common Missing Keys - Arabic 'total_patients' => 'إجمالي المرضى', 'today_appointments' => 'مواعيد اليوم', + 'today' => 'اليوم', 'revenue' => 'الإيرادات', 'pending' => 'معلق', 'add_patient' => 'إضافة مريض',