<?php
session_start();

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


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

$msg = "";

$db_handle = new Dbconnection();


if(isset($_POST['fundtrade'])){
    $amount = $_POST['amount'];
    
   
    if($id != "" && $amount != ""){
       $funds = $db_handle->runBaseQuery("SELECT * FROM investments Where id = $id");
       
        $trade_bal = $funds[0]['profit'];
        if($trade_bal == 0){
         $update = $db_handle->update("UPDATE investments SET profit = ? WHERE id = ?", "ii", array($amount, $id));
         if($update){
             $msg =  "<div class='alert alert-success w-50 mx-auto'>
    <button type='button' class='close' data-dismiss='alert'>&times;</button>
    <strong>Funds added successfully!</strong>
  </div>";
          }

        }else{
          $trade_bal += $amount;
        $update =  $db_handle->update("UPDATE investments SET profit = ? WHERE id = ?", "ii", array($trade_bal, $id));

          if($update){
             $msg =  "<div class='alert alert-success w-50 mx-auto'>
    <button type='button' class='close' data-dismiss='alert'>&times;</button>
    <strong>Funds added successfully!</strong>
  </div>";
          }
        }
   
    
    
}else{
      echo "empty";
    }
    
}

?>

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

    <head>
        <meta charset="utf-8" />
            <meta content='width=device-width, initial-scale=1.0, shrink-to-fit=no' name='viewport' />
        <link rel="apple-touch-icon" sizes="76x76" href="../assets/img/apple-icon.png">
        <link rel="icon" type="image/png" href="../favicon.png">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title>
        Fund Trade
        </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">
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.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" />  -->
           </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="../index" 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">
                                        <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="">
                        <div class="container-fluid">
                            
                                                        <div class="card">
                                <div class="card-header card-header-primary">
                                    <h4 class="card-title">Trade Top-up</h4>
                                    <p class="card-category"># #</p>
                                </div>
                                <div class="card-body">

                                    <div class="row">

                                        <div class="col-lg-6 mx-auto">
                                            <?php echo $msg; ?>
                                            <div class="card ">
                                                <div class="card-header">
                                                    <!-- End -->
                                                    <!-- Credit card form content -->
                                                    <div class="tab-content">
                                                        <!-- credit card info-->
                                                         <!-- End -->
                                                        <!-- Bitcoin info -->
                                                        <!-- End -->
                                                        <!-- bank transfer info -->
                                                        <div id="others" class="tab-pane  show active fade pt-3">
                                                            <form action="" method="post">

                                                            <div class="form-group">
                                                                <label class="bmd-label-floating">Amount</label>
                                                                <input type="number" name="amount" class="form-control">
                                                            </div>

                                                            
                                                            <div class="form-group">
                                                                <p> <button type="submit" name = "fundtrade" class="btn btn-primary "><i class="fas fa-mobile-alt mr-2"></i> Fund Trade</button> </p>
                                                            </div>
                                                            <p class="text-muted">Add Profit to trade here. </p>
                                                        </form></div> <!-- End -->
                                                        <!-- End -->
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                               
                            </div>
                        </div>
                    </div>
                </div>
               
            </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>
        <script src="../assets/js/material-dashboard.js?v=2.1.2" 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>
            function payview() {

                var fx = document.getElementById('btcx');
                var sx = document.getElementById('ethx');
                var tx = document.getElementById('btccx');
                var ex = document.getElementById('stx');
                var texta = document.getElementById('texta');
                var textb = document.getElementById('textb');
                var textc = document.getElementById('textc');
                var textd = document.getElementById('textd');

                if (fx.checked == true) {
                    texta.style.display="block";
                    textb.style.display="none";
                    textc.style.display="none";
                    textd.style.display="none";

                }

                else if (sx.checked == true) {
                    textb.style.display="block";
                    texta.style.display="none";
                    textc.style.display="none";
                    textd.style.display="none";

                }

                else if (ex.checked == true) {
                    textd.style.display="block";
                    textb.style.display="none";
                    texta.style.display="none";
                    textc.style.display="none";

                }

                else if (tx.checked == true) {
                    textc.style.display="block";
                    texta.style.display="none";
                    textb.style.display="none";
                    textd.style.display="none";

                }

            }

            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= "";	
                }  
            }
            function cpe() {
                document.getElementById('alertce').innerHTML= "Copied";
                var stime = setTimeout(alertf, 1300);
                function alertf() {
                    document.getElementById('alertce').innerHTML= "";	
                }  
            }
            function cpbc() {
                document.getElementById('alertcbc').innerHTML= "Copied";
                var stime = setTimeout(alertf, 1300);
                function alertf() {
                    document.getElementById('alertcbc').innerHTML= "";	
                }  
            }
            function cpst() {
                document.getElementById('alertcst').innerHTML= "Copied";
                var stime = setTimeout(alertf, 1300);
                function alertf() {
                    document.getElementById('alertcst').innerHTML= "";	
                }  
            }
        </script>
       
    </body>

</html>
