MOON
Server: Apache
System: Linux e2e-78-16.ssdcloudindia.net 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
User: imensosw (1005)
PHP: 8.0.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/imensosw/demo.imensosoftware.com/matrix/admin/assignment_completed.php
<?php 
include 'admin_header.php';

/**
 * ============================
 * HANDLE RE-ASSIGN (OPTIMIZED)
 * ============================
 */
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['doc_no']) && !empty($_POST['operator_id'])) {

    $docNos = array_map('intval', $_POST['doc_no']);
    $operator_id = (int) $_POST['operator_id'];

    $docList = implode(',', $docNos);

    // ✅ Single query
    $stmt = $conn->prepare("
        UPDATE assignments 
        SET user_id = ?, assignment_status_id = 1 
        WHERE assignment_no IN ($docList)
    ");

    $stmt->bind_param("i", $operator_id);
    $stmt->execute();
}

/**
 * ============================
 * FETCH COMPLETED DATA
 * ============================
 */
$sql = "
SELECT 
    a.assignment_no,
    a.no_of_record,
    a.assignment_date,
    a.submit_date,
    u.name
FROM assignments a
JOIN users u ON u.id = a.user_id
WHERE a.assignment_status_id = 2 
AND a.deleted = 0
ORDER BY a.submit_date DESC
";

$result = $conn->query($sql);

$total = 0;
?>

<div class="container" style="background:#fff; margin-top:42px">
<div class="assignment-dashboard">

<!-- DOWNLOAD FORM -->
<form action="download_excel.php" method="post" id="download_form">
<input type="hidden" name="list[]" id="list">
</form>

<form method="POST">
<div class="row">

<!-- LEFT -->
<div class="col-sm-8 border-right">
<h5 class="mt-3 mb-3">
COMPLETED FOLDERS 
<span class="font-weight-light small text-info total_count">[0]</span>
<div class="pull-right">
<strong class="badge badge-secondary checked_count">0</strong>
<button type="button" id="download_excel" class="btn btn-primary">Download XLS</button>
</div>
</h5>

<input type="text" class="mb-3 assignment_complete" placeholder="Search: [Folder Index/User]" id="search" style="width:100%; text-align:center;">

<div class="table-responsive">
<table id="assignment_complete_table" class="table table-striped table-sm table-bordered">
<thead>
<tr>
<th>Action</th>
<th>Folder</th>
<th>Count</th>
<th>Completed By</th>
<th>Assigned</th>
<th>Completed</th>
</tr>
</thead>
<tbody>

<?php while($row = $result->fetch_assoc()):
$total += $row['no_of_record'];
?>
<tr>
<td>
<input type="checkbox" class="chk_doc_no" value="<?= $row['assignment_no'] ?>" file_count="<?= $row['no_of_record'] ?>">
</td>
<td>
<a href="show_doc.php?assignment_no=<?= urlencode($row['assignment_no']) ?>" target="_blank">
<?= htmlspecialchars($row['assignment_no']) ?>
</a>
</td>
<td><?= $row['no_of_record'] ?></td>
<td><?= htmlspecialchars($row['name']) ?></td>
<td><?= date('m/d/Y', strtotime($row['assignment_date'])) ?></td>
<td><?= date('m/d/Y', strtotime($row['submit_date'])) ?></td>
</tr>
<?php endwhile; ?>

</tbody>
</table>
</div>
</div>

<!-- RIGHT -->
<div class="col-sm-4">
<h5 class="mt-3 mb-3">RE-ASSIGN TO:</h5>

<?php
$sqlUsers = "
SELECT u.id, u.name, COALESCE(SUM(a.no_of_record),0) as no_of_pending
FROM users u
JOIN role_user r ON r.user_id = u.id
LEFT JOIN assignments a 
    ON a.user_id = u.id AND a.assignment_status_id = 1
WHERE r.role_id IN (2,3)
GROUP BY u.id
";

$resUsers = $conn->query($sqlUsers);

while($row = $resUsers->fetch_assoc()):
?>

<div class="card mb-3">
<div class="card-body">
<div class="card-text pull-left">
<img src="../images/user.png" class="rounded-circle border mr-3" width="36">
<strong><?= htmlspecialchars($row["name"]) ?></strong>
<span class="badge badge-info"><?= $row["no_of_pending"] ?></span>
</div>
<div class="card-link pull-right" style="margin-top:6px;">
<input type="radio" name="operator_id" value="<?= $row["id"] ?>">
</div>
</div>
</div>

<?php endwhile; ?>

<div class="text-right">
<input class="btn btn-primary" type="submit" name="save" value="Assign">
</div>

</div>
</div>
</form>
</div>
</div>

<script>
document.addEventListener("DOMContentLoaded", function(){

    document.querySelector(".total_count").innerText = "[<?= $total ?>]";

    document.querySelectorAll(".chk_doc_no").forEach(el => {
        el.addEventListener("change", function(){
            let total = 0;
            document.querySelectorAll(".chk_doc_no:checked").forEach(chk => {
                total += parseInt(chk.getAttribute("file_count")) || 0;
            });
            document.querySelector(".checked_count").innerText = total;
        });
    });

    // DOWNLOAD
    document.getElementById("download_excel").addEventListener("click", function(){

        let selected = [];
        document.querySelectorAll(".chk_doc_no:checked").forEach(chk => {
            selected.push(chk.value);
        });

        if (selected.length === 0) return;

        document.getElementById("list").value = selected.join(",");
        document.getElementById("download_form").submit();
    });

});
</script>

<?php $conn->close(); ?>