HEX
Server: LiteSpeed
System: Linux server214.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
User: bigisxfd (746)
PHP: 8.4.15
Disabled: NONE
Upload Files
File: /home/bigisxfd/public_html/cowork/extend_booking.php
<?php
// Include necessary files
include_once("functions.php");

if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["bookingId"]) && isset($_POST["extensionDuration"])) {
    $bookingId = $_POST["bookingId"];
    $extensionDuration = $_POST["extensionDuration"];

    // Fetch the booking details from the database based on the bookingId
    $query = "SELECT startdate, enddate FROM Bookings WHERE bookingid = ?";
    $stmt = $conn->prepare($query);
    $stmt->bind_param("i", $bookingId);
    $stmt->execute();
    $stmt->bind_result($startTime, $endTime);
    $stmt->fetch();
    $stmt->close();

    // Calculate new end time after extension
    $extendedEndTime = date("Y-m-d H:i:s", strtotime($endTime . "+$extensionDuration hours"));

    // Update the booking record with the new end time and payment status
    $updateQuery = "UPDATE Bookings SET enddate = ?, paymentstatus = 0 WHERE bookingid = ?";
    $updateStmt = $conn->prepare($updateQuery);
    $updateStmt->bind_param("si", $extendedEndTime, $bookingId);

    if ($updateStmt->execute()) {
        // Insert a record into the Orders table
        $insertOrderQuery = "INSERT INTO Orders (bookingid, memberid, userid, date, amount, items) VALUES (?, ?, ?, NOW(), ?, ?)";
        $insertOrderStmt = $conn->prepare($insertOrderQuery);

        // Get the member ID and user ID from the Bookings table
        $memberIdQuery = "SELECT memberid, userid FROM Bookings WHERE bookingid = ?";
        $memberIdStmt = $conn->prepare($memberIdQuery);
        $memberIdStmt->bind_param("i", $bookingId);
        $memberIdStmt->execute();
        $memberIdStmt->bind_result($memberId, $userId);
        $memberIdStmt->fetch();
        $memberIdStmt->close();

        // Calculate the order amount based on extension duration
        if ($extensionDuration == 1) {
            $orderAmount = 150; // 1 Hour Extension
            $extensionText = "1 Hour Extension";
        } elseif ($extensionDuration == 3) {
            $orderAmount = 250; // 3 Hours Extension
            $extensionText = "3 Hours Extension";
        } else {
            // Invalid extension duration
            echo "Invalid extension duration.";
            exit;
        }

        // Bind parameters and execute the insert query
        $insertOrderStmt->bind_param("iiids", $bookingId, $memberId, $userId, $orderAmount, $extensionText);
        if ($insertOrderStmt->execute()) {
            // Order insertion successful
            echo "Booking extended successfully and order inserted.";
        } else {
            // Error occurred while inserting order
            echo "Error extending booking and inserting order.";
        }
        $insertOrderStmt->close();
    } else {
        // Error occurred while updating the booking
        echo "Error extending booking.";
    }
    $updateStmt->close();
} else {
    // Invalid request
    echo "Invalid request.";
}

// Close the database connection
$conn->close();
?>