146 lines
7.2 KiB
PHP
146 lines
7.2 KiB
PHP
<?php
|
|
require_once 'config.php';
|
|
requireLogin();
|
|
|
|
// This page is for students
|
|
if (isAdmin()) {
|
|
header('Location: assignments.php');
|
|
exit;
|
|
}
|
|
|
|
$user_id = $_SESSION['user_id'];
|
|
|
|
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">งานของฉัน</h2>
|
|
<p class="text-gray-600 mt-1">รายการงานที่ได้รับมอบหมายทั้งหมด</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="bg-white rounded-lg shadow-md p-6">
|
|
<table class="dataTable display w-full text-sm text-left text-gray-500">
|
|
<thead class="text-xs text-gray-700 uppercase bg-gray-50">
|
|
<tr>
|
|
<th class="text-center w-16">ลำดับ</th>
|
|
<th class="text-center">ชื่องาน/ชื่อวิชา</th>
|
|
<th class="text-center">รายละเอียด</th>
|
|
<th class="text-center w-32">วันที่เพิ่มข้อมูล</th>
|
|
<th class="text-center">กำหนดส่ง</th>
|
|
<th class="text-center w-24">สถานะ</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php
|
|
$days_before = getSetting($pdo, 'days_before_due') ?: 3;
|
|
$stmt = $pdo->prepare("SELECT *, DATEDIFF(due_date, CURDATE()) as days_left FROM assignments WHERE student_id = ? ORDER BY id DESC");
|
|
$stmt->execute([$user_id]);
|
|
$index = 1;
|
|
while ($row = $stmt->fetch()):
|
|
// Get all assigned students for this specific task
|
|
$stmt_group = $pdo->prepare("SELECT u.name FROM assignments a JOIN users u ON a.student_id = u.id WHERE a.title = ? AND a.due_date = ?");
|
|
$stmt_group->execute([$row['title'], $row['due_date']]);
|
|
$assigned_names = $stmt_group->fetchAll(PDO::FETCH_COLUMN);
|
|
$assigned_list = implode(', ', $assigned_names);
|
|
|
|
// Format Created At
|
|
$created_timestamp = strtotime($row['created_at']);
|
|
$created_date_th = date('d-m-', $created_timestamp) . (date('Y', $created_timestamp) + 543);
|
|
|
|
// Format Due Date
|
|
$due_timestamp = strtotime($row['due_date']);
|
|
$due_date_th = date('d-m-', $due_timestamp) . (date('Y', $due_timestamp) + 543);
|
|
|
|
$due_html = "<span>{$due_date_th}</span>";
|
|
$status_text = "รอดำเนินการ";
|
|
if ($row['status'] === 'pending') {
|
|
if ($row['days_left'] < 0) {
|
|
$due_html .= " <span class=\"bg-gray-800 text-white text-xs px-2 py-0.5 rounded ml-2 whitespace-nowrap\">เลยกำหนด " . abs($row['days_left']) . " วัน</span>";
|
|
} elseif ($row['days_left'] <= $days_before) {
|
|
$due_html .= " <span class=\"bg-orange-500 text-white text-xs px-2 py-0.5 rounded ml-2 whitespace-nowrap\">เหลือ {$row['days_left']} วัน</span>";
|
|
} else {
|
|
$due_html .= " <span class=\"bg-gray-100 text-gray-600 text-xs px-2 py-0.5 rounded ml-2 whitespace-nowrap\">เหลือ {$row['days_left']} วัน</span>";
|
|
}
|
|
} else {
|
|
$status_text = "เสร็จสิ้น";
|
|
}
|
|
?>
|
|
<tr class="bg-white border-b hover:bg-gray-50">
|
|
<td class="text-center"><?= $index++ ?></td>
|
|
<td class="font-medium text-gray-900"><?= htmlspecialchars($row['title']) ?></td>
|
|
<td class="text-center">
|
|
<button type="button"
|
|
onclick="showDetails(
|
|
'<?= htmlspecialchars(addslashes($row['title'])) ?>',
|
|
'<?= htmlspecialchars(addslashes($row['description'] ?: '-')) ?>',
|
|
'<?= htmlspecialchars(addslashes($assigned_list)) ?>',
|
|
'<?= $due_date_th ?>',
|
|
'<?= $status_text ?>'
|
|
)"
|
|
class="text-blue-600 hover:text-blue-800 bg-blue-50 hover:bg-blue-100 px-3 py-1 rounded-full text-xs font-semibold transition-colors">
|
|
<i class="fas fa-info-circle mr-1"></i> ดูรายละเอียด
|
|
</button>
|
|
</td>
|
|
<td class="text-center"><?= $created_date_th ?></td>
|
|
<td class="text-center"><?= $due_html ?></td>
|
|
<td class="text-center">
|
|
<?php if ($row['status'] === 'submitted' || $row['status'] === 'completed'): ?>
|
|
<span class="bg-green-100 text-green-800 py-1 px-2 rounded-full text-xs font-semibold">เสร็จสิ้น</span>
|
|
<?php else: ?>
|
|
<span class="bg-yellow-100 text-yellow-800 py-1 px-2 rounded-full text-xs font-semibold">รอดำเนินการ</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<?php endwhile; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
|
|
<script>
|
|
function showDetails(title, desc, assignedTo, dueDate, status) {
|
|
const statusColor = status === 'เสร็จสิ้น' ? 'text-green-600' : 'text-yellow-600';
|
|
|
|
let htmlContent = `
|
|
<div class="text-left space-y-4 text-sm mt-4">
|
|
<div class="bg-gray-50 p-3 rounded border">
|
|
<p class="text-gray-500 mb-1"><i class="fas fa-align-left mr-2"></i><strong>รายละเอียดงาน:</strong></p>
|
|
<p class="text-gray-800 whitespace-pre-wrap">${desc}</p>
|
|
</div>
|
|
|
|
<div class="flex items-center justify-between border-b pb-2">
|
|
<span class="text-gray-500"><i class="fas fa-users mr-2"></i><strong>ผู้ที่ถูกมอบหมาย:</strong></span>
|
|
<span class="text-gray-800 text-right ml-4">${assignedTo}</span>
|
|
</div>
|
|
|
|
<div class="flex items-center justify-between border-b pb-2">
|
|
<span class="text-gray-500"><i class="far fa-calendar-alt mr-2"></i><strong>วันที่กำหนดส่ง:</strong></span>
|
|
<span class="text-gray-800 font-medium">${dueDate}</span>
|
|
</div>
|
|
|
|
<div class="flex items-center justify-between pb-2">
|
|
<span class="text-gray-500"><i class="fas fa-info-circle mr-2"></i><strong>สถานะปัจจุบัน:</strong></span>
|
|
<span class="font-bold ${statusColor}">${status}</span>
|
|
</div>
|
|
</div>
|
|
`;
|
|
|
|
Swal.fire({
|
|
title: `<div class="text-xl text-blue-700 font-bold border-b pb-3">${title}</div>`,
|
|
html: htmlContent,
|
|
width: 600,
|
|
showCloseButton: true,
|
|
confirmButtonText: 'ปิดหน้าต่าง',
|
|
confirmButtonColor: '#3085d6',
|
|
customClass: {
|
|
title: 'mb-0'
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<?php include 'includes/footer.php'; ?>
|