diff --git a/admin/audit_log.php b/admin/audit_log.php new file mode 100644 index 0000000..2617589 --- /dev/null +++ b/admin/audit_log.php @@ -0,0 +1,226 @@ +requireAdmin(); +I18n::init(); + +$db = Database::getInstance(); +$appTitle = $db->getSetting('app_title', 'UniFi Voucher System'); + +$filterAction = trim($_GET['action'] ?? ''); +$filterUser = trim($_GET['user_id'] ?? ''); +$page = max(1, (int)($_GET['page'] ?? 1)); +$perPage = 50; +$offset = ($page - 1) * $perPage; + +$where = []; +$params = []; +if ($filterAction !== '') { $where[] = 'a.action = ?'; $params[] = $filterAction; } +if ($filterUser !== '') { $where[] = 'a.user_id = ?'; $params[] = (int)$filterUser; } +$whereStr = $where ? 'WHERE ' . implode(' AND ', $where) : ''; + +$total = (int)$db->fetchOne("SELECT COUNT(*) as c FROM audit_log a $whereStr", $params)['c']; +$pages = max(1, (int)ceil($total / $perPage)); +$logs = $db->fetchAll( + "SELECT a.*, u.name as user_name, u.email as user_email + FROM audit_log a LEFT JOIN users u ON a.user_id = u.id + $whereStr ORDER BY a.created_at DESC LIMIT ? OFFSET ?", + array_merge($params, [$perPage, $offset]) +); + +// Distinct actions for filter +$actions = $db->fetchAll("SELECT DISTINCT action FROM audit_log ORDER BY action"); + +// User list for filter +$users = $db->fetchAll("SELECT id, name FROM users WHERE is_active = 1 ORDER BY name"); + +$currentPage = 'audit_log'; +$adminBase = ''; + +$actionLabels = [ + 'voucher_created' => '🎫 Voucher erstellt', + 'voucher_bulk' => '🎫 Bulk Voucher', + 'user_login' => '🔐 Login', + 'user_logout' => '🚪 Logout', + 'user_created' => '👤 Benutzer erstellt', + 'user_updated' => '👤 Benutzer geändert', + 'user_deleted' => '👤 Benutzer gelöscht', + 'site_added' => '🌐 Site hinzugefügt', + 'site_updated' => '🌐 Site geändert', + 'site_deleted' => '🌐 Site gelöscht', + 'settings_saved' => '⚙️ Einstellungen gespeichert', + 'password_reset' => '🔑 Passwort-Reset', + 'template_created' => '📋 Profil erstellt', + 'template_updated' => '📋 Profil geändert', + 'template_deleted' => '📋 Profil gelöscht', +]; +?> + + +
+ + += __('audit_subtitle') ?>
+= __('audit_none') ?>
| = __('audit_time') ?> | += __('audit_action') ?> | += __('audit_user') ?> | += __('audit_entity') ?> | += __('audit_details') ?> | += __('audit_ip') ?> | +
|---|---|---|---|---|---|
|
+ = date('d.m.Y', strtotime($log['created_at'])) ?> + = date('H:i:s', strtotime($log['created_at'])) ?> + |
+ + + = htmlspecialchars($actionLabels[$log['action']] ?? $log['action']) ?> + + | +
+
+ = htmlspecialchars($log['user_name']) ?> + = htmlspecialchars($log['user_email'] ?? '') ?> + + System/Anonym + + |
+
+
+ = htmlspecialchars($log['entity_type']) ?>:= htmlspecialchars($log['entity_id'] ?? '') ?>
+
+ -
+
+ |
+ + = htmlspecialchars(mb_strimwidth($log['details'] ?? '-', 0, 80, '…')) ?> + | += htmlspecialchars($log['ip_address'] ?? '-') ?> | +