<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.4
 * @ Decoder version: 1.0.2
 * @ Release: 10/08/2022
 */

// Decoded file for php version 74.
if(!defined("IN_SITE")) {
    exit("The Request Not Found");
}
$body = ["title" => __("Lịch sử CRON") . " | " . $CMSNT->site("title"), "desc" => $CMSNT->site("description"), "keyword" => $CMSNT->site("keywords")];
$body["header"] = "\n<link rel=\"stylesheet\" href=\"" . BASE_URL("public/client/") . "css/wallet.css\">\n";
$body["footer"] = "\n\n";
require_once __DIR__ . "/../../models/is_user.php";
require_once __DIR__ . "/header.php";
require_once __DIR__ . "/nav.php";
if(isset($_GET["limit"])) {
    $limit = (int) check_string($_GET["limit"]);
} else {
    $limit = 10;
}
if(isset($_GET["page"])) {
    $page = check_string((int) $_GET["page"]);
} else {
    $page = 1;
}
$from = ($page - 1) * $limit;
$where = " `user_id` = '" . $getUser["id"] . "' ";
$shortByDate = "";
$link_cron = "";
$time = "";
$status = "";
if(!empty($_GET["status"])) {
    $status = check_string($_GET["status"]);
    $where .= " AND `status` = \"" . $status . "\" ";
}
if(!empty($_GET["link_cron"])) {
    $link_cron = check_string($_GET["link_cron"]);
    $where .= " AND `link_cron` LIKE \"%" . $link_cron . "%\" ";
}
if(!empty($_GET["time"])) {
    $time = check_string($_GET["time"]);
    $create_date_1 = str_replace("-", "/", $time);
    $create_date_1 = explode(" to ", $create_date_1);
    if($create_date_1[0] != $create_date_1[1]) {
        $create_date_1 = [$create_date_1[0] . " 00:00:00", $create_date_1[1] . " 23:59:59"];
        $where .= " AND `created_at` >= '" . $create_date_1[0] . "' AND `created_at` <= '" . $create_date_1[1] . "' ";
    }
}
if(isset($_GET["shortByDate"])) {
    $shortByDate = check_string($_GET["shortByDate"]);
    $yesterday = date("Y-m-d", strtotime("-1 day"));
    $currentWeek = date("W");
    $currentMonth = date("m");
    $currentYear = date("Y");
    $currentDate = date("Y-m-d");
    if($shortByDate == 1) {
        $where .= " AND `created_at` LIKE '%" . $currentDate . "%' ";
    }
    if($shortByDate == 2) {
        $where .= " AND YEAR(created_at) = " . $currentYear . " AND WEEK(created_at, 1) = " . $currentWeek . " ";
    }
    if($shortByDate == 3) {
        $where .= " AND MONTH(created_at) = '" . $currentMonth . "' AND YEAR(created_at) = '" . $currentYear . "' ";
    }
}
$listDatatable = $CMSNT->get_list(" SELECT * FROM `cron_jobs` WHERE " . $where . " ORDER BY `id` DESC LIMIT " . $from . "," . $limit . " ");
$totalDatatable = $CMSNT->num_rows(" SELECT * FROM `cron_jobs` WHERE " . $where . " ORDER BY id DESC ");
$urlDatatable = pagination_client(base_url("?action=cron-jobs&limit=" . $limit . "&shortByDate=" . $shortByDate . "&time=" . $time . "&link_cron=" . $link_cron . "&status=" . $status . "&"), $from, $totalDatatable, $limit);
echo "\n<section class=\"py-5 inner-section profile-part\">\n    <div class=\"container\">\n        <div class=\"row\">\n            <div class=\"col-lg-3\">\n                <div class=\"account-card pt-4\">\n                    <p><i class=\"fa-solid fa-chart-simple\"></i> ";
echo __("Tổng số Link CRON");
echo "</p>\n                    <h4>\n                        ";
$cronStats = $CMSNT->get_row("SELECT \n                                            COUNT(id) AS total, \n                                            SUM(CASE WHEN status = 'active' THEN 1 ELSE 0 END) AS active,\n                                            SUM(CASE WHEN status = 'pause' THEN 1 ELSE 0 END) AS pause\n                                        FROM `cron_jobs` \n                                        WHERE `user_id` = '" . $getUser["id"] . "'");
echo format_cash($cronStats["total"]);
echo " Link\n                    </h4>\n                </div>\n            </div>\n            <div class=\"col-lg-3\">\n                <div class=\"account-card pt-4\">\n                    <p><i class=\"fa-solid fa-chart-simple\"></i> ";
echo __("Link CRON đang chạy");
echo "</p>\n                    <h4>";
echo format_cash($cronStats["active"]);
echo " Link</h4>\n                </div>\n            </div>\n            <div class=\"col-lg-3\">\n                <div class=\"account-card pt-4\">\n                    <p><i class=\"fa-solid fa-chart-simple\"></i> ";
echo __("Link CRON tạm dừng");
echo "</p>\n                    <h4>";
echo format_cash($cronStats["pause"]);
echo " Link</h4>\n                </div>\n            </div>\n            <div class=\"col-lg-3\">\n                <div class=\"account-card pt-4\">\n                    <p><i class=\"fa-solid fa-chart-simple\"></i> ";
echo __("Link CRON hết hạn");
echo "</p>\n                    <h4>\n                        ";
$expiredLinks = $CMSNT->get_row("SELECT COUNT(id) AS expired FROM `cron_jobs` WHERE `user_id` = '" . $getUser["id"] . "' AND `status` = 'expired'");
echo format_cash($expiredLinks["expired"]);
echo " Link\n                    </h4>\n                </div>\n            </div>\n\n            <div class=\"col-lg-12\">\n                <div class=\"home-heading mb-3\">\n                    <h3><i class=\"fa-solid fa-list-ul m-2\"></i>";
echo mb_strtoupper(__("Lịch sử CRON"));
echo "                        <span style=\"float: right;\">\n                            <a class=\"btn btn-danger btn-sm\" href=\"";
echo base_url("cron-job-add");
echo "\"><i\n                                    class=\"fa-solid fa-cart-plus me-2\"></i>";
echo mb_strtoupper(__("Thêm link CRON mới"));
echo "</a>\n                        </span>\n                    </h3>\n                </div>\n                <div class=\"account-card pt-3\">\n                    <form action=\"";
echo base_url();
echo "\" method=\"GET\">\n                        <input type=\"hidden\" name=\"action\" value=\"cron-jobs\">\n                        <input type=\"hidden\" id=\"token\" class=\"form-control\" value=\"";
echo $getUser["token"];
echo "\" />\n                        <div class=\"row\">\n                            <div class=\"col-lg col-md-4 col-6\">\n                                <input class=\"form-control mb-2\" value=\"";
echo $link_cron;
echo "\" name=\"link_cron\"\n                                    placeholder=\"";
echo __("Link CRON");
echo "\">\n                            </div>\n                            <div class=\"col-lg col-md-4 col-6\">\n                                <select class=\"form-select mb-2\" name=\"status\">\n                                    <option value=\"\">";
echo __("Trạng thái");
echo "</option>\n                                    <option ";
echo $status == "active" ? "selected" : "";
echo " value=\"active\">\n                                        ";
echo __("Hoạt động");
echo "</option>\n                                    <option ";
echo $status == "pause" ? "selected" : "";
echo " value=\"pause\">\n                                        ";
echo __("Tạm dừng");
echo "</option>\n                                    <option ";
echo $status == "expired" ? "selected" : "";
echo " value=\"expired\">\n                                        ";
echo __("Hết hạn");
echo "</option>\n                                </select>\n                            </div>\n                            <div class=\"col-lg col-md-4 col-6\">\n                                <input type=\"text\" class=\"js-flatpickr form-control mb-2\" id=\"example-flatpickr-range\"\n                                    name=\"time\" placeholder=\"";
echo __("Chọn thời gian cần tìm");
echo "\" value=\"";
echo $time;
echo "\"\n                                    data-mode=\"range\">\n                            </div>\n                            <div class=\"col-lg col-md-4 col-6\">\n                                <button class=\"shop-widget-btn mb-2\"><i\n                                        class=\"fas fa-search\"></i><span>";
echo __("Tìm kiếm");
echo "</span></button>\n                            </div>\n                            <div class=\"col-lg col-md-4 col-6\">\n                                <a href=\"";
echo base_url("?action=cron-jobs");
echo "\" class=\"shop-widget-btn mb-2\"><i\n                                        class=\"far fa-trash-alt\"></i><span>";
echo __("Bỏ lọc");
echo "</span></a>\n                            </div>\n                        </div>\n                        <div class=\"top-filter\">\n                            <div class=\"filter-show\"><label class=\"filter-label\">Show :</label>\n                                <select name=\"limit\" onchange=\"this.form.submit()\" class=\"form-select filter-select\">\n                                    <option ";
echo $limit == 5 ? "selected" : "";
echo " value=\"5\">5</option>\n                                    <option ";
echo $limit == 10 ? "selected" : "";
echo " value=\"10\">10</option>\n                                    <option ";
echo $limit == 20 ? "selected" : "";
echo " value=\"20\">20</option>\n                                    <option ";
echo $limit == 50 ? "selected" : "";
echo " value=\"50\">50</option>\n                                    <option ";
echo $limit == 100 ? "selected" : "";
echo " value=\"100\">100</option>\n                                    <option ";
echo $limit == 500 ? "selected" : "";
echo " value=\"500\">500</option>\n                                    <option ";
echo $limit == 1000 ? "selected" : "";
echo " value=\"1000\">1000\n                                    </option>\n                                </select>\n                            </div>\n                            <div class=\"filter-short\">\n                                <label class=\"filter-label\">";
echo __("Short by Date:");
echo "</label>\n                                <select name=\"shortByDate\" onchange=\"this.form.submit()\"\n                                    class=\"form-select filter-select\">\n                                    <option value=\"\">";
echo __("Tất cả");
echo "</option>\n                                    <option ";
echo $shortByDate == 1 ? "selected" : "";
echo " value=\"1\">\n                                        ";
echo __("Hôm nay");
echo "                                    </option>\n                                    <option ";
echo $shortByDate == 2 ? "selected" : "";
echo " value=\"2\">\n                                        ";
echo __("Tuần này");
echo "                                    </option>\n                                    <option ";
echo $shortByDate == 3 ? "selected" : "";
echo " value=\"3\">\n                                        ";
echo __("Tháng này");
echo "                                    </option>\n                                </select>\n                            </div>\n                        </div>\n                    </form>\n                    <div class=\"table-scroll table-wrapper\">\n                        <table class=\"table fs-sm text-nowrap table-hover mb-0\">\n                            <thead>\n                                <th class=\"text-center\">\n                                    <input type=\"checkbox\" class=\"form-check-input\" name=\"check_all\"\n                                        id=\"check_all_checkbox\" value=\"option1\">\n                                </th>\n                                <th class=\"text-center\">";
echo __("Link CRON");
echo "</th>\n                                <th class=\"text-center\">";
echo __("Cấu hình");
echo "</th>\n                                <th class=\"text-center\">";
echo __("Trạng thái");
echo "</th>\n                                <th class=\"text-center\">";
echo __("Thực hiện lần cuối");
echo "</th>\n                                <th class=\"text-center\">";
echo __("Thời gian");
echo "</th>\n                                <th class=\"text-center\">";
echo __("Thao tác");
echo "</th>\n                            </thead>\n                            <tbody>\n                                ";
foreach ($listDatatable as $cron) {
    echo "                                <tr>\n                                    <td class=\"text-center\">\n                                        <input type=\"checkbox\" class=\"form-check-input checkbox\"\n                                            data-id=\"";
    echo $cron["id"];
    echo "\" name=\"checkbox\" value=\"";
    echo $cron["id"];
    echo "\" />\n                                    </td>\n                                    <td>\n                                        <small><strong>";
    echo $cron["link_cron"];
    echo "</strong></small>\n                                    </td>\n                                    <td>\n                                        <ul>\n                                            <li>";
    echo __("Vòng lặp:");
    echo "                                                <strong>";
    echo format_cash($cron["timeloop"]);
    echo "</strong>\n                                                ";
    echo __("giây");
    echo "                                            </li>\n                                            <li>Method: <strong>";
    echo $cron["method"];
    echo "</strong></li>\n                                        </ul>\n                                    </td>\n                                    <td class=\"text-center\">\n                                        ";
    echo display_cron_jobs($cron["status"]);
    echo "                                    </td>\n                                    <td class=\"text-center\">\n                                        ";
    if($cron["last_run"] != 0) {
        echo "                                        <strong data-toggle=\"tooltip\" data-placement=\"bottom\"\n                                            title=\"";
        echo date("Y-m-d H:i:s", $cron["last_run"]);
        echo "\"><small>";
        echo timeAgo($cron["last_run"]);
        echo "</small></strong>\n                                        ";
    }
    echo "<br>\n                                        ";
    echo display_cron_jobs($cron["code"]);
    echo " -\n                                        <small>(";
    echo $cron["timeout"];
    echo "s)</small>\n                                    </td>\n                                    <td>\n                                        <ul>\n                                            <li>";
    echo __("Ngày tạo:");
    echo " <strong data-toggle=\"tooltip\"\n                                                    data-placement=\"bottom\"\n                                                    title=\"";
    echo timeAgo(strtotime($cron["created_at"]));
    echo "\"><small><i\n                                                            class=\"fa-solid fa-calendar\"></i>\n                                                        ";
    echo $cron["created_at"];
    echo "</small></strong></li>\n                                            <li>";
    echo __("Hết hạn:");
    echo " <strong data-toggle=\"tooltip\"\n                                                    data-placement=\"bottom\"\n                                                    title=\"";
    echo timeRemaining(strtotime($cron["expires_at"]));
    echo "\"><small><i\n                                                            class=\"fa-solid fa-calendar-days\"></i>\n                                                        ";
    echo $cron["expires_at"];
    echo "</small></strong></li>\n                                        </ul>\n\n                                    </td>\n                                    <td class=\"text-center\">\n                                        ";
    if($cron["status"] == "pause") {
        echo "                                        <button type=\"button\" id=\"btnActive";
        echo $cron["id"];
        echo "\" data-toggle=\"tooltip\"\n                                            data-placement=\"bottom\" title=\"";
        echo __("Kích hoạt");
        echo "\"\n                                            onclick=\"activeCron(`";
        echo $cron["id"];
        echo "`)\" class=\"btn btn-info btn-sm\">\n                                            <i class=\"fa-solid fa-play\"></i>\n                                        </button>\n                                        ";
    } elseif($cron["status"] == "active") {
        echo "                                        <button type=\"button\" id=\"btnPause";
        echo $cron["id"];
        echo "\" data-toggle=\"tooltip\"\n                                            data-placement=\"bottom\" title=\"";
        echo __("Tạm dừng");
        echo "\"\n                                            onclick=\"pauseCron(`";
        echo $cron["id"];
        echo "`)\" class=\"btn btn-danger btn-sm\">\n                                            <i class=\"fa-solid fa-pause\"></i>\n                                        </button>\n                                        ";
    }
    echo "                                        <a type=\"button\" data-toggle=\"tooltip\" data-placement=\"bottom\"\n                                            title=\"";
    echo __("Chỉnh sửa");
    echo "\"\n                                            href=\"";
    echo base_url("?action=cron-job-edit&id=" . $cron["trans_id"]);
    echo "\"\n                                            class=\"btn btn-primary btn-sm\">\n                                            <i class=\"fa-solid fa-pen-to-square\"></i>\n                                        </a>\n                                        <button type=\"button\" id=\"showHistoryCron_";
    echo $cron["id"];
    echo "\"\n                                            data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"";
    echo __("Nhật ký");
    echo "\"\n                                            onclick=\"showHistoryCron(`";
    echo $cron["id"];
    echo "`)\" class=\"btn btn-dark btn-sm\">\n                                            <i class=\"fa-solid fa-clock-rotate-left\"></i>\n                                        </button>\n                                        <a type=\"button\" data-toggle=\"tooltip\" data-placement=\"bottom\"\n                                            title=\"";
    echo __("Gia hạn");
    echo "\"\n                                            href=\"";
    echo base_url("?action=cron-job-renew&id=" . $cron["trans_id"]);
    echo "\"\n                                            class=\"btn btn-success btn-sm\">\n                                            <i class=\"fa-solid fa-rotate-right\"></i>\n                                        </a>\n                                    </td>\n                                </tr>\n                                ";
}
echo "                            </tbody>\n\n                            <tfoot>\n                                <td colspan=\"7\">\n                                    <button type=\"button\" id=\"btn_pause\" class=\"btn btn-danger btn-sm\">\n                                        <i class=\"fa-solid fa-pause\"></i> ";
echo __("Tạm dừng");
echo "                                    </button>\n                                    <button type=\"button\" id=\"btn_active\" class=\"btn btn-info btn-sm\">\n                                        <i class=\"fa-solid fa-play\"></i> ";
echo __("Kích hoạt");
echo "                                    </button>\n                                </td>\n                            </tfoot>\n                        </table>\n                    </div>\n\n                    <div class=\"bottom-paginate\">\n                        <p class=\"page-info\">Showing ";
echo $limit;
echo " of ";
echo $totalDatatable;
echo " Results</p>\n                        <div class=\"pagination\">\n                            ";
echo $limit < $totalDatatable ? $urlDatatable : "";
echo "                        </div>\n                    </div>\n                </div>\n            </div>\n        </div>\n\n    </div>\n</section>\n\n\n\n\n<div class=\"modal fade\" id=\"openModal\" tabindex=\"-1\" aria-labelledby=\"modal-block-popout\" role=\"dialog\"\n    aria-hidden=\"true\">\n    <div class=\"modal-dialog modal-lg modal-dialog-popout\" role=\"document\">\n        <div class=\"modal-content\" style=\"background-color:#fafafa00;\">\n            <div id=\"modal_showHistoryCron\"></div>\n        </div>\n    </div>\n</div>\n<script>\nfunction showHistoryCron(id) {\n    \$(\"#modal_showHistoryCron\").html('');\n    var originalButtonContent = \$('#showHistoryCron_' + id).html();\n    \$('#showHistoryCron_' + id).html('<span><i class=\"fa fa-spinner fa-spin\"></i></span>')\n        .prop('disabled', true);\n\n    \$.ajax({\n        url: \"";
echo BASE_URL("ajaxs/client/cronjob.php");
echo "\",\n        method: \"POST\",\n        data: {\n            action: 'HistoryCron',\n            id: id,\n            token: \$(\"#token\").val()\n        },\n        success: function(response) {\n            try {\n                var data = JSON.parse(response);\n                if (data.status === 'success') {\n                    var html = `\n    <div class=\"home-heading mb-3\">\n        <h3><i class=\"fa-solid fa-clock-rotate-left me-2\"></i> \${data.cron.link}\n            <span style=\"float: right;\">\n                <button type=\"button\" class=\"btn btn-danger btn-sm\" data-bs-dismiss=\"modal\">\n                    <i class=\"fa-solid fa-xmark\"></i>\n                </button>\n            </span>\n        </h3>\n    </div>\n    <div class=\"account-card pt-3\">\n        <div class=\"table-responsive table-wrapper\" style=\"width: 1000px; height: 500px;\">\n            <table class=\"table text-nowrap table-striped table-hover table-bordered\">\n                <thead>\n                    <tr>\n                        <th class=\"text-center\">";
echo __("Thời gian");
echo "</th>\n                        <th class=\"text-center\">";
echo __("Trạng thái");
echo "</th>\n                        <th class=\"text-center\">";
echo __("Khoảng thời gian tải");
echo "</th>\n                        <th class=\"text-center\">";
echo __("Output");
echo "</th>\n                    </tr>\n                </thead>\n                <tbody>\n`;\n\n                    data.history.forEach(function(row) {\n                        html += `\n                    <tr>\n                        <td>\n                            <strong data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"\${row.time_ago}\">\n                                <small>\n                                    <i class=\"fa-solid fa-calendar\"></i> \${row.run_at} - \${row.time_ago}\n                                </small>\n                            </strong>\n                        </td>\n                        <td class=\"text-center\">\${row.status}</td>\n                        <td class=\"text-right\">\${row.timeout}s</td>\n                        <td class=\"text-right\"><textarea class=\"form-control\" readonly rows=\"1\">\${row.output}</textarea></td>\n                    </tr>\n    `;\n                    });\n\n                    html += `\n                </tbody>\n            </table>\n        </div>\n        <div class=\"alert alert-info mt-3\">\n            <small>";
echo __("Nhật ký CRON có thể cập nhật chậm hơn so với thực tế");
echo "</small>\n        </div>\n    </div>\n`;\n\n\n                    \$(\"#modal_showHistoryCron\").html(html);\n                    \$('#openModal').modal('show');\n                } else {\n                    Swal.fire('";
echo __("Thất bại!");
echo "', data.msg, 'error');\n                }\n            } catch (e) {\n                Swal.fire('";
echo __("Thất bại!");
echo "', 'Có lỗi trong việc xử lý dữ liệu', 'error');\n            }\n            \$('#showHistoryCron_' + id).html(originalButtonContent).prop('disabled', false);\n        },\n        error: function() {\n            Swal.fire('";
echo __("Thất bại!");
echo "', 'Có lỗi xảy ra', 'error');\n            \$('#showHistoryCron_' + id).html(originalButtonContent).prop('disabled', false);\n        }\n    });\n}\n</script>\n\n\n\n<script>\n\$(function() {\n    \$('#check_all_checkbox').on('click', function() {\n        \$('.checkbox').prop('checked', this.checked);\n    });\n    \$('.checkbox').on('click', function() {\n        \$('#check_all_checkbox').prop('checked', \$('.checkbox:checked')\n            .length === \$('.checkbox').length);\n    });\n});\n</script>\n\n<script>\n\$(\"#btn_pause\").click(function() {\n    var checkboxes = document.querySelectorAll('input[name=\"checkbox\"]:checked');\n    if (checkboxes.length === 0) {\n        showMessage('";
echo __("Vui lòng tích vào link cần Tạm dừng.");
echo "', 'error');\n        return;\n    }\n    Swal.fire({\n        title: \"";
echo __("Bạn có chắc không?");
echo "\",\n        text: \"";
echo __("Hệ thống tạm dừng");
echo " \" + checkboxes.length +\n            \" ";
echo __("link bạn chọn khi nhấn Đồng Ý");
echo "\",\n        icon: \"warning\",\n        showCancelButton: true,\n        confirmButtonColor: \"#3085d6\",\n        cancelButtonColor: \"#d33\",\n        confirmButtonText: \"";
echo __("Đồng ý");
echo "\",\n        cancelButtonText: \"";
echo __("Đóng");
echo "\"\n    }).then((result) => {\n        if (result.isConfirmed) {\n            pause_records();\n        }\n    });\n});\n\nfunction pause_records() {\n    var checkbox = document.getElementsByName('checkbox');\n\n    function postUpdatesSequentially(index) {\n        if (index < checkbox.length) {\n            if (checkbox[index].checked === true) {\n                post_pause(checkbox[index].value);\n            }\n            setTimeout(function() {\n                postUpdatesSequentially(index + 1);\n            }, 100);\n        } else {\n            Swal.fire({\n                title: \"";
echo __("Thành công!");
echo "\",\n                text: \"";
echo __("Tạm dừng thành công");
echo "\",\n                icon: \"success\"\n            });\n            setTimeout(function() {\n                location.reload();\n            }, 1000);\n        }\n    }\n    postUpdatesSequentially(0);\n}\n\nfunction post_pause(id) {\n    \$.ajax({\n        url: \"";
echo BASE_URL("ajaxs/client/cronjob.php");
echo "\",\n        method: \"POST\",\n        dataType: \"JSON\",\n        data: {\n            id: id,\n            token: \$(\"#token\").val(),\n            action: 'pauseCron'\n        },\n        success: function(result) {\n            if (result.status == 'success') {\n                showMessage(result.msg, result.status);\n            } else {\n                showMessage(result.msg, result.status);\n            }\n        },\n        error: function() {\n            alert(html(response));\n            location.reload();\n        }\n    });\n}\n\nfunction pauseCron(id) {\n    \$('#btnPause' + id).html('<span><i class=\"fa fa-spinner fa-spin\"></i></span>')\n        .prop('disabled', true);\n    post_pause(id);\n    setTimeout(() => {\n        location.reload();\n    }, 100);\n}\n</script>\n\n<script>\n\$(\"#btn_active\").click(function() {\n    var checkboxes = document.querySelectorAll('input[name=\"checkbox\"]:checked');\n    if (checkboxes.length === 0) {\n        showMessage('";
echo __("Vui lòng tích vào link cần Kích hoạt.");
echo "', 'error');\n        return;\n    }\n    Swal.fire({\n        title: \"";
echo __("Bạn có chắc không?");
echo "\",\n        text: \"";
echo __("Hệ thống Kích hoạt");
echo " \" + checkboxes.length +\n            \" ";
echo __("link bạn chọn khi nhấn Đồng Ý");
echo "\",\n        icon: \"warning\",\n        showCancelButton: true,\n        confirmButtonColor: \"#3085d6\",\n        cancelButtonColor: \"#d33\",\n        confirmButtonText: \"";
echo __("Đồng ý");
echo "\",\n        cancelButtonText: \"";
echo __("Đóng");
echo "\"\n    }).then((result) => {\n        if (result.isConfirmed) {\n            active_records();\n        }\n    });\n});\n\nfunction active_records() {\n    var checkbox = document.getElementsByName('checkbox');\n\n    function postUpdatesSequentially(index) {\n        if (index < checkbox.length) {\n            if (checkbox[index].checked === true) {\n                post_active(checkbox[index].value);\n            }\n            setTimeout(function() {\n                postUpdatesSequentially(index + 1);\n            }, 100);\n        } else {\n            Swal.fire({\n                title: \"";
echo __("Thành công!");
echo "\",\n                text: \"";
echo __("Kích hoạt thành công");
echo "\",\n                icon: \"success\"\n            });\n            setTimeout(function() {\n                location.reload();\n            }, 1000);\n        }\n    }\n    postUpdatesSequentially(0);\n}\n\nfunction post_active(id) {\n    \$.ajax({\n        url: \"";
echo BASE_URL("ajaxs/client/cronjob.php");
echo "\",\n        method: \"POST\",\n        dataType: \"JSON\",\n        data: {\n            id: id,\n            token: \$(\"#token\").val(),\n            action: 'activeCron'\n        },\n        success: function(result) {\n            if (result.status == 'success') {\n                showMessage(result.msg, result.status);\n            } else {\n                showMessage(result.msg, result.status);\n            }\n        },\n        error: function() {\n            alert(html(response));\n            location.reload();\n        }\n    });\n}\n\nfunction activeCron(id) {\n    \$('#btnActive' + id).html('<span><i class=\"fa fa-spinner fa-spin\"></i></span>')\n        .prop('disabled', true);\n    post_active(id);\n    setTimeout(() => {\n        location.reload();\n    }, 100);\n}\n</script>\n\n\n";
require_once __DIR__ . "/footer.php";

?>