<?php

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

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

		//get user 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");
		
		
		//check if user was suspended from withdrawing
		if(!empty($row["suspendWithdrawal"])){
			header("location: account.php");
		}
		
		
		
		//If Widthdrawal e-code is enabled
		if(!empty($row["withdrawalPassCode"] && !isset($_SESSION["e_code"]))){
				header("location:withdrawal-ecodeBlock.php");
		}
		
		if(!empty($row["withdrawalPassCode"])){

		if(isset($_SESSION["e_code"]) && $_SESSION["e_code"] !== $row["withdrawalPassCode"]){
			header("location:withdrawal-ecodeBlock.php");
		}
		}
		
		
		
		
		
		//redirect incase it was admin
		if($row["type"]=="admin"){
			header("location: ../admin/dashboard.php");
		}
		
		//Get Account User Balance
		$stmt="SELECT * FROM account WHERE userid = :userid";
		$stmt=$pdo->prepare($stmt);
		$stmt->bindParam("userid", $userid, PDO::PARAM_STR);
		$stmt->execute();
		$balance=$stmt->fetch();
		
		
		//Generate unique transcation ID
		$gen = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
		$shuff = str_shuffle($gen);
		$widRef = substr($shuff,0,25);
		
		
		
		
		//Block withdrawal once user deposits or invests money, only allow after processing 5days profit
		$stmt=$pdo->prepare("SELECT * FROM duedate WHERE userid=:userid");
		$stmt->bindParam(":userid",$userid, PDO::PARAM_STR);
		$stmt->execute();
		$check = $stmt->rowCount();
	
?>

<style>
form label{
	font-weight:500!important;
	color:#444;
	cursor:pointer;
	font-size:16px!important;
}
#btcCon, #ethCon, #usdtCon{
	height:0px;
	overflow:hidden;
	transition:1s;
}


input[type='radio']:after {
	width: 20px;
    height: 20px;
    border-radius: 15px;
    top: 1px;
    left: -1px;
    position: relative;
    background-color: #fbfbfb;
    content: '';
    display: inline-block;
    visibility: visible;
    border: 2px solid #6aa8cb;
}

    input[type='radio']:checked:after {
	width: 20px;
    height: 20px;
    border-radius: 15px;
    top: -2px;
    left: -1px;
    position: relative;
    box-shadow: 0em 0.1em 0.1em #bbb;
    background-color: #6aa8cb;
    content: '';
    display: inline-block;
    visibility: visible;
    border: 2px solid #ffffff;
 }
</style>


<!DOCTYPE html>

<html lang="en">

