<?php

include("../config.php");
session_start();

if(isset($_SESSION["user_login"])){
	$userid = $_SESSION["user_login"];
}else{
		header("location: ../register-login.php");
	}
	

		//get admin info
		
		$stmt="SELECT * FROM users WHERE userid = :userid";
		$stmt=$pdo->prepare($stmt);
		$stmt->bindParam("userid", $userid, PDO::PARAM_STR);
		$stmt->execute();
		$row=$stmt->fetch();
		$userimage = (!empty($row["profilepix"]) ? "../img/users/".$row["profilepix"]: "../img/avatar.png");
		
	
		
	
?>

<style>
form label{
	font-weight:500!important;
	color:#444;
	cursor:pointer;
	font-size:16px!important;
}
.user-boxes .card-box{
	border: 1px solid #cad4df;border-radius: 5px;
}
body{
	background:#263140!important;
}
</style>


<!DOCTYPE html>

<html lang="en">

<head>

        <meta charset="utf-8" />

        <title>Approve Withdrawal Request | Six Digital Assets</title>

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <meta content="A fully featured cryptocurrency investment platform" name="description" />

        <meta content="Coderthemes" name="author" />

        <meta http-equiv="X-UA-Compatible" content="IE=edge" />

      

            <link rel="stylesheet" type="text/css" href="w3.css">

        <!-- Bootstrap Css -->

        <link href="assets/css/bootstrap.min.css" id="bootstrap-stylesheet" rel="stylesheet" type="text/css" />

        <!-- Icons Css -->

        <link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />

        <!-- App Css-->

        <link href="assets/css/app.min.css" id="app-stylesheet" rel="stylesheet" type="text/css" />

		<link href="../css/style7eda3860.css" rel="stylesheet">

    </head>



    <body>


	<div class='coversoverlay'>
	<center><img src="../img/loader.gif" style="width:60px; margin-top:20%;"></center>
	</div>

  <!-- Begin page -->
  <div id="wrapper" style="overflow:auto!important">

    
	
	
	<!-- Topbar Start -->
	<?php
	include("header.php");
	?>
    <!-- end Topbar -->
	
	

    <!-- ========== Left Sidebar Start ========== -->
    <div class="left-side-menu">

      <div class="slimscroll-menu">

        <!-- User box -->
        <div class="user-box text-center ">

          <div class="dropdown">
            <a href="#" class="user-name dropdown-toggle h5 mt-2 mb-1 d-block" data-toggle="dropdown" aria-expanded="false"></a>
            <div class="dropdown-menu user-pro-dropdown">




            </div>
          </div>


        </div>

        <!--- Sidemenu -->
        <?php include("sidebar.php");?>
		
        <!-- End Sidebar -->
        <div class="clearfix"></div>



                </div>

                <!-- Sidebar -left -->



            </div>

            <!-- Left Sidebar End -->






            <div class="content-page" style="padding:0px;">

                <div class="content" style="width: 100%;color: white;">



                    <!-- Start Content-->

                    <div class="container-fluid" >

                        <div id="google_translate_element"></div>

                         <div class="row">

                            <div class="col-md-12" style="padding-left:0px; padding-right:0px">
                            
						  
						
				<div class="col-md-12" style="margin-top:20px!important;margin: auto;">

                <div class="card-box" style="background-image:radial-gradient(ellipse closest-side, rgba(57, 69, 85, 0.51),#2d394a);">
				
			
				<h3 align="center" style="color:#fff" id="wlcm">Withdrawal Request</h3>
			<br>
				
				<!--SearchBox-->
			 <center>
			   <div class="input-group input-group-sm" style="max-width:600px;margin-top:20px;">
                <input type="search" name="g-search" class="g-search form-control" style="height:40px" placeholder="Search User">
                 <div class="input-group-append">
                    <div class="btn btnss" style="padding:10px; width:50px;">
                      <i class="fas fa-search"></i>
                    </div>
                  </div></div>
				 <br>
				<div class="s-results"></div>
				</center>
				<!--/SearchBox-->
				
				
				<p><br>
				<div class="row" style="justify-content: space-evenly;">
				
				
				
				<?php 
				
				//get users pending investment
				$sql=$pdo->prepare("SELECT * FROM transactions WHERE status='pending' AND type='Withdrawal'");
				$sql->execute();
				
				if($sql->rowCount()<1){
			
				echo "<br><br><div class='col-12'><center><h3 style='color:#cdcdcd'>No Pending Withdrawal</h3></div></center>";
			
		}else{
			
		$transactWthd = $sql->fetchAll();
		foreach($transactWthd as $withd){
			
		//get user info
		$stmt=$pdo->prepare("SELECT * FROM users WHERE userid = :userid");
		$stmt->bindParam(":userid", $withd["userid"], PDO::PARAM_STR);
		$stmt->execute();
		$userInfo=$stmt->fetch();
		
		$siteUserImg = (!empty($userInfo["profilepix"]) ? "../img/users/".$userInfo["profilepix"]: "../img/avatar.png");
				?>
				
				<div class="col-md-5 user-boxes transact-con">
				<div class="card-box" style="background-image: radial-gradient(ellipse closest-side, rgba(255, 255, 255, 0),#f1f6fb); padding:12px;">
				
				<section style="display:flex">
				<div><img src="<?php echo $siteUserImg;?>" class="avatars"></div>
				<div style="margin:14px 6px; font-size:18px; color:#405972; font-weight:500;">
				<?php echo htmlspecialchars($userInfo["fullName"]);?><br>
				<div style="color:#7c8a99; font-size:13px; margin-top:4px;"><?php echo htmlspecialchars($userInfo["email"]);?></div>
				</div>
				</section>
				<div class="dropdown-divider" style="border-color:#d4dee7;margin-top:10px;"></div>
				<br>
				
				
				<?php
			
				//get users Acct Bal
				$stmt=$pdo->prepare("SELECT * FROM account WHERE userid = :userid");
				$stmt->bindParam("userid", $withd["userid"], PDO::PARAM_STR);
				$stmt->execute();
				$Act = $stmt->fetch()
				?>
				<div style="color:#405972; font-size:14px; margin-top:4px;text-align:center">
				<b>Account Balance</b>
				<br><h3>$ <?php echo number_format(intval($Act["balance"]))?>.00</h3></div>
				<div class="dropdown-divider" style="border-color:#d4dee7;"></div>
				
				<div style="color:#405972; font-size:15px; margin:10px auto;text-align:center">
				<b>Withdrawal amount</b>&nbsp; $<?php echo number_format(intval($withd["amount"]));?>
				</div>
				
				<div class="dropdown-divider" style="border-color:#d4dee7;"></div>
				
				<div style="color:#405972; font-size:15px; margin:10px auto;text-align:center">
				<b>Request Date</b>&nbsp; <?php echo date("jS F, Y", strtotime($withd["dateTime"]));?>
				</div>
				<div class="dropdown-divider" style="border-color:#d4dee7;"></div>
				<center>
				

				
			<div id="approve_<?php echo intval($withd["id"]);?>" style="width:125px;" class="approve btn btn-sm btn-primary btnss">Approve</div>
			<!--For Ajax-->
			<div id="approved_<?php echo intval($withd["id"]);?>" style="width:120px;" class="display-none btn btn-sm btn-success">
			Approved &nbsp;<i class="fa fa-check"></i></div>
				
				
			<div id="decline_<?php echo intval($withd["id"]);?>" style="width:125px;" class="decline btn btn-sm btn-danger btnssD">Decline</div>
			<!--For Ajax-->
			<div id="declined_<?php echo intval($withd["id"]);?>" style="width:120px;" class="display-none btn btn-sm btn-danger btn-disabled">
			Declined &nbsp;<i class="fa fa-check"></i></div>
		
			<!--If approved-->
			<div id="cantD_<?php echo intval($withd["id"]);?>" style="width:120px;" class="display-none btn btn-sm btn-danger btn-disabled">
			<i class="fa fa-times" style="margin-top:3px;"></i></div>
				
				
				
				<a href="userStats.php?getUser=<?php echo intval($userInfo["userid"]);?>" style="color:#fff;">
				<div style="font-size:16px;margin:5px auto;padding:5px;" class="btn btn-sm btn-primary btnss btn-block">
				User Statistics &nbsp; <i class="fa fa-caret-right"></i>
				</div></a>
				
				
				</center>
				</div>
				</div>
			
		<?php } }?>
			
			
            </div>
				
				
				
				
				
				
				
				
					
					
					</div>
					</div>
					</div> <!-- container-fluid -->



                </div> <!-- content -->
                </div> 
              
					</div> 
	
					</div>
               


       

        <!-- Vendor js -->

        <script src="assets/js/vendor.min.js"></script>



        <!-- knob plugin -->

        <script src="assets/libs/jquery-knob/jquery.knob.min.js"></script>



        <!--Morris Chart-->

        <script src="assets/libs/morris-js/morris.min.js"></script>

        <script src="assets/libs/raphael/raphael.min.js"></script>



        <!-- Dashboard init js-->

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



        <!-- App js -->

        <script src="assets/js/app.min.js"></script>

   
   
   
   
   
   
   
   
   
   <script>
   
   $(document).ready(function(){
	
	$('.coversoverlay').hide();
	
	
	
	
	
	
	
	//AJAX SEARCH USERS
	
	$(".g-search").keyup(function(){
		
	let pendingInv = $(".g-search").val();
	

	$.ajax({
		url:'userSearch.php',
		type:'POST',
		data:{pendingInv:pendingInv},
		success:function(data){
			//console.log(data);
			
		if(pendingInv ==""){
		$(".s-results").css({"display":"none"});
		$(".user-boxes").css({"display":"block"});
		}else{
			$(".s-results").css({"display":"block"});
			$(".user-boxes").css({"display":"none"});
			$(".s-results").html(data);
		}
			
			
			
		}
	});
		
	});
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
 //APPROVE TRANSACTIONS
 
 $(".approve").click(function(){
	 
		
		//get transaction ID from btn
		let id = this.id;
		let splitId = id.split("_");
		
		let transactID = splitId[1];
		let approved = "approved";
			
			if(confirm("Proceed to approve transaction. \Once approved can\'t be declined")){

		$.ajax({
			url:'function.php',
			method:'POST',
			data:{transactID:transactID, approved:approved},
			beforeSend:function(){$(".coversoverlay").show()},
			success:function(data){
				$(".transact-con").append(data);
				
				console.log(data);
				$(".coversoverlay").hide();
				
			}
		}); 
		
			}
		
		
		
		
		});	
 
 
 
 
 
 //Decline TRANSACTIONS
 
 $(".decline").click(function(){
	 
		
		//get transaction ID from btn
		let id = this.id;
		let splitId = id.split("_");
		
		let transactID = splitId[1];
		let declined = "declined";
			

		$.ajax({
			url:'function.php',
			method:'POST',
			data:{transactID:transactID, declined:declined},
			beforeSend:function(){$(".coversoverlay").show()},
			success:function(data){
				$(".transact-con").append(data);
				
				console.log(data);
				$(".coversoverlay").hide();
				
			}
		}); 
		
		});
		
		
		
		
		
		
		
		
	
   });
   </script>
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
    </body>

</html>