<?php

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

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

		//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");
		
		
		
		if(!isset($_GET["user"])){
			header("location:users.php");
		}else{
			$theUser = intval($_GET["user"]);
		}
		
		
		//get user info
		$stmt="SELECT * FROM users WHERE userid = :userid";
		$stmt=$pdo->prepare($stmt);
		$stmt->bindParam("userid", $theUser, PDO::PARAM_STR);
		$stmt->execute();
		$userInfo=$stmt->fetch();
		$userimg = (!empty($userInfo["profilepix"]) ? "../img/users/".$userInfo["profilepix"]: "../img/avatar.png");
		
	
	
		//Generate unique e-Code
		$gen = "1234567890";
		$shuff = str_shuffle($gen);
		$eCode = substr($shuff,0,6);
	
	
	
	
?>

<style>
form label{
	font-weight:500!important;
	color:#444;
	cursor:pointer;
	font-size:16px!important;
}
</style>


<!DOCTYPE html>

<html lang="en">

<head>

        <meta charset="utf-8" />

        <title>Site Maintenance | 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" >

                <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-7" style="margin-top:20px!important;margin: auto;">
                
				<div class="card-box" style="background-image: radial-gradient(ellipse closest-side, rgba(255, 255, 255, 0.8),#d5e1ed); background-repeat:no-repeat; background-position:center">
				
			
				<h3 align="center" style="color:#475d79" id="wlcm"><i class="fa fa-lock"></i> e-Code Withdrawal</h3>
				<div class="dropdown-divider" style="border-color:#d4dee7;"></div>
				
		<center>
		<img src="<?php echo $userimg;?>" class="avatars"><br><br>
		<div style="color:#405972; font-size:16px; margin-bottom:10px;"><b><?php echo htmlspecialchars($userInfo["fullName"]);?></b></div>
		<br>
		
		<div id="codeResult">
		<?php if(!empty($userInfo["withdrawalPassCode"])){
		echo '<div style="color: #405972;font-size:17px"><b>User e-Code</b>&nbsp; <font color="#e13131">'. 
				intval($userInfo["withdrawalPassCode"]) . '</font></div>';}?>
		</div>
		
		</center>
		<div class="dropdown-divider" style="border-color:#d4dee7;"></div>		
			
		
				
			<div class="form-group charge" style="margin:10px auto 20px auto">
			
			<br>
			
			
			
		<label for="passCode" style="color: #405972;font-size:17px;"><b>Auto Generated e-Code</b></label>
		<div class="form-group charge" style="margin:-2px auto 20px auto">
		<input type="number" name="passCode" readonly id="passCode" class="form-control" placeholder="Enter Pass Code" 
		value="<?php echo intval($eCode); ?>">
		<div style="color:#4c6681; font-size:13px; margin:5px 0px">Refresh page to change code</div>
		</div>
			
			<div style="color: #405972;font-size: 16px;border: 1px solid #bfcedd;margin:14px auto;border-radius: 10px;padding:15px;background: #e5edf3;line-height: 1.5;">
			<i class="fa fa-exclamation-circle"></i> This option allows you to turn on an <b>e-code Withdrawal Lock.</b> This user can not process withdrawal without the alternate <b>Pass Code</b> 
			</div>
			
			
			<?php if(empty($userInfo["withdrawalPassCode"])){?>
			
			<div style="color: #405972;font-size: 15px;margin:8px;text-align:center" id="ltext">
			<i class="fa fa-unlock"></i> Currently turned off</div>
             <button id="lock" class="btnss btn btn-block" style="cursor:pointer;color:#fff;border-radius:0px;">
			 <i class="fa fa-power-off"></i> Turn on e-code lock</button>
			 
			<?php }else{?>
			
			<!--for Ajax-->
			<div style="color: #405972;font-size: 15px;margin:8px;text-align:center" id="ltext" class="display-none">
			<i class="fa fa-unlock"></i> Currently turned off</div>
			<button id="lock" class="btnss btn btn-block display-none" style="cursor:pointer;color:#fff;border-radius:0px;">
			<i class="fa fa-power-off"></i> Turn on e-code lock</button>
			
			
			<div style="color:#e13131;font-size: 15px;margin:8px;text-align:center" id="utext"><i class="fa fa-lock">
			</i> Currently turned on</div>
			<button id="unlock" class="btnssD btn btn-block" style="cursor:pointer;color:#fff;border-radius:0px;">
			<i class="fa fa-exclamation-triangle"></i> Turn off e-code lock</button>
			<?php }?>
			
			<!--for Ajax-->
			<div style="color:#e13131;font-size: 15px;margin:8px;text-align:center" id="utext" class="display-none">
			<i class="fa fa-lock"></i> Currently turned on</div>
             <button id="unlock" class="btnssD btn btn-block display-none" style="cursor:pointer;color:#fff;border-radius:0px;">
			 <i class="fa fa-exclamation-triangle"></i> Turn off e-code lock</button>
              
			</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();
		 
 

 
		//LOCK E-withdrawal
 
		$("#lock").click(function(){
	 
	 
		let passCode = $("#passCode").val();
		let eLocked = "locked";	
		let user = <?php echo $theUser; ?>;	
		
		
		if(passCode == ""){
			$("#passCode").focus();
			alert("Enter 6 Digits Passcode");
			return false;
		}
		else{
		
		$.ajax({
			url:'function.php',
			method:'POST',
			data:{passCode:passCode, eLocked:eLocked, user:user},
			beforeSend:function(){$(".coversoverlay").show()},
			success:function(data){
				
				if(data == 1){
					$("#lock").addClass("display-none");
					$("#ltext").addClass("display-none");
					
					$("#unlock").removeClass("display-none");
					$("#utext").removeClass("display-none");
					
					
		//swap user Previous display code
		$("#codeResult").html('<div style="color: #405972;font-size:17px"><b>User e-Code</b>&nbsp; <font color="#e13131"> '+passCode+'</font></div>');
				}
				
				$(".coversoverlay").hide();
				
			}
		}); 
		
		}
		
		});






		//UNLOCK E-withdrawal
 
	$("#unlock").click(function(){
	 
		let eUnlocked = "unlock";
		let user = <?php echo $theUser; ?>;			

		$.ajax({
			url:'function.php',
			method:'POST',
			data:{eUnlocked:eUnlocked, user:user},
			beforeSend:function(){$(".coversoverlay").show()},
			success:function(data){
				
				if(data == 1){
					$("#unlock").addClass("display-none");
					$("#utext").addClass("display-none");
					
					
					$("#lock").removeClass("display-none");
					$("#ltext").removeClass("display-none");
					
					
					$("#codeResult").html("");
				}
				
				$(".coversoverlay").hide();
				
			}
		}); 
		
		});
	
 
 
 
 
 
 
	 
   });
   
   
   
   
   </script>
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
    </body>

</html>