| Server IP : 104.21.80.248 / 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/pr/ |
Upload File : |
<?php
include 'functions.php';
// ตรวจสอบสิทธิ์ (บล็อก user ทั่วไป)
if(!isset($_SESSION['user_id']) || $_SESSION['role'] == 'user') {
echo "<script>alert('คุณไม่มีสิทธิ์เข้าถึงหน้านี้'); window.location='dashboard.php';</script>";
exit();
}
$role = $_SESSION['role'];
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
$limit = 20;
$offset = ($page - 1) * $limit;
// ==========================================
// อัปเดตสถานะอัตโนมัติ หากเลยวันที่ต้องใช้งานแล้ว
// ==========================================
$today = date('Y-m-d');
mysqli_query($conn, "UPDATE requests SET status = 'done' WHERE status = 'pending' AND end_date < '$today'");
mysqli_query($conn, "UPDATE meeting_requests SET status = 'done' WHERE status = 'pending' AND end_date < '$today'");
// ==========================================
// ส่วนที่ 1: ADMIN (ดูแลจอโทรทัศน์)
// ==========================================
if($role == 'admin') {
// Logic: อัปโหลดผลงาน (TV)
if(isset($_POST['upload_work'])) {
$req_id = intval($_POST['req_id']);
$chk_sql = "SELECT * FROM requests WHERE req_id = $req_id AND status = 'done' AND req_type = 'design'";
$chk_res = mysqli_query($conn, $chk_sql);
if(mysqli_num_rows($chk_res) > 0) {
if(isset($_FILES['admin_imgs'])) {
$total_files = count($_FILES['admin_imgs']['name']);
$count_success = 0;
for($i=0; $i<$total_files; $i++) {
if($_FILES['admin_imgs']['name'][$i] != "") {
$ext = pathinfo($_FILES['admin_imgs']['name'][$i], PATHINFO_EXTENSION);
$new_name = "DONE_" . time() . "_$i." . $ext;
if(move_uploaded_file($_FILES['admin_imgs']['tmp_name'][$i], "uploads/" . $new_name)){
mysqli_query($conn, "INSERT INTO request_images (req_id, filename, uploader_role) VALUES ('$req_id', '$new_name', 'admin')");
$count_success++;
}
}
}
if($count_success > 0){
echo "<script>alert('อัปโหลดผลงานเรียบร้อย จำนวน $count_success รูป'); window.location='admin_history.php';</script>";
}
}
}
}
echo get_header("ประวัติทั้งหมด - จอโทรทัศน์");
$sql_c = "SELECT COUNT(*) as total FROM requests";
$total_pages = ceil(mysqli_fetch_assoc(mysqli_query($conn, $sql_c))['total']/$limit);
$sql = "SELECT r.*, u.group_name FROM requests r JOIN users u ON r.user_id = u.user_id ORDER BY created_at DESC LIMIT $offset, $limit";
$result = mysqli_query($conn, $sql);
?>
<div class="d-flex justify-content-between align-items-center mb-4">
<h3 class="text-primary"><i class="bi bi-clock-history"></i> ประวัติและส่งมอบงาน (จอโทรทัศน์)</h3>
</div>
<div class="card shadow-sm border-0 border-top border-primary border-3">
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead class="table-light">
<tr>
<th class="ps-3">วันที่แจ้ง</th>
<th>กลุ่มงาน</th>
<th>หัวข้อ</th>
<th>ประเภท</th>
<th>ช่วงเวลาแสดงผล</th>
<th>สถานะ</th>
<th class="text-center">จัดการ / ส่งงาน</th>
</tr>
</thead>
<tbody>
<?php if(mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$modal_id = "adminModal_" . $row['req_id'];
$is_done = ($row['status'] == 'done');
$is_design = ($row['req_type'] == 'design');
?>
<tr>
<td class="ps-3 text-secondary small"><?php echo thai_date($row['created_at']); ?></td>
<td><span class="fw-bold text-dark"><?php echo $row['group_name']; ?></span></td>
<td><a href="#" class="text-decoration-none fw-bold text-primary" data-bs-toggle="modal" data-bs-target="#<?php echo $modal_id; ?>"><?php echo $row['title']; ?></a></td>
<td><?php echo ($row['req_type']=='ready') ? '<span class="badge rounded-pill bg-light text-success border border-success">ทำรูปแล้ว</span>' : '<span class="badge rounded-pill bg-light text-warning border border-warning">ให้จัดทำ</span>'; ?></td>
<td class="small text-muted"><?php echo thai_date($row['start_date']) . " - " . thai_date($row['end_date']); ?></td>
<td><?php echo $is_done ? '<span class="badge bg-primary">ดำเนินการแล้ว</span>' : '<span class="badge bg-danger">รอ (Pending)</span>'; ?></td>
<td class="text-center">
<?php if(!$is_done){ ?>
<a href="dashboard.php?mark_done=<?php echo $row['req_id']; ?>" class="btn btn-sm btn-outline-success" onclick="return confirm('ยืนยันจบงาน?');"><i class="bi bi-check-circle"></i> จบงาน</a>
<?php } else { ?>
<?php if($is_design) { ?>
<button class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#<?php echo $modal_id; ?>"><i class="bi bi-cloud-upload"></i> ส่งไฟล์งาน</button>
<?php } else { ?>
<span class="text-success small"><i class="bi bi-check-all"></i> เรียบร้อย</span>
<?php } ?>
<?php } ?>
</td>
</tr>
<div class="modal fade" id="<?php echo $modal_id; ?>" tabindex="-1">
<div class="modal-dialog modal-lg">
<div class="modal-content border-primary border-top border-3">
<div class="modal-header bg-white">
<h5 class="modal-title text-primary"><i class="bi bi-tv"></i> รายละเอียด: <?php echo $row['title']; ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div class="row mb-3">
<div class="col-md-6">
<p class="mb-1"><strong>ผู้ร้องขอ:</strong> <span class="text-primary"><?php echo $row['group_name']; ?></span></p>
<p class="mb-1"><strong>ประเภท:</strong> <?php echo ($is_design)?'ให้จัดทำรูป (Design)':'มีรูปมาแล้ว (Ready)'; ?></p>
</div>
<div class="col-md-6">
<p class="mb-1"><strong>สถานะ:</strong> <?php echo $is_done ? '<span class="text-success">Finished</span>' : '<span class="text-danger">Pending</span>'; ?></p>
<p class="mb-1"><strong>ช่วงเวลา:</strong> <?php echo thai_date($row['start_date']) . " - " . thai_date($row['end_date']); ?></p>
</div>
</div>
<div class="alert alert-light border"><strong>รายละเอียดความต้องการ:</strong><br><?php echo nl2br($row['details'] ? $row['details'] : "-"); ?></div>
<div class="row">
<div class="col-md-6 border-end">
<h6 class="text-muted border-bottom pb-2"><i class="bi bi-person"></i> ไฟล์แนบจากผู้ขอ (Reference)</h6>
<div class="d-flex flex-wrap gap-2">
<?php
$res_m = mysqli_query($conn, "SELECT filename FROM request_images WHERE req_id = ".$row['req_id']." AND (uploader_role = 'user' OR uploader_role IS NULL)");
if(mysqli_num_rows($res_m) > 0){
while($img_m = mysqli_fetch_assoc($res_m)){
echo "<a href='uploads/".$img_m['filename']."' target='_blank'><img src='uploads/".$img_m['filename']."' class='img-thumbnail' style='height:80px; object-fit:cover;'></a>";
}
} else { echo "<span class='text-muted small'>- ไม่มีไฟล์แนบ -</span>"; }
?>
</div>
</div>
<div class="col-md-6 bg-light p-2 rounded">
<h6 class="text-primary border-bottom pb-2"><i class="bi bi-palette"></i> ผลงานที่ทำเสร็จแล้ว (Admin)</h6>
<div class="d-flex flex-wrap gap-2 mb-3">
<?php
$res_admin = mysqli_query($conn, "SELECT filename FROM request_images WHERE req_id = ".$row['req_id']." AND uploader_role = 'admin'");
if(mysqli_num_rows($res_admin) > 0){
while($img_a = mysqli_fetch_assoc($res_admin)){
echo "<a href='uploads/".$img_a['filename']."' target='_blank'><img src='uploads/".$img_a['filename']."' class='img-thumbnail border-primary' style='height:80px; object-fit:cover;'></a>";
}
} else { echo "<span class='text-muted small'>- ยังไม่มีการอัปโหลดผลงาน -</span>"; }
?>
</div>
<?php if($is_done && $is_design) { ?>
<form method="post" enctype="multipart/form-data" class="border-top pt-2">
<input type="hidden" name="req_id" value="<?php echo $row['req_id']; ?>">
<label class="form-label small fw-bold">อัปโหลดผลงานเพิ่ม:</label>
<div class="input-group input-group-sm">
<input type="file" name="admin_imgs[]" class="form-control" multiple accept="image/*" required>
<button class="btn btn-primary" type="submit" name="upload_work"><i class="bi bi-upload"></i> อัปโหลด</button>
</div>
</form>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php }} else { echo "<tr><td colspan='7' class='text-center py-5 text-muted'>ยังไม่มีข้อมูล</td></tr>"; } ?>
</tbody>
</table>
</div>
</div>
</div>
<?php
// ==========================================
// ส่วนที่ 2: ADMIN MEETING (ดูแลจอห้องประชุม)
// ==========================================
} else if($role == 'admin_meeting') {
echo get_header("ประวัติทั้งหมด - จอห้องประชุม");
$sql_c = "SELECT COUNT(*) as total FROM meeting_requests";
$total_pages = ceil(mysqli_fetch_assoc(mysqli_query($conn, $sql_c))['total']/$limit);
$sql_m = "SELECT m.*, u.group_name FROM meeting_requests m JOIN users u ON m.user_id = u.user_id ORDER BY created_at DESC LIMIT $offset, $limit";
$result_m = mysqli_query($conn, $sql_m);
?>
<div class="d-flex justify-content-between align-items-center mb-4">
<h3 class="text-success"><i class="bi bi-clock-history"></i> ประวัติการใช้งาน (จอห้องประชุม)</h3>
</div>
<div class="card shadow-sm border-0 border-top border-success border-3">
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead class="table-light">
<tr>
<th class="ps-3">วันที่แจ้ง</th>
<th>กลุ่มงาน</th>
<th>หัวข้อการประชุม</th>
<th>ห้องประชุม</th>
<th>ช่วงเวลาใช้งาน</th>
<th>สถานะ</th>
<th class="text-center">จัดการ</th>
</tr>
</thead>
<tbody>
<?php if(mysqli_num_rows($result_m) > 0) {
while($row_m = mysqli_fetch_assoc($result_m)) {
$modal_id = "adminMtgModal_" . $row_m['mreq_id'];
$is_done = ($row_m['status'] == 'done');
?>
<tr>
<td class="ps-3 text-secondary small"><?php echo thai_date($row_m['created_at']); ?></td>
<td><span class="fw-bold text-dark"><?php echo $row_m['group_name']; ?></span></td>
<td><a href="#" class="text-decoration-none fw-bold text-success" data-bs-toggle="modal" data-bs-target="#<?php echo $modal_id; ?>"><?php echo $row_m['topic']; ?></a></td>
<td><span class="badge bg-light text-dark border border-secondary"><?php echo $row_m['room']; ?></span></td>
<td class="small text-muted"><?php echo ($row_m['date_type']=='single') ? thai_date($row_m['start_date']) : thai_date($row_m['start_date']) . " - " . thai_date($row_m['end_date']); ?></td>
<td><?php echo $is_done ? '<span class="badge bg-primary">ดำเนินการแล้ว</span>' : '<span class="badge bg-danger">รอ (Pending)</span>'; ?></td>
<td class="text-center">
<?php if(!$is_done){ ?>
<a href="dashboard.php?mark_mtg_done=<?php echo $row_m['mreq_id']; ?>" class="btn btn-sm btn-outline-success" onclick="return confirm('ยืนยันจบงาน?');"><i class="bi bi-check-circle"></i> จบงาน</a>
<?php } else { ?>
<span class="text-success small"><i class="bi bi-check-all"></i> เรียบร้อย</span>
<?php } ?>
</td>
</tr>
<div class="modal fade" id="<?php echo $modal_id; ?>" tabindex="-1">
<div class="modal-dialog modal-lg">
<div class="modal-content border-success border-top border-3">
<div class="modal-header bg-white">
<h5 class="modal-title text-success"><i class="bi bi-projector"></i> รายละเอียด: <?php echo $row_m['topic']; ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div class="row mb-3">
<div class="col-md-6">
<p class="mb-1"><strong>ผู้ร้องขอ:</strong> <span class="text-success"><?php echo $row_m['group_name']; ?></span></p>
<p class="mb-1"><strong>ห้องประชุม:</strong> <span class="badge bg-success"><?php echo $row_m['room']; ?></span></p>
</div>
<div class="col-md-6">
<p class="mb-1"><strong>สถานะ:</strong> <?php echo $is_done ? '<span class="text-success">Finished</span>' : '<span class="text-danger">Pending</span>'; ?></p>
<p class="mb-1"><strong>ช่วงเวลาใช้งาน:</strong> <?php echo ($row_m['date_type']=='single') ? thai_date($row_m['start_date']) : thai_date($row_m['start_date']) . " - " . thai_date($row_m['end_date']); ?></p>
</div>
</div>
<div class="alert alert-light border">
<strong class="d-block mb-2"><i class="bi bi-paperclip"></i> ไฟล์ที่แนบมา:</strong>
<div class="d-flex flex-wrap gap-2">
<?php
$res_f = mysqli_query($conn, "SELECT * FROM meeting_files WHERE mreq_id = ".$row_m['mreq_id']);
if(mysqli_num_rows($res_f) > 0){
while($file = mysqli_fetch_assoc($res_f)){
$ext = strtolower(pathinfo($file['filename'], PATHINFO_EXTENSION));
$is_image = in_array($ext, ['jpg','jpeg','png','gif','webp']);
if($is_image){
echo "<a href='uploads/".$file['filename']."' target='_blank'><img src='uploads/".$file['filename']."' class='img-thumbnail border-success' style='height:80px; width:80px; object-fit:cover;' title='".$file['original_name']."'></a>";
} else {
echo "<a href='uploads/".$file['filename']."' target='_blank' class='btn btn-outline-secondary p-1 d-flex flex-column align-items-center justify-content-center shadow-sm' style='height:80px; width:80px;' title='".$file['original_name']."'>
<i class='bi bi-file-earmark-text fs-4'></i><span class='small text-truncate w-100 mt-1' style='font-size:10px;'>".strtoupper($ext)."</span>
</a>";
}
}
} else { echo "<span class='text-muted small'>- ไม่มีไฟล์แนบ -</span>"; }
?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php }} else { echo "<tr><td colspan='7' class='text-center py-5 text-muted'>ยังไม่มีข้อมูลจอห้องประชุม</td></tr>"; } ?>
</tbody>
</table>
</div>
</div>
</div>
<?php } ?>
<?php if(isset($total_pages) && $total_pages > 1) { ?>
<nav class="mt-4">
<ul class="pagination justify-content-center">
<?php for($i=1; $i<=$total_pages; $i++){ ?>
<li class="page-item <?php echo ($i==$page)?'active':''; ?>">
<a class="page-link" href="?page=<?php echo $i; ?>"><?php echo $i; ?></a>
</li>
<?php } ?>
</ul>
</nav>
<?php } ?>
<?php echo get_footer(); ?>