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

81 lines
3.9 KiB
PHP

<?php
require_once 'db/config.php';
require_once 'includes/header.php';
$tour_id = isset($_GET['tour_id']) ? (int)$_GET['tour_id'] : 0;
$tour = null;
if ($tour_id) {
$stmt = db()->prepare("SELECT * FROM tour_packages WHERE id = ?");
$stmt->execute([$tour_id]);
$tour = $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'] ?? '';
$tour_date = $_POST['tour_date'] ?? '';
$num_people = $_POST['num_people'] ?? 1;
$status = 'pending';
if ($tour_id && !empty($customer_name) && !empty($customer_email) && !empty($tour_date)) {
$stmt = db()->prepare("INSERT INTO tour_bookings (tour_package_id, customer_name, customer_email, customer_phone, tour_date, num_people, status) VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$tour_id, $customer_name, $customer_email, $customer_phone, $tour_date, $num_people, $status]);
$booking_id = db()->lastInsertId();
echo '<div class="container mt-5 pt-5"><div class="alert alert-success">Thank you! Your tour 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 (!$tour) {
echo '<div class="container mt-5 pt-5"><div class="alert alert-danger">Tour package not found.</div></div>';
require_once 'includes/footer.php';
exit;
}
?>
<div class="container mt-5 pt-5">
<h2 class="text-center mb-4">Book Tour: <?php echo htmlspecialchars($tour['name']); ?></h2>
<div class="row">
<div class="col-md-6">
<img src="assets/images/<?php echo htmlspecialchars($tour['image']); ?>" class="img-fluid rounded" alt="<?php echo htmlspecialchars($tour['name']); ?>">
</div>
<div class="col-md-6">
<p><strong>Duration:</strong> <?php echo htmlspecialchars($tour['duration']); ?></p>
<p><strong>Itinerary:</strong> <?php echo nl2br(htmlspecialchars($tour['itinerary'])); ?></p>
<p><strong>Price:</strong> Rp <?php echo number_format($tour['price'], 0, ',', '.'); ?> / person</p>
<hr>
<form action="tour_booking.php?tour_id=<?php echo $tour_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="tour_date" class="form-label">Tour Date</label>
<input type="date" class="form-control" id="tour_date" name="tour_date" required>
</div>
<div class="col-md-6 mb-3">
<label for="num_people" class="form-label">Number of People</label>
<input type="number" class="form-control" id="num_people" name="num_people" min="1" value="1" 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'; ?>