Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
<?php
require_once 'config.php';
include_once 'class/class.php';
$zoekterm = isset($_GET['zoekterm']) ? htmlspecialchars($_GET['zoekterm']) : '';
$selectedLocations = isset($_GET['location']) ? (array)$_GET['location'] : [];
$selectedEigenschappen = isset($_GET['eigenschap']) ? (array)$_GET['eigenschap'] : [];
$minPrice = isset($_GET['min_price']) ? $_GET['min_price'] : '';
$maxPrice = isset($_GET['max_price']) ? $_GET['max_price'] : '';
// Haal alle liggingen en eigenschappen op
$sql = "SELECT id, name FROM locations";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$locations = $stmt->fetchAll();
$sql = "SELECT id, name FROM eigenschappen";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$eigenschappen = $stmt->fetchAll();
// SQL Query voor gefilterde villa's
$sql = "SELECT DISTINCT v.id, v.name AS villa_name, v.price, v.persons, v.description AS villa_description,
GROUP_CONCAT(DISTINCT l.name) AS location_names,
GROUP_CONCAT(DISTINCT e.name) AS feature_names
FROM villas v
LEFT JOIN villa_has_locations vl ON v.id = vl.villa_id
LEFT JOIN locations l ON vl.location_id = l.id
LEFT JOIN villa_has_eigenschappen ve ON v.id = ve.villa_id
LEFT JOIN eigenschappen e ON ve.eigenschappen_id = e.id
WHERE 1";
$params = [];
if (!empty($selectedLocations)) {
$locationPlaceholders = implode(',', array_fill(0, count($selectedLocations), '?'));
$sql .= " AND vl.location_id IN ($locationPlaceholders)";
$params = array_merge($params, $selectedLocations);
}
if (!empty($selectedEigenschappen)) {
$eigenschaftPlaceholders = implode(',', array_fill(0, count($selectedEigenschappen), '?'));
$sql .= " AND ve.eigenschappen_id IN ($eigenschaftPlaceholders)";
$params = array_merge($params, $selectedEigenschappen);
}
if ($minPrice) {
$sql .= " AND v.price >= ?";
$params[] = $minPrice;
}
if ($maxPrice) {
$sql .= " AND v.price <= ?";
$params[] = $maxPrice;
}
if ($zoekterm) {
$sql .= " AND (v.name LIKE ? OR l.name LIKE ?)";
$params[] = "%$zoekterm%";
$params[] = "%$zoekterm%";
}
$sql .= " GROUP BY v.id";
try {
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$villas = $stmt->fetchAll();
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Villa Verkenner - Aanbod</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<div class="container">
<nav>
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="Aboutus.html">Over Ons</a></li>
<li><a href="aanbod.php">Aanbod</a></li>
<li class="login-signup">
<a href="admin_login.php">Inloggen</a>
<a href="register.php">Aanmelden</a>
</li>
</ul>
</nav>
</div>
</header>
<section class="featured-properties">
<div class="container">
<div class="title-aanbod">
<h2>Uitgelichte Huizen</h2>
</div>
<section class="filter-options">
<div class="container-filter">
<form method="GET" action="aanbod.php" class="filter-form">
<div class="filter-item">
<label for="location">Filter op ligging (houd CTRL ingedrukt voor meerdere):</label>
<select name="location[]" id="location" multiple>
<?php
foreach ($locations as $location) {
$selected = in_array($location['id'], $selectedLocations) ? 'selected' : '';
echo '<option value="' . $location['id'] . '" ' . $selected . '>' . $location['name'] . '</option>';
}
?>
</select>
</div>
<div class="filter-item">
<label for="eigenschap">Filter op eigenschap (houd CTRL ingedrukt voor meerdere):</label>
<select name="eigenschap[]" id="eigenschap" multiple>
<?php
foreach ($eigenschappen as $eigenschap) {
$selected = in_array($eigenschap['id'], $selectedEigenschappen) ? 'selected' : '';
echo '<option value="' . $eigenschap['id'] . '" ' . $selected . '>' . $eigenschap['name'] . '</option>';
}
?>
</select>
</div>
<div class="filter-item">
<label for="min_price">Zoek op prijs:</label>
<input type="number" name="min_price" id="min_price" placeholder="Minimale prijs"
value="<?= htmlspecialchars($minPrice) ?>">
<input type="number" name="max_price" id="max_price" placeholder="Maximale prijs"
value="<?= htmlspecialchars($maxPrice) ?>">
</div>
<div class="filter-item">
<label for="zoekterm">Zoek op plaatsnaam:</label>
<input type="text" name="zoekterm" id="zoekterm" placeholder="Plaatsnaam"
value="<?= htmlspecialchars($zoekterm) ?>">
</div>
<button class="filter-button" type="submit">Filter</button>
</form>
<form method="GET" action="aanbod.php" class="filter-form">
<button class="clear-button" type="submit">Clear Filters</button>
</form>
</div>
</section>
<div class="huis-list">
<?php functions::showFilteredVillas($villas); ?>
</div>
</div>
</section>
</body>
<script src="script.js"></script>
</html>