Initial Commit

This commit is contained in:
ldy
2025-06-06 17:31:03 +08:00
parent 787a7b5741
commit 66cd489ea8
244 changed files with 13574 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
<?php
include "../../../ConnectDB.php";
session_start();
$uid = mysqli_real_escape_string($conn, $_SESSION['uid']);
if (isset($_GET["booking_id"]) && isset($_GET["table"])) {
$booking_id = $_GET["booking_id"];
switch ($_GET["table"]) {
case '1':
$table = "hotel_booking";
break;
case '2':
$table = "restaurant_booking";
break;
case '3':
$table = "attraction_booking";
break;
case '4':
$table = "guide_booking";
break;
case '5':
$table = "transport_flight_booking";
break;
case '6':
$table = "transport_railway_booking";
break;
default:
echo "Unknown booking type";
}
$price_query = "SELECT `subtotal_price` FROM cart_bookings WHERE booking_id=" . $booking_id;
$priceRes = mysqli_query($conn, $price_query);
$price = mysqli_fetch_assoc($priceRes);
$price = $price["subtotal_price"];
$quantity_query = "SELECT quantity FROM `$table` WHERE booking_id='$booking_id'";
$res = mysqli_query($conn, $quantity_query);
$quantity = mysqli_fetch_assoc($res);
$quantity = $quantity['quantity'];
$add = "UPDATE `$table` SET quantity = '$quantity' + 1 WHERE booking_id='$booking_id'";
$res = mysqli_query($conn, $add);
if (!$res) {
echo "<script type='text/javascript'>
alert('Error occurred!');
</script>";
}
$total = "UPDATE user_buyer SET cart_total_price = cart_total_price + '$price' WHERE u_id='$uid'";
$res = mysqli_query($conn, $total);
if (!$res) {
echo "<script type='text/javascript'>
alert('Error occurred!');
</script>";
}
}
header('Location: ../cart.php');
?>

View File

@@ -0,0 +1,65 @@
<?php
include "../../../ConnectDB.php";
session_start();
$uid = mysqli_real_escape_string($conn, $_SESSION['uid']);
if (isset($_GET["booking_id"]) && isset($_GET["table"])) {
$booking_id = mysqli_real_escape_string($conn, $_GET["booking_id"]);
switch ($_GET["table"]) {
case '1':
$table = "hotel_booking";
break;
case '2':
$table = "restaurant_booking";
break;
case '3':
$table = "attraction_booking";
break;
case '4':
$table = "guide_booking";
break;
case '5':
$table = "transport_flight_booking";
break;
case '6':
$table = "transport_railway_booking";
break;
default:
echo "Unknown booking type";
}
$subtotal_price = "SELECT subtotal_price FROM cart_bookings WHERE booking_id='$booking_id'";
$res = mysqli_query($conn, $subtotal_price);
$subtotal_price = mysqli_fetch_assoc($res);
$subtotal_price = $subtotal_price['subtotal_price'];
$quantity_query = "SELECT quantity FROM `$table` WHERE booking_id='$booking_id'";
$res = mysqli_query($conn, $quantity_query);
$quantity = mysqli_fetch_assoc($res);
$quantity = $quantity['quantity'];
$delete_query = "DELETE FROM bookings WHERE booking_id='$booking_id'";
$res = mysqli_query($conn, $delete_query);
if (!$res) {
echo "<script type='text/javascript'>
alert('Error occurred!');
</script>";
} else {
header('Location: ../cart.php'); // Redirect after successful deletion
}
$total = "UPDATE user_buyer SET cart_total_price = cart_total_price - ('$subtotal_price' * '$quantity') WHERE u_id='$uid'";
$res = mysqli_query($conn, $total);
if (!$res) {
echo "<script type='text/javascript'>
alert('Error occurred!');
</script>";
}
exit();
} else {
header('Location: ../cart.php'); // Redirect if booking_id is not set
exit();
}
?>

