Files
gravity/ส่งออกข้อมูลประชากร HOSxP/system_logs.php
T
2026-09-16 23:20:08 +07:00

151 lines
8.4 KiB
PHP

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once __DIR__ . '/config.php';
checkAdmin();
$topbar_text = getSystemSetting('topbar_text', 'ระบบตรวจสอบข้อมูล HOSxP');
$footer_text = getSystemSetting('footer_text', 'หน่วยงานสุขภาพดิจิทัล โรงพยาบาลเกาะสมุย');
?>
<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ประวัติการใช้งานระบบ (System Logs) - <?php echo htmlspecialchars($topbar_text); ?></title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css">
<link rel="icon" href="assets/img/logo.png" type="image/png">
<style>
body { font-family: 'Sarabun', sans-serif; }
/* Custom DataTables Styling */
.dataTables_wrapper { padding: 1rem 0; }
.dataTables_wrapper .dataTables_filter input {
border: 1px solid #d1d5db; border-radius: 0.5rem; padding: 0.35rem 0.75rem; margin-left: 0.5rem; outline: none; transition: all 0.2s;
}
.dataTables_wrapper .dataTables_filter input:focus {
border-color: #10b981; box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}
.dataTables_wrapper .dataTables_length select {
border: 1px solid #d1d5db; border-radius: 0.5rem; padding: 0.25rem 1.5rem 0.25rem 0.75rem; margin: 0 0.5rem; outline: none;
}
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_length {
margin-bottom: 1rem;
}
table.dataTable.no-footer { border-bottom: 1px solid #e5e7eb; margin-top: 1rem !important; margin-bottom: 1rem !important; }
table.dataTable thead th {
border-bottom: 2px solid #e5e7eb; background-color: #f3f4f6; color: #374151; font-weight: 600; padding: 0.75rem 1rem; white-space: nowrap; text-align: center;
}
table.dataTable tbody td {
border-bottom: 1px solid #f3f4f6; padding: 1rem; color: #4b5563; vertical-align: top;
}
table.dataTable tbody tr:hover { background-color: #f9fafb; }
.dataTables_wrapper .dataTables_paginate .paginate_button {
padding: 0.35rem 0.85rem; margin-left: 0.25rem; border: 1px solid #d1d5db; border-radius: 0.5rem; background: white; color: #374151 !important; transition: all 0.2s; font-size: 0.875rem;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
background: #10b981 !important; color: white !important; border-color: #10b981; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}
.dataTables_wrapper .dataTables_paginate .paginate_button:not(.current):hover {
background: #f3f4f6 !important; border-color: #d1d5db; color: #111827 !important;
}
.dataTables_wrapper .dataTables_info { color: #6b7280; font-size: 0.875rem; padding-top: 0.85rem; }
/* Action Type Badges */
.badge { padding: 0.25rem 0.6rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 600; display: inline-block; }
.badge-login { background-color: #dcfce7; color: #166534; }
.badge-logout { background-color: #f3f4f6; color: #4b5563; }
.badge-create { background-color: #dbeafe; color: #1e40af; }
.badge-edit { background-color: #fef08a; color: #854d0e; }
.badge-delete { background-color: #fee2e2; color: #991b1b; }
.badge-export { background-color: #f3e8ff; color: #6b21a8; }
.badge-default { background-color: #e5e7eb; color: #374151; }
</style>
</head>
<body class="bg-gray-100 flex flex-col min-h-screen">
<?php include 'topbar.php'; ?>
<div class="max-w-7xl mx-auto py-8 px-4 sm:px-6 lg:px-8">
<div class="mb-4">
<a href="settings.php" class="text-blue-600 hover:text-blue-800 text-sm font-medium flex items-center">
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"></path></svg>
กลับไปหน้าตั้งค่าระบบ
</a>
</div>
<div class="bg-white shadow rounded-lg mb-8">
<div class="px-6 py-5 border-b border-gray-200">
<h3 class="text-lg font-medium text-gray-900">ประวัติการใช้งานระบบ (System Logs)</h3>
<p class="mt-1 text-sm text-gray-500">บันทึกการกระทำต่างๆ ในระบบ เช่น การเข้าสู่ระบบ, การตั้งค่า และการ Export ข้อมูล</p>
</div>
<div class="px-6 py-5 overflow-x-auto">
<table id="logsTable" class="display w-full text-sm">
<thead>
<tr>
<th class="w-10">ลำดับ</th>
<th>ประเภทรายการ</th>
<th>ผู้ใช้งาน</th>
<th>รายละเอียด</th>
<th>IP Address</th>
<th>วันเวลา</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
<?php include 'footer.php'; ?>
<!-- jQuery and DataTables -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function() {
$('#logsTable').DataTable({
"language": {
"url": "//cdn.datatables.net/plug-ins/1.13.6/i18n/th.json"
},
"ajax": "api_system_logs.php?action=list",
"columns": [
{ "data": null, "orderable": false, "searchable": false, "className": "text-center align-middle", "render": function(data, type, row, meta) {
return meta.row + 1;
}},
{ "data": "action_type", "className": "text-center align-middle", "render": function(data) {
let badgeClass = 'badge-default';
if (data === 'LOGIN') badgeClass = 'badge-login';
else if (data === 'LOGOUT') badgeClass = 'badge-logout';
else if (data.includes('CREATE') || data.includes('ADD')) badgeClass = 'badge-create';
else if (data.includes('EDIT')) badgeClass = 'badge-edit';
else if (data.includes('DELETE') || data.includes('REMOVE')) badgeClass = 'badge-delete';
else if (data === 'EXPORT_DATA') badgeClass = 'badge-export';
return `<span class="badge ${badgeClass}">${data}</span>`;
}},
{ "data": null, "className": "text-center align-middle", "render": function(data, type, row) {
if (!row.user_name) return '<div class="text-gray-400">-</div>';
return `<div>${row.user_name}</div><div class="text-xs text-gray-500">${row.user_cid || ''}</div>`;
}},
{ "data": "details", "className": "align-middle", "render": function(data) {
return data ? data : '<span class="text-gray-400">-</span>';
}},
{ "data": "ip_address", "className": "text-center align-middle", "render": function(data) {
return data ? data : '<span class="text-gray-400">-</span>';
}},
{ "data": "created_at", "className": "text-center align-middle" }
],
"order": [[ 0, "desc" ]] // เรียงล่าสุดขึ้นก่อน
});
});
</script>
</body>
</html>