prepare('SELECT slug FROM tenants WHERE id = ?'); $stmt->execute([$tenantId]); $slug = $stmt->fetchColumn(); if ($slug === false) { http_response_code(404); exit('Mandant wurde nicht gefunden.'); } $data = app_export_tenant_data($pdo, $tenantId); app_audit_log($pdo, $tenantId, (int)$user['user_id'], 'backoffice.tenant_exported', 'tenant', $tenantId); $json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); $filename = 'backoffice-export-' . $slug . '-' . date('Ymd_His') . '.json'; header('Content-Type: application/json; charset=UTF-8'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Content-Length: ' . strlen((string)$json)); echo $json;