34943-vm/customer_dashboard.php
Flatlogic Bot 0fcbb065ea 0001
2025-10-14 03:03:16 +00:00

100 lines
3.8 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'customer') {
header('Location: login.php');
exit();
}
require_once 'db/config.php';
$pdo = db();
$stmt = $pdo->prepare(
"SELECT o.id, o.created_at, o.total_price, o.status, r.name as restaurant_name
FROM orders o
JOIN restaurants r ON o.restaurant_id = r.id
WHERE o.user_id = ?
ORDER BY o.created_at DESC"
);
$stmt->execute([$_SESSION['user_id']]);
$orders = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Account - MajuroEats</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<header class="navbar">
<div class="container">
<div class="navbar-inner">
<a href="/" class="logo">MajuroEats</a>
<nav class="nav-links">
<a href="index.php#how-it-works">How It Works</a>
<a href="restaurants.php">Restaurants</a>
<a href="index.php#contact">Contact</a>
<a href="cart.php" class="cart-icon">
<i data-feather="shopping-cart"></i>
<span id="cart-count">0</span>
</a>
<?php if (isset($_SESSION['user_id'])): ?>
<a href="customer_dashboard.php">My Account</a>
<a href="logout.php">Log Out</a>
<?php else: ?>
<a href="login.php">Login</a>
<a href="customer_signup.php" class="btn btn-primary">Sign Up</a>
<?php endif; ?>
</nav>
</div>
</div>
</header>
<main class="container section">
<h1 class="page-title">Your Order History</h1>
<div class="dashboard-content">
<?php if (count($orders) > 0): ?>
<table class="table order-history-table">
<thead>
<tr>
<th>Order ID</th>
<th>Date</th>
<th>Restaurant</th>
<th>Total</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php foreach ($orders as $order): ?>
<tr>
<td>#<?php echo $order['id']; ?></td>
<td><?php echo date('M d, Y', strtotime($order['created_at'])); ?></td>
<td><?php echo htmlspecialchars($order['restaurant_name']); ?></td>
<td>$<?php echo htmlspecialchars(number_format($order['total_price'], 2)); ?></td>
<td><span class="status status-<?php echo strtolower(htmlspecialchars($order['status'])); ?>"><?php echo ucfirst(htmlspecialchars($order['status'])); ?></span></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<p>You have not placed any orders yet. <a href="restaurants.php">Start your first order!</a></p>
<?php endif; ?>
</div>
</main>
<footer>
<div class="container">
<p>&copy; 2025 MajuroEats. All Rights Reserved.</p>
</div>
</footer>
<script src="https://unpkg.com/feather-icons"></script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
<script>
feather.replace();
</script>
</body>
</html>