<?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");
}
echo "\n<div class=\"col-lg-7\">\n    <div class=\"home-heading mb-3\">\n        <h3><i class=\"fa-solid fa-plus m-2\"></i>";
echo mb_strtoupper(__("Thêm link CRON"));
echo "            <span style=\"float: right;\">\n                <a class=\"btn btn-danger btn-sm\" href=\"";
echo base_url("cron-jobs");
echo "\"><i\n                        class=\"fa-solid fa-history me-1\"></i>";
echo mb_strtoupper(__("Lịch sử CRON"));
echo "</a>\n            </span>\n        </h3>\n    </div>\n    <div class=\"account-card pt-3\">\n        <fieldset>\n            <legend>";
echo __("Cấu hình");
echo "</legend>\n            <div class=\"form-group row\">\n                <div class=\"col-lg-3 col-form-label required fw-bold fs-6\">\n                    <label class=\"form-label\">";
echo __("Liên kết cần CRON");
echo " (<span class=\"text-danger\">*</span>)</label>\n                </div>\n                <div class=\"col-xl-9 fv-row\">\n                    <input type=\"hidden\" id=\"token\" class=\"form-control\"\n                        value=\"";
echo isset($getUser) ? $getUser["token"] : "";
echo "\" />\n                    <input type=\"text\" class=\"form-control\" id=\"link_cron\" required>\n                    <small id=\"link-error\" class=\"text-danger\" style=\"display: none;\">\n                        ";
echo __("Vui lòng nhập liên kết hợp lệ.");
echo "                    </small>\n                </div>\n            </div>\n            <div class=\"form-group row\">\n                <div class=\"col-lg-8 col-form-label required fw-bold fs-6\">\n                    <label class=\"form-label\">";
echo __("Vòng lặp");
echo " (<span class=\"text-danger\">*</span>)</label>\n                </div>\n                <div class=\"col-xl-4 fv-row\">\n                    <div class=\"input-group mb-3\">\n                        <input type=\"number\" class=\"form-control\" id=\"timeloop\" value=\"60\">\n                        <span class=\"input-group-text\">";
echo __("giây");
echo "</span>\n                    </div>\n                    <small id=\"timeloop-error\" class=\"text-danger\" style=\"display: none;\">";
echo __("Vòng lặp phải lớn\n                                    hơn hoặc bằng <span id=\"showTimeloop\"></span> giây.");
echo "</small>\n                </div>\n            </div>\n            <div class=\"form-group row\">\n                <div class=\"col-lg-8 col-form-label required fw-bold fs-6\">\n                    <label class=\"form-label\">";
echo __("Phương thức");
echo " (<span class=\"text-danger\">*</span>)</label>\n                </div>\n                <div class=\"col-xl-4 fv-row\">\n                    <select class=\"form-control\" id=\"method\">\n                        <option value=\"GET\">GET</option>\n                        <option value=\"POST\">POST</option>\n                    </select>\n                </div>\n            </div>\n        </fieldset>\n        <fieldset>\n            <legend>";
echo __("Server");
echo "</legend>\n            <div class=\"form-group row\">\n                <div class=\"col-lg-4 col-form-label required fw-bold fs-6\">\n                    <label class=\"form-label\">";
echo __("Máy chủ");
echo " (<span class=\"text-danger\">*</span>)</label>\n                </div>\n                <div class=\"col-xl-8 fv-row\">\n                    <select class=\"form-control\" id=\"server_id\" onchange=\"totalPrice()\">\n                        ";
foreach ($CMSNT->get_list(" SELECT * FROM `cron_server` WHERE `status` = 1 ") as $server) {
    echo "                        ";
    $total_active_link_server = $CMSNT->get_row(" SELECT COUNT(id) FROM `cron_jobs` WHERE `server_id` = '" . $server["id"] . "' AND `status` = 'active' ")["COUNT(id)"];
    if($server["max"] <= $total_active_link_server) {
    } else {
        echo "                        <option value=\"";
        echo $server["id"];
        echo "\" data-timeloop=\"";
        echo $server["timeloop"];
        echo "\">\n                            ";
        echo $server["name"];
        echo " - ";
        echo format_currency($server["price"]);
        echo "</option>\n                        ";
    }
}
echo "                    </select>\n                </div>\n            </div>\n            <div class=\"form-group row\">\n                <div class=\"col-lg-4 col-form-label required fw-bold fs-6\">\n                    <label class=\"form-label\">";
echo __("Thời hạn");
echo " (<span class=\"text-danger\">*</span>)</label>\n                </div>\n                <div class=\"col-xl-8 fv-row\">\n                    <select class=\"form-control\" id=\"rental_period\" onchange=\"totalPrice()\">\n                        ";
foreach (explode(PHP_EOL, $CMSNT->site("cronjob_billing_cycle")) as $option) {
    echo "                        ";
    $option = explode("|", $option);
    echo "                        <option value=\"";
    echo $option[0];
    echo "\">";
    echo __($option[1]);
    echo "</option>\n                        ";
}
echo "                    </select>\n                </div>\n            </div>\n        </fieldset>\n        <div class=\"form-group text-center\">\n            <div class=\"alert bg-white alert-info\" role=\"alert\">\n                <div class=\"iq-alert-icon\">\n                    <i class=\"ri-alert-line\"></i>\n                </div>\n                <div class=\"iq-alert-text\">";
echo __("Số tiền cần thanh toán");
echo ": <b id=\"ketqua\" style=\"color: red;\">0đ</b>\n                </div>\n            </div>\n        </div>\n        <script>\n        totalPrice();\n\n        function totalPrice() {\n            \$.ajax({\n                url: \"";
echo BASE_URL("ajaxs/client/cronjob.php");
echo "\",\n                method: \"POST\",\n                dataType: \"JSON\",\n                data: {\n                    action: 'totalPayment',\n                    server_id: \$(\"#server_id\").val(),\n                    rental_period: \$(\"#rental_period\").val(),\n                    token: \$(\"#token\").val()\n                },\n                success: function(data) {\n                    if (data.status == 'success') {\n                        const ketqua = \$(\"#ketqua\");\n                        ketqua.html(data.money);\n                    } else {\n                        showMessage(data.msg, data.status);\n                    }\n                },\n                error: function() {\n                    showMessage('";
echo __("Vui lòng liên hệ Developer");
echo "', 'error');\n                }\n            });\n        }\n        </script>\n\n        <button class=\"btn-buy\" id=\"btnBuy\" onclick=\"buyProduct()\">\n            <i class=\"fa-solid fa-cart-shopping\"></i>\n            <span>";
echo __("THANH TOÁN");
echo "</span>\n        </button>\n\n    </div>\n</div>\n<div class=\"col-lg-5\">\n    <div class=\"home-heading mb-3\">\n        <h3><i class=\"fa-solid fa-triangle-exclamation m-2\"></i>";
echo mb_strtoupper(__("Lưu ý"));
echo "        </h3>\n    </div>\n    <div class=\"account-card pt-3\">\n        ";
echo $CMSNT->site("cronjob_note");
echo "    </div>\n</div>\n\n\n\n<script type=\"text/javascript\">\nfunction isValidURL(url) {\n    const pattern = new RegExp('^(https?:\\\\/\\\\/)?' +\n        '((([a-zA-Z0-9\\\\-]+\\\\.)+[a-zA-Z]{2,})|' +\n        '((\\\\d{1,3}\\\\.){3}\\\\d{1,3}))' +\n        '(\\\\:\\\\d+)?(\\\\/[-a-zA-Z0-9@:%_\\\\+.~#?&//=]*)?\$', 'i');\n    return !!pattern.test(url);\n}\n\nfunction buyProduct() {\n    // Xóa khoảng trắng ở đầu và cuối chuỗi\n    const linkCron = document.getElementById('link_cron').value.trim();\n    if (!isValidURL(linkCron)) {\n        Swal.fire('";
echo __("Failure!");
echo "', '";
echo __("Liên kết CRON không hợp lệ");
echo "', 'error');\n        return;\n    }\n    Swal.fire({\n        title: '";
echo __("Xác nhận thanh toán");
echo "',\n        text: \"";
echo __("Bạn có chắc chắn muốn thanh toán không?");
echo "\",\n        icon: 'warning',\n        showCancelButton: true,\n        confirmButtonText: '";
echo __("Đồng ý");
echo "',\n        cancelButtonText: '";
echo __("Hủy bỏ");
echo "',\n        reverseButtons: true\n    }).then((result) => {\n        if (result.isConfirmed) {\n            processBuyProduct();\n        }\n    });\n}\n\n\nfunction processBuyProduct() {\n    const btnBuy = document.getElementById('btnBuy');\n    const btnContent = btnBuy.innerHTML;\n    \$('#btnBuy').html('<i class=\"fa fa-spinner fa-spin\"></i>')\n        .prop('disabled',\n            true);\n    \$.ajax({\n        url: \"";
echo base_url("ajaxs/client/cronjob.php");
echo "\",\n        method: \"POST\",\n        dataType: \"JSON\",\n        data: {\n            action: 'AddCronJob',\n            token: \$(\"#token\").val(),\n            link_cron: \$(\"#link_cron\").val(),\n            timeloop: \$(\"#timeloop\").val(),\n            method: \$(\"#method\").val(),\n            server_id: \$(\"#server_id\").val(),\n            rental_period: \$(\"#rental_period\").val(),\n        },\n        success: function(response) {\n            if (response.status == 'success') {\n                Swal.fire({\n                    title: '";
echo __("Successful!");
echo "',\n                    text: response.msg,\n                    icon: 'success',\n                    showCancelButton: true,\n                    confirmButtonText: '";
echo __("Xem đơn hàng");
echo "', // Nút xem đơn hàng\n                    cancelButtonText: '";
echo __("Thêm liên kết mới");
echo "', // Nút tạo tiếp\n                    reverseButtons: true\n                }).then((result) => {\n                    if (result.isConfirmed) {\n                        window.location.href = '";
echo base_url("cron-jobs");
echo "';\n                    }\n                });\n            } else {\n                Swal.fire('";
echo __("Failure!");
echo "', response.msg, 'error');\n            }\n            \$('#btnBuy').html(btnContent).prop('disabled', false);\n        },\n        error: function() {\n            showMessage('";
echo __("Không thể xử lý");
echo "', 'error');\n            \$('#btnBuy').html(\n                btnContent\n            ).prop('disabled',\n                false);\n        }\n    });\n}\n</script>\n\n<script>\ndocument.addEventListener('DOMContentLoaded', function() {\n\n\n    document.getElementById('link_cron').addEventListener('input', function() {\n        let linkValue = this.value.trim(); // Loại bỏ khoảng trắng ở đầu và cuối\n        const errorElement = document.getElementById('link-error');\n\n        if (!isValidURL(linkValue)) {\n            errorElement.style.display = 'block';\n        } else {\n            errorElement.style.display = 'none';\n        }\n    });\n\n    document.getElementById('timeloop').addEventListener('input', function() {\n        const timeloopValue = parseInt(this.value, 10);\n        const selectedServer = document.getElementById('server_id').selectedOptions[0];\n        const minTimeloop = parseInt(selectedServer.getAttribute('data-timeloop'), 10);\n        const errorElement = document.getElementById('timeloop-error');\n        const showTimeloopElement = document.getElementById('showTimeloop');\n\n        if (timeloopValue < minTimeloop) {\n            errorElement.style.display = 'block';\n            showTimeloopElement.textContent = minTimeloop;\n        } else {\n            errorElement.style.display = 'none';\n        }\n    });\n\n    document.getElementById('server_id').addEventListener('change', function() {\n        // Reset timeloop input value when changing server\n        document.getElementById('timeloop').value = '';\n        document.getElementById('timeloop-error').style.display = 'none';\n    });\n});\n</script>";

?>