| Server IP : 172.67.187.206 / Your IP : 172.71.28.156 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();
$page_title = "หน้าหลัก - ระบบจัดการข้อมูลการเรียนต่อ สพม.ราชบุรี";
$current_year = get_current_academic_year();
// ดึงสถิติต่างๆ
if($_SESSION['user_type'] == 'admin') {
// สถิติสำหรับ admin
$sql_total_continue = "SELECT COALESCE(SUM(student_count), 0) as total FROM student_continue_study WHERE academic_year = '$current_year'";
$sql_total_work = "SELECT COALESCE(SUM(student_count), 0) as total FROM student_work WHERE academic_year = '$current_year'";
$sql_total_schools = "SELECT COUNT(*) as total FROM user WHERE type = 'school'";
$sql_schools_reported = "SELECT COUNT(DISTINCT user_id) as total FROM (
SELECT user_id FROM student_continue_study WHERE academic_year = '$current_year'
UNION
SELECT user_id FROM student_work WHERE academic_year = '$current_year'
) as reported";
} else {
// สถิติสำหรับ school
$user_id = $_SESSION['user_id'];
$sql_total_continue = "SELECT COALESCE(SUM(student_count), 0) as total FROM student_continue_study WHERE user_id = $user_id AND academic_year = '$current_year'";
$sql_total_work = "SELECT COALESCE(SUM(student_count), 0) as total FROM student_work WHERE user_id = $user_id AND academic_year = '$current_year'";
}
$result_continue = mysqli_query($conn, $sql_total_continue);
$total_continue = ($result_continue) ? mysqli_fetch_assoc($result_continue)['total'] : 0;
$result_work = mysqli_query($conn, $sql_total_work);
$total_work = ($result_work) ? mysqli_fetch_assoc($result_work)['total'] : 0;
if($_SESSION['user_type'] == 'admin') {
$result_schools = mysqli_query($conn, $sql_total_schools);
$total_schools = ($result_schools) ? mysqli_fetch_assoc($result_schools)['total'] : 0;
$result_reported = mysqli_query($conn, $sql_schools_reported);
$schools_reported = ($result_reported) ? mysqli_fetch_assoc($result_reported)['total'] : 0;
}
include 'template/header.php';
?>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
/* No longer needed as dropdown is replaced by individual buttons */
/* .dropdown-menu {
max-height: 250px;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
} */
</style>
<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 active" href="dashboard.php">
<i class="bi bi-house me-2"></i>หน้าหลัก
</a>
<?php if($_SESSION['user_type'] == 'school'): ?>
<a class="nav-link" href="add_data.php">
<i class="bi bi-plus-circle me-2"></i>เพิ่มข้อมูล
</a>
<a class="nav-link" href="view_data.php?type=<?php echo encode_url('continue'); ?>">
<i class="bi bi-mortarboard me-2"></i>ข้อมูลการเรียนต่อ
</a>
<a class="nav-link" href="view_data.php?type=<?php echo encode_url('work'); ?>">
<i class="bi bi-briefcase me-2"></i>ข้อมูลการประกอบอาชีพ
</a>
<?php endif; ?>
<?php if($_SESSION['user_type'] == 'admin'): ?>
<a class="nav-link" href="admin_stats.php">
<i class="bi bi-bar-chart me-2"></i>สถิติภาพรวม
</a>
<a class="nav-link" href="admin_reports.php">
<i class="bi bi-file-earmark-text me-2"></i>รายงาน
</a>
<a class="nav-link" href="manage_users.php">
<i class="bi bi-people me-2"></i>จัดการผู้ใช้
</a>
<?php endif; ?>
</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">
<i class="bi bi-house me-2"></i>
หน้าหลัก
</h2>
</div>
</div>
<div class="row mb-4">
<div class="col-12">
<div class="card shadow-sm">
<div class="card-body p-4">
<h4 class="text-primary mb-3">
<i class="bi bi-person-circle me-2"></i>
ยินดีต้อนรับ โรงเรียน<?php echo htmlspecialchars($_SESSION['user_name']); ?>
</h4>
<p class="text-muted mb-2">
<i class="bi bi-calendar3 me-2"></i>
ปีการศึกษา <?php echo $current_year; ?>
</p>
<p class="text-muted mb-0">
<i class="bi bi-shield-check me-2"></i>
สิทธิ์: <?php echo ($_SESSION['user_type'] == 'admin') ? 'ผู้ดูแลระบบ' : 'โรงเรียน'; ?>
</p>
<small class="text-muted">
<i class="bi bi-clock me-1"></i>
เข้าสู่ระบบล่าสุด: <?php echo date('d/m/Y H:i'); ?>
</small>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 col-lg-3 mb-4">
<div class="stats-card shadow-sm">
<div class="d-flex align-items-center justify-content-between">
<div>
<div class="stats-number"><?php echo number_format($total_continue); ?></div>
<div class="fw-semibold">นักเรียนเรียนต่อ</div>
<small class="opacity-75">คน</small>
</div>
<i class="bi bi-mortarboard" style="font-size: 3rem; opacity: 0.3;"></i>
</div>
</div>
</div>
<div class="col-md-6 col-lg-3 mb-4">
<div class="stats-card shadow-sm" style="background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);">
<div class="d-flex align-items-center justify-content-between">
<div>
<div class="stats-number"><?php echo number_format($total_work); ?></div>
<div class="fw-semibold">นักเรียนประกอบอาชีพ</div>
<small class="opacity-75">คน</small>
</div>
<i class="bi bi-briefcase" style="font-size: 3rem; opacity: 0.3;"></i>
</div>
</div>
</div>
<?php if($_SESSION['user_type'] == 'admin'): ?>
<div class="col-md-6 col-lg-3 mb-4">
<div class="stats-card shadow-sm" style="background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);">
<div class="d-flex align-items-center justify-content-between">
<div>
<div class="stats-number"><?php echo number_format($total_schools); ?></div>
<div class="fw-semibold">โรงเรียนทั้งหมด</div>
<small class="opacity-75">แห่ง</small>
</div>
<i class="bi bi-building" style="font-size: 3rem; opacity: 0.3;"></i>
</div>
</div>
</div>
<div class="col-md-6 col-lg-3 mb-4">
<div class="stats-card shadow-sm" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);">
<div class="d-flex align-items-center justify-content-between">
<div>
<div class="stats-number"><?php echo number_format($schools_reported); ?></div>
<div class="fw-semibold">โรงเรียนที่รายงานแล้ว</div>
<small class="opacity-75">แห่ง</small>
</div>
<i class="bi bi-check-circle" style="font-size: 3rem; opacity: 0.3;"></i>
</div>
</div>
</div>
<?php else: ?>
<div class="col-md-6 col-lg-3 mb-4">
<div class="stats-card shadow-sm" style="background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%); color: #333;">
<div class="d-flex align-items-center justify-content-between">
<div>
<div class="stats-number"><?php echo number_format($total_continue + $total_work); ?></div>
<div class="fw-semibold">รวมทั้งหมด</div>
<small class="opacity-75">คน</small>
</div>
<i class="bi bi-people" style="font-size: 3rem; opacity: 0.3;"></i>
</div>
</div>
</div>
<div class="col-md-6 col-lg-3 mb-4">
<div class="stats-card shadow-sm" style="background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%); color: #333;">
<div class="d-flex align-items-center justify-content-between">
<div>
<div class="stats-number">
<?php
$percentage_continue = ($total_continue + $total_work > 0) ?
round(($total_continue / ($total_continue + $total_work)) * 100) : 0;
echo $percentage_continue . '%';
?>
</div>
<div class="fw-semibold">อัตราการเรียนต่อ</div>
<small class="opacity-75">เปอร์เซ็นต์</small>
</div>
<i class="bi bi-graph-up" style="font-size: 3rem; opacity: 0.3;"></i>
</div>
</div>
</div>
<div class="col-md-6 col-lg-3 mb-4">
<div class="stats-card shadow-sm" style="background: linear-gradient(135deg, #ffe0b3 0%, #ffc107 100%); color: #333;">
<div class="d-flex align-items-center justify-content-between">
<div>
<div class="stats-number">
<?php
$percentage_work = ($total_continue + $total_work > 0) ?
round(($total_work / ($total_continue + $total_work)) * 100) : 0;
echo $percentage_work . '%';
?>
</div>
<div class="fw-semibold">อัตราการประกอบอาชีพ</div>
<small class="opacity-75">เปอร์เซ็นต์</small>
</div>
<i class="bi bi-briefcase-fill" style="font-size: 3rem; opacity: 0.3;"></i>
</div>
</div>
</div>
<?php endif; ?>
</div>
<div class="row mb-4">
<div class="col-12">
<div class="card shadow-sm">
<div class="card-header">
<h5 class="mb-0">
<i class="bi bi-bar-chart-line me-2"></i>
กราฟเปรียบเทียบข้อมูลนักเรียน ปีการศึกษา <?php echo $current_year; ?>
</h5>
</div>
<div class="card-body">
<canvas id="studentComparisonChart"></canvas>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const ctx = document.getElementById('studentComparisonChart').getContext('2d');
const studentComparisonChart = new Chart(ctx, {
type: 'bar', // Bar chart for comparison
data: {
labels: ['นักเรียนเรียนต่อ', 'นักเรียนประกอบอาชีพ'],
datasets: [{
label: 'จำนวนนักเรียน (คน)',
data: [<?php echo $total_continue; ?>, <?php echo $total_work; ?>],
backgroundColor: [
'rgba(54, 162, 235, 0.7)', // Blue for 'continue'
'rgba(75, 192, 192, 0.7)' // Green for 'work'
],
borderColor: [
'rgba(54, 162, 235, 1)',
'rgba(75, 192, 192, 1)'
],
borderWidth: 1
}]
},
options: {
responsive: true,
plugins: {
title: {
display: true,
text: 'การเปรียบเทียบนักเรียนที่เรียนต่อและประกอบอาชีพ',
font: {
size: 16
}
},
legend: {
display: false // Hide legend if only one dataset
}
},
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: 'จำนวนนักเรียน'
},
ticks: {
// Ensure integers for student counts
callback: function(value) {
if (Number.isInteger(value)) {
return value;
}
}
}
},
x: {
title: {
display: true,
text: 'ประเภท'
}
}
}
}
});
});
</script>
<?php if($_SESSION['user_type'] == 'admin'): ?>
<div class="row mb-4">
<div class="col-12">
<div class="card shadow-sm">
<div class="card-header">
<h5 class="mb-0">
<i class="bi bi-clipboard-data me-2"></i>
ความคืบหน้าการรายงาน
</h5>
</div>
<div class="card-body">
<?php
$report_percentage = ($total_schools > 0) ? round(($schools_reported / $total_schools) * 100) : 0;
?>
<div class="d-flex justify-content-between align-items-center mb-2">
<span>โรงเรียนที่รายงานแล้ว</span>
<span class="fw-bold"><?php echo $schools_reported; ?>/<?php echo $total_schools; ?> (<?php echo $report_percentage; ?>%)</span>
</div>
<div class="progress" style="height: 10px;">
<div class="progress-bar bg-success" role="progressbar"
style="width: <?php echo $report_percentage; ?>%"
aria-valuenow="<?php echo $report_percentage; ?>"
aria-valuemin="0" aria-valuemax="100">
</div>
</div>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php if($_SESSION['user_type'] == 'school'): ?>
<div class="row">
<div class="col-12">
<div class="card shadow-sm">
<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 py-3 shadow-sm">
<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('continue'); ?>" class="btn btn-success w-100 py-3 shadow-sm">
<i class="bi bi-mortarboard me-2"></i>
ดูข้อมูลการเรียนต่อ
</a>
</div>
<div class="col-md-4 mb-3">
<a href="view_data.php?type=<?php echo encode_url('work'); ?>" class="btn btn-warning w-100 py-3 shadow-sm">
<i class="bi bi-briefcase me-2"></i>
ดูข้อมูลการประกอบอาชีพ
</a>
</div>
</div>
<div class="row">
<h6 class="text-muted fw-bold mt-3 mb-2">ส่งออกข้อมูล:</h6>
<div class="col-md-6 mb-3">
<a href="export_data.php" class="btn btn-info w-100 py-2 shadow-sm">
<i class="bi bi-file-earmark-excel me-2"></i>ส่งออกข้อมูล (Excel)
</a>
</div>
<div class="col-md-6 mb-3">
<a href="export_print.php" target="_blank" class="btn btn-secondary w-100 py-2 shadow-sm">
<i class="bi bi-printer me-2"></i>ส่งออกข้อมูล (สำหรับพิมพ์)
</a>
</div>
</div>
<!-- <div class="row">
<div class="col-12 mt-3">
<a href="profile.php" class="btn btn-dark w-100 py-2 shadow-sm">
<i class="bi bi-person-gear me-2"></i>
จัดการโปรไฟล์
</a>
</div>
</div> -->
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php if($_SESSION['user_type'] == 'admin'): ?>
<div class="row">
<div class="col-12">
<div class="card shadow-sm">
<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-6 col-lg-3 mb-3">
<a href="admin_stats.php" class="btn btn-primary w-100 py-3 shadow-sm">
<i class="bi bi-bar-chart me-2"></i>
สถิติภาพรวม
</a>
</div>
<div class="col-md-6 col-lg-3 mb-3">
<a href="admin_reports.php" class="btn btn-success w-100 py-3 shadow-sm">
<i class="bi bi-file-earmark-text me-2"></i>
รายงานโดยละเอียด
</a>
</div>
<div class="col-md-6 col-lg-3 mb-3">
<a href="manage_users.php" class="btn btn-warning w-100 py-3 shadow-sm">
<i class="bi bi-people me-2"></i>
จัดการผู้ใช้
</a>
</div>
<div class="col-md-6 col-lg-3 mb-3">
<a href="system_settings.php" class="btn btn-info w-100 py-3 shadow-sm">
<i class="bi bi-gear me-2"></i>
ตั้งค่าระบบ
</a>
</div>
</div>
<div class="row mt-3">
<h6 class="text-muted fw-bold mt-3 mb-2">ส่งออกข้อมูลทั้งหมด:</h6>
<div class="col-md-6 mb-3">
<a href="export_data.php" class="btn btn-secondary w-100 py-2 shadow-sm">
<i class="bi bi-file-earmark-excel me-2"></i>ส่งออกข้อมูล (Excel)
</a>
</div>
<div class="col-md-6 mb-3">
<a href="export_print.php" target="_blank" class="btn btn-dark w-100 py-2 shadow-sm">
<i class="bi bi-printer me-2"></i>ส่งออกข้อมูล (สำหรับพิมพ์)
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php if($_SESSION['user_type'] == 'school'): ?>
<div class="row mt-4">
<div class="col-12">
<div class="card shadow-sm">
<div class="card-header">
<h5 class="mb-0">
<i class="bi bi-clock-history me-2"></i>
กิจกรรมล่าสุด
</h5>
</div>
<div class="card-body">
<?php
$user_id = $_SESSION['user_id'];
$sql_recent = "SELECT 'continue' as type, scs.created_at, scs.student_count,
CONCAT(un.name, ' - ', fn.name, ' - ', fd.name) as detail_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'
UNION ALL
SELECT 'work' as type, sw.created_at, sw.student_count, 'การประกอบอาชีพ' as detail_name
FROM student_work sw
WHERE sw.user_id = $user_id AND sw.academic_year = '$current_year'
ORDER BY created_at DESC LIMIT 5";
$result_recent = mysqli_query($conn, $sql_recent);
if($result_recent && mysqli_num_rows($result_recent) > 0):
?>
<div class="list-group list-group-flush">
<?php while($row = mysqli_fetch_assoc($result_recent)): ?>
<div class="list-group-item border-0 px-0">
<div class="d-flex justify-content-between align-items-center">
<div>
<i class="bi bi-<?php echo ($row['type'] == 'continue') ? 'mortarboard' : 'briefcase'; ?> me-2 text-primary"></i>
<span class="fw-semibold">
<?php echo ($row['type'] == 'continue') ? 'เรียนต่อ' : 'ประกอบอาชีพ'; ?>
</span>
- <?php echo htmlspecialchars($row['detail_name']); ?>
<span class="badge bg-secondary ms-2"><?php echo number_format($row['student_count']); ?> คน</span>
</div>
<small class="text-muted">
<?php echo date('d/m/Y H:i', strtotime($row['created_at'])); ?>
</small>
</div>
</div>
<?php endwhile; ?>
</div>
<?php else: ?>
<div class="text-center text-muted py-3">
<i class="bi bi-inbox display-4"></i>
<p class="mt-2">ยังไม่มีข้อมูลการบันทึก</p>
<?php if(!$result_recent): ?>
<small class="text-danger">
เกิดข้อผิดพลาด: <?php echo mysqli_error($conn); ?>
</small>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php include 'template/footer.php'; ?>