Files
2026-09-16 23:20:08 +07:00

98 lines
4.5 KiB
PHP

<?php
session_start();
if (empty($_SESSION['sess_userid']) || $_SESSION['sess_userid'] !== session_id()) {
header("Location: index.php");
exit();
}
$account = $_SESSION['account'];
$name = $_SESSION['name'];
$position = $_SESSION['position'];
$ip = $_SESSION['ip'];
$page_link = "search_name.php";
// Only itcenter can access
$chk1 = preg_match('/itcenter/', $account);
if (!$chk1) {
echo "<center><font color='red'>ไม่มีสิทธิ์เข้าถึงหน้านี้</font></center>";
exit();
}
require_once("config/db.php");
?>
<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>HOSxP Web Service | ค้นหาจาก ชื่อ-สกุล</title>
<link href="https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/style.css" type="text/css" />
<style>
.search-table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.search-table th, .search-table td { border: 1px solid var(--border); padding: 0.75rem; text-align: center; }
.search-table th { background-color: rgba(37, 99, 235, 0.05); color: var(--text-main); font-weight: 600; }
.search-table tr:hover { background-color: rgba(0,0,0,0.02); }
</style>
</head>
<body>
<div class="app-container">
<?php require_once("includes/sidebar.php"); ?>
<main class="main-content">
<?php require_once("includes/header.php"); ?>
<div class="content-wrapper animate-fade-in">
<div class="card">
<div class="card-title">ค้นหาข้อมูลผู้รับบริการ จาก ชื่อ หรือ นามสกุล</div>
<form id="searchForm" style="display:flex; gap:1rem; margin-bottom: 2rem; align-items:center;">
<input type="text" id="fname" class="form-control" placeholder="ชื่อ" style="max-width: 200px;">
<input type="text" id="lname" class="form-control" placeholder="นามสกุล" style="max-width: 200px;">
<button type="submit" class="btn btn-primary">
<svg style="width:16px;height:16px;display:inline;vertical-align:middle;margin-right:0.25rem;" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path></svg>
ค้นหาข้อมูล
</button>
</form>
<h3 style="font-size:1.1rem; margin-bottom:0.5rem; color:var(--text-main);">ผลการค้นหา (จำกัด 5 รายการ)</h3>
<div style="overflow-x:auto;">
<table class="search-table">
<thead>
<tr>
<th>ลำดับที่</th>
<th>HN</th>
<th>ชื่อ - สกุล</th>
<th>เลขบัตรประชาชน</th>
<th>ดูข้อมูล</th>
</tr>
</thead>
<tbody id="resultTableBody">
<tr><td colspan="5" style="color:var(--text-muted); padding:2rem;">กรุณากรอก ชื่อ หรือ นามสกุล และกดค้นหา</td></tr>
</tbody>
</table>
</div>
</div>
</div>
</main>
</div>
<script>
document.getElementById('searchForm').addEventListener('submit', function(e) {
e.preventDefault();
const fname = document.getElementById('fname').value;
const lname = document.getElementById('lname').value;
const tbody = document.getElementById('resultTableBody');
tbody.innerHTML = '<tr><td colspan="5">กำลังค้นหา...</td></tr>';
fetch('search_name2.php?fname=' + encodeURIComponent(fname) + '&lname=' + encodeURIComponent(lname))
.then(response => response.text())
.then(html => {
tbody.innerHTML = html;
})
.catch(err => {
tbody.innerHTML = '<tr><td colspan="5" class="text-danger">เกิดข้อผิดพลาดในการค้นหา</td></tr>';
});
});
</script>
</body>
</html>