120 lines
4.8 KiB
PHP
120 lines
4.8 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
$query = $_GET['q'] ?? '';
|
|
$location = $_GET['location'] ?? '';
|
|
$results = [];
|
|
|
|
if (!empty($query) || !empty($location)) {
|
|
try {
|
|
$pdo = db();
|
|
|
|
$sql = "
|
|
SELECT
|
|
s.id,
|
|
s.name,
|
|
s.description,
|
|
s.price,
|
|
c.name as category_name,
|
|
u.first_name,
|
|
u.last_name,
|
|
u.location
|
|
FROM services s
|
|
JOIN users u ON s.provider_id = u.id
|
|
JOIN service_categories c ON s.category_id = c.id
|
|
WHERE u.user_type = 'provider'
|
|
";
|
|
|
|
$params = [];
|
|
|
|
if (!empty($query)) {
|
|
$sql .= " AND (s.name LIKE :query OR s.description LIKE :query)";
|
|
$params[':query'] = '%' . $query . '%';
|
|
}
|
|
|
|
if (!empty($location)) {
|
|
$sql .= " AND u.location LIKE :location";
|
|
$params[':location'] = '%' . $location . '%';
|
|
}
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute($params);
|
|
$results = $stmt->fetchAll();
|
|
|
|
} catch (PDOException $e) {
|
|
// In a real app, you would log this error.
|
|
$error_message = "Si è verificato un errore durante la ricerca. Riprova più tardi.";
|
|
}
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="it">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Risultati della Ricerca - MeToo</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
|
|
<?php include __DIR__ . '/_header.php'; ?>
|
|
|
|
<main class="container my-5">
|
|
<h1 class="mb-4">Risultati della ricerca</h1>
|
|
|
|
<div class="row mb-4">
|
|
<div class="col">
|
|
<form action="search.php" method="GET" class="row g-3">
|
|
<div class="col-md-6">
|
|
<input type="text" class="form-control" name="q" placeholder="Che servizio cerchi?" value="<?= htmlspecialchars($query) ?>">
|
|
</div>
|
|
<div class="col-md-4">
|
|
<input type="text" class="form-control" name="location" placeholder="Comune" value="<?= htmlspecialchars($location) ?>">
|
|
</div>
|
|
<div class="col-md-2">
|
|
<button type="submit" class="btn btn-primary w-100">Cerca</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if (isset($error_message)): ?>
|
|
<div class="alert alert-danger"><?= $error_message ?></div>
|
|
<?php elseif (empty($results)): ?>
|
|
<div class="alert alert-info">
|
|
Nessun servizio trovato per "<?= htmlspecialchars($query) ?>" <?= !empty($location) ? 'a ' . htmlspecialchars($location) : '' ?>. Prova a modificare i criteri di ricerca.
|
|
</div>
|
|
<?php else: ?>
|
|
<p class="text-muted">Trovati <?= count($results) ?> risultati.</p>
|
|
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-4">
|
|
<?php foreach ($results as $service): ?>
|
|
<div class="col">
|
|
<div class="card h-100">
|
|
<div class="card-body">
|
|
<h5 class="card-title"><?= htmlspecialchars($service['name']) ?></h5>
|
|
<h6 class="card-subtitle mb-2 text-muted"><?= htmlspecialchars($service['category_name']) ?></h6>
|
|
<p class="card-text"><?= htmlspecialchars(substr($service['description'], 0, 100)) ?>...</p>
|
|
<p class="card-text">
|
|
<strong>Prezzo:</strong> € <?= htmlspecialchars(number_format($service['price'], 2, ',', '.')) ?><br>
|
|
<strong>Fornitore:</strong> <?= htmlspecialchars($service['first_name'] . ' ' . $service['last_name']) ?><br>
|
|
<strong>Comune:</strong> <?= htmlspecialchars($service['location']) ?>
|
|
</p>
|
|
<a href="service.php?id=<?= $service['id'] ?>" class="btn btn-primary">Vedi Dettagli</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
</main>
|
|
|
|
<?php include __DIR__ . '/_footer.php'; ?>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
|
</body>
|
|
</html>
|