<head>

        <meta charset="utf-8" />

        <title> Withdrawal </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" />

     

        <!-- 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" >

                <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">
                            
						
						
				<form class="col-md-7" style="margin-top:20px!important;margin: auto;">
				
                <div class="card-box" style="background-image: radial-gradient(ellipse closest-side, rgb(255 255 255 / 72%),#f3f6f9), url(../img/piggy.jpg); background-repeat: no-repeat;background-position: center;">
				<h3 align="center" style='color:#767e80' id="wlcm">Withdrawal Form</h3>
				<div class="dropdown-divider"></div>
				
		
		
		
		
		<br>
		<section id="suc" class="display-none">
		<div class="success-display">Withdrawal request recieved <i class="fas fa-check"></i></div>
		<div style="color:#497589;font-size:15px; text-align:center;margin:20px;line-height:20px;">
		 A confirmation mail has been sent to you.<br>We will contact you once payment is processed</div>
		<p>
		<div class="dropdown-divider"></div>
		<div style="text-align:center">
		<a href="account.php" style="color:#2e657e; font-size:16px;"><i class="fas fa-tachometer-alt"></i> Dashboard</a> 
		&nbsp; &nbsp; <a href="../" style="color:#2e657e; font-size:16px;"> <i class="fas fa-home"></i> Back Home</a>
		</div>
		</section>
		
		<div align="center" style="color:#ff3737; margin-left:-20px!important; margin-bottom:30px;font-size:17px;font-weight:500" id="result"></div>
				
				
				
				<?php 
				
				//Pend this for future use - max daily withdrawal
				
		/*'<center><h4 style="margin-left:10px;margin-top:30px; color:#3d658d;font-weight:500">
		You have exceeded the Maximum daily withdrawal slots</h4>
		<div style="color:#999; margin:1px 15px;font-size:13px;letter-spacing: .7;line-height:17px;"> Maximum withdrawal slot is 5 times</div>
		
		<div class="dropdown-divider"></div><br><br>
		
		<a href="transactions.php" style="font-size:14px;margin-top:-5px; margin-bottom:-10px" class="btn btn-sm btn-primary btnss">
					 Check pending withdrawals &nbsp; <i class="fa fa-caret-right"></i></a>
		</center>';
			*/
				
				
				
		
			
				
				
				//check Balance Before showing withdrawal Form
				if($balance["balance"]<50){
				echo 
		'<center><h4 style="margin-left:10px;margin-top:-20px; color:#3d658d;font-weight:500">Your account is less than $50</h4>
		<div style="color:#999; margin:5px 15px;font-size:15px;letter-spacing: .2;line-height:20px;">Minimum withdrawal amount is $50</div>
		
		<div class="dropdown-divider"></div>
		<div style="margin-left:10px; margin:20px auto 20px; color:#ed3c3c;font-size:17px"> Balance: $ '. intval($balance["balance"]).'</div>
		<div class="dropdown-divider"></div><br>
		
		<a href="transactions.php" style="font-size:15px;margin-top:-5px; margin-bottom:-10px" class="btn btn-sm btn-primary btnss">
					 Check pending deposits &nbsp; <i class="fa fa-history"></i></a>
		</center>';
				
		}
				
		
		//Block withdrawal once user deposits or invests money, only allow after processing 5days profit
		elseif($check > 0){	
					
		echo 
		'<center>
		<h4 style="margin-left:10px;margin-top:30px; color:#3d658d;font-weight:500">
		Sorry! you can\'t Withdraw at this time</h4>
		<div style="color:#999; margin:5px 15px;font-size:15px;letter-spacing: .2;line-height:20px;">
		As your profit from the last deposits is actively reading, withdrawals are restricted untill processing is completed
		</div>
		
		<div class="dropdown-divider"></div><br><br>
		
		<a href="contactUs.php" style="font-size:14px;margin-top:-5px; margin-bottom:0" class="btn btn-sm btn-primary btnss">
					 Message us if you\'ve issues &nbsp; <i class="fa fa-envelope"></i></a>
		<p>
		<a href="tandc.php" style="font-size:14px;margin-top:10px;" class="btn btn-sm btn-primary btnss">
					 Read our terms of service &nbsp; <i class="fa fa-caret-right"></i></a>
		
		</center>';
				
				
		}else{
		?>
				
				
				
				
				<div id="withdrawalForm">
				
				  <div class="form-group">
                    <label for="fullName" required style="margin-left:10px"><i class="fas fa-user"></i> Full name</label>
                    <div class="col-sm-12">
                      <input type="text" name="fullName" readonly class="form-control" id="fullName" value="<?php echo htmlspecialchars($row["fullName"])?>">
                    </div>
                  </div>
				  
				  <div class="form-group">
                    <label for="email" style="margin-left:10px"><i class="fas fa-envelope"></i> Email</label>
                    <div class="col-sm-12">
                      <input type="email" required name="email" class="form-control" readonly id="email" 
					  value="<?php echo htmlspecialchars($row["email"])?>">
                    </div>
                  </div>
				  
				  <div class="form-group">
                    <label for="password" style="margin-left:10px"><i class="fas fa-key"></i> Password</label>
                    <div class="col-sm-12">
                      <input type="password" name="password" class="form-control" id="password" placeholder="Enter your password">
                    </div>
					<div style="color:#888; margin:8px 10px;font-size:15px;line-height:17px;">
					For security reasons we will need your password to process your request</div>
                  </div><br>
				   <div class="dropdown-divider"></div>
				   <h5 style="margin-left:10px;color:#3d658d!important">Select withdrawal method</h5>
				  <div class="dropdown-divider"></div>
				  
				  <br>
				  
				  
				  
				  
				  <!--BTC Withdrawal-->
				  <div style="margin-left:10px; display:flex">
				  <input type="radio" name="walletAdress" id="btcs">&nbsp; &nbsp; 
				  <label for="btcs" style="color:#3d658d!important;font-size:17px;">Bitcoin</label>
				  </div>
				  
				   <div class="form-group" id="btcCon"><br>
                    <label for="btc" style="margin-left:10px"><i class="fas fa-wallet"></i> Bitcoin wallet address</label>
                    <div class="col-sm-12">
                      <input type="text" name="btc" class="form-control" id="btc" 
					  value="<?php if(!empty($row["btc"])){echo htmlspecialchars($row["btc"]);}?>" placeholder="Enter your correct wallet address">
                    </div>
					<div style="color:#888; margin:8px 10px;font-size:15px;line-height:17px;">
					Make no mistake on your address as payment won't be refunded!</div>
					<div class="dropdown-divider"></div>
					</div>
				  
				  
				  <!--Ethereum Withdrawal-->
				  <div style="margin-left:10px; display:flex">
				  <input type="radio" name="walletAdress" id="eth">&nbsp; &nbsp; 
				  <label for="eth" style="color:#3d658d!important;font-size:17px;">Ethereum Bep20</label>
				  </div>
				  
				   <div class="form-group" id="ethCon"><br>
                    <label for="ethereum" style="margin-left:10px"><i class="fas fa-wallet"></i> Ethereum wallet address</label>
                    <div class="col-sm-12">
                      <input type="text" name="ethereum" class="form-control" id="ethereum" 
					  value="<?php if(!empty($row["ethereum"])){echo htmlspecialchars($row["ethereum"]);}?>" placeholder="Enter Ethereum Bep20 address">
                    </div>
					<div style="color:#888; margin:8px 10px;font-size:15px;line-height:17px;">
					Make no mistake on your address as payment won't be refunded!</div>
					<div class="dropdown-divider"></div>
					</div>
				  
				  
				  
				  <!--USDT Withdrawal-->
				  <div style="margin-left:10px; display:flex">
				  <input type="radio" name="walletAdress" id="usdts">&nbsp; &nbsp; 
				  <label for="usdts" style="color:#3d658d!important;font-size:17px;"> Tether USDT(TRC20)</label>
				  </div>
				  
				   <div class="form-group" id="usdtCon"><br>
                    <label for="usdt" style="margin-left:10px"><i class="fas fa-wallet"></i> Tether USDT wallet address</label>
                    <div class="col-sm-12">
                      <input type="text" name="usdt" class="form-control" id="usdt" 
					  value="<?php if(!empty($row["usdt"])){echo htmlspecialchars($row["usdt"]);}?>" placeholder="Enter Tether USDT(TRC20) address">
                    </div>
					<div style="color:#888; margin:8px 10px;font-size:15px;line-height:17px;">
					Make no mistake on your address as payment won't be refunded!</div>
					<div class="dropdown-divider"></div>
					</div>
				  
				 
				 
				  
				  
				  
				  
				  
				  
				  <br><br>
					<div class="dropdown-divider"></div>
				   <div style="margin-left:10px; color:#3d658d;font-size:17px">Your Balance: $ <?php echo intval($balance["balance"]);?></div>
				  
				  <div class="dropdown-divider"></div><br>
				  
				  <div class="form-group">
                    <label for="amount" style="margin-left:10px"> Enter amount (USD)</label>
                    <div class="col-sm-12">
                      <input type="number" step="10" name="amount" class="form-control" id="amount" placeholder="Enter amount">
                    </div>
					<div style="color:#888; margin:8px 10px;font-size:15px;line-height:17px;">
					Minimum withdrawal amount $50</div>
                  </div>
				  
				  <br>
				  
				
                 
	
                  <button type="submit" id="withdraw" class="btn btnss btn-block">Withdraw</button>
                
               </div>
			   
				<?php } ?>
			   
               </div>
              </form>

                   
						   </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();
	
 
 
 
	//Drop address link container
	
	$("#btcs").click(function(){
		$("#btcCon").css({"height":"160","transition":"1s"});
		$("#ethCon").css({"height":"0","transition":"1s"});
		$("#usdtCon").css({"height":"0","transition":"1s"});
	});
	
	$("#eth").click(function(){
		$("#ethCon").css({"height":"160","transition":"1s"});
		$("#btcCon").css({"height":"0","transition":"1s"});
		$("#usdtCon").css({"height":"0","transition":"1s"});
	});
	
	$("#usdts").click(function(){
		$("#usdtCon").css({"height":"160","transition":"1s"});
		$("#ethCon").css({"height":"0","transition":"1s"});
		$("#btcCon").css({"height":"0","transition":"1s"});
	});
 
 
 
 
 
 
 //send message
 
 $("#withdraw").click(function(e){
	 e.preventDefault();
	 
		let withdrawal = "withdraw";
		let btc = $("#btc").val();
		let ethereum = $("#ethereum").val();
		let usdt = $("#usdt").val();
		let amount = $("#amount").val();
		let widRef = "<?php echo $widRef;?>";
		let password = $("#password").val();
		
		//Radios for withdrawal method
		if($("#btcs").is(":checked")){ var walletType = "Bitcoin";}	
		else if($("#eth").is(":checked")){ var walletType = "Ethereum Bep20";}
		else if($("#usdts").is(":checked")){ var walletType = "Tether USDT(TRC20)";}
		else{
			var walletType ="";
		}

		
		$.ajax({
			url:'function.php',
			method:'POST',
			data:{btc:btc, ethereum:ethereum, usdt:usdt, amount:amount, widRef:widRef, 
					password:password, walletType:walletType, withdrawal:withdrawal},
			beforeSend:function(){$(".coversoverlay").show()},
			success:function(data){
				$("#result").html(data);
				
				//console.log(data);
				$(".coversoverlay").hide();
				
			}
		});
		
		
		
		
		});
	
 
 
 
	 
   });
   
   
   
   
   </script>
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
    </body>

</html>