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

120 lines
5.6 KiB
PHP

<?php
require_once 'db/config.php';
$restaurant_id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
$restaurant = null;
$menu_items = [];
if ($restaurant_id) {
try {
$pdo = db();
$stmt_restaurant = $pdo->prepare('SELECT name, description, image_url FROM restaurants WHERE id = :id');
$stmt_restaurant->bindParam(':id', $restaurant_id, PDO::PARAM_INT);
$stmt_restaurant->execute();
$restaurant = $stmt_restaurant->fetch(PDO::FETCH_ASSOC);
if ($restaurant) {
$stmt_menu = $pdo->prepare('SELECT id, name, description, price, image_url FROM menu_items WHERE restaurant_id = :id ORDER BY name');
$stmt_menu->bindParam(':id', $restaurant_id, PDO::PARAM_INT);
$stmt_menu->execute();
$menu_items = $stmt_menu->fetchAll(PDO::FETCH_ASSOC);
}
} catch (PDOException $e) {
// In a real app, log this error.
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo $restaurant ? htmlspecialchars($restaurant['name']) : 'Menu'; ?> - 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>
<?php session_start(); ?>
<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'])): ?>
<?php if ($_SESSION['user_role'] === 'customer'): ?>
<a href="customer_dashboard.php">My Account</a>
<?php elseif ($_SESSION['user_role'] === 'restaurant_owner'): ?>
<a href="dashboard.php">Dashboard</a>
<?php endif; ?>
<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>
<?php if ($restaurant): ?>
<section class="menu-header" style="background-image: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)), url('<?php echo htmlspecialchars($restaurant['image_url'] ? $restaurant['image_url'] : 'assets/images/placeholder.jpg'); ?>');">
<div class="container">
<h1><?php echo htmlspecialchars($restaurant['name']); ?></h1>
<p><?php echo htmlspecialchars($restaurant['description']); ?></p>
</div>
</section>
<div class="container section">
<h2 class="section-title">Menu</h2>
<?php if (count($menu_items) > 0): ?>
<div class="menu-grid">
<?php foreach ($menu_items as $item): ?>
<div class="menu-item-card">
<div class="menu-item-image" style="background-image: url('<?php echo htmlspecialchars($item['image_url'] ? $item['image_url'] : 'assets/images/placeholder.jpg'); ?>');"></div>
<div class="menu-item-content">
<h3><?php echo htmlspecialchars($item['name']); ?></h3>
<p><?php echo htmlspecialchars($item['description']); ?></p>
<div class="menu-item-footer">
<span class="menu-item-price">$<?php echo htmlspecialchars(number_format($item['price'], 2)); ?></span>
<?php
$item_json = htmlspecialchars(json_encode(['id' => $item['id'], 'name' => $item['name'], 'price' => $item['price']]), ENT_QUOTES, 'UTF-8');
?>
<button class="btn btn-primary add-to-cart-btn" onclick="shoppingCart.addItem(<?php echo $item_json; ?>, <?php echo $restaurant_id; ?>)">Add to Cart</button>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<p>This restaurant currently has no menu items.</p>
<?php endif; ?>
</div>
<?php else: ?>
<div class="container section">
<h1 class="page-title">Restaurant not found</h1>
<p>Sorry, the restaurant you are looking for does not exist.</p>
</div>
<?php endif; ?>
</main>
<footer>
<div class="container">
<p>&copy; 2025 MajuroEats. All Rights Reserved.</p>
</div>
</footer>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
<script>
feather.replace();
</script>
</body>
</html>