Files
gravity/One Stop Web Service/admin/logs.php
T
2026-09-16 23:20:08 +07:00

81 lines
4.3 KiB
PHP

<?php
require_once '../init.php';
requireLogin();
$stmt = $pdo->query("SELECT * FROM activity_logs ORDER BY created_at DESC");
$logs = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ประวัติการทำงาน - <?= htmlspecialchars($globalSettings['site_name'] ?? 'ศูนย์รวมเว็บหน่วยงาน') ?></title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="../assets/css/style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Datatables -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css">
<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
</head>
<body class="antialiased min-h-screen bg-gray-50 py-10 px-4">
<div class="w-full max-w-6xl mx-auto glass-container">
<div class="flex flex-wrap justify-between items-center mb-8 border-b border-gray-200 pb-4 gap-4">
<h1 class="text-2xl font-bold text-gray-800"><i class="fa-solid fa-history mr-2"></i> ประวัติการทำงาน</h1>
<div class="flex gap-2">
<a href="index.php" class="magic-btn-outline"><i class="fa-solid fa-arrow-left mr-1"></i> กลับไปจัดการเว็บไซต์</a>
</div>
</div>
<div class="bg-white rounded-xl shadow-sm p-4 border border-gray-100 overflow-x-auto">
<table id="logsTable" class="w-full border-collapse">
<thead>
<tr class="bg-gray-50">
<th class="p-3 border-b text-center whitespace-nowrap">วัน-เวลา</th>
<th class="p-3 border-b text-center whitespace-nowrap">การกระทำ</th>
<th class="p-3 border-b text-center whitespace-nowrap">รายละเอียด</th>
<th class="p-3 border-b text-center whitespace-nowrap">IP</th>
</tr>
</thead>
<tbody>
<?php foreach($logs as $log): ?>
<tr>
<td class="p-3 border-b text-sm text-gray-600 text-center whitespace-nowrap"><?= htmlspecialchars($log['created_at']) ?></td>
<td class="p-3 border-b font-medium text-center whitespace-nowrap">
<?php
$badgeColor = 'bg-gray-100 text-gray-800';
if(strpos($log['action'], 'Add') !== false) $badgeColor = 'bg-green-100 text-green-800';
else if(strpos($log['action'], 'Edit') !== false) $badgeColor = 'bg-blue-100 text-blue-800';
else if(strpos($log['action'], 'Delete') !== false) $badgeColor = 'bg-red-100 text-red-800';
else if(strpos($log['action'], 'Login') !== false) $badgeColor = 'bg-purple-100 text-purple-800';
else if(strpos($log['action'], 'Mock') !== false) $badgeColor = 'bg-orange-100 text-orange-800';
?>
<span class="px-2 py-1 rounded text-xs <?= $badgeColor ?>"><?= htmlspecialchars($log['action']) ?></span>
</td>
<td class="p-3 border-b text-gray-700 text-center whitespace-nowrap"><?= htmlspecialchars($log['details']) ?></td>
<td class="p-3 border-b text-sm text-gray-500 text-center whitespace-nowrap"><?= htmlspecialchars($log['ip_address']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<script>
$(document).ready(function() {
$('#logsTable').DataTable({
"language": {
"url": "//cdn.datatables.net/plug-ins/1.13.6/i18n/th.json"
},
"order": [[ 0, "desc" ]]
});
});
</script>
</body>
</html>