Files
xamxam/app/templates/public/search.php
T
Pontoporeia f427352a71 tfe: redirect internal metadata links from /repertoire to /search
redirect internal metadata links from /repertoire to /search, add query param for search bar prefill, fix filter visibility on desktop

 redirect metadata links from /repertoire to /search, prefill search bar, fix filter visibility

 link metadata to /search, preserve keyword filter in form, show active keyword chip
2026-07-10 14:16:36 +02:00

113 lines
5.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php if ($validationError): ?>
<div class="search-error">⚠ <?= htmlspecialchars($validationError) ?></div>
<?php endif; ?>
<?php
// Count active filters (excluding 'query' and 'page')
$filterKeys = ['year', 'ap_program', 'orientation', 'finality', 'format', 'keyword'];
$activeFilterCount = 0;
foreach ($filterKeys as $k) {
if (!empty($_GET[$k])) $activeFilterCount++;
}
?>
<!-- Filter controls -->
<details class="search-filters-toggle" open>
<summary class="search-filters-summary">
Filtres
<?php if ($activeFilterCount > 0): ?>
<span class="search-filters-badge"><?= $activeFilterCount ?></span>
<?php endif; ?>
</summary>
<form class="search-controls" method="GET" action="/search">
<input type="hidden" name="query" value="<?= htmlspecialchars($_GET['query'] ?? '') ?>">
<?php if (!empty($_GET['keyword'])): ?>
<input type="hidden" name="keyword" value="<?= htmlspecialchars($_GET['keyword']) ?>">
<span class="search-active-keyword">Mot-clé&nbsp;: <strong><?= htmlspecialchars($_GET['keyword']) ?></strong>
<a href="/search?query=<?= urlencode($_GET['query'] ?? '') ?>" class="search-keyword-remove" aria-label="Retirer le filtre mot-clé">×</a>
</span>
<?php endif; ?>
<label class="search-filter-label" for="filter-year">Année
<select class="search-filter-select" name="year" id="filter-year">
<option value="">Toutes</option>
<?php foreach ($years as $y): ?>
<option value="<?= (int)$y ?>" <?= (isset($_GET['year']) && $_GET['year'] == $y) ? 'selected' : '' ?>>
<?= (int)$y ?>
</option>
<?php endforeach; ?>
</select>
</label>
<label class="search-filter-label" for="filter-ap">AP
<select class="search-filter-select" name="ap_program" id="filter-ap">
<option value="">Tous</option>
<?php foreach ($apPrograms as $ap): ?>
<option value="<?= htmlspecialchars($ap['name']) ?>"
<?= (isset($_GET['ap_program']) && $_GET['ap_program'] == $ap['name']) ? 'selected' : '' ?>>
<?= htmlspecialchars($ap['name']) ?>
</option>
<?php endforeach; ?>
</select>
</label>
<label class="search-filter-label" for="filter-orientation">Orientation
<select class="search-filter-select" name="orientation" id="filter-orientation">
<option value="">Toutes</option>
<?php foreach ($orientations as $o): ?>
<option value="<?= htmlspecialchars($o['name']) ?>"
<?= (isset($_GET['orientation']) && $_GET['orientation'] == $o['name']) ? 'selected' : '' ?>>
<?= htmlspecialchars($o['name']) ?>
</option>
<?php endforeach; ?>
</select>
</label>
<label class="search-filter-label" for="filter-finality">Finalité
<select class="search-filter-select" name="finality" id="filter-finality">
<option value="">Toutes</option>
<?php foreach ($finalityTypes as $f): ?>
<option value="<?= htmlspecialchars($f['name']) ?>"
<?= (isset($_GET['finality']) && $_GET['finality'] == $f['name']) ? 'selected' : '' ?>>
<?= htmlspecialchars($f['name']) ?>
</option>
<?php endforeach; ?>
</select>
</label>
<label class="search-filter-label" for="filter-format">Format
<select class="search-filter-select" name="format" id="filter-format">
<option value="">Tous</option>
<?php foreach ($formatTypes as $fmt): ?>
<option value="<?= htmlspecialchars($fmt['name']) ?>"
<?= (isset($_GET['format']) && $_GET['format'] == $fmt['name']) ? 'selected' : '' ?>>
<?= htmlspecialchars($fmt['name']) ?>
</option>
<?php endforeach; ?>
</select>
</label>
<button type="submit" class="btn btn--primary btn--sm search-apply-btn">Filtrer</button>
<a href="/search?query=<?= urlencode($_GET['query'] ?? '') ?>" class="btn btn--secondary btn--sm search-reset-link">Réinitialiser</a>
</form>
</details>
<main class="search-main" id="main-content">
<?php include APP_ROOT . '/templates/partials/search-results.php'; ?>
</main>
<script>
// Close filter <details> on mobile by default when no filters active
(function() {
if (window.innerWidth > 768) return;
var params = new URLSearchParams(window.location.search);
var hasActive = false;
params.forEach(function(v, k) {
if (k === 'page' || k === 'query') return;
if (v !== '') hasActive = true;
});
if (hasActive) return;
var toggle = document.querySelector('.search-filters-toggle');
if (toggle) toggle.removeAttribute('open');
})();
</script>