Upload via GUI (94 Dateien)
This commit is contained in:
@@ -0,0 +1,237 @@
|
||||
<?php
|
||||
// Schichtübergabe. Alle Funktionen beginnen mit schicht_.
|
||||
|
||||
const SCHICHT = 'schichtuebergabe';
|
||||
|
||||
function schicht_keep_days(): int
|
||||
{
|
||||
return max(1, min(365, (int) plugin_setting(SCHICHT, 'keep_days', '30')));
|
||||
}
|
||||
|
||||
/** Abteilungen eines Mitarbeiters (Hauptabteilung und weitere); null = Administrator, sieht alle. */
|
||||
function schicht_departments(PDO $pdo, array $staff): ?array
|
||||
{
|
||||
if (($staff['role'] ?? '') === 'admin') return null;
|
||||
$ids = [];
|
||||
if (!empty($staff['department_id'])) $ids[] = (int) $staff['department_id'];
|
||||
$s = $pdo->prepare('SELECT department_id FROM staff_department WHERE staff_id = ?');
|
||||
$s->execute([(int) $staff['id']]);
|
||||
foreach ($s->fetchAll(PDO::FETCH_COLUMN) as $d) $ids[] = (int) $d;
|
||||
return array_values(array_unique($ids));
|
||||
}
|
||||
|
||||
/** SQL-Bedingung und Parameter: Notizen, die dieser Mitarbeiter sehen darf (für alle oder für eine seiner Abteilungen). */
|
||||
function schicht_visible_sql(PDO $pdo, array $staff, string $alias = 'n'): array
|
||||
{
|
||||
$depts = schicht_departments($pdo, $staff);
|
||||
if ($depts === null) return ['1=1', []];
|
||||
if (!$depts) return ["{$alias}.department_id IS NULL", []];
|
||||
return ["({$alias}.department_id IS NULL OR {$alias}.department_id IN (" . implode(',', array_fill(0, count($depts), '?')) . '))', $depts];
|
||||
}
|
||||
|
||||
/** Notiz anlegen. @return array{ok:bool,error?:string,id?:int} */
|
||||
function schicht_create(PDO $pdo, array $staff, string $message, ?int $departmentId, bool $important): array
|
||||
{
|
||||
$message = trim($message);
|
||||
if ($message === '') return ['ok' => false, 'error' => 'Bitte eine Notiz schreiben.'];
|
||||
if (mb_strlen($message) > 3000) return ['ok' => false, 'error' => 'Die Notiz ist zu lang (höchstens 3000 Zeichen).'];
|
||||
if ($departmentId !== null) {
|
||||
$own = schicht_departments($pdo, $staff);
|
||||
if ($own !== null && !in_array($departmentId, $own, true)) return ['ok' => false, 'error' => 'Sie können Notizen nur für Ihre eigenen Abteilungen schreiben.'];
|
||||
$d = $pdo->prepare('SELECT COUNT(*) FROM departments WHERE id = ?');
|
||||
$d->execute([$departmentId]);
|
||||
if (!(int) $d->fetchColumn()) return ['ok' => false, 'error' => 'Die Abteilung gibt es nicht.'];
|
||||
}
|
||||
$pdo->prepare('INSERT INTO plugin_schichtuebergabe_notes (staff_id, department_id, message, is_important, created_at) VALUES (?,?,?,?,?)')
|
||||
->execute([(int) $staff['id'], $departmentId, $message, $important ? 1 : 0, db_now()]);
|
||||
$id = (int) $pdo->lastInsertId();
|
||||
// Der Verfasser hat sie natürlich gelesen
|
||||
$pdo->prepare('INSERT INTO plugin_schichtuebergabe_reads (note_id, staff_id, read_at) VALUES (?,?,?)')->execute([$id, (int) $staff['id'], db_now()]);
|
||||
return ['ok' => true, 'id' => $id];
|
||||
}
|
||||
|
||||
/** Ungelesene Notizen für einen Mitarbeiter (innerhalb der Aufbewahrungsfrist). */
|
||||
function schicht_unread(PDO $pdo, array $staff, bool $onlyImportant = false): array
|
||||
{
|
||||
[$cond, $params] = schicht_visible_sql($pdo, $staff);
|
||||
$sql = "SELECT n.*, s.name AS author FROM plugin_schichtuebergabe_notes n LEFT JOIN staff s ON s.id = n.staff_id
|
||||
WHERE {$cond} AND n.created_at >= ? AND NOT EXISTS (SELECT 1 FROM plugin_schichtuebergabe_reads r WHERE r.note_id = n.id AND r.staff_id = ?)"
|
||||
. ($onlyImportant ? ' AND n.is_important = 1' : '') . ' ORDER BY n.id DESC LIMIT 50';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute(array_merge($params, [date('Y-m-d H:i:s', time() - schicht_keep_days() * 86400), (int) $staff['id']]));
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
function schicht_unread_count(PDO $pdo, array $staff): int
|
||||
{
|
||||
return count(schicht_unread($pdo, $staff));
|
||||
}
|
||||
|
||||
/** Alle sichtbaren Notizen (neueste zuerst) mit Leseinfo. */
|
||||
function schicht_list(PDO $pdo, array $staff, int $limit = 60): array
|
||||
{
|
||||
[$cond, $params] = schicht_visible_sql($pdo, $staff);
|
||||
$stmt = $pdo->prepare("SELECT n.*, s.name AS author, d.name AS department,
|
||||
(SELECT COUNT(*) FROM plugin_schichtuebergabe_reads r WHERE r.note_id = n.id AND r.staff_id = ?) AS is_read
|
||||
FROM plugin_schichtuebergabe_notes n LEFT JOIN staff s ON s.id = n.staff_id LEFT JOIN departments d ON d.id = n.department_id
|
||||
WHERE {$cond} AND n.created_at >= ? ORDER BY n.id DESC LIMIT " . max(1, $limit));
|
||||
$stmt->execute(array_merge([(int) $staff['id']], $params, [date('Y-m-d H:i:s', time() - schicht_keep_days() * 86400)]));
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
/** Markiert die Notizen als gelesen. */
|
||||
function schicht_mark_read(PDO $pdo, array $staff, array $noteIds): void
|
||||
{
|
||||
foreach ($noteIds as $id) {
|
||||
$id = (int) $id;
|
||||
$has = $pdo->prepare('SELECT COUNT(*) FROM plugin_schichtuebergabe_reads WHERE note_id = ? AND staff_id = ?');
|
||||
$has->execute([$id, (int) $staff['id']]);
|
||||
if ((int) $has->fetchColumn()) continue;
|
||||
$pdo->prepare('INSERT INTO plugin_schichtuebergabe_reads (note_id, staff_id, read_at) VALUES (?,?,?)')->execute([$id, (int) $staff['id'], db_now()]);
|
||||
}
|
||||
}
|
||||
|
||||
/** Wer hat die Notiz gelesen? @return list<string> */
|
||||
function schicht_readers(PDO $pdo, int $noteId): array
|
||||
{
|
||||
$s = $pdo->prepare('SELECT s.name FROM plugin_schichtuebergabe_reads r JOIN staff s ON s.id = r.staff_id WHERE r.note_id = ? ORDER BY r.read_at');
|
||||
$s->execute([$noteId]);
|
||||
return array_map('strval', $s->fetchAll(PDO::FETCH_COLUMN));
|
||||
}
|
||||
|
||||
/** Löschen darf der Verfasser und jeder Administrator. */
|
||||
function schicht_delete(PDO $pdo, array $staff, int $id): bool
|
||||
{
|
||||
$s = $pdo->prepare('SELECT staff_id FROM plugin_schichtuebergabe_notes WHERE id = ?');
|
||||
$s->execute([$id]);
|
||||
$owner = $s->fetchColumn();
|
||||
if ($owner === false) return false;
|
||||
if (($staff['role'] ?? '') !== 'admin' && (int) $owner !== (int) $staff['id']) return false;
|
||||
$pdo->prepare('DELETE FROM plugin_schichtuebergabe_reads WHERE note_id = ?')->execute([$id]);
|
||||
$pdo->prepare('DELETE FROM plugin_schichtuebergabe_notes WHERE id = ?')->execute([$id]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Aufräumen: Notizen nach Ablauf der Frist löschen (höchstens einmal pro Stunde). */
|
||||
function schicht_cleanup(PDO $pdo): int
|
||||
{
|
||||
if (time() - (int) plugin_setting(SCHICHT, 'last_cleanup', '0') < 3600) return 0;
|
||||
plugin_set_setting(SCHICHT, 'last_cleanup', (string) time());
|
||||
$cut = date('Y-m-d H:i:s', time() - schicht_keep_days() * 86400);
|
||||
$pdo->prepare('DELETE FROM plugin_schichtuebergabe_reads WHERE note_id IN (SELECT id FROM plugin_schichtuebergabe_notes WHERE created_at < ?)')->execute([$cut]);
|
||||
$del = $pdo->prepare('DELETE FROM plugin_schichtuebergabe_notes WHERE created_at < ?');
|
||||
$del->execute([$cut]);
|
||||
return $del->rowCount();
|
||||
}
|
||||
|
||||
/** Beschriftung des Menüpunkts mit Zähler. Ohne angemeldeten Mitarbeiter oder bei Fehlern der einfache Name. */
|
||||
function schicht_menu_label(): string
|
||||
{
|
||||
try {
|
||||
$staff = function_exists('current_staff') ? current_staff() : null;
|
||||
if ($staff) {
|
||||
$n = schicht_unread_count(get_db(), $staff);
|
||||
if ($n > 0) return 'Schichtübergabe (' . $n . ' neu)';
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
// Der Menüpunkt darf nie wegen eines Fehlers fehlen
|
||||
}
|
||||
return 'Schichtübergabe';
|
||||
}
|
||||
|
||||
/** Wichtige Notizen für die Seitenleiste: ungelesene und die eigenen der letzten 12 Stunden (so sieht der Verfasser, dass sie ankommt). */
|
||||
function schicht_sidebar_notes(PDO $pdo, array $staff): array
|
||||
{
|
||||
$byId = [];
|
||||
foreach (schicht_unread($pdo, $staff, true) as $n) $byId[(int) $n['id']] = $n + ['own' => (int) $n['staff_id'] === (int) $staff['id']];
|
||||
$own = $pdo->prepare("SELECT n.*, s.name AS author FROM plugin_schichtuebergabe_notes n LEFT JOIN staff s ON s.id = n.staff_id WHERE n.staff_id = ? AND n.is_important = 1 AND n.created_at >= ? ORDER BY n.id DESC LIMIT 5");
|
||||
$own->execute([(int) $staff['id'], date('Y-m-d H:i:s', time() - 12 * 3600)]);
|
||||
foreach ($own->fetchAll() as $n) $byId[(int) $n['id']] = $n + ['own' => true];
|
||||
krsort($byId);
|
||||
return array_values($byId);
|
||||
}
|
||||
|
||||
/** HTML für die Seitenleiste eines Tickets: wichtige ungelesene Notizen und die eigenen wichtigen der letzten Stunden. */
|
||||
function schicht_sidebar_html(PDO $pdo, ?array $staff): string
|
||||
{
|
||||
if (!$staff) return '';
|
||||
$notes = schicht_sidebar_notes($pdo, $staff);
|
||||
if (!$notes) return '';
|
||||
$html = '<div class="card" style="margin-bottom:14px;border-left:4px solid #dc2626"><h3 style="margin:0 0 6px;font-size:.95rem">Wichtige Schichtübergabe</h3>';
|
||||
foreach (array_slice($notes, 0, 3) as $n) {
|
||||
$who = !empty($n['own']) ? 'Ihre Notiz' : (string) $n['author'];
|
||||
$readers = !empty($n['own']) ? count(array_filter(schicht_readers($pdo, (int) $n['id']), fn($r) => $r !== (string) ($staff['name'] ?? ''))) : null;
|
||||
$html .= '<p style="margin:0 0 8px;font-size:.85rem"><strong>' . e($who) . '</strong> <span class="muted">' . e(format_dt((string) $n['created_at'])) . ($readers !== null ? ' · von ' . $readers . ' gelesen' : '') . '</span><br>' . nl2br(e(mb_strimwidth((string) $n['message'], 0, 300, '…'))) . '</p>';
|
||||
}
|
||||
$html .= '<a class="btn secondary" href="/staff/plugin.php?p=' . SCHICHT . '&page=schichtuebergabe">Alle Notizen öffnen</a></div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
/** Ausgeblendete eigene Notizen (je Mitarbeiter, nur die Bestätigung auf der Übersicht). @return list<int> */
|
||||
function schicht_hidden_own(array $staff): array
|
||||
{
|
||||
$raw = (string) plugin_setting(SCHICHT, 'hidden_own_' . (int) $staff['id'], '');
|
||||
return $raw === '' ? [] : array_map('intval', explode(',', $raw));
|
||||
}
|
||||
|
||||
function schicht_hide_own(array $staff, int $noteId): void
|
||||
{
|
||||
$ids = array_slice(array_values(array_unique(array_merge(schicht_hidden_own($staff), [$noteId]))), -50);
|
||||
plugin_set_setting(SCHICHT, 'hidden_own_' . (int) $staff['id'], implode(',', $ids));
|
||||
}
|
||||
|
||||
/** Eigene Notizen der letzten 12 Stunden (für die Bestätigung auf der Übersicht), mit den Namen der Leser. */
|
||||
function schicht_own_recent(PDO $pdo, array $staff): array
|
||||
{
|
||||
$s = $pdo->prepare('SELECT n.*, d.name AS department FROM plugin_schichtuebergabe_notes n LEFT JOIN departments d ON d.id = n.department_id WHERE n.staff_id = ? AND n.created_at >= ? ORDER BY n.id DESC LIMIT 5');
|
||||
$s->execute([(int) $staff['id'], date('Y-m-d H:i:s', time() - 12 * 3600)]);
|
||||
$hidden = schicht_hidden_own($staff);
|
||||
$rows = array_values(array_filter($s->fetchAll(), fn($r) => !in_array((int) $r['id'], $hidden, true)));
|
||||
foreach ($rows as &$r) $r['readers'] = array_values(array_filter(schicht_readers($pdo, (int) $r['id']), fn($n) => $n !== (string) ($staff['name'] ?? '')));
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deutlicher Hinweis oben auf den Seiten des Mitarbeiterbereichs (also schon direkt nach der Anmeldung):
|
||||
* - solange es ungelesene Notizen anderer gibt, auf jeder Seite (rot bei wichtigen); auf der Seite der Schichtübergabe selbst entfällt er;
|
||||
* - die eigenen Notizen der letzten 12 Stunden als ruhige Bestätigung auf der Übersicht, mit den Namen derer, die sie gelesen haben.
|
||||
*/
|
||||
function schicht_banner_html(PDO $pdo, ?array $staff, string $activePage = ''): string
|
||||
{
|
||||
if (!$staff || $activePage === 'plugin_' . SCHICHT) return '';
|
||||
$html = '';
|
||||
$notes = schicht_unread($pdo, $staff);
|
||||
if ($notes) {
|
||||
usort($notes, fn($a, $b) => [(int) $b['is_important'], (int) $b['id']] <=> [(int) $a['is_important'], (int) $a['id']]);
|
||||
$important = count(array_filter($notes, fn($n) => (int) $n['is_important'] === 1));
|
||||
$color = $important ? '#dc2626' : '#0f6f6a';
|
||||
$bg = $important ? '#fef2f2' : '#ecfdf5';
|
||||
$count = count($notes);
|
||||
$html .= '<div class="schicht-banner" role="status" style="margin:0 0 16px;padding:14px 18px;border-radius:12px;border:1px solid ' . $color . ';border-left-width:6px;background:' . $bg . ';color:#16202a">'
|
||||
. '<div style="display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap">'
|
||||
. '<strong style="font-size:1rem">' . ($important ? '⚠ ' : '') . 'Schichtübergabe: ' . $count . ($count === 1 ? ' neue Notiz' : ' neue Notizen') . ($important ? ' (' . $important . ' wichtig)' : '') . '</strong>'
|
||||
. '<div style="display:flex;gap:8px;flex-wrap:wrap"><a class="btn secondary" href="/staff/plugin.php?p=' . SCHICHT . '&page=schichtuebergabe">Öffnen</a>'
|
||||
. '<form method="post" action="/staff/plugin.php?p=' . SCHICHT . '&page=schichtuebergabe" style="margin:0">' . csrf_field() . '<input type="hidden" name="action" value="mark_all"><button class="btn" type="submit">✓ Gelesen</button></form></div></div>';
|
||||
foreach (array_slice($notes, 0, 3) as $n) {
|
||||
$html .= '<div style="margin-top:10px;font-size:.9rem;line-height:1.45"><strong>' . e((string) $n['author']) . '</strong>'
|
||||
. ' <span style="color:#64748b;font-size:.8rem">' . e(format_dt((string) $n['created_at'])) . ((int) $n['is_important'] ? ' · wichtig' : '') . '</span><br>'
|
||||
. nl2br(e(mb_strimwidth((string) $n['message'], 0, 400, '…'))) . '</div>';
|
||||
}
|
||||
if ($count > 3) $html .= '<div style="margin-top:8px;font-size:.85rem;color:#64748b">… und ' . ($count - 3) . ' weitere</div>';
|
||||
$html .= '</div>';
|
||||
}
|
||||
// Eigene Notizen: nur auf der Übersicht, damit der Verfasser sieht, dass seine Notiz da ist und wer sie schon gelesen hat
|
||||
if (in_array($activePage, ['reports', 'dashboard'], true)) {
|
||||
foreach (schicht_own_recent($pdo, $staff) as $n) {
|
||||
$readers = $n['readers'];
|
||||
$html .= '<div class="schicht-banner schicht-banner-own" role="status" style="margin:0 0 16px;padding:12px 18px;border-radius:12px;border:1px solid #93c5fd;border-left-width:6px;background:#eff6ff;color:#16202a">'
|
||||
. '<div style="display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap">'
|
||||
. '<strong style="font-size:.95rem">Ihre Notiz an die nächste Schicht' . ((int) $n['is_important'] ? ' (wichtig)' : '') . ' · ' . ($n['department'] ? 'Abteilung ' . e((string) $n['department']) : 'alle Mitarbeiter') . '</strong>'
|
||||
. '<div style="display:flex;gap:8px;flex-wrap:wrap"><a class="btn secondary" href="/staff/plugin.php?p=' . SCHICHT . '&page=schichtuebergabe">Alle Notizen</a>'
|
||||
. '<form method="post" action="/staff/plugin.php?p=' . SCHICHT . '&page=schichtuebergabe" style="margin:0">' . csrf_field() . '<input type="hidden" name="action" value="hide_own"><input type="hidden" name="id" value="' . (int) $n['id'] . '"><button class="btn" type="submit">Ausblenden</button></form></div></div>'
|
||||
. '<div style="margin-top:8px;font-size:.9rem;line-height:1.45">' . nl2br(e(mb_strimwidth((string) $n['message'], 0, 400, '…'))) . '</div>'
|
||||
. '<div style="margin-top:6px;font-size:.8rem;color:#64748b">' . e(format_dt((string) $n['created_at'])) . ' · ' . ($readers ? 'Gelesen von: ' . e(implode(', ', $readers)) : 'noch von niemandem gelesen') . '</div></div>';
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
CREATE TABLE IF NOT EXISTS plugin_schichtuebergabe_notes (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
staff_id INT NOT NULL,
|
||||
department_id INT NULL,
|
||||
message TEXT NOT NULL,
|
||||
is_important TINYINT(1) NOT NULL DEFAULT 0,
|
||||
created_at DATETIME NOT NULL,
|
||||
KEY idx_plugin_schichtuebergabe_created (created_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
CREATE TABLE IF NOT EXISTS plugin_schichtuebergabe_reads (
|
||||
note_id INT NOT NULL,
|
||||
staff_id INT NOT NULL,
|
||||
read_at DATETIME NOT NULL,
|
||||
PRIMARY KEY (note_id, staff_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
|
||||
@@ -0,0 +1,15 @@
|
||||
CREATE TABLE IF NOT EXISTS plugin_schichtuebergabe_notes (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
staff_id INTEGER NOT NULL,
|
||||
department_id INTEGER NULL,
|
||||
message TEXT NOT NULL,
|
||||
is_important INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TEXT NOT NULL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_plugin_schichtuebergabe_created ON plugin_schichtuebergabe_notes (created_at);
|
||||
CREATE TABLE IF NOT EXISTS plugin_schichtuebergabe_reads (
|
||||
note_id INTEGER NOT NULL,
|
||||
staff_id INTEGER NOT NULL,
|
||||
read_at TEXT NOT NULL,
|
||||
PRIMARY KEY (note_id, staff_id)
|
||||
)
|
||||
@@ -0,0 +1,104 @@
|
||||
<?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; ?>
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"slug": "schichtuebergabe",
|
||||
"name": "Schichtübergabe",
|
||||
"version": "1.1.3",
|
||||
"description": "Am Ende der Schicht schreibt ein Mitarbeiter eine kurze Notiz, die der nächste sieht: als deutlicher Hinweis oben auf jeder Seite (schon direkt nach der Anmeldung), im Menü als „neu“-Zähler und, wenn sie wichtig ist, in der Seitenleiste jedes Tickets. Die Notiz gilt für alle oder nur für eine Abteilung, der Verfasser sieht, wer sie gelesen hat. Alte Notizen werden automatisch gelöscht (Frist nur für Administratoren einstellbar).",
|
||||
"author": "DeskHub",
|
||||
"requires": "1.0.0",
|
||||
"permissions": ["hooks.cron", "ui.menu", "ui.sidebar", "db.migrations"]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
// Schichtübergabe: Notizen für die nächste Schicht.
|
||||
require_once __DIR__ . '/lib.php';
|
||||
|
||||
plugin_add_hook('cron.run', function () {
|
||||
schicht_cleanup(get_db());
|
||||
});
|
||||
// Deutlicher Hinweis oben auf jeder Seite, solange Notizen ungelesen sind (gilt ab dem aktuellen DeskHub; sonst bleibt der Zähler im Menü)
|
||||
plugin_add_filter('staff.page.top', function ($html, array $ctx) {
|
||||
return $html . schicht_banner_html(get_db(), $ctx['staff'] ?? null, (string) ($ctx['activePage'] ?? ''));
|
||||
});
|
||||
plugin_add_filter('ticket.view.sidebar', function ($html, array $ctx) {
|
||||
return $html . schicht_sidebar_html(get_db(), $ctx['staff'] ?? null);
|
||||
});
|
||||
|
||||
// Für alle Mitarbeiter und Administratoren; der Zähler zeigt ungelesene Notizen
|
||||
plugin_register_menu(schicht_menu_label(), 'schichtuebergabe');
|
||||
Reference in New Issue
Block a user