38394-vm/admin/audit_logs.php
2026-02-13 10:15:56 +00:00

83 lines
3.3 KiB
PHP

<?php
require_once 'auth.php';
require_once '../db/config.php';
require_login();
$user = get_user();
$pdo = db();
// Fetch audit logs with user info
$logs = $pdo->query("
SELECT l.*, u.email as user_email
FROM audit_logs l
LEFT JOIN users u ON l.user_id = u.id
ORDER BY l.created_at DESC
LIMIT 100
")->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Audit Logs - <?= htmlspecialchars(get_org_name()) ?> Admin</title>
<?php if ($favicon = get_favicon_url()): ?>
<link rel="icon" type="image/x-icon" href="../<?= htmlspecialchars($favicon) ?>">
<?php endif; ?>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
<style>
:root { --sidebar-width: 260px; --primary-color: #059669; }
body { background-color: #f3f4f6; }
.sidebar { width: var(--sidebar-width); height: 100vh; position: fixed; left: 0; top: 0; background: #111827; color: #fff; padding: 1.5rem; }
.main-content { margin-left: var(--sidebar-width); padding: 2rem; }
.nav-link { color: #9ca3af; margin-bottom: 0.5rem; border-radius: 8px; }
.nav-link:hover, .nav-link.active { color: #fff; background: #1f2937; }
.nav-link.active { background: var(--primary-color); }
.card { border: none; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
</style>
</head>
<body>
<?php include "sidebar.php"; ?>
<div class="main-content">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="mb-0">Activity Audit Logs</h2>
</div>
<div class="card p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead class="table-light">
<tr>
<th class="ps-4">User</th>
<th>Action</th>
<th>Details</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php foreach ($logs as $log): ?>
<tr>
<td class="ps-4">
<strong><?= htmlspecialchars($log['user_email'] ?? 'System/Unknown') ?></strong>
</td>
<td>
<span class="badge bg-secondary rounded-pill"><?= htmlspecialchars($log['action']) ?></span>
</td>
<td><?= htmlspecialchars($log['details']) ?></td>
<td><?= date('Y-m-d H:i:s', strtotime($log['created_at'])) ?></td>
</tr>
<?php endforeach; ?>
<?php if (empty($logs)): ?>
<tr>
<td colspan="4" class="text-center py-4 text-muted">No logs found.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>