From 45c192058a45bf20afc08b8dfd99324fa245cbfb Mon Sep 17 00:00:00 2001 From: Zoli Date: Sat, 4 Oct 2025 13:52:17 +0200 Subject: [PATCH] 3 month limit setup --- application/controllers/Pages.php | 14 ++++++++++++++ application/models/Service_model.php | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/application/controllers/Pages.php b/application/controllers/Pages.php index 4d8e623..8eab6e8 100755 --- a/application/controllers/Pages.php +++ b/application/controllers/Pages.php @@ -403,6 +403,20 @@ class Pages extends CI_Controller { ])); return; } + + $today = new DateTime(); + $maxDate = (clone $today)->modify('+3 months'); + $selectedDate = new DateTime($bookingArray['booking_date']); + + if ($selectedDate > $maxDate) { + $this->output + ->set_status_header(403) + ->set_content_type('application/json') + ->set_output(json_encode([ + 'error' => 'Bookings can only be made up to 3 months in advance.' + ])); + return; + } // 6. Create booking $this->Service_model->createBooking($bookingArray); diff --git a/application/models/Service_model.php b/application/models/Service_model.php index 30099e7..c437e28 100755 --- a/application/models/Service_model.php +++ b/application/models/Service_model.php @@ -406,9 +406,19 @@ class Service_model extends CI_Model { public function getAvailableTimes($worker_id, $selectedDate, $servicelength) { $this->load->database(); + if (strtotime($selectedDate) < strtotime(date('Y-m-d'))) { return []; } + + $today = new DateTime(); + $maxDate = (clone $today)->modify('+3 months'); + $selected = new DateTime($selectedDate); + + if ($selected > $maxDate) { + return []; + } + $ts = strtotime($selectedDate); $debugDate = date('Y-m-d (w)', $ts) . ' - ' . date('l', $ts); log_message('error', "📅 DEBUG DATE CHECK for '{$selectedDate}': {$debugDate}");