34 lines
964 B
PHP
34 lines
964 B
PHP
<?php
|
|
session_start();
|
|
require_once '../includes/db.php';
|
|
require_once '../includes/api_helper.php';
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
jsonResponse(false, 'Unauthorized', [], 401);
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
jsonResponse(false, 'Invalid request method');
|
|
}
|
|
|
|
$id = $_POST['id'] ?? '';
|
|
$status = $_POST['status'] ?? '';
|
|
|
|
if (empty($id) || empty($status)) {
|
|
jsonResponse(false, 'ข้อมูลไม่ครบถ้วน');
|
|
}
|
|
|
|
try {
|
|
$stmt = $pdo->prepare("UPDATE drivers SET status = ? WHERE id = ?");
|
|
$stmt->execute([$status, $id]);
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
jsonResponse(true, 'อัปเดตสถานะสำเร็จ');
|
|
} else {
|
|
jsonResponse(false, 'ไม่พบพนักงานในระบบ หรือสถานะเหมือนเดิม');
|
|
}
|
|
} catch (PDOException $e) {
|
|
jsonResponse(false, 'Database Error: ' . $e->getMessage());
|
|
}
|
|
?>
|