Erst anmelden: Login

"; include __DIR__ . "/templates/footer.inc.php"; exit; } if (!check_worker()) { echo "
Dieser Bereich ist nur fuer Bearbeiter freigeschaltet.
"; include __DIR__ . "/templates/footer.inc.php"; exit; } function esc($v): string { return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8'); } function weekdayName(int $d): string { $map = [1 => 'Montag', 2 => 'Dienstag', 3 => 'Mittwoch', 4 => 'Donnerstag', 5 => 'Freitag', 6 => 'Samstag', 7 => 'Sonntag']; return $map[$d] ?? 'Unbekannt'; } function ensureWorkflowTables(PDO $pdo): void { impfWorkflowEnsureTables($pdo); } function tableHasColumn(PDO $pdo, string $table, string $column): bool { static $cache = []; $cacheKey = $table . '.' . $column; if (array_key_exists($cacheKey, $cache)) { return $cache[$cacheKey]; } $st = $pdo->prepare("SHOW COLUMNS FROM `" . $table . "` LIKE :column"); $st->execute(['column' => $column]); $cache[$cacheKey] = (bool)$st->fetch(PDO::FETCH_ASSOC); return $cache[$cacheKey]; } function getImpfstoffe(PDO $pdo, bool $onlyActive = true): array { $sql = "SELECT impfid, impfname, sortierung, aktiv, aktivwarteliste, aktivtermin, aktivgrippe FROM impfstoff"; if ($onlyActive) { $sql .= " WHERE aktiv = 1 OR aktivwarteliste = 1 OR aktivtermin = 1 OR aktivgrippe = 1"; } $sql .= " ORDER BY sortierung, impfname"; $st = $pdo->prepare($sql); $st->execute(); return $st->fetchAll(PDO::FETCH_ASSOC); } function getImpforte(PDO $pdo, bool $onlyActive = true): array { $sql = "SELECT ortid, anzeigename, adresse, aktiv"; if (tableHasColumn($pdo, 'impfort', 'art')) { $sql .= ", art"; } $sql .= " FROM impfort"; if ($onlyActive) { $sql .= " WHERE aktiv = 1"; } $sql .= " ORDER BY anzeigename, adresse"; $st = $pdo->prepare($sql); $st->execute(); return $st->fetchAll(PDO::FETCH_ASSOC); } function setImpfstoffAktiv(PDO $pdo, int $impfstoffId, int $aktiv): void { if ($aktiv === 1) { $st = $pdo->prepare("UPDATE impfstoff SET aktiv = 1, aktivwarteliste = 1, aktivtermin = 1 WHERE impfid = :iid"); $st->execute(['iid' => $impfstoffId]); return; } $st = $pdo->prepare("UPDATE impfstoff SET aktiv = 0, aktivwarteliste = 0, aktivtermin = 0, aktivgrippe = 0 WHERE impfid = :iid"); $st->execute(['iid' => $impfstoffId]); } function setImpfortAktiv(PDO $pdo, int $impfortId, int $aktiv): void { $st = $pdo->prepare("UPDATE impfort SET aktiv = :aktiv WHERE ortid = :oid"); $st->execute([ 'aktiv' => $aktiv, 'oid' => $impfortId, ]); } $message = ""; $error = ""; try { ensureWorkflowTables($pdo); } catch (Throwable $e) { $error = "Workflow-Tabellen konnten nicht erstellt werden: " . $e->getMessage(); } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $aktion = (string)($_POST['aktion'] ?? ''); if ($aktion === 'add_impfstoff') { $impfname = trim((string)($_POST['impfname'] ?? '')); $sortierung = (int)($_POST['sortierung'] ?? 100); if ($impfname === '') { $error = "Bitte einen Impfstoffnamen eingeben."; } else { try { $stExisting = $pdo->prepare("SELECT impfid FROM impfstoff WHERE LOWER(TRIM(impfname)) = LOWER(TRIM(:name)) LIMIT 1"); $stExisting->execute(['name' => $impfname]); $existingId = (int)($stExisting->fetchColumn() ?: 0); if ($existingId > 0) { $stUpdate = $pdo->prepare("UPDATE impfstoff SET impfname = :name, sortierung = :sortierung WHERE impfid = :iid"); $stUpdate->execute([ 'name' => $impfname, 'sortierung' => $sortierung, 'iid' => $existingId, ]); setImpfstoffAktiv($pdo, $existingId, 1); $message = "Impfstoff wurde reaktiviert und aktualisiert."; } else { $stInsert = $pdo->prepare("INSERT INTO impfstoff (impfname, sortierung, aktiv, aktivwarteliste, aktivtermin, aktivgrippe) VALUES (:name, :sortierung, 1, 1, 1, 0)"); $stInsert->execute([ 'name' => $impfname, 'sortierung' => $sortierung, ]); $message = "Impfstoff wurde hinzugefuegt."; } } catch (Throwable $e) { $error = "Impfstoff konnte nicht gespeichert werden: " . $e->getMessage(); } } } if ($aktion === 'toggle_impfstoff') { $impfstoffId = (int)($_POST['impfstoff_id'] ?? 0); $aktiv = ((int)($_POST['aktiv'] ?? 0) === 1) ? 1 : 0; if ($impfstoffId <= 0) { $error = "Bitte einen gueltigen Impfstoff auswaehlen."; } else { setImpfstoffAktiv($pdo, $impfstoffId, $aktiv); $message = ($aktiv === 1) ? "Impfstoff wurde aktiviert." : "Impfstoff wurde deaktiviert."; } } if ($aktion === 'add_impfort') { $anzeigename = trim((string)($_POST['anzeigename'] ?? '')); $adresse = trim((string)($_POST['adresse'] ?? '')); $art = trim((string)($_POST['art'] ?? '')); if ($anzeigename === '' || $adresse === '') { $error = "Bitte Standortname und Adresse eingeben."; } else { try { $stExisting = $pdo->prepare("SELECT ortid FROM impfort WHERE LOWER(TRIM(anzeigename)) = LOWER(TRIM(:name)) AND LOWER(TRIM(adresse)) = LOWER(TRIM(:adresse)) LIMIT 1"); $stExisting->execute([ 'name' => $anzeigename, 'adresse' => $adresse, ]); $existingId = (int)($stExisting->fetchColumn() ?: 0); if ($existingId > 0) { if (tableHasColumn($pdo, 'impfort', 'art')) { $stUpdate = $pdo->prepare("UPDATE impfort SET anzeigename = :name, adresse = :adresse, art = :art WHERE ortid = :oid"); $stUpdate->execute([ 'name' => $anzeigename, 'adresse' => $adresse, 'art' => $art, 'oid' => $existingId, ]); } else { $stUpdate = $pdo->prepare("UPDATE impfort SET anzeigename = :name, adresse = :adresse WHERE ortid = :oid"); $stUpdate->execute([ 'name' => $anzeigename, 'adresse' => $adresse, 'oid' => $existingId, ]); } setImpfortAktiv($pdo, $existingId, 1); $message = "Standort wurde reaktiviert und aktualisiert."; } else { if (tableHasColumn($pdo, 'impfort', 'art')) { $stInsert = $pdo->prepare("INSERT INTO impfort (anzeigename, adresse, art, aktiv) VALUES (:name, :adresse, :art, 1)"); $stInsert->execute([ 'name' => $anzeigename, 'adresse' => $adresse, 'art' => $art, ]); } else { $stInsert = $pdo->prepare("INSERT INTO impfort (anzeigename, adresse, aktiv) VALUES (:name, :adresse, 1)"); $stInsert->execute([ 'name' => $anzeigename, 'adresse' => $adresse, ]); } $message = "Standort wurde hinzugefuegt."; } } catch (Throwable $e) { $error = "Standort konnte nicht gespeichert werden: " . $e->getMessage(); } } } if ($aktion === 'toggle_impfort') { $impfortId = (int)($_POST['impfort_id'] ?? 0); $aktiv = ((int)($_POST['aktiv'] ?? 0) === 1) ? 1 : 0; if ($impfortId <= 0) { $error = "Bitte einen gueltigen Standort auswaehlen."; } else { setImpfortAktiv($pdo, $impfortId, $aktiv); $message = ($aktiv === 1) ? "Standort wurde aktiviert." : "Standort wurde deaktiviert."; } } if ($aktion === 'save_rule') { $impfstoffId = (int)($_POST['impfstoff_id'] ?? 0); $dosen = max(1, (int)($_POST['dosen_pro_flasche'] ?? 0)); if ($impfstoffId <= 0) { $error = "Bitte einen Impfstoff auswaehlen."; } else { $st = $pdo->prepare("INSERT INTO impfstoff_workflow (impfstoff_id, dosen_pro_flasche) VALUES (:iid, :dosen) ON DUPLICATE KEY UPDATE dosen_pro_flasche = VALUES(dosen_pro_flasche)"); $st->execute(['iid' => $impfstoffId, 'dosen' => $dosen]); $message = "Stammdaten gespeichert."; } } if ($aktion === 'delete_rule') { $impfstoffId = (int)($_POST['impfstoff_id'] ?? 0); if ($impfstoffId <= 0) { $error = "Bitte einen gueltigen Impfstoff auswaehlen."; } else { $st = $pdo->prepare("DELETE FROM impfstoff_workflow WHERE impfstoff_id = :iid"); $st->execute(['iid' => $impfstoffId]); $message = "Stammdaten fuer den Impfstoff wurden entfernt."; } } if ($aktion === 'add_zeitraum') { $bezeichnung = trim((string)($_POST['bezeichnung'] ?? '')); if (function_exists('mb_substr')) { $bezeichnung = mb_substr($bezeichnung, 0, 50, 'UTF-8'); } else { $bezeichnung = substr($bezeichnung, 0, 50); } $wochentag = (int)($_POST['wochentag'] ?? 0); $start = trim((string)($_POST['start'] ?? '')); $ende = trim((string)($_POST['ende'] ?? '')); $impfortId = (int)($_POST['impfortid'] ?? 0); if ($wochentag < 1 || $wochentag > 7 || $start === '' || $ende === '' || $impfortId <= 0) { $error = "Bitte Zeitraum vollstaendig ausfuellen."; } elseif ($ende <= $start) { $error = "Die Endzeit muss nach der Startzeit liegen."; } else { $startSql = $start . ':00'; $endeSql = $ende . ':00'; $stExisting = $pdo->prepare("SELECT zeitraum_id, bezeichnung FROM impf_zeitraum WHERE wochentag = :wochentag AND start = :start AND ende = :ende AND impfortid = :impfortid LIMIT 1"); $stExisting->execute([ 'wochentag' => $wochentag, 'start' => $startSql, 'ende' => $endeSql, 'impfortid' => $impfortId, ]); $existingRow = $stExisting->fetch(PDO::FETCH_ASSOC) ?: null; $existingId = (int)($existingRow['zeitraum_id'] ?? 0); if ($existingId > 0) { $stUpdate = $pdo->prepare("UPDATE impf_zeitraum SET bezeichnung = :bezeichnung, aktiv = 1 WHERE zeitraum_id = :zid"); $stUpdate->execute([ 'bezeichnung' => $bezeichnung, 'zid' => $existingId, ]); $message = "Zeitraum wurde reaktiviert."; } else { $st = $pdo->prepare("INSERT INTO impf_zeitraum (bezeichnung, wochentag, start, ende, impfortid, aktiv) VALUES (:bezeichnung, :wd, :start, :ende, :oid, 1)"); $st->execute([ 'bezeichnung' => $bezeichnung, 'wd' => $wochentag, 'start' => $startSql, 'ende' => $endeSql, 'oid' => $impfortId, ]); $message = "Zeitraum gespeichert."; } } } if ($aktion === 'save_zeitraum_assignments') { $zeitraumId = (int)($_POST['zeitraum_id'] ?? 0); $impfstoffIds = array_values(array_unique(array_map('intval', $_POST['impfstoff_ids'] ?? []))); if ($zeitraumId <= 0) { $error = "Bitte einen gueltigen Zeitraum auswaehlen."; } else { try { $pdo->beginTransaction(); $stDelete = $pdo->prepare("DELETE FROM impf_zeitraum_impfstoff WHERE zeitraum_id = :zid"); $stDelete->execute(['zid' => $zeitraumId]); if (!empty($impfstoffIds)) { $stInsert = $pdo->prepare("INSERT INTO impf_zeitraum_impfstoff (zeitraum_id, impfstoff_id) VALUES (:zid, :iid)"); foreach ($impfstoffIds as $impfstoffId) { if ($impfstoffId <= 0) { continue; } $stInsert->execute([ 'zid' => $zeitraumId, 'iid' => $impfstoffId, ]); } } $pdo->commit(); $message = "Zuordnung fuer den Zeitraum gespeichert."; } catch (Throwable $e) { if ($pdo->inTransaction()) { $pdo->rollBack(); } $error = "Zuordnung konnte nicht gespeichert werden: " . $e->getMessage(); } } } if ($aktion === 'delete_zeitraum') { $zeitraumId = (int)($_POST['zeitraum_id'] ?? 0); if ($zeitraumId > 0) { $pdo->beginTransaction(); try { $stDeleteMap = $pdo->prepare("DELETE FROM impf_zeitraum_impfstoff WHERE zeitraum_id = :zid"); $stDeleteMap->execute(['zid' => $zeitraumId]); $stDelete = $pdo->prepare("DELETE FROM impf_zeitraum WHERE zeitraum_id = :zid"); $stDelete->execute(['zid' => $zeitraumId]); $pdo->commit(); $message = "Zeitraum geloescht."; } catch (Throwable $e) { if ($pdo->inTransaction()) { $pdo->rollBack(); } $error = "Zeitraum konnte nicht geloescht werden: " . $e->getMessage(); } } } } $impfstoffe = getImpfstoffe($pdo, true); $allImpfstoffe = getImpfstoffe($pdo, false); $impforte = getImpforte($pdo, true); $allImpforte = getImpforte($pdo, false); $zeitraeume = impfGetZeitraumRows($pdo, true); $stRules = $pdo->prepare("SELECT r.impfstoff_id, r.dosen_pro_flasche, i.impfname, COALESCE((SELECT COUNT(DISTINCT w.userid) FROM warteliste w WHERE w.checked = 1 AND (w.impfstoff = r.impfstoff_id OR w.impfstoff = 0)),0) AS wartende FROM impfstoff_workflow r INNER JOIN impfstoff i ON i.impfid = r.impfstoff_id WHERE (i.aktiv = 1 OR i.aktivwarteliste = 1 OR i.aktivtermin = 1 OR i.aktivgrippe = 1) ORDER BY i.impfname"); $stRules->execute(); $rules = $stRules->fetchAll(PDO::FETCH_ASSOC); ?>

Impfverwaltung - Stammdaten

Impfstoffe pflegen (hinzufuegen und entfernen)
Impfstoff Sortierung Nutzung Status Aktion
Standorte pflegen (hinzufuegen und entfernen)
Standort Adresse Typ Status Aktion
Stammdaten pro Impfstoff
= $dosen) ? 'bereit' : ('fehlen: ' . ($dosen - $wartende)); ?>
ImpfstoffDosen pro FlascheBestaetigte WartelisteStatusAktion
Zeitraeume pflegen
BezeichnungWochentagZeitImpfortZugeordnete ImpfstoffeAktion
Impfstoffe den Zeitraeumen zuordnen

Bitte zuerst mindestens einen Zeitraum anlegen.