173 lines
9.2 KiB
PHP
173 lines
9.2 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// Fetch emergency shutdown status
|
|
$stmt_shutdown = db()->prepare("SELECT value FROM settings WHERE name = ?");
|
|
$stmt_shutdown->execute(['emergency_shutdown']);
|
|
$shutdown_active = ($stmt_shutdown->fetchColumn() === 'true');
|
|
|
|
$restaurant_id = isset($_GET['restaurant_id']) ? (int)$_GET['restaurant_id'] : 0;
|
|
|
|
if ($restaurant_id === 0) {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
require_once 'header.php';
|
|
|
|
try {
|
|
// Fetch restaurant details
|
|
$stmt = db()->prepare("SELECT r.id, r.name, r.image_url, STRING_AGG(c.name, ', ') as cuisines
|
|
FROM restaurants r
|
|
LEFT JOIN restaurant_cuisines rc ON r.id = rc.restaurant_id
|
|
LEFT JOIN cuisines c ON rc.cuisine_id = c.id
|
|
WHERE r.id = :id
|
|
GROUP BY r.id");
|
|
$stmt->bindParam(':id', $restaurant_id, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
$restaurant = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$restaurant) {
|
|
throw new Exception("Restaurant not found.");
|
|
}
|
|
|
|
// Fetch menu items
|
|
$menu_stmt = db()->prepare("SELECT id, name, description, price, image_url FROM menu_items WHERE restaurant_id = :restaurant_id ORDER BY name ASC");
|
|
$menu_stmt->bindParam(':restaurant_id', $restaurant_id, PDO::PARAM_INT);
|
|
$menu_stmt->execute();
|
|
$menu_items = $menu_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// Fetch ratings and calculate average
|
|
$ratings_stmt = db()->prepare("SELECT r.rating, r.review, r.created_at, u.name as user_name FROM ratings r JOIN users u ON r.user_id = u.id WHERE r.restaurant_id = :restaurant_id ORDER BY r.created_at DESC");
|
|
$ratings_stmt->bindParam(':restaurant_id', $restaurant_id, PDO::PARAM_INT);
|
|
$ratings_stmt->execute();
|
|
$ratings = $ratings_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$average_rating = 0;
|
|
$rating_count = count($ratings);
|
|
if ($rating_count > 0) {
|
|
$total_rating = array_sum(array_column($ratings, 'rating'));
|
|
$average_rating = round($total_rating / $rating_count, 1);
|
|
}
|
|
|
|
// Check if this restaurant is a favorite for the current user
|
|
$is_favorite = false;
|
|
if (isset($_SESSION['user_id'])) {
|
|
$fav_stmt = db()->prepare("SELECT COUNT(*) FROM favorite_restaurants WHERE user_id = :user_id AND restaurant_id = :restaurant_id");
|
|
$fav_stmt->bindParam(':user_id', $_SESSION['user_id'], PDO::PARAM_INT);
|
|
$fav_stmt->bindParam(':restaurant_id', $restaurant_id, PDO::PARAM_INT);
|
|
$fav_stmt->execute();
|
|
$is_favorite = $fav_stmt->fetchColumn() > 0;
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
echo "<div class='container my-5'><p class='alert alert-danger'>" . $e->getMessage() . "</p></div>";
|
|
require_once 'footer.php';
|
|
exit;
|
|
}
|
|
?>
|
|
|
|
<!-- Restaurant Hero Section -->
|
|
<div class="restaurant-hero-menu" style="background-image: url('<?php echo htmlspecialchars($restaurant['image_url'] ?: 'https://via.placeholder.com/1600x500/dee2e6/6c757d.text=Restaurant+Image'); ?>');">
|
|
<div class="restaurant-hero-menu-content">
|
|
<h1 class="display-4 fw-bold"><?php echo htmlspecialchars($restaurant['name']); ?></h1>
|
|
<p class="lead"><?php echo htmlspecialchars($restaurant['cuisines']); ?></p>
|
|
<div class="d-flex align-items-center justify-content-center">
|
|
<span class="h4 text-warning me-2 fw-bold"><?php echo number_format($average_rating, 1); ?> <i class="fas fa-star"></i></span>
|
|
<span class="text-white">(<?php echo $rating_count; ?> reviews)</span>
|
|
<?php if (isset($_SESSION['user_id'])) : ?>
|
|
<form action="toggle_favorite.php" method="post" class="ms-4">
|
|
<input type="hidden" name="restaurant_id" value="<?php echo $restaurant_id; ?>">
|
|
<button type="submit" class="btn <?php echo $is_favorite ? 'btn-danger' : 'btn-outline-light'; ?> btn-sm">
|
|
<i class="fas fa-heart"></i> <?php echo $is_favorite ? 'Favorited' : 'Favorite'; ?>
|
|
</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="container my-5">
|
|
<?php if ($shutdown_active): ?>
|
|
<div class="alert alert-danger text-center" role="alert">
|
|
<h4 class="alert-heading">Ordering Temporarily Disabled</h4>
|
|
<p>We have temporarily suspended all delivery services for safety reasons. We apologize for any inconvenience.</p>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="row">
|
|
<div class="col-lg-8">
|
|
<h2 class="mb-4 fw-bold">Menu</h2>
|
|
<div class="row row-cols-1 row-cols-md-2 g-4">
|
|
<?php if ($menu_items): ?>
|
|
<?php foreach ($menu_items as $item): ?>
|
|
<div class="col">
|
|
<div class="card menu-item-card-new h-100 shadow-sm">
|
|
<div class="row g-0">
|
|
<div class="col-md-4">
|
|
<img src="<?php echo htmlspecialchars($item['image_url'] ?: 'https://via.placeholder.com/300x300/dee2e6/6c757d.text=No+Image'); ?>" class="img-fluid rounded-start" alt="<?php echo htmlspecialchars($item['name']); ?>">
|
|
</div>
|
|
<div class="col-md-8">
|
|
<div class="card-body d-flex flex-column h-100">
|
|
<h5 class="card-title fw-bold"><?php echo htmlspecialchars($item['name']); ?></h5>
|
|
<p class="card-text text-muted flex-grow-1"><?php echo htmlspecialchars($item['description']); ?></p>
|
|
<div class="d-flex justify-content-between align-items-center mt-auto">
|
|
<span class="price fs-5 fw-bold text-primary">$<?php echo htmlspecialchars(number_format($item['price'], 2)); ?></span>
|
|
<?php if (!$shutdown_active): ?>
|
|
<form action="cart_actions.php" method="post" class="add-to-cart-form">
|
|
<input type="hidden" name="action" value="add">
|
|
<input type="hidden" name="restaurant_id" value="<?php echo $restaurant_id; ?>">
|
|
<input type="hidden" name="menu_item_id" value="<?php echo $item['id']; ?>">
|
|
<input type="hidden" name="quantity" value="1">
|
|
<button type="submit" class="btn btn-primary btn-sm">Add <i class="fas fa-cart-plus"></i></button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php else: ?>
|
|
<div class="col-12">
|
|
<div class="alert alert-info text-center">
|
|
<i class="fas fa-info-circle fa-2x mb-2"></i><br>
|
|
This restaurant has no menu items yet.
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-4">
|
|
<div class="reviews-section bg-light p-4 rounded-3">
|
|
<h2 class="mb-4 fw-bold">Reviews</h2>
|
|
<?php if ($ratings): ?>
|
|
<?php foreach (array_slice($ratings, 0, 5) as $rating): ?>
|
|
<div class="review-card mb-3">
|
|
<div class="d-flex align-items-center mb-2">
|
|
<strong class="me-auto"><?php echo htmlspecialchars($rating['user_name']); ?></strong>
|
|
<span class="text-warning small"><?php echo str_repeat('★', $rating['rating']) . str_repeat('☆', 5 - $rating['rating']); ?></span>
|
|
</div>
|
|
<p class="review-text fst-italic text-muted">"<?php echo nl2br(htmlspecialchars($rating['review'])); ?>"</p>
|
|
<small class="text-muted"><?php echo date('F j, Y', strtotime($rating['created_at'])); ?></small>
|
|
</div>
|
|
<hr>
|
|
<?php endforeach; ?>
|
|
<?php else: ?>
|
|
<p>This restaurant has no reviews yet.</p>
|
|
<?php endif; ?>
|
|
|
|
<?php if (isset($_SESSION['user_id'])): ?>
|
|
<a href="leave_review.php?restaurant_id=<?php echo $restaurant_id; ?>" class="btn btn-outline-primary mt-3 w-100">Leave a Review</a>
|
|
<?php else: ?>
|
|
<p class="mt-3 text-center"><a href="login.php?redirect_url=<?php echo urlencode($_SERVER['REQUEST_URI']); ?>">Log in</a> to leave a review.</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once 'footer.php'; ?>
|