<?php
if (!isset($_COOKIE["user"])) {
    header("Location: ../login.html");
    exit();
}

if (isset($_GET["action"])) {
    if ($_GET["action"] == "logout") {
        setcookie("user", "logout", time() - (24 * 60 * 60 * 24), "/");
        header("Location: ../login.html");
        exit();
    }
}

$user = $_COOKIE["user"];
$j_data = json_decode(file_get_contents("../u.j"), false);
$admin_text = "";
if (isset($j_data->users->$user)) {
    if ($j_data->users->$user->admin) {
        $admin_text = '<li>
                            <a href="admin.php" class="waves-effect">
                                <i class="fas fa-user-lock-cog"></i><span> ADMIN Dashboard </span>
                            </a>
                        </li>';
    }
    $email = $j_data->users->$user->email;
    $interest_rate = $j_data->users->$user->interest_rate;
    $investment_date = $j_data->users->$user->investment_date;
    $investment_plan = $j_data->users->$user->stock;
    $account_balance = $j_data->users->$user->account_balance;
    $investment_profits = $j_data->users->$user->investment_profits;
    $duration = $j_data->users->$user->duration;
        $ref = $j_data->users->$user->refs_earnings;

    $daily_rate =($interest_rate/100) / ($duration * 7);
    $seconds_past = time() - $investment_date;
    $minutes_past = $seconds_past / 60;
    $hours_past = $minutes_past / 60;
    $days_past = $hours_past / 24;
    $weeks_past = $days_past / 7;

    if (!isset($j_data->users->$user->refs_earnings)) {
        $j_data->users->$user->refs_earnings = 0;
    }
    $refs_earnings = $j_data->users->$user->refs_earnings;

    $deposits_data = "";
    foreach (array_reverse($j_data->users->$user->deposits) as $var) {
        $deposits_data .= '<tr> <th scope="row">' . $var->ID . '</th> <td>' . $var->payment_method . '</td> <td>' . $var->amount . '</td> <td>' . $var->datee . '</td>  </tr>';
    }
    if ($deposits_data == "") {
        $deposits_data = "No deposits have been made.";
    } else {
        $deposits_data = '<table class="table table-striped mb-0"><thead> <tr> <th>Payment ID</th> <th>Payment Method</th><th>Amount</th> <th>Date</th></tr></thead><tbody>' . $deposits_data . '</tbody> </table>';
    }

    $withdraws_data = "";
    foreach (array_reverse($j_data->users->$user->withdraws) as $var) {
        $withdraws_data .= '<tr> <th scope="row">' . $var->ID . '</th> <td>' . $var->payment_method . '</td> <td>' . $var->amount . '</td> <td>' . $var->datee . '</td>  <td>' . $var->status . '</td> </tr>';
    }
    if ($withdraws_data == "") {
        $withdraws_data = "No withdraws have been made.";
    } else {
        $withdraws_data = '<table class="table table-striped mb-0"><thead> <tr> <th>Payment ID</th> <th>Payment Method</th><th>Amount</th> <th>Date</th><th>Status</th></tr></thead><tbody>' . $withdraws_data . '</tbody> </table>';
    }
} else {
    setcookie("user", "logout", time() - (24 * 60 * 60 * 24), "/");
    header("Location: ../login.html");
    exit();
}
?>


<!DOCTYPE html>
<html lang="en">


<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=1024">

    <title>globalqfsvault -Dashboard</title>

    <link rel="shortcut icon" href="ass/images/favicon.png">


    <link href="ass/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="ass/css/metismenu.min.css" rel="stylesheet" type="text/css">
    <link href="ass/css/icons.css" rel="stylesheet" type="text/css">
    <link href="ass/css/style.css" rel="stylesheet" type="text/css">

</head>

