<?php
include('include/head.php');
include("loginCheck.php");
include('include/header.php');
include('include/menu.php');
requireLogin();

$db = getDB();

$todayDate = date('Y-m-d');
$d = date('Y-m-d H:i:s');


$stmt = $db->query("SELECT COUNT(*) FROM meddolic_user_details WHERE user_type=2");
$totalUser = (int) $stmt->fetchColumn();


$stmt = $db->query("SELECT COUNT(*) FROM meddolic_user_details WHERE user_type=2 AND topup_flag=1");
$activeUser = (int) $stmt->fetchColumn();


$stmt = $db->query("SELECT COUNT(*) FROM meddolic_user_details WHERE user_type=2 AND topup_flag=0");
$inActiveUser = (int) $stmt->fetchColumn();


$stmt = $db->prepare("SELECT COUNT(*) FROM meddolic_user_details WHERE DATE(date_time)=?");
$stmt->execute([$todayDate]);
$todayActive = (int) $stmt->fetchColumn();


$stmt = $db->query("SELECT COALESCE(SUM(wallet),0) AS wallet, COALESCE(SUM(fundWallet),0) AS fundWallet FROM meddolic_user_details");
$row = $stmt->fetch();

$workingWallet = (float) $row['wallet'];
$fundWallet = (float) $row['fundWallet'];


$stmt = $db->query("SELECT COALESCE(SUM(investPrice),0) FROM meddolic_user_activation_details");
$totalBusiness = (float) $stmt->fetchColumn();


$stmt = $db->prepare("SELECT COALESCE(SUM(investPrice),0) FROM meddolic_user_activation_details WHERE DATE(date_time)=?");
$stmt->execute([$todayDate]);
$todayBusiness = (float) $stmt->fetchColumn();


// $stmt = $db->query("SELECT COALESCE(SUM(amount),0) FROM meddolic_user_wallet_withdrawal_crypto WHERE released IN (0,1)");
// $totalWithdraw = (float) $stmt->fetchColumn();

// $stmt = $db->query("SELECT COALESCE(SUM(amount),0) FROM meddolic_user_wallet_withdrawal_crypto WHERE released IN (0,4)");
// $totalPendingWithdraw = (float) $stmt->fetchColumn();

?>

