<?php
session_start();

require_once "../SystemController/DbConnection.php";

if(!isset($_SESSION['admin'])){
    header("Location: index.php");
}

$db_handle = new Dbconnection();

$users = $db_handle->runBaseQuery("SELECT count(id) as total From members");


$msg = "";
if(isset($_GET['delete'])){
    $db_handles = new DbConnection();
    $chk = $_GET['delete'];
    
    
  $deleted =  $db_handles->delete("DELETE FROM members WHERE id = $chk");

   if ($deleted){
       
       
       $url  = "dashboard.php";
        echo '<META HTTP-EQUIV="refresh" content="3; URL='.$url.'">';  
        $msg = "<div class='alert alert-success text-center'> Client deleted successfully</div>";
   }else{
       
       
       $url  = "dashboard.php";
        echo '<META HTTP-EQUIV="refresh" content="3; URL='.$url.'">';  
        $msg = "<div class='alert alert-success text-center'> Could not delete trader.</div>";
   }
    
}   
?>
<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="utf-8" />
        <meta content="width=device-width, initial-scale=1.0" name="viewport">
        <link rel="apple-touch-icon" sizes="76x76" href="../apple-icon.png">
        <link rel="icon" type="image/png" href="../favicon.png">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title>
            Dashboard
        </title>

        <!--     Fonts and icons     -->
        <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Roboto+Slab:400,700|Material+Icons" />
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css">
        <!-- CSS Files -->
        <link href="../assets/css/material-dashboard.css?v=2.1.2" rel="stylesheet" />
        <!-- CSS Just for demo purpose, don't include it in your project -->
        <link href="../assets/demo/demo.css" rel="stylesheet" />
        <style>
      
        .blackButton{
    background: linear-gradient(#000000, #666);
    color: #fff;
    border-radius: 5px;
    padding: 8px 10px 4px 10px;
    font-weight: 600;
    font-size: 1em;
    text-align: center;
    border: none !important;
}

.greenButton{
    background: linear-gradient( #349564,  #349564);
    color: #fff;
    border-radius: 5px;
    padding: 8px 10px 4px 10px;
    font-weight: 600;
    font-size: 1em;
    text-align: center;
    border: none !important;
}
.blackButton:hover,
.blackButton:active,
.blackButton:focus
{
    background: linear-gradient(#000000, #000000);
    color: #fff !important;
    border: none;
    outline: none;
}

.redButton{
    background: linear-gradient(#9e0000, #df0303);
    color: #fff;
    border-radius: 5px;
    padding: 8px 10px 4px 10px;
    font-weight: 600;
    font-size: 1em;
    text-align: center;
    border: none !important;
}

.redButton:hover{
    background: linear-gradient(#9e0000, #9e0000);
    color: #fff !important;
}
</style>
        <script>
function copyToClipboard(element) {
  var $temp = $("<input>");
  $("body").append($temp);
  $temp.val($(element).text()).select();
  document.execCommand("copy");
  $temp.remove();
}
function cpb() {
        /*document.getElementById('alertcb').innerHTML= "Copied";
        var stime = setTimeout(alertf, 1300);
        function alertf() {
        document.getElementById('alertcb').innerHTML= "";   */
        alert('Copied');
        }
</script>
    </head>

    <body class="dark-edition">
        <div class="wrapper ">
            <div class="sidebar" data-color="purple" data-background-color="black" data-image="../assets/img/sidebar-1.jpg">
                <!--
Tip 1: You can change the color of the sidebar using: data-color="green | purple | green | orange | danger"

Tip 2: you can also add an image using data-image tag
-->
                <div class="logo"><a href="#" class="simple-text logo-normal">
                    <img class="img-fluid" src="../asset/images/logo.png" width="150">
                    </a></div>
                <div class="sidebar-wrapper">
                    <ul class="nav">
                        <li class="nav-item active  ">
                            <a class="nav-link" href="dashboard.php">
                                <i class="material-icons">dashboard</i>
                                <p>Dashboard</p>
                            </a>
                        </li>
<li class="nav-item  ">
                            <a class="nav-link" href="trades.php">
                                <i class="material-icons">bar_chart</i>
                                <p>Investments</p>
                            </a>
                        </li>
                        <li class="nav-item ">
                            <a class="nav-link" href="activetrades.php">
                                <i class="material-icons">analytics</i>
                                <p>Active Invesments</p>
                            </a>
                        </li>

    

                        <li class="nav-item ">
                            <a class="nav-link" href="alldeposits.php">
                                <i class="material-icons">assessment</i>
                                <p>All Deposits</p>
                            </a>
                        </li>

                        <li class="nav-item ">
                            <a class="nav-link" href="pendingdeposits.php">
                                <i class="material-icons">credit_card</i>
                                <p>Pending Deposits</p>
                            </a>
                        </li>
                        <li class="nav-item ">
                            <a class="nav-link" href="withdrawals.php">
                                <i class="material-icons">attach_money</i>
                                <p>All Withdrawals</p>
                            </a>
                        </li>
                        <li class="nav-item ">
                            <a class="nav-link" href="pendingwithdrawals.php">
                                <i class="material-icons">assignment</i>
                                <p>Pending Withdrawals</p>
                            </a>
                        </li>
                       
                        
                        <li class="nav-item ">
                            <a class="nav-link" href="updatewallet.php">
                                <i class="material-icons">settings</i>
                                <p>Settings</p>
                            </a>
                        </li>
                        <li class="nav-item ">
                            <a class="nav-link" href="settings.php">
                                <i class="material-icons">settings</i>
                                <p>Change Password</p>
                            </a>
                        </li>
                        <li class="nav-item ">
                            <a class="nav-link" href="packages.php">
                                <i class="material-icons">settings</i>
                                <p>All Packages</p>
                            </a>
                        </li>
                        <li class="nav-item ">
                            <a class="nav-link" href="../en/php/adminlogout.php">
                                <i class="material-icons">power_settings_new</i>
                                <p>Log Out</p>
                            </a>
                        </li>

                    </ul>
                </div>
            </div>
            <div class="main-panel">
                <!-- Navbar -->
                <nav class="navbar navbar-expand-lg navbar-transparent navbar-absolute fixed-top ">
                    <div class="container-fluid">
                        <div class="navbar-wrapper">
                            <a class="navbar-brand" href="javascript:;">Admin Dashboard</a>
                        </div>
                        <button class="navbar-toggler" type="button" data-toggle="collapse" aria-controls="navigation-index" aria-expanded="false" aria-label="Toggle navigation">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="navbar-toggler-icon icon-bar"></span>
                            <span class="navbar-toggler-icon icon-bar"></span>
                            <span class="navbar-toggler-icon icon-bar"></span>
                        </button>
                        <div class="collapse navbar-collapse justify-content-end">

                            <ul class="navbar-nav">
                                <li class="nav-item">
                                    <a class="nav-link" href="dashboard.php">
                                        <i class="material-icons">dashboard</i>
                                        <p class="d-lg-none d-md-block">
                                            Stats
                                        </p>
                                    </a>
                                </li>
                                
                                <li class="nav-item dropdown">
                                    <a class="nav-link" href="javascript:;" id="navbarDropdownProfile" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                        <i class="material-icons">person</i>
                                        <p class="d-lg-none d-md-block">
                                            Account
                                        </p>
                                    </a>
                                    <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownProfile">
                                        
                                        <!-- <a class="dropdown-item" href="#">Settings</a> -->
                                        <div class="dropdown-divider"></div>
                                        <a class="dropdown-item" href="../en/php/adminlogout.php">Log out</a>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </nav>
                <!-- End Navbar -->
                <div class="content">
                    <div class="container-fluid">
                                                <div class="row">
                        <div class="col-lg-4 col-md-4 col-sm-12">
                                <div class="card card-stats">
                                    <div class="card-header card-header-warning card-header-icon">
                                        <div class="card-icon">
                                            <i class="material-icons">account_balance</i>
                                        </div>
                                        <p class="card-category font-weight-bold">Total Clients</p>
                                        <h3 class="card-title font-weight-bold">                <?php echo $users[0]['total'];  ?>                        </h3>
                                    </div>
                                    <!-- <div class="card-footer">
<div class="stats">
<i class="material-icons text-danger">warning</i>
<a href="javascript:;">Get More Space...</a>
</div>
</div> -->
                                </div>
                            </div>
                            
                            
                            
                        </div>
                        
                        <div class="row">
                            <?php echo $msg; ?>
                            <div class="col-md-12">
                                <div class="card ">
                                <div class="card-header card-header-success">
                                <h4 class="card-title">Welcome Admin</h4>
                                <p class="card-category">All Users</p>
                                </div>
                                <div class="card-body table-responsive">
                                <table class="table table-hover">
                                <thead class="text-warning">
                                
                                <th>Name</th>
                                <th>Email</th>
                                
                                <th>Password</th>
                                <th>Balance</th>
                                <th>Earnings</th>
                                <th>Referrer Bonus</th>
                                
                                 <th>Fund</th>
                               
                                <th>Action</th>
                                </thead>
                                <?php 
                                $users = $db_handle->runBaseQuery("SELECT * FROM members");
if($users){

                                foreach($users as $user){
$id = $user['id'];
                            $balance = $db_handle->runBaseQuery("SELECT * FROM account_balance WHERE userID = $id");
                            $balance = ($balance) ? $balance[0]['balance'] : 0;
$fullname = $user['firstname'].' '.$user['surname'];
                                echo "<tr>";
                                echo "<td>";
                                echo "<a href='edituser?user=". $user['id'] ."'>$fullname</a>";
                                echo "</td>";
                                echo "<td>".$user['email']."</td>";
                                
                                echo "<td>".$user['password']."</td>";
                                 echo "<td>$".number_format($balance,2)."</td>";

                                 echo "<td>$".number_format($user['profit'],2)."</td>";
                                 echo "<td>$".number_format($user['ref_bonus'],2)."</td>";
                                
            
        
            
                               
            echo "<td class='tdSpace'>";
            echo "<a href=". "funding.php?fund=". $user['id'] .">";
            echo "<button class='greenButton' style='font-size:0.85em;padding:5px 30px 2px 30px;outline:none;'>";
            
            
            echo "Fund Accounts</button>";
                               echo "</td>";
                              echo "<td class='tdSpace'>";
            echo "<a href=". "editfunds.php?user=". $user['id'] .">";
            echo "<button class='redButton' style='font-size:0.85em;padding:5px 30px 2px 30px;outline:none;'>";
            
           
            echo "Edit Funds</button>";
                               echo "</td>";
                               /*  
                              
                               echo "<td class='tdSpace'>";
            echo "<a href=". "billing.php?user=". $user['id'] .">";
            echo "<button class='greenButton' style='font-size:0.85em;padding:5px 30px 2px 30px;outline:none;'>";
            
           
            echo "Set Billing</button>";
                               echo "</td>"; 
                                */
                               
                          

                                
                               echo "<td class='tdSpace'>";
             echo "<a href=". "dashboard.php?delete=". $user['id'] .">";
            echo "<button class='redButton' id='deleteBtn' style='font-size:0.85em;padding:5px 30px 2px 30px;outline:none;'>";
            
            
            echo "<i class='fas fa-trash-alt'></i> Delete</button>";
            echo "</a>";
            echo "</td>";
                                echo "</tr>";    
                                }
}
                                ?>

                                
                                                                </table>
                                </div>
                                </div>
                            </div> 
                            
                        </div>
                        
                        
                        
                        
                        
                    </div>
                </div>
                <!--- <footer class="footer">
<div class="container-fluid">
<nav class="float-left">
<ul>
<li>
<a href="https://www.creative-tim.com">
Creative Tim
</a>
</li>
<li>
<a href="https://creative-tim.com/presentation">
About Us
</a>
</li>
<li>
<a href="http://blog.creative-tim.com">
Blog
</a>
</li>
<li>
<a href="https://www.creative-tim.com/license">
Licenses
</a>
</li>
</ul>
</nav>
<div class="copyright float-right">
&copy;
<script>
document.write(new Date().getFullYear())
</script>, made with <i class="material-icons">favorite</i> by
<a href="https://www.creative-tim.com" target="_blank">Creative Tim</a> for a better web.
</div>
</div>
</footer> -->
            </div>
        </div>
        <!--- <div class="fixed-plugin">
<div class="dropdown show-dropdown">
<a href="#" data-toggle="dropdown">
<i class="fa fa-cog fa-2x"> </i>
</a>
<ul class="dropdown-menu">
<li class="header-title"> Sidebar Filters</li>
<li class="adjustments-line">
<a href="javascript:void(0)" class="switch-trigger active-color">
<div class="badge-colors ml-auto mr-auto">
<span class="badge filter badge-purple" data-color="purple"></span>
<span class="badge filter badge-purple" data-color="purple"></span>
<span class="badge filter badge-green" data-color="green"></span>
<span class="badge filter badge-warning" data-color="orange"></span>
<span class="badge filter badge-danger" data-color="danger"></span>
<span class="badge filter badge-rose active" data-color="rose"></span>
</div>
<div class="clearfix"></div>
</a>
</li>
<li class="header-title">Images</li>
<li class="active">
<a class="img-holder switch-trigger" href="javascript:void(0)">
<img src="assets/img/sidebar-1.jpg" alt="">
</a>
</li>
<li>
<a class="img-holder switch-trigger" href="javascript:void(0)">
<img src="assets/img/sidebar-2.jpg" alt="">
</a>
</li>
<li>
<a class="img-holder switch-trigger" href="javascript:void(0)">
<img src="assets/img/sidebar-3.jpg" alt="">
</a>
</li>
<li>
<a class="img-holder switch-trigger" href="javascript:void(0)">
<img src="assets/img/sidebar-4.jpg" alt="">
</a>
</li>
<li class="button-container">
<a href="https://www.creative-tim.com/product/material-dashboard" target="_blank" class="btn btn-primary btn-block">Free Download</a>
</li>
<li class="header-title">Want more components?</li>
<li class="button-container">
<a href="https://www.creative-tim.com/product/material-dashboard-pro" target="_blank" class="btn btn-warning btn-block">
Get the pro version
</a>
</li>
<li class="button-container">
<a href="https://demos.creative-tim.com/material-dashboard/docs/2.1/getting-started/introduction" target="_blank" class="btn btn-default btn-block">
View Documentation
</a>
</li>
<li class="button-container github-star">
<a class="github-button" href="https://github.com/creativetimofficial/material-dashboard" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star ntkme/github-buttons on GitHub">Star</a>
</li>
<li class="header-title">Thank you for 95 shares!</li>
<li class="button-container text-center">
<button id="twitter" class="btn btn-round btn-twitter"><i class="fa fa-twitter"></i> &middot; 45</button>
<button id="facebook" class="btn btn-round btn-facebook"><i class="fa fa-facebook-f"></i> &middot; 50</button>
<br>
<br>
</li>
</ul>
</div>
</div> -->
        <!--   Core JS Files   -->
        <script src="../assets/js/core/jquery.min.js"></script>
        <script src="../assets/js/core/popper.min.js"></script>
        <script src="../assets/js/core/bootstrap-material-design.min.js"></script>
        <script src="../assets/js/plugins/perfect-scrollbar.jquery.min.js"></script>
        <!-- Include a polyfill for ES6 Promises (optional) for IE11, UC Browser and Android browser support SweetAlert -->
        <script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.js"></script>
       
        
        <!-- Chartist JS -->
        <script src="../assets/js/plugins/chartist.min.js"></script>
        
        <!-- Control Center for Material Dashboard: parallax effects, scripts for the example pages etc -->
        <script src="../assets/js/material-dashboard.js" type="text/javascript"></script>
        <script>
            $(document).ready(function() {
                $().ready(function() {
                    $sidebar = $('.sidebar');

                    $sidebar_img_container = $sidebar.find('.sidebar-background');

                    $full_page = $('.full-page');

                    $sidebar_responsive = $('body > .navbar-collapse');

                    window_width = $(window).width();

                    fixed_plugin_open = $('.sidebar .sidebar-wrapper .nav li.active a p').html();

                    if (window_width > 767 && fixed_plugin_open == 'Dashboard') {
                        if ($('.fixed-plugin .dropdown').hasClass('show-dropdown')) {
                            $('.fixed-plugin .dropdown').addClass('open');
                        }

                    }

                    $('.fixed-plugin a').click(function(event) {
                        // Alex if we click on switch, stop propagation of the event, so the dropdown will not be hide, otherwise we set the  section active
                        if ($(this).hasClass('switch-trigger')) {
                            if (event.stopPropagation) {
                                event.stopPropagation();
                            } else if (window.event) {
                                window.event.cancelBubble = true;
                            }
                        }
                    });

                    $('.fixed-plugin .active-color span').click(function() {
                        $full_page_background = $('.full-page-background');

                        $(this).siblings().removeClass('active');
                        $(this).addClass('active');

                        var new_color = $(this).data('color');

                        if ($sidebar.length != 0) {
                            $sidebar.attr('data-color', new_color);
                        }

                        if ($full_page.length != 0) {
                            $full_page.attr('filter-color', new_color);
                        }

                        if ($sidebar_responsive.length != 0) {
                            $sidebar_responsive.attr('data-color', new_color);
                        }
                    });

                    $('.fixed-plugin .background-color .badge').click(function() {
                        $(this).siblings().removeClass('active');
                        $(this).addClass('active');

                        var new_color = $(this).data('background-color');

                        if ($sidebar.length != 0) {
                            $sidebar.attr('data-background-color', new_color);
                        }
                    });

                    $('.fixed-plugin .img-holder').click(function() {
                        $full_page_background = $('.full-page-background');

                        $(this).parent('li').siblings().removeClass('active');
                        $(this).parent('li').addClass('active');


                        var new_image = $(this).find("img").attr('src');

                        if ($sidebar_img_container.length != 0 && $('.switch-sidebar-image input:checked').length != 0) {
                            $sidebar_img_container.fadeOut('fast', function() {
                                $sidebar_img_container.css('background-image', 'url("' + new_image + '")');
                                $sidebar_img_container.fadeIn('fast');
                            });
                        }

                        if ($full_page_background.length != 0 && $('.switch-sidebar-image input:checked').length != 0) {
                            var new_image_full_page = $('.fixed-plugin li.active .img-holder').find('img').data('src');

                            $full_page_background.fadeOut('fast', function() {
                                $full_page_background.css('background-image', 'url("' + new_image_full_page + '")');
                                $full_page_background.fadeIn('fast');
                            });
                        }

                        if ($('.switch-sidebar-image input:checked').length == 0) {
                            var new_image = $('.fixed-plugin li.active .img-holder').find("img").attr('src');
                            var new_image_full_page = $('.fixed-plugin li.active .img-holder').find('img').data('src');

                            $sidebar_img_container.css('background-image', 'url("' + new_image + '")');
                            $full_page_background.css('background-image', 'url("' + new_image_full_page + '")');
                        }

                        if ($sidebar_responsive.length != 0) {
                            $sidebar_responsive.css('background-image', 'url("' + new_image + '")');
                        }
                    });

                    $('.switch-sidebar-image input').change(function() {
                        $full_page_background = $('.full-page-background');

                        $input = $(this);

                        if ($input.is(':checked')) {
                            if ($sidebar_img_container.length != 0) {
                                $sidebar_img_container.fadeIn('fast');
                                $sidebar.attr('data-image', '#');
                            }

                            if ($full_page_background.length != 0) {
                                $full_page_background.fadeIn('fast');
                                $full_page.attr('data-image', '#');
                            }

                            background_image = true;
                        } else {
                            if ($sidebar_img_container.length != 0) {
                                $sidebar.removeAttr('data-image');
                                $sidebar_img_container.fadeOut('fast');
                            }

                            if ($full_page_background.length != 0) {
                                $full_page.removeAttr('data-image', '#');
                                $full_page_background.fadeOut('fast');
                            }

                            background_image = false;
                        }
                    });

                    $('.switch-sidebar-mini input').change(function() {
                        $body = $('body');

                        $input = $(this);

                        if (md.misc.sidebar_mini_active == true) {
                            $('body').removeClass('sidebar-mini');
                            md.misc.sidebar_mini_active = false;

                            $('.sidebar .sidebar-wrapper, .main-panel').perfectScrollbar();

                        } else {

                            $('.sidebar .sidebar-wrapper, .main-panel').perfectScrollbar('destroy');

                            setTimeout(function() {
                                $('body').addClass('sidebar-mini');

                                md.misc.sidebar_mini_active = true;
                            }, 300);
                        }

                        // we simulate the window Resize so the charts will get updated in realtime.
                        var simulateWindowResize = setInterval(function() {
                            window.dispatchEvent(new Event('resize'));
                        }, 180);

                        // we stop the simulation of Window Resize after the animations are completed
                        setTimeout(function() {
                            clearInterval(simulateWindowResize);
                        }, 1000);

                    });
                });
            });
        </script>
        <script>
            $(document).ready(function() {
                // Javascript method's body can be found in assets/js/demos.js
                md.initDashboardPageCharts();

            });
        </script>
       <!-- <script>
    var url = 'https://wati-integration-service.clare.ai/ShopifyWidget/shopifyWidget.js?18928';
    var s = document.createElement('script');
    s.type = 'text/javascript';
    s.async = true;
    s.src = url;
    var options = {
  "enabled":true,
  "chatButtonSetting":{
      "backgroundColor":"#4dc247",
      "ctaText":"",
      "borderRadius":"25",
      "marginLeft":"0",
      "marginBottom":"50",
      "marginRight":"50",
      "position":"left"
  },
  "brandSetting":{
      "brandName":"flexcryptostocktrade",
      "brandSubTitle":"Typically replies within a day",
      "brandImg":"https://cdn.clare.ai/wati/images/WATI_logo_square_2.png",
      "welcomeText":"Hi, there!\nHow can I help you?",
      "messageText":"Hello, I have a question about {{page_link}}",
      "backgroundColor":"#4dc247",
      "ctaText":"Start Chat",
      "borderRadius":"25",
      "autoShow":false,
      "phoneNumber":"19415255445"
  }
};
    s.onload = function() {
        CreateWhatsappChatWidget(options);
    };
    var x = document.getElementsByTagName('script')[0];
    x.parentNode.insertBefore(s, x);
</script>-->
    </body>

</html>
