diff --git a/admin_restaurants.php b/admin_restaurants.php index a570583..84121e8 100644 --- a/admin_restaurants.php +++ b/admin_restaurants.php @@ -59,6 +59,7 @@ Address Phone Email + Cuisine Actions @@ -97,6 +98,10 @@ +
+ + +
@@ -185,6 +190,7 @@ ${r.address} ${r.phone} ${r.email} + ${r.cuisine} @@ -210,6 +216,7 @@ document.getElementById('address').value = row.querySelector('[data-field="address"]').textContent; document.getElementById('phone').value = row.querySelector('[data-field="phone"]').textContent; document.getElementById('email').value = row.querySelector('[data-field="email"]').textContent; + document.getElementById('cuisine').value = row.querySelector('[data-field="cuisine"]').textContent; restaurantModalLabel.textContent = 'Edit Restaurant'; restaurantModal.show(); diff --git a/api/restaurants.php b/api/restaurants.php index d7c882a..a3b69b7 100644 --- a/api/restaurants.php +++ b/api/restaurants.php @@ -27,7 +27,7 @@ switch ($method) { function handle_get() { try { $pdo = db(); - $stmt = $pdo->query("SELECT id, name, address, phone, email FROM restaurants ORDER BY created_at DESC"); + $stmt = $pdo->query("SELECT id, name, cuisine, address, phone, email FROM restaurants ORDER BY created_at DESC"); $restaurants = $stmt->fetchAll(PDO::FETCH_ASSOC); echo json_encode(['success' => true, 'data' => $restaurants]); } catch (PDOException $e) { @@ -39,7 +39,7 @@ function handle_get() { function handle_post() { $data = json_decode(file_get_contents('php://input'), true); - if (empty($data['name']) || empty($data['address']) || empty($data['phone']) || empty($data['email'])) { + if (empty($data['name']) || empty($data['address']) || empty($data['phone']) || empty($data['email']) || empty($data['cuisine'])) { header('HTTP/1.1 400 Bad Request'); echo json_encode(['success' => false, 'error' => 'All fields are required.']); return; @@ -47,10 +47,11 @@ function handle_post() { try { $pdo = db(); - $sql = "INSERT INTO restaurants (name, address, phone, email) VALUES (:name, :address, :phone, :email)"; + $sql = "INSERT INTO restaurants (name, cuisine, address, phone, email) VALUES (:name, :cuisine, :address, :phone, :email)"; $stmt = $pdo->prepare($sql); $stmt->execute([ ':name' => $data['name'], + ':cuisine' => $data['cuisine'], ':address' => $data['address'], ':phone' => $data['phone'], ':email' => $data['email'], @@ -59,7 +60,7 @@ function handle_post() { $lastInsertId = $pdo->lastInsertId(); // Fetch the created restaurant to return it - $stmt = $pdo->prepare("SELECT id, name, address, phone, email FROM restaurants WHERE id = :id"); + $stmt = $pdo->prepare("SELECT id, name, cuisine, address, phone, email FROM restaurants WHERE id = :id"); $stmt->execute(['id' => $lastInsertId]); $newRestaurant = $stmt->fetch(PDO::FETCH_ASSOC); @@ -73,7 +74,7 @@ function handle_post() { function handle_put() { $data = json_decode(file_get_contents('php://input'), true); - if (empty($data['id']) || empty($data['name']) || empty($data['address']) || empty($data['phone']) || empty($data['email'])) { + if (empty($data['id']) || empty($data['name']) || empty($data['address']) || empty($data['phone']) || empty($data['email']) || empty($data['cuisine'])) { header('HTTP/1.1 400 Bad Request'); echo json_encode(['success' => false, 'error' => 'All fields including ID are required.']); return; @@ -81,11 +82,12 @@ function handle_put() { try { $pdo = db(); - $sql = "UPDATE restaurants SET name = :name, address = :address, phone = :phone, email = :email WHERE id = :id"; + $sql = "UPDATE restaurants SET name = :name, cuisine = :cuisine, address = :address, phone = :phone, email = :email WHERE id = :id"; $stmt = $pdo->prepare($sql); $stmt->execute([ ':id' => $data['id'], ':name' => $data['name'], + ':cuisine' => $data['cuisine'], ':address' => $data['address'], ':phone' => $data['phone'], ':email' => $data['email'], diff --git a/index.php b/index.php index d366bee..444ff56 100644 --- a/index.php +++ b/index.php @@ -2,12 +2,15 @@ require_once 'db/config.php'; $restaurants = []; +$cuisines = []; try { $pdo = db(); - $stmt = $pdo->query("SELECT id, name, address, phone, email FROM restaurants ORDER BY name ASC"); + $stmt = $pdo->query("SELECT id, name, cuisine, address, phone, email FROM restaurants ORDER BY name ASC"); $restaurants = $stmt->fetchAll(PDO::FETCH_ASSOC); + + $stmt = $pdo->query("SELECT DISTINCT cuisine FROM restaurants WHERE cuisine IS NOT NULL AND cuisine != '' ORDER BY cuisine ASC"); + $cuisines = $stmt->fetchAll(PDO::FETCH_COLUMN); } catch (PDOException $e) { - // For a real app, you would log this error and show a user-friendly message. error_log("Database error: " . $e->getMessage()); } @@ -58,17 +61,32 @@ try {
-
+
+
+ +
+
+ +
+
+ +

No restaurants are available at the moment. Please check back later.

-
+
@@ -77,11 +95,49 @@ try {
+
+