+
+
diff --git a/index.php b/index.php
index a9c38a52..1096e358 100644
--- a/index.php
+++ b/index.php
@@ -1,132 +1,96 @@
query("
+ SELECT r.*, AVG(ra.rating) as avg_rating
+ FROM restaurants r
+ LEFT JOIN ratings ra ON r.id = ra.restaurant_id
+ GROUP BY r.id
+ ORDER BY avg_rating DESC
+ LIMIT 6
+");
+$top_restaurants = $stmt->fetchAll();
- $db = db();
- // Haversine formula to calculate distance
- $stmt = $db->prepare("
- SELECT r.id, r.name, r.image_url, AVG(rt.rating) as average_rating,
- (6371 * acos(cos(radians(?)) * cos(radians(latitude)) * cos(radians(longitude) - radians(?)) + sin(radians(?)) * sin(radians(latitude)))) AS distance
- FROM restaurants r
- LEFT JOIN ratings rt ON r.id = rt.restaurant_id
- WHERE latitude IS NOT NULL AND longitude IS NOT NULL
- GROUP BY r.id
- HAVING distance < ?
- ORDER BY distance
- LIMIT 12
- ");
-
- $stmt->execute([$lat, $lng, $lat, $radius]);
- $restaurants = $stmt->fetchAll(PDO::FETCH_ASSOC);
-
- // Get cuisines for each restaurant
- $cuisine_sql = "SELECT c.name FROM cuisines c JOIN restaurant_cuisines rc ON c.id = rc.cuisine_id WHERE rc.restaurant_id = ?";
- $cuisine_stmt = $db->prepare($cuisine_sql);
-
- foreach ($restaurants as &$restaurant) {
- $cuisine_stmt->execute([$restaurant['id']]);
- $restaurant['cuisines'] = $cuisine_stmt->fetchAll(PDO::FETCH_COLUMN);
- }
-
- echo json_encode($restaurants);
- exit;
-}
+// Fetch featured cuisines
+$stmt = $pdo->query("SELECT * FROM cuisines ORDER BY name ASC LIMIT 6");
+$cuisines = $stmt->fetchAll();
?>
-
-
-
-
-
-
-
$0 Delivery Fee
-
On your first order
-
-
-
Earn Rewards
-
With every meal
-
-
-
Support Local
-
Majuro Restaurants
+
+
+
How It Works
+
+
+
+
+
Choose A Restaurant
+
Browse from our extensive list of local restaurants.
+
+
+
+
+
+
Pick Your Meal
+
Select your favorite dishes and add them to your cart.
+
+
+
+
+
+
Fast Delivery
+
Get your food delivered right to your doorstep, fast!
+
+
- query("
- SELECT r.id, r.name, r.image_url, GROUP_CONCAT(c.name SEPARATOR ', ') as cuisines, AVG(rt.rating) as average_rating
- FROM restaurants r
- LEFT JOIN restaurant_cuisines rc ON r.id = rc.restaurant_id
- LEFT JOIN cuisines c ON rc.cuisine_id = c.id
- LEFT JOIN ratings rt ON r.id = rt.restaurant_id
- GROUP BY r.id
- ORDER BY average_rating DESC
- LIMIT 4
- ");
- $top_restaurants = $top_restaurants_stmt->fetchAll(PDO::FETCH_ASSOC);
-
- // Fetch Featured Cuisines
- $featured_cuisines_stmt = $db->query("
- SELECT c.id, c.name, c.image_url
- FROM cuisines c
- JOIN (
- SELECT cuisine_id, COUNT(*) as restaurant_count
- FROM restaurant_cuisines
- GROUP BY cuisine_id
- ORDER BY restaurant_count DESC
- LIMIT 4
- ) as popular_cuisines ON c.id = popular_cuisines.cuisine_id
- ");
- $featured_cuisines = $featured_cuisines_stmt->fetchAll(PDO::FETCH_ASSOC);
- ?>
-
-
-
-
+
diff --git a/order_status.php b/order_status.php
index 2742e3a5..4654885e 100644
--- a/order_status.php
+++ b/order_status.php
@@ -15,18 +15,29 @@ if (!$order_id) {
$pdo = db();
$order = null;
+// Fetch order details along with restaurant location
+$sql = "SELECT o.*, r.name as restaurant_name, r.lat as restaurant_lat, r.lng as restaurant_lng FROM orders o JOIN restaurants r ON o.restaurant_id = r.id WHERE o.id = ?";
+$params = [$order_id];
+
if ($user_id) {
- // User is logged in, verify order belongs to them
- $stmt = $pdo->prepare("SELECT o.*, r.name as restaurant_name FROM orders o JOIN restaurants r ON o.restaurant_id = r.id WHERE o.id = ? AND o.user_id = ?");
- $stmt->execute([$order_id, $user_id]);
- $order = $stmt->fetch(PDO::FETCH_ASSOC);
+ $sql .= " AND o.user_id = ?";
+ $params[] = $user_id;
} elseif ($token) {
- // Guest access, verify token
- $stmt = $pdo->prepare("SELECT o.*, r.name as restaurant_name FROM orders o JOIN restaurants r ON o.restaurant_id = r.id WHERE o.id = ? AND o.guest_token = ?");
- $stmt->execute([$order_id, $token]);
- $order = $stmt->fetch(PDO::FETCH_ASSOC);
+ $sql .= " AND o.token = ?";
+ $params[] = $token;
+} else {
+ // No user and no token, deny access
+ include 'header.php';
+ echo "
Authentication required to view this order.
";
+ include 'footer.php';
+ exit();
}
+$stmt = $pdo->prepare($sql);
+$stmt->execute($params);
+$order = $stmt->fetch(PDO::FETCH_ASSOC);
+
+
if (!$order) {
include 'header.php';
echo "
Order not found or you do not have permission to view it.