306 lines
16 KiB
PHP
306 lines
16 KiB
PHP
<html>
|
|
<head>
|
|
<title>Cart</title>
|
|
<script src="iframe.js"></script>
|
|
<script src="./item_modify.js"></script>
|
|
<link rel="stylesheet" href="./cart.css" type="text/css" />
|
|
<link rel="shortcut icon" href="../../../icon/favicon/favicon.ico" type="image/x-icon" />
|
|
<link rel="icon" href="../../../icon/favicon/favicon.ico" type="image/x-icon" />
|
|
<link rel="stylesheet" href="../home.css?version=1" type="text/css" />
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<?php
|
|
include "../../ConnectDB.php";
|
|
// Start the session
|
|
session_start();
|
|
// Check if the user is already logged in
|
|
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
|
if(!isset($_SESSION['usertype']) && !$_SESSION['usertype'] === 'buyer'){
|
|
header('Location: ../../../index.php');
|
|
}
|
|
}
|
|
else{
|
|
header('Location: ../../../index.php');
|
|
}
|
|
$u_id = $_SESSION['uid'];
|
|
?>
|
|
|
|
<header>
|
|
<div class="logo">
|
|
<a href="../../../index.php"><img src="../../../icon/favicon/logo_white.svg" alt="RoamEase"></a>
|
|
</div>
|
|
|
|
<div class="nav-links">
|
|
<?php
|
|
if (isset($_SESSION['loggedin'])) {
|
|
echo '<a href="./cart.php">Cart</a>
|
|
<a href="../../../login/login.php">Account</a>';
|
|
}
|
|
else {
|
|
echo '<a href="../../../login/register.php">Sign up</a>
|
|
<a href="../../../login/username.php">Log in</a>';
|
|
}
|
|
?>
|
|
</div>
|
|
</header>
|
|
|
|
<header>
|
|
<nav>
|
|
<a href="../stays.php">
|
|
<img src="../../../icon/header/stays.svg" alt="Stays">
|
|
</a>
|
|
<a href="../transport.php">
|
|
<img src="../../../icon/header/transportations.svg" alt="Transportations">
|
|
</a>
|
|
<a href="../foods.php">
|
|
<img src="../../../icon/header/foods.svg" alt="Foods">
|
|
</a>
|
|
<a href="../attractions.php">
|
|
<img src="../../../icon/header/attractions.svg" alt="Attractions">
|
|
</a>
|
|
<a href="../guiding.php">
|
|
<img src="../../../icon/header/guiding.svg" alt="Guiding">
|
|
</a>
|
|
<a href="../plans.php">
|
|
<img src="../../../icon/header/plans.svg" alt="Plans">
|
|
</a>
|
|
</nav>
|
|
</header>
|
|
|
|
<div id="grid">
|
|
|
|
<?php
|
|
$username = mysqli_real_escape_string($conn, $_SESSION['username']);
|
|
$uid = mysqli_real_escape_string($conn, $_SESSION['uid']);
|
|
|
|
$sql_cart_bookings = "SELECT * FROM cart_bookings WHERE u_id='$u_id'";
|
|
$result_cart_bookings = mysqli_query($conn, $sql_cart_bookings);
|
|
$num_rows = mysqli_num_rows($result_cart_bookings);
|
|
|
|
while ($cartBooking = mysqli_fetch_assoc($result_cart_bookings)) {
|
|
$booking_id = $cartBooking['booking_id'];
|
|
// Use a switch statement for different booking types
|
|
switch ($cartBooking['booking_type_id']) {
|
|
case '1':
|
|
$bookingQuery = "SELECT * FROM hotel_booking WHERE booking_id = " . $booking_id;
|
|
$bookingResult = mysqli_query($conn, $bookingQuery);
|
|
$bookingDetails = mysqli_fetch_assoc($bookingResult);
|
|
|
|
$quantity = $bookingDetails['quantity'];
|
|
$id = $bookingDetails['hotel_room_id'];
|
|
$start_date = $bookingDetails['start_date'];
|
|
$end_date = $bookingDetails['end_date'];
|
|
|
|
$productQuery = "SELECT hotel_room.hotel_id, hotel_room.price, hotel_room_type.room_type_image, hotel.name, hotel_room_type.room_type_name FROM hotel_room JOIN hotel ON (hotel_room.hotel_id = hotel.hotel_id) JOIN hotel_room_type ON (hotel_room.room_type_id = hotel_room_type.room_type_id) WHERE hotel_room_id = " . $bookingDetails['hotel_room_id'];
|
|
$bookingResult = mysqli_query($conn, $productQuery);
|
|
$productDetails = mysqli_fetch_assoc($bookingResult);
|
|
|
|
$price = $productDetails['price'];
|
|
$img = $productDetails['room_type_image'];
|
|
$name = $productDetails['name'] . " - " . $productDetails['room_type_name'];
|
|
|
|
break;
|
|
case '2':
|
|
$bookingQuery = "SELECT * FROM restaurant_booking WHERE booking_id = " . $booking_id;
|
|
$bookingResult = mysqli_query($conn, $bookingQuery);
|
|
$bookingDetails = mysqli_fetch_assoc($bookingResult);
|
|
|
|
$quantity = $bookingDetails['quantity'];
|
|
$id = $bookingDetails['restaurant_id'];
|
|
$start_date = $bookingDetails['visit_date'];
|
|
$end_date = null;
|
|
|
|
$productQuery = "SELECT name, fee, restaurant_style.restaurant_style_image FROM restaurant JOIN restaurant_style ON (restaurant.restaurant_style_id = restaurant_style.restaurant_style_id) WHERE restaurant_id = " . $bookingDetails['restaurant_id'];
|
|
$bookingResult = mysqli_query($conn, $productQuery);
|
|
$productDetails = mysqli_fetch_assoc($bookingResult);
|
|
|
|
$price = $productDetails['fee'];
|
|
$img = $productDetails['restaurant_style_image'];
|
|
$name = $productDetails['name'];
|
|
|
|
break;
|
|
case '3':
|
|
$bookingQuery = "SELECT * FROM attraction_booking WHERE booking_id = " . $booking_id;
|
|
$bookingResult = mysqli_query($conn, $bookingQuery);
|
|
$bookingDetails = mysqli_fetch_assoc($bookingResult);
|
|
|
|
$quantity = $bookingDetails['quantity'];
|
|
$id = $bookingDetails['attraction_id'];
|
|
$start_date = $bookingDetails['visit_date'];
|
|
$end_date = null;
|
|
|
|
$productQuery = "SELECT name, price, attraction_type.attraction_type_image FROM attraction JOIN attraction_type ON (attraction.attraction_type_id = attraction_type.attraction_type_id) WHERE attraction_id = " . $bookingDetails['attraction_id'];
|
|
$bookingResult = mysqli_query($conn, $productQuery);
|
|
$productDetails = mysqli_fetch_assoc($bookingResult);
|
|
|
|
$price = $productDetails['price'];
|
|
$img = $productDetails['attraction_type_image'];
|
|
$name = $productDetails['name'];
|
|
|
|
break;
|
|
case '4':
|
|
$bookingQuery = "SELECT * FROM guide_booking WHERE booking_id = " . $booking_id;
|
|
$bookingResult = mysqli_query($conn, $bookingQuery);
|
|
$bookingDetails = mysqli_fetch_assoc($bookingResult);
|
|
|
|
$quantity = $bookingDetails['quantity'];
|
|
$id = $bookingDetails['guide_id'];
|
|
$start_date = $bookingDetails['start_date'];
|
|
$end_date = $bookingDetails['end_date'];
|
|
|
|
$productQuery = "SELECT user_guide.username, user_guide.fee, user_guide.avatar FROM user_guide WHERE u_id = " . $bookingDetails['guide_id'];
|
|
$bookingResult = mysqli_query($conn, $productQuery);
|
|
$productDetails = mysqli_fetch_assoc($bookingResult);
|
|
|
|
$price = $productDetails['fee'];
|
|
$img = $productDetails['avatar'];
|
|
$name = $productDetails['username'];
|
|
|
|
break;
|
|
case '5':
|
|
$bookingQuery = "SELECT * FROM transport_flight_booking WHERE booking_id = " . $booking_id;
|
|
$bookingResult = mysqli_query($conn, $bookingQuery);
|
|
$bookingDetails = mysqli_fetch_assoc($bookingResult);
|
|
|
|
$quantity = $bookingDetails['quantity'];
|
|
$id = $bookingDetails['flight_class_id'];
|
|
$start_date = $bookingDetails['visit_date'];
|
|
$end_date = null;
|
|
|
|
$productQuery = "SELECT transport_flight_class.flight_id, transport_flight_class.class, transport_flight_class.fee, transport_flight.flight_code, transport_flight.takeoff_time, transport_flight.landing_time FROM transport_flight_class JOIN transport_flight ON (transport_flight.flight_id = transport_flight_class.flight_id) WHERE flight_class_id = " . $bookingDetails['flight_class_id'];
|
|
$bookingResult = mysqli_query($conn, $productQuery);
|
|
$productDetails = mysqli_fetch_assoc($bookingResult);
|
|
|
|
$price = $productDetails['fee'];
|
|
$img = '';
|
|
$name = $productDetails['flight_code'] . " - " . $productDetails['class'];
|
|
|
|
break;
|
|
case '6':
|
|
$bookingQuery = "SELECT * FROM transport_railway_booking WHERE booking_id = " . $booking_id;
|
|
$bookingResult = mysqli_query($conn, $bookingQuery);
|
|
$bookingDetails = mysqli_fetch_assoc($bookingResult);
|
|
|
|
$quantity = $bookingDetails['quantity'];
|
|
$id = $bookingDetails['railway_class_id'];
|
|
$visit_date = $bookingDetails['visit_date'];
|
|
$end_date = null;
|
|
|
|
$productQuery = "SELECT transport_railway_class.train_id, transport_railway_class.class, transport_railway_class.fee, transport_railway.train_code, transport_railway.start_time, transport_railway.arrive_time FROM transport_railway_class JOIN transport_railway ON (transport_railway.train_id = transport_railway_class.train_id) WHERE train_seat_id = " . $id;
|
|
$bookingResult = mysqli_query($conn, $productQuery);
|
|
$productDetails = mysqli_fetch_assoc($bookingResult);
|
|
|
|
$price = $productDetails['fee'];
|
|
$img = '';
|
|
$name = $productDetails['train_code'] . " - " . $productDetails['class'];
|
|
|
|
break;
|
|
default:
|
|
echo "Unknown booking type";
|
|
continue 2; // Skip to the next cart booking
|
|
}
|
|
|
|
//unit price
|
|
$unitprice = $cartBooking['subtotal_price'];
|
|
|
|
//choose
|
|
$choose = $cartBooking['choose'];
|
|
|
|
//display
|
|
echo '<table id="items" style="border:none;">';
|
|
echo '<tr>';
|
|
echo '<td width="15%">';
|
|
|
|
if ($img != ''){
|
|
echo '<img src="data:image/jpeg;base64,' . base64_encode($img) . '" title="' . $id . '" id="' . $id . '" onclick="details(this)">';
|
|
}
|
|
|
|
echo '</td>';
|
|
//name
|
|
echo '<td width="20%">';
|
|
echo '<h4 style="margin: 0%; font-size: large;">' . $name . '</h4>';
|
|
echo '</td>';
|
|
|
|
if($end_date != null){
|
|
//start date
|
|
echo '<td width="10%">';
|
|
echo '<p style="font-size: large;">'.$start_date.'</p>';
|
|
echo '</td>';
|
|
//start date
|
|
echo '<td width="10%">';
|
|
echo '<p style="font-size: large;">'.$end_date.'</p>';
|
|
echo '</td>';
|
|
}
|
|
else{
|
|
//start date
|
|
echo '<td width="20%">';
|
|
echo '<p style="font-size: large;">'.$start_date.'</p>';
|
|
echo '</td>';
|
|
}
|
|
|
|
//unit price
|
|
echo '<td width="10%">';
|
|
echo '<p style="font-size: large;">¥'.$unitprice.'</p>';
|
|
echo '</td>';
|
|
//add
|
|
echo '<td width="6%" id="icon">';
|
|
echo '<img src="../../../icon/add.svg" id="' . $booking_id . '" name="'. $cartBooking['booking_type_id'] .'" onclick="item_add(this)">';
|
|
echo '</td>';
|
|
//modify
|
|
echo '<td width="8%">';
|
|
echo '<input type="text" style="margin: 0%; font-size: large;" name="'. $cartBooking['booking_type_id'] .'" id="' . $booking_id . '" value="' . $quantity . '" onfocusout="item_modify(this)">';
|
|
echo '</td>';
|
|
//subtract
|
|
echo '<td width="6%" id="icon">';
|
|
echo '<img src="../../../icon/subtract.svg" id="' . $booking_id . '" name="'. $cartBooking['booking_type_id'] .'" onclick="item_subtract(this)">';
|
|
echo '</td>';
|
|
//delete
|
|
echo '<td width="6%" id="icon">';
|
|
echo '<img src="../../../icon/delete.svg" id="' . $booking_id . '" name="'. $cartBooking['booking_type_id'] .'" onclick="item_del(this)">';
|
|
echo '</td>';
|
|
echo '</tr>';
|
|
echo '</table>';
|
|
}
|
|
|
|
$cart_total_Query = "SELECT cart_total_price FROM user_buyer WHERE u_id = " . $u_id;
|
|
$cart_total_Result = mysqli_query($conn, $cart_total_Query);
|
|
$cart_total_price = mysqli_fetch_assoc($cart_total_Result);
|
|
$total = $cart_total_price['cart_total_price'];
|
|
|
|
if($num_rows != 0){
|
|
echo '<table width="20%" style="text-align: center; border:none; background-color: transparent;">';
|
|
echo '<tr>';
|
|
echo '<td><h1>Total Price: ¥ '.$total.'</h1></td>';
|
|
echo '<td>';
|
|
echo '<form action="./checkup.php">';
|
|
echo '<button type="submit">Check up</button>';
|
|
echo '</form>';
|
|
echo '</td>';
|
|
echo '</tr>';
|
|
echo '</table>';
|
|
}
|
|
else{
|
|
echo '<h1>Nothing Here</h1>';
|
|
echo '<br><br><br><br><br><br><br><br><br><br><br><br><br>
|
|
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>';
|
|
}
|
|
|
|
?>
|
|
|
|
</div>
|
|
<footer>
|
|
<img src="../../../icon/favicon/logo_white.svg" alt="RoamEase" width="300px">
|
|
<div style="margin: 20px 0;">
|
|
<a href="#" style="color: white; margin: 0 10px;">About us</a>
|
|
<a href="#" style="color: white; margin: 0 10px;">Privacy Policy</a>
|
|
<a href="#" style="color: white; margin: 0 10px;">Terms For Usage</a>
|
|
</div>
|
|
<p>© 2023 COMP3013 Group10. All rights reserved.</p>
|
|
</footer>
|
|
|
|
</body>
|
|
</html>
|