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,48 @@
<?php
session_start();
require_once '../includes/db.php';
require_once '../includes/api_helper.php';
require_once '../includes/logger.php';
require_once '../includes/notifier.php';
if (!isset($_SESSION['user_id'])) {
jsonResponse(false, 'Unauthorized', [], 401);
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
jsonResponse(false, 'Invalid request method');
}
$id = $_POST['id'] ?? '';
if (empty($id)) {
jsonResponse(false, 'ไม่พบข้อมูลที่ต้องการลบ');
}
try {
// ตรวจสอบว่ามีการจองผูกอยู่หรือไม่
$stmt = $pdo->prepare("SELECT id FROM schedules WHERE driver_id = ? LIMIT 1");
$stmt->execute([$id]);
if ($stmt->fetch()) {
jsonResponse(false, 'ไม่สามารถลบได้ เนื่องจากพนักงานขับรถคนนี้มีคิวการจองอยู่ในระบบ');
}
$stmt = $pdo->prepare("SELECT first_name, last_name FROM drivers WHERE id = ?");
$stmt->execute([$id]);
$driverInfo = $stmt->fetch();
$driverName = $driverInfo ? trim($driverInfo['first_name'] . ' ' . $driverInfo['last_name']) : $id;
$stmt = $pdo->prepare("DELETE FROM drivers WHERE id = ?");
$stmt->execute([$id]);
if ($stmt->rowCount() > 0) {
logActivity("Delete Driver ({$driverName})", 'drivers', $id);
notifyEvent('driver', "👤 แจ้งเตือนพนักงานขับรถ\nลบข้อมูลพนักงานออกจากระบบ: {$driverName}");
jsonResponse(true, 'ลบข้อมูลสำเร็จ');
} else {
jsonResponse(false, 'ไม่พบข้อมูลในฐานข้อมูล');
}
} catch (PDOException $e) {
jsonResponse(false, 'Database Error: ' . $e->getMessage());
}
?>