<?php
session_start();
include_once ('conn/session.php');
require_once 'conn/controller.php';

if(!isset($_SESSION['acc_no'])){
    
header("Location: auth_login.php");
exit(); 
}

 

$reg_user = new USER();
$stmt = $reg_user->runQuery("SELECT * FROM account WHERE acc_no=:acc_no");
$stmt->execute(array(":acc_no" => $_SESSION['acc_no']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);

$email = $row['email'];
 
 

  if(isset($_POST['fund_card'])){

        $conn = mysqli_connect($host, $username, $password, $database);
        
        // Check connection
        
        if (!$conn) {
              die("Connection failed: " . mysqli_connect_error());
        }
         
        echo ""; 
        
        $db_select = mysqli_select_db($con, $database);

        
        $acc_no =$_REQUEST['acc_no'];
        $card_bal =$_REQUEST['card_bal']; 
        $amount =$_REQUEST['amount'];

  
  
  
  
        $ego = $reg_user->runQuery("SELECT a_bal FROM account WHERE acc_no=:acc_no");
        $ego->execute(array(":acc_no" => $_SESSION['acc_no'])); 
        $owo = $ego->fetch(PDO::FETCH_ASSOC); 
        
        
        $a_bal = $row['a_bal'];
        $amount = "$amount";
        
        
        if ($a_bal < $amount ) {
           
        $msg = "
		      <div class='alert alert-danger'>
				<button class='close' data-dismiss='alert'>&times;</button>
					<strong>Sorry! </strong> You Have Insufficient Fund!!
			  </div>
			  ";
    } else { 
  
   
    $card_bal = $card_bal + $amount;
    $sql = "UPDATE `virtual_card` SET `card_bal` = '$card_bal' WHERE `virtual_card`.`acc_no` = $acc_no ";                                             
                                    
                       
            						 
	   $insert=mysqli_query($conn, $sql);
	   
	   if($insert){
	       
	       
	       $conn = mysqli_connect($host, $username, $password, $database);

		   $acc_no = $row['acc_no']; 
	       $a_bal = $row['a_bal'];
           $a_bal = $a_bal - $amount;
           
	        $query=mysqli_query ($conn, "UPDATE account SET a_bal = '$a_bal' WHERE acc_no = '$acc_no'");
            
	       
	       
		  	$msg = "
				<div class='alert alert-success'>
				
				<script type='text/javascript'>
						<!--
						function Redirect() {
						window.location='virtual_card.php';
						}
						document.write ('');
						setTimeout('Redirect()', 3000);
						//-->
						</script>
						
				<center><img src='icon/logo-ok-png-2.png' width='60px'  /></center>
				
                
				<center>	<strong style='color:white;'>Your have Funded your Card with $amount Successfully.
                       </strong></center>
		  		</div>
				";
		   
	   }else{
	       
	       echo '<h3>Card Funding Failed!</h3>';
	       
	       
	   }
   }

        }                                 
                                     


?>
 <?php 

if (isset($_POST['card_bal'])) { 
    $_SESSION['card_bal'] = $_POST['card_bal'];
}
?> 

 <?php include 'auth_header.php'; ?>
 
 <!---begin of Mobile View Here   only from Digital Forest Team-->
 
     
   
   
  				
  <script>
    $(document).ready(function() {
      $('#mybutton').hide().delay(5000).fadeIn(2200);
});
    </script> 

 <style>
input[type=text2] {
  width: 60%;
  padding: 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
  margin-top: 6px;
  margin-bottom: 16px;
  resize: vertical;
} 

input[type=text], select, textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
  margin-top: 6px;
  margin-bottom: 16px;
  resize: vertical;
}

input[type=number], date{
  width: 100%;
  padding: 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
  margin-top: 6px;
  margin-bottom: 16px;
  resize: vertical;
}


input[type=submit] {
  padding: 12px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

input[type=submit]:hover {
  background-color: #45a049;
}

.container {
  border-radius: 5px;
  background-color: ;
  padding: 20px;
}
</style>
						
<style>


.card-block {
  height: 250px;
  background: #6236FF;
  border-radius: 10px;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.09);
  color: #fff;
  position: relative;
}

.card-block .card-main {
  background-image: linear-gradient(-180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.23) 100%);
  position: absolute;
  border-radius: 10px;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  display: flex;
  align-items: flex-end;
  padding: 20px 24px;
}

.card-block .card-button {
  position: absolute;
  right: 10px;
  top: 10px;
}

.card-block .card-button > .btn {
  background: transparent !important;
  color: #fff !important;
}

.card-block span.label {
  font-size: 11px;
  letter-spacing: 1px;
  opacity: 0.5;
  line-height: 1em;
  margin-bottom: 5px;
  text-transform: uppercase;
  display: block;
  font-weight: 500;
}

.card-block .in .card-number {
  font-size: 17px;
  letter-spacing: 3px;
  font-weight: 500;
}

.card-block .in .card-expiry {
  font-size: 14px;
  font-weight: 500;
  margin-right: 20px;
}

.card-block .in .card-ccv {
  font-weight: 500;
  font-size: 14px;
}

