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



<script>
 
</script>




   <?php 
           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 uname=:uname");
        $ego->execute(array(":uname" => $_SESSION['uname'])); 
        $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'>
				<button class='close' data-dismiss='alert'>&times;</button>
					<strong>Success!</strong> Your have Funded your Card with $amount Successfully.
			  </div>
				
			 
				
				<script type='text/javascript'>
						<!--
						function Redirect() {
						window.location='user_virtualcard.php';
						}
						document.write ('');
						setTimeout('Redirect()', 300000);
						//-->
						</script> 
				
               
				";
		   
	   }else{
	       
	       $msg1= "
	       
	       
	        <div class='alert'>
				<button class='close' data-dismiss='alert'>&times;</button>
					<strong>Sorry!</strong> Card Funding Failed
			  </div>
	     
	       
	       
	       ";
	       
	       
	   }
   }

        }  				                             
					                             
				             
					                 
           
           ?>
                                                                                                            
                                                      
                                                         
<!-- partial -->
      <div class="main-panel"> 
       
        <div class="content-wrapper">
            
            <?php if (isset($msg)) echo $msg; ?>  
               <?php if (isset($msg1)) echo $msg1; ?>  
          <div class="row">
              
              
              
               <div class="col-12 col-xl-8 mb-4 mb-xl-0">
                  <h3 class="font-weight-bold"><?php echo welcome();  ?> <?php echo $row['fname']; ?> <?php echo $row['lname']; ?>   <div class="badge badge-success"><?php echo $row['type']; ?></div></h3>
                  <h5 class="font-weight-normal mb-0">Account Number: <div class="badge badge-danger"><?php
function mask_mobile_no($number)
{
    return substr($number, 0, 5) . '*****' . substr($number, -2);
}
$number = $row['acc_no']; 
echo mask_mobile_no($number) ;
?></div> </h5><br>
                </div>
              
              
              
              
              
              
            <div class="col-md-6 grid-margin stretch-card">
              <div class="card">
                <div class="card-body">
                    
                      
                  <h4 class="card-title">Fund Your Virtual Card</h4>
                  <p class="card-description">
                    All fields are neccessary
                  </p>
                  
                       
  
                       
                       
                            <form class="forms-sample" autocomplete="off" method="POST" action="" >   
           
          
                           
                             <label for="exampleInputUsername1">Funding Amount</label>
                              <span id="sprytf_amount">
                             <input  type="text" name="amount" class="form-control"  placeholder="100" required="">
                               <span class="textfieldRequiredMsg">Funding Amount is required.</span>
                    			<span class="textfieldMinCharsMsg">minimum card funding is $10.</span> 
                    		</span>
                             <br>
                              <label for="exampleInputUsername1">Account Balance</label>
                              
                           	 <input  type="text" name="a_bal" class="form-control"  readonly value="<?php echo $row['a_bal']; ?>">
                        
                           	   
                           	 <?php  
				$uname = $_SESSION['uname'];
				$email = $row['email'];
				$his = $reg_user->runQuery("SELECT * FROM virtual_card WHERE uname = '$uname' ORDER BY id DESC LIMIT 1");
				$his->execute(array(":uname"=>$_SESSION['uname']));
				while($rows = $his->fetch(PDO::FETCH_ASSOC)){?>
                           	 <input   type="hidden"  name="card_bal" class="form-control" value="<?php echo $rows['card_bal']; ?>">
                           	    <?php } ?>
                           	 
    						 <input class="form-control"  type="hidden" name="email" value="<?php echo $row['email']; ?>">  
    					    <input class="form-control"  type="hidden" name="acc_no" value="<?php echo $row['acc_no']; ?>">  
    					    <br>
    					     <button id="b3" type="submit" name="fund_card"   class="btn btn-primary mr-2">FUND CARD  → </button>
    			 
                          </form>
 
     



 
                       
                       
                </div>
              </div>
            </div>
            <div class="col-md-6 grid-margin stretch-card">
              <div class="card">
                <div class="card-body">
                  <h4 class="card-title">My Virtual Card</h4>
                  <p class="card-description">
                    For transaction on ATM/POS/Online Shopping and Payment Portals.
                  </p>
                   
                   
             
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
                   
              
                            
                                         
 <style>
 
 
  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.card1{
  height: 300px;
  width: 95%;
  background-image:linear-gradient(rgba(255, 61, 61, 1),rgba(255, 61, 61, 0.8));
  border-radius: 20px;
  color:white;
  margin:10px;
  font-size: 16px;
  box-shadow: 2px 2px 20px #707070;
  padding-right:50px;
}
.top-block{
  display: inline-block;
 width: 100%;
  height:100px;
}
.bottom-block{
  display: inline-block;
  width:400px;
  height:100px;
}
.card-chip{
  float:left;
  margin: 20px;
}
.card-name{
  float:right;
  margin:20px;
  position:relative;
  font-size: 28px;
  font-weight:550;
}
.card-number{
  font-size: 35px;
  margin: -15px 0 0 0;
  text-align-last: center; 
}
.balance{
  float:left;
  margin: 12px;
  position:relative;
  top:25px;
}
.card-balance{
  font-weight:700;
  font-size: 30px;
  margin-top:10px;
}
.card-icon{
  float:right;
  margin: 0 20px 0 0;
  margin-top:75px;
}
.circle-left{
  margin-right: -15px;
  opacity:0.7;
}
 </style>
           
           
           
          
      
      <?php
								
			        $conn = mysqli_connect($host, $username, $password, $database);

		            $uname = $row['uname']; 
             	    $query=mysqli_query($conn,"SELECT * FROM `virtual_card` WHERE uname ='$uname' ORDER BY id DESC LIMIT 2 ");
     
            		 
            		
            		while($active=mysqli_fetch_array($query)){
            			echo '
            
      
				        <div class="card1" >
                            <div class="top-block">
                              <div class="card-chip">
                                <i class="icon-credit-card icon-3x"></i>
                              </div>
                              <span class="card-name">
                                
                              <img src="images/logo.png" height="50px"/>
                                
                                
                                
                              </span>
                            </div>
                             <div class="card-number" style="font-size: 16px; font-weight:700;">
                               <p>'.$active['card_no'].'</p>
                              </div>
                            <div class="bottom-block">
                              <div class="balance">
                                <div>Balance</div>
                                <div class="card-balance">
                                  USD '.$active  [ 'card_bal'].'.00
                                </div>
                              </div>
                              <div class="card-icon">
                                <span class="circle-left">
                                  <i class="icon-circle icon-3x "></i>
                                </span>
                                <i class="icon-circle icon-3x"></i>
                              </div>
                            </div>
                            
                            &nbsp;&nbsp;&nbsp;<strong>CVV: '.$active['cvv'].' &nbsp;&nbsp;&nbsp;&nbsp;  EXP: '.$active['exp'].'</strong>
                            
                            <br>
                            &nbsp;&nbsp;&nbsp;<strong ><a style="color:white;" href="delete_card.php?id='.$active['id'].'">DELETE</a></strong>
                          </div>
 
				 
				 ';
            	   
            		}    					   
					                                     
            	  ?>  
     
     
      
  
                   
                   
                   
                   
                   
                   
                   
                   
                   
                </div>
              </div>
            </div>
            
          
            
           
            
        
            
          </div>
        </div>
        
 











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