105 lines
7.1 KiB
PHP
105 lines
7.1 KiB
PHP
<?php
|
|
// Seite des Schichtübergabe-Plugins. Verfügbar: $staff, $pdo.
|
|
$isAdmin = ($staff['role'] ?? '') === 'admin';
|
|
$message = null;
|
|
$error = null;
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
verify_csrf();
|
|
$action = $_POST['action'] ?? '';
|
|
if ($action === 'create') {
|
|
$dept = ($_POST['department_id'] ?? '') !== '' ? (int) $_POST['department_id'] : null;
|
|
$r = schicht_create($pdo, $staff, (string) ($_POST['message'] ?? ''), $dept, !empty($_POST['important']));
|
|
if ($r['ok']) $message = 'Die Notiz ist gespeichert (unten steht sie ganz oben). Die anderen sehen sie als „neu“ im Menü' . (!empty($_POST['important']) ? ' und in der Seitenleiste jedes Tickets. Sie selbst sehen sie dort die nächsten 12 Stunden ebenfalls, mit der Zahl der Leser' : '') . '.'; else $error = $r['error'];
|
|
} elseif ($action === 'delete') {
|
|
if (schicht_delete($pdo, $staff, (int) ($_POST['id'] ?? 0))) $message = 'Die Notiz wurde gelöscht.'; else $error = 'Diese Notiz können Sie nicht löschen.';
|
|
} elseif ($action === 'mark_read') {
|
|
schicht_mark_read($pdo, $staff, [(int) ($_POST['id'] ?? 0)]);
|
|
$message = 'Als gelesen markiert. Der Hinweis ist ausgeblendet.';
|
|
} elseif ($action === 'hide_own') {
|
|
schicht_hide_own($staff, (int) ($_POST['id'] ?? 0));
|
|
$message = 'Die Bestätigung auf der Übersicht ist ausgeblendet. Die Notiz selbst bleibt unten erhalten.';
|
|
} elseif ($action === 'mark_all') {
|
|
schicht_mark_read($pdo, $staff, array_map(fn($n) => (int) $n['id'], schicht_unread($pdo, $staff)));
|
|
$message = 'Alle Notizen sind als gelesen markiert. Die Hinweise sind ausgeblendet.';
|
|
} elseif ($action === 'settings') {
|
|
if (!$isAdmin) $error = 'Einstellungen ändern darf nur ein Administrator.';
|
|
else {
|
|
plugin_set_setting(SCHICHT, 'keep_days', (string) max(1, min(365, (int) ($_POST['keep_days'] ?? 30))));
|
|
$message = 'Einstellungen gespeichert.';
|
|
}
|
|
}
|
|
}
|
|
|
|
// Notizen gelten erst als gelesen, wenn der Mitarbeiter sie bestätigt („Gelesen“); erst dann verschwinden die Hinweise
|
|
$notes = schicht_list($pdo, $staff);
|
|
$newIds = array_map(fn($n) => (int) $n['id'], array_filter($notes, fn($n) => !(int) $n['is_read']));
|
|
|
|
$own = schicht_departments($pdo, $staff);
|
|
$depts = $pdo->query('SELECT id, name FROM departments ORDER BY name')->fetchAll();
|
|
if ($own !== null) $depts = array_values(array_filter($depts, fn($d) => in_array((int) $d['id'], $own, true)));
|
|
?>
|
|
<h1>Schichtübergabe</h1>
|
|
<?php if ($message): ?><div class="flash success"><?= e($message) ?></div><?php endif; ?>
|
|
<?php if ($error): ?><div class="flash error"><?= e($error) ?></div><?php endif; ?>
|
|
|
|
<form method="post" class="card" style="max-width:820px;margin-bottom:16px">
|
|
<?= csrf_field() ?>
|
|
<input type="hidden" name="action" value="create">
|
|
<h3>Notiz für die nächste Schicht</h3>
|
|
<textarea name="message" rows="4" maxlength="3000" required placeholder="Was muss die nächste Schicht wissen? Offene Punkte, Störungen, besondere Kunden …"></textarea>
|
|
<div style="display:flex;gap:14px;flex-wrap:wrap;align-items:center;margin-top:8px">
|
|
<div><label>Gilt für</label>
|
|
<select name="department_id">
|
|
<option value="">Alle Mitarbeiter</option>
|
|
<?php foreach ($depts as $d): ?><option value="<?= (int) $d['id'] ?>">Nur Abteilung: <?= e($d['name']) ?></option><?php endforeach; ?>
|
|
</select></div>
|
|
<label style="font-weight:400"><input type="checkbox" name="important" value="1" style="width:auto"> Wichtig (erscheint auch in der Seitenleiste jedes Tickets)</label>
|
|
</div>
|
|
<div class="btn-row"><button type="submit" class="btn">Notiz speichern</button></div>
|
|
</form>
|
|
|
|
<div class="card" style="max-width:820px;margin-bottom:16px">
|
|
<div style="display:flex;justify-content:space-between;align-items:center;gap:10px;flex-wrap:wrap">
|
|
<h3 style="margin:0">Notizen der letzten <?= schicht_keep_days() ?> Tage</h3>
|
|
<?php if ($newIds): ?><form method="post"><?= csrf_field() ?><input type="hidden" name="action" value="mark_all"><button class="btn" type="submit">Alle <?= count($newIds) ?> als gelesen markieren</button></form><?php endif; ?>
|
|
</div>
|
|
<?php if (!$notes): ?><p class="muted">Noch keine Notizen.</p><?php endif; ?>
|
|
<?php foreach ($notes as $n): $isNew = in_array((int) $n['id'], $newIds, true); $mine = (int) $n['staff_id'] === (int) $staff['id']; ?>
|
|
<div style="padding:12px 0;border-top:1px solid var(--border,#e3e9ee);<?= $isNew ? 'background:rgba(15,111,106,.07);margin:0 -10px;padding-left:10px;padding-right:10px' : '' ?>">
|
|
<div style="display:flex;justify-content:space-between;gap:10px;flex-wrap:wrap">
|
|
<div style="font-size:.88rem">
|
|
<strong><?= e((string) $n['author']) ?></strong>
|
|
<span class="muted"> · <?= e(format_dt((string) $n['created_at'])) ?> · <?= $n['department'] ? 'Abteilung ' . e((string) $n['department']) : 'alle' ?></span>
|
|
<?php if ($isNew): ?><span class="tag" style="background:#e6f7ee;color:#157a45;border-radius:20px;padding:2px 9px;font-size:.72rem;font-weight:700">neu</span><?php endif; ?>
|
|
<?php if ($mine): ?><span style="background:#e6edff;color:#2f4fc4;border-radius:20px;padding:2px 9px;font-size:.72rem;font-weight:700">von Ihnen</span><?php endif; ?>
|
|
<?php if ($n['is_important']): ?><span style="background:#fde8e8;color:#b42318;border-radius:20px;padding:2px 9px;font-size:.72rem;font-weight:700">wichtig</span><?php endif; ?>
|
|
</div>
|
|
<div style="display:flex;gap:6px;align-items:flex-start">
|
|
<?php if ($isNew): ?>
|
|
<form method="post"><?= csrf_field() ?><input type="hidden" name="action" value="mark_read"><input type="hidden" name="id" value="<?= (int) $n['id'] ?>"><button class="btn" type="submit" style="padding:2px 10px;font-size:.78rem">✓ Gelesen</button></form>
|
|
<?php endif; ?>
|
|
<?php if ($mine || $isAdmin): ?>
|
|
<form method="post" onsubmit="return confirm('Notiz löschen?')"><?= csrf_field() ?><input type="hidden" name="action" value="delete"><input type="hidden" name="id" value="<?= (int) $n['id'] ?>"><button class="btn secondary" type="submit" style="padding:2px 10px;font-size:.78rem">Löschen</button></form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<p style="margin:6px 0 0;white-space:normal"><?= nl2br(e((string) $n['message'])) ?></p>
|
|
<?php if ($mine || $isAdmin): $readers = schicht_readers($pdo, (int) $n['id']); ?>
|
|
<div class="muted" style="font-size:.76rem;margin-top:4px">Gelesen von: <?= $readers ? e(implode(', ', $readers)) : 'noch niemand' ?></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<?php if ($isAdmin): ?>
|
|
<form method="post" class="card" style="max-width:820px">
|
|
<?= csrf_field() ?>
|
|
<input type="hidden" name="action" value="settings">
|
|
<h3>Einstellungen (nur Administratoren)</h3>
|
|
<label for="keep_days">Notizen automatisch löschen nach (Tagen)</label>
|
|
<input type="number" id="keep_days" name="keep_days" min="1" max="365" value="<?= schicht_keep_days() ?>" style="max-width:120px">
|
|
<div class="btn-row"><button type="submit" class="btn">Speichern</button></div>
|
|
</form>
|
|
<?php endif; ?>
|