Add search, filters and pages to the central registry
CMS quality / php (8.2) (push) Canceled after 0s
CMS quality / php (8.4) (push) Canceled after 0s
CMS quality / browser (push) Canceled after 0s
CMS quality / mysql (push) Canceled after 0s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
kantarciandClaude Opus 5.5 committed 2026-10-14 11:04:46 +02:00
1 parent 821c799225
commit 7cdb431fd4
7 files changed
+158 -18

No files matched your search

+12
View File
@@ -34,6 +34,18 @@ final class Ansicht
return '<input type="hidden" name="_csrf" value="'.$this->e($this->csrf).'">';
}
/**
* Eine Adresse der Übersicht; leere Werte und Seite 1 fallen weg.
*
* @param array<string, mixed> $werte
*/
public function adresse(array $werte): string
{
$werte = array_filter($werte, static fn (mixed $wert): bool => null !== $wert && '' !== $wert && 1 !== $wert);
return '/'.([] === $werte ? '' : '?'.http_build_query($werte));
}
/** Ein Zeitpunkt in deutscher Ortszeit. */
public function zeit(?string $iso): string
{
+50 -8
View File
@@ -10,6 +10,9 @@ namespace Zentrale;
*/
final class Anwendung
{
/** Zeilen je Seite in der Übersicht. */
private const PRO_SEITE = 25;
private \PDO $db;
/** @param array<string, mixed> $config */
@@ -113,17 +116,56 @@ final class Anwendung
{
$neueste = $fassungen->neueste();
$alle = $bestand->alle($neueste['version'] ?? null);
// Die Zähler oben sind zugleich die Filter; sie zählen immer den ganzen Bestand.
$filter = [
'aktuell' => static fn (array $i): bool => null !== $neueste && !$i['veraltet'] && 'unbekannt' !== $i['fassung'],
'veraltet' => static fn (array $i): bool => $i['veraltet'],
'still' => static fn (array $i): bool => $i['still'],
'unbekannt' => static fn (array $i): bool => $i['unbekannt'],
];
$zahlen = ['alle' => count($alle)];
foreach ($filter as $name => $passt) {
$zahlen[$name] = count(array_filter($alle, $passt));
}
if (null === $neueste) {
$zahlen['aktuell'] = null;
}
$suche = mb_substr(trim((string) ($_GET['q'] ?? '')), 0, 100);
$gewaehlt = is_string($_GET['filter'] ?? null) && isset($filter[$_GET['filter']]) ? $_GET['filter'] : null;
$treffer = array_values(array_filter($alle, static function (array $i) use ($suche, $gewaehlt, $filter): bool {
if (null !== $gewaehlt && !$filter[$gewaehlt]($i)) {
return false;
}
if ('' === $suche) {
return true;
}
foreach (['domain', 'domain_vorher', 'adresse', 'notiz', 'fassung', 'ip'] as $feld) {
if (null !== $i[$feld] && false !== mb_stripos((string) $i[$feld], $suche)) {
return true;
}
}
return false;
}));
$proSeite = self::PRO_SEITE;
$seiten = max(1, (int) ceil(count($treffer) / $proSeite));
$seite = min($seiten, max(1, (int) ($_GET['seite'] ?? 1)));
$this->zeigen('uebersicht', [
'titel' => 'Installationen',
'neueste' => $neueste,
'installationen' => $alle,
'zahlen' => [
'alle' => count($alle),
'aktuell' => null === $neueste ? null : count(array_filter($alle, static fn (array $i): bool => !$i['veraltet'] && 'unbekannt' !== $i['fassung'])),
'veraltet' => count(array_filter($alle, static fn (array $i): bool => $i['veraltet'])),
'still' => count(array_filter($alle, static fn (array $i): bool => $i['still'])),
'unbekannt' => count(array_filter($alle, static fn (array $i): bool => $i['unbekannt'])),
],
'installationen' => array_slice($treffer, ($seite - 1) * $proSeite, $proSeite),
'treffer' => count($treffer),
'suche' => $suche,
'filter' => $gewaehlt,
'seite' => $seite,
'seiten' => $seiten,
'von' => [] === $treffer ? 0 : ($seite - 1) * $proSeite + 1,
'bis' => min(count($treffer), $seite * $proSeite),
'zahlen' => $zahlen,
// Verstummte bleiben außen vor: Sie holen den Auftrag womöglich nie ab. Wartende haben schon einen.
'aktualisierbar' => array_values(array_filter($alle, static fn (array $i): bool => $i['kann_update'] && !$i['still'] && 'wartet' !== ($i['auftrag_zustand']['art'] ?? null))),
]);
+2
View File
@@ -23,6 +23,8 @@ final class Bestand
public function alle(?string $neueste): array
{
$zeilen = $this->db->query('SELECT * FROM installation ORDER BY domain, erste_meldung')->fetchAll();
// Natürlich sortiert und ohne www: kunde-2 vor kunde-10, www.ebsolar.de bei e.
usort($zeilen, static fn (array $a, array $b): int => strnatcasecmp(preg_replace('/^www\./', '', (string) $a['domain']), preg_replace('/^www\./', '', (string) $b['domain'])));
$auftraege = [];
foreach ($this->db->query('SELECT a.* FROM auftrag a JOIN (SELECT installation, MAX(id) AS id FROM auftrag GROUP BY installation) j ON j.id = a.id')->fetchAll() as $auftrag) {
$auftraege[$auftrag['installation']] = $auftrag;
+59 -10
View File
@@ -8,35 +8,65 @@
</form>
</div>
<ul class="zahlen" aria-label="Zusammenfassung">
<li><strong><?= $zahlen['alle'] ?></strong> gesamt</li>
<li class="z-ok"><strong><?= $zahlen['aktuell'] ?? '–' ?></strong> aktuell</li>
<li class="z-warn"><strong><?= $zahlen['veraltet'] ?></strong> veraltet</li>
<li class="z-still"><strong><?= $zahlen['still'] ?></strong> ohne Meldung seit 48 h</li>
<li class="z-fremd"><strong><?= $zahlen['unbekannt'] ?></strong> ohne Kundenzuordnung</li>
</ul>
<?php
$kacheln = [
null => ['', 'gesamt', $zahlen['alle']],
'aktuell' => ['z-ok', 'aktuell', $zahlen['aktuell'] ?? '–'],
'veraltet' => ['z-warn', 'veraltet', $zahlen['veraltet']],
'still' => ['z-still', 'ohne Meldung seit 48 h', $zahlen['still']],
'unbekannt' => ['z-fremd', 'ohne Kundenzuordnung', $zahlen['unbekannt']],
];
?>
<nav aria-label="Nach Zustand filtern">
<ul class="zahlen">
<?php foreach ($kacheln as $name => [$klasse, $text, $zahl]) { $aktiv = ($filter ?? '') === $name; ?>
<li class="<?= $klasse ?><?= $aktiv ? ' gewaehlt' : '' ?>"><a href="<?= $v->e($v->adresse(['q' => $suche, 'filter' => '' === $name ? null : $name])) ?>"<?= $aktiv ? ' aria-current="true"' : '' ?>><strong><?= $v->e($zahl) ?></strong> <?= $v->e($text) ?></a></li>
<?php } ?>
</ul>
</nav>
<?php if ([] !== $aktualisierbar && null !== $neueste) { ?>
<form method="post" action="/auftrag/alle" class="karte alle">
<?= $v->csrf() ?>
<div>
<h2>Alle auf <?= $v->e($neueste['version']) ?> aktualisieren</h2>
<p><?= count($aktualisierbar) ?> Installation(en): <?= $v->e(implode(', ', array_column($aktualisierbar, 'domain'))) ?>. Jede holt den Auftrag mit ihrer nächsten Meldung ab, sichert sich vorher und schaltet bei einem Fehler zurück.</p>
<?php $namen = array_column($aktualisierbar, 'domain'); ?>
<p><?= count($aktualisierbar) ?> Installation(en): <?= $v->e(implode(', ', array_slice($namen, 0, 8))) ?><?= count($namen) > 8 ? ' und '.(count($namen) - 8).' weitere' : '' ?>. Jede holt den Auftrag mit ihrer nächsten Meldung ab, sichert sich vorher und schaltet bei einem Fehler zurück.</p>
<label class="bestaetigen"><input type="checkbox" name="bestaetigt" value="ja" required> Ja, alle <?= count($aktualisierbar) ?> aktualisieren</label>
</div>
<button type="submit" class="knopf">Alle aktualisieren</button>
</form>
<?php } ?>
<?php if ([] === $installationen) { ?>
<?php if ($zahlen['alle'] > 0) { ?>
<form method="get" action="/" class="suche" role="search">
<?php if (null !== $filter) { ?><input type="hidden" name="filter" value="<?= $v->e($filter) ?>"><?php } ?>
<label for="q">Suchen</label>
<div class="suche-zeile">
<input id="q" name="q" type="search" value="<?= $v->e($suche) ?>" placeholder="Domain, Kunde, Fassung oder IP" aria-describedby="treffer">
<button type="submit" class="knopf">Suchen</button>
<?php if ('' !== $suche || null !== $filter) { ?><a class="knopf knopf-leise" href="/">Zurücksetzen</a><?php } ?>
</div>
<p class="klein" id="treffer" role="status">
<?php if (0 === $treffer) { ?>Keine Treffer.<?php } else { ?><?= $von ?>–<?= $bis ?> von <?= $treffer ?> <?= 1 === $treffer ? 'Installation' : 'Installationen' ?><?= null !== $filter ? ' · Filter: '.$v->e($kacheln[$filter][1]) : '' ?><?= '' !== $suche ? ' · Suche: „'.$v->e($suche).'“' : '' ?><?php } ?>
</p>
</form>
<?php } ?>
<?php if (0 === $zahlen['alle']) { ?>
<div class="karte leer">
<h2>Noch keine Meldung</h2>
<p>Sobald eine KantSites-Installation ab Fassung 1.36.0 läuft, meldet sie sich hier – spätestens 15 Minuten nach dem ersten Besuch oder Cron-Aufruf.</p>
</div>
<?php } elseif (0 === $treffer) { ?>
<div class="karte leer">
<h2>Nichts gefunden</h2>
<p>Keine Installation passt zu Suche und Filter. <a href="/">Alle anzeigen</a></p>
</div>
<?php } else { ?>
<div class="tabelle-rahmen">
<table class="tabelle">
<caption class="unsichtbar">Alle gemeldeten Installationen</caption>
<caption class="unsichtbar">Gemeldete Installationen, Seite <?= $seite ?> von <?= $seiten ?></caption>
<thead>
<tr><th scope="col">Domain</th><th scope="col">Kunde</th><th scope="col">Fassung</th><th scope="col">Letzte Meldung</th><th scope="col">Zustand</th><th scope="col"><span class="unsichtbar">Aktion</span></th></tr>
</thead>
@@ -66,4 +96,23 @@
</tbody>
</table>
</div>
<?php if ($seiten > 1) { ?>
<nav class="seiten" aria-label="Seiten">
<?php $basis = ['q' => $suche, 'filter' => $filter]; ?>
<?php if ($seite > 1) { ?><a class="knopf knopf-leise" href="<?= $v->e($v->adresse([...$basis, 'seite' => $seite - 1])) ?>" rel="prev">← Zurück</a><?php } ?>
<ul>
<?php
// Erste, letzte und zwei um die aktuelle; dazwischen Auslassungen.
$zeigen = array_unique(array_filter([1, $seite - 2, $seite - 1, $seite, $seite + 1, $seite + 2, $seiten], static fn (int $n): bool => $n >= 1 && $n <= $seiten));
sort($zeigen);
$vorher = 0;
foreach ($zeigen as $n) {
if ($n > $vorher + 1) { ?><li aria-hidden="true">…</li><?php }
$vorher = $n; ?>
<li><?php if ($n === $seite) { ?><span aria-current="page"><span class="unsichtbar">Seite </span><?= $n ?></span><?php } else { ?><a href="<?= $v->e($v->adresse([...$basis, 'seite' => $n])) ?>"><span class="unsichtbar">Seite </span><?= $n ?></a><?php } ?></li>
<?php } ?>
</ul>
<?php if ($seite < $seiten) { ?><a class="knopf knopf-leise" href="<?= $v->e($v->adresse([...$basis, 'seite' => $seite + 1])) ?>" rel="next">Weiter →</a><?php } ?>
</nav>
<?php } ?>
<?php } ?>