View File

@@ -0,0 +1,68 @@
<?php
include "../../../ConnectDB.php";
session_start();
$uid = mysqli_real_escape_string($conn, $_SESSION['uid']);
if (isset($_GET["booking_id"]) && isset($_GET["table"]) && isset($_GET["quantity"])) {
$booking_id = $_GET["booking_id"];
$quantity = $_GET["quantity"];
if($quantity > 0){
switch ($_GET["table"]) {
case '1':
$table = "hotel_booking";
break;
case '2':
$table = "restaurant_booking";
break;
case '3':
$table = "attraction_booking";
break;
case '4':
$table = "guide_booking";
break;
case '5':
$table = "transport_flight_booking";
break;
case '6':
$table = "transport_railway_booking";
break;
default:
echo "Unknown booking type";
exit();
}
$quantity_query = "SELECT quantity FROM `$table` WHERE booking_id='$booking_id'";
$res = mysqli_query($conn, $quantity_query);
$old_quantity = mysqli_fetch_assoc($res);
$old_quantity = $old_quantity['quantity'];
$price_query = "SELECT `subtotal_price` FROM cart_bookings WHERE booking_id=" . $booking_id;
$priceRes = mysqli_query($conn, $price_query);
$price = mysqli_fetch_assoc($priceRes);
$price = $price["subtotal_price"];
$modified_price = $price * ($quantity - $old_quantity);
$add = "UPDATE `$table` SET quantity = '$quantity' WHERE booking_id='$booking_id'";
$res = mysqli_query($conn, $add);
if (!$res) {
echo "<script type='text/javascript'>
alert('Error occurred!');
</script>";
}
$total = "UPDATE user_buyer SET cart_total_price = cart_total_price + '$modified_price' WHERE u_id='$uid'";
$res = mysqli_query($conn, $total);
if (!$res) {
echo "<script type='text/javascript'>
alert('Error occurred!');
</script>";
}
}
}
header('Location: ../cart.php');
?>

View File

@@ -0,0 +1,69 @@
<?php
include "../../../ConnectDB.php";
session_start();
$uid = mysqli_real_escape_string($conn, $_SESSION['uid']);
if (isset($_GET["booking_id"]) && isset($_GET["table"])) {
$booking_id = $_GET["booking_id"];
switch ($_GET["table"]) {
case '1':
$table = "hotel_booking";
break;
case '2':
$table = "restaurant_booking";
break;
case '3':
$table = "attraction_booking";
break;
case '4':
$table = "guide_booking";
break;
case '5':
$table = "transport_flight_booking";
break;
case '6':
$table = "transport_railway_booking";
break;
default:
echo "Unknown booking type";
}
$price_query = "SELECT `subtotal_price` FROM cart_bookings WHERE booking_id=" . $booking_id;
$priceRes = mysqli_query($conn, $price_query);
$price = mysqli_fetch_assoc($priceRes);
$price = $price["subtotal_price"];
$quantity_query = "SELECT quantity FROM `$table` WHERE booking_id='$booking_id'";
$res = mysqli_query($conn, $quantity_query);
$quantity = mysqli_fetch_assoc($res);
$quantity = $quantity['quantity'];
if($quantity > 1){
$add = "UPDATE `$table` SET quantity = '$quantity' - 1 WHERE booking_id='$booking_id'";
$res = mysqli_query($conn, $add);
if (!$res) {
echo "<script type='text/javascript'>
alert('Error occurred!');
</script>";
}
$total = "UPDATE user_buyer SET cart_total_price = cart_total_price - '$price' WHERE u_id='$uid'";
$res = mysqli_query($conn, $total);
if (!$res) {
echo "<script type='text/javascript'>
alert('Error occurred!');
</script>";
}
}
else{
echo "<script type='text/javascript'>
alert('You cannot buy 0 quantity!');
</script>";
}
}
header('Location: ../cart.php');
?>