<?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-tv"></li> TV Payment </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'];
										$service = $_POST['service'];
										$plan = $_POST['plan'];
										$phone = $_POST['tel'];
										$iuc = $_POST['iuc'];
								
										$variation = $_POST['variation_code'];

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


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

$phone = $phone = str_replace( array( '+', ',', '-', '/', '(', ')',   '_',   '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $phone); 
$iuc = $phone = str_replace( array( '+', ',', '-', '/', '(', ')',   '_',   '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $iuc); 

						if(!empty($amount) && !empty($service) && !empty($iuc) && !empty($variation) ){
									
										
										// replace comma
$xamount = str_replace( array( '+', ',', '-', '/', '(', ')',   '_',   '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $amount);
								 
if($amount >= '50'){

if($xamount <= $bal){								 
										
										
										$_SESSION['amt'] = $xamount;
										$_SESSION['carier'] = $service;
										$_SESSION['phone'] = $phone;
										$_SESSION['iuc'] = $iuc;
										$_SESSION['transid'] = $uid;
										$_SESSION['plan'] = $plan;
										$_SESSION['variation_code'] = $variation;
										
									
										
										if($service === 'gotv'){
											
											$pnt = "GOTV Payment";
											
											}elseif($service === 'dstv'){
												
												$pnt = "DSTV Payment";
												
										}elseif($service === 'startimes'){
												
												$pnt = "Startimes Payment";	

										}elseif($service === 'showmax'){
												
												$pnt = "Showmax Payment";
												
												}else{
													
													$pnt = "Invalid Cable TV";
													}	
									

										
										
include('inc/verify-tv.php');							    
							    

		    
		    if($status !== "Completed"){
	
		    

			
			echo'<div class="alert alert-warning">
		<button type="button" class="close" data-dismiss="alert">×</button>
		<strong>Error Occured '.$APImessage.' <br> Contact Admin on '.$sitephone.'</strong>  
									</div>'; 
			
			}	else{		
					
									
$qsel = "INSERT INTO transactions(network,serviceid,vcode,meterno,phone,ref,refer,amount,email,status,token,customer,balanceB,balanceA,date)VALUES('$pnt','$service','$variation','$iuc','$phone','$uid','$token','$xamount','$username','$stat','$token','$customer','$bal','$bal','$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/paytv/index.php?<?php echo $uid; ?>#transPreview";
          </script>
         <?php 
											
$_SESSION['customer_number']=$result->description->customerNumber;
			
$_SESSION['customer'] = $result->description->Customer;

$_SESSION['service']=$service;

$_SESSION['customerNumber'] = $result->description->customerNumber;
				
$_SESSION['invoiceNo'] = $result->description->invoiceNo;

$customer = $_SESSION['customer'];
$invoice = $_SESSION['invoiceNo'];
$customerno = $_SESSION['customerNumber'];
								
                                }	
								
			}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;50</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('inc/paytv_func.php');									
									
									 ?>
                      
           
                   
                                        <label for="inputText3" class="col-form-label">Please Select TV Gateway To Recharge</label><br>
                                            <label class="custom-control custom-radio custom-control-inline">
                                                <input type="radio" name="carier"  class="custom-control-input" value="gotv" onclick="javascript:showTv();" id="gotv" ><span class="custom-control-label"><img src="assets/images/Gotv-Payment.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="dstv" onclick="javascript:showTv();" id="dstv"><span class="custom-control-label" ><img src="assets/images/Pay-DSTV-Subscription.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="startimes" onclick="javascript:showTv();" id="startimes"><span class="custom-control-label" ><img src="assets/images/Startimes-Subscription.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>Bouquet:</label>
		
		<select class="form-control" id="IsGotv" required="required" ><option value = "" selected="selected" required="required">Select Gotv Banquet</option>
            
<!--<option data-plan="GOtv Smallie - Quaterly N2100" data-amount="2100" data-service="GOTV" data-variation_code="gotv-smallie-3months">GOtv Smallie-Quaterly N2100</option>
<option data-plan="GOtv Smallie - yearly N6200" data-amount="6200" data-service="GOTV" data-variation_code="gotv-smallie-1year">GOtv Smallie-Yearly N6200</option>-->


                   
<option data-plan="Gotv Smallie" data-amount="<?php echo $smallieA;?>" data-service="gotv" data-variation_code="gotv_smallie">GOtv Smallie-Monthly N<?php echo $smallieA;?></option>
<option data-plan="Gotv Jinja" data-amount="<?php echo $jinja;?>" data-service="gotv" data-variation_code="gotv_jinja">GOtv Jinja  N<?php echo $jinja;?></option>
<option data-plan="Gotv Jolli" data-amount="<?php echo $jolli;?>" data-service="gotv" data-variation_code="gotv_jolli">GOtv Jolli N<?php echo $jolli;?></option>
<option data-plan="Gotv Max" data-amount="<?php echo $max;?>" data-service="gotv" data-variation_code="gotv_max">Gotv Max N<?php echo $max;?></option>
                </select>
</div>
		
		
      


      
     <div class="form-group">
          <label for="inputText3" class="col-form-label">Smartcard Number</label>
    <input id="smartno" type="text" class="form-control" name="smartno" oninput="javacript:document.getElementById('iuc').value = document.getElementById('smartno').value;" onSelect="javacript:document.getElementById('iuc').value = document.getElementById('smartno').value;">
                                            </div>
                                            
              <!-- <div class="form-group">
          <label for="inputText3" class="col-form-label">Phone Number (Optional)</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>Bouquet:</label>
		
		<select class="form-control" id="IsDstv" required="required" ><option value = "" selected="selected" required="required">Select DSTV Banquet</option>
           
            <option data-plan="Dstv Padi" data-amount="<?php echo $padi;?>" data-service="dstv" data-variation_code="dstv_padi">DStv Padi N<?php echo $padi;?></option>
 <option data-plan="DSTv Yanga" data-amount="<?php echo $yanga;?>" data-service="dstv" data-variation_code="dstv_yanga">DStv Yanga N<?php echo $yanga;?></option>
  <option data-plan="Dstv Confam" data-amount="<?php echo $confam;?>" data-service="dstv" data-variation_code="dstv_confam">Dstv Confam N<?php echo $confam;?></option>
<option data-plan="DSTv Compact" data-amount="<?php echo $compact;?>" data-service="dstv" data-variation_code="dstv_compact">DStv  Compact N<?php echo $compact;?></option>
<option data-plan="DsTv Compact Plus" data-amount="<?php echo $compactplus;?>" data-service="dstv" data-variation_code="dstv_compact_plus">DStv Compact Plus N<?php echo $compactplus;?></option>
<option data-plan="DSTv Premium" data-amount="<?php echo $premium;?>" data-service="dstv" data-variation_code="dstv_premium">DStv Premium N<?php echo $premium;?></option>



                
                </select>
	
	
      </div>


      
      
     <div class="form-group">
          <label for="inputText3" class="col-form-label">Smartcard Number</label>
    <input id="smartcard" type="text" class="form-control" name="smartno" oninput="javascript:document.getElementById('iuc').value = document.getElementById('smartcard').value;" onSelect="javascript:document.getElementById('iuc').value = document.getElementById('smartcard').value;">
                                            </div>
                                            
             <!-- <div class="form-group">
          <label for="inputText3" class="col-form-label">Phone Number (Optional)</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>Bouquet:</label>
		
		<select class="form-control" id="IsStar" required="required" ><option value = "" selected="selected" required="required">Select Startimes Banquet</option>

<option data-plan="Startimes Nova" data-amount="<?php echo $nova;?>" data-service="startimes" data-variation_code="startimes_nova"> Startimes Nova - N<?php echo $nova;?> Naira  - 1 Month</option>
<option data-plan="Startimes Basic" data-amount="<?php echo $basic;?>" data-service="startimes" data-variation_code="startimes_basic">Startimes Basic - N<?php echo $basic;?> Naira  - 1 Month</option>
<option data-plan="Startimes Smart" data-amount="<?php echo $smart;?>" data-service="startimes" data-variation_code="startimes_smart">Startimes Smart - N<?php echo $smart;?> Naira  - 1 Month</option>
<option data-plan="Startimes Classic" data-amount="<?php echo $classic;?>" data-service="startimes" data-variation_code="startimes_classic">Startimes Classic - N<?php echo $classic;?> Naira  - 1 Month</option>
<option data-plan="Startimes Unique" data-amount="<?php echo $unique;?>" data-service="startimes" data-variation_code="startimes_unique">StarTimes Unique - N<?php echo $unique;?></option>
<option data-plan="Startimes Super" data-amount="<?php echo $super;?>" data-service="startimes" data-variation_code="startimes_super">Startimes Super - N<?php echo $super;?> Naira - 1 Month</option>
                
                </select>
	
      </div>


      
       
     <div class="form-group">
          <label for="inputText3" class="col-form-label">Smartcard Number</label>
    <input id="smart" type="text" class="form-control" name="smartno" oninput="javascript:document.getElementById('iuc').value = document.getElementById('smart').value;" onSelect="javascript:document.getElementById('iuc').value = document.getElementById('smart').value;">
                                            </div>
                                            
              <!-- <div class="form-group">
          <label for="inputText3" class="col-form-label">Phone Number (Optional)</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 -->                                      
                 <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="form-group">
          <label for="inputText3" class="col-form-label">Smartcard Number</label>
    <input id="inputText3" type="phone" class="form-control" name="iuc">
                                            </div> -->
                                            
                     <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('gotv').checked) {
        document.getElementById('ifGotv').style.display = 'block';
		
		var sourceOfPicture = "assets/images/Gotv-Payment.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');
	  var variation_code = selected.data('variation_code');
	  $('#amount').val(amount);
	  $('#service').val(service);
	  $('#plan').val(plan);
	  $('#variation_code').val(variation_code);
	  }); 
  
    }else document.getElementById('ifGotv').style.display = 'none';
	
	
	if (document.getElementById('dstv').checked) {
        document.getElementById('ifDstv').style.display = 'block';
		
		var sourceOfPicture = "assets/images/Pay-DSTV-Subscription.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');
	  var variation_code = selected.data('variation_code');
	  $('#amount').val(amount);
	  $('#service').val(service);
	  $('#plan').val(plan);
	  $('#variation_code').val(variation_code);
	  });
		
	
		
		}else document.getElementById('ifDstv').style.display = 'none';
	
	if (document.getElementById('startimes').checked) {
        document.getElementById('ifStar').style.display = 'block';
		
		var sourceOfPicture = "assets/images/Startimes-Subscription.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');
	  var variation_code = selected.data('variation_code');
	  $('#amount').val(amount);
	  $('#service').val(service);
	  $('#plan').val(plan);
	  $('#variation_code').val(variation_code);
	  });
		
	}
    
	else document.getElementById('ifStar').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');?>