= $from; }); } if ($filterDateTo) { $to = strtotime($filterDateTo . ' 23:59:59'); $entries = array_filter($entries, function($e) use ($to) { return strtotime($e['timestamp'] ?? '0') <= $to; }); } if ($search) { $entries = array_filter($entries, function($e) use ($search) { $haystack = strtolower(json_encode($e)); return stripos($haystack, strtolower($search)) !== false; }); } $entries = array_values($entries); $total = count($entries); $totalPages = ceil($total / $limit); $offset = ($page - 1) * $limit; $pagedEntries = array_slice($entries, $offset, $limit); // Build stats for charts $actionCounts = []; $userCounts = []; $dailyCounts = []; foreach ($entries as $e) { $a = $e['action'] ?? 'unknown'; $actionCounts[$a] = ($actionCounts[$a] ?? 0) + 1; $u = ucfirst(explode('@', $e['user'] ?? 'unknown')[0]); $userCounts[$u] = ($userCounts[$u] ?? 0) + 1; $day = date('Y-m-d', strtotime($e['timestamp'] ?? 'now')); $dailyCounts[$day] = ($dailyCounts[$day] ?? 0) + 1; } ksort($dailyCounts); echo json_encode([ 'success' => true, 'entries' => $pagedEntries, 'total' => $total, 'page' => $page, 'total_pages' => $totalPages, 'stats' => [ 'action_counts' => $actionCounts, 'user_counts' => $userCounts, 'daily_counts' => $dailyCounts ] ]); break; default: echo json_encode(['success' => false, 'error' => 'Invalid action']); } } catch (Exception $e) { echo json_encode(['success' => false, 'error' => $e->getMessage()]); } exit; } // Load summary data for initial page render $totalEntries = 0; $recentEntries = []; $actionTypes = []; if (file_exists(AUDIT_LOG_FILE)) { $allEntries = json_decode(file_get_contents(AUDIT_LOG_FILE), true) ?: []; $totalEntries = count($allEntries); usort($allEntries, function($a, $b) { return strcmp($b['timestamp'] ?? '', $a['timestamp'] ?? ''); }); $recentEntries = array_slice($allEntries, 0, 50); foreach ($allEntries as $e) { $a = $e['action'] ?? 'unknown'; $actionTypes[$a] = ($actionTypes[$a] ?? 0) + 1; } } ?>
| Timestamp | User | Action | Target | Details | IP |
|---|---|---|---|---|---|
No audit events yetActions performed in the Space Manager will appear here. | |||||