<?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.
define("IN_SITE", true);
require_once __DIR__ . "/../../config.php";
require_once __DIR__ . "/../../libs/db.php";
require_once __DIR__ . "/../../libs/lang.php";
require_once __DIR__ . "/../../libs/helper.php";
require_once __DIR__ . "/../../models/is_admin.php";
if(!isset($_POST["action"])) {
    $data = json_encode(["status" => "error", "msg" => __("The Request Not Found")]);
    exit($data);
}
if($_POST["action"] == "phan_tich_utm_source_users") {
    if(empty($_POST["token"])) {
        exit(json_encode(["status" => "error", "msg" => __("Vui lòng đăng nhập để sử dụng tính năng này")]));
    }
    if(!($getUser = $CMSNT->get_row("SELECT * FROM `users` WHERE `token` = '" . check_string($_POST["token"]) . "' AND `banned` = 0 AND `admin` != 0 "))) {
        exit(json_encode(["status" => "error", "msg" => __("Vui lòng đăng nhập để sử dụng tính năng này")]));
    }
    if(!checkPermission($getUser["admin"], "view_user")) {
        exit(json_encode(["status" => "error", "msg" => __("Bạn không có quyền sử dụng tính năng này")]));
    }
    $html = "<ul class=\"nav nav-tabs mb-5 nav-justified nav-style-1 d-sm-flex d-block\" id=\"myTab\" role=\"tablist\">";
    $html .= "<li class=\"nav-item\">";
    $html .= "<a class=\"nav-link active\" id=\"table-tab\" data-toggle=\"tab\" href=\"#table-content\" role=\"tab\" aria-controls=\"table-content\" aria-selected=\"true\">Table</a>";
    $html .= "</li>";
    $html .= "<li class=\"nav-item\">";
    $html .= "<a class=\"nav-link\" id=\"chart-tab\" data-toggle=\"tab\" href=\"#chart-content\" role=\"tab\" aria-controls=\"chart-content\" aria-selected=\"false\">Pie Chart</a>";
    $html .= "</li>";
    $html .= "</ul>";
    $html .= "<div class=\"tab-content\" id=\"myTabContent\">";
    $html .= "<div class=\"tab-pane fade show active\" id=\"table-content\" role=\"tabpanel\" aria-labelledby=\"table-tab\">";
    $html .= "<div class=\"table-responsive table-wrapper\" style=\"max-height: 500px;overflow-y: auto;\">";
    $html .= "<table class=\"table text-nowrap table-striped table-hover table-bordered\">\n            <thead>\n                <tr>\n                    <th class=\"text-center\">Xếp hạng</th>\n                    <th class=\"text-center\">utm_source</th>\n                    <th class=\"text-center\">Số thành viên đăng ký</th>\n                </tr>\n            </thead>\n            <tbody>";
    $i = 1;
    $data_labels = [];
    $data_user_counts = [];
    foreach ($CMSNT->get_list("SELECT \n    utm_source, \n    COUNT(*) AS total_users\nFROM users \nGROUP BY utm_source \nORDER BY total_users DESC ") as $row) {
        $data_labels[] = $row["utm_source"];
        $data_user_counts[] = $row["total_users"];
        $html .= "<tr>\n    <td class='text-center' style='font-size:15px;'>" . $i++ . "</td>\n    <td class='text-center'>" . $row["utm_source"] . "</td>\n    <td class='text-center'><b>" . format_cash($row["total_users"]) . "</b></td>\n  </tr>";
    }
    $html .= "</tbody>\n        </table>";
    $html .= "</div>";
    $html .= "</div>";
    $html .= "<div class=\"tab-pane fade\" id=\"chart-content\" role=\"tabpanel\" aria-labelledby=\"chart-tab\">";
    $html .= "<canvas id=\"myChart\" width=\"500\" height=\"300\"></canvas>";
    $html .= "</div>";
    $html .= "</div>";
    $html .= "<script>\n            \$(document).ready(function(){\n                \$(\"#table-tab\").click(function(){\n                    \$(\"#chart-content\").removeClass(\"show active\");\n                    \$(\"#chart-tab\").removeClass(\"active\");\n                    \$(\"#table-content\").addClass(\"show active\");\n                    \$(\"#table-tab\").addClass(\"active\");\n                });\n                \$(\"#chart-tab\").click(function(){\n                    \$(\"#table-content\").removeClass(\"show active\");\n                    \$(\"#table-tab\").removeClass(\"active\");\n                    \$(\"#chart-content\").addClass(\"show active\");\n                    \$(\"#chart-tab\").addClass(\"active\");\n                    // Thêm kịch bản JavaScript để vẽ biểu đồ Pie Chart\n                    var ctx = document.getElementById(\"myChart\").getContext(\"2d\");\n                    var myChart = new Chart(ctx, {\n                        type: \"pie\",\n                        data: {\n                            labels: " . json_encode($data_labels) . ",\n                            datasets: [{\n                                label: \"Số lượng người dùng\",\n                                data: " . json_encode($data_user_counts) . ",\n                                backgroundColor: [\n                                    \"rgba(255, 99, 132, 0.6)\",\n                                    \"rgba(54, 162, 235, 0.6)\",\n                                    \"rgba(255, 206, 86, 0.6)\",\n                                    \"rgba(75, 192, 192, 0.6)\",\n                                    \"rgba(153, 102, 255, 0.6)\",\n                                    \"rgba(255, 159, 64, 0.6)\"\n                                ],\n                                borderColor: [\n                                    \"rgba(255, 99, 132, 1)\",\n                                    \"rgba(54, 162, 235, 1)\",\n                                    \"rgba(255, 206, 86, 1)\",\n                                    \"rgba(75, 192, 192, 1)\",\n                                    \"rgba(153, 102, 255, 1)\",\n                                    \"rgba(255, 159, 64, 1)\"\n                                ],\n                                borderWidth: 1\n                            }]\n                        },\n                        options: {\n                            responsive: true,\n                            maintainAspectRatio: false,\n                            legend: {\n                                position: \"right\",\n                                labels: {\n                                    fontColor: \"black\",\n                                    fontSize: 12\n                                }\n                            }\n                        }\n                    });\n                });\n            });\n        </script>";
    exit($html);
} elseif($_POST["action"] == "view_nap_tien_gan_day") {
    if(empty($_POST["token"])) {
        exit(json_encode(["status" => "error", "msg" => __("Vui lòng đăng nhập để sử dụng tính năng này")]));
    }
    if(!($getUser = $CMSNT->get_row("SELECT * FROM `users` WHERE `token` = '" . check_string($_POST["token"]) . "' AND `banned` = 0 AND `admin` != 0 "))) {
        exit(json_encode(["status" => "error", "msg" => __("Vui lòng đăng nhập để sử dụng tính năng này")]));
    }
    if(!checkPermission($getUser["admin"], "view_recent_transactions")) {
        exit(json_encode(["status" => "error", "msg" => __("Bạn không có quyền sử dụng tính năng này")]));
    }
    $deposits = $CMSNT->get_list("SELECT * FROM `deposit_log` WHERE `is_virtual` = 0 ORDER BY id DESC limit 100");
    $html = "";
    foreach ($deposits as $deposit) {
        $html .= "<li>\n        <div class=\"timeline-time text-end\">\n            <span class=\"date\">" . timeAgo($deposit["create_time"]) . "</span>\n        </div>\n        <div class=\"timeline-icon\">\n            <a href=\"javascript:void(0);\"></a>\n        </div>\n        <div class=\"timeline-body\">\n            <div class=\"d-flex align-items-top timeline-main-content flex-wrap mt-0\">\n                <div class=\"flex-fill\">\n                    <div class=\"d-flex align-items-center\">\n                        <div class=\"mt-sm-0 mt-2\">\n                            <p class=\"mb-0 text-muted\"><b style=\"color: green;\">" . getRowRealtime("users", $deposit["user_id"], "username") . "</b>\n                                thực hiện nạp <b style=\"color: blue;\">" . format_currency($deposit["amount"]) . "</b>\n                                bằng <b style=\"color:red\">" . $deposit["method"] . "</b> thực nhận <b style=\"color:blue;\">" . format_currency($deposit["received"]) . "</b>\n                            </p>\n                        </div>\n                    </div>\n                </div>\n            </div>\n        </div>\n    </li>";
    }
    exit($html);
} elseif($_POST["action"] == "view_don_hang_gan_day") {
    if(empty($_POST["token"])) {
        exit(json_encode(["status" => "error", "msg" => __("Vui lòng đăng nhập để sử dụng tính năng này")]));
    }
    if(!($getUser = $CMSNT->get_row("SELECT * FROM `users` WHERE `token` = '" . check_string($_POST["token"]) . "' AND `banned` = 0 AND `admin` != 0 "))) {
        exit(json_encode(["status" => "error", "msg" => __("Vui lòng đăng nhập để sử dụng tính năng này")]));
    }
    if(!checkPermission($getUser["admin"], "view_recent_transactions")) {
        exit(json_encode(["status" => "error", "msg" => __("Bạn không có quyền sử dụng tính năng này")]));
    }
    $orders = $CMSNT->get_list("SELECT * FROM `cron_jobs` ORDER BY id DESC limit 100");
    $html = "";
    foreach ($orders as $order) {
        $html .= "<li>\n            <div class=\"timeline-time text-end\">\n                <span class=\"date\">" . timeAgo(strtotime($order["created_at"])) . "</span>\n            </div>\n            <div class=\"timeline-icon\">\n                <a href=\"javascript:void(0);\"></a>\n            </div>\n            <div class=\"timeline-body\">\n                <div class=\"d-flex align-items-top timeline-main-content flex-wrap mt-0\">\n                    <div class=\"flex-fill\">\n                        <div class=\"d-flex align-items-center\">\n                            <div class=\"mt-sm-0 mt-2\">\n                                <p class=\"mb-0 text-muted\"><b style=\"color: green;\">" . getRowRealtime("users", $order["user_id"], "username") . "</b>\n                                    tạo đơn hàng CRON link\n                                    <b>" . $order["link_cron"] . "</b> với giá <b style=\"color:blue;\">" . format_currency($order["pay"]) . "</b>\n                                </p>\n                            </div>\n                        </div>\n                    </div>\n                </div>\n            </div>\n        </li>";
    }
    exit($html);
}

?>