prepare('INSERT INTO saved_reports (staff_id, name, config, is_shared, created_at, updated_at) VALUES (?,?,?,?,?,?)') ->execute([$staff['id'], mb_substr($name, 0, 120), json_encode($cfg, JSON_UNESCAPED_UNICODE), !empty($_POST['shared']) ? 1 : 0, $now, $now]); flash('success', 'Bericht gespeichert.'); } redirect('/staff/report_builder.php?' . ltrim((string) ($_POST['return_query'] ?? ''), '?')); } if ($action === 'delete') { $row = $pdo->prepare('SELECT * FROM saved_reports WHERE id = ?'); $row->execute([(int) $_POST['id']]); if (($r = $row->fetch()) && ((int) $r['staff_id'] === (int) $staff['id'] || $staff['role'] === 'admin')) { $pdo->prepare('DELETE FROM saved_reports WHERE id = ?')->execute([$r['id']]); flash('success', 'Bericht gelöscht.'); } redirect('/staff/report_builder.php'); } } // ── Konfiguration: aus gespeichertem Bericht oder aus der URL ─────────────── $saved = $pdo->prepare('SELECT r.*, s.name AS owner FROM saved_reports r LEFT JOIN staff s ON s.id = r.staff_id WHERE r.staff_id = ? OR r.is_shared = 1 ORDER BY r.name'); $saved->execute([$staff['id']]); $savedReports = $saved->fetchAll(); $cfgIn = $_GET; if (isset($_GET['saved'])) { foreach ($savedReports as $sr) { if ((int) $sr['id'] === (int) $_GET['saved']) { $cfgIn = json_decode($sr['config'], true) ?: []; break; } } } $cfg = report_clean_config($pdo, $cfgIn); $report = report_run($pdo, $cfg, $scope); $queryOf = fn(array $c) => http_build_query([ 'dimension' => $c['dimension'], 'from' => $c['from'], 'to' => $c['to'], 'sort' => $c['sort'], 'desc' => $c['desc'] ? 1 : 0, 'metrics' => $c['metrics'], 'filters' => $c['filters'], ]); if (($_GET['export'] ?? '') === 'csv') { header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename="bericht-' . $cfg['dimension'] . '-' . $cfg['from'] . '_' . $cfg['to'] . '.csv"'); echo report_to_csv($report); exit; } $departments = $pdo->query('SELECT id, name FROM departments ORDER BY name')->fetchAll(); $priorities = $pdo->query('SELECT id, name FROM priorities ORDER BY sort_order')->fetchAll(); $agents = $pdo->query('SELECT id, name FROM staff WHERE is_active = 1 ORDER BY name')->fetchAll(); $topics = help_topic_options($pdo, false, false); $fmtValue = function ($v, string $unit) { if ($v === null) return '–'; return ($unit === '%' || $unit === 'Std' ? number_format((float) $v, 1, ',', '.') : (string) $v) . ($unit === '%' ? ' %' : ($unit === 'Std' ? ' Std' : '')); }; $maxByMetric = []; foreach (array_slice($report['columns'], 1) as $c) $maxByMetric[$c['key']] = max(1, ...array_map(fn($r) => (float) ($r[$c['key']] ?? 0), $report['rows'] ?: [[$c['key'] => 0]])); $pageTitle = 'Bericht-Baukasten'; $activePage = 'report_builder'; require __DIR__ . '/_header.php'; ?>

Bericht-Baukasten

Standard-Berichte CSV exportieren

Wähle Gruppierung, Kennzahlen, Zeitraum und Filter – nach dem Erstellungsdatum der Tickets. Berichte lassen sich speichern und mit allen teilen.

Gespeichert
$m): ?>
Keine Tickets im gewählten Zeitraum.
Gesamt Ø' : '' ?>
Diesen Bericht speichern