Initial commit

This commit is contained in:
Porawit Dongwang
2026-09-16 23:20:08 +07:00
commit 0041668dbb
32577 changed files with 3687927 additions and 0 deletions
@@ -0,0 +1,226 @@
<?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', 'หน่วยงานสุขภาพดิจิทัล โรงพยาบาลเกาะสมุย');
$log_db = getDB(DB_LOG_HOST, DB_LOG_NAME, DB_LOG_USER, DB_LOG_PASS);
?>
<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>จัดการผู้ดูแลระบบ (Admins) - <?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;
}
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; }
</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 flex justify-between items-center">
<div>
<h3 class="text-lg font-medium text-gray-900">จัดการผู้ดูแลระบบ (System Admins)</h3>
<p class="mt-1 text-sm text-gray-500">เพิ่ม/ลบ สิทธิ์ผู้ดูแลระบบด้วยเลขบัตรประชาชน (CID) หรือรหัสผู้ใช้งาน</p>
</div>
<button onclick="openModal()" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded text-sm flex items-center">
<svg class="w-4 h-4 mr-2" 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="M12 4v16m8-8H4"></path></svg>
เพิ่มผู้ดูแลระบบ
</button>
</div>
<div class="px-6 py-5 overflow-x-auto">
<table id="adminsTable" class="display w-full text-sm">
<thead>
<tr>
<th class="w-10">ID</th>
<th>เลขบัตรประชาชน (CID)</th>
<th>ชื่อ-นามสกุล</th>
<th>วันที่เพิ่ม</th>
<th class="w-24">จัดการ</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
<!-- Modal Form -->
<div id="adminModal" class="fixed inset-0 z-50 hidden overflow-y-auto" aria-labelledby="modal-title" role="dialog" aria-modal="true">
<div class="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
<div class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" aria-hidden="true"></div>
<span class="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">&#8203;</span>
<div class="inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg w-full">
<form id="adminForm">
<div class="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
<h3 class="text-lg leading-6 font-medium text-gray-900 mb-4" id="modal-title">เพิ่มผู้ดูแลระบบ</h3>
<input type="hidden" id="admin_id" name="id">
<div class="mb-4">
<label class="block text-gray-700 text-sm font-bold mb-2" for="cid">เลขบัตรประชาชน (13 หลัก)</label>
<input class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="cid" name="cid" type="text" maxlength="13" required placeholder="x-xxxx-xxxxx-xx-x">
</div>
<div class="mb-4">
<label class="block text-gray-700 text-sm font-bold mb-2" for="name">ชื่อ-นามสกุล</label>
<input class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="name" name="name" type="text" required placeholder="เช่น นพ.ทดสอบ ระบบดี">
</div>
</div>
<div class="bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse">
<button type="submit" class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-blue-600 text-base font-medium text-white hover:bg-blue-700 focus:outline-none sm:ml-3 sm:w-auto sm:text-sm">
บันทึกข้อมูล
</button>
<button type="button" onclick="closeModal()" class="mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none sm:mt-0 sm:ml-3 sm:w-auto sm:text-sm">
ยกเลิก
</button>
</div>
</form>
</div>
</div>
</div>
<?php include 'footer.php'; ?>
<!-- jQuery, DataTables, and SweetAlert2 -->
<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 src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
let table;
$(document).ready(function() {
table = $('#adminsTable').DataTable({
"language": {
"url": "//cdn.datatables.net/plug-ins/1.13.6/i18n/th.json"
},
"ajax": "api_admins.php?action=list",
"columns": [
{ "data": "id" },
{ "data": "cid" },
{ "data": "name" },
{ "data": "created_at" },
{ "data": null, "render": function(data, type, row) {
return `
<div class="flex items-center">
<button onclick="deleteAdmin(${row.id})" class="text-red-500 hover:text-red-700 hover:bg-red-50 p-1.5 rounded-md transition-colors" title="ลบสิทธิ์">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path></svg>
</button>
</div>
`;
}}
],
"order": [[ 0, "asc" ]]
});
$('#adminForm').on('submit', function(e) {
e.preventDefault();
$.ajax({
url: 'api_admins.php?action=save',
type: 'POST',
data: $(this).serialize(),
success: function(res) {
if (res.status === 'success') {
Swal.fire('สำเร็จ', res.message, 'success');
closeModal();
table.ajax.reload();
} else {
Swal.fire('ข้อผิดพลาด', res.message, 'error');
}
}
});
});
});
function openModal() {
$('#adminForm')[0].reset();
$('#admin_id').val('');
$('#modal-title').text('เพิ่มผู้ดูแลระบบ');
$('#adminModal').removeClass('hidden');
}
function closeModal() {
$('#adminModal').addClass('hidden');
}
function deleteAdmin(id) {
Swal.fire({
title: 'ยืนยันการลบสิทธิ์?',
text: "ผู้ใช้งานนี้จะไม่สามารถเข้าถึงเมนูตั้งค่าได้อีกต่อไป",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#d33',
cancelButtonColor: '#3085d6',
confirmButtonText: 'ใช่, ลบเลย!',
cancelButtonText: 'ยกเลิก'
}).then((result) => {
if (result.isConfirmed) {
$.post('api_admins.php?action=delete', { id: id }, function(res) {
if (res.status === 'success') {
Swal.fire('ลบสำเร็จ!', res.message, 'success');
table.ajax.reload();
} else {
Swal.fire('ข้อผิดพลาด', res.message, 'error');
}
});
}
});
}
</script>
</body>
</html>