Add per-column filters, smart pagination (25/page), and date range filter to audit logs
This commit is contained in:
@@ -168,19 +168,34 @@ class AdminController
|
||||
|
||||
$page = (int) ($_GET['page'] ?? 1);
|
||||
$action = $_GET['action'] ?? '';
|
||||
$userId = $_GET['user_id'] ?? '';
|
||||
$username = $_GET['username'] ?? '';
|
||||
$ipAddress = $_GET['ip_address'] ?? '';
|
||||
$entityType = $_GET['entity_type'] ?? '';
|
||||
$details = $_GET['details'] ?? '';
|
||||
$dateFrom = $_GET['date_from'] ?? '';
|
||||
$dateTo = $_GET['date_to'] ?? '';
|
||||
|
||||
$filters = [];
|
||||
if ($action) $filters['action'] = $action;
|
||||
if ($userId) $filters['user_id'] = (int) $userId;
|
||||
if ($action !== '') $filters['action'] = $action;
|
||||
if ($username !== '') $filters['username'] = $username;
|
||||
if ($ipAddress !== '') $filters['ip_address'] = $ipAddress;
|
||||
if ($entityType !== '') $filters['entity_type'] = $entityType;
|
||||
if ($details !== '') $filters['details'] = $details;
|
||||
if ($dateFrom !== '') $filters['date_from'] = $dateFrom;
|
||||
if ($dateTo !== '') $filters['date_to'] = $dateTo;
|
||||
|
||||
$logs = $this->auditService->getAuditLogs($page, 50, $filters);
|
||||
$logs = $this->auditService->getAuditLogs($page, 25, $filters);
|
||||
|
||||
$this->view->display('admin.audit', [
|
||||
'title' => 'Audit Logs - ServerManager',
|
||||
'logs' => $logs,
|
||||
'action' => $action,
|
||||
'userId' => $userId,
|
||||
'username' => $username,
|
||||
'ipAddress' => $ipAddress,
|
||||
'entityType' => $entityType,
|
||||
'details' => $details,
|
||||
'dateFrom' => $dateFrom,
|
||||
'dateTo' => $dateTo,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -157,11 +157,27 @@ class AuditService
|
||||
$params[] = $filters['user_id'];
|
||||
}
|
||||
|
||||
if (!empty($filters['username'])) {
|
||||
$where[] = '(al.username LIKE ? OR u.username LIKE ?)';
|
||||
$params[] = '%' . $filters['username'] . '%';
|
||||
$params[] = '%' . $filters['username'] . '%';
|
||||
}
|
||||
|
||||
if (!empty($filters['entity_type'])) {
|
||||
$where[] = 'al.entity_type = ?';
|
||||
$params[] = $filters['entity_type'];
|
||||
}
|
||||
|
||||
if (!empty($filters['ip_address'])) {
|
||||
$where[] = 'al.ip_address LIKE ?';
|
||||
$params[] = '%' . $filters['ip_address'] . '%';
|
||||
}
|
||||
|
||||
if (!empty($filters['details'])) {
|
||||
$where[] = 'al.details LIKE ?';
|
||||
$params[] = '%' . $filters['details'] . '%';
|
||||
}
|
||||
|
||||
if (!empty($filters['date_from'])) {
|
||||
$where[] = 'al.created_at >= ?';
|
||||
$params[] = $filters['date_from'];
|
||||
|
||||
Reference in New Issue
Block a user