═══ File: functions.php ═══ Line: 851 ════════════════════════════════════════ function getProperties($filters = []) { try { $db = db(); $sql = "SELECT p.*, c.name AS category_name, ct.name AS city_name, co.name AS country_name, co.flag_emoji, (SELECT file_path FROM property_media WHERE property_id = p.id AND is_primary = 1 LIMIT 1) AS image FROM properties p LEFT JOIN categories c ON p.category_id = c.id LEFT JOIN destinations ct ON p.city_id = ct.id LEFT JOIN destinations co ON p.country_id = co.id WHERE p.is_active = 1 AND p.status = 'published'"; $params = []; if (!empty($filters['search'])) { $s = '%' . $filters['search'] . '%'; $sql .= " AND ( p.name LIKE ? OR p.short_description LIKE ? OR p.description LIKE ? OR ct.name LIKE ? OR co.name LIKE ? OR p.address_line1 LIKE ? OR p.address LIKE ? )"; for ($i = 0; $i < 7; $i++) $params[] = $s; } if (!empty($filters['category'])) { $sql .= " AND p.category_id = ?"; $params[] = (int)$filters['category']; } if (!empty($filters['country'])) { $countryId = (int)$filters['country']; $country = null; if ($countryId > 0) { try { $country = $db->fetchOne( "SELECT id, country_code FROM destinations WHERE id = ? AND type = 'country' LIMIT 1", [$countryId] ); } catch (Throwable $e) {} } if ($country) { $code = $country['country_code'] ?? ''; if ($code !== '') { $sql .= " AND ( p.country_id = ? OR co.country_code = ? OR p.city_id IN ( SELECT id FROM destinations WHERE type = 'city' AND (parent_id = ? OR country_code = ?) ) )"; $params[] = $countryId; $params[] = $code; $params[] = $countryId; $params[] = $code; } else { $sql .= " AND ( p.country_id = ? OR p.city_id IN ( SELECT id FROM destinations WHERE type = 'city' AND parent_id = ? ) )"; $params[] = $countryId; $params[] = $countryId; } } else { $sql .= " AND p.country_id = ?"; $params[] = $countryId; } } if (!empty($filters['city'])) { if (is_numeric($filters['city'])) { $sql .= " AND p.city_id = ?"; $params[] = (int)$filters['city']; } else { $sql .= " AND ct.name = ?"; $params[] = (string)$filters['city']; } } if (isset($filters['min_price']) && $filters['min_price'] !== '' && $filters['min_price'] !== null) { if ((float)$filters['min_price'] > 0) { $sql .= " AND p.min_price_per_night >= ?"; $params[] = (float)$filters['min_price']; } } if (isset($filters['max_price']) && $filters['max_price'] !== '' && $filters['max_price'] !== null) { if ((float)$filters['max_price'] > 0 && (float)$filters['max_price'] < 100000) { $sql .= " AND p.min_price_per_night <= ?"; $params[] = (float)$filters['max_price']; } } if (!empty($filters['star_rating'])) { $sql .= " AND p.star_rating >= ?"; $params[] = (int)$filters['star_rating']; } if (!empty($filters['instant_book'])) { $sql .= " AND p.is_instant_bookable = 1"; } $sort = $filters['sort'] ?? 'relevance'; switch ($sort) { case 'price_asc': $sql .= " ORDER BY p.min_price_per_night ASC, p.id DESC"; break; case 'price_desc': $sql .= " ORDER BY p.min_price_per_night DESC, p.id DESC"; break; case 'rating': $sql .= " ORDER BY p.average_rating DESC, p.total_reviews DESC"; break; case 'popularity': $sql .= " ORDER BY p.booking_count DESC, p.views_count DESC"; break; case 'newest': $sql .= " ORDER BY p.created_at DESC"; break; case 'relevance': default: $sql .= " ORDER BY p.is_featured DESC, p.average_rating DESC, p.created_at DESC"; } $limit = !empty($filters['limit']) ? (int)$filters['limit'] : 60; if ($limit < 1) $limit = 60; if ($limit > 500) $limit = 500; $sql .= " LIMIT " . $limit; $rows = $db->fetchAll($sql, $params); if (!is_array($rows)) $rows = []; if (empty($rows) && !empty($filters['search'])) { $s = '%' . $filters['search'] . '%'; $fallback = " SELECT p.*, c.name AS category_name, ct.name AS city_name, co.name AS country_name, co.flag_emoji, (SELECT file_path FROM property_media WHERE property_id = p.id AND is_primary = 1 LIMIT 1) AS image FROM properties p LEFT JOIN categories c ON p.category_id = c.id LEFT JOIN destinations ct ON p.city_id = ct.id LEFT JOIN destinations co ON p.country_id = co.id WHERE p.is_active = 1 AND (LOWER(p.name) LIKE LOWER(?) OR LOWER(p.description) LIKE LOWER(?) OR LOWER(ct.name) LIKE LOWER(?) OR LOWER(co.name) LIKE LOWER(?)) ORDER BY p.is_featured DESC, p.average_rating DESC LIMIT 100"; $rows = $db->fetchAll($fallback, [$s, $s, $s, $s]); if (!is_array($rows)) $rows = []; } return $rows; } catch (Throwable $e) { error_log('getProperties() failed: ' . $e->getMessage()); return []; } } ═══════════════════════════════════════════════════════ getQuickAvailability() ═══════════════════════════════════════════════════════ ═══ File: functions.php ═══ Line: 1956 ════════════════════════════════════════ function getQuickAvailability($propertyId) { try { $roomTypes = getRoomTypes($propertyId); if (empty($roomTypes)) { $prop = getPropertyById($propertyId); return ['available' => true, 'next_available' => date('Y-m-d'), 'lowest_price' => (float)($prop['min_price_per_night'] ?? 0)]; } $room = $roomTypes[0]; return ['available' => true, 'next_available' => date('Y-m-d'), 'lowest_price' => (float)($room['base_price'] ?? 0)]; } catch (Throwable $e) { return ['available' => true, 'next_available' => date('Y-m-d'), 'lowest_price' => 0]; } }