<?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'];
 

?>


 <?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: 260px;
  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" > VIRTUAL CARDS</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;">Use the form below to create a virtual Visa card for POS  and Online Shopping, Pay Bill and Subscriptions</p>
          
            		    <div class="container"> 
                    <form class="cmxform"  autocomplete="off" method="POST" action="">  
                    
                    	     <?php
					                                if(isset($_POST['add_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);
						   
						                            $name =$_REQUEST['name'];
						                            $acc_no =$_REQUEST['acc_no'];
						                            $email =$_REQUEST['email'];
						                            $card_no =$_REQUEST['card_no'];
						                            $exp =$_REQUEST['exp'];
						                            $cvv =$_REQUEST['cvv'];
                                                    $card_type =$_REQUEST['card_type'];
                                                    $card_status =$_REQUEST['card_status'];
                                                    $card_bal =$_REQUEST['card_bal'];
                                                    $card_date =$_REQUEST['card_date'];
                                               
                                            
    $stmt = $reg_user->runQuery("SELECT * FROM virtual_card WHERE card_no=:card_no");
    $stmt1 = $reg_user->runQuery("SELECT * FROM virtual_card WHERE cvv=:cvv");
    $stmt2 = $reg_user->runQuery("SELECT * FROM virtual_card WHERE acc_no=:acc_no");
    $stmt->execute(array(":card_no" => $card_no));
    $stmt1->execute(array(":cvv" => $cvv));
    $stmt2->execute(array(":acc_no" => $acc_no));
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    $row1 = $stmt1->fetch(PDO::FETCH_ASSOC);
    $row2 = $stmt2->fetch(PDO::FETCH_ASSOC);


    if ($stmt->rowCount() > 0 || $stmt1->rowCount() > 0 || $stmt2->rowCount() > 0) {
        $msg = "
		      <div class='alert alert-danger'>
				<button class='close' data-dismiss='alert'>&times;</button>
					<strong>Sorry!</strong> Customer/Card  Details Already Issued, Please use your CARD!!
			  </div>
			                                                            <script type='text/javascript'>
                                                							<!--
                                                							function Redirect() {
                                                							window.location='virtual_card.php';
                                                							}
                                                							document.write ('');
                                                							setTimeout('Redirect()', 3000);
                                                							//-->
                                                							</script>
			  ";
    } else {        
        
        $sql = "INSERT INTO `virtual_card` (`id`, `name`, `acc_no`, `email`, `card_no`, `exp`, `cvv`, `card_type`, `card_status`, `card_bal`, `card_date`) 
        VALUES (NULL, '$name', '$acc_no', '$email', '$card_no', '$exp', '$cvv', '$card_type', '$card_status', '$card_bal', '$card_date')";
                                                      
                                                    
          
                            						   $insert=mysqli_query($conn, $sql);
                            						   
                            						   if($insert){
                            						       
                            						       
                            							  
                            							  	$msg = "
                                            					<div class='alert alert-success'> 
                                            					<center>	<strong style='color:black;'>You Have Created Card Successfully.
                                                                       </strong></center>
                                                                       
                                                                       	<script type='text/javascript'>
                                                							<!--
                                                							function Redirect() {
                                                							window.location='virtual_card.php';
                                                							}
                                                							document.write ('');
                                                							setTimeout('Redirect()', 3000);
                                                							//-->
                                                							</script>
                                            			  		</div>
                                            					";
                                            					
                            
                            						   }else{
                            						       
                            						       echo '<h3>Card Creation Failed!</h3>';
                            						       
                            						       
                            						   }
                            					   
					                                }
					                                }
                            					?>
                    
                    
                    
                                             <?php if (isset($msg)) echo $msg; ?>
                                     
                                     
								     
                           
                             <label for="firstName1">Card Type:</label>
                             <select  name="card_type" required >
                                            <option value="">Select Card Type</option> 
                                            <option value="Visa Card">Visa Card</option> 
                                       
                            </select> 
                        
                            
                            
                               
                             <label for="lastName1">Card Serial Number:</label>
                             <input  type="text" name="card_no" placeholder="e.g  5310 1092 2902 1922" required="">
                           
                             <label for="lastName1">Card Expiry Date:</label>
                             <input  type="text" name="exp" placeholder="e.g  10/25" required="">
                           
                             <label for="lastName1">CVV/Security Code:</label>
                             <input  type="text" name="cvv" placeholder="e.g 899" required="">
                            
                            
                            <input class="custom-date form-control"  type="hidden" name="card_status" value="INACTIVE"> 
                            <input class="custom-date form-control"  type="hidden" name="card_bal" value="0"> 
                             <input class="custom-date form-control"  type="hidden" name="card_date" value="<?php echo date("h:i A d M Y"); ?>">
    						 <input class="custom-date form-control"  type="hidden" name="email" value="<?php echo $row['email']; ?>"> 
    						<input class="custom-date form-control"  type="hidden" name="name" value="<?php echo $row['fname']; ?> <?php echo $row['lname']; ?>"> 
    					    <input class="custom-date form-control"  type="hidden" name="acc_no" value="<?php echo $row['acc_no']; ?>">     
                            
                            
                             
                         
                            
                            <input type="submit" name="add_card" id="mybutton" class="btn bg-gradient-dark mb-0" value="+ ADD 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'].'.00</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="fund_card.php">
			         <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="FUND CARD" />
			     </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'; ?>		
	 
    
								
						
 

         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         