115 lines
4.4 KiB
PHP
115 lines
4.4 KiB
PHP
<?php
|
|
session_start();
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
// If user is not logged in, redirect to login page
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
// Optional: Add role-based access control here if needed
|
|
|
|
$displayName = $_SESSION['user_display_name'] ?? 'User';
|
|
$pdo = db();
|
|
|
|
// Fetch audit events
|
|
$stmt = $pdo->query(
|
|
"SELECT ae.*, u.display_name " .
|
|
"FROM audit_events ae " .
|
|
"LEFT JOIN users u ON ae.user_id = u.user_id " .
|
|
"ORDER BY ae.created_at DESC LIMIT 200" // Limit to recent 200 events for performance
|
|
);
|
|
$events = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en" data-bs-theme="light">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Audit Log - FlexPass</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body>
|
|
|
|
<nav class="navbar navbar-expand-lg bg-body-tertiary">
|
|
<div class="container-fluid">
|
|
<a class="navbar-brand" href="dashboard.php">
|
|
<i class="bi bi-shield-lock"></i> FlexPass
|
|
</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="dashboard.php">Clients</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link active" aria-current="page" href="audit-log.php">Audit Log</a>
|
|
</li>
|
|
</ul>
|
|
<div class="d-flex">
|
|
<ul class="navbar-nav">
|
|
<li class="nav-item dropdown">
|
|
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">
|
|
<i class="bi bi-person-circle"></i> <?php echo htmlspecialchars($displayName); ?>
|
|
</a>
|
|
<ul class="dropdown-menu dropdown-menu-end">
|
|
<li><a class="dropdown-item" href="logout.php">Logout</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container mt-4">
|
|
<h1 class="mb-3">Audit Log</h1>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<table class="table table-sm table-striped">
|
|
<thead>
|
|
<tr>
|
|
<th>Timestamp</th>
|
|
<th>User</th>
|
|
<th>Action</th>
|
|
<th>Target</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($events as $event): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars(date('Y-m-d H:i:s', strtotime($event['created_at']))); ?></td>
|
|
<td><?php echo htmlspecialchars($event['display_name'] ?? 'System/Unknown'); ?></td>
|
|
<td><span class="badge bg-info text-dark"><?php echo htmlspecialchars($event['action']); ?></span></td>
|
|
<td>
|
|
<?php if ($event['target_type'] && $event['target_id']): ?>
|
|
<?php echo htmlspecialchars($event['target_type'] . ' #' . $event['target_id']); ?>
|
|
<?php else: ?>
|
|
N/A
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php if (empty($events)): ?>
|
|
<tr>
|
|
<td colspan="4" class="text-center text-muted">No audit events found.</td>
|
|
</tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="assets/js/main.js"></script>
|
|
</body>
|
|
</html>
|