<?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-wifi"></li> SME DATA Bundle </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($_POST['DataCheck'])){


					
										 $username = $_SESSION['user'];
										$amount = $_POST['amount'];


										$serviceID = $_POST['service'];
										$plan = $_POST['plan'];
										$phone = $_POST['phone'];
										$variation = $_POST['plan'];

$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);

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

$variation = str_replace( array( '+', ',', '-', '/', '(', ')',   '_',  '//', 'drop', 'update', 'delete', 'insert', 'add', '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $variation);

$phone = str_replace( array( '+', ',', '-', '/', '(', ')',   '_', '//', 'drop', 'update', 'delete', 'insert', 'add',  '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $phone);

$xamount = str_replace( array( '+', ',', '-', '/', '(', ')',   '_',  '//', 'drop', 'update', 'delete', 'insert', 'add', '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $amount);

												
		
		if(!empty($serviceID)&& !empty($phone) && !empty($variation) ){
											
										
if($xamount >= '100'){

if($xamount <= $bal){
		                  
$type = "SME";
$_SESSION['amt'] = $xamount;
$_SESSION['phone'] = $phone;
$_SESSION['transid'] = $uid;
$_SESSION['plan'] = $plan;
$_SESSION['variation_code'] = $variation;
$_SESSION['service'] = $type;

										
$variation = preg_replace('/[^0-9]/', '', $variation);				
if($variation == '100'  ){
$valu = "100MB";

}elseif($variation == '250'  ){
$valu = "250MB";

}elseif($variation == '260'  ){
$valu = "260MB";

}elseif($variation == '300'  ){
$valu = "300MB";

}elseif($variation == '500'  ){
$valu = "500MB";

}elseif($variation == '1000'  ){
$valu = "1GB";

}elseif($variation == '1500'  ){
$valu = "1.5GB";
			
}elseif($variation == '2000' ){
$valu = "2GB";

}elseif($variation == '3000' ){
$valu = "3GB";

}elseif($variation == '3500' ){
$valu = "3.5GB";

}elseif($variation == '3750' ){
$valu = "3.75GB";

}elseif($variation == '4000' ){
$valu = "4GB";


}elseif($variation == '4500' ){
$valu = "4.5GB";

}elseif($variation == '5000' ){
$valu = "5GB";
						
}elseif($variation == '10000'){			 
$valu = "10GB";

}elseif($variation == '15000' ){
$valu = "15GB";

}elseif($variation == '20000' ){
$valu = "20GB";
}else{
$MB = "MB";
$valu = "$variation$MB";
}	



	if($serviceID === '01'){
	$pnt = "$valu MTN $type DATA";
	$net = "MTN";
	$service = "MTNSME";
	
	}elseif($serviceID === '02'){		
		$pnt = "$valu GLO $type DATA";
		$net = "GLO";
		$service = "GLOSME"; 
		
		}elseif($serviceID === '03'){		
		$pnt = "$valu 9Mobile $type DATA";
        $net = "9Mobile";
        $service = "9MOBILESME";		
			
			}elseif($serviceID === '04'){				
				$pnt = "$valu Airtel $type DATA";
				$net = "Airtel";
				$service = "AIRTELSME";
				}
				

$_SESSION['carier'] = $service;
$_SESSION['pnt'] = $pnt;
$_SESSION['network'] = $net;


										
									
										
											
											$token = uniqid();
											$stat = "Pending";


									
$qsel = "INSERT INTO transactions(network,serviceid,phone,amount,customer,email,status,ref,refer,token,balanceB,balanceA,del,action,date)VALUES('$pnt','$net','$phone','$xamount','$customer','$username','$stat','$uid','$token','$token','$bal','$bal','$del','$accno','$date')";								
$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/data?<?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>'; }
									}
									
									
						
include('transaction-view/data/data_SME_func.php');			
									 ?>
                      
           
                   
                                         <label for="inputText3" class="col-form-label">Please Network To Recharge</label><br>
                                            <label class="custom-control custom-radio custom-control-inline">
                                                <input type="radio" name="carier"  class="custom-control-input" value="mtn-data" onclick="javascript:showTv();" id="gotv" ><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-data" onclick="javascript:showTv();" id="dstv"><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-data" onclick="javascript:showTv();" id="startimes"><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-data" onclick="javascript:showTv();" id="9mobile"><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 GOTV hidden -->       
                              <div class="float-center" id="ifGotv" style="display:none;">                 
                                       <div class="form-group" >
                                          
		 
        <label>Select Bundle:</label>
		
		<select class="form-control" id="IsGotv" required="required" ><option value = "" selected="selected" required="required">Select MTN SME Data</option>
               
 <option data-plan="500W" data-amount="<?php echo $mtnA;?>" data-service="01" >MTN SME Data &#x20A6;<?php echo $mtnA;?> 500MB - 30 days</option>
 <option data-plan="1000" data-amount="<?php echo $mtnB;?>" data-service="01">MTN SME Data &#x20A6;<?php echo $mtnB;?> 1GB - 30 days</option>
 <option data-plan="2000" data-amount="<?php echo $mtnC;?>"  data-service="01">MTN SME Data &#x20A6;<?php echo $mtnC;?> 2GB - 30 days</option>
<option data-plan="3000" data-amount="<?php echo $mtnD;?>"  data-service="01">MTN SME Data &#x20A6;<?php echo $mtnD;?> 3GB - 30 days</option>
<option data-plan="5000" data-amount="<?php echo $mtnE;?>" data-service="01" >MTN SME Data &#x20A6;<?php echo $mtnE;?> - 5GB - 30days</option>
<option data-plan="10000" data-amount="<?php echo $mtnF;?>" data-service="01">MTN SME Data &#x20A6;<?php echo $mtnF;?> - 10GB - 30days</option>

                
                </select>
		
      </div>

                
           <div class="form-group">
          <label for="inputText3" class="col-form-label">Phone Number</label>
    <input id="mobile" type="phone" class="form-control" name="phone" oninput="javascript:document.getElementById('tele').value = document.getElementById('mobile').value;" onSelect="javascript:document.getElementById('tele').value = document.getElementById('mobile').value;">
                                            </div>             
                             
                                            
                </div>
                <!-- End GOTV hidden -->   
                
               
                <!-- Start DSTV hidden -->       
                              <div class="float-center" id="ifDstv" style="display:none;">                 
                                       <div class="form-group" >
                                                 
		 
        <label>Select Bundle:</label>
		
		<select class="form-control" id="IsDstv" required="required" ><option value = "" selected="selected" required="required">Select Airtel SME Data</option>
                
    
 <!--<option data-plan="500" data-amount="<?php echo $airtelA;?>" data-service="04">Airtel SME Data - &#x20A6;<?php echo $airtelA;?> - 500MB - 30 Days</option>-->
                
<option data-plan="1000D" data-amount="<?php echo $airtelB;?>" data-service="04">Airtel SME Data - &#x20A6;<?php echo $airtelB;?> - 1GB - 7 Days</option>
                
 <option data-plan="2000D" data-amount="<?php echo $airtelC;?>" data-service="04">Airtel SME Data - &#x20A6;<?php echo $airtelC;?> - 2GB - 7 Days</option>
 <option data-plan="3000W" data-amount="<?php echo $airtelD;?>" data-service="04">Airtel SME Data - &#x20A6;<?php echo $airtelD;?> - 3GB - 7 Days</option>
<!-- <option data-plan="5000" data-amount="<?php echo $airtelE;?>" data-service="04">Airtel SME Data - &#x20A6;<?php echo $airtelE;?> - 5GB - 30 Days</option>-->
 <option data-plan="10000" data-amount="<?php echo $airtelF;?>" data-service="04">Airtel SME Data - &#x20A6;<?php echo $airtelF;?> - 10GB - 30 Days</option>             
                
                </select>
	
      </div>


      
                                            
             <div class="form-group">
          <label for="inputText3" class="col-form-label">Phone Number</label>
    <input id="phone" type="phone" class="form-control" name="phone" oninput="javascript:document.getElementById('tele').value = document.getElementById('phone').value;" onSelect="javascript:document.getElementById('tele').value = document.getElementById('phone').value;">
                                            </div>                
                                              
                                            
                </div>
                <!-- End DSTV hidden -->  
                
          <!-- Start STARTTIMES hidden -->       
                              <div class="float-center" id="ifStar" style="display:none;">                 
                                       <div class="form-group" >
                                                 
		 
        <label>Select Bundle:</label>
		
		<select class="form-control" id="IsStar" required="required" ><option value = "" selected="selected" required="required">Select GLO SME Data</option>
               

            
            
 <option data-plan="260" data-amount="<?php echo $gloA;?>" data-service="02"> Glo SME Data &#x20A6;<?php echo $gloA;?> - 260MB - 7 day</option>
                
         <!-- <option data-plan="500" data-amount="<?php echo $gloB;?>" data-service="02">Glo SME Data &#x20A6;<?php echo $gloB;?> -  500MB - 30 days</option>-->
          
          <option data-plan="1500D" data-amount="<?php echo $gloC;?>" data-service="02"> Glo SME Data &#x20A6;<?php echo $gloC;?> -  1.5GB - 1 day</option>
          
          
       <option data-plan="2500D" data-amount="<?php echo $gloD;?>" data-service="02">Glo SME Data &#x20A6;<?php echo $gloD;?> -  2.5GB - 2 days</option>
          
          
       <option data-plan="3750D" data-amount="<?php echo $gloE;?>" data-service="02"> Glo SME Data &#x20A6;<?php echo $gloE;?> -  3.75GB - 7 days</option>

<!--       <option data-plan="4000" data-amount="<?php echo $gloF;?>" data-service="02"> Glo SME Data &#x20A6;<?php echo $gloF;?> -  4GB - 30 days</option>
          
          
          <option data-plan="5000" data-amount="<?php echo $gloG;?>" data-service="02">Glo SME Data &#x20A6;<?php echo $gloG;?> - 5GB - 30 days</option>-->

<option data-plan="10000W" data-amount="<?php echo $gloH;?>" data-service="02"> Glo SME Data &#x20A6;<?php echo $gloH;?> - 10GB  - 7 day</option>
            
                
                </select>
	
      </div>


   
                                            
            <div class="form-group">
          <label for="inputText3" class="col-form-label">Phone Number</label>
    <input id="mobil" type="phone" class="form-control" name="phone" oninput="javascript:document.getElementById('tele').value = document.getElementById('mobil').value;" onSelect="javascript:document.getElementById('tele').value = document.getElementById('mobil').value;">
                                            </div>                   
                                            
                </div>
                <!-- End STARTIMES hidden --> 
                
                
                
           <!-- Start 9Mobile hidden -->       
                              <div class="float-center" id="if9mob" style="display:none;">                 
                                       <div class="form-group" >
                                                 
		 
        <label>Select Bundle:</label>
		
		<select class="form-control" id="Is9mob" required="required" ><option value = "" selected="selected" required="required">Select 9Mobile SME Data </option>
               

            
            
            
    <option data-plan="250" data-amount="<?php echo $etisalatA;?>" data-service="03">9mobile SME Data - &#x20A6;<?php echo $etisalatA;?> - 250MB - 30 Days </option>

 <option data-plan="500" data-amount="<?php echo $etisalatB;?>" data-service="03">9mobile SME Data - &#x20A6;<?php echo $etisalatB;?> - 500MB - 30 Days </option>
 
  <option data-plan="3500" data-amount="<?php echo $etisalatF;?>" data-service="03"> 9mobile SME Data - &#x20A6;<?php echo $etisalatF;?> - 3.5GB - 30 Days</option>
                
        <!--  <option data-plan="1000" data-amount="<?php echo $etisalatC;?>" data-service="03">9mobile SME Data - &#x20A6;<?php echo $etisalatC;?> - 1GB - 30 Days</option>
          
          <option data-plan="1500" data-amount="<?php echo $etisalatD;?>" data-service="03"> 9mobile SME Data - &#x20A6;<?php echo $etisalatD;?> - 1.5GB - 30 Days</option>
          
          
          <option data-plan="2000" data-amount="<?php echo $etisalatE;?>" data-service="03">9mobile SME Data - &#x20A6;<?php echo $etisalatE;?> - 2GB - 30 Days</option>
          
          
    
          

  <option data-plan="4000" data-amount="<?php echo $etisalatG;?>" data-service="03">9mobile SME Data - &#x20A6;<?php echo $etisalatG;?> -4GB - 30 Days</option>


  <option data-plan="4500" data-amount="<?php echo $etisalatH;?>" data-service="03">9mobile SME Data - &#x20A6;<?php echo $etisalatH;?> - 4.5GB - 30 Days</option>
          
          
          <option data-plan="5000" data-amount="<?php echo $etisalatI;?>" data-service="03">9mobile SME Data - &#x20A6;<?php echo $etisalatI;?> - 5GB - 30 Days</option>
          
          

            
            
            <option data-plan="10000" data-amount="<?php echo $etisalatJ;?>" data-service="03">9mobile SME Data - &#x20A6;<?php echo $etisalatJ;?> - 10GB - 30 Days</option> -->
               
         
            
             
              
                </select>
	
      </div>


   
                                            
                   <div class="form-group">
          <label for="inputText3" class="col-form-label">Phone Number</label>
    <input id="9mobil" type="phone" class="form-control" name="phone" oninput="javascript:document.getElementById('tele').value = document.getElementById('9mobil').value;" onSelect="javascript:document.getElementById('tele').value = document.getElementById('9mobil').value;">
                                            </div> -                   
                                            
                </div>
                <!-- End 9Mobile 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="phone" id="tele">
         
                <!--   <div class="form-group">
          <label for="inputText3" class="col-form-label">Phone Number</label>
    <input id="inputText3" type="phone" class="form-control" name="tel" required>
                                            </div> -->
											
        
                                            
                     <div class="col-sm-6 pl-0">
                           <p class="text-center">
                                                    <button type="submit" name="DataCheck" 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('gotv').checked) {
        document.getElementById('ifGotv').style.display = 'block';
		
		var sourceOfPicture = "assets/images/Data-mtn.jpg";
  var img = document.getElementById('bigpic')
  img.src = sourceOfPicture.replace('90x90', '225x225');
  img.style.display = "block";
	
  $('#IsGotv').change(function(){
	  var selected = $(this).find('option:selected');
	  var amount = selected.data('amount');



	  var service = selected.data('service');
	  var plan = selected.data('plan');
	  $('#amount').val(amount);
                
	  $('#service').val(service);
	  $('#plan').val(plan);
	  
	  }); 
  
    }else document.getElementById('ifGotv').style.display = 'none';
	
	
	if (document.getElementById('dstv').checked) {
        document.getElementById('ifDstv').style.display = 'block';
		
		var sourceOfPicture = "assets/images/Airtel-Data.jpg";
  var img = document.getElementById('bigpic')
  img.src = sourceOfPicture.replace('90x90', '225x225');
  img.style.display = "block";
  
  $('#IsDstv').change(function(){
	  var selected = $(this).find('option:selected');
	  var amount = selected.data('amount');
	  var service = selected.data('service');
	  var plan = selected.data('plan');
	  $('#amount').val(amount);
	  $('#service').val(service);
	  $('#plan').val(plan);
	  });
		
	
		
		}else document.getElementById('ifDstv').style.display = 'none';
	
	if (document.getElementById('startimes').checked) {
        document.getElementById('ifStar').style.display = 'block';
		
		var sourceOfPicture = "assets/images/GLO-Data.jpg";
  var img = document.getElementById('bigpic')
  img.src = sourceOfPicture.replace('90x90', '225x225');
  img.style.display = "block";
		
		
		$('#IsStar').change(function(){
	  var selected = $(this).find('option:selected');
	  var amount = selected.data('amount');
	  var service = selected.data('service');
	  var plan = selected.data('plan');
	  $('#amount').val(amount);
	  $('#service').val(service);
	  $('#plan').val(plan);
	  });
		
	}
    
	else document.getElementById('ifStar').style.display = 'none';
	


if (document.getElementById('9mobile').checked) {
        document.getElementById('if9mob').style.display = 'block';
		
		var sourceOfPicture = "assets/images/9mobile-Data.jpg";
  var img = document.getElementById('bigpic')
  img.src = sourceOfPicture.replace('90x90', '225x225');
  img.style.display = "block";
		
		
		$('#Is9mob').change(function(){
	  var selected = $(this).find('option:selected');
	  var amount = selected.data('amount');
	  var service = selected.data('service');
	  var plan = selected.data('plan');
	  $('#amount').val(amount);
	  $('#service').val(service);
	  $('#plan').val(plan);
	  });
		
	}
    
	else document.getElementById('if9mob').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');?>