<div id="main-content">
    <div class="container-fluid">
        <div class="block-header">
            <div class="row">
                <div class="col-lg-5 col-md-8 col-sm-12">
                    <h2><a href="javascript:void(0);" onclick="window.history.back();"
                            class="btn btn-xs btn-link btn-toggle-fullwidth"><i class="fa fa-arrow-left"></i></a>
                        Dashboard</h2>
                    <ul class="breadcrumb">
                        <li class="breadcrumb-item"><a href="dashboard"><i class="icon-home"></i></a></li>
                        <li class="breadcrumb-item active">Dashboard</li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="row clearfix">
            <div class="col-lg-12 col-xs-12">
                <div class="form-group" align="center"
                    style="font-size: 16px;font-weight: 600;background-color: #fff;color: #000;">
                    <label>Referral URL</label>
                    <input id="referralCone" type="hidden" readonly
                        value="https://hisshoglobal.com/register/Register.php?ref=<?= $walletAddress ?>">
                    <a style="display: inline-block;margin-top: 1px;font-weight: bold;padding: 3px 8px;border-radius: 5px;"
                        href="javascript:void(0)" onclick="copyLink('referralCone')"
                        class="btn btn-sm btn-success waves-effect">
                        <i class="fa fa-copy"></i>
                        <span>Copy </span>
                    </a>
                    <a style="display: inline-block;margin-top: 1px;font-weight: bold;padding: 3px 8px;border-radius: 5px;"
                        target="_blank"
                        href="https://api.whatsapp.com/send?phone=&amp;text=https://hisshoglobal.com/register/Register.php?ref<?= $walletAddress ?>"
                        class="btn btn-sm btn-danger waves-effect">
                        <i class="fa fa-whatsapp"></i>
                        <span>Whatsapp</span>
                    </a>

                    <a style="display: inline-block;margin-top: 1px;font-weight: bold;padding: 3px 8px;border-radius: 5px;"
                        target="_blank"
                        href="http://www.facebook.com/sharer/sharer.php?u=https://hisshoglobal.com/register/Register.php?ref<?= $walletAddress ?>&amp;quote=text"
                        class="btn btn-sm btn-primary waves-effect">
                        <i class="fa fa-facebook-f"></i>
                        <span>Facebook</span>
                    </a>
                    <a style="display: inline-block;margin-top: 1px;font-weight: bold;padding: 3px 8px;border-radius: 5px;"
                        target="_blank"
                        href="https://telegram.me/share/url?url=https://hisshoglobal.com/register/Register.php?ref<?= $walletAddress ?>&text=text"
                        class="btn btn-sm btn-success waves-effect">
                        <i class="fa fa-telegram"></i>
                        <span>Telegram</span>
                    </a>
                </div>
            </div>
        </div>
        <div class="row clearfix">
            <div class="col-lg-3 col-md-6">
                <a href="viewMember.php">
                    <div class="card top_counter currency_state ">
                        <div class="body">
                            <div class="icon text-primary"><i class="fa fa-users"></i> </div>
                            <div class="content">
                                <div class="text">Total Users</div>
                                <h5 class="number"><?= isset($totalUser) ? $totalUser : '0'; ?></h5>
                            </div>
                        </div>
                    </div>
                </a>
            </div>

            <div class="col-lg-3 col-md-6">
                <a href="viewMember.php">
                    <div class="card top_counter currency_state ">
                        <div class="body">
                            <div class="icon text-primary"><i class="fa fa-users"></i> </div>
                            <div class="content">
                                <div class="text">Active Users</div>
                                <h5 class="number"><?= isset($activeUser) ? $activeUser : '0'; ?></h5>
                            </div>
                        </div>
                    </div>
                </a>
            </div>

            <div class="col-lg-3 col-md-6">
                <a href="viewMember.php">
                    <div class="card top_counter currency_state ">
                        <div class="body">
                            <div class="icon text-primary"><i class="fa fa-users"></i> </div>
                            <div class="content">
                                <div class="text">Inactive Users</div>
                                <h5 class="number"><?= isset($inActiveUser) ? $inActiveUser : '0'; ?></h5>
                            </div>
                        </div>
                    </div>
                </a>
            </div>
            <div class="col-lg-3 col-md-6">
                <a href="activationHistory.php">
                    <div class="card top_counter currency_state">
                        <div class="body">
                            <div class="icon text-primary"><i class="fa fa-users"></i></div>
                            <div class="content">
                                <div class="text">Today Activation</div>
                                <h5 class="number"> <?= isset($todayActive) ? $todayActive : '0'; ?></h5>
                            </div>
                        </div>
                    </div>
                </a>
            </div>

            <div class="col-lg-3 col-md-6">
                <a href="">
                    <div class="card top_counter currency_state">
                        <div class="body">
                            <div class="icon text-primary"><i class="fa fa-users"></i></div>
                            <div class="content">
                                <div class="text"> Wallet</div>
                                <h5 class="number">$ <?= isset($workingWallet) ? $workingWallet : '0'; ?></h5>
                            </div>
                        </div>
                    </div>
                </a>
            </div>

            <!-- <div class="col-lg-3 col-md-6">
                <a href="walletWithdrawStatus">
                    <div class="card top_counter currency_state">
                        <div class="body">
                            <div class="icon text-primary"><i class="fa fa-users"></i></div>
                            <div class="content">
                                <div class="text">Total Withdrawal</div>
                                <h5 class="number">$ <?= isset($totalWithdraw) ? $totalWithdraw : '0'; ?></h5>
                            </div>
                        </div>
                    </div>
                </a>
            </div>



            <div class="col-lg-3 col-md-6">
                <a href="walletWithdrawStatus">
                    <div class="card top_counter currency_state">
                        <div class="body">
                            <div class="icon text-primary"><i class="fa fa-users"></i></div>
                            <div class="content">
                                <div class="text">Pending Withdrawal</div>
                                <h5 class="number">$ <?= isset($totalPendingWithdraw) ? $totalPendingWithdraw : '0'; ?>
                                </h5>
                            </div>
                        </div>
                    </div>
                </a>
            </div> -->


            <div class="col-lg-3 col-md-6">
                <a href="activationHistory.php">
                    <div class="card top_counter currency_state">
                        <div class="body">
                            <div class="icon text-primary"><i class="fa fa-money"></i></div>
                            <div class="content">
                                <div class="text">Total Business</div>
                                <h5 class="number">$ <?= isset($totalBusiness) ? $totalBusiness : '0'; ?></h5>
                            </div>
                        </div>
                    </div>
                </a>
            </div>


            <div class="col-lg-3 col-md-6">
                <a href="activationHistory.php">
                    <div class="card top_counter currency_state">
                        <div class="body">
                            <div class="icon text-primary"><i class="fa fa-money"></i></div>
                            <div class="content">
                                <div class="text">Today Business</div>
                                <h5 class="number">$ <?= isset($todayBusiness) ? $todayBusiness : '0'; ?></h5>
                            </div>
                        </div>
                    </div>
                </a>
            </div>



        </div>
    </div>
</div>
<?php include('include/footer.php'); ?>
<script>
    function copyLink(referralId) {
        var link = $("#" + referralId).val();
        var tempInput = document.createElement("input");
        tempInput.style = "position: absolute; left: -1000px; top: -1000px";
        tempInput.value = link;
        document.body.appendChild(tempInput);
        tempInput.select();
        document.execCommand("copy");
        alert('Referral Link Copied Successfully');
    }
    var d = document.getElementById("dashboard");
    d.className += " active";
</script>
</body>

</html>