36766-vm/orders.php
Flatlogic Bot 6c14b2436f 2.0
2025-12-18 09:40:37 +00:00

73 lines
2.1 KiB
PHP

<?php
require_once 'includes/header.php';
require_once 'db/config.php';
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
$pdo = db();
$status = isset($_GET['status']) ? $_GET['status'] : 'All';
$statuses = ['All', 'Pending', 'Completed', 'Shipped', 'Delivered'];
if (!in_array($status, $statuses)) {
$status = 'All';
}
$sql = "SELECT * FROM orders WHERE user_id = ?";
$params = [$_SESSION['user_id']];
if ($status !== 'All') {
$sql .= " AND status = ?";
$params[] = $status;
}
$sql .= " ORDER BY created_at DESC";
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$orders = $stmt->fetchAll();
?>
<h1 class="mb-4">My Orders</h1>
<ul class="nav nav-tabs mb-3">
<?php foreach ($statuses as $s): ?>
<li class="nav-item">
<a class="nav-link <?php echo ($status === $s) ? 'active' : ''; ?>" href="?status=<?php echo $s; ?>"><?php echo $s; ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php if (empty($orders)): ?>
<div class="alert alert-info">
You have no orders with the status '<?php echo htmlspecialchars($status); ?>'.
</div>
<?php else: ?>
<table class="table">
<thead>
<tr>
<th>Order ID</th>
<th>Total Amount</th>
<th>Status</th>
<th>Date</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($orders as $order): ?>
<tr>
<td>#<?php echo $order['id']; ?></td>
<td>$<?php echo number_format($order['total_amount'], 2); ?></td>
<td><span class="badge bg-primary"><?php echo htmlspecialchars($order['status']); ?></span></td>
<td><?php echo date("F j, Y, g:i a", strtotime($order['created_at'])); ?></td>
<td><a href="order_details.php?id=<?php echo $order['id']; ?>" class="btn btn-sm btn-info">View Details</a></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<?php require_once 'includes/footer.php'; ?>