Initial import

This commit is contained in:
pongpon pitisuk
2026-06-25 16:49:13 +07:00
commit 72701ad58c
120 changed files with 17590 additions and 0 deletions
+260
View File
@@ -0,0 +1,260 @@
<?php
$page_title = 'สรุปผลการเรียน';
require_once __DIR__ . '/../includes/functions.php';
requireLogin();
$student_id = intval($_GET['student_id'] ?? 0);
requireStudentAccess($student_id);
$student = getStudent($student_id);
if (!$student) {
die('ไม่พบข้อมูลนักศึกษา');
}
$summary = getStudentSummary($student_id);
$student_courses = getStudentCourses($student_id);
$completed_map = $summary['completed_map'];
$total_curriculum_credits = getTotalCurriculumCredits($student['curriculum_id']);
$transfer_credits_total = getTransferCreditsTotal($student_id);
$total_completed = getCompletedCreditsTotal($student_id);
$is_dbc = ($student['curriculum_code'] == 'DBC');
?>
<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<title>สรุปผลการเรียน - <?= htmlspecialchars($student['student_code']) ?></title>
<style>
@media print { .no-print { display: none; } body { font-family: 'TH Sarabun New', 'Leelawadee', 'Tahoma', sans-serif; } }
body {
font-family: 'TH Sarabun New', 'Leelawadee', 'Tahoma', sans-serif;
font-size: 14px; padding: 20px; color: #333;
}
.header { text-align: center; border-bottom: 2px solid #333; padding-bottom: 10px; margin-bottom: 20px; }
.header h1 { font-size: 22px; margin: 0; }
.header h2 { font-size: 18px; margin: 5px 0; font-weight: normal; }
.student-info { margin-bottom: 15px; }
.student-info table { width: 100%; }
.student-info td { padding: 2px 10px; }
.progress-bar { background: #e9ecef; border-radius: 10px; height: 20px; margin: 10px 0; overflow: hidden; }
.progress-bar-fill { background: #28a745; height: 100%; border-radius: 10px; text-align: center; color: white; line-height: 20px; font-size: 12px; }
.section { margin-bottom: 15px; }
.section-title { background: #0d6efd; color: white; padding: 5px 10px; font-size: 15px; font-weight: bold; }
.section-title.dbc { background: #198754; }
.subsection-title { background: #e9ecef; padding: 3px 10px; margin: 5px 0; font-size: 13px; font-weight: bold; color: #555; }
.subsubsection-title { font-weight: bold; color: #666; margin: 3px 0; font-size: 12px; }
table { width: 100%; border-collapse: collapse; margin: 5px 0; }
th, td { border: 1px solid #ccc; padding: 3px 6px; text-align: left; font-size: 13px; }
th { background: #f8f9fa; }
.center { text-align: center; }
.completed { background: #d4edda; }
.transfer { background: #fff3cd; }
.pending { color: #999; }
.summary-row { background: #f0f0f0; font-weight: bold; }
.footer { text-align: center; margin-top: 30px; padding-top: 10px; border-top: 1px solid #ccc; font-size: 12px; color: #666; }
.btn-print { display: inline-block; padding: 8px 16px; background: #0d6efd; color: white; text-decoration: none; border-radius: 4px; margin-bottom: 15px; }
.btn-print:hover { background: #0b5ed7; }
.conclusion { text-align: center; font-size: 16px; margin: 15px 0; padding: 10px; border: 2px solid #28a745; border-radius: 5px; }
.credit-cards { display: flex; gap: 10px; margin-bottom: 15px; }
.credit-card { flex: 1; padding: 8px; border-radius: 5px; text-align: center; font-size: 18px; }
</style>
</head>
<body>
<div class="no-print" style="margin-bottom:10px;">
<a href="#" onclick="window.print();return false;" class="btn-print">🖨️ พิมพ์ / บันทึกเป็น PDF</a>
<a href="summary_grouped_pdf.php?student_id=<?= $student_id ?>" class="btn-print" style="background:#6f42c1;">📊 สรุปผลการเรียนแยกตามโครงสร้าง</a>
<a href="transfer_report.php?student_id=<?= $student_id ?>" class="btn-print" style="background:#20c997;">📋 ผลการประเมินเทียบโอน</a>
<a href="../students/view.php?id=<?= $student_id ?>" class="btn-print" style="background:#6c757d;">⬅ กลับ</a>
</div>
<div class="header">
<h1>ใบควบคุมผลการเรียน</h1>
<h2>มหาวิทยาลัยตาปี</h2>
</div>
<div class="student-info">
<table>
<tr><td style="width:140px;"><strong>รหัสนักศึกษา:</strong></td><td><?= htmlspecialchars($student['student_code']) ?></td></tr>
<tr><td><strong>ชื่อ-นามสกุล:</strong></td><td><?= htmlspecialchars($student['name_th']) ?> (<?= htmlspecialchars($student['name_en']) ?>)</td></tr>
<tr><td><strong>สาขาวิชา:</strong></td><td><?= htmlspecialchars($student['curriculum_code']) ?> - <?= htmlspecialchars($student['curriculum_name']) ?></td></tr>
<tr><td><strong>คณะ:</strong></td><td><?= htmlspecialchars($student['faculty'] ?: '-') ?></td></tr>
<tr><td><strong>สถาบันที่จบ:</strong></td><td><?= htmlspecialchars($student['graduated_institution'] ?: '-') ?></td></tr>
<tr><td><strong>ปีการศึกษา:</strong></td><td><?= $student['enrollment_year'] ?></td></tr>
</table>
</div>
<div class="progress-bar">
<?php $pct = $total_curriculum_credits > 0 ? round(($total_completed / $total_curriculum_credits) * 100) : 0; ?>
<div class="progress-bar-fill" style="width:<?= min(100, $pct) ?>%;">
<?= $total_completed ?> / <?= $total_curriculum_credits ?> หน่วยกิต (<?= $pct ?>%)
</div>
</div>
<div class="credit-cards">
<div class="credit-card" style="background:#ffc107;">
<strong><?= $transfer_credits_total ?></strong><br><small>หน่วยกิตเทียบโอน</small>
</div>
<div class="credit-card" style="background:#28a745;color:white;">
<strong><?= $total_completed ?></strong><br><small>หน่วยกิตเรียนผ่านแล้ว</small>
</div>
<div class="credit-card" style="background:#0d6efd;color:white;">
<strong><?= max(0, $total_curriculum_credits - $total_completed) ?></strong><br><small>หน่วยกิตคงเหลือ</small>
</div>
</div>
<?php renderPrintTree($summary['groups'], $is_dbc); ?>
<div class="section">
<div class="section-title" style="background:#6c757d;">สรุปรายวิชาที่เรียนผ่านแล้วทั้งหมด (แยกตามโครงสร้างหลักสูตร)</div>
<?php renderGroupedSummary($summary['groups'], $is_dbc); ?>
<table style="margin-top:10px;">
<tr class="summary-row">
<td colspan="2" class="center">รวมหน่วยกิตที่เรียนผ่านแล้วทั้งหมด</td>
<td class="center"><?= $total_completed ?> หน่วยกิต</td><td colspan="4"></td>
</tr>
</table>
</div>
<?php $remaining = max(0, $total_curriculum_credits - $total_completed); ?>
<div class="conclusion" style="border-color: <?= $remaining <= 0 ? '#28a745' : '#ffc107' ?>;">
<?php if ($remaining <= 0): ?>
<strong style="color:#28a745;">✓ ครบตามหลักสูตรแล้ว (<?= $total_completed ?> / <?= $total_curriculum_credits ?> หน่วยกิต)</strong>
<?php else: ?>
<strong>หน่วยกิตคงเหลือที่ต้องเรียน: <?= $remaining ?> หน่วยกิต (<?= $total_completed ?> / <?= $total_curriculum_credits ?> หน่วยกิต)</strong>
<?php endif; ?>
</div>
<div class="footer">
ระบบใบควบคุมผลการเรียน มหาวิทยาลัยตาปี<br>
พิมพ์เมื่อ <?= date('d/m/Y H:i') ?> น.
</div>
</body>
</html>
<?php
function renderPrintTree($nodes, $is_dbc, $level = 0) {
foreach ($nodes as $node) {
$g = $node['group'];
$has_courses = !empty($node['courses']);
$has_children = !empty($node['children']);
$style = $level == 0 ? 'section-title' : ($level == 1 ? 'subsection-title' : 'subsubsection-title');
echo '<div class="section" style="margin-left:' . ($level * 10) . 'px;">';
echo '<div class="' . $style . '">' . htmlspecialchars($g['name_th']);
if ($g['min_credits'] > 0) echo ' (ไม่น้อยกว่า ' . $g['min_credits'] . ' หน่วยกิต)';
echo '</div>';
if ($has_courses) {
echo '<table style="table-layout: fixed; width: 100%;">';
echo '<thead>';
echo '<tr>';
echo '<th class="center" style="width: 13%;">รหัสวิชา</th>';
echo '<th style="width: 38%;">ชื่อวิชา</th>';
echo '<th class="center" style="width: 17%;">หน่วยกิต(ท-ป-อ)</th>';
echo '<th class="center" style="width: 10%;">ภาคเรียน</th>';
echo '<th class="center" style="width: 10%;">ปีการศึกษา</th>';
echo '<th class="center" style="width: 12%;">สถานะ</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
foreach ($node['courses'] as $course) {
$row_class = '';
$status_text = 'ยังไม่เรียน';
$sem = $yr = '-';
if (isset($course['_completed'])) {
$row_class = $course['_completed']['source_type'] == 'transfer' ? 'transfer' : 'completed';
$status_text = $course['_completed']['source_type'] == 'transfer' ? 'เทียบโอน' : 'เรียนแล้ว';
$sem = $course['_completed']['semester'] ? 'ภาค ' . htmlspecialchars($course['_completed']['semester']) : '-';
$yr = htmlspecialchars($course['_completed']['academic_year'] ?: '-');
}
echo '<tr class="' . $row_class . '">';
echo '<td class="center"><code>' . htmlspecialchars($course['code']) . '</code></td>';
echo '<td>' . htmlspecialchars($course['name_th']) . '</td>';
echo '<td class="center">' . number_format($course['credits'], 1) . '(' . $course['lecture_hours'] . '-' . $course['practice_hours'] . '-' . $course['self_study_hours'] . ')</td>';
echo '<td class="center">' . $sem . '</td>';
echo '<td class="center">' . $yr . '</td>';
echo '<td class="center bold">' . $status_text . '</td>';
echo '</tr>';
}
echo '</tbody></table>';
}
if ($has_children) {
renderPrintTree($node['children'], $is_dbc, $level + 1);
}
echo '</div>';
}
}
function renderGroupedSummary($nodes, $level = 0) {
foreach ($nodes as $node) {
$g = $node['group'];
$has_completed = $node['completed_credits'] > 0;
$has_courses = !empty($node['courses']);
$has_children = !empty($node['children']);
if (!$has_completed && !$has_children) {
continue;
}
$style = $level == 0 ? 'section-title' : ($level == 1 ? 'subsection-title' : 'subsubsection-title');
echo '<div style="margin-left:' . ($level * 10) . 'px;">';
echo '<div class="' . $style . '">' . htmlspecialchars($g['name_th']);
if ($g['min_credits'] > 0) echo ' (ไม่น้อยกว่า ' . $g['min_credits'] . ' หน่วยกิต)';
if ($level == 0 && $has_completed) {
echo ' <span style="font-weight:normal;font-size:12px;">— เรียนผ่านแล้ว ' . $node['completed_credits'] . ' หน่วยกิต</span>';
}
echo '</div>';
if ($has_courses) {
$group_total = 0;
echo '<table style="table-layout: fixed; width: 100%;">';
echo '<thead>';
echo '<tr>';
echo '<th class="center" style="width: 13%;">รหัสวิชา</th>';
echo '<th style="width: 41%;">ชื่อวิชา</th>';
echo '<th class="center" style="width: 10%;">หน่วยกิต</th>';
echo '<th class="center" style="width: 8%;">เกรด</th>';
echo '<th class="center" style="width: 10%;">ภาคเรียน</th>';
echo '<th class="center" style="width: 10%;">ปีการศึกษา</th>';
echo '<th class="center" style="width: 8%;">ประเภท</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
foreach ($node['courses'] as $course) {
if (!isset($course['_completed'])) continue;
$sc = $course['_completed'];
$group_total += $sc['credits'];
$type = htmlspecialchars($sc['course_type'] ?: ($sc['source_type'] == 'transfer' ? 'เทียบโอน' : 'เรียน'));
$sem = $sc['semester'] ? 'ภาค ' . htmlspecialchars($sc['semester']) : '-';
$yr = htmlspecialchars($sc['academic_year'] ?: '-');
$row_class = $sc['source_type'] == 'transfer' ? 'transfer' : 'completed';
echo '<tr class="' . $row_class . '">';
echo '<td class="center"><code>' . htmlspecialchars($sc['course_code']) . '</code></td>';
echo '<td>' . htmlspecialchars($sc['course_name_th']) . '</td>';
echo '<td class="center">' . number_format($sc['credits'], 1) . '</td>';
echo '<td class="center bold">' . htmlspecialchars($sc['grade'] ?: '-') . '</td>';
echo '<td class="center">' . $sem . '</td>';
echo '<td class="center">' . $yr . '</td>';
echo '<td class="center">' . $type . '</td>';
echo '</tr>';
}
echo '<tr class="summary-row">';
echo '<td colspan="2" class="right bold" style="text-align: right; padding-right: 15px;">รวมหน่วยกิต</td>';
echo '<td class="center bold">' . number_format($group_total, 1) . '</td>';
echo '<td colspan="4"></td>';
echo '</tr>';
echo '</tbody></table>';
}
if ($has_children) {
renderGroupedSummary($node['children'], $level + 1);
}
echo '</div>';
}
}
+215
View File
@@ -0,0 +1,215 @@
<?php
$page_title = 'สรุปผลการเรียนแยกตามโครงสร้าง';
require_once __DIR__ . '/../includes/functions.php';
requireLogin();
$student_id = intval($_GET['student_id'] ?? 0);
requireStudentAccess($student_id);
$student = getStudent($student_id);
if (!$student) {
die('ไม่พบข้อมูลนักศึกษา');
}
$summary = getStudentSummary($student_id);
$total_curriculum_credits = getTotalCurriculumCredits($student['curriculum_id']);
$transfer_credits_total = getTransferCreditsTotal($student_id);
$total_completed = getCompletedCreditsTotal($student_id);
$remaining = max(0, $total_curriculum_credits - $total_completed);
$pct = $total_curriculum_credits > 0 ? round(($total_completed / $total_curriculum_credits) * 100) : 0;
// ดึงข้อมูลชื่ออาจารย์ที่ปรึกษาจากระบบ
$advisor_name = '................................';
if (!empty($student['advisor_id'])) {
$advisor = getUser($student['advisor_id']);
if ($advisor) {
$advisor_name = $advisor['name'];
}
}
?>
<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<title>สรุปผลการเรียนแยกตามโครงสร้าง - <?= htmlspecialchars($student['student_code']) ?></title>
<style>
@media print { .no-print { display: none; } body { font-family: 'TH Sarabun New', 'Leelawadee', 'Tahoma', sans-serif; } }
body {
font-family: 'TH Sarabun New', 'Leelawadee', 'Tahoma', sans-serif;
font-size: 14px; padding: 20px; color: #333;
}
.header { text-align: center; border-bottom: 2px solid #333; padding-bottom: 10px; margin-bottom: 20px; }
.header h1 { font-size: 22px; margin: 0; }
.header h2 { font-size: 18px; margin: 5px 0; font-weight: normal; }
.student-info { margin-bottom: 15px; }
.student-info table { width: 100%; }
.student-info td { padding: 2px 10px; }
.credit-cards { display: flex; gap: 10px; margin-bottom: 15px; }
.credit-card { flex: 1; padding: 8px; border-radius: 5px; text-align: center; font-size: 18px; }
.section { margin-bottom: 15px; }
.section-title { background: #0d6efd; color: white; padding: 5px 10px; font-size: 15px; font-weight: bold; }
.subsection-title { background: #e9ecef; padding: 3px 10px; margin: 5px 0; font-size: 13px; font-weight: bold; color: #555; }
.subsubsection-title { font-weight: bold; color: #666; margin: 3px 0; font-size: 12px; }
table { width: 100%; border-collapse: collapse; margin: 5px 0; }
th, td { border: 1px solid #ccc; padding: 3px 6px; text-align: left; font-size: 13px; }
th { background: #f8f9fa; }
.center { text-align: center; }
.completed { background: #d4edda; }
.transfer { background: #fff3cd; }
.summary-row { background: #f0f0f0; font-weight: bold; }
.footer { text-align: center; margin-top: 30px; padding-top: 10px; border-top: 1px solid #ccc; font-size: 12px; color: #666; }
.btn-print { display: inline-block; padding: 8px 16px; background: #0d6efd; color: white; text-decoration: none; border-radius: 4px; margin-bottom: 15px; }
.btn-print:hover { background: #0b5ed7; }
.conclusion { text-align: center; font-size: 16px; margin: 15px 0; padding: 10px; border: 2px solid #28a745; border-radius: 5px; }
</style>
</head>
<body>
<div class="no-print" style="margin-bottom:10px;">
<a href="#" onclick="window.print();return false;" class="btn-print">🖨️ พิมพ์ / บันทึกเป็น PDF</a>
<a href="../students/view.php?id=<?= $student_id ?>" class="btn-print" style="background:#6c757d;">⬅ กลับ</a>
</div>
<div class="header">
<h1>สรุปผลการเรียน</h1>
<h2>มหาวิทยาลัยตาปี</h2>
</div>
<div class="student-info">
<table>
<tr><td style="width:140px;"><strong>รหัสนักศึกษา:</strong></td><td><?= htmlspecialchars($student['student_code']) ?></td></tr>
<tr><td><strong>ชื่อ-นามสกุล:</strong></td><td><?= htmlspecialchars($student['name_th']) ?> (<?= htmlspecialchars($student['name_en']) ?>)</td></tr>
<tr><td><strong>สาขาวิชา:</strong></td><td><?= htmlspecialchars($student['curriculum_code']) ?> - <?= htmlspecialchars($student['curriculum_name']) ?></td></tr>
<tr><td><strong>คณะ:</strong></td><td><?= htmlspecialchars($student['faculty'] ?: '-') ?></td></tr>
<tr><td><strong>สถาบันที่จบ:</strong></td><td><?= htmlspecialchars($student['graduated_institution'] ?: '-') ?></td></tr>
<tr><td><strong>ปีการศึกษา:</strong></td><td><?= $student['enrollment_year'] ?></td></tr>
</table>
</div>
<div class="credit-cards">
<div class="credit-card" style="background:#ffc107;">
<strong><?= $transfer_credits_total ?></strong><br><small>หน่วยกิตเทียบโอน</small>
</div>
<div class="credit-card" style="background:#28a745;color:white;">
<strong><?= $total_completed ?></strong><br><small>หน่วยกิตเรียนผ่านแล้ว</small>
</div>
<div class="credit-card" style="background:#0d6efd;color:white;">
<strong><?= $remaining ?></strong><br><small>หน่วยกิตคงเหลือ</small>
</div>
</div>
<div class="section">
<div class="section-title">สรุปรายวิชาที่เรียนผ่านแล้วทั้งหมด (แยกตามโครงสร้างหลักสูตร)</div>
<?php renderGroupedSummary($summary['groups']); ?>
<table style="margin-top:10px;">
<tr class="summary-row">
<td colspan="2" class="center">รวมหน่วยกิตที่เรียนผ่านแล้วทั้งหมด</td>
<td class="center"><?= $total_completed ?> หน่วยกิต</td><td colspan="4"></td>
</tr>
</table>
</div>
<div class="conclusion" style="border-color: <?= $remaining <= 0 ? '#28a745' : '#ffc107' ?>;">
<?php if ($remaining <= 0): ?>
<strong style="color:#28a745;">✓ ครบตามหลักสูตรแล้ว (<?= $total_completed ?> / <?= $total_curriculum_credits ?> หน่วยกิต)</strong>
<?php else: ?>
<strong>หน่วยกิตคงเหลือที่ต้องเรียน: <?= $remaining ?> หน่วยกิต (<?= $total_completed ?> / <?= $total_curriculum_credits ?> หน่วยกิต)</strong>
<?php endif; ?>
</div>
<!-- ส่วนลงชื่อ 3 ช่องท้ายรายงาน -->
<table style="width: 100%; border: none !important; margin-top: 50px; margin-bottom: 20px; page-break-inside: avoid;">
<tr style="border: none !important;">
<td style="width: 33%; text-align: center; border: none !important; padding: 10px; font-size: 14px; line-height: 1.8; vertical-align: top;">
............................................................<br>
( <?= htmlspecialchars($advisor_name) ?> )<br>
อาจารย์ที่ปรึกษา<br>&nbsp;
</td>
<td style="width: 33%; text-align: center; border: none !important; padding: 10px; font-size: 14px; line-height: 1.8; vertical-align: top;">
............................................................<br>
( ............................................................ )<br>
ประธานหลักสูตรสาขาวิชา<br><?= htmlspecialchars($student['curriculum_name']) ?>
</td>
<td style="width: 34%; text-align: center; border: none !important; padding: 10px; font-size: 14px; line-height: 1.8; vertical-align: top;">
............................................................<br>
( ............................................................ )<br>
คณบดี<br><?= htmlspecialchars($student['faculty'] ?: 'คณะ................................') ?>
</td>
</tr>
</table>
<div class="footer">
ระบบใบควบคุมผลการเรียน มหาวิทยาลัยตาปี<br>
พิมพ์เมื่อ <?= date('d/m/Y H:i') ?> น.
</div>
</body>
</html>
<?php
function renderGroupedSummary($nodes, $level = 0) {
foreach ($nodes as $node) {
$g = $node['group'];
$has_completed = $node['completed_credits'] > 0;
$has_courses = !empty($node['courses']);
$has_children = !empty($node['children']);
if (!$has_completed && !$has_children) continue;
$style = $level == 0 ? 'section-title' : ($level == 1 ? 'subsection-title' : 'subsubsection-title');
echo '<div style="margin-left:' . ($level * 10) . 'px;">';
echo '<div class="' . $style . '">' . htmlspecialchars($g['name_th']);
if ($g['min_credits'] > 0) echo ' (ไม่น้อยกว่า ' . $g['min_credits'] . ' หน่วยกิต)';
if ($level == 0 && $has_completed) {
echo ' <span style="font-weight:normal;font-size:12px;">— เรียนผ่านแล้ว ' . $node['completed_credits'] . ' หน่วยกิต</span>';
}
echo '</div>';
if ($has_courses) {
$group_total = 0;
echo '<table style="table-layout: fixed; width: 100%;">';
echo '<thead>';
echo '<tr>';
echo '<th class="center" style="width: 13%;">รหัสวิชา</th>';
echo '<th style="width: 41%;">ชื่อวิชา</th>';
echo '<th class="center" style="width: 10%;">หน่วยกิต</th>';
echo '<th class="center" style="width: 8%;">เกรด</th>';
echo '<th class="center" style="width: 10%;">ภาคเรียน</th>';
echo '<th class="center" style="width: 10%;">ปีการศึกษา</th>';
echo '<th class="center" style="width: 8%;">ประเภท</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
foreach ($node['courses'] as $course) {
if (!isset($course['_completed'])) continue;
$sc = $course['_completed'];
$group_total += $sc['credits'];
$type = htmlspecialchars($sc['course_type'] ?: ($sc['source_type'] == 'transfer' ? 'เทียบโอน' : 'เรียน'));
$sem = $sc['semester'] ? 'ภาค ' . htmlspecialchars($sc['semester']) : '-';
$yr = htmlspecialchars($sc['academic_year'] ?: '-');
$row_class = $sc['source_type'] == 'transfer' ? 'transfer' : 'completed';
echo '<tr class="' . $row_class . '">';
echo '<td class="center"><code>' . htmlspecialchars($sc['course_code']) . '</code></td>';
echo '<td>' . htmlspecialchars($sc['course_name_th']) . '</td>';
echo '<td class="center">' . number_format($sc['credits'], 1) . '</td>';
echo '<td class="center bold">' . htmlspecialchars($sc['grade'] ?: '-') . '</td>';
echo '<td class="center">' . $sem . '</td>';
echo '<td class="center">' . $yr . '</td>';
echo '<td class="center">' . $type . '</td>';
echo '</tr>';
}
echo '<tr class="summary-row">';
echo '<td colspan="2" class="right bold" style="text-align: right; padding-right: 15px;">รวมหน่วยกิต</td>';
echo '<td class="center bold">' . number_format($group_total, 1) . '</td>';
echo '<td colspan="4"></td>';
echo '</tr>';
echo '</tbody></table>';
}
if ($has_children) {
renderGroupedSummary($node['children'], $level + 1);
}
echo '</div>';
}
}
+167
View File
@@ -0,0 +1,167 @@
<?php
require_once __DIR__ . '/../includes/functions.php';
require_once __DIR__ . '/../vendor/fpdf.php';
requireLogin();
$student_id = intval($_GET['student_id'] ?? 0);
requireStudentAccess($student_id);
$student = getStudent($id = $student_id);
if (!$student) die('ไม่พบข้อมูลนักศึกษา');
$summary = getStudentSummary($student_id);
if (!$summary) die('ไม่พบข้อมูล');
$student_courses = getStudentCourses($student_id);
$completed_map = $summary['completed_map'];
$total_curriculum_credits = getTotalCurriculumCredits($student['curriculum_id']);
$transfer_credits_total = getTransferCreditsTotal($student_id);
$total_completed = getCompletedCreditsTotal($student_id);
class SummaryPDF extends FPDF {
function header() {
$this->SetFont('Courier', '', 10);
$this->Cell(0, 8, iconv('UTF-8','cp874','ใบควบคุมผลการเรียน'), 0, 1, 'C');
$this->Ln(2);
}
function footer() {
$this->SetY(-15);
$this->SetFont('Courier', '', 8);
$this->Cell(0, 10, iconv('UTF-8','cp874','หน้าที่ ').$this->PageNo().'/{nb}', 0, 0, 'C');
}
}
$pdf = new SummaryPDF('P', 'mm', 'A4');
$pdf->AliasNbPages();
$pdf->SetMargins(8, 10, 8);
$pdf->AddPage();
// Student info
$pdf->SetFont('Courier', '', 9);
$info = [
['รหัสนักศึกษา:', $student['student_code']],
['ชื่อ-นามสกุล:', $student['name_th'] . ' (' . $student['name_en'] . ')'],
['สาขาวิชา:', $student['curriculum_code'] . ' - ' . $student['curriculum_name']],
['คณะ:', $student['faculty'] ?: '-'],
['สถาบันที่จบ:', $student['graduated_institution'] ?: '-'],
['ปีการศึกษา:', $student['enrollment_year']],
];
foreach ($info as $row) {
$pdf->Cell(45, 5, iconv('UTF-8','cp874',$row[0]), 0, 0);
$pdf->Cell(0, 5, iconv('UTF-8','cp874//IGNORE',$row[1]), 0, 1);
}
$pdf->Ln(1);
$remaining = max(0, $total_curriculum_credits - $total_completed);
$pct = $total_curriculum_credits > 0 ? round(($total_completed / $total_curriculum_credits) * 100) : 0;
$pdf->SetFont('Courier', 'B', 9);
$pdf->Cell(0, 6, iconv('UTF-8','cp874','เทียบโอน: '.$transfer_credits_total.' | เรียนแล้ว: '.$total_completed.' | คงเหลือ: '.$remaining.' | คิดเป็น '.$pct.'%'), 0, 1);
$pdf->Ln(3);
// Render tree recursively
$level = 0;
renderPdfTree($summary['groups'], $pdf, $level);
// Summary table
$pdf->Ln(3);
$pdf->SetFont('Courier', 'B', 9);
$pdf->Cell(0, 6, iconv('UTF-8','cp874','--- สรุปรายวิชาที่เรียนผ่านแล้วทั้งหมด ---'), 0, 1);
$pdf->Ln(1);
$pdf->SetFont('Courier', '', 8);
$pdf->Cell(28, 4, iconv('UTF-8','cp874','รหัสวิชา'), 1, 0);
$pdf->Cell(46, 4, iconv('UTF-8','cp874','ชื่อวิชา'), 1, 0);
$pdf->Cell(12, 4, iconv('UTF-8','cp874','หน่วยกิต'), 1, 0, 'C');
$pdf->Cell(10, 4, iconv('UTF-8','cp874','เกรด'), 1, 0, 'C');
$pdf->Cell(16, 4, iconv('UTF-8','cp874','ภาคเรียน'), 1, 0, 'C');
$pdf->Cell(16, 4, iconv('UTF-8','cp874','ปีการศึกษา'), 1, 0, 'C');
$pdf->Cell(19, 4, iconv('UTF-8','cp874','ประเภท'), 1, 1);
$total = 0;
foreach ($student_courses as $sc) {
$total += $sc['credits'];
$name = mb_substr($sc['course_name_th'], 0, 24, 'UTF-8');
$type = iconv('UTF-8','cp874//IGNORE', $sc['course_type'] ?: ($sc['source_type'] == 'transfer' ? 'เทียบโอน' : 'เรียน'));
$sem = $sc['semester'] ? 'ภาค '.$sc['semester'] : '-';
$yr = $sc['academic_year'] ?: '-';
$grade = $sc['grade'] ?: '-';
$pdf->SetFont('Courier', '', 8);
$pdf->Cell(28, 4, iconv('UTF-8','cp874//IGNORE',$sc['course_code']), 1, 0);
$pdf->Cell(46, 4, iconv('UTF-8','cp874//IGNORE',$name), 1, 0);
$pdf->Cell(12, 4, $sc['credits'], 1, 0, 'C');
$pdf->Cell(10, 4, $grade, 1, 0, 'C');
$pdf->Cell(16, 4, iconv('UTF-8','cp874//IGNORE',$sem), 1, 0, 'C');
$pdf->Cell(16, 4, iconv('UTF-8','cp874//IGNORE',$yr), 1, 0, 'C');
$pdf->Cell(19, 4, $type, 1, 1);
}
$pdf->SetFont('Courier', 'B', 8);
$pdf->Cell(147, 5, iconv('UTF-8','cp874','รวมหน่วยกิตที่เรียนผ่านแล้วทั้งหมด: '.$total.' หน่วยกิต'), 0, 1);
$pdf->Ln(3);
if ($remaining <= 0) {
$pdf->SetFont('Courier', 'B', 10);
$pdf->Cell(0, 6, iconv('UTF-8','cp874','*** ครบตามหลักสูตรแล้ว ***'), 0, 1, 'C');
} else {
$pdf->SetFont('Courier', '', 9);
$pdf->Cell(0, 6, iconv('UTF-8','cp874','หน่วยกิตคงเหลือที่ต้องเรียน: '.$remaining.' หน่วยกิต'), 0, 1);
}
$filename = 'Summary_' . $student['student_code'] . '_' . date('Ymd') . '.pdf';
$pdf->Output('I', $filename);
// ============================================================
function renderPdfTree($nodes, &$pdf, $level) {
foreach ($nodes as $node) {
$g = $node['group'];
$has_courses = !empty($node['courses']);
$has_children = !empty($node['children']);
$indent = $level * 4;
$pdf->SetX(8 + $indent);
if ($level == 0) {
$pdf->SetFont('Courier', 'B', 9);
} elseif ($level == 1) {
$pdf->SetFont('Courier', 'B', 8);
} else {
$pdf->SetFont('Courier', '', 8);
}
$title = $g['name_th'];
if ($g['min_credits'] > 0) $title .= ' ('.iconv('UTF-8','cp874','ไม่น้อยกว่า ').$g['min_credits'].iconv('UTF-8','cp874',' หน่วยกิต').')';
$pdf->Cell(0, 5, iconv('UTF-8','cp874//IGNORE',$title), 0, 1);
if ($has_courses) {
$pdf->SetX(8 + $indent);
$pdf->SetFont('Courier', '', 7);
$pdf->Cell(30, 3, iconv('UTF-8','cp874','รหัสวิชา'), 0, 0);
$pdf->Cell(50, 3, iconv('UTF-8','cp874','ชื่อวิชา'), 0, 0);
$pdf->Cell(12, 3, iconv('UTF-8','cp874','หน่วยกิต'), 0, 0, 'C');
$pdf->Cell(10, 3, iconv('UTF-8','cp874','เกรด'), 0, 0, 'C');
$pdf->Cell(18, 3, iconv('UTF-8','cp874','ประเภท'), 0, 1);
foreach ($node['courses'] as $course) {
$status_text = '';
$grade_text = '';
if (isset($course['_completed'])) {
$sc = $course['_completed'];
$status_text = iconv('UTF-8','cp874//IGNORE', $sc['course_type'] ?: ($sc['source_type'] == 'transfer' ? 'เทียบโอน' : 'เรียนแล้ว'));
$grade_text = $sc['grade'] ?: '-';
}
$name = mb_substr($course['name_th'], 0, 28, 'UTF-8');
$pdf->SetX(8 + $indent);
$pdf->SetFont('Courier', '', 8);
$pdf->Cell(30, 4, iconv('UTF-8','cp874//IGNORE',$course['code']), 0, 0);
$pdf->Cell(50, 4, iconv('UTF-8','cp874//IGNORE',$name), 0, 0);
$pdf->Cell(12, 4, $course['credits'], 0, 0, 'C');
$pdf->Cell(10, 4, $grade_text, 0, 0, 'C');
$pdf->Cell(18, 4, $status_text, 0, 1);
}
$pdf->Ln(1);
}
if ($has_children) {
renderPdfTree($node['children'], $pdf, $level + 1);
}
}
}
+216
View File
@@ -0,0 +1,216 @@
<?php
$page_title = 'รายงานการประเมินเทียบโอนรายวิชา';
require_once __DIR__ . '/../includes/functions.php';
requireLogin();
$student_id = intval($_GET['student_id'] ?? 0);
requireStudentAccess($student_id);
$student = getStudent($student_id);
if (!$student) {
die('ไม่พบข้อมูลนักศึกษา');
}
$pdf_path = getStudentTransferPdfPath($student_id);
$report = null;
$error_msg = null;
if ($pdf_path && file_exists($pdf_path)) {
try {
$report = parseTransferReportFromPdf($pdf_path);
} catch (Exception $e) {
$error_msg = 'เกิดข้อผิดพลาดในการประมวลผลไฟล์ PDF: ' . $e->getMessage();
}
} else {
$error_msg = 'ยังไม่ได้นำเข้าไฟล์ PDF สำหรับการเทียบโอนวิชานี้ หรือไม่พบไฟล์ PDF ในระบบ';
}
$is_dbc = ($student['curriculum_code'] == 'DBC');
?>
<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<title>รายงานผลการประเมินเทียบโอนรายวิชา - <?= htmlspecialchars($student['student_code']) ?></title>
<style>
@media print {
.no-print { display: none; }
body { font-family: 'TH Sarabun New', 'Leelawadee', 'Tahoma', sans-serif; }
}
body {
font-family: 'TH Sarabun New', 'Leelawadee', 'Tahoma', sans-serif;
font-size: 14px; padding: 20px; color: #333;
background-color: #f8f9fa;
}
.container {
max-width: 1000px;
margin: 0 auto;
background: white;
padding: 30px;
box-shadow: 0 0 10px rgba(0,0,0,0.05);
border-radius: 8px;
}
.header { text-align: center; border-bottom: 2px solid #333; padding-bottom: 10px; margin-bottom: 20px; }
.header h1 { font-size: 22px; margin: 0; font-weight: bold; }
.header h2 { font-size: 18px; margin: 5px 0; font-weight: normal; }
.student-info { margin-bottom: 25px; }
.student-info table { width: 100%; border: none; }
.student-info td { padding: 4px 10px; border: none; font-size: 14px; }
.section-title {
background: #0d6efd;
color: white;
padding: 6px 12px;
font-size: 15px;
font-weight: bold;
margin-top: 25px;
margin-bottom: 10px;
border-radius: 4px;
}
.section-title.dbc { background: #198754; }
.section-title.secondary { background: #6c757d; }
table { width: 100%; border-collapse: collapse; margin: 10px 0; }
th, td { border: 1px solid #ccc; padding: 6px 10px; text-align: left; font-size: 13px; }
th { background: #f1f3f5; font-weight: bold; }
.center { text-align: center; }
.right { text-align: right; }
.bold { font-weight: bold; }
.text-muted { color: #6c757d; }
.btn-print {
display: inline-block;
padding: 8px 16px;
background: #0d6efd;
color: white;
text-decoration: none;
border-radius: 4px;
margin-bottom: 15px;
font-size: 13px;
font-weight: bold;
}
.btn-print:hover { background: #0b5ed7; }
.alert {
padding: 15px;
margin-bottom: 20px;
border: 1px solid transparent;
border-radius: 4px;
font-size: 14px;
}
.alert-danger {
color: #842029;
background-color: #f8d7da;
border-color: #f5c2c7;
}
.footer { text-align: center; margin-top: 40px; padding-top: 15px; border-top: 1px solid #eee; font-size: 12px; color: #888; }
</style>
</head>
<body>
<div class="container">
<div class="no-print" style="margin-bottom:20px;">
<a href="#" onclick="window.print();return false;" class="btn-print">🖨️ พิมพ์รายงานนี้</a>
<a href="../students/view.php?id=<?= $student_id ?>" class="btn-print" style="background:#6c757d;">⬅ กลับไปข้อมูลนักศึกษา</a>
</div>
<div class="header">
<h1>ผลการประเมินเทียบโอนรายวิชา</h1>
<h2>มหาวิทยาลัยตาปี (Tapee University)</h2>
</div>
<div class="student-info">
<table>
<tr>
<td style="width:15%;"><strong>รหัสนักศึกษา:</strong></td>
<td style="width:35%;"><?= htmlspecialchars($student['student_code']) ?></td>
<td style="width:15%;"><strong>ปีที่เข้าศึกษา:</strong></td>
<td style="width:35%;"><?= $student['enrollment_year'] ?></td>
</tr>
<tr>
<td><strong>ชื่อ-นามสกุล:</strong></td>
<td><?= htmlspecialchars($student['name_th']) ?> (<?= htmlspecialchars($student['name_en']) ?>)</td>
<td><strong>คณะ:</strong></td>
<td><?= htmlspecialchars($student['faculty'] ?: '-') ?></td>
</tr>
<tr>
<td><strong>สาขาวิชา:</strong></td>
<td>
<?= htmlspecialchars($student['curriculum_code']) ?> - <?= htmlspecialchars($student['curriculum_name']) ?>
<div style="margin-top: 4px; font-size: 13px; color: #555;">
<strong>หน่วยกิตที่เทียบโอนได้:</strong> <span style="font-weight: bold; color: #198754; font-size: 14px;"><?= getTransferCreditsTotal($student_id) ?></span> หน่วยกิต
</div>
</td>
<td><strong>สถาบันที่จบเดิม:</strong></td>
<td><?= htmlspecialchars($student['graduated_institution'] ?: '-') ?></td>
</tr>
</table>
</div>
<?php if ($error_msg): ?>
<div class="alert alert-danger">
⚠️ <?= htmlspecialchars($error_msg) ?>
</div>
<?php else: ?>
<div class="section-title <?= $is_dbc ? 'dbc' : '' ?>">รายละเอียดวิชาที่เทียบโอนได้</div>
<table>
<thead>
<tr>
<th rowspan="2" class="center" style="vertical-align: middle; width: 5%;">ลำดับ</th>
<th colspan="3" class="center">วิชาปลายทาง (ตามหลักสูตร)</th>
<th colspan="5" class="center">วิชาต้นทางที่ใช้เทียบ (สถาบันเดิม)</th>
</tr>
<tr>
<th class="center" style="width: 10%;">รหัส</th>
<th>ชื่อวิชา</th>
<th class="center" style="width: 8%;">หน่วยกิต</th>
<th class="center" style="width: 12%;">รหัส</th>
<th>ชื่อวิชา</th>
<th class="center" style="width: 8%;">หน่วยกิต</th>
<th class="center" style="width: 6%;">เกรด</th>
<th class="center" style="width: 10%;">ความสอดคล้อง</th>
</tr>
</thead>
<tbody>
<?php if (empty($report['transfers'])): ?>
<tr>
<td colspan="9" class="center text-muted">ไม่พบข้อมูลรายวิชาที่เทียบโอนได้</td>
</tr>
<?php else: ?>
<?php foreach ($report['transfers'] as $transfer): ?>
<?php
$num_sources = count($transfer['sources']);
$first_source = $transfer['sources'][0];
?>
<tr>
<td class="center" rowspan="<?= $num_sources ?>"><?= htmlspecialchars($transfer['seq']) ?></td>
<td class="center bold" rowspan="<?= $num_sources ?>"><?= htmlspecialchars($transfer['target_code']) ?></td>
<td class="bold" rowspan="<?= $num_sources ?>"><?= htmlspecialchars($transfer['target_name']) ?></td>
<td class="center bold" rowspan="<?= $num_sources ?>"><?= number_format($transfer['target_credits'], 1) ?></td>
<td class="center"><?= htmlspecialchars($first_source['code']) ?></td>
<td><?= htmlspecialchars($first_source['name']) ?></td>
<td class="center"><?= htmlspecialchars($first_source['credits']) ?></td>
<td class="center bold"><?= htmlspecialchars($first_source['grade']) ?></td>
<td class="center"><?= htmlspecialchars($first_source['similarity']) ?></td>
</tr>
<?php for ($i = 1; $i < $num_sources; $i++): $src = $transfer['sources'][$i]; ?>
<tr>
<td class="center"><?= htmlspecialchars($src['code']) ?></td>
<td><?= htmlspecialchars($src['name']) ?></td>
<td class="center"><?= htmlspecialchars($src['credits']) ?></td>
<td class="center bold"><?= htmlspecialchars($src['grade']) ?></td>
<td class="center"><?= htmlspecialchars($src['similarity']) ?></td>
</tr>
<?php endfor; ?>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<?php endif; ?>
<div class="footer">
ระบบเทียบโอนรายวิชา มหาวิทยาลัยตาปี<br>
เอกสารฉบับนี้วิเคราะห์และแสดงผลข้อมูลเทียบเคียงโดยตรงจากเอกสารผลประเมิน (PDF) ณ วันที่ <?= date('d/m/Y H:i') ?> น.
</div>
</div>
</body>
</html>