Upload via GUI (278 Dateien)

This commit is contained in:
2026-10-21 16:44:46 +00:00
parent 738b54048f
commit a94a36444c
6 changed files with 730 additions and 11 deletions
+66 -11
View File
@@ -25,17 +25,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['status']) && !isset($
exit;
}
$drv = $pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
$availabilitySql = $drv === 'sqlite'
? 'INSERT INTO staff_availability (staff_id, status, note, updated_at) VALUES (?,?,?,?)
ON CONFLICT(staff_id) DO UPDATE SET
status=excluded.status, note=excluded.note, updated_at=excluded.updated_at'
: 'INSERT INTO staff_availability (staff_id, status, note, updated_at) VALUES (?,?,?,?)
ON DUPLICATE KEY UPDATE
status=VALUES(status), note=VALUES(note), updated_at=VALUES(updated_at)';
try {
$pdo->prepare($availabilitySql)->execute([$staff['id'], $newStatus, $note ?: null, db_now()]);
staff_set_status($pdo, (int) $staff['id'], $newStatus, $note);
staff_touch_activity($pdo, (int) $staff['id']);
echo json_encode(['ok' => true, 'status' => $newStatus]);
} catch (Throwable $e) {
error_log('staff_availability: ' . $e->getMessage());
@@ -52,6 +44,31 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
verify_csrf();
$action = $_POST['action'] ?? '';
// Admin: Status eines Mitarbeiters ändern
if ($action === 'set_staff_status' && $admin) {
$targetId = (int) ($_POST['staff_id'] ?? 0);
$newStatus = (string) ($_POST['status'] ?? '');
$exists = $pdo->prepare('SELECT name FROM staff WHERE id = ? AND is_active = 1');
$exists->execute([$targetId]);
$targetName = $exists->fetchColumn();
if (!$targetName || !in_array($newStatus, STAFF_AVAILABILITY_STATUSES, true)) {
flash('error', 'Ungültiger Mitarbeiter oder Status.');
} else {
staff_set_status($pdo, $targetId, $newStatus, (string) ($_POST['note'] ?? ''));
audit_log($admin['id'], "Status von Mitarbeiter #$targetId auf $newStatus gesetzt");
flash('success', 'Status von ' . $targetName . ' geändert.');
}
redirect('/staff/availability.php');
}
// Admin: Zeit bis zum automatischen Offline einstellen
if ($action === 'save_auto_offline' && $admin) {
$m = max(0, min(1440, (int) ($_POST['auto_offline_minutes'] ?? 30)));
set_setting('staff_auto_offline_minutes', (string) $m);
audit_log($admin['id'], 'Automatisch offline nach ' . ($m > 0 ? $m . ' Minuten' : 'aus') . ' gesetzt');
flash('success', $m > 0 ? "Mitarbeiter werden nach $m Minuten ohne Aktivität automatisch auf Offline gesetzt." : 'Automatisch offline ist ausgeschaltet.');
redirect('/staff/availability.php');
}
if ($action === 'save_shifts' && $admin) {
$targetId = (int)($_POST['staff_id'] ?? 0);
$__nameStmt = $pdo->prepare('SELECT name FROM staff WHERE id = ?');
@@ -81,8 +98,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
// ── Daten laden ───────────────────────────────────────────────────────────────
staff_run_auto_offline($pdo);
$agents = $pdo->query(
"SELECT s.*, sa.status AS avail_status, sa.note AS avail_note, sa.updated_at AS avail_updated
"SELECT s.*, sa.status AS avail_status, sa.auto_offline AS avail_auto, sa.note AS avail_note, sa.updated_at AS avail_updated
FROM staff s
LEFT JOIN staff_availability sa ON sa.staff_id = s.id
WHERE s.is_active = 1
@@ -174,11 +192,48 @@ $myStatus = $myAvail['avail_status'] ?? 'available';
<a href="?edit=<?= $ag['id'] ?>" title="Schichtplan bearbeiten"
style="color:var(--muted);font-size:.78rem;text-decoration:none;flex-shrink:0">⚙️</a>
<?php endif; ?>
<?php $__la = staff_last_active_label($ag['last_active_at'] ?? null); ?>
<?php if ($__la !== '' || !empty($ag['avail_auto'])): ?><div style="font-size:.68rem;color:var(--muted);flex-shrink:0;text-align:right"><?= !empty($ag['avail_auto']) ? 'automatisch<br>offline' : '' ?><?= $__la !== '' && empty($ag['avail_auto']) ? 'aktiv ' . e($__la) : '' ?></div><?php endif; ?>
</div>
<?php endforeach; ?>
</div>
</div>
<?php if ($admin): ?>
<!-- ── Admin: Status der Mitarbeiter ändern + Auto-Offline ───────────────────── -->
<div class="card" style="margin-bottom:20px">
<div style="font-size:.72rem;font-weight:700;text-transform:uppercase;letter-spacing:.06em;color:var(--muted);margin-bottom:6px">Status der Mitarbeiter ändern (Admin)</div>
<p class="muted" style="font-size:.8rem;margin-bottom:12px">Ein von dir gesetzter Status bleibt, bis der Mitarbeiter ihn selbst ändert oder du ihn erneut änderst.</p>
<table style="width:100%;border-collapse:collapse;font-size:.85rem">
<?php foreach ($agents as $ag): ?>
<tr style="border-top:1px solid var(--border)">
<td style="padding:6px 8px"><?= e($ag['name']) ?></td>
<td style="padding:6px 8px">
<form method="post" style="display:flex;gap:6px;flex-wrap:wrap;align-items:center">
<?= csrf_field() ?>
<input type="hidden" name="action" value="set_staff_status">
<input type="hidden" name="staff_id" value="<?= (int) $ag['id'] ?>">
<select name="status" style="width:auto">
<?php foreach ($statusLabels as $sk => [$sl]): ?><option value="<?= $sk ?>" <?= ($ag['avail_status'] ?? 'offline') === $sk ? 'selected' : '' ?>><?= $sl ?></option><?php endforeach; ?>
</select>
<input type="text" name="note" value="<?= e($ag['avail_note'] ?? '') ?>" placeholder="Notiz (optional)" maxlength="120" style="width:180px">
<button type="submit" class="btn secondary">Setzen</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</table>
<form method="post" style="margin-top:14px;display:flex;gap:8px;align-items:center;flex-wrap:wrap">
<?= csrf_field() ?>
<input type="hidden" name="action" value="save_auto_offline">
<label style="margin:0;font-weight:500">Automatisch offline nach</label>
<input type="number" name="auto_offline_minutes" min="0" max="1440" value="<?= (int) staff_auto_offline_minutes() ?>" style="width:90px"> Minuten ohne Aktivität
<button type="submit" class="btn secondary">Speichern</button>
<span class="muted" style="font-size:.78rem">0 = aus. Bei neuer Aktivität kommt der vorherige Status zurück.</span>
</form>
</div>
<?php endif; ?>
<!-- ── Schichtplan-Editor (Admin) ─────────────────────────────────────────────── -->
<?php if ($admin && $editStaffId): ?>
<?php