35438-vm/booking.php
2025-11-03 08:24:38 +00:00

80 lines
3.9 KiB
PHP

<?php
require_once 'db/config.php';
require_once 'includes/header.php';
$vehicle_id = isset($_GET['vehicle_id']) ? (int)$_GET['vehicle_id'] : 0;
$vehicle = null;
if ($vehicle_id) {
$stmt = db()->prepare("SELECT * FROM vehicles WHERE id = ?");
$stmt->execute([$vehicle_id]);
$vehicle = $stmt->fetch(PDO::FETCH_ASSOC);
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$customer_name = $_POST['customer_name'] ?? '';
$customer_email = $_POST['customer_email'] ?? '';
$customer_phone = $_POST['customer_phone'] ?? '';
$start_date = $_POST['start_date'] ?? '';
$end_date = $_POST['end_date'] ?? '';
$status = 'pending';
if ($vehicle_id && !empty($customer_name) && !empty($customer_email) && !empty($start_date) && !empty($end_date)) {
$stmt = db()->prepare("INSERT INTO bookings (vehicle_id, customer_name, customer_email, customer_phone, start_date, end_date, status) VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$vehicle_id, $customer_name, $customer_email, $customer_phone, $start_date, $end_date, $status]);
$booking_id = db()->lastInsertId();
echo '<div class="container mt-5 pt-5"><div class="alert alert-success">Thank you! Your booking has been received. We will contact you shortly.</div></div>';
} else {
echo '<div class="container mt-5 pt-5"><div class="alert alert-danger">Please fill in all required fields.</div></div>';
}
}
if (!$vehicle) {
echo '<div class="container mt-5 pt-5"><div class="alert alert-danger">Vehicle not found.</div></div>';
require_once 'includes/footer.php';
exit;
}
?>
<div class="container mt-5 pt-5">
<h2 class="text-center mb-4">Book Vehicle: <?php echo htmlspecialchars($vehicle['name']); ?></h2>
<div class="row">
<div class="col-md-6">
<img src="assets/images/<?php echo htmlspecialchars($vehicle['image']); ?>" class="img-fluid rounded" alt="<?php echo htmlspecialchars($vehicle['name']); ?>">
</div>
<div class="col-md-6">
<p><strong>Type:</strong> <?php echo htmlspecialchars($vehicle['type']); ?></p>
<p><strong>Capacity:</strong> <?php echo htmlspecialchars($vehicle['capacity']); ?> people</p>
<p><strong>Price:</strong> Rp <?php echo number_format($vehicle['price_per_day'], 0, ',', '.'); ?> / day</p>
<hr>
<form action="booking.php?vehicle_id=<?php echo $vehicle_id; ?>" method="POST">
<div class="mb-3">
<label for="customer_name" class="form-label">Full Name</label>
<input type="text" class="form-control" id="customer_name" name="customer_name" required>
</div>
<div class="mb-3">
<label for="customer_email" class="form-label">Email Address</label>
<input type="email" class="form-control" id="customer_email" name="customer_email" required>
</div>
<div class="mb-3">
<label for="customer_phone" class="form-label">Phone Number</label>
<input type="tel" class="form-control" id="customer_phone" name="customer_phone" required>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="start_date" class="form-label">Start Date</label>
<input type="date" class="form-control" id="start_date" name="start_date" required>
</div>
<div class="col-md-6 mb-3">
<label for="end_date" class="form-label">End Date</label>
<input type="date" class="form-control" id="end_date" name="end_date" required>
</div>
</div>
<button type="submit" class="btn btn-primary w-100">Book Now</button>
</form>
</div>
</div>
</div>
<?php require_once 'includes/footer.php'; ?>