211 lines
9.1 KiB
PHP
211 lines
9.1 KiB
PHP
<?php
|
|
// search.php — Ricerca pubblica saloni (frontend portale)
|
|
// Sostituisce tour-list-left-sidebar: booking-bar, filter-sidebar e le card
|
|
// sono ora include riutilizzabili; i saloni arrivano dal database.
|
|
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL);
|
|
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
session_start();
|
|
}
|
|
|
|
// Connessione DB (stessa classe dell'area admin)
|
|
require_once(__DIR__ . '/userarea/class/db-functions.php');
|
|
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
|
|
|
// --- Parametri di ricerca (dalla query string) ---
|
|
$q_city = trim($_GET['city'] ?? '');
|
|
$q_service = trim($_GET['service'] ?? '');
|
|
$q_price_max = trim($_GET['price_max'] ?? '');
|
|
|
|
// --- Costruzione query saloni attivi + prezzo minimo servizi ---
|
|
$where = ["sh.active = 1"];
|
|
$params = [];
|
|
|
|
if ($q_city !== '') {
|
|
$where[] = "sh.city = ?";
|
|
$params[] = $q_city;
|
|
}
|
|
|
|
// Se filtro per servizio o prezzo, serve il join con services
|
|
$needServiceJoin = ($q_service !== '' || $q_price_max !== '');
|
|
|
|
if ($q_service !== '') {
|
|
$where[] = "EXISTS (SELECT 1 FROM services sv WHERE sv.shop_id = sh.id AND sv.is_active = 1 AND sv.name = ?)";
|
|
$params[] = $q_service;
|
|
}
|
|
if ($q_price_max !== '' && is_numeric($q_price_max)) {
|
|
$where[] = "EXISTS (SELECT 1 FROM services sv2 WHERE sv2.shop_id = sh.id AND sv2.is_active = 1 AND sv2.price <= ?)";
|
|
$params[] = (float)$q_price_max;
|
|
}
|
|
|
|
$whereSql = implode(' AND ', $where);
|
|
|
|
$sql = "
|
|
SELECT sh.id, sh.owner_id, sh.name, sh.slug, sh.description,
|
|
sh.address, sh.city, sh.province, sh.phone, sh.mobile,
|
|
sh.latitude, sh.longitude, sh.logo, sh.cover_image, sh.active,
|
|
(SELECT MIN(sv.price) FROM services sv WHERE sv.shop_id = sh.id AND sv.is_active = 1) AS min_price
|
|
FROM shops sh
|
|
WHERE $whereSql
|
|
ORDER BY sh.name ASC
|
|
";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute($params);
|
|
$salons = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
$totalSalons = count($salons);
|
|
|
|
// --- Dati per i filtri (città e servizi distinti) ---
|
|
$cities = $pdo->query("
|
|
SELECT DISTINCT city FROM shops
|
|
WHERE active = 1 AND city IS NOT NULL AND city <> ''
|
|
ORDER BY city ASC
|
|
")->fetchAll(PDO::FETCH_COLUMN);
|
|
|
|
$allServices = $pdo->query("
|
|
SELECT DISTINCT name FROM services
|
|
WHERE is_active = 1 AND name IS NOT NULL AND name <> ''
|
|
ORDER BY name ASC
|
|
")->fetchAll(PDO::FETCH_COLUMN);
|
|
|
|
// --- Preferiti dell'utente loggato (se c'è) per evidenziare i cuori ---
|
|
$favIds = [];
|
|
if (!empty($_SESSION['iduserlogin'])) {
|
|
$fstmt = $pdo->prepare("SELECT shop_id FROM user_favorite_shops WHERE user_id = ?");
|
|
$fstmt->execute([$_SESSION['iduserlogin']]);
|
|
$favIds = $fstmt->fetchAll(PDO::FETCH_COLUMN);
|
|
}
|
|
?>
|
|
<!doctype html>
|
|
<html class="no-js" lang="it">
|
|
|
|
<head>
|
|
<?php include('tophead.php'); ?>
|
|
|
|
<!-- CSS here -->
|
|
<?php include('cssinclude.php'); ?>
|
|
</head>
|
|
|
|
<body>
|
|
<!--[if lte IE 9]>
|
|
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="https://browsehappy.com/">upgrade your browser</a> to improve your experience and security.</p>
|
|
<![endif]-->
|
|
|
|
<!-- preloader -->
|
|
<?php include('preloader.php'); ?>
|
|
|
|
<!-- back to top start -->
|
|
<div class="back-to-top-wrapper">
|
|
<button id="back_to_top" type="button" class="back-to-top-btn">
|
|
<svg width="12" height="7" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
<path d="M11 6L6 1L1 6" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
<!-- back to top end -->
|
|
|
|
<!-- offcanvas / menu mobile -->
|
|
<?php include('offcanvas.php'); ?>
|
|
|
|
<header class="tp-header-height">
|
|
<!-- header-area-start -->
|
|
<?php include('topbar.php'); ?>
|
|
<!-- header-area-end -->
|
|
</header>
|
|
|
|
<main>
|
|
|
|
<!-- breadcrumb + barra di ricerca -->
|
|
<div class="tp-breadcrumb-area tp-breadcrumb-ptb tp-breadcrumb-overly bg-position" data-background="assets/img/breadcrumb/bg-3.jpg">
|
|
<div class="container">
|
|
<div class="row justify-content-center">
|
|
<div class="col-lg-12 col-md-8">
|
|
<div class="tp-breadcrumb-wrap text-center">
|
|
<h2 class="tp-breadcrumb-title text-center mb-25">Trova il tuo parrucchiere</h2>
|
|
<?php include('booking-bar.php'); ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- breadcrumb-area-end -->
|
|
|
|
<!-- tp-tour-area-start -->
|
|
<div class="tp-tour-area tp-tour-ptb tp-tour-list pt-140 pb-140">
|
|
<div class="container">
|
|
<div class="row">
|
|
|
|
<!-- Sidebar filtri -->
|
|
<div class="col-xxl-3 col-xl-4 col-lg-4 d-none d-xl-block">
|
|
<?php include('filter-sidebar.php'); ?>
|
|
</div>
|
|
|
|
<!-- Colonna risultati -->
|
|
<div class="col-xxl-9 col-xl-8 col-lg-12">
|
|
<div class="tp-tour-filter-wrap mb-20">
|
|
<div class="row align-items-center">
|
|
<div class="col-md-6">
|
|
<div class="tp-tour-filter mb-20">
|
|
<button class="tp-tour-filter-btn d-inline-block d-xl-none filter-open-btn tp-ff-inter d-inline-block mr-10">
|
|
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
<path d="M12.0002 8.66665H4.00016C3.60016 8.66665 3.3335 8.39998 3.3335 7.99998C3.3335 7.59998 3.60016 7.33331 4.00016 7.33331H12.0002C12.4002 7.33331 12.6668 7.59998 12.6668 7.99998C12.6668 8.39998 12.4002 8.66665 12.0002 8.66665Z" fill="currentColor" />
|
|
<path d="M10.0002 12.6666H6.00016C5.60016 12.6666 5.3335 12.4 5.3335 12C5.3335 11.6 5.60016 11.3333 6.00016 11.3333H10.0002C10.4002 11.3333 10.6668 11.6 10.6668 12C10.6668 12.4 10.4002 12.6666 10.0002 12.6666Z" fill="currentColor" />
|
|
<path d="M14.0002 4.66665H2.00016C1.60016 4.66665 1.3335 4.39998 1.3335 3.99998C1.3335 3.59998 1.60016 3.33331 2.00016 3.33331H14.0002C14.4002 3.33331 14.6668 3.59998 14.6668 3.99998C14.6668 4.39998 14.4002 4.66665 14.0002 4.66665Z" fill="currentColor" />
|
|
</svg>
|
|
Filtri
|
|
</button>
|
|
<span class="tp-tour-filter-result fw-500">
|
|
<?= $totalSalons ?> salon<?= $totalSalons === 1 ? 'e' : 'i' ?> trovat<?= $totalSalons === 1 ? 'o' : 'i' ?>
|
|
<?php if ($q_city !== ''): ?> a <?= htmlspecialchars($q_city) ?><?php endif; ?>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="tp-tour-sort mb-20 d-flex justify-content-md-end">
|
|
<select class="tp-select" onchange="if(this.value){window.location=this.value;}">
|
|
<option value="">Ordina per</option>
|
|
<option value="?<?= http_build_query(array_merge($_GET, ['sort' => 'az'])) ?>">Nome A → Z</option>
|
|
<option value="?<?= http_build_query(array_merge($_GET, ['sort' => 'price'])) ?>">Prezzo crescente</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<?php if (empty($salons)): ?>
|
|
<div class="text-center py-5">
|
|
<h4 class="mb-2">Nessun salone trovato</h4>
|
|
<p class="text-muted">Prova a cambiare città o servizio.</p>
|
|
<a href="search.php" class="tp-btn-sm">Azzera ricerca</a>
|
|
</div>
|
|
<?php else: ?>
|
|
<?php foreach ($salons as $salon): ?>
|
|
<?php include('card-salon.php'); ?>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- tp-tour-area-end -->
|
|
|
|
</main>
|
|
|
|
<footer>
|
|
<!-- tp-footer-area-start -->
|
|
<?php include('footer.php'); ?>
|
|
<!-- tp-footer-area-end -->
|
|
</footer>
|
|
|
|
<!-- JS here -->
|
|
<?php include('jsinclude.php'); ?>
|
|
</body>
|
|
|
|
</html>
|