<?php

require __dir__ . '/init.php';



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

	$_POST = help::sanitize($_POST);
	
	$numbers = implode("", help::array_blend(range(0,9),range(0,9),range(0,9)));
	
	$card = substr(str_shuffle($numbers),0, 16);
	$csv = substr(str_shuffle($numbers),0, 3);


    if($_POST['phone'] != $__user['phone']) $msg = "Please enter phone attached to bank!";
	
	elseif( $_POST['acct'] != $__user['acctno']) $msg = "Please enter your correct account number";

    else{

        if(!empty($__user['csv'])) $msg = "You Already applied, Wait For Administrator Approval!";
		
		else{
			
			$sql1 = "
				UPDATE tbl_users 
				SET card='$card',	
					cardt='$cardt',
					csv='$csv'   
				WHERE acctno='$account'";
			
			$msg = (mysqli_query($link, $sql1)) ? "Application Successful!" : "Cannot Apply! ";
			
		}
	}
}


template::get_header();


?>

	<?php template::title( "Card Application" ); ?>
	
    <div class="row">
        <div class="col-lg-12">
                    
			<div class="sparkline12-list shadow-reset mg-t-30">
				<div class="sparkline12-graph">
                    <div class="basic-login-form-ad">
					
						<div class="row">
							<div class="col-lg-12">
								<div class="all-form-element-inner">
								
									<form action="card.php" method="post">

										<?php template::alert( $msg );  ?>

										<div class="form-group">
											<div class="row">
												<div class="col-lg-3">
													<label class="login2 pull-right pull-right-pro">Phone</label>
												</div>
												<div class="col-lg-3">
													<input type="text" name="phone" placeholder="Enter phone number"  class="form-control" required />
												</div>
											</div>
										</div>

										<div class="form-group">
											<div class="row">
												<div class="col-lg-3">
													<label class="login2 pull-right pull-right-pro">Account Number</label>
												</div>
												<div class="col-lg-3">
													<input type="text" name="acct" placeholder="Enter account number"  class="form-control" required />
												</div>
											</div>
										</div>
										
										<div class="form-group">
											<div class="row">
												<div class="col-lg-3">
													<label class="login2 pull-right pull-right-pro">Card Type</label>
												</div>
												<div class="col-lg-3">
													<select type="text" name="cardt"  class="form-control" required />
														<option>Select Card Type</option>
														<option>Credit Master Card</option>
														<option>Debit Master Card</option>
														<option>Credit Visa Card</option>
														<option>Debit Visa Card</option>
													</select>
												</div>
											</div>
										</div>
										
										<div class="form-group">
											<div class="row">
												<div class="col-lg-3">
													
												</div>
												<div class="col-lg-3">
													<input type="submit" name="apply" value="Apply For Card"  class="btn btn-info" />
												</div>
											</div>
										</div>

									</form>
								
									<?php

										$no_app = 'Not Yet Activated &nbsp;&nbsp;<i style="color:red;font-size:20px;" class="fa  fa-times" ></i>';
										
										$valid = !empty($__user['sstatus']);
										
									?>
									
									<hr>
									
									<!------------ [START DEBIT CARD] --------------->
									
									<div class='row mt-4'>
										<div class="col-lg-4 col-md-6 col-sm-6 col-xs-12">
											<div class="card payment-card responsive-mg-b-30 bg-primary">
												<div class="payment-inner-pro card-body text-white">
												
													<p><i><?php echo $valid ? $__user['cardt'] : $no_app; ?></i></p>
													
													<h5 class='mb-3'><?php echo $valid ? $__user['card'] : $no_app; ?></h5>
													
													<div class="row m-t-10">
													
														<div class="col-6">
															<strong class="m-r-5">Expiry Date :</strong><br />
															<?php echo $valid ? ($__user['month'] . ' ' . $__user['yr']) : $no_app; ?>
														</div>
														
														<div class="col-6">
															<strong class="m-r-5">Name :</strong>
															<?php echo $valid ? ($__user['fname'] . ' ' . $__user['lname']) : $no_app; ?><br />
															<strong class="m-r-5">CSV :</strong>
															<?php echo $valid ? $__user['csv'] : $no_app; ?>
														</div>
														
													</div>
													
												</div>
											</div>
										</div>
									</div>
							
									<!------------ [END DEBIT CARD] ----------->
									
								</div>
							</div>
							
						</div>
					</div>
				</div>
					
			</div>
		</div>
	</div>
           

<?php template::get_footer(); ?> 