Fix: blocked dates enforce on date input; fix CORS + no-cache on availability endpoint

This commit is contained in:
2026-05-22 22:15:41 +00:00
parent 41773a6905
commit 9029ce2d12
2 changed files with 25 additions and 15 deletions
+6 -5
View File
@@ -2,7 +2,8 @@
require_once __DIR__ . '/db.php';
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: https://parkerslingshotrentals.com');
header('Access-Control-Allow-Origin: ' . SITE_URL);
header('Cache-Control: no-store, no-cache, must-revalidate');
$month = (int)($_GET['month'] ?? date('n'));
$year = (int)($_GET['year'] ?? date('Y'));
@@ -12,7 +13,7 @@ $year = max(date('Y'), min(date('Y') + 2, $year));
$start = sprintf('%04d-%02d-01', $year, $month);
$end = date('Y-m-t', strtotime($start));
// Booked dates from confirmed/pending bookings
// Bookings that overlap this month — including those that start last month and end this month
$booked = db()->prepare(
"SELECT rental_date, end_date FROM bookings
WHERE status IN ('pending','confirmed')
@@ -30,7 +31,7 @@ foreach ($booked->fetchAll() as $row) {
}
}
// Admin-blocked dates
// Admin-blocked dates for this month
$blocked = db()->prepare(
"SELECT block_date FROM blocked_dates WHERE block_date BETWEEN ? AND ?"
);
@@ -40,7 +41,7 @@ foreach ($blocked->fetchAll() as $row) {
}
echo json_encode([
'month' => $month,
'year' => $year,
'month' => $month,
'year' => $year,
'booked_dates' => array_values(array_unique($bookedDays)),
]);