<?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" => "Quản lý Link CRON", "desc" => "CMSNT Panel", "keyword" => "cmsnt, CMSNT, cmsnt.co,"];
$body["header"] = "\n \n\n";
$body["footer"] = "\n \n";
require_once __DIR__ . "/../../models/is_admin.php";
require_once __DIR__ . "/header.php";
require_once __DIR__ . "/sidebar.php";
if(!checkPermission($getUser["admin"], "view_server")) {
    exit("<script type=\"text/javascript\">if(!alert(\"Bạn không có quyền sử dụng tính năng này\")){window.history.back();}</script>");
}
if(isset($_POST["AddServer"])) {
    if($CMSNT->site("status_demo") != 0) {
        exit("<script type=\"text/javascript\">if(!alert(\"" . __("This function cannot be used as this is a demo site.") . "\")){window.history.back().location.reload();}</script>");
    }
    if(!checkPermission($getUser["admin"], "edit_server")) {
        exit("<script type=\"text/javascript\">if(!alert(\"Bạn không có quyền sử dụng tính năng này\")){window.history.back();}</script>");
    }
    if(empty($_POST["name"])) {
        exit("<script type=\"text/javascript\">if(!alert(\"Vui lòng nhập tên Server\")){window.history.back().location.reload();}</script>");
    }
    $name = check_string($_POST["name"]);
    if(empty($_POST["ip"])) {
        exit("<script type=\"text/javascript\">if(!alert(\"Vui lòng nhập IP Server\")){window.history.back().location.reload();}</script>");
    }
    $ip = check_string($_POST["ip"]);
    if(empty($_POST["price"])) {
        exit("<script type=\"text/javascript\">if(!alert(\"Vui lòng nhập giá thuê\")){window.history.back().location.reload();}</script>");
    }
    $price = (int) check_string($_POST["price"]);
    if($price <= 0) {
        exit("<script type=\"text/javascript\">if(!alert(\"Giá thuê không hợp lệ\")){window.history.back().location.reload();}</script>");
    }
    if(empty($_POST["max"])) {
        exit("<script type=\"text/javascript\">if(!alert(\"Số lượng giới hạn không hợp lệ\")){window.history.back().location.reload();}</script>");
    }
    $max = (int) check_string($_POST["max"]);
    if($max <= 0) {
        exit("<script type=\"text/javascript\">if(!alert(\"Số lượng giới hạn không hợp lệ\")){window.history.back().location.reload();}</script>");
    }
    $isInsert = $CMSNT->insert("cron_server", ["name" => $name, "ip" => $ip, "max" => $max, "price" => $price, "status" => 1, "created_at" => gettime(), "updated_at" => gettime()]);
    if($isInsert) {
        $Mobile_Detect = new Mobile_Detect();
        $CMSNT->insert("logs", ["user_id" => $getUser["id"], "ip" => myip(), "device" => $Mobile_Detect->getUserAgent(), "createdate" => gettime(), "action" => "Add Server (" . $name . ")"]);
        $my_text = $CMSNT->site("noti_action");
        $my_text = str_replace("{domain}", $_SERVER["SERVER_NAME"], $my_text);
        $my_text = str_replace("{username}", $getUser["username"], $my_text);
        $my_text = str_replace("{action}", "Add Server (" . $name . ")", $my_text);
        $my_text = str_replace("{ip}", myip(), $my_text);
        $my_text = str_replace("{time}", gettime(), $my_text);
        sendMessAdmin($my_text);
        exit("<script type=\"text/javascript\">if(!alert(\"Thêm thành công!\")){location.href = \"" . base_url_admin("cron-job-server") . "\";}</script>");
    }
    exit("<script type=\"text/javascript\">if(!alert(\"Thêm thất bại!\")){window.history.back().location.reload();}</script>");
}
if(isset($_GET["limit"])) {
    $limit = (int) check_string($_GET["limit"]);
} else {
    $limit = 20;
}
if(isset($_GET["page"])) {
    $page = check_string((int) $_GET["page"]);
} else {
    $page = 1;
}
$from = ($page - 1) * $limit;
$where = " `id` > 0 ";
$shortByDate = "";
$link_cron = "";
$time = "";
$status = "";
$user_id = "";
$username = "";
$server_id = "";
if(!empty($_GET["server_id"])) {
    $server_id = check_string($_GET["server_id"]);
    $where .= " AND `server_id` = " . $server_id . " ";
}
if(!empty($_GET["username"])) {
    $username = check_string($_GET["username"]);
    if($idUser = $CMSNT->get_row(" SELECT * FROM `users` WHERE `username` = '" . $username . "' ")) {
        $where .= " AND `user_id` =  \"" . $idUser["id"] . "\" ";
    } else {
        $where .= " AND `user_id` =  \"\" ";
    }
}
if(!empty($_GET["user_id"])) {
    $user_id = check_string($_GET["user_id"]);
    $where .= " AND `user_id` = " . $user_id . " ";
}
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(base_url_admin("cron-jobs&limit=" . $limit . "&shortByDate=" . $shortByDate . "&time=" . $time . "&link_cron=" . $link_cron . "&status=" . $status . "&user_id=" . $user_id . "&username=" . $username . "&server_id=" . $server_id . "&"), $from, $totalDatatable, $limit);
echo "\n\n<div class=\"main-content app-content\">\n    <div class=\"container-fluid\">\n        <div class=\"d-md-flex d-block align-items-center justify-content-between my-4 page-header-breadcrumb\">\n            <h1 class=\"page-title fw-semibold fs-18 mb-0\"><i class=\"fa-solid fa-server\"></i> Quản lý Link CRON</h1>\n        </div>\n        ";
if(120 <= time() - $CMSNT->site("check_time_cron_cron")) {
    echo "        <div class=\"alert alert-danger alert-dismissible fade show custom-alert-icon shadow-sm\" role=\"alert\">\n            <svg class=\"svg-danger\" xmlns=\"http://www.w3.org/2000/svg\" height=\"1.5rem\" viewBox=\"0 0 24 24\"\n                width=\"1.5rem\" fill=\"#000000\">\n                <path d=\"M0 0h24v24H0z\" fill=\"none\" />\n                <path\n                    d=\"M15.73 3H8.27L3 8.27v7.46L8.27 21h7.46L21 15.73V8.27L15.73 3zM12 17.3c-.72 0-1.3-.58-1.3-1.3 0-.72.58-1.3 1.3-1.3.72 0 1.3.58 1.3 1.3 0 .72-.58 1.3-1.3 1.3zm1-4.3h-2V7h2v6z\" />\n            </svg>\n            Vui lòng thực hiện <b>CRON JOB</b> liên kết: <a class=\"text-primary\" href=\"";
    echo base_url("cron/cron.php");
    echo "\"\n                target=\"_blank\">";
    echo base_url("cron/cron.php");
    echo "</a> 1 phút 1 lần.\n            <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"alert\" aria-label=\"Close\"><i\n                    class=\"bi bi-x\"></i></button>\n        </div>\n        ";
}
echo "        <div class=\"row\">\n\n            <div class=\"col-xl-12\">\n                <div class=\"card custom-card\">\n                    <div class=\"card-header justify-content-between\">\n                        <div class=\"card-title\">\n                            DANH SÁCH LINK CRON JOBS\n                        </div>\n                    </div>\n                    <div class=\"card-body\">\n                        <form action=\"\" class=\"align-items-center mb-3\" name=\"formSearch\" method=\"GET\">\n                            <div class=\"row row-cols-lg-auto g-3 mb-3\">\n                                <input type=\"hidden\" name=\"module\" value=\"admin\">\n                                <input type=\"hidden\" name=\"action\" value=\"cron-jobs\">\n                                <div class=\"col-md-4 col-6\">\n                                    <input class=\"form-control form-control-sm\" value=\"";
echo $user_id;
echo "\" name=\"user_id\"\n                                        placeholder=\"";
echo __("Search ID User");
echo "\">\n                                </div>\n                                <div class=\"col-md-4 col-6\">\n                                    <input class=\"form-control form-control-sm\" value=\"";
echo $username;
echo "\" name=\"username\"\n                                        placeholder=\"";
echo __("Search Username");
echo "\">\n                                </div>\n                                <div class=\"col-md-4 col-6\">\n                                    <input class=\"form-control form-control-sm\" value=\"";
echo $link_cron;
echo "\"\n                                        name=\"link_cron\" placeholder=\"";
echo __("Link CRON");
echo "\">\n                                </div>\n                                <div class=\"col-md-4 col-6\">\n                                    <select class=\"form-control form-control-sm mb-1\" name=\"server_id\">\n                                        <option value=\"\">";
echo __("Server");
echo "</option>\n                                        ";
foreach ($CMSNT->get_list(" SELECT * FROM `cron_server` ") as $server) {
    echo "                                        <option ";
    echo $server["id"] == $server_id ? "selected" : "";
    echo "                                            value=\"";
    echo $server_id;
    echo "\">\n                                            ";
    echo __($server["name"]);
    echo "</option>\n                                        ";
}
echo "\n                                    </select>\n                                </div>\n                                <div class=\"col-md-4 col-6\">\n                                    <select class=\"form-control form-control-sm mb-1\" 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\" name=\"time\" class=\"form-control form-control-sm\" id=\"daterange\"\n                                        value=\"";
echo $time;
echo "\" placeholder=\"Chọn thời gian\">\n                                </div>\n                                <div class=\"col-12\">\n                                    <button class=\"btn btn-sm btn-primary\"><i class=\"fa fa-search\"></i>\n                                        ";
echo __("Search");
echo "                                    </button>\n                                    <a class=\"btn btn-sm btn-danger\" href=\"";
echo base_url_admin("cron-jobs");
echo "\"><i\n                                            class=\"fa fa-trash\"></i>\n                                        ";
echo __("Clear filter");
echo "                                    </a>\n                                </div>\n                            </div>\n                            <div class=\"top-filter\">\n                                <div class=\"filter-show\">\n                                    <label class=\"filter-label\">Show :</label>\n                                    <select name=\"limit\" onchange=\"this.form.submit()\"\n                                        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</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\">";
echo __("Hôm nay");
echo "                                        </option>\n                                        <option ";
echo $shortByDate == 2 ? "selected" : "";
echo " value=\"2\">";
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-responsive mb-3\">\n                            <table class=\"table text-nowrap table-striped table-hover table-bordered\">\n                                <thead>\n                                    <tr>\n                                        <th class=\"text-center\">\n                                            <div class=\"form-check form-check-md d-flex align-items-center\">\n                                                <input type=\"checkbox\" class=\"form-check-input\" name=\"check_all\"\n                                                    id=\"check_all_checkbox\" value=\"option1\">\n                                            </div>\n                                        </th>\n                                        <th>";
echo __("Username");
echo "</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 __("Máy chủ");
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                                    </tr>\n                                </thead>\n                                <tbody>\n                                    ";
foreach ($listDatatable as $cron) {
    echo "                                    <tr>\n                                        <td class=\"text-center\">\n                                            <div class=\"form-check form-check-md d-flex align-items-center\">\n                                                <input type=\"checkbox\" class=\"form-check-input checkbox\"\n                                                    data-id=\"";
    echo $cron["id"];
    echo "\" name=\"checkbox\"\n                                                    value=\"";
    echo $cron["id"];
    echo "\" />\n                                            </div>\n                                        </td>\n                                        <td class=\"text-center\"><a class=\"text-primary\"\n                                                href=\"";
    echo base_url_admin("user-edit&id=" . $cron["user_id"]);
    echo "\">";
    echo getRowRealtime("users", $cron["user_id"], "username");
    echo "                                                [ID ";
    echo $cron["user_id"];
    echo "]</a>\n                                        </td>\n                                        <td>\n                                            <small><strong>";
    echo $cron["link_cron"];
    echo "</strong></small>\n                                        </td>\n                                        <td>\n                                            Vòng lặp: <strong>";
    echo format_cash($cron["timeloop"]);
    echo "</strong>\n                                            ";
    echo __("giây");
    echo "<br>\n                                            Method: <strong>";
    echo $cron["method"];
    echo "</strong>\n                                        </td>\n                                        <td class=\"text-center\">\n                                            <a class=\"text-primary\"\n                                                href=\"";
    echo base_url_admin("cron-job-server-edit&id=" . $cron["server_id"]);
    echo "\"><i\n                                                    class=\"fa-solid fa-pen-to-square me-1\"></i>";
    echo getRowRealtime("cron_server", $cron["server_id"], "name");
    echo "                                            </a>\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                                            ";
    echo __("Ngày tạo:");
    echo " <strong data-toggle=\"tooltip\" 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><br>\n                                            ";
    echo __("Hết hạn:");
    echo " <strong data-toggle=\"tooltip\" 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>\n                                        </td>\n                                        <td class=\"text-center\">\n                                            ";
    if($cron["status"] == "pause") {
        echo "                                            <button type=\"button\" id=\"btnActive";
        echo $cron["id"];
        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 "\"\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\"\n                                                href=\"";
    echo base_url_admin("cron-job-edit&id=" . $cron["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                                                onclick=\"showHistoryCron(`";
    echo $cron["id"];
    echo "`)\"\n                                                class=\"btn btn-dark btn-sm\">\n                                                <i class=\"fa-solid fa-clock-rotate-left\"></i>\n                                            </button>\n                                            <button type=\"button\" id=\"btnDeleteCron";
    echo $cron["id"];
    echo "\"\n                                                onclick=\"deleteCron(`";
    echo $cron["id"];
    echo "`)\" class=\"btn btn-danger btn-sm\">\n                                                <i class=\"fa-solid fa-trash\"></i>\n                                            </button>\n                                        </td>\n                                    </tr>\n                                    ";
}
echo "                                </tbody>\n                                <tfoot>\n                                    <td colspan=\"9\">\n                                        <div class=\"d-flex justify-content-between align-items-center\">\n                                            <div class=\"btn-list\">\n                                                <button type=\"button\" id=\"btn_pause\" class=\"btn btn-danger btn-sm\"\n                                                    data-toggle=\"tooltip\" data-placement=\"bottom\"\n                                                    title=\"";
echo __("Tạm dừng các link đã chọn");
echo "\">\n                                                    <i class=\"fa-solid fa-pause\"></i> ";
echo __("Tạm dừng");
echo "                                                </button>\n                                                <button type=\"button\" id=\"btn_active\" data-toggle=\"tooltip\"\n                                                    data-placement=\"bottom\"\n                                                    title=\"";
echo __("Kích hoạt các link đã chọn");
echo "\"\n                                                    class=\"btn btn-info btn-sm\">\n                                                    <i class=\"fa-solid fa-play\"></i> ";
echo __("Kích hoạt");
echo "                                                </button>\n                                                <button type=\"button\" id=\"btn_delete\" class=\"btn btn-danger btn-sm\"\n                                                    data-toggle=\"tooltip\" data-placement=\"bottom\"\n                                                    title=\"";
echo __("Xóa các link đã chọn");
echo "\">\n                                                    <i class=\"fa-solid fa-trash\"></i> ";
echo __("Xóa");
echo "                                                </button>\n                                            </div>\n                                            <div class=\"text-right\">\n                                                ";
echo __("Doanh thu:");
echo "                                                <strong\n                                                    style=\"color:red;\">";
echo format_currency($CMSNT->get_row(" SELECT SUM(`pay`) FROM `cron_jobs` WHERE " . $where . " ")["SUM(`pay`)"]);
echo "</strong>\n\n                                            </div>\n                                        </div>\n                                    </td>\n                                </tfoot>\n                            </table>\n                        </div>\n                        <div class=\"row\">\n                            <div class=\"col-sm-12 col-md-5\">\n                                <p class=\"dataTables_info\">Showing ";
echo $limit;
echo " of ";
echo format_cash($totalDatatable);
echo "                                    Results</p>\n                            </div>\n                            <div class=\"col-sm-12 col-md-7 mb-3\">\n                                ";
echo $limit < $totalDatatable ? $urlDatatable : "";
echo "                            </div>\n                        </div>\n                    </div>\n                </div>\n            </div>\n        </div>\n    </div>\n</div>\n\n\n\n\n\n<div class=\"modal fade\" id=\"exampleModalScrollable2\" tabindex=\"-1\" aria-labelledby=\"exampleModalScrollable2\"\n    data-bs-keyboard=\"false\" aria-hidden=\"true\">\n    <!-- Scrollable modal -->\n    <div class=\"modal-dialog modal-dialog-centered modal-lg dialog-scrollable\">\n        <div class=\"modal-content\">\n            <div class=\"modal-header\">\n                <h6 class=\"modal-title\" id=\"staticBackdropLabel2\"><i class=\"fa-solid fa-plus\"></i>\n                    ";
echo __("Thêm server mới");
echo "                </h6>\n                <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\"></button>\n            </div>\n            <form action=\"\" method=\"POST\" enctype=\"multipart/form-data\">\n                <div class=\"modal-body\">\n                    <div class=\"row mb-4\">\n                        <label class=\"col-sm-4 col-form-label\" for=\"example-hf-email\">";
echo __("Tên Server");
echo " (<span\n                                class=\"text-danger\">*</span>)</label>\n                        <div class=\"col-sm-8\">\n                            <input type=\"text\" class=\"form-control\" name=\"name\" required>\n                        </div>\n                    </div>\n                    <div class=\"row mb-4\">\n                        <label class=\"col-sm-4 col-form-label\" for=\"example-hf-email\">";
echo __("IP Server");
echo " (<span\n                                class=\"text-danger\">*</span>)</label>\n                        <div class=\"col-sm-8\">\n                            <input type=\"text\" class=\"form-control\" name=\"ip\" required>\n                        </div>\n                    </div>\n                    <div class=\"row mb-4\">\n                        <label class=\"col-sm-4 col-form-label\" for=\"example-hf-email\">";
echo __("Giá thuê");
echo " (<span\n                                class=\"text-danger\">*</span>)</label>\n                        <div class=\"col-sm-8\">\n                            <div class=\"input-group\">\n                                <input type=\"number\" class=\"form-control\" name=\"price\" required>\n                                <span class=\"input-group-text\">\n                                    ";
echo __("1 Tháng");
echo "                                </span>\n                            </div>\n                        </div>\n                    </div>\n                    <div class=\"row mb-4\">\n                        <label class=\"col-sm-4 col-form-label\" for=\"example-hf-email\">";
echo __("Giới hạn tối đa");
echo " (<span\n                                class=\"text-danger\">*</span>)</label>\n                        <div class=\"col-sm-8\">\n                            <div class=\"input-group\">\n                                <input type=\"text\" class=\"form-control\" name=\"max\" value=\"1000\" required>\n                                <span class=\"input-group-text\">\n                                    ";
echo __("Link Active");
echo "                                </span>\n                            </div>\n                        </div>\n                    </div>\n                </div>\n                <div class=\"modal-footer\">\n                    <button type=\"button\" class=\"btn btn-light \" data-bs-dismiss=\"modal\">Close</button>\n                    <button type=\"submit\" name=\"AddServer\" class=\"btn btn-primary shadow-primary btn-wave\"><i\n                            class=\"fa fa-fw fa-plus me-1\"></i>\n                        ";
echo __("Submit");
echo "</button>\n                </div>\n            </form>\n        </div>\n    </div>\n</div>\n\n\n\n";
require_once __DIR__ . "/footer.php";
echo "\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-dialog-centered modal-xl dialog-scrollable\">\n        <div class=\"modal-content\">\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/admin/cronjob.php");
echo "\",\n        method: \"POST\",\n        data: {\n            action: 'HistoryCron',\n            id: id,\n            token: '";
echo $getUser["token"];
echo "'\n        },\n        success: function(response) {\n            try {\n                var data = JSON.parse(response);\n                if (data.status === 'success') {\n                    var html = `\n                        <div class=\"modal-header\">\n                            <h6 class=\"modal-title\"><i class=\"fa-solid fa-clock-rotate-left me-2\"></i> \${data.cron.link}\n                            </h6>\n                            <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\"></button>\n                        </div>\n                        <div class=\"modal-body\">\n                            <div class=\"table-responsive table-wrapper\">\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><strong data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"\${row.time_ago}\">\n                                    <small><i class=\"fa-solid fa-calendar\"></i> \${row.run_at} - \${row.time_ago}</small></strong></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>\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<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/admin/cronjob.php");
echo "\",\n        method: \"POST\",\n        dataType: \"JSON\",\n        data: {\n            id: id,\n            token: '";
echo $getUser["token"];
echo "',\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/admin/cronjob.php");
echo "\",\n        method: \"POST\",\n        dataType: \"JSON\",\n        data: {\n            id: id,\n            token: '";
echo $getUser["token"];
echo "',\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<script>\n\$(\"#btn_delete\").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 xóa.");
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 sẽ XÓA");
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            delete_records();\n        }\n    });\n});\n\nfunction delete_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_delete(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 __("Xóa link 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_delete(id) {\n    \$.ajax({\n        url: \"";
echo BASE_URL("ajaxs/admin/cronjob.php");
echo "\",\n        method: \"POST\",\n        dataType: \"JSON\",\n        data: {\n            id: id,\n            token: '";
echo $getUser["token"];
echo "',\n            action: 'deleteCron'\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 deleteCron(id) {\n    const originalContent = \$('#btnDeleteCron' + id).html(); // Save the original button content\n    \$('#btnDeleteCron' + id).html('<span><i class=\"fa fa-spinner fa-spin\"></i></span>')\n        .prop('disabled', true);\n\n    Swal.fire({\n        title: \"";
echo __("Bạn có chắc không?");
echo "\",\n        text: \"";
echo __("Hệ thống sẽ xóa Link CRON này nếu bạn 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            post_delete(id);\n            setTimeout(() => {\n                location.reload();\n            }, 500);\n        }\n    }).finally(() => {\n        // Restore the button content and enable it when Swal closes\n        \$('#btnDeleteCron' + id).html(originalContent)\n            .prop('disabled', false);\n    });\n}\n</script>";

?>