328 lines
18 KiB
PHP
328 lines
18 KiB
PHP
<?php
|
||
require_once $_SERVER['DOCUMENT_ROOT'] . '/intranet_repo/general_files/initialise.php';
|
||
require_once __DIR__ . '/util/contentpanel_helpers.php';
|
||
|
||
$generalPermission = $groups['Allgemein'] ?? null;
|
||
if (!in_array($generalPermission, [1, '1', true, 't', 'true'], true)) {
|
||
header('Location: /intranet_repo/projects/intranet/index.php', true, 303);
|
||
exit();
|
||
}
|
||
|
||
contentpanel_cleanup_expired_news();
|
||
$csrfToken = contentpanel_csrf_token();
|
||
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||
$action = trim((string) ($_POST['action'] ?? ''));
|
||
$tab = contentpanel_action_tab($action);
|
||
$flashType = 'success';
|
||
|
||
try {
|
||
contentpanel_verify_csrf($_POST['csrf_token'] ?? null);
|
||
|
||
$message = match ($action) {
|
||
'import_leitgedanken' => contentpanel_import_leitgedanken($pdo, $_FILES['leitgedanken_pdf'] ?? []),
|
||
'create_service' => contentpanel_create_service($pdo, $_POST),
|
||
'delete_service' => contentpanel_delete_service($pdo, $_POST['id'] ?? null),
|
||
'create_announcement' => contentpanel_create_announcement($pdo, $_POST),
|
||
'delete_announcement' => contentpanel_delete_announcement($pdo, $_POST['id'] ?? null),
|
||
'upload_news' => contentpanel_upload_news($_POST, $_FILES['fileToUpload'] ?? []),
|
||
'delete_news' => contentpanel_delete_news_files((string) ($_POST['file_base'] ?? ''))
|
||
? 'Aushang wurde vollständig gelöscht.'
|
||
: throw new InvalidArgumentException('Ungültiger Dateiname oder Aushang konnte nicht vollständig gelöscht werden.'),
|
||
default => throw new InvalidArgumentException('Unbekannte Aktion.'),
|
||
};
|
||
} catch (InvalidArgumentException $exception) {
|
||
$message = $exception->getMessage();
|
||
$flashType = 'error';
|
||
} catch (Throwable $exception) {
|
||
error_log('Contentpanel action failed (' . $action . '): ' . $exception->getMessage());
|
||
$message = 'Die Aktion konnte nicht abgeschlossen werden. Bitte versuchen Sie es erneut.';
|
||
$flashType = 'error';
|
||
}
|
||
|
||
$_SESSION['contentpanel_flash'] = [
|
||
'tab' => $tab,
|
||
'message' => $message,
|
||
'type' => $flashType,
|
||
];
|
||
|
||
header('Location: insert.php#' . rawurlencode($tab), true, 303);
|
||
exit();
|
||
}
|
||
|
||
$flash = $_SESSION['contentpanel_flash'] ?? null;
|
||
unset($_SESSION['contentpanel_flash']);
|
||
|
||
$today = date('Y-m-d');
|
||
$services = contentpanel_fetch_services($pdo, $today);
|
||
$announcements = contentpanel_fetch_announcements($pdo, $today);
|
||
$newsItems = contentpanel_list_news();
|
||
$pdo = null;
|
||
|
||
$flashTab = is_array($flash) ? (string) ($flash['tab'] ?? '') : '';
|
||
$flashMessage = is_array($flash) ? (string) ($flash['message'] ?? '') : '';
|
||
$flashType = is_array($flash) ? (string) ($flash['type'] ?? '') : '';
|
||
?>
|
||
<!DOCTYPE html>
|
||
<html lang="de" dir="ltr">
|
||
<head>
|
||
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/intranet_repo/projects/_central/php/html_head.php'; ?>
|
||
<link rel="stylesheet" href="/intranet_repo/projects/_central/layouts/contentpanel.css">
|
||
<script src="/intranet_repo/projects/_central/scripts/contentpanel.js" defer></script>
|
||
</head>
|
||
<body class="theme-raspberry">
|
||
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/intranet_repo/projects/_central/php/header.php'; ?>
|
||
|
||
<div class="header_title ht_raspberry text_white" id="header_title">
|
||
<span class="header_title_text">Schwarzes Brett</span>
|
||
</div>
|
||
|
||
<div class="sb-page">
|
||
<div class="content-tab-bar" role="tablist" aria-label="Schwarzes Brett">
|
||
<button type="button" class="content-tab-bar__item active" data-tab="gottesdienst">Gottesdienst</button>
|
||
<button type="button" class="content-tab-bar__item" data-tab="ansagen">Ansagen</button>
|
||
<button type="button" class="content-tab-bar__item" data-tab="dateien">Dateiverwaltung</button>
|
||
</div>
|
||
|
||
<section class="sb-tab-content active" id="tab-gottesdienst">
|
||
<?php if ($flashTab === 'gottesdienst' && $flashMessage !== ''): ?>
|
||
<div class="sb-alert<?= $flashType === 'error' ? ' sb-alert-error' : '' ?>" role="status">
|
||
<?= contentpanel_html($flashMessage) ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<div class="sb-card">
|
||
<div class="sb-card-title">
|
||
<svg viewBox="0 0 24 24"><path d="M19 3h-1V1h-2v2H8V1H6v2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V8h14v11z"/></svg>
|
||
Geplante Gottesdienste
|
||
</div>
|
||
<div class="sb-entry-list">
|
||
<?php if ($services === []): ?>
|
||
<div class="sb-empty">Keine Einträge vorhanden.</div>
|
||
<?php else: ?>
|
||
<?php foreach ($services as $row): ?>
|
||
<div class="sb-entry">
|
||
<div class="sb-entry-info">
|
||
<div class="sb-entry-date"><?= contentpanel_html($row['datum']) ?></div>
|
||
<div class="sb-entry-title"><?= contentpanel_html($row['bibelwort']) ?></div>
|
||
<div class="sb-entry-subtitle"><?= contentpanel_html($row['bibelvers']) ?></div>
|
||
</div>
|
||
<form method="post" action="insert.php">
|
||
<input type="hidden" name="csrf_token" value="<?= contentpanel_html($csrfToken) ?>">
|
||
<input type="hidden" name="action" value="delete_service">
|
||
<input type="hidden" name="id" value="<?= (int) $row['id'] ?>">
|
||
<button type="submit" class="sb-btn sb-btn-danger" data-confirm="Eintrag wirklich löschen?">Löschen</button>
|
||
</form>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
<?php endif; ?>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="sb-card">
|
||
<div class="sb-card-title">
|
||
<svg viewBox="0 0 24 24"><path d="M9 16h6v-6h4l-7-7-7 7h4v6zm-4 2h14v2H5v-2z"/></svg>
|
||
Leitgedanken importieren
|
||
</div>
|
||
<form action="insert.php" method="post" enctype="multipart/form-data" data-upload-form>
|
||
<input type="hidden" name="csrf_token" value="<?= contentpanel_html($csrfToken) ?>">
|
||
<input type="hidden" name="action" value="import_leitgedanken">
|
||
<div class="sb-form-grid sb-form-grid-single">
|
||
<div class="sb-field-group">
|
||
<label class="sb-label" for="leitgedanken_pdf">PDF hochladen (LG_*.pdf)</label>
|
||
<input class="sb-field" id="leitgedanken_pdf" type="file" name="leitgedanken_pdf" accept=".pdf,application/pdf" required>
|
||
</div>
|
||
<div class="sb-field-group">
|
||
<button type="submit" class="sb-btn sb-btn-primary sb-upload-button">Import starten</button>
|
||
<span class="sb-spinner" aria-label="Import läuft"></span>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
|
||
<div class="sb-card">
|
||
<div class="sb-card-title">
|
||
<svg viewBox="0 0 24 24"><path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/></svg>
|
||
Neuen Gottesdienst planen
|
||
</div>
|
||
<form method="post" action="insert.php">
|
||
<input type="hidden" name="csrf_token" value="<?= contentpanel_html($csrfToken) ?>">
|
||
<input type="hidden" name="action" value="create_service">
|
||
<div class="sb-form-grid">
|
||
<div class="sb-field-group sb-form-full">
|
||
<label class="sb-label" for="bibeldatum">Datum des Gottesdienstes <span class="sb-required">*</span></label>
|
||
<input class="sb-field" id="bibeldatum" type="date" name="bibeldatum" required>
|
||
</div>
|
||
<div class="sb-field-group">
|
||
<label class="sb-label" for="bibelwort">Bibelstelle <span class="sb-required">*</span></label>
|
||
<input class="sb-field" id="bibelwort" type="text" name="bibelwort" required placeholder="z.B. Joh 3,16">
|
||
</div>
|
||
<div class="sb-field-group">
|
||
<label class="sb-label" for="bibelvers">Bibelvers <span class="sb-required">*</span></label>
|
||
<input class="sb-field" id="bibelvers" type="text" name="bibelvers" required placeholder="Bibelvers eingeben">
|
||
</div>
|
||
<div class="sb-field-group sb-form-full sb-field-group-action">
|
||
<button type="submit" class="sb-btn sb-btn-primary">Eintragen</button>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="sb-tab-content" id="tab-ansagen">
|
||
<?php if ($flashTab === 'ansagen' && $flashMessage !== ''): ?>
|
||
<div class="sb-alert<?= $flashType === 'error' ? ' sb-alert-error' : '' ?>" role="status">
|
||
<?= contentpanel_html($flashMessage) ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<div class="sb-card">
|
||
<div class="sb-card-title">
|
||
<svg viewBox="0 0 24 24"><path d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"/></svg>
|
||
Geplante Ansagen
|
||
</div>
|
||
<div class="sb-entry-list">
|
||
<?php if ($announcements === []): ?>
|
||
<div class="sb-empty">Keine Einträge vorhanden.</div>
|
||
<?php else: ?>
|
||
<?php foreach ($announcements as $row): ?>
|
||
<div class="sb-entry">
|
||
<div class="sb-entry-info">
|
||
<div class="sb-entry-date">
|
||
<?= contentpanel_html($row['datum_von']) ?><?php if ($row['datum_bis'] !== ''): ?> – <?= contentpanel_html($row['datum_bis']) ?><?php endif; ?>
|
||
</div>
|
||
<div class="sb-entry-title"><?= contentpanel_html($row['ansage_titel']) ?></div>
|
||
<?php if (!empty($row['ansage_untertitel'])): ?>
|
||
<div class="sb-entry-subtitle"><?= contentpanel_html($row['ansage_untertitel']) ?></div>
|
||
<?php endif; ?>
|
||
<?php if ($row['uhrzeit'] !== '' || !empty($row['ansage_ort'])): ?>
|
||
<div class="sb-entry-meta">
|
||
<?php if ($row['uhrzeit'] !== ''): ?><?= contentpanel_html($row['uhrzeit']) ?> Uhr<?php endif; ?>
|
||
<?php if ($row['uhrzeit'] !== '' && !empty($row['ansage_ort'])): ?> · <?php endif; ?>
|
||
<?php if (!empty($row['ansage_ort'])): ?><?= contentpanel_html($row['ansage_ort']) ?><?php endif; ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
</div>
|
||
<form method="post" action="insert.php">
|
||
<input type="hidden" name="csrf_token" value="<?= contentpanel_html($csrfToken) ?>">
|
||
<input type="hidden" name="action" value="delete_announcement">
|
||
<input type="hidden" name="id" value="<?= (int) $row['id'] ?>">
|
||
<button type="submit" class="sb-btn sb-btn-danger" data-confirm="Ansage wirklich löschen?">Löschen</button>
|
||
</form>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
<?php endif; ?>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="sb-card">
|
||
<div class="sb-card-title">
|
||
<svg viewBox="0 0 24 24"><path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/></svg>
|
||
Neue Ansage planen
|
||
</div>
|
||
<form method="post" action="insert.php">
|
||
<input type="hidden" name="csrf_token" value="<?= contentpanel_html($csrfToken) ?>">
|
||
<input type="hidden" name="action" value="create_announcement">
|
||
<div class="sb-form-grid">
|
||
<div class="sb-field-group sb-form-full">
|
||
<label class="sb-label" for="ansage_titel">Titel <span class="sb-required">*</span></label>
|
||
<input class="sb-field" id="ansage_titel" type="text" name="ansage_titel" required placeholder="Titel der Ansage">
|
||
</div>
|
||
<div class="sb-field-group">
|
||
<label class="sb-label" for="ansage_datum_von">Datum <span class="sb-required">*</span></label>
|
||
<input class="sb-field" id="ansage_datum_von" type="date" name="ansage_datum_von" required>
|
||
</div>
|
||
<div class="sb-field-group">
|
||
<label class="sb-label" for="ansage_datum_bis">Datum bis <span class="sb-optional">(optional)</span></label>
|
||
<input class="sb-field" id="ansage_datum_bis" type="date" name="ansage_datum_bis">
|
||
</div>
|
||
<div class="sb-field-group">
|
||
<label class="sb-label" for="ansage_uhrzeit">Uhrzeit <span class="sb-optional">(optional)</span></label>
|
||
<input class="sb-field" id="ansage_uhrzeit" type="time" name="ansage_uhrzeit">
|
||
</div>
|
||
<div class="sb-field-group">
|
||
<label class="sb-label" for="ansage_ort">Ort <span class="sb-optional">(optional)</span></label>
|
||
<input class="sb-field" id="ansage_ort" type="text" name="ansage_ort" placeholder="z.B. Gemeindesaal">
|
||
</div>
|
||
<div class="sb-field-group sb-form-full">
|
||
<label class="sb-label" for="ansage_untertitel">Weitere Informationen <span class="sb-optional">(optional)</span></label>
|
||
<input class="sb-field" id="ansage_untertitel" type="text" name="ansage_untertitel" placeholder="Zusätzliche Hinweise">
|
||
</div>
|
||
<div class="sb-field-group sb-form-full sb-field-group-action">
|
||
<button type="submit" class="sb-btn sb-btn-primary">Eintragen</button>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="sb-tab-content" id="tab-dateien">
|
||
<?php if ($flashTab === 'dateien' && $flashMessage !== ''): ?>
|
||
<div class="sb-alert<?= $flashType === 'error' ? ' sb-alert-error' : '' ?>" role="status">
|
||
<?= contentpanel_html($flashMessage) ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<div class="sb-card">
|
||
<div class="sb-card-title">
|
||
<svg viewBox="0 0 24 24"><path d="M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6zm4 18H6V4h7v5h5v11z"/></svg>
|
||
Aktuelle Aushänge
|
||
</div>
|
||
<div class="sb-aushang-grid">
|
||
<?php if ($newsItems === []): ?>
|
||
<div class="sb-empty">Keine Aushänge vorhanden.</div>
|
||
<?php else: ?>
|
||
<?php foreach ($newsItems as $item): ?>
|
||
<div class="sb-aushang-card">
|
||
<img src="<?= contentpanel_html($item['image_url']) ?>" alt="Aushang">
|
||
<div class="sb-aushang-title"><?= contentpanel_html($item['title']) ?></div>
|
||
<div class="sb-aushang-meta">
|
||
<?= (int) $item['pages'] ?> <?= (int) $item['pages'] === 1 ? 'Seite' : 'Seiten' ?> · Verfällt <?= contentpanel_html($item['expiry']) ?>
|
||
</div>
|
||
<form method="post" action="insert.php" class="sb-aushang-delete-form">
|
||
<input type="hidden" name="csrf_token" value="<?= contentpanel_html($csrfToken) ?>">
|
||
<input type="hidden" name="action" value="delete_news">
|
||
<input type="hidden" name="file_base" value="<?= contentpanel_html($item['base']) ?>">
|
||
<button type="submit" class="sb-btn sb-btn-danger" data-confirm="Aushang wirklich löschen?">Löschen</button>
|
||
</form>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
<?php endif; ?>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="sb-card">
|
||
<div class="sb-card-title">
|
||
<svg viewBox="0 0 24 24"><path d="M9 16h6v-6h4l-7-7-7 7h4v6zm-4 2h14v2H5v-2z"/></svg>
|
||
Neuen Aushang hochladen
|
||
</div>
|
||
<form action="insert.php" method="post" enctype="multipart/form-data" data-upload-form>
|
||
<input type="hidden" name="csrf_token" value="<?= contentpanel_html($csrfToken) ?>">
|
||
<input type="hidden" name="action" value="upload_news">
|
||
<div class="sb-form-grid">
|
||
<div class="sb-field-group">
|
||
<label class="sb-label" for="news_date">Verfallsdatum <span class="sb-required">*</span></label>
|
||
<input class="sb-field" id="news_date" type="date" name="date" required>
|
||
</div>
|
||
<div class="sb-field-group">
|
||
<label class="sb-label" for="news_name">Titel des Aushangs <span class="sb-required">*</span></label>
|
||
<input class="sb-field" id="news_name" type="text" name="name" required placeholder="Name des Dokuments">
|
||
</div>
|
||
<div class="sb-field-group sb-form-full">
|
||
<label class="sb-label" for="fileToUpload">PDF-Datei auswählen <span class="sb-required">*</span></label>
|
||
<input class="sb-field" id="fileToUpload" type="file" name="fileToUpload" accept=".pdf,application/pdf" required>
|
||
</div>
|
||
<div class="sb-field-group sb-form-full sb-field-group-action">
|
||
<button type="submit" class="sb-btn sb-btn-primary sb-upload-button">Datei hochladen</button>
|
||
<span class="sb-spinner" aria-label="Upload läuft"></span>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
|
||
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/intranet_repo/projects/_central/php/footer.php'; ?>
|
||
</body>
|
||
</html>
|