Haerte Verwaltungsflows und Zahlungsabgleich
This commit is contained in:
+55
-19
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
ob_start();
|
||||
|
||||
include "functions.php";
|
||||
require_once __DIR__ . "/app/ledger.php";
|
||||
require_once __DIR__ . "/app/notices.php";
|
||||
@@ -32,7 +34,15 @@ if ($saasUser !== null && saas_user_has_role(['owner', 'admin'], $saasUser)) {
|
||||
|
||||
if($hasAccess){
|
||||
|
||||
echo "<h2>Kaffeeliste - Hinweise</h2>";
|
||||
$meldung = null;
|
||||
$fehler = null;
|
||||
|
||||
if (isset($_SESSION['flash_hinweise']) && is_array($_SESSION['flash_hinweise'])) {
|
||||
$flash = $_SESSION['flash_hinweise'];
|
||||
unset($_SESSION['flash_hinweise']);
|
||||
$meldung = isset($flash['meldung']) ? (string)$flash['meldung'] : null;
|
||||
$fehler = isset($flash['fehler']) ? (string)$flash['fehler'] : null;
|
||||
}
|
||||
|
||||
// Hinweis speichern oder als geloescht markieren
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
@@ -44,26 +54,50 @@ if($hasAccess){
|
||||
$id = (int)($_POST['id'] ?? 0);
|
||||
if ($id > 0 && notices_soft_delete($pdo, $tenantId, $id)) {
|
||||
app_audit_log($pdo, $tenantId, $actorUserId, 'notice.deleted', 'notice', $id);
|
||||
$meldung = 'Hinweis wurde gelöscht.';
|
||||
} else {
|
||||
$fehler = 'Der Hinweis konnte nicht gelöscht werden.';
|
||||
}
|
||||
} else {
|
||||
$nachricht = $_POST['nachricht'] ?? '';
|
||||
$gueltig_bis = $_POST['gueltig_bis'] ?? ''; // z.B. "2025-09-03T14:00"
|
||||
$nachricht = trim((string)($_POST['nachricht'] ?? ''));
|
||||
$gueltig_bis = trim((string)($_POST['gueltig_bis'] ?? '')); // z.B. "2025-09-03T14:00"
|
||||
$dt = DateTime::createFromFormat('Y-m-d\TH:i', $gueltig_bis);
|
||||
$dtErrors = DateTime::getLastErrors();
|
||||
|
||||
if ($dt) {
|
||||
if ($nachricht === '') {
|
||||
$fehler = 'Bitte eine Nachricht eintragen.';
|
||||
} elseif ($dt === false || ($dtErrors !== false && ((int)$dtErrors['warning_count'] > 0 || (int)$dtErrors['error_count'] > 0))) {
|
||||
$fehler = 'Bitte ein gültiges Datum mit Uhrzeit angeben.';
|
||||
} else {
|
||||
$gueltig_bis_sql = $dt->format('Y-m-d H:i:s'); // z.B. "2025-09-03 14:00:00"
|
||||
notices_create($pdo, $tenantId, (string)$nachricht, $gueltig_bis_sql, $actorUserId);
|
||||
app_audit_log($pdo, $tenantId, $actorUserId, 'notice.created', 'notice', null, ['valid_until' => $gueltig_bis_sql]);
|
||||
$meldung = 'Hinweis wurde gespeichert.';
|
||||
}
|
||||
}
|
||||
|
||||
$_SESSION['flash_hinweise'] = [
|
||||
'meldung' => $meldung,
|
||||
'fehler' => $fehler,
|
||||
];
|
||||
header('Location: hinweise.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$hinweise = notices_fetch_all($pdo, $tenantId);
|
||||
?>
|
||||
|
||||
<h2>Kaffeeliste - Hinweise</h2>
|
||||
|
||||
<?php if ($meldung !== null): ?>
|
||||
<div class="hint-box success"><p><?php echo saas_html($meldung); ?></p></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($fehler !== null): ?>
|
||||
<div class="hint-box error"><p><?php echo saas_html($fehler); ?></p></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<h2>Neuen Hinweis hinzufügen</h2>
|
||||
<form method="post">
|
||||
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
|
||||
<input type="hidden" name="aktion" value="speichern">
|
||||
<?php echo app_csrf_field(); ?>
|
||||
<label>Nachricht:</label>
|
||||
@@ -74,20 +108,22 @@ if($hasAccess){
|
||||
</form>
|
||||
|
||||
<h2>Alle Hinweise</h2>
|
||||
<?php foreach ($hinweise as $hinweis): ?>
|
||||
<div class="hinweis">
|
||||
<strong><?php echo saas_html($hinweis['message']); ?></strong><br>
|
||||
<small>Gültig bis: <?php echo saas_html((new DateTimeImmutable($hinweis['valid_until']))->format('d.m.Y H:i')); ?></small><br>
|
||||
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" onsubmit="return confirm('Diesen Hinweis wirklich löschen?')">
|
||||
<input type="hidden" name="aktion" value="loeschen">
|
||||
<input type="hidden" name="id" value="<?php echo (int)$hinweis['id']; ?>">
|
||||
<?php echo app_csrf_field(); ?>
|
||||
<button type="submit">Löschen</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</body>
|
||||
</html>
|
||||
<?php if ($hinweise === []): ?>
|
||||
<p>Aktuell sind keine Hinweise angelegt.</p>
|
||||
<?php else: ?>
|
||||
<?php foreach ($hinweise as $hinweis): ?>
|
||||
<div class="hinweis">
|
||||
<strong><?php echo saas_html($hinweis['message']); ?></strong><br>
|
||||
<small>Gültig bis: <?php echo saas_html((new DateTimeImmutable($hinweis['valid_until']))->format('d.m.Y H:i')); ?></small><br>
|
||||
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" onsubmit="return confirm('Diesen Hinweis wirklich löschen?')">
|
||||
<input type="hidden" name="aktion" value="loeschen">
|
||||
<input type="hidden" name="id" value="<?php echo (int)$hinweis['id']; ?>">
|
||||
<?php echo app_csrf_field(); ?>
|
||||
<button type="submit">Löschen</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
|
||||
|
||||
Reference in New Issue
Block a user