SetDrawColor(0, 0, 0); // สีดำ $pdf->SetLineWidth(0.3); $pdf->Rect($x, $y, 4, 4); // วาดกรอบ 4x4 mm // วาดเครื่องหมายถูกถ้าเลือก if ($isChecked) { $pdf->SetLineWidth(0.5); // วาดเครื่องหมายถูก (checkmark) ด้วยเส้น $pdf->Line($x + 0.8, $y + 2, $x + 1.8, $y + 2.8); // เส้นแรก $pdf->Line($x + 1.8, $y + 2.8, $x + 3.2, $y + 1.2); // เส้นสอง } } // ฟังก์ชันแปลงวันที่เป็นภาษาไทย function thai_date($date) { if (empty($date) || $date == '0000-00-00') return ''; $thai_month_arr = array( "01" => "มกราคม", "02" => "กุมภาพันธ์", "03" => "มีนาคม", "04" => "เมษายน", "05" => "พฤษภาคม", "06" => "มิถุนายน", "07" => "กรกฎาคม", "08" => "สิงหาคม", "09" => "กันยายน", "10" => "ตุลาคม", "11" => "พฤศจิกายน", "12" => "ธันวาคม" ); $year = date("Y", strtotime($date)) + 543; $month = $thai_month_arr[date("m", strtotime($date))]; $day = date("d", strtotime($date)); return "$day $month $year"; } // ดึงข้อมูลหลัก (เอาเงื่อนไข username และ schoolID ออกเพื่อทดสอบ) try { $stmt = $pdo->prepare("SELECT * FROM group_guidance WHERE id = ?"); $stmt->execute(array($report_id)); $editData = $stmt->fetch(PDO::FETCH_ASSOC); if (!$editData) { die('ไม่พบข้อมูลรายงาน ID: ' . $report_id); } } catch (PDOException $e) { die('เกิดข้อผิดพลาดในการดึงข้อมูล: ' . $e->getMessage()); } // ดึงข้อมูลประเภทต่างๆ (PHP 5.3 compatible) try { $stmt = $pdo->prepare("SELECT id, title FROM typeActivity WHERE status = 1 ORDER BY id"); $stmt->execute(); $participantTypes = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { $participantTypes = array(); } try { $stmt = $pdo->prepare("SELECT id, title FROM typeGuidance WHERE status = 1 ORDER BY id"); $stmt->execute(); $guidanceTypes = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { $guidanceTypes = array(); } // ดึงข้อมูล objectives try { $sql = "SELECT id, title FROM typeObjectives WHERE status = 1 ORDER BY id"; $stmt = $pdo->prepare($sql); $stmt->execute(); $objectives = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { $objectives = array(); } // สร้างเอกสาร PDF $pdf = new FPDF('P', 'mm', 'A4'); $pdf->SetMargins(20, 20, 20); // เพิ่มฟอนต์ไทย (เหมือนใน school_view_library_pdf.php) $pdf->AddFont('THSarabunNew', 'b', 'THSarabunNew Bold.php'); $pdf->AddFont('THSarabunNew', '', 'THSarabunNew.php'); $pdf->AddFont('THSarabunNew', 'i', 'THSarabunNew Italic.php'); $pdf->AddFont('THSarabunNew', 'bi', 'THSarabunNew BoldItalic.php'); $pdf->AddPage(); // หัวเรื่อง $pdf->SetFont('THSarabunNew', 'b', 18); $pdf->Cell(0, 10, thai_text('แบบบันทึกข้อมูลการให้บริการแนะแนวและให้คำปรึกษา สกร.'), 0, 1, 'C'); $pdf->SetFont('THSarabunNew', 'B', 16); $pdf->Cell(0, 8, thai_text('แบบที่ 1 บริการแนะแนวแบบรายกลุ่ม'), 0, 1, 'C'); $pdf->Ln(5); // ตอนที่ 1 ข้อมูลทั่วไป $pdf->SetFont('THSarabunNew', 'B', 16); $pdf->Cell(0, 8, thai_text( 'ตอนที่ 1 ข้อมูลทั่วไป'), 0, 1, 'L'); $pdf->Ln(2); $pdf->SetFont('THSarabunNew', '', 14); // 1.1 วันที่จัดกิจกรรม $service_date = thai_date(isset($editData['service_date']) ? $editData['service_date'] : ''); $pdf->Cell(0, 8, thai_text( '1.1 วันที่จัดกิจกรรม: ' . $service_date), 0, 1, 'L'); // 1.2 สถานที่ที่จัด $service_location = isset($editData['service_location']) ? $editData['service_location'] : ''; $pdf->Cell(0, 8, thai_text( '1.2 สถานที่ที่จัด: ' . $service_location), 0, 1, 'L'); // 1.3 จำนวนผู้เข้าร่วม $participant_count = isset($editData['participant_count']) ? $editData['participant_count'] : ''; $pdf->Cell(0, 8, thai_text( '1.3 จำนวนผู้เข้าร่วม (คน): ' . $participant_count), 0, 1, 'L'); // 1.4 ประเภทผู้เข้าร่วมกิจกรรม $pdf->Cell(0, 8, thai_text( '1.4 ประเภทผู้เข้าร่วมกิจกรรม:'), 0, 1, 'L'); $participantType = isset($editData['participant_type']) ? $editData['participant_type'] : ''; foreach ($participantTypes as $type) { $isSelected = ($type['id'] == $participantType); // ตำแหน่งสำหรับ checkbox $x = $pdf->GetX() + 8; $y = $pdf->GetY() + 1; // วาด checkbox drawCheckbox($pdf, $x, $y, $isSelected); // แสดงข้อความ $pdf->SetXY($x + 6, $y - 1); $pdf->Cell(0, 6, thai_text($type['title']), 0, 1, 'L'); } $pdf->Ln(3); // ตอนที่ 2 ข้อมูลการจัดกิจกรรม $pdf->SetFont('THSarabunNew', 'b', 16); $pdf->Cell(0, 8, thai_text( 'ตอนที่ 2 ข้อมูลการจัดกิจกรรม'), 0, 1, 'L'); $pdf->Ln(2); $pdf->SetFont('THSarabunNew', '', 14); // 2.1 ชื่อกิจกรรม $objectives_title = isset($editData['objectives']) ? $editData['objectives'] : ''; $pdf->Cell(0, 8, thai_text( '2.1 ชื่อกิจกรรม: ' . $objectives_title), 0, 1, 'L'); // 2.2 วัตถุประสงค์ในการจัดกิจกรรม $pdf->Cell(0, 8, thai_text( '2.2 วัตถุประสงค์ในการจัดกิจกรรม:'), 0, 1, 'L'); $objectives_activities = isset($editData['objectives_activities']) ? $editData['objectives_activities'] : ''; if (!empty($objectives_activities)) { // แยกข้อความเป็นหลายบรรทัด $lines = explode("\n", $objectives_activities); foreach ($lines as $line) { $pdf->Cell(8, 6, '', 0, 0, 'L'); // เยื้องขวา $pdf->Cell(0, 6, thai_text( trim($line)), 0, 1, 'L'); } } // 2.3 ประเภทของการแนะแนว $pdf->Cell(0, 8, thai_text( '2.3 ประเภทของการแนะแนว:'), 0, 1, 'L'); $guidanceType = isset($editData['guidance_type']) ? $editData['guidance_type'] : ''; foreach ($guidanceTypes as $type) { $isSelected = ($type['id'] == $guidanceType); // ตำแหน่งสำหรับ checkbox $x = $pdf->GetX() + 8; $y = $pdf->GetY() + 1; // วาด checkbox drawCheckbox($pdf, $x, $y, $isSelected); // แสดงข้อความ $pdf->SetXY($x + 6, $y - 1); $pdf->Cell(0, 6, thai_text($type['title']), 0, 1, 'L'); } $pdf->Ln(3); // ตอนที่ 3 ผลการจัดกิจกรรม $pdf->SetFont('THSarabunNew', 'b', 16); $pdf->Cell(0, 8, thai_text( 'ตอนที่ 3 ผลการจัดกิจกรรม'), 0, 1, 'L'); $pdf->Ln(2); // 3.1 บรรลุประสงค์ (เลียนแบบจาก group_reports.php บรรทัด 214-226) $pdf->SetFont('THSarabunNew', '', 14); $pdf->Cell(0, 8, thai_text( '3.1 บรรลุประสงค์:'), 0, 1, 'L'); // ใช้ goal_achieved เหมือนในไฟล์ต้นฉบับ $goalAchieved = isset($editData['goal_achieved']) ? $editData['goal_achieved'] : ''; // แสดงตัวเลือกทั้งหมดจาก typeObjectives (เลียนแบบจาก group_reports.php บรรทัด 214-226) if (empty($objectives)) { $pdf->Cell(8, 6, '', 0, 0, 'L'); $pdf->Cell(0, 6, thai_text( '(ไม่พบข้อมูลในตาราง typeObjectives)'), 0, 1, 'L'); } else { foreach ($objectives as $objective) { $isSelected = ($objective['id'] == $goalAchieved); // ตำแหน่งสำหรับ checkbox $x = $pdf->GetX() + 8; $y = $pdf->GetY() + 1; // วาด checkbox drawCheckbox($pdf, $x, $y, $isSelected); // แสดงข้อความ $pdf->SetXY($x + 6, $y - 1); $pdf->Cell(0, 6, thai_text($objective['title']), 0, 1, 'L'); // แสดง failure_reason ใต้ตัวเลือกที่ถูกเลือก if ($isSelected && !empty($editData['failure_reason'])) { $pdf->SetFont('THSarabunNew', '', 12); $pdf->Cell(16, 6, '', 0, 0, 'L'); // เยื้องขวาเพิ่ม $pdf->Cell(0, 6, thai_text( 'เหตุผล: ' . $editData['failure_reason']), 0, 1, 'L'); $pdf->SetFont('THSarabunNew', '', 14); } } } $pdf->Ln(2); // 3.2 บันทึกผลการจัดกิจกรรม $pdf->SetFont('THSarabunNew', '', 14); $pdf->Cell(0, 8, thai_text( '3.2 บันทึกผลการจัดกิจกรรม:'), 0, 1, 'L'); $service_details = isset($editData['service_details']) ? $editData['service_details'] : ''; if (!empty($service_details)) { // แยกข้อความเป็นหลายบรรทัด $lines = explode("\n", $service_details); foreach ($lines as $line) { $pdf->Cell(8, 6, '', 0, 0, 'L'); // เยื้องขวา $pdf->Cell(0, 6, thai_text( trim($line)), 0, 1, 'L'); } } $pdf->Ln(2); // 3.3 ผู้ปฏิบัติหน้าที่ให้แนะแนวในครั้งนี้ $pdf->SetFont('THSarabunNew', '', 14); $pdf->Cell(0, 8, thai_text( '3.3 ผู้ปฏิบัติหน้าที่ให้แนะแนวในครั้งนี้:'), 0, 1, 'L'); // แยกชื่อและนามสกุล (เลียนแบบจาก group_reports.php บรรทัด 248-251) $consultant_name = isset($editData['consultant_name']) ? $editData['consultant_name'] : ''; $nameParts = explode(' ', $consultant_name, 2); $firstName = isset($nameParts[0]) ? $nameParts[0] : ''; $lastName = isset($nameParts[1]) ? $nameParts[1] : ''; $consultant_position = isset($editData['consultant_position']) ? $editData['consultant_position'] : ''; $consultant_phone = isset($editData['consultant_phone']) ? $editData['consultant_phone'] : ''; $pdf->Cell(8, 6, '', 0, 0, 'L'); // เยื้องขวา $pdf->Cell(30, 6, thai_text( 'ชื่อ:'), 0, 0, 'L'); $pdf->SetFont('THSarabunNew', 'b', 14); $pdf->Cell(60, 6, thai_text( $firstName), 0, 0, 'L'); $pdf->SetFont('THSarabunNew', '', 14); $pdf->Cell(20, 6, thai_text( 'สกุล:'), 0, 0, 'L'); $pdf->SetFont('THSarabunNew', 'b', 14); $pdf->Cell(0, 6, thai_text( $lastName), 0, 1, 'L'); $pdf->SetFont('THSarabunNew', '', 14); $pdf->Cell(8, 6, '', 0, 0, 'L'); // เยื้องขวา $pdf->Cell(30, 6, thai_text( 'ตำแหน่ง:'), 0, 0, 'L'); $pdf->SetFont('THSarabunNew', 'b', 14); $pdf->Cell(60, 6, thai_text( $consultant_position), 0, 0, 'L'); $pdf->SetFont('THSarabunNew', '', 14); $pdf->Cell(20, 6, thai_text( 'โทรศัพท์:'), 0, 0, 'L'); $pdf->SetFont('THSarabunNew', 'b', 14); $pdf->Cell(0, 6, thai_text( $consultant_phone), 0, 1, 'L'); // เส้นใต้หน้า $pdf->Ln(15); $pdf->SetDrawColor(0, 0, 0); $pdf->SetLineWidth(1); $pdf->Line(20, $pdf->GetY(), 190, $pdf->GetY()); // สร้างชื่อไฟล์ตามรูปแบบที่ต้องการ: รายงานข้อมูลรายกลุ่ม_ddmmyyyy_hhmmss $current_datetime = date('dmY_His'); $filename = 'รายงานข้อมูลรายกลุ่ม_' . $current_datetime . '.pdf'; // ส่งออกไฟล์ PDF $pdf->Output($filename, 'I'); ?>