×
Upcoming Bookings
prepare($sql); $stmt->bind_param("i", $user_id); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { // Loop through each row while ($row = $result->fetch_assoc()) { $booking_id = $row['booking_id']; $booking_type = $row['booking_type']; $from_date = $row['from_date']; $to_date = $row['to_date']; $num_vehicles = $row['num_vehicles']; $num_adults = $row['num_adults']; $num_children = $row['num_children']; $add_firewood = $row['add_firewood']; $total_amount = $row['total_amount']; $discount_amount = $row['discount_amount']; $status = $row['status']; $trip_id = $row['trip_id']; $course_id = $row['course_id']; $course_nonmembers = $row['course_non_members']; $radio = $row['radio']; $amount = $total_amount - $discount_amount; $total_adults = $num_adults + $course_nonmembers; if (!is_null($trip_id)) { // Prepare a SQL statement to retrieve trip details $sql_trip = "SELECT trip_name, location, short_description, start_date, end_date FROM trips WHERE trip_id = ?"; $stmt_trip = $conn->prepare($sql_trip); $stmt_trip->bind_param("i", $trip_id); if ($stmt_trip->execute()) { $result_trip = $stmt_trip->get_result(); if ($result_trip->num_rows > 0) { // Fetch trip details $trip_data = $result_trip->fetch_assoc(); $trip_name = $trip_data['trip_name'] ?? "Trip Name Placeholder"; $location = $trip_data['location'] ?? "Location Placeholder"; $short_description = $trip_data['short_description'] ?? "Short description of the trip."; $start_date = $trip_data['start_date'] ?? $from_date; // Default to booking start date if not set $end_date = $trip_data['end_date'] ?? $to_date; // Default to booking end date if not set } else { // Set default values if no trip data found $trip_name = "Trip Name Placeholder"; $location = "Location Placeholder"; $short_description = "Short description of the trip."; $start_date = $from_date; // Default to booking start date $end_date = $to_date; // Default to booking end date } } else { // Handle SQL execution error echo "Error retrieving trip information: " . $stmt_trip->error; } // Close the statement $stmt_trip->close(); } elseif (!is_null($course_id)) { // Prepare a SQL statement to retrieve trip details $sql_course = "SELECT course_type, date FROM courses WHERE course_id = ?"; $stmt_course = $conn->prepare($sql_course); $stmt_course->bind_param("i", $course_id); if ($stmt_course->execute()) { $result_course = $stmt_course->get_result(); if ($result_course->num_rows > 0) { // Fetch trip details $trip_data = $result_course->fetch_assoc(); $date = $trip_data['date'] ?? "Location Placeholder"; $type = $trip_data['course_type'] ?? "Trip Name Placeholder"; if ($type === "driver_training") { $trip_name = "Basic 4X4 Driver Training Course"; } elseif ($type === "bush_mechanics") { $trip_name = "Bush Mechanics Course"; } elseif ($type === "rescue_recovery") { $trip_name = "Rescue & Recovery Training Course"; } else { $trip_name = "General Course"; // Default fallback description } $start_date = $date; $end_date = $date; $location = "BASE4, Hennops"; $short_description = getDetail($type); } else { // Set default values if no trip data found $trip_name = "Trip Name Placeholder"; $location = "BASE4, Hennops"; $short_description = getDetail($type); $start_date = $from_date; // Default to booking start date $end_date = $to_date; // Default to booking end date } } else { // Handle SQL execution error echo "Error retrieving trip information: " . $stmt_course->error; } // Close the statement $stmt_course->close(); } else { // Set default values if trip_id is null $trip_name = "BASE4 Camping"; $location = "BASE4, Hennops"; $short_description = "Please remember to bring 2 bags of firewood and drinking water for personal use."; $start_date = $from_date; // Default to booking start date $end_date = $to_date; // Default to booking end date } // Get today's date $today = date("Y-m-d"); // Determine if the date is past or future if ($end_date < $today) { $tense = 'past'; } else { $tense = 'future'; } // Output the HTML structure with dynamic data echo '
'; if ($booking_type === 'trip') { echo '' . htmlspecialchars($trip_name) . ''; } elseif ($booking_type === 'course') { echo '' . htmlspecialchars($trip_name) . ''; } else { echo 'Base4'; } echo '
' . htmlspecialchars($location) . '
' . htmlspecialchars($trip_name) . '

' . htmlspecialchars($short_description) . '

    '; if ($booking_type === 'course') { echo '
  • ' . convertDate($start_date) . '
  • '; } else { echo '
  • ' . convertDate($start_date) . ' - ' . convertDate($end_date) . '
  • ' . calculateDaysAndNights($start_date, $end_date) . '
  • '; } ?>
  • 1 ? 'vehicles' : 'vehicle') . ' ' . $total_adults . ' ' . ($total_adults > 1 ? 'adults' : 'adult'); if ($num_children > 0) { echo ' ' . $num_children . ' ' . ($num_children > 1 ? 'children' : 'child'); } ?>
'; } } else { echo '

You have no upcoming bookings.

'; } // Close connection $conn->close(); ?>