.card-block .bottom {
  display: flex;
  align-items: center;
  margin-top: 20px;
}

.card-block .balance {
  position: absolute;
  left: 24px;
  top: 24px;
}

.card-block .balance .title {
  font-weight: 700;
  color: #fff;
  margin-top: 7px;
  font-size: 24px;
}


</style>				
				




					
<br><br>
 
 
 <div class="container-fluid py-4">
 
  <div class="row">
        <div class="col-12">
          <div class="card my-4">
            <div class="card-header p-0 position-relative mt-n4 mx-3 z-index-2">
              <div class="bg-gradient-primary shadow-primary border-radius-lg pt-4 pb-3">
                <h4 class="text-white text-capitalize ps-3"><img src="icon/ibft.png" height="40" width="40" > CARD FUNDING</h4> 
              </div>
            </div>
            <div class="card-body px-0 pb-2"> 
                
                
                
                
                      <div class="row">
        <div class="col-md-7 mt-4">
          <div class="card"> 
            <div class="card-body pt-4 p-3">
               <p style="color:darkgreen;">Fund your card from your Avaliable Balance</p>
          
            		    <div class="container"> 
       
                            <form class="cmxform"  autocomplete="off" method="POST" action="">   
                                             <?php if (isset($msg)) echo $msg; ?>
                                     
                                      
                        
                           
                             <label for="lastName1">Funding Amount</label>
                             <input  type="text" name="amount" placeholder="100" required="">
                              <label for="lastName1">Avaliable Balance</label>
                              
                           	 <input  type="text" name="a_bal" disabled value="<?php echo $row['a_bal']; ?>">
                           	  <label for="lastName1">Card Balance</label>
                           	 <input   type="text" disabled name="card_bal" value="<?php echo $_SESSION['card_bal']; ?>">
    						 <input class="form-control"  type="hidden" name="email" value="<?php echo $row['email']; ?>">  
    					    <input class="custom-date form-control"  type="hidden" name="acc_no" value="<?php echo $row['acc_no']; ?>">  
                            <input type="submit" name="fund_card" id="mybutton" class="btn bg-gradient-dark mb-0" value="FUND CARD  → ">  
                          </form>
             
	  
                         
        
            </div>
            </div>
          </div>
        </div>
        <div class="col-md-5 mt-4">
          <div class="card h-100 mb-4">
            <div class="card-header pb-0 px-3">
              <div class="row">
                <div class="col-md-6">
                  <h6 class="mb-0">My Bank Cards</h6>
                </div>
                <div class="col-md-6 d-flex justify-content-start justify-content-md-end align-items-center">
                  <i class="material-icons me-2 text-lg">date_range</i>
                  <small><?php echo date("h:i A d M Y"); ?></small>
                </div>
              </div>
            </div>
            <div class="card-body pt-4 p-3"> 
                   
                   
			    <?php
								
			        $conn = mysqli_connect($host, $username, $password, $database);

		            $acc_no = $row['acc_no']; 
             	    $query=mysqli_query($conn,"SELECT * FROM `virtual_card` WHERE acc_no ='$acc_no' ORDER BY id DESC LIMIT 2 ");
     
            		 
            		
            		while($active=mysqli_fetch_array($query)){
            			echo '
            
            <div class="card-block " style="background-color:#0d5154;">
                <div class="card-main">
                    <div class="card-button dropdown"> 
                           <img  src="icon/visa.png" height="20px" width="70px"> 
                    </div>
                    <div class="balance">
                        <span class="label">BALANCE</span>
                        <h3 class="title">USD '.$active['card_bal'].'</h3>
                    </div>
                    <div class="in">
                        <div class="card-number">
                            <span class="label">Card Number</span>
                            <strong style="font-size:16px;  font-weight:700;">'.$active['card_no'].'</strong>
                        </div>
                        <div class="bottom">
                            <div class="card-expiry">
                                <span class="label">Expiry</span>
                                '.$active['exp'].'
                            </div>
                            <div class="card-ccv">
                                <span class="label">CCV</span>
                               '.$active['cvv'].'
                            </div>
                            
                             <div class="card-ccv">
                                &nbsp;&nbsp; &nbsp;&nbsp;<strong style="color:red;"><a href="delete_card.php?id='.$active['id'].'">X DELETE</a></strong>&nbsp;&nbsp;&nbsp;&nbsp;
                                
                                  <form method="POST" action="#">
			         <input type="hidden" name="card_bal"  value="'.$active['card_bal'].'"/>
			     &nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" class="btn bg-gradient-primary"  style="width:120px;" value="DISABLED" />
			     </form>
                                
                                
                                
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- * card block -->
				 ';
            	   
            		}    					   
					                                     
            	  ?>  
			   
                   
                   
            </div>
          </div>
        </div>
      </div>
                
                
      
                          
		    
		    </div>
 
                 
              
              <br><br>
            </div>
          </div>
        </div><br><br>
      </div>
 
 
 
 </div>
 







				
				
				
				
			 
           
                    
	
	
	
       

 <?php include 'auth_footer.php'; ?>		
	 
    
								
						
 

         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         