<body>


    <!-- Begin page -->
    <div id="wrapper">

        <!-- Top Bar Start -->
        <div class="topbar">

 <!-- LOGO -->
            <div class="topbar-left">
                <a href="index.php" class="logo">
                  
                   
                </a>
            </div>

            <nav class="navbar-custom">


                <ul class="list-inline menu-right mb-0">
                    <li class="float-right">
                        <button class="button-menu-mobile open-right waves-effect">
                            <i class="mdi mdi-menu"></i>
                        </button>
                    </li>

                </ul>

            </nav>

        </div>
        <!-- Top Bar End -->

        <!-- ========== Left Sidebar Start ========== -->
        <div class="left side-menu">
            <div class="slimscroll-menu" id="remove-scroll">

                <!--- Sidemenu -->
                <div id="sidebar-menu">
                    <!-- Left Menu Start -->
                    <ul class="metismenu" id="side-menu">
                        <li class="menu-title">Menu</li>
                        <?php echo $admin_text; ?>
                        <li>
                            <a href="index.php" class="waves-effect">
                                <i class="icon-accelerator"></i><span> Dashboard </span>
                            </a>
                        </li>

                        <li>
                            <a href="account.php" class="waves-effect"><i class="fas fa-book"></i><span> Account Overview</span></a>

                        </li>

                        <li>
                            <a href="profile.php" class="waves-effect"><i class="fas fa-user-lock"></i><span> Profile</span></a>

                        </li>

                        <li>
                            <a href="deposit.php" class="waves-effect"><i class="fab  fa-dropbox"></i><span> Deposit</span></a>

                        </li>


                        <li>
                            <a href="withdraw.php" class="waves-effect"><i class="fas fa-donate"></i><span> Withdraw</span></a>

                        </li>

                        <li>
                            <a href="support.php" class="waves-effect"><i class="fas fa-mail-bulk"></i><span> Customer Support</span></a>

                        </li>

                        <li>
                            <a href="index.php?action=logout" class="waves-effect"><i class="fas fa-sign-out-alt"></i><span> Logout</span></a>

                        </li>



                    </ul>

                </div>
                <!-- Sidebar -->
                <div class="clearfix"></div>

            </div>
            <!-- Sidebar -left -->

        </div>
        <!-- Left Sidebar End -->

        <!-- ============================================================== -->
        <!-- Start right Content here -->
        <!-- ============================================================== -->
        <div class="content-page">
            <!-- Start content -->
            <div class="col-sm-12">
                <h2 class="page-title">

                    <br>
                    <br>
                    Account Overview</h2>
            </div>

            <div class="content">

                <div class="container-fluid">



                    <div class="row">

                        <div class="col-sm-6 col-xl-6">
                            <div class="card">
                                <div class="card-heading p-4">
                                    <div class="mini-stat-icon float-right">
                                        <i class="fas fa-dollar-sign bg-primary text-white"></i>
                                    </div>
                                    <div>
                                        <h5 class="font-16">Last Deposit</h5>
                                    </div>
                                    <h3 class="mt-4">$ <?php echo $account_balance; ?></h3>

                                </div>
                            </div>
                        </div>

                        <div class="col-sm-6 col-xl-6">
                            <div class="card">
                                <div class="card-heading p-4">
                                    <div class="mini-stat-icon float-right">
                                        <i class="fas fa-money-bill-alt bg-danger  text-white"></i>
                                    </div>
                                    <div>
                                        <h5 class="font-16">Investment Profit</h5>
                                    </div>
                                    <h3 class="mt-4">$ <?php


$investment_profits;
echo number_format(  $investment_profits,00);

                                                        ?></h3>

                                </div>
                            </div>
                        </div>

                        <div class="col-sm-6 col-xl-6">
                            <div class="card">
                                <div class="card-heading p-4">
                                    <div class="mini-stat-icon float-right">
                                        <i class="fas fa-coins bg-warning  text-white"></i>
                                    </div>
                                    <div>
                                        <h5 class="font-16">Trading</h5>
                                    </div>
                                    <h3 class="mt-4"><?php echo $investment_plan; ?></h3>

                                </div>
                            </div>
                        </div>

                        <div class="col-sm-6 col-xl-6">
                            <div class="card">
                                <div class="card-heading p-4">
                                    <div class="mini-stat-icon float-right">
                                        <i class="fas fa-money-bill-alt bg-danger  text-white"></i>
                                    </div>
                                    <div>
                                        <h5 class="font-16">Total Balance</h5>
                                    </div>
                                    <h3 class="mt-4">$ <?php

