mirror of
https://github.com/myronblair/parkerslingshotrentals
synced 2026-06-30 17:50:31 -05:00
Add availability calendar, admin portal, and booking backend
- db.php: shared config, PDO, SendGrid, package definitions - availability.php: GET endpoint returning booked/blocked dates by month - contact.php: booking handler with DB record, availability check, SendGrid emails - admin/index.php: full admin portal (login, bookings table, status/notes AJAX, block dates) - index.html: interactive availability calendar with click-to-select, wires to /contact.php - .htaccess: block direct access to db.php Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/db.php';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
header('Access-Control-Allow-Origin: https://parkerslingshotrentals.com');
|
||||
|
||||
$month = (int)($_GET['month'] ?? date('n'));
|
||||
$year = (int)($_GET['year'] ?? date('Y'));
|
||||
$month = max(1, min(12, $month));
|
||||
$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
|
||||
$booked = db()->prepare(
|
||||
"SELECT rental_date, end_date FROM bookings
|
||||
WHERE status IN ('pending','confirmed')
|
||||
AND rental_date <= ? AND end_date >= ?"
|
||||
);
|
||||
$booked->execute([$end, $start]);
|
||||
|
||||
$bookedDays = [];
|
||||
foreach ($booked->fetchAll() as $row) {
|
||||
$d = new DateTime($row['rental_date']);
|
||||
$e = new DateTime($row['end_date']);
|
||||
while ($d <= $e) {
|
||||
$bookedDays[] = $d->format('Y-m-d');
|
||||
$d->modify('+1 day');
|
||||
}
|
||||
}
|
||||
|
||||
// Admin-blocked dates
|
||||
$blocked = db()->prepare(
|
||||
"SELECT block_date FROM blocked_dates WHERE block_date BETWEEN ? AND ?"
|
||||
);
|
||||
$blocked->execute([$start, $end]);
|
||||
foreach ($blocked->fetchAll() as $row) {
|
||||
$bookedDays[] = $row['block_date'];
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'month' => $month,
|
||||
'year' => $year,
|
||||
'booked_dates' => array_values(array_unique($bookedDays)),
|
||||
]);
|
||||
Reference in New Issue
Block a user