$user_type_id, 'username' => $username, 'schoolID' => $schoolID ]; // ตรวจสอบการเข้าสู่ระบบ if (empty($username) || empty($schoolID)) { http_response_code(403); echo json_encode(['error' => 'ไม่มีข้อมูล session', 'debug' => $debug]); exit; } try { // ดึงข้อมูลการนัดหมายติดตาม (follow_up_date >= วันนี้) $stmt = $pdo->prepare(" SELECT ic.id as person_id, ic.first_name, ic.last_name, ics.follow_up_date, ics.id as service_id, ics.service_request_number FROM individual_counseling ic INNER JOIN individual_counseling_service ics ON ic.id = ics.individual_counseling_id WHERE ics.follow_up_date IS NOT NULL AND ics.follow_up_date >= CURDATE() AND ic.schoolID = ? AND ic.username = ? ORDER BY ics.follow_up_date ASC "); $stmt->execute([$schoolID, $username]); $alerts = $stmt->fetchAll(PDO::FETCH_ASSOC); echo json_encode([ 'success' => true, 'alerts' => $alerts, 'count' => count($alerts), 'debug' => $debug ]); } catch (PDOException $e) { http_response_code(500); echo json_encode(['error' => 'เกิดข้อผิดพลาด: ' . $e->getMessage(), 'debug' => $debug]); exit; } ?>