<?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 ">
                    <!-- ============================================================== -->
              
                    <!-- 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> Recharge 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'];

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



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

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

if($xamount >= '90'){

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;
										$network = strtoupper($serviceID);
										$pnt = "$network Recharge PIN";
										
									
										
											
											$token = uniqid();
											$stat = "Pending";
										
										
			
		
$qsel= "INSERT INTO transactions(network,serviceid,phone,ref,refer,amount,email,status,token,balanceB,balanceA)VALUES('$pnt','$serviceID','$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/pingenerator/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;100</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/mtn.jpg" width="35" height="30"></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/airtel.jpg" width="35" height="30"></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/glo.jpg" width="35" height="30"></span>
                                            </label>
                                            
										 <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/9mobile.jpg" width="35" height="30"></span>
                                            </label>
                                            
                                       
                                           
                                        <p></p>
                                        <div class="float-center">
                                        <img style="display:none;" id="bigpic" src="bigpic"  width="120" height="90"/>     
                                                   
                                    </div>
                                    
                                   
                                 
                                  <!-- Start MTN PIN hidden -->       
                              <div class="float-center" id="ifMtn" style="display:none;">                 
                                       <div class="form-group" >
                                          
                                          <?php  
$qrypinBil = mysqli_query($conn,"SELECT * FROM pin_billing");
 $pin = mysqli_fetch_array($qrypinBil);

$qrypinBil = mysqli_query($conn,"SELECT * FROM pin_billing_agent");
  $pinA = mysqli_fetch_array($qrypinBil);

$qrypinBil = mysqli_query($conn,"SELECT * FROM pin_billing_regular");
  $pinR= mysqli_fetch_array($qrypinBil);

$Reseller  = 'paid';
$Agent  = 'agent';
$free  = 'free';
		


if($level == $Reseller ){
$mtn = $pin['mtn'];
$airtel = $pin['airtel'];
$glo = $pin['glo'];
$etisalat = $pin['etisalat'];

	 
						
						
}elseif($level == $Agent){
		
$mtn = $pinA['mtn'];
$airtel = $pinA['airtel'];
$glo = $pinA['glo'];
$etisalat = $pinA['etisalat'];

	
					
}elseif($level == $free){
		
$mtn = $pinR['mtn'];
$airtel = $pinR['airtel'];
$glo = $pinR['glo'];
$etisalat = $pinR['etisalat'];

                                         
}else{

$mtn = 100;
$airtel = 100;
$glo = 100;
$etisalat = 100;
 

}
 ?>
		 
        <label>Select Denomination:</label>
		
		<select class="form-control" id="IsMtn" required="required" >
			<option value = "" selected="selected" required="required">Select Denomination</option>
               
			<option data-plan="MTN N100 PIN" data-amount="100" data-service="mtn" data-variation_code="1" >MTN N100 (<?php echo $mtn*1; ?>)</option>
			
			<option data-plan="MTN N200 PIN" data-amount="200" data-service="mtn" data-variation_code="2" >MTN N200 (<?php echo $mtn*2; ?>)</option>
			
			<option data-plan="MTN N500 PIN"  data-amount="500" data-service="mtn" data-variation_code="5" >MTN N500 (<?php echo $mtn*5; ?>)</option>
			
			<!--<option data-plan="MTN N750 PIN"  data-amount="750" data-service="mtn" data-variation_code="7.5" >MTN N750 (<?php echo $mtn*7.5; ?>)</option>
			
			<option data-plan="MTN N1500 PIN"  data-amount="1500" data-service="mtn" data-variation_code="15" >MTN N1500 (<?php echo $mtn*15; ?>)</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 Denomination</option>
                
			<option data-plan="Airtel N100 PIN" data-amount="100"  data-service="airtel" data-variation_code="1" >Airtel N100 (<?php echo $airtel*1; ?>)</option>
			
			<option data-plan="Airtel N200 PIN"  data-amount="200" data-service="airtel" data-variation_code="2" >Airtel N200 (<?php echo $airtel*2; ?>)</option>
			
			<option data-plan="Airtel N500 PIN"  data-amount="500" data-service="airtel" data-variation_code="5" >Airtel N500 (<?php echo $airtel*5; ?>)</option>
			
			<!--<option data-plan="Airtel N1000 PIN"  data-amount="1000" data-service="airtel" data-variation_code="10" >Airtel N1000 (<?php echo $airtel*10; ?>)</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 Denomination</option>
                
               
                
			<option data-plan="Glo N100 PIN" data-amount="100"  data-service="glo" data-variation_code="1" >Glo N100 (<?php echo $glo*1; ?>)</option>
			
			<option data-plan="Glo N200 PIN" data-amount="200" data-service="glo" data-variation_code="2" >Glo N200 (<?php echo $glo*2; ?>)</option>
			
			<option data-plan="Glo N500 PIN"  data-amount="500" data-service="glo" data-variation_code="5" >Glo N500 (<?php echo $glo*5; ?>)</option>
			
			<!--<option data-plan="Glo N1000 PIN" data-amount="1000"  data-service="glo" data-variation_code="10" >Glo N1000 (<?php echo $glo*10; ?>)</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 Denomination</option>
                
               
                
			<option data-plan="9Mobile N100 PIN" data-amount="100"  data-service="9mobile" data-variation_code="1" >9Mobile N100 (<?php echo $etisalat*1; ?>)</option>
			
			<option data-plan="9Mobile N200 PIN" data-amount="200"  data-service="9mobile" data-variation_code="2" >9Mobile N200 (<?php echo $etisalat*2; ?>)</option>
			
			<option data-plan="9Mobile N500 PIN"  data-amount="500" data-service="9mobile" data-variation_code="5" >9Mobile N500 (<?php echo $etisalat*5; ?>)</option>
			
			<!--<option data-plan="9Mobile N1000 PIN" data-amount="1000"  data-service="9mobile" data-variation_code="10" >9Mobile N1000 (<?php echo $etisalat*10; ?>)</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/mtn.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/airtel.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/glo.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/9mobile.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  -->
                            <!-- ============================================================== -->
                            <?php include('inc/nav-reflink.php'); ?> 
                          
                            <!-- ============================================================== -->
                        </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');?>