199 lines
9.2 KiB
PHP
199 lines
9.2 KiB
PHP
<?php
|
|
require_once 'config.php';
|
|
requireLogin();
|
|
|
|
$user_id = $_SESSION['user_id'];
|
|
$role = $_SESSION['role'];
|
|
|
|
// Get statistics
|
|
$stats = [];
|
|
if ($role === 'admin') {
|
|
$stmt = $pdo->query("SELECT COUNT(*) FROM assignments");
|
|
$stats['total_assignments'] = $stmt->fetchColumn();
|
|
|
|
$stmt = $pdo->query("SELECT COUNT(*) FROM assignments WHERE status = 'pending'");
|
|
$stats['pending_assignments'] = $stmt->fetchColumn();
|
|
|
|
$stmt = $pdo->query("SELECT COUNT(*) FROM assignments WHERE status = 'completed'");
|
|
$stats['completed_assignments'] = $stmt->fetchColumn();
|
|
|
|
$stmt = $pdo->query("SELECT COUNT(*) FROM users WHERE role = 'student'");
|
|
$stats['total_students'] = $stmt->fetchColumn();
|
|
} else {
|
|
$stmt = $pdo->prepare("SELECT COUNT(*) FROM assignments WHERE student_id = ?");
|
|
$stmt->execute([$user_id]);
|
|
$stats['total_assignments'] = $stmt->fetchColumn();
|
|
|
|
$stmt = $pdo->prepare("SELECT COUNT(*) FROM assignments WHERE student_id = ? AND status = 'pending'");
|
|
$stmt->execute([$user_id]);
|
|
$stats['pending_assignments'] = $stmt->fetchColumn();
|
|
|
|
$stmt = $pdo->prepare("SELECT COUNT(*) FROM assignments WHERE student_id = ? AND status = 'completed'");
|
|
$stmt->execute([$user_id]);
|
|
$stats['completed_assignments'] = $stmt->fetchColumn();
|
|
}
|
|
|
|
include 'includes/header.php';
|
|
include 'includes/sidebar.php';
|
|
?>
|
|
|
|
<div class="mb-6 flex justify-between items-center">
|
|
<div>
|
|
<h2 class="text-2xl font-bold text-gray-800">ยินดีต้อนรับ, <?= htmlspecialchars($_SESSION['name']) ?>!</h2>
|
|
<p class="text-gray-600 mt-1">ภาพรวมระบบการแจ้งเตือนงานของคุณ</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="grid grid-cols-1 md:grid-cols-4 gap-4 mb-8">
|
|
<div class="bg-white rounded-lg shadow-md p-5 border-l-4 border-blue-500 cursor-pointer hover:bg-blue-50 transition" onclick="filterTable('all', 'งานทั้งหมด')">
|
|
<div class="flex items-center">
|
|
<div class="p-3 rounded-full bg-blue-100 text-blue-500 mr-4">
|
|
<i class="fas fa-tasks fa-xl"></i>
|
|
</div>
|
|
<div>
|
|
<p class="text-gray-500 text-xs font-semibold uppercase">งานทั้งหมด</p>
|
|
<p class="text-xl font-bold text-gray-800"><?= $stats['total_assignments'] ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="bg-white rounded-lg shadow-md p-5 border-l-4 border-yellow-500 cursor-pointer hover:bg-yellow-50 transition" onclick="filterTable('pending', 'งานที่ค้างส่ง (รอดำเนินการ)')">
|
|
<div class="flex items-center">
|
|
<div class="p-3 rounded-full bg-yellow-100 text-yellow-500 mr-4">
|
|
<i class="fas fa-clock fa-xl"></i>
|
|
</div>
|
|
<div>
|
|
<p class="text-gray-500 text-xs font-semibold uppercase">รอดำเนินการ</p>
|
|
<p class="text-xl font-bold text-gray-800"><?= $stats['pending_assignments'] ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="bg-white rounded-lg shadow-md p-5 border-l-4 border-green-500 cursor-pointer hover:bg-green-50 transition" onclick="filterTable('completed', 'งานที่เสร็จสิ้นแล้ว')">
|
|
<div class="flex items-center">
|
|
<div class="p-3 rounded-full bg-green-100 text-green-500 mr-4">
|
|
<i class="fas fa-check-circle fa-xl"></i>
|
|
</div>
|
|
<div>
|
|
<p class="text-gray-500 text-xs font-semibold uppercase">เสร็จสิ้น</p>
|
|
<p class="text-xl font-bold text-gray-800"><?= $stats['completed_assignments'] ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($role === 'admin'): ?>
|
|
<div class="bg-white rounded-lg shadow-md p-5 border-l-4 border-purple-500 cursor-pointer hover:bg-purple-50 transition" onclick="window.location.href='users.php'">
|
|
<div class="flex items-center">
|
|
<div class="p-3 rounded-full bg-purple-100 text-purple-500 mr-4">
|
|
<i class="fas fa-users fa-xl"></i>
|
|
</div>
|
|
<div>
|
|
<p class="text-gray-500 text-xs font-semibold uppercase">นักเรียนทั้งหมด</p>
|
|
<p class="text-xl font-bold text-gray-800"><?= $stats['total_students'] ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="bg-white rounded-lg shadow-md p-5 border-l-4 border-red-500 cursor-pointer hover:bg-red-50 transition" onclick="filterTable('urgent', 'งานที่ใกล้กำหนดส่ง')">
|
|
<div class="flex items-center">
|
|
<div class="p-3 rounded-full bg-red-100 text-red-500 mr-4">
|
|
<i class="fas fa-exclamation-triangle fa-xl"></i>
|
|
</div>
|
|
<div>
|
|
<p class="text-gray-500 text-xs font-semibold uppercase">ใกล้กำหนดส่ง</p>
|
|
<p class="text-xl font-bold text-gray-800">-</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div class="bg-white rounded-lg shadow-md p-6">
|
|
<div class="flex justify-between items-center mb-4 pb-2 border-b">
|
|
<h3 id="tableTitle" class="text-lg font-bold text-gray-800"><i class="fas fa-exclamation-circle text-red-500 mr-2"></i> งานที่ใกล้กำหนดส่ง</h3>
|
|
<button onclick="filterTable('urgent', 'งานที่ใกล้กำหนดส่ง')" class="text-xs bg-gray-100 hover:bg-gray-200 text-gray-700 py-1 px-2 rounded border">
|
|
<i class="fas fa-filter"></i> คืนค่า (ใกล้กำหนดส่ง)
|
|
</button>
|
|
</div>
|
|
|
|
<table id="dashboardTable" class="dataTable display min-w-full bg-white w-full">
|
|
<thead class="bg-gray-100 text-gray-600">
|
|
<tr>
|
|
<th class="py-3 px-4 text-center font-semibold text-sm border-b w-16">ลำดับ</th>
|
|
<th class="py-3 px-4 text-center font-semibold text-sm border-b">ชื่องาน/ชื่อวิชา</th>
|
|
<?php if ($role === 'admin'): ?>
|
|
<th class="py-3 px-4 text-center font-semibold text-sm border-b">นักเรียน</th>
|
|
<?php endif; ?>
|
|
<th class="py-3 px-4 text-center font-semibold text-sm border-b w-32">วันที่เพิ่มข้อมูล</th>
|
|
<th class="py-3 px-4 text-center font-semibold text-sm border-b">กำหนดส่ง</th>
|
|
<th class="py-3 px-4 text-center font-semibold text-sm border-b w-24">สถานะ</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="text-gray-700">
|
|
<!-- Data will be loaded via AJAX -->
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<!-- DataTables Export Plugins -->
|
|
<script src="https://cdn.datatables.net/buttons/2.4.1/js/dataTables.buttons.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
|
|
<script src="https://cdn.datatables.net/buttons/2.4.1/js/buttons.html5.min.js"></script>
|
|
|
|
<script>
|
|
let dashboardTable;
|
|
|
|
$(document).ready(function() {
|
|
// Determine columns based on role
|
|
const columns = [
|
|
{ data: 'index', className: 'text-center' },
|
|
{ data: 'title' },
|
|
<?php if ($role === 'admin'): ?>
|
|
{ data: 'student' },
|
|
<?php endif; ?>
|
|
{ data: 'created_at', className: 'text-center' },
|
|
{ data: 'due_date', className: 'text-center' },
|
|
{ data: 'status', className: 'text-center' }
|
|
];
|
|
|
|
dashboardTable = $('#dashboardTable').DataTable({
|
|
ajax: 'api/get_dashboard_table.php?filter=urgent',
|
|
columns: columns,
|
|
scrollX: true,
|
|
columnDefs: [{ className: "dt-head-center", targets: "_all" }],
|
|
pageLength: 10,
|
|
dom: '<"flex justify-between items-center mb-4"lBf>rt<"flex justify-between items-center mt-4"ip>',
|
|
buttons: [
|
|
{
|
|
extend: 'excelHtml5',
|
|
text: '<i class="fas fa-file-excel mr-1"></i> ส่งออก Excel',
|
|
className: 'bg-green-600 text-white hover:bg-green-700 px-3 py-1 rounded text-sm',
|
|
title: 'รายงานการส่งงาน',
|
|
exportOptions: {
|
|
columns: ':visible'
|
|
}
|
|
}
|
|
],
|
|
language: {
|
|
url: '//cdn.datatables.net/plug-ins/1.13.6/i18n/th.json'
|
|
}
|
|
});
|
|
});
|
|
|
|
function filterTable(filterType, titleText) {
|
|
// Update Title
|
|
let icon = '';
|
|
if (filterType === 'urgent') icon = '<i class="fas fa-exclamation-circle text-red-500 mr-2"></i>';
|
|
else if (filterType === 'all') icon = '<i class="fas fa-tasks text-blue-500 mr-2"></i>';
|
|
else if (filterType === 'pending') icon = '<i class="fas fa-clock text-yellow-500 mr-2"></i>';
|
|
else if (filterType === 'completed') icon = '<i class="fas fa-check-circle text-green-500 mr-2"></i>';
|
|
|
|
$('#tableTitle').html(icon + ' ' + titleText);
|
|
|
|
// Reload DataTable
|
|
dashboardTable.ajax.url('api/get_dashboard_table.php?filter=' + filterType).load();
|
|
}
|
|
</script>
|
|
|
|
<?php include 'includes/footer.php'; ?>
|