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,45 @@
<?php
session_start();
require_once '../includes/db.php';
if (!isset($_SESSION['admin_logged_in'])) {
echo json_encode(['success' => false, 'message' => 'Unauthorized']);
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$cid = $_POST['cid'] ?? '';
if (empty($cid)) {
echo json_encode(['success' => false, 'message' => 'ไม่พบข้อมูล CID']);
exit;
}
if (!$conn_hosoffice) {
echo json_encode(['success' => false, 'message' => 'ไม่สามารถเชื่อมต่อฐานข้อมูล HR (hosoffice) ได้']);
exit;
}
$cid_safe = mysqli_real_escape_string($conn_hosoffice, $cid);
$query = "SELECT HR_STATUS_ID FROM hr_person WHERE HR_CID = '$cid_safe' LIMIT 1";
$result = mysqli_query($conn_hosoffice, $query);
if ($result && mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
$hr_status = $row['HR_STATUS_ID'];
$new_status = ($hr_status === '01') ? 'Y' : 'N';
// Update line_staff_register
$stmt = $pdo_bot->prepare("UPDATE line_staff_register SET ksh_user = ? WHERE cid = ?");
$stmt->execute([$new_status, $cid]);
echo json_encode(['success' => true, 'new_status' => $new_status, 'message' => 'อัปเดตสถานะเรียบร้อย']);
} else {
// Not found in hr_person
$stmt = $pdo_bot->prepare("UPDATE line_staff_register SET ksh_user = 'N' WHERE cid = ?");
$stmt->execute([$cid]);
echo json_encode(['success' => true, 'new_status' => 'N', 'message' => 'ไม่พบ CID นี้ในระบบ HR (อัปเดตเป็นพ้นสภาพ)']);
}
}