From 92cb51ae60a1cbca6ece13bc25686f7f7edd5307 Mon Sep 17 00:00:00 2001 From: coolneng Date: Wed, 15 Jul 2020 18:58:41 +0200 Subject: [PATCH] Disable appointment selection for days off --- src/appointment_management.php | 7 +++++++ src/calendar.js | 16 +++++++++++++--- src/calendar_management.php | 6 ++++++ src/calendar_settings_feed.php | 28 ++++++++++++++++++++++++++++ src/calendar_setup_form.php | 2 +- src/database.php | 4 ++-- src/holiday_feed.php | 2 -- 7 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 src/calendar_settings_feed.php diff --git a/src/appointment_management.php b/src/appointment_management.php index 33d3aa6..aa94551 100644 --- a/src/appointment_management.php +++ b/src/appointment_management.php @@ -26,6 +26,13 @@ function listHolidays($pdo){ } +function listCalendarSettings($pdo){ + $doctor = fetchDoctor($pdo); + $calendar_settings = fetchCalendarSettings($pdo, $doctor); + return $calendar_settings; +} + + function appointmentCreation(){ $data = $_POST; $pdo = connectDatabase(); diff --git a/src/calendar.js b/src/calendar.js index 5890de1..bf443b6 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -22,19 +22,29 @@ }, selectAllow: function(selectInfo){ + var daysOff = null; var holidays = null; $.ajax({ - url: 'holiday_feed.php', + url: 'holiday_feed.php' + queryString, async: false, dataType: 'json', success: function (json) { holidays = json; } }); + $.ajax({ + url: 'calendar_settings_feed.php' + queryString, + async: false, + dataType: 'json', + success: function (json) { + daysOff = json; + } + }); var date = selectInfo.start._d; var formatted_date = date.toISOString().substr(0, 10); - var found = holidays.find(el => el.start === formatted_date); - if(found == null){ + var foundHoliday = holidays.find(el => el.start === formatted_date); + var foundDayOff = daysOff.find(el => el === date.getDay()); + if(foundDayOff == null && foundHoliday == null){ return true; } return false; diff --git a/src/calendar_management.php b/src/calendar_management.php index 089cd8b..d109281 100644 --- a/src/calendar_management.php +++ b/src/calendar_management.php @@ -33,6 +33,12 @@ function holidayDeletion() function calendarConfig() { $data = $_POST; + if (!isset($data["sabado_habil"])){ + $data["sabado_habil"] = 0; + } + if (!isset($data["domingo_habil"])){ + $data["domingo_habil"] = 0; + } $pdo = connectDatabase(); configureCalendar($pdo, $data); closeDatabase($pdo); diff --git a/src/calendar_settings_feed.php b/src/calendar_settings_feed.php new file mode 100644 index 0000000..8e8d3bb --- /dev/null +++ b/src/calendar_settings_feed.php @@ -0,0 +1,28 @@ + diff --git a/src/calendar_setup_form.php b/src/calendar_setup_form.php index 9c673ea..2d05172 100644 --- a/src/calendar_setup_form.php +++ b/src/calendar_setup_form.php @@ -68,7 +68,7 @@
- +
diff --git a/src/database.php b/src/database.php index 7ce4320..b77caad 100644 --- a/src/database.php +++ b/src/database.php @@ -359,10 +359,10 @@ function configureCalendar($pdo, $data) } else { $query = "UPDATE calendario SET hora_inicio_mañana=?, hora_fin_mañana=?, hora_inicio_tarde=?, hora_fin_tarde=?, horario=?, sabado_habil=?, domingo_habil=?, - duracion_cita_por_defecto=?, medico=? WHERE medico=?"; + duracion_cita_por_defecto=? WHERE medico=?"; $pdo->prepare($query)->execute([$data["hora_inicio_mañana"], $data["hora_fin_mañana"], $data["hora_inicio_tarde"], $data["hora_fin_tarde"], $data["horario"], $data["sabado_habil"], $data["domingo_habil"], - $data["duracion_cita_por_defecto"], $data["medico"], $data["medico"]]); + $data["duracion_cita_por_defecto"], $data["medico"]]); } return "Calendario configurado con éxito"; } diff --git a/src/holiday_feed.php b/src/holiday_feed.php index 43cb7bf..75dbd5d 100644 --- a/src/holiday_feed.php +++ b/src/holiday_feed.php @@ -7,11 +7,9 @@ function formatArray($data){ foreach($data as $row){ $events[] = array( "id" => $row["id"], - "title" => "Festivo", "start" => $row["fecha_festivo"], "description" => $row["tipo_festivo"], "doctor" => $row["nombre"], - "groupId" => "holidays", "rendering" => "background", "color" => "#ffa6a3", );