32 lines
891 B
PHP
32 lines
891 B
PHP
<?php
|
|
session_start();
|
|
require_once '../db/config.php';
|
|
|
|
// Check if the user is logged in as a restaurant owner
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'restaurant_owner') {
|
|
header('Location: ../restaurant_login.php');
|
|
exit;
|
|
}
|
|
|
|
$menu_item_id = $_GET['id'] ?? null;
|
|
|
|
if ($menu_item_id) {
|
|
$pdo = db();
|
|
|
|
// Get the restaurant ID associated with the logged-in user
|
|
$stmt = $pdo->prepare("SELECT id FROM restaurants WHERE user_id = ?");
|
|
$stmt->execute([$_SESSION['user_id']]);
|
|
$restaurant = $stmt->fetch();
|
|
|
|
if ($restaurant) {
|
|
$restaurant_id = $restaurant['id'];
|
|
|
|
// Delete the menu item only if it belongs to the owner's restaurant
|
|
$stmt = $pdo->prepare("DELETE FROM menu_items WHERE id = ? AND restaurant_id = ?");
|
|
$stmt->execute([$menu_item_id, $restaurant_id]);
|
|
}
|
|
}
|
|
|
|
header('Location: menu.php');
|
|
exit;
|
|
?>
|