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

184 lines
8.3 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'restaurant_owner') {
header('Location: login.php');
exit();
}
require_once 'db/config.php';
$pdo = db();
$stmt = $pdo->prepare("SELECT id, name FROM restaurants WHERE user_id = ?");
$stmt->execute([$_SESSION['user_id']]);
$restaurant = $stmt->fetch(PDO::FETCH_ASSOC);
$orders = [];
$menu_items = [];
if ($restaurant) {
$stmt_orders = $pdo->prepare(
"SELECT o.*, GROUP_CONCAT(CONCAT(oi.quantity, ' x ', mi.name) SEPARATOR '<br>') as items
FROM orders o
JOIN order_items oi ON o.id = oi.order_id
JOIN menu_items mi ON oi.menu_item_id = mi.id
WHERE o.restaurant_id = ?
GROUP BY o.id
ORDER BY o.created_at DESC
LIMIT 20"
);
$stmt_orders->execute([$restaurant['id']]);
$orders = $stmt_orders->fetchAll(PDO::FETCH_ASSOC);
$stmt_menu = $pdo->prepare("SELECT id, name, description, price FROM menu_items WHERE restaurant_id = ? ORDER BY id DESC");
$stmt_menu->execute([$restaurant['id']]);
$menu_items = $stmt_menu->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>Dashboard - 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(); ?>">
<script src="https://unpkg.com/feather-icons"></script>
</head>
<body>
<header class="navbar">
<div class="container">
<div class="navbar-inner">
<a href="/" class="logo">MajuroEats</a>
<nav class="nav-links">
<a href="logout.php">Log Out</a>
</nav>
</div>
</div>
</header>
<main class="container section">
<h1 class="page-title">Restaurant Dashboard</h1>
<?php if ($restaurant): ?>
<div class="dashboard-header">
<h2><?php echo htmlspecialchars($restaurant['name']); ?></h2>
</div>
<div class="tabs">
<button class="tab-link active" onclick="openTab(event, 'orders')">Orders</button>
<button class="tab-link" onclick="openTab(event, 'menu')">Menu</button>
</div>
<div id="orders" class="tab-content active">
<div class="dashboard-content">
<h3>Recent Orders</h3>
<?php if (count($orders) > 0): ?>
<div class="order-list">
<?php foreach ($orders as $order): ?>
<div class="order-card">
<div class="order-header">
<span class="order-id">Order #<?php echo $order['id']; ?></span>
<span class="status status-<?php echo strtolower(htmlspecialchars($order['status'])); ?>"><?php echo ucfirst(htmlspecialchars($order['status'])); ?></span>
</div>
<div class="order-body">
<p><strong>Customer:</strong> <?php echo htmlspecialchars($order['customer_name']); ?></p>
<p><strong>Items:</strong><br><?php echo $order['items']; ?></p>
</div>
<div class="order-footer">
<form action="update_order_status.php" method="POST">
<input type="hidden" name="order_id" value="<?php echo $order['id']; ?>">
<select name="status">
<option value="pending" <?php if($order['status'] == 'pending') echo 'selected'; ?>>Pending</option>
<option value="confirmed" <?php if($order['status'] == 'confirmed') echo 'selected'; ?>>Confirmed</option>
<option value="delivered" <?php if($order['status'] == 'delivered') echo 'selected'; ?>>Delivered</option>
<option value="cancelled" <?php if($order['status'] == 'cancelled') echo 'selected'; ?>>Cancelled</option>
</select>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<p>You have no recent orders.</p>
<?php endif; ?>
</div>
</div>
<div id="menu" class="tab-content">
<div class="dashboard-content">
<h3>Your Menu Items</h3>
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Price</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($menu_items as $item): ?>
<tr>
<td><?php echo htmlspecialchars($item['name']); ?></td>
<td>$<?php echo htmlspecialchars(number_format($item['price'], 2)); ?></td>
<td><a href="#">Edit</a></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<div class="dashboard-content" style="margin-top: 2rem;">
<h3>Add New Item</h3>
<form action="add_menu_item.php" method="POST" class="form-card">
<input type="hidden" name="restaurant_id" value="<?php echo $restaurant['id']; ?>">
<div class="form-group">
<label for="item_name">Item Name</label>
<input type="text" id="item_name" name="item_name" required>
</div>
<div class="form-group">
<label for="item_description">Description</label>
<textarea id="item_description" name="item_description" rows="3"></textarea>
</div>
<div class="form-group">
<label for="item_price">Price</label>
<input type="number" id="item_price" name="item_price" step="0.01" required>
</div>
<button type="submit" class="btn btn-primary">Add Item</button>
</form>
</div>
</div>
<?php else: ?>
<p>You do not have a restaurant associated with your account.</p>
<?php endif; ?>
</main>
<footer>
<div class="container">
<p>&copy; 2025 MajuroEats. All Rights Reserved.</p>
</div>
</footer>
<script>
feather.replace();
function openTab(evt, tabName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tab-content");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tab-link");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(tabName).style.display = "block";
evt.currentTarget.className += " active";
}
// Set default open tab
document.addEventListener('DOMContentLoaded', function() {
document.querySelector('.tab-link.active').click();
});
</script>
</body>
</html>