Sindbad~EG File Manager
<?php
session_start();
include 'conn.php';
include 'manage-common1.php';
// Pagination
$limit = 10; // Number of orders per page
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$offset = ($page - 1) * $limit;
// Fetch orders with pagination
$sql = "SELECT * FROM orders ORDER BY order_date DESC LIMIT ? OFFSET ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ii", $limit, $offset);
$stmt->execute();
$orders = $stmt->get_result();
// Fetch total number of orders for pagination
$sqlTotal = "SELECT COUNT(*) AS total FROM orders";
$result = $conn->query($sqlTotal);
$totalOrders = $result->fetch_assoc()['total'];
$totalPages = ceil($totalOrders / $limit);
// Delete Order
if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['delete_order_id'])) {
$order_id = $_GET['delete_order_id'];
$sqlDelete = "DELETE FROM orders WHERE id=?";
$stmt = $conn->prepare($sqlDelete);
$stmt->bind_param("i", $order_id);
if ($stmt->execute()) {
header("Location: manage-orders.php?page=$page");
exit();
} else {
echo "Error: Unable to delete order.";
}
$stmt->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Manage Orders</title>
</head>
<body>
<?php include 'manage-nav.php';?>
<div class="container mt-5">
<h2>Orders</h2>
<table class="table table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Pincode</th>
<th>Address</th>
<th>Contact</th>
<th>Item Details</th>
<th>Order Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php while ($row = $orders->fetch_assoc()): ?>
<tr class="mt-3">
<td><?php echo htmlspecialchars($row['id']); ?></td>
<td><?php echo htmlspecialchars($row['name']); ?></td>
<td><?php echo htmlspecialchars($row['pincode']); ?></td>
<td><?php echo htmlspecialchars($row['address']); ?></td>
<td><?php echo htmlspecialchars($row['contact']); ?></td>
<td>
<?php
$item_details = json_decode($row['item_details'], true);
$total_price = 0; // Initialize total price for this order
foreach ($item_details as $item) {
$item_price = $item['price']; // Assuming item details include 'price'
$item_total = $item_price * $item['quantity'];
$total_price += $item_total;
echo htmlspecialchars($item['name']) . " (Qty: " . htmlspecialchars($item['quantity']) . ", Price: ₹" . number_format($item_price, 2) . ") - Total: ₹" . number_format($item_total, 2) . "<br>";
}
?>
<strong>Total Price:</strong> : ₹<?php echo number_format($total_price, 2); ?>
</td>
<td><?php echo htmlspecialchars($row['order_date']); ?></td>
<td>
<a href="manage-orders.php?delete_order_id=<?php echo htmlspecialchars($row['id']); ?>" class="btn btn-danger">Delete</a>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<nav>
<ul class="pagination">
<li class="page-item <?php if ($page <= 1) echo 'disabled'; ?>">
<a class="page-link" href="?page=<?php echo $page - 1; ?>">Previous</a>
</li>
<?php for ($i = 1; $i <= $totalPages; $i++): ?>
<li class="page-item <?php if ($i == $page) echo 'active'; ?>">
<a class="page-link" href="?page=<?php echo $i; ?>"><?php echo $i; ?></a>
</li>
<?php endfor; ?>
<li class="page-item <?php if ($page >= $totalPages) echo 'disabled'; ?>">
<a class="page-link" href="?page=<?php echo $page + 1; ?>">Next</a>
</li>
</ul>
</nav>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists