Create New Item
×
Item Type
File
Folder
Item Name
×
Search file in folder and subfolders...
File Manager
/
admin
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php // Database connection include_once("header.php"); // Define tables and respective date columns $tableDateColumns = [ "card_log" => "created_at", "history_work" => "order_time", "logsn" => "created_at", "order_list" => "order_time", "tin_data" => "created_at", "server_copy" => "created_at" ]; // Bengali table names $tableNamesBn = [ "card_log" => "đ āĻāĻāĻĄāĻŋ āĻāĻžāϰā§āĻĄ āϞāĻŋāώā§āĻ", "history_work" => "đ āĻāĻžāĻā§āϰ āĻšāĻŋāϏā§āĻā§āϰāĻŋ āϞāĻŋāώā§āĻ", "logsn" => "đ āύāĻŋāĻŦāύā§āϧāύ āϞāĻŋāώā§āĻ", "order_list" => "đĻ āĻ āϰā§āĻĄāĻžāϰ āϞāĻŋāώā§āĻ", "tin_data" => "đī¸ āĻāĻŋāύ āĻĄāĻžāĻāĻž āϞāĻŋāώā§āĻ", "server_copy" => "đž āϏāĻžāϰā§āĻāĻžāϰ āĻāĻĒāĻŋ āϞāĻŋāώā§āĻ" ]; // Allowed days in Bengali $validDays = [1, 3, 5, 7, 15]; $validDaysBn = [ 1 => "ā§§ āĻĻāĻŋāύ", 3 => "ā§Š āĻĻāĻŋāύ", 5 => "ā§Ģ āĻĻāĻŋāύ", 7 => "ā§ āĻĻāĻŋāύ", 15 => "ā§§ā§Ģ āĻĻāĻŋāύ" ]; // Initialize response variables $message = ""; $alertClass = ""; // Handle Form Submission if ($_SERVER["REQUEST_METHOD"] == "POST") { $days = isset($_POST['days']) ? intval($_POST['days']) : 7; $selectedTable = isset($_POST['table']) ? $_POST['table'] : ""; if (!in_array($days, $validDays)) { $message = "â ī¸ āĻ āĻŦā§āϧ āĻĻāĻŋāύā§āϰ āϏāĻāĻā§āϝāĻž āύāĻŋāϰā§āĻŦāĻžāĻāύ āĻāϰāĻž āĻšāϝāĻŧā§āĻā§!"; $alertClass = "alert-danger"; } elseif (!array_key_exists($selectedTable, $tableDateColumns)) { $message = "â ī¸ āĻ āĻŦā§āϧ āĻā§āĻŦāĻŋāϞ āύāĻŋāϰā§āĻŦāĻžāĻāύ āĻāϰāĻž āĻšāϝāĻŧā§āĻā§!"; $alertClass = "alert-danger"; } else { // Get correct date column $dateColumn = $tableDateColumns[$selectedTable]; // Prepare & Execute SQL Query $sql = "DELETE FROM `$selectedTable` WHERE `$dateColumn` < NOW() - INTERVAL ? DAY"; $stmt = $conn->prepare($sql); $stmt->bind_param("i", $days); if ($stmt->execute()) { $message = "â <b>{$tableNamesBn[$selectedTable]}</b> āĻĨā§āĻā§ <b>$validDaysBn[$days]</b> āĻĻāĻŋāύā§āϰ āĻŦā§āĻļāĻŋ āĻĒā§āϰāύ⧠āϰā§āĻāϰā§āĻĄ āϏāĻĢāϞāĻāĻžāĻŦā§ āĻŽā§āĻā§ āĻĢā§āϞāĻž āĻšāϝāĻŧā§āĻā§!"; $alertClass = "alert-success"; } else { $message = "â āϤā§āϰā§āĻāĻŋ: " . $stmt->error; $alertClass = "alert-danger"; } $stmt->close(); } } $conn->close(); ?> <!DOCTYPE html> <html lang="bn"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>āĻĄāĻžāĻāĻžāĻŦā§āϏ āĻā§āϞāĻŋāύāĻžāϰ</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <style> body { background-color: #f4f6f9; } .container { max-width: 480px; margin-top: 50px; background: white; padding: 30px; border-radius: 12px; box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.1); } h2 { font-weight: bold; color: #343a40; text-align: center; margin-bottom: 20px; } .btn-delete { background-color: #d9534f; color: white; font-weight: bold; } .btn-delete:hover { background-color: #c9302c; } </style> </head> <body> <div class="container"> <h2>đī¸ āĻĒā§āϰāύ⧠āϰā§āĻāϰā§āĻĄ āĻŽā§āĻā§āύ</h2> <?php if (!empty($message)): ?> <div class="alert <?php echo $alertClass; ?>" role="alert"> <?php echo $message; ?> </div> <?php endif; ?> <form id="deleteForm" method="POST"> <div class="mb-3"> <label for="table" class="form-label">đ āĻā§āĻŦāĻŋāϞ āύāĻŋāϰā§āĻŦāĻžāĻāύ āĻāϰā§āύ:</label> <select class="form-control" id="table" name="table" required> <option value="" disabled selected>đŊ āĻā§āĻŦāĻŋāϞ āύāĻŋāϰā§āĻŦāĻžāĻāύ āĻāϰā§āύ</option> <?php foreach ($tableNamesBn as $table => $label): ?> <option value="<?php echo $table; ?>"><?php echo $label; ?></option> <?php endforeach; ?> </select> </div> <div class="mb-3"> <label for="days" class="form-label">đ āĻĻāĻŋāύ āύāĻŋāϰā§āĻŦāĻžāĻāύ āĻāϰā§āύ:</label> <select class="form-control" id="days" name="days" required> <option value="" disabled selected>đŊ āĻĻāĻŋāύ āύāĻŋāϰā§āĻŦāĻžāĻāύ āĻāϰā§āύ</option> <?php foreach ($validDaysBn as $day => $label): ?> <option value="<?php echo $day; ?>"><?php echo $label; ?></option> <?php endforeach; ?> </select> </div> <button type="submit" class="btn btn-delete w-100">đī¸ āϰā§āĻāϰā§āĻĄ āĻŽā§āĻā§āύ</button> </form> </div> <script> document.addEventListener("DOMContentLoaded", function() { document.getElementById("deleteForm").addEventListener("submit", function(event) { event.preventDefault(); // Prevent form submission // Get selected values let tableElement = document.getElementById("table"); let daysElement = document.getElementById("days"); let selectedTable = tableElement.options[tableElement.selectedIndex].text; let selectedDays = daysElement.options[daysElement.selectedIndex].text; // Show confirmation alert with selected table and days Swal.fire({ title: "āĻāĻĒāύāĻŋ āĻāĻŋ āύāĻŋāĻļā§āĻāĻŋāϤ?", html: `<b>đ āĻā§āĻŦāĻŋāϞ:</b> ${selectedTable} <br> <b>đ āĻĻāĻŋāύ:</b> ${selectedDays}`, icon: "warning", showCancelButton: true, confirmButtonColor: "#d33", cancelButtonColor: "#3085d6", confirmButtonText: "â āĻšā§āϝāĻžāĻ, āĻŽā§āĻā§ āĻĢā§āϞā§āύ!", cancelButtonText: "â āĻŦāĻžāϤāĻŋāϞ āĻāϰā§āύ" }).then((result) => { if (result.isConfirmed) { this.submit(); // Submit form if confirmed } }); }); }); </script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html>