$profit= $investment_profits + $account_balance + $ref;
echo number_format(  $profit,00);

                                                        ?></h3>



                                </div>
                            </div>
                        </div>



                    </div>

                    <!--
				<hr style="border-color:white">
				<div class="row">
					<div class="col-lg-6">
                                <div class="card m-b-30">
                                    <div class="card-body">
        
                                        <h4 class="mt-0 header-title">Withdrawal Form</h4>
                                        
                                        <form action="withdraw.php" method="post">
                                            <div class="form-group">
                                                <label>Email</label>
                                                <input type="email" class="colorpicker-default form-control" name="email" value="<?php echo $email; ?>">
                                                <input type="hidden" name="type" value="dashboard">
                                            </div><div class="form-group">
                                                <label>Account Balance</label>
                                                <input type="text" class="colorpicker-default form-control" value="$<?php echo $account_balance; ?>" disabled>
                                            </div><div class="form-group">
                                                <label>Amount</label>
                                                <input type="number" class="colorpicker-default form-control" name="amount">
                                            </div><div class="form-group">
                                                <label>Payment Method</label>
                                                <select class="colorpicker-default form-control" name="method">
													<option>Bitcoin</option>
													<option>Ethereum</option>
													<option>LiteCoin</option>
													<option>MoneyGram</option>
													<option>Western Union</option>
													<option>Perfect Money</option>
												</select>
                                            </div>
											<div class="form-group">
                                              
                                                <input type="submit" class="colorpicker-default form-control" value="Make Withdrawal">
                                            </div>
                                            
                                        </form>
        
                                    </div>
                                </div>
        
                       
                            </div><div class="col-lg-6">
                                <div class="card m-b-30">
                                    <div class="card-body">
        
                                        <h4 class="mt-0 header-title">Deposit Form</h4>
                                        
                                        <form action="deposit.php" method="post">
                                            <div class="form-group">
                                                <label>Email</label>
                                                <input type="email" class="colorpicker-default form-control" name="email" value="<?php echo $email; ?>">
                                                <input type="hidden" name="type" value="dashboard">
                                            </div><div class="form-group">
                                                <label>Amount</label>
                                                <input type="number" class="colorpicker-default form-control" name="amount">
                                            </div><div class="form-group">
                                                <label>Payment Method</label>
                                                <select class="colorpicker-default form-control" name="method">
													<option>Bitcoin</option>
													<option>Ethereum</option>
													<option>LiteCoin</option>
													<option>MoneyGram</option>
													<option>Western Union</option>
													<option>Perfect Money</option>
												</select>
                                            </div>
											<div class="form-group">
                                              
                                                <input type="submit" class="colorpicker-default form-control" value="Make Deposit">
                                            </div>
                                            
                                        </form>
        
                                    </div>
                                </div>
        
                       
                            </div>
				</div>
            -->
                    <hr style="border-color:white">
                    <div class="row">
                        <div class="col-lg-6">
                            <div class="card m-b-30">
                                <div class="card-body">

                                    <h4 class="mt-0 header-title">Withdrawal History</h4>


                                    <div class="table-responsive">

                                        <?php echo $withdraws_data; ?>

                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-6">
                            <div class="card m-b-30">
                                <div class="card-body">

                                    <h4 class="mt-0 header-title">Deposit History</h4>

                                    <div class="table-responsive">

                                        <?php echo $deposits_data; ?>

                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <footer class="footer">
                © 2020 All Rights Reserved
            </footer>

        </div>
        <!-- ============================================================== -->
        <!-- End Right content here -->
        <!-- ============================================================== -->

    </div>
    <!-- END wrapper -->

    <!-- jQuery  -->
    <script src="ass/js/jquery.min.js"></script>
    <script src="ass/js/bootstrap.bundle.min.js"></script>
    <script src="ass/js/metismenu.min.js"></script>
    <script src="ass/js/jquery.slimscroll.js"></script>
    <script src="ass/js/waves.min.js"></script>

    <script src="ass/pages/dashboard.init.js"></script>

    <!-- App js -->
    <script src="ass/js/app.js"></script>
<!-- GetButton.io widget -->
<
<!-- /GetButton.io widget -->
</body>

</html>