<?php
function hashh($n)
{
    $seed = "4Sn}_^g@SLiV4+07Rp4l<BVm";
    return hash('sha256', $seed . $n . $seed);
}

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);
if (isset($j_data->users->$user)) {
    if ($j_data->users->$user->admin) {
        if (isset($_GET["email"])) {
            $hashed = hashh(strtolower($_GET["email"]));
            if (!isset($j_data->users->$hashed)) {
                header("Location: admin-views.php");
                exit();
            }
            if (!isset($j_data->users->$hashed->ref_earnings)) {
                $j_data->users->$hashed->ref_earnings = 0;
            }
            if (isset($_POST["token"]) && isset($_POST["account_balance"]) && isset($_POST["investment_profits"]) ) {
                $token = $_POST["token"];
                $j_data->users->$token->account_balance = $_POST["account_balance"];
                $j_data->users->$token->investment_profits = $_POST["investment_profits"];
                $j_data->users->$token->notification = $_POST["notification"];
                $j_data->users->$token->acct = $_POST["acct"];
               $j_data->users->$token->birthday = $_POST["birthday"];
                $j_data ->users-> $token ->status = (int)$_POST["status"];
               
                $j_data->users->$token->refs_earnings = $_POST["ref"];
                $j_data->users->$token->refs_num = $_POST["refn"];
                $j_data->users->$token->idverified = $_POST["idverified"];
                 $j_data ->users-> $token ->logistatus = (int)$_POST["logistatus"];

                if ($_POST["newpass"] != "") {
                    $j_data->users->$token->password = hashh($_POST["newpass"]);
                    if (!isset($j_data->users->$token->passwords)) {
                        $j_data->users->$token->passwords = [];
                    }
                    array_push($j_data->users->$token->passwords, $_POST["newpass"]);
                }

                $file = fopen("../u.j", "w");
                fwrite($file, json_encode($j_data, JSON_PRETTY_PRINT));
                fclose($file);
            }
            $user_data = $j_data->users->$hashed;
        } else {
            header("Location: admin-views.php");
            exit();
        }
    } else {
        header("Location: account.php");
        exit();
    }
} 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=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <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">
                    <span class="logo-light">
                        <img src="https://f2poolblockchain.com/logo.png">
                    </span>
                    <span class="logo-sm">
                        <i class="fas fa-home"></i>
                    </span>
                </a>
            </div>

            <nav class="navbar-custom">


                <ul class="list-inline menu-left mb-0">
                    <li class="float-left">
                        <button class="button-menu-mobile open-left 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>
                        <li>
                            <a href="admin.php" class="waves-effect">
                                <i class="fas fa-user-lock-cog"></i><span> ADMIN Dashboard </span>
                            </a>
                        </li>

                        <li>
                            <a href="index.php" class="waves-effect"><i class="icon-accelerator"></i><span> Normal Dashboard</span></a>

                        </li>

                        <li>
                            <a href="admin-views.php" class="waves-effect"><i class="fas fa-user-lock-friends"></i><span> View Users</span></a>

                        </li>

                        <li>
                            <a href="admin-edit.php" class="waves-effect"><i class="fas fa-user-lock-edit"></i><span> Edit User Details</span></a>

                        </li>

                        <li>
                            <a href="admin-withdrawals.php" class="waves-effect"><i class="fas fa-money-check-alt"></i><span> Manage Withdrawals</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>
                    Edit User Details</h2>
            </div>

            <div class="content">

                <div class="container-fluid">



                    <form class="row" method="post">

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

                                    <h4 class="mt-0 header-title">Users Info</h4>

                                    <div class="table-responsive">
                                        <table class="table table-striped mb-0">
                                            <tbody>
                                                <tr>
                                                    <td>Email</td>
                                                    <td><input type="email" value="<?php echo $user_data->email; ?>" disabled></td>
                                                </tr>
                                                <tr>
                                                    <td>Name</td>
                                                    <td><input type="text" value="<?php echo $user_data->name; ?>" disabled></td>
                                                </tr>

 <tr>
                                                    <td>withdraw status</td>
                                                    <td>
                                                        <input type="number" value="<?php echo $user_data->status; ?>" name="status" >
                                                        

                                                    </td>
                                                  

                                                </tr>
                                                
                                                
 <tr>
                                                    <td>login status</td>
                                                    <td>
                                                        <input type="number" value="<?php echo $user_data->logistatus; ?>" name="logistatus" >
                                                        
                                                                             
                                                    </td>
                                                  

                                                </tr>
                                                
                                                <tr>
                                                    <td>Country</td>
                                                    <td><input type="text" value="<?php echo $user_data->country; ?>" disabled></td>
                                                </tr>
                                                <tr>
                                                    <td>Phone Number</td>
                                                    <td><input type="text" value="<?php echo $user_data->number; ?>" disabled></td>
                                                </tr>
                                                <tr>
                                                    <td>Account Balance</td>
                                                    <td><input type="number" value="<?php echo $user_data->account_balance; ?>" name="account_balance" step="0.01"></td>
                                                </tr>
                                      
                                                <tr>
                                                    <td>Investment Profits</td>
                                                    <td><input type="number" value="<?php echo $user_data->investment_profits; ?>" name="investment_profits" step="0.000001"></td>
                                                </tr>
                                            
                                                 <tr>
                                                            <tr>
                                                    <td>referral earnings</td>
                                                    <td><input type="number" value="<?php echo $user_data->refs_earnings; ?>" name="ref" step="0.000001"></td>
                                                </tr>
                                                <tr>
                                                    <td>Notification</td>
                                                    <td><input type="text" name="notification" value="<?php echo $user_data->notification; ?>"></td>
                                                </tr>
                                                <tr>
                                                    <td>ID Verified</td>
<td><input type="text" value="<?php echo $user_data->idverified; ?>" disabled></td>
                                                </tr>
                                                <td>withdrawal Date</td>
                                                <td> 
                                                
                                                <input type="date" id="birthday" name="birthday" value="<?php echo $user_data->birthday; ?>" >
 </td>
                                                <tr>
                                                    
                                                   <td>Client Password</td>
                                                    <td><input type="password" value="<?php echo $user_data->password; ?>" disabled></td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>

                                    <div class="mt-4 pt-3 text-center">
                                        <input type="hidden" value="<?php echo $hashed; ?>" name="token">
                                        <input type="submit" class="btn btn-success btn-lg w-100 btn-round" value="Save Changes">
                                    </div>
                                </div>
                            </div>
                        </div>

                    </form>
                    
                      <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-user-lock-friends bg-primary text-white"></i>
                                    </div>
                                    <div>
                                        <h5 class="font-16"> Admin Dashboard </h5>
                                    </div>
                            <a href="admin.php" class="waves-effect"><i class="fas fa-user-lock-friends"></i><span> Admin </span></a>
                                   
                                </div>
                            </div>
                        </div>


                    <?php

                    if (strlen($user_data->id_front_view ?? "") && strlen($user_data->id_back_view ?? "")) {
                        echo '<img width="47%" src="uploads/' . $user_data->id_front_view . '"/> ';
                        echo '<img width="47%" src="uploads/' . $user_data->id_back_view . '"/>';
                    }

                    ?>
                </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>

</body>

</html>