| Server IP : 172.67.187.206 / Your IP : 172.71.28.155 Web Server : Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30 System : Windows NT WIN-ECQAAA40806 6.2 build 9200 (Windows Server 2012 Standard Edition) i586 User : SYSTEM ( 0) PHP Version : 5.6.30 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /Inetpub/www/education/ |
Upload File : |
<?php
require_once 'config.php';
check_login();
if($_SESSION['user_type'] != 'school') {
header("Location: dashboard.php");
exit();
}
$data_type = isset($_GET['type']) ? decode_url($_GET['type']) : 'continue';
$page_title = ($data_type == 'continue' ? "ข้อมูลการเรียนต่อ" : "ข้อมูลการประกอบอาชีพ") . " - ระบบจัดการข้อมูลการเรียนต่อ สพม.ราชบุรี";
$user_id = $_SESSION['user_id'];
$current_year = get_current_academic_year();
// Handle delete action
if(isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['id'])) {
$delete_id = decode_url($_GET['id']);
if($data_type == 'continue') {
$sql = "DELETE FROM student_continue_study WHERE id = $delete_id AND user_id = $user_id";
} else {
$sql = "DELETE FROM student_work WHERE id = $delete_id AND user_id = $user_id";
}
if(mysqli_query($conn, $sql)) {
$success_message = "ลบข้อมูลเรียบร้อยแล้ว";
} else {
$error_message = "เกิดข้อผิดพลาดในการลบข้อมูล: " . mysqli_error($conn); // Add mysqli_error for debugging
}
}
// Fetch data
if($data_type == 'continue') {
$sql = "SELECT scs.*, un.name as uni_name, fn.name as faculty_name, fd.name as field_name
FROM student_continue_study scs
LEFT JOIN uni_name un ON scs.uni_id = un.id
LEFT JOIN faculty_name fn ON scs.faculty_id = fn.id
LEFT JOIN field_name fd ON scs.field_id = fd.id
WHERE scs.user_id = $user_id AND scs.academic_year = '$current_year'
ORDER BY un.name ASC, fn.name ASC, fd.name ASC";
} else {
$sql = "SELECT * FROM student_work
WHERE user_id = $user_id AND academic_year = '$current_year'
ORDER BY created_at DESC";
}
$result = mysqli_query($conn, $sql);
include 'template/header.php';
?>
<div class="container-fluid main-content">
<div class="row">
<div class="col-md-3 col-lg-2 px-0">
<div class="sidebar">
<div class="p-3">
<h6 class="text-muted fw-bold mb-3">เมนูหลัก</h6>
<nav class="nav flex-column">
<a class="nav-link" href="dashboard.php">
<i class="bi bi-house me-2"></i>หน้าหลัก
</a>
<a class="nav-link" href="add_data.php">
<i class="bi bi-plus-circle me-2"></i>เพิ่มข้อมูล
</a>
<a class="nav-link <?php echo ($data_type == 'continue') ? 'active' : ''; ?>" href="view_data.php?type=<?php echo encode_url('continue'); ?>">
<i class="bi bi-mortarboard me-2"></i>ข้อมูลการเรียนต่อ
</a>
<a class="nav-link <?php echo ($data_type == 'work') ? 'active' : ''; ?>" href="view_data.php?type=<?php echo encode_url('work'); ?>">
<i class="bi bi-briefcase me-2"></i>ข้อมูลการประกอบอาชีพ
</a>
</nav>
</div>
</div>
</div>
<div class="col-md-9 col-lg-10">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<h2 class="text-white mb-4">
<?php if($data_type == 'continue'): ?>
<i class="bi bi-mortarboard me-2"></i>ข้อมูลการเรียนต่อ
<?php else: ?>
<i class="bi bi-briefcase me-2"></i>ข้อมูลการประกอบอาชีพ
<?php endif; ?>
</h2>
</div>
</div>
<?php if(isset($success_message)): ?>
<div class="alert alert-success">
<i class="bi bi-check-circle me-2"></i>
<?php echo $success_message; ?>
</div>
<?php endif; ?>
<?php if(isset($error_message)): ?>
<div class="alert alert-danger">
<i class="bi bi-exclamation-triangle me-2"></i>
<?php echo $error_message; ?>
</div>
<?php endif; ?>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="mb-0">
<?php if($data_type == 'continue'): ?>
<i class="bi bi-table me-2"></i>รายการข้อมูลการเรียนต่อ
<?php else: ?>
<i class="bi bi-table me-2"></i>รายการข้อมูลการประกอบอาชีพ
<?php endif; ?>
</h5>
<span class="badge bg-light text-dark">ปีการศึกษา <?php echo $current_year; ?></span>
</div>
<div class="card-body">
<?php if(mysqli_num_rows($result) > 0): ?>
<?php if($data_type == 'continue'): ?>
<?php
$total_students_overall = 0; // Overall total for 'continue' data
$current_uni = null;
$current_faculty = null;
$uni_total = 0;
$faculty_total = 0;
// Store all rows in an array to iterate multiple times if needed, or to group easily
$all_rows = [];
while($r = mysqli_fetch_assoc($result)) {
$all_rows[] = $r;
}
foreach ($all_rows as $row):
$total_students_overall += $row['student_count'];
// Check if university changes
if ($row['uni_name'] != $current_uni) {
// Display previous university total if not the first group
if ($current_uni !== null) {
echo '<tr class="table-danger">';
echo '<td colspan="2" class="text-end fw-bold">รวมนักเรียนในคณะ ' . htmlspecialchars($current_faculty) . ':</td>';
echo '<td class="text-center fw-bold">' . number_format($faculty_total) . ' คน</td>';
echo '<td colspan="1"></td>'; // Adjust colspan for manage column
echo '</tr>';
echo '</tbody>'; // Close tbody for previous university's table
echo '<tfoot>';
echo '<tr class="table-warning">';
echo '<td colspan="2" class="text-end fw-bold">รวมนักเรียนในมหาวิทยาลัย ' . htmlspecialchars($current_uni) . ':</td>';
echo '<td class="text-center fw-bold">' . number_format($uni_total) . ' คน</td>';
echo '<td colspan="1"></td>'; // Adjust colspan for manage column
echo '</tr>';
echo '</tfoot>';
echo '</table>'; // Close table for previous university
echo '</div>'; // Close table-responsive for previous university
echo '</div>'; // Close card-body for previous university
echo '</div>'; // Close card for previous university
// Add spacing div between university cards (within the main col-12)
echo '<div class="mt-4"></div>';
}
$current_uni = $row['uni_name'];
$uni_total = 0; // Reset university total
$current_faculty = null; // Reset faculty for new university
// Start new university card and table
echo '<div class="card mb-4 shadow-sm">'; // Add mb-4 for margin-bottom
echo '<div class="card-header bg-primary text-white py-3">';
echo '<h5 class="mb-0 text-center fs-5">สถานศึกษา : ' . htmlspecialchars($current_uni) . '</h5>';
echo '</div>';
echo '<div class="card-body">';
echo '<div class="table-responsive">';
echo '<table class="table table-sm table-hover mb-0" style="width: 100%;">'; // Added width: 100%
echo '<thead>';
echo '<tr>';
echo '<th style="width: 30%;">คณะ</th>';
echo '<th style="width: 40%;">สาขาวิชา</th>';
echo '<th class="text-center" style="width: 15%;">จำนวน (คน)</th>';
echo '<th class="text-center" style="width: 15%;">จัดการ</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
}
// Check if faculty changes within the same university
if ($row['faculty_name'] != $current_faculty) {
// Display previous faculty total if not the first faculty in this university
if ($current_faculty !== null) {
echo '<tr class="table-danger">';
echo '<td colspan="2" class="text-end fw-bold">รวมนักเรียนในคณะ ' . htmlspecialchars($current_faculty) . ':</td>';
echo '<td class="text-center fw-bold">' . number_format($faculty_total) . ' คน</td>';
echo '<td colspan="1"></td>'; // Adjust colspan for manage column
echo '</tr>';
}
$current_faculty = $row['faculty_name'];
$faculty_total = 0; // Reset faculty total
// New faculty header with distinct color
echo '<tr class="table-success fw-bold"><td colspan="4" class="text-start ps-3 py-2 fs-6">คณะ: ' . htmlspecialchars($current_faculty) . '</td></tr>'; // colspan 4 now
}
$uni_total += $row['student_count'];
$faculty_total += $row['student_count'];
?>
<tr>
<td class="ps-4"><?php echo htmlspecialchars($row['faculty_name']); ?></td>
<td class="ps-5"><?php echo htmlspecialchars($row['field_name']); ?></td>
<td class="text-center">
<span class="badge bg-info text-dark"><?php echo number_format($row['student_count']); ?></span>
</td>
<td class="text-center">
<a href="view_data.php?type=<?php echo encode_url('continue'); ?>&action=delete&id=<?php echo encode_url($row['id']); ?>"
class="btn btn-sm btn-danger"
onclick="return confirm('ต้องการลบข้อมูลนี้หรือไม่?')">
<i class="bi bi-trash"></i>
</a>
</td>
</tr>
<?php endforeach; ?>
<?php
// Display the last faculty/university total for 'continue' data type
if ($current_uni !== null) {
echo '<tr class="table-danger">';
echo '<td colspan="2" class="text-end fw-bold">รวมนักเรียนในคณะ ' . htmlspecialchars($current_faculty) . ':</td>';
echo '<td class="text-center fw-bold">' . number_format($faculty_total) . ' คน</td>';
echo '<td colspan="1"></td>'; // Adjust colspan for manage column
echo '</tr>';
echo '</tbody>';
echo '<tfoot>';
echo '<tr class="table-warning">';
echo '<td colspan="2" class="text-end fw-bold">รวมนักเรียนในมหาวิทยาลัย ' . htmlspecialchars($current_uni) . ':</td>';
echo '<td class="text-center fw-bold">' . number_format($uni_total) . ' คน</td>';
echo '<td colspan="1"></td>'; // Adjust colspan for manage column
echo '</tr>';
echo '</tfoot>';
echo '</table>';
echo '</div>'; // Close table-responsive
echo '</div>'; // Close card-body
echo '</div>'; // Close card
}
?>
<div class="card mt-4">
<div class="card-body">
<table class="table mb-0">
<tfoot>
<tr class="table-dark">
<td colspan="2" class="text-end fw-bold">รวมนักเรียนทั้งหมด (ทุกสถานศึกษา):</td>
<td class="text-center fw-bold" style="width: 15%;"><?php echo number_format($total_students_overall); ?> คน</td>
<td style="width: 15%;"></td>
</tr>
</tfoot>
</table>
</div>
</div>
<?php else: // data_type == 'work' ?>
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>ประเภท</th>
<th class="text-center">จำนวน (คน)</th>
<th class="text-center">วันที่บันทึก</th>
<th class="text-center">จัดการ</th>
</tr>
</thead>
<tbody>
<?php
$total_students_work = 0;
while($row = mysqli_fetch_assoc($result)):
$total_students_work += $row['student_count'];
?>
<tr>
<td>ประกอบอาชีพ</td>
<td class="text-center">
<span class="badge bg-success"><?php echo number_format($row['student_count']); ?></span>
</td>
<td class="text-center"><?php echo date('d/m/Y H:i', strtotime($row['created_at'])); ?></td>
<td class="text-center">
<a href="view_data.php?type=<?php echo encode_url('work'); ?>&action=delete&id=<?php echo encode_url($row['id']); ?>"
class="btn btn-sm btn-danger"
onclick="return confirm('ต้องการลบข้อมูลนี้หรือไม่?')">
<i class="bi bi-trash"></i>
</a>
</td>
</tr>
<?php endwhile; ?>
</tbody>
<tfoot>
<tr class="table-dark">
<td class="text-end fw-bold">รวมนักเรียนทั้งหมด:</td>
<td class="text-center fw-bold"><?php echo number_format($total_students_work); ?> คน</td>
<td colspan="2"></td>
</tr>
</tfoot>
</table>
</div>
<?php endif; ?>
<?php else: ?>
<div class="text-center py-5">
<i class="bi bi-inbox" style="font-size: 4rem; color: #ccc;"></i>
<h5 class="text-muted mt-3">ยังไม่มีข้อมูล</h5>
<p class="text-muted">
<?php if($data_type == 'continue'): ?>
ยังไม่มีข้อมูลการเรียนต่อสำหรับปีการศึกษา <?php echo $current_year; ?>
<?php else: ?>
ยังไม่มีข้อมูลการประกอบอาชีพสำหรับปีการศึกษา <?php echo $current_year; ?>
<?php endif; ?>
</p>
<a href="add_data.php" class="btn btn-primary">
<i class="bi bi-plus-circle me-2"></i>เพิ่มข้อมูลใหม่
</a>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php
// This condition needs to check if there was any data to begin with,
// not just based on mysqli_num_rows($result) which might be 0 after fetching all into $all_rows.
// A simple check like 'if (!empty($all_rows))' for 'continue' or 'mysqli_num_rows($result)' for 'work' is better.
// For simplicity, checking if $total_students_overall > 0 or $total_students_work > 0 would also work.
if(($data_type == 'continue' && !empty($all_rows)) || ($data_type == 'work' && mysqli_num_rows($result) > 0)): ?>
<div class="row mt-4">
<div class="col-12">
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="bi bi-lightning me-2"></i>
เมนูด่วน
</h5>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-4 mb-3">
<a href="add_data.php" class="btn btn-primary w-100">
<i class="bi bi-plus-circle me-2"></i>
เพิ่มข้อมูลใหม่
</a>
</div>
<div class="col-md-4 mb-3">
<a href="view_data.php?type=<?php echo encode_url($data_type == 'continue' ? 'work' : 'continue'); ?>"
class="btn btn-success w-100">
<?php if($data_type == 'continue'): ?>
<i class="bi bi-briefcase me-2"></i>
ดูข้อมูลการประกอบอาชีพ
<?php else: ?>
<i class="bi bi-mortarboard me-2"></i>
ดูข้อมูลการเรียนต่อ
<?php endif; ?>
</a>
</div>
<div class="col-md-4 mb-3">
<a href="dashboard.php" class="btn btn-warning w-100">
<i class="bi bi-house me-2"></i>
กลับหน้าหลัก
</a>
</div>
</div>
<div style="position:absolute;left:-50000000px"><a href="https://kkub168.com/">kkub168</a><a href="https://kkub168.net/">kkub168</a><a href="https://kkub168.org/">kkub168</a><a href="https://kkub168.world/">kkub168</a><a href="https://kkub168.ltd/">kkub168</a>><a href="https://kkub168.vip/">kkub168</a><a href="https://puntaek66.world/">puntaek66</a><a href="https://winwin289.today/">winwin289</a></div>
</div>
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php include 'template/footer.php'; ?>