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_delete.php
<?php 
include 'admin_header.php';

// Better error handling (log only)
ini_set('log_errors', 1);
ini_set('error_log', __DIR__ . '/error.log');

/**
 * ============================
 * FETCH DATA (OPTIMIZED)
 * ============================
 */
$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 
    AND a.submit_date IS NOT NULL
    AND a.submit_date <= DATE_SUB(CURDATE(), INTERVAL 3 DAY)
ORDER BY a.submit_date ASC
";

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

$total = 0;
?>

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

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

<!-- LEFT SIDE -->
<div class="col-sm-8 border-right">

<h5 class="mt-3 mb-3">
    DELETE 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="delete_folder" class="btn btn-danger">
            Delete
        </button>
    </div>
</h5>

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

<div class="table-responsive">
<table id="assignment_delete_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_no1"
        value="<?= htmlspecialchars($row['assignment_no']) ?>"
        file_count="<?= $row['no_of_record'] ?>"
    >
</td>

<td><?= htmlspecialchars($row['assignment_no']) ?></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>

</div>
</form>

</div>
</div>

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

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

    // UPDATE CHECKED COUNT
    function updateCount(){
        let total = 0;

        document.querySelectorAll(".chk_doc_no1:checked").forEach(chk => {
            total += parseInt(chk.getAttribute("file_count")) || 0;
        });

        document.querySelector(".checked_count").innerText = total;
    }

    document.querySelectorAll(".chk_doc_no1").forEach(el => {
        el.addEventListener("change", updateCount);
    });

    // DELETE FUNCTION
    document.getElementById("delete_folder").addEventListener("click", function(){

        let selected = [];

        document.querySelectorAll(".chk_doc_no1:checked").forEach(chk => {
            selected.push(chk.value);
        });

        if (selected.length === 0) {
            alert("Please select at least one folder");
            return;
        }

        // if (!confirm("Are you sure you want to delete selected folders?")) {
        //     return;
        // }

        fetch("assignment_delete_code.php", {
            method: "POST",
            headers: {
                "Content-Type": "application/x-www-form-urlencoded"
            },
            body: "assignment_ids=" + selected.join(",")
        })
        .then(res => res.text())
        .then(res => {
            console.log(res);
            location.reload();
        })
        .catch(() => {
            alert("Something went wrong!");
        });

    });

});
</script>

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