<?php 
session_start();
require('db.php'); 
include('inc/func.php');
include('inc/logo.php');
?> 
<?php include('inc/header.php');?>
        <!-- ============================================================== -->
        <!-- end navbar -->
        <!-- ============================================================== -->
      
        <!-- ============================================================== -->
        <!-- left sidebar -->
        <!-- ============================================================== -->
         <?php include('inc/nav.php');?>
        <!-- ============================================================== -->
        <!-- end left sidebar -->
        <!-- ============================================================== -->
        <!-- ============================================================== -->
        <!-- wrapper  -->
        <!-- ============================================================== -->
        <div class="dashboard-wrapper">
            <div class="dashboard-ecommerce">
                <div class="container-fluid dashboard-content ">
                    <!-- ============================================================== -->
                     <?php 
                                  
                       
                         include('inc/coinpayments.inc.php');
                         
                       	
										 ?>
                    <!-- pageheader  -->
                    <!-- ============================================================== -->
                    <div class="row">
                        <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                            <div class="page-header">
                                <h2 class="pageheader-title"><li class="fa fa-mobile-alt"></li> Examination PIN Generator </h2>
                        
                            </div>
                        </div>
                    </div>
                    <!-- ============================================================== -->
                    <!-- end pageheader  -->
                    <!-- ============================================================== -->
                    <div class="ecommerce-widget">

                        <div class="row"></div>
                        <div class="row">
                            <!-- ============================================================== -->
                      
                            <!-- ============================================================== -->

                                          <!-- recent orders  -->
                            <!-- ============================================================== -->
                            <div class="col-xl-9 col-lg-12 col-md-6 col-sm-12 col-12">
                            
                                <div class="card">
                                          
                                    <h5 class="card-header"></h5>
                                    <div class="card-body">
                                      
                                    <?php
							
							if(isset($_GET['ref'])){
								       echo'<div class="alert alert-success">
										<button type="button" class="close" data-dismiss="alert">×</button>
										<strong>Transaction successful</strong>  
									</div>'; 
									
									echo '<script>
									setTimeout(function(){ window.location.href="dashboard.php" }, 3000);</script>';
									      
								        }
								        
								
									
									if(isset($_POST['tvCheck'])){
										
										$username = $_SESSION['user'];
										$amount = $_POST['amount'];
										$serviceID = $_POST['service'];
										$plan = $_POST['plan'];
										$phone = $data['phone'];
										$iuc = $_POST['iuc'];
										$variation = $_POST['variation_code'];

$amount = filter_var($amount, FILTER_SANITIZE_STRING);
$serviceID = filter_var($serviceID, FILTER_SANITIZE_STRING);
$phone = filter_var($phone, FILTER_SANITIZE_STRING);
$plan = filter_var($plan, FILTER_SANITIZE_STRING);
$variation = filter_var($variation, FILTER_SANITIZE_STRING);
$iuc = filter_var($iuc, FILTER_SANITIZE_STRING);

$amount = mysqli_real_escape_string ($conn, $amount);
$serviceID = mysqli_real_escape_string ($conn, $serviceID);
$iuc = mysqli_real_escape_string ($conn, $iuc);
$plan = mysqli_real_escape_string ($conn, $plan);
$variation = mysqli_real_escape_string ($conn, $variation);
$phone = mysqli_real_escape_string ($conn, $phone);
$username = mysqli_real_escape_string ($conn, $username);


						if(!empty($serviceID) && !empty($iuc) && !empty($variation) ){
									
										
										// replace comma
$xamount = str_replace( array( '+', ',', '-', '/', '(', ')',   '_', '//', 'drop', 'update', 'delete', 'insert', 'add',  '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $amount);

if($xamount >= '700'){

if($xamount <= $bal){
										
							
							
										
										$_SESSION['amt'] = $xamount;
										$_SESSION['carier'] = $serviceID;
										$_SESSION['phone'] = $phone;
										$_SESSION['iuc'] = $iuc;
										$_SESSION['transid'] = $uid;
										$_SESSION['plan'] = $plan;
										$_SESSION['variation_code'] = $variation;
										$pnt = $plan;
										
									
								

										
										
			
	
		
$qsel= "INSERT INTO transactions(network,phone,ref,refer,amount,email,status,token,balanceB,balanceA)VALUES('$pnt','$phone','$uid','$token','$xamount','$username','$stat','$token','$bal','$bal')";							
$sav = $conn->query($qsel);

$updateuser = mysqli_query($conn,"UPDATE users SET action='$uid' WHERE email='$user' ") or die(mysqli_error());
								
			?>
			
							  
      <script>
 window.location="transaction-view/exampin/index.php?<?php echo $uid; ?>#transPreview";
                                </script>  
                            <?php
			
								
                              	
	}else{
										echo'<div class="alert alert-danger">
										<button type="button" class="close" data-dismiss="alert">×</button>
										<strong>Insufficient Balance</strong>  
									</div>'; }
									
									
									
		}else{
										echo'<div class="alert alert-danger">
										<button type="button" class="close" data-dismiss="alert">×</button>
										<strong>Invalid Amount. Minimum Amount is &#x20A6;750</strong>  
									</div>'; }

} else{
										echo'<div class="alert alert-danger">
										<button type="button" class="close" data-dismiss="alert">×</button>
										<strong>Enter required fields</strong>  
									</div>'; }
									}
									
									 ?>
                      
           
                   
                                        <label for="inputText3" class="col-form-label">Please Select Network</label><br>
                                            <label class="custom-control custom-radio custom-control-inline">
                                                <input type="radio" name="carier"  class="custom-control-input" value="mtn" onclick="javascript:showTv();" id="mtn" ><span class="custom-control-label"><img src="assets/images/waec.jpg" width="50" height="45"></span>
                                            </label>
                                            
                                            
                                            <label class="custom-control custom-radio custom-control-inline">
                                                <input type="radio" name="carier" class="custom-control-input"value="airtel" onclick="javascript:showTv();" id="airtel"><span class="custom-control-label" ><img src="assets/images/neco.jpg" width="50" height="45"></span>
                                            </label>
                                            
                                            <label class="custom-control custom-radio custom-control-inline">
                                                <input type="radio" name="carier" class="custom-control-input"value="glo" onclick="javascript:showTv();" id="glo"><span class="custom-control-label" ><img src="assets/images/nabteb.jpg" width="50" height="45"></span>
                                            </label>
                                            
<a href="jamb.php"><img src="assets/images/jamb.jpg" width="60" height="50"></a>
										 <!--<label class="custom-control custom-radio custom-control-inline">
                                                <input type="radio" name="carier" class="custom-control-input"value="etisalat" onclick="javascript:showTv();" id="etisalat"><span class="custom-control-label" ><img src="assets/images/jamb.jpg" width="50" height="45"></span>
                                            </label>-->
                                            
                                       
                                           
                                        <p></p>
                                        <div class="float-center">
                                        <img style="display:none;" id="bigpic" src="bigpic"  width="150" height="120"/>     
                                                   
                                    </div>
                                    
                                   
                                 
                                  <!-- Start MTN PIN hidden -->       
                              <div class="float-center" id="ifMtn" style="display:none;">                 
                                       <div class="form-group" >
                                          
                                          <?php  
$query_rec = mysqli_query($conn,"SELECT * FROM exam_billing");
$waec2A = mysqli_fetch_array($query_rec);
	



$query_rec2 = mysqli_query($conn,"SELECT * FROM exam_billing_regular");
$waecR = mysqli_fetch_array($query_rec2);





if($level == $Reseller ){
$waec = $waec2A['waec'];
$neco = $waec2A['neco'];
$nabteb = $waec2A['nabteb'];
$nysc = $waec2A['nysc'];
$waec2 = $waec2A['waecGCE'];
$neco2 = $waec2A['necoGCE'];
$nabteb2 = $waec2A['nabtebGCE'];
$jambutme = $waec2A['jambutme'];
$jambde = $waec2A['jambde'];
		

	
					
				
}else{
		

$waec = $waecR['waec'];
$neco = $waecR['neco'];
$nabteb = $waecR['nabteb'];
$nysc = $waecR['nysc'];
$waec2 = $waecR['waecGCE'];
$neco2 = $waecR['necoGCE'];
$nabteb2 = $waecR['nabtebGCE'];
$jambutme = $waecR['jambutme'];
$jambde = $waecR['jambde'];
 } ?>
		 
        <label>Select Denomination:</label>
		
		<select class="form-control" id="IsMtn" required="required" >
			<option value = "" selected="selected" required="required">Select PIN Type</option>
               
			<option data-plan="WAEC Result Checking PIN" data-amount="<?php echo $waec;?>" data-service="waec" data-variation_code="1" >WAEC Result Checking PIN (N<?php echo $waec; ?>)</option>
			
			<option data-plan="WAEC Verification PIN" data-amount="<?php echo $nysc; ?>" data-service="waec" data-variation_code="3" >WAEC Verification PIN (N<?php echo $nysc; ?>)</option>
			
			<option data-plan="WAEC GCE Registration PIN"  data-amount="<?php echo $waec2; ?>" data-service="waec" data-variation_code="2" >WAEC GCE Registration PIN (N<?php echo $waec2; ?>)</option>
			
			
			
			
			
			
			
			
                </select>
		
		
      </div>


      
      <div class="form-group">
          <label for="inputText3" class="col-form-label">Number of PINs</label>
    <input id="smartno" type="text" class="form-control" name="smartno" onKeyUp="javacript:document.getElementById('iuc').value = document.getElementById('smartno').value;" onSelect="javacript:document.getElementById('iuc').value = document.getElementById('smartno').value;">
                                            </div>
                                            
                       
                             
                                            
                </div>
                <!-- End MTN PIN hidden -->   
                
               
                <!-- Start Airtel PIN hidden -->       
                              <div class="float-center" id="ifAirtel" style="display:none;">                 
                                       <div class="form-group" >
                                                 
		 
        <label>Select Denomination:</label>
		
		<select class="form-control" id="IsAirtel" required="required" >
			<option value = "" selected="selected" required="required">Select PIN Type</option>
                
			<option data-plan="NECO Result Checking TOKEN" data-amount="<?php echo $neco;?>"  data-service="neco" data-variation_code="1" >NECO Result Checking TOKEN (N<?php echo $neco; ?>)</option>
			
			<option data-plan="NECO GCE Registration PIN"  data-amount="<?php echo $neco2; ?>" data-service="neco" data-variation_code="2" >NECO GCE Registration PIN (N<?php echo $neco2; ?>)</option>
			
			
			
			
                
                </select>
	
	
      </div>


      
      
      <div class="form-group">
          <label for="inputText3" class="col-form-label">Number of PINs</label>
    <input id="smartcard" type="text" class="form-control" name="smartno" onKeyUp="javascript:document.getElementById('iuc').value = document.getElementById('smartcard').value;" onSelect="javascript:document.getElementById('iuc').value = document.getElementById('smartcard').value;">
                                            </div>
                                            
                           
                                              
                                            
                </div>
                <!-- End Airtel PIN hidden -->  
                
          <!-- Start Glo PIN hidden -->       
                              <div class="float-center" id="ifGlo" style="display:none;">                 
                                       <div class="form-group" >
                                                 
		 
        <label>Select Denomination:</label>
		
		<select class="form-control" id="IsGlo" required="required" >
			
			<option value = "" selected="selected" required="required">Select PIN Type</option>
                
               
                
			<option data-plan="NABTEB Result Checking PIN" data-amount="<?php echo $nabteb;?>"  data-service="nabteb" data-variation_code="1" >NABTEB Result Checking PIN (N<?php echo $nabteb;?>)</option>
			
			<option data-plan="NABTEB GCE Registration PIN" data-amount="<?php echo $nabteb2;?>" data-service="nabteb" data-variation_code="2" >NABTEB GCE Registration PIN (N<?php echo $nabteb2;?>)</option>
			
                </select>
	
      </div>


      
       
      <div class="form-group">
          <label for="inputText3" class="col-form-label">Number of PINs</label>
    <input id="smart" type="text" class="form-control" name="smartno" onKeyUp="javascript:document.getElementById('iuc').value = document.getElementById('smart').value;" onSelect="javascript:document.getElementById('iuc').value = document.getElementById('smart').value;">
                                            </div>
                               
                                            
                </div>
                <!-- End Glo PIN hidden -->  
										
										
			  <!-- Start Etisalat PIN hidden -->       
                              <div class="float-center" id="ifEtisalat" style="display:none;">                 
                                       <div class="form-group" >
                                                 
		 
        <label>Select Denomination:</label>
		
<select class="form-control" id="IsEtisalat" required="required" ><option value = "" selected="selected" required="required">Select PIN Type</option>
                
               
                
			<option data-plan="JAMB UTME Registration PIN" data-amount="<?php echo $jambutme;?>"  data-service="jamb" data-variation_code="jambutme" >JAMB UTME Registration PIN (N<?php echo $jambde;?>)</option>
			
			<option data-plan="JAMB Direct Entry Registration PIN" data-amount="<?php echo $jambde;?>"  data-service="jamb" data-variation_code="jambde" >JAMB Direct Entry Registration PIN (N<?php echo $jambde;?>)</option>
                
                </select>
	
      </div>


      
       
      <div class="form-group">
          <label for="inputText3" class="col-form-label">Number of PINs</label>
    <input id="pinNO" type="text" class="form-control" name="etisano" onKeyUp="javascript:document.getElementById('iuc').value = document.getElementById('pinNO').value;" onSelect="javascript:document.getElementById('iuc').value = document.getElementById('pinNO').value;">
                                            </div>
                               
                                            
                </div>
                <!-- End Etisalat PIN hidden -->							
										
										
										
                 <form method="post" action="" >                            
          
                 <input type="hidden" value="" name="plan" id="plan">
		 <input type="hidden" value="" name="service" id="service">
         
         <input type="hidden" value="" name="amount" id="amount">
         
         <input type="hidden" value="" name="iuc" id="iuc">
         
         <input type="hidden" value="" name="tel" id="tele">
         <input type="hidden" value="" name="variation_code" id="variation_code">
                                            
                     <div class="col-sm-6 pl-0">
                           <p class="text-center">
                                                    <button type="submit" name="tvCheck" class="btn btn-rounded btn-primary" >Proceed </button>
                           <button class="btn btn-rounded btn-secondary">Cancel</button>                    
                                                </p>                                            
                                            </div>       
                                        </form>
                                        
                                 
                                    </div>
                                </div>
                            </div>
                            <!-- ============================================================== -->
                            <!-- end recent orders  -->
                            
                    
                            
<script>

 function Comma(Num)
 {
       Num += '';
       Num = Num.replace(/,/g, '');

       x = Num.split('.');
       x1 = x[0];

       x2 = x.length > 1 ? '.' + x[1] : '';

       
         var rgx = /(\d)((\d{3}?)+)$/;

       while (rgx.test(x1))

       x1 = x1.replace(rgx, '$1' + ',' + '$2');
     
       return x1 + x2;       
        
 }
 
 
 
 function showTv(){
    if (document.getElementById('mtn').checked) {
        document.getElementById('ifMtn').style.display = 'block';
		
		var sourceOfPicture = "assets/images/waec.jpg";
  var img = document.getElementById('bigpic')
  img.src = sourceOfPicture.replace('90x90', '225x225');
  img.style.display = "block";
	
  $('#IsMtn').change(function(){
	  var selected = $(this).find('option:selected');
	  var amount = selected.data('amount');
	  var service = selected.data('service');
	  var plan = selected.data('plan');
	  var variation_code = selected.data('variation_code');
	  $('#amount').val(amount);
	  $('#service').val(service);
	  $('#plan').val(plan);
	  $('#variation_code').val(variation_code);
	  }); 
  
    }else document.getElementById('ifMtn').style.display = 'none';
	
	
	if (document.getElementById('airtel').checked) {
        document.getElementById('ifAirtel').style.display = 'block';
		
		var sourceOfPicture = "assets/images/neco.jpg";
  var img = document.getElementById('bigpic')
  img.src = sourceOfPicture.replace('90x90', '225x225');
  img.style.display = "block";
  
  $('#IsAirtel').change(function(){
	  var selected = $(this).find('option:selected');
	  var amount = selected.data('amount');
	  var service = selected.data('service');
	  var plan = selected.data('plan');
	  var variation_code = selected.data('variation_code');
	  $('#amount').val(amount);
	  $('#service').val(service);
	  $('#plan').val(plan);
	  $('#variation_code').val(variation_code);
	  });
		
	
		
		}else document.getElementById('ifAirtel').style.display = 'none';
	
	if (document.getElementById('glo').checked) {
        document.getElementById('ifGlo').style.display = 'block';
		
		var sourceOfPicture = "assets/images/nabteb.jpg";
  var img = document.getElementById('bigpic')
  img.src = sourceOfPicture.replace('90x90', '225x225');
  img.style.display = "block";
		
		
		$('#IsGlo').change(function(){
	  var selected = $(this).find('option:selected');
	  var amount = selected.data('amount');
	  var service = selected.data('service');
	  var plan = selected.data('plan');
	  var variation_code = selected.data('variation_code');
	  $('#amount').val(amount);
	  $('#service').val(service);
	  $('#plan').val(plan);
	  $('#variation_code').val(variation_code);
	  });
		
	}
    
	else document.getElementById('ifGlo').style.display = 'none';
	 
	 
	 if (document.getElementById('etisalat').checked) {
        document.getElementById('ifEtisalat').style.display = 'block';
		
		var sourceOfPicture = "assets/images/jamb.jpg";
  var img = document.getElementById('bigpic')
  img.src = sourceOfPicture.replace('90x90', '225x225');
  img.style.display = "block";
		
		
		$('#IsEtisalat').change(function(){
	  var selected = $(this).find('option:selected');
	  var amount = selected.data('amount');
	  var service = selected.data('service');
	  var plan = selected.data('plan');
	  var variation_code = selected.data('variation_code');
	  $('#amount').val(amount);
	  $('#service').val(service);
	  $('#plan').val(plan);
	  $('#variation_code').val(variation_code);
	  });
		
	}
    
	else document.getElementById('ifEtisalat').style.display = 'none';
	 
	}



                            </script> 
                            <!-- ============================================================== -->
                            <!-- ============================================================== -->
                            <!-- customer acquistion  -->
                            <!-- ============================================================== -->
                            <div class="col-xl-3 col-lg-6 col-md-6 col-sm-12 col-12">
                                <div class="card">
                                    <h5 class="card-header">Account Status</h5>
                                    <div class="card-body">
                                   <div class="d-inline-block">
                                        <h5 class="text-muted">Current Balance</h5>
                                        <h2 class="mb-0"> &#x20A6;<?php echo number_format($bal,2,'.',',');?></h2>
                                    </div>
                                    <div class="float-right icon-circle-medium  icon-box-lg  bg-brand-light mt-1">
                                        <i class="fa fa-money-bill-alt fa-fw fa-sm text-brand"></i>
                                    </div>
                                   
                                    </div>
                                </div>
                                
                                <div class="card">
                                <div class="card-body">
                                    <div class="d-inline-block">
                                        <h5 class="text-muted">Affiliate Link:</h5>
                                        <p class="mb-0"> <?php echo $data['reflink'];echo $data['refid'];?></p>
                                        
                                    </div>
                                    <div class="float-left"><p class="text-muted"><strong>Total Referred:</strong> <?php echo $data['refcount']; ?> <br> 
                                    
                                   <strong> Earning:</strong> &#x20A6;<?php echo number_format($data['refwallet'],2,'.',','); ?>
                                    </p> </div>
                                    
                                    
                                    <div class="float-right icon-circle-medium  icon-box-lg  bg-primary-light mt-1">
                                        
                                        <i class="fa fa-users fa-fw fa-sm text-primary"></i>
                                    </div>
                                </div>
                            </div>
                            </div>
                            <!-- ============================================================== -->
                            
                            
                            
                            <!-- end customer acquistion  -->
                      <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                        <div class="card">
                            <h5 class="card-header">Transaction History</h5>
                            <div class="card-body">
                                <div class="table-responsive">
                                    <table class="table table-striped table-bordered first">
                                        <thead>
                                            <tr>
                                                <th>Transaction ID</th>
                                                
                                                <th>Amount</th>
                                                <th>Status</th>
                                                <th>Date</th>
                                               
                                            </tr>
                                        </thead>
                                        <tbody>
                                         <?php 
										
										while($row = $resu->fetch_assoc())
											
											{
										
											?>
                                            <tr>
                                           
                                                <td><?php echo $row['orderno']; ?></td>
                                                
                                                <td><?php echo '&#x20A6;'.$row['amount'].' ';?></td>
                                                 <td><?php echo $row['status'];?></td>
                                                <td><?php echo $row['date'];?></td>
                                                
                                            </tr>
                                           
                                           <?php } ?>
                                          
                                           
                                        </tbody>
                                        <tfoot>
                                            <tr>
                                                <th>Transaction ID</th>
                                                
                                                <th>Amount</th>
                                                <th>Status</th>
                                                <th>Date</th>
                                                
                                            </tr>
                                        </tfoot>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>      
                          
                            <!-- ============================================================== -->
                        </div>
                        <div class="row">
                          
                        </div>

                        <div class="row">
                            <!-- ============================================================== -->
                            <!-- sales  -->
                         
                            <!-- end new customer  -->
                           
                        </div>
                        <div class="row">
              
                        </div>
                        <div class="row">
                      
                        </div>
                    </div>
                </div>
            </div>
            <!-- ============================================================== -->
            <!-- footer -->
            <!-- ============================================================== -->
            <?php include('inc/footer.php');?>