
<?PHP

	 session_id('oelibmb8jkej60s9bssefjomov');
	session_start();
			
			//echo session_id();
?>


<a href="dashboard.php"><input type="button" value="Proceed" onClick="spinner()" style= "width:; height: inherit; float: " > </a>	






<?php


 //$txnid= $_GET['txnId'];
 

//$errorMessage = "";


  $errorMessage = @ $_GET['txnfailed'];


		
			
/*

if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
	header ("Location: ../login.php");
}
		
*/






  $current_date = date("Y-m-d");
echo '<br>';

 $activation_d = $_SESSION['activation_date'];

echo '<br>';
  $expiration_d = $_SESSION['expiration_date'];

echo '<br>';



  $app_code = $_SESSION['app_code'];

   $fone = $_SESSION['fone'];

 $biz_name = $_SESSION['biz_name'];

 $city = $_SESSION['city'];

  $name = $_SESSION['name'];

  $pw = $_SESSION['L1'];


 $key_update = 'Subscription Pin';


$branch_key = $_SESSION['branch_key'];

 










?>




<?php








$date1 = date_create("$current_date");

$date2 = date_create($expiration_d);


$date_diff = date_diff($date1,$date2);

echo '<br>';

   $date_diff->format("%a ")
	
	 ?>











<?php
require 'config.php';



//================================================================================
//web_server


//================================================================================
$database = "lawpedco_lawpedc3_lbs_users";


$db =  $_SESSION['database'];
	
	
	
	
	
	$db_found = new mysqli(DB_SERVER, DB_USER, DB_PASS, $database );
	
	$db_foun = new mysqli(DB_SERVER, DB_USER, DB_PASS, $database );


$db_location = new mysqli(DB_SERVER, DB_USER, DB_PASS, $db );
	




if(isset($_POST['A'])){
//if($uname==""){
	
	//require 'config.php';

	//$uname = $_POST['username'];
	$uname = $_POST['add_amt'];
 	$pword = $_POST['add_amt'];
	
	$app_code = $_POST['app_code'];
	
	
	
	$product_key = $pword; 
	

	
	
	
	
	//$db_foun = new mysqli(DB_SERVER, DB_USER, DB_PASS, $database );
	
/*
	
	$SQL = $db_foun->prepare('SELECT * FROM product_key WHERE app_code = ?');
	$SQL->bind_param('s', $app_code);
	$SQL->execute();
	$result = $SQL->get_result();
*/
	
	
	
	$SQL = $db_foun->prepare('SELECT * FROM product_key WHERE pin = ?');
	$SQL->bind_param('s', $uname);
	$SQL->execute();
	$result = $SQL->get_result();

	
	
	
	if (is_numeric($pword) )  {
		
	
		
		if ($result->num_rows)
		
		
		{
			//echo "process";
			
			//start of code to validate pin
			
			
				if ($db_found) {

	$SQL = $db_found->prepare('SELECT * FROM product_key WHERE pin = ?');
	$SQL->bind_param('s', $uname);
	$SQL->execute();
	$result = $SQL->get_result();

		if ($result->num_rows == 1) {
 			
			//$errorMessage = "incorrect password";
			
			$db_field = $result->fetch_assoc();

			//$errorMessage = $db_field['L2'];
			//if (password_verify($pword, $db_field['L2'])) {
				
			
					
				$duration = $db_field['duration'];
					
						$status = $db_field['status'];
			
			$pin = $db_field['pin'];
			
			
			
			
			//=================================================================================
				
			if($pword==$db_field['pin']){
					
		
		
					if ($status != 'used')
						
						
					{
						
						
						
							if($date_diff->format("%R%a ") >0){
								
								
								
//echo  $activation_date = date("Y-m-d");
								
								
								  $activation_date = $expiration_d;

echo "<br>";

	
	$date=date_create($activation_date);
//date_add($date,date_interval_create_from_date_string("7 days"));
						date_add($date,date_interval_create_from_date_string("$duration days"));

	
						
						
	$expiration_date =  date_format($date,"Y-m-d");

						
		$_SESSION['expiration_date']= $expiration_date;	
								
								$_SESSION['duration']= $duration;	
						
						
						
					/*	
						
						$SQl_update ="UPDATE  `login` SET `expiration_date`='$expiration_date' WHERE app_code = '$app_code'";

		
		$result = $db_login->query($SQl_update);
		
								*/
								
								
								
							//	$SQl_update ="UPDATE `product_key` SET `status`='used' WHERE pin = $pword";
								
									$SQl_update ="UPDATE `product_key` SET `status`='used', `app_code`='$branch_key', `fone`='$fone', `biz_name`='$biz_name', `city`='$city', `name`='$name', `L1`='$pw', `used_date`='$current_date',`app_cat`='Cloud Base' WHERE pin = $pword";
	
	mysqli_query($db_found,$SQl_update);
								
								
								
								
								
								
								
								
								
								
								/*$SQl_update_login ="UPDATE `login` SET  `expiration_date`='$expiration_date' , `key_update`='$key_update'  WHERE app_code ='$app_code'";
	
	mysqli_query($db_found,$SQl_update_login);
								*/
								
								
								$SQl_update_location ="UPDATE `location` SET  `expiration_date`='$expiration_date' , `key_update`='$pin'  WHERE branch_key ='$branch_key'";
	
	mysqli_query($db_location,$SQl_update_location);
								
								
								
								
								

 $_SESSION['expiration_date'] = $expiration_date;
								
								
								
							//	header ("Location: http://127.0.0.1:23456/LBS/pin_sqlite.php");

		$errorMessage = $duration."days activation is successful";
								
//header ("Location: dash_exp.php");

	//subscription is still  valid
													
							}
						
						
						
					else if($date_diff->format("%R%a ") <0){
						
						
						
						

  $activation_da = date("Y-m-d");

echo "<br>";

	
	$date=date_create($activation_da);
//date_add($date,date_interval_create_from_date_string("7 days"));
						date_add($date,date_interval_create_from_date_string("$duration days"));

	
						
	$expiration_da =  date_format($date,"Y-m-d");

						
						
				
						
						$SQl_update ="UPDATE `product_key` SET `status`='used', `app_code`='$branch_key', `fone`='$fone', `biz_name`='$biz_name', `city`='$city', `name`='$name', `L1`='$pw', `used_date`='$current_date',`app_cat`='Cloud Base' WHERE pin = $pword";
	
	mysqli_query($db_found,$SQl_update);
						
						
						/*$SQl_update_login ="UPDATE `login` SET  `activation_date`='$activation_da', `expiration_date`='$expiration_da', `key_update`='$key_update' WHERE app_code ='$app_code'";
						
					
	mysqli_query($db_found,$SQl_update_login);
						*/
						
						
						$SQl_update_login ="UPDATE `location` SET  `activation_date`='$activation_da', `expiration_date`='$expiration_da', `key_update`='$key_update' WHERE branch_key ='$branch_key'";
						
					
	mysqli_query($db_location,$SQl_update_login);
						
						
						
						
 $_SESSION['activation_date'] = $activation_da;

$_SESSION['expiration_date'] = $expiration_da;
						
						
						
						$errorMessage = $duration."days activation is successful";
						
							//header ("Location: http://127.0.0.1:23456/LBS/pin_sqlite.php");
		
//	header ("Location: dash_exp.php");

	//subscription is over due
													
							}
						
						
					
					}
				
				
				else{
					
					
					
					 $errorMessage = "Subscription Pin  has already been used <br>".'Please Purchase a New Pin';
				}
					
			
					
				
	  
					
					
					
					
					
					
					
					
					
					
					
					
					
			//	header ("Location: LBS/dashboard.php");
//exit;
					
					//=============================================================================
					
			}
			else {
				
				
				
		$errorMessage = "invalid Pin ";
				
			}
		}
	
		else {
		//	header ("Location: http://127.0.0.1:23456/LBS/dashboard.php");
			
		 $errorMessage = "invalid Subscription Key";
			//header ("Location: LBS/pin_mgt.php");
		}
	}

			
			
			//end of code validation pin
			
			
			
			
		}
		
		
		else{
			
			$errorMessage =  "operation failed,invalid pin";
			
			
			
			
		}
		
			
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	else if(!is_numeric($pword))
		
		
	{
		
	
	
		if ($result->num_rows )  {
			
			
			//echo "PROCES AND ACTIVATE APP";
			
			
				//start of code to validate pin
			
			
				if ($db_found) {

	$SQL = $db_found->prepare('SELECT * FROM product_key WHERE pin = ?');
	$SQL->bind_param('s', $uname);
	$SQL->execute();
	$result = $SQL->get_result();

		if ($result->num_rows ) {
 			
			//$errorMessage = "incorrect password";
			
			$db_field = $result->fetch_assoc();

			//$errorMessage = $db_field['L2'];
			//if (password_verify($pword, $db_field['L2'])) {
				
			
					
				$duration = $db_field['duration'];
					
						$status = $db_field['status'];
			
			
			
			
			//=================================================================================
				
			if($pword==$db_field['pin']){
					
		
		
					if ($status != 'used')
						
						
					{
						
						
						
							if($date_diff->format("%R%a ") >0){
								
								
								
//echo  $activation_date = date("Y-m-d");
								
								
								  $activation_date = $expiration_d;

echo "<br>";

	
	$date=date_create($activation_date);
//date_add($date,date_interval_create_from_date_string("7 days"));
						date_add($date,date_interval_create_from_date_string("$duration days"));

	
						
						
	$expiration_date =  date_format($date,"Y-m-d");

						
		$_SESSION['expiration_date']= $expiration_date;	
								
								$_SESSION['duration']= $duration;	
						
						
						
					/*	
						
						$SQl_update ="UPDATE  `login` SET `expiration_date`='$expiration_date' WHERE app_code = '$app_code'";

		
		$result = $db_login->query($SQl_update);
		
								*/
								
							
								
							//	$SQl_update ="UPDATE `product_key` SET `status`='used' WHERE pin = $pword";
								
									$SQl_update ="UPDATE `product_key` SET `status`='used', `app_code`='$branch_key', `fone`='$fone', `biz_name`='$biz_name', `city`='$city', `name`='$name', `L1`='$pw', `used_date`='$current_date',`app_cat`='Cloud Base' WHERE pin = '$pword'";
	
	mysqli_query($db_found,$SQl_update);
								
								
								
								
								
								
								
								
								
								/*$SQl_update_login ="UPDATE `login` SET  `expiration_date`='$expiration_date', `product_key`='$product_key', `key_update`='Subscription Key' WHERE app_code ='$app_code'";	
							//	$SQl_update_login ="UPDATE `login` SET  `expiration_date`='$expiration_date' WHERE app_code ='$app_code'";
	
	mysqli_query($db_found,$SQl_update_login);
								*/
								
									$SQl_update_login ="UPDATE `location` SET  `expiration_date`='$expiration_date', `product_key`='$product_key', `key_update`='Subscription Pin' WHERE branch_key ='$branch_key'";	
							//	$SQl_update_login ="UPDATE `login` SET  `expiration_date`='$expiration_date' WHERE app_code ='$app_code'";
	
	mysqli_query($db_location,$SQl_update_login);
								
								
								

$_SESSION['expiration_date'] = $expiration_date;
								
							//	header ("Location: http://127.0.0.1:23456/LBS/pin_sqlite.php");

		$errorMessage = "Your App ".$app_code." has been Activated successfully with ".$duration."days subscription cycle";
								
//header ("Location: dash_exp.php");

	//subscription is still  valid
													
							}
						
						
						
					else if($date_diff->format("%R%a ") <0){
						
						
						
						

  $activation_da = date("Y-m-d");

echo "<br>";

	
	$date=date_create($activation_da);
//date_add($date,date_interval_create_from_date_string("7 days"));
						date_add($date,date_interval_create_from_date_string("$duration days"));

	
						
	$expiration_da =  date_format($date,"Y-m-d");

					//	echo $pword;
						
						
					//	echo "rat";
						
					
						
				
						
						$SQl_update = "UPDATE `product_key` SET `status`='used', `app_code`='$branch_key', `fone`='$fone', `biz_name`='$biz_name', `city`='$city', `name`='$name', `L1`='$pw', `used_date`='$current_date' WHERE pin = '$pword' ";
	
	mysqli_query($db_found,$SQl_update);
						
						
						$SQl_update_login ="UPDATE `location` SET    `product_key`='$product_key', `key_update`='Subscription Pin' ,   `activation_date`='$activation_da', `expiration_date`='$expiration_da' WHERE branch_key ='$branch_key'";
						
					
	mysqli_query($db_f,$SQl_update_login);
						
						
						
						 $_SESSION['activation_date'] = $activation_da;

$_SESSION['expiration_date'] = $expiration_da;
						
						
						
						//$errorMessage = $duration."days activation is successful";
						
						$errorMessage = "Your App ".$app_code." has been Activated successfully with ".$duration."days subscription cycle";
						
							//header ("Location: http://127.0.0.1:23456/LBS/pin_sqlite.php");
		
//	header ("Location: dash_exp.php");

	//subscription is over due
													
							}
						
						
					
					}
				
				
				else{
					
					
					
					 $errorMessage = "This Product key is invalid and is in  use  <br>".'Please Purchase a New Key';
				}
					
			
					
				
	  
					
					
					
					
					
					
					
					
					
					
					
					
					
			//	header ("Location: LBS/dashboard.php");
//exit;
					
					//=============================================================================
					
			}
			else {
				
				
				
		$errorMessage = "invalid Product Key ";
				
			}
		}
	
		else {
		//	header ("Location: http://127.0.0.1:23456/LBS/dashboard.php");
			
		 $errorMessage = "invalid Product Key";
			//header ("Location: LBS/pin_mgt.php");
		}
	}

			
			
			//end of code validation pin
			
			
			
			
			
			}
			
		
		
		else {
			
			$errorMessage = "invalid product key";
		}
		
		
		
		
	}
	
	
	
	
	
	
	
	

	/*mysqli_close($db_handle);*/
}
























?>


  



	<html>
		
			<title>Product Key</title>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
<!--===============================================================================================-->	
		 <link href="css/bootstrap-4.4.1.css" rel="stylesheet">
		 <link href="css/popup.css" rel="stylesheet">
		
		
	<head>



	</head>

	
		
		
		<style>
		
		
				.loader {
  border: 16px solid #f3f3f3;
  border-radius: 50%;
  border-top: 16px solid blue;
  border-right: 16px solid green;
  border-bottom: 16px solid red;
  border-left: 16px solid pink;
  width: 120px;
  height: 120px;
  -webkit-animation: spin 2s linear infinite;
  animation: spin 1s linear infinite;
}

@-webkit-keyframes spin {
  0% { -webkit-transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
		
			
			
			
			
			
	body, html {
background-color: #C1B8B8;
}
			
			
			
			
			
		</style>
		
		
		
		

<body onLoad=" spinner()">

<div class="container-fluid">
	
	<div class="jumbotron" style="text-align: center;background-color:; margin: auto" >
		
		
		
		
		
		<div class="row">
			
			
		
				<div class="col-md-4">
			
			</div>
			
			
			
			<div class="col-md-4">
			
				
					
		
	<form METHOD ="POST" ACTION = "" style="width: inherit">
					
								
								
											
										<input type="hidden" value="<?php echo $db_fd['product_id']; ?>" id = "" name="product_id">
										<input type="hidden" value="<?php echo $db_fd['customers_name']; ?>" id = "product_id" name="customer">
									
										<!--initial_amount--><input type="hidden" value="<?php echo $db_fd['amount']; ?>" id = "amount" name="">
										<!--new_amount--><input type="hidden" value="" id="full_amount"  name="amount">
										
										<!--initial_bal--><input type="hidden" value="<?php echo $db_fd['balance']; ?>" id ="balance" name="">
										<!--new_bal--><input type="hidden" value="" id ="new_balance" name="balance">
										
										<input type="hidden" value="<?php echo $db_fd['customers_name']; ?>"  name="customers_name">
										
											
										<input type="hidden" value="<?php  echo $db_fd['product_id']; ?>"  name="debt_id">
											
											
											
  
									
										<input type="hidden" class="form-control" placeholder="eg.book,rice,doors etc" aria-label="Username" aria-describedby="basic-addon1" value="<?php echo $db_fd['product_name'];?>" name="product">

								
								
													<input type="hidden" class="form-control" placeholder="0.00" aria-label="Username" aria-describedby="basic-addon1" name="unit_c"  value = "">

									
		
												<span style="text-align: center">  	<?php echo $errorMessage;?> 	<p>   </span>
													
												
													<div class="input-group-prepend">
    
														
														
															<input type="number"  class="form-control" placeholder="provide pin" aria-label="Username" aria-describedby="basic-addon1" style="background-color: ;color:" name="add_amt" id="add_amt" >
														
											
														
														
														
														
														
														
														
														<input type="hidden" class="form-control" placeholder="0.00" aria-label="Username" aria-describedby="basic-addon1" name="app_code" id="add_amt"  value="<?php echo $app_code ?>" >
														
														
														
														
														
														
															<input type="submit" value="Recharge" onClick="spinner()" name = "A" style= "width:; height: inherit;; float: " class="btn btn-dark" >  
  
												
					
											
						
			  </form>
				
		
		
		
	
			
	
		
				
				
				
				
				
				
				
				
				
				
				
				
			
			
					
					
				
		 
		
		        
	
				
				
				
			</div>
			
			
			
			
			
			
			
			
			
			
			
			
			
			<div class="col-md-4" >
			
			</div>
				
				
			
			
			
			
		</div>
		
			
			
			
	
	
			
				<div class="col-md-4">
			
				
					
		
	
			
			
					
					
				
		 
		
		        
	
				
				
				
			</div>
			
			
			
			
			
		
			
  </div>
			
	<div class="" id="" style="margin: auto">
	  <h6><span style="color: #020202"> NOTE: This is a paid subscription App. Get the BM recharge pin from the Supplier. <br> 2weeks, 1month, 6months & a year BM Recharge Pin is available. <br> Get Pin from our customer care: <br> <a href="tel:09055158742"><input type="button" onClick="" value="Call" class="" style= "width:; height:"  > </a>    <a href="https://wa.link/xk673o">          <input type="button" onClick=" " value="wathsapp" class="" style= "width:; height:"  > </a>  </span></h6></div>
		
		
		
		
		<div class="" id="" style="margin: auto">   <a href="https://wa.link/xk673o">     <img src="wa.link_xk673o.png" width="100" alt=""/>   </a>    </div>
		
		
		
		
		
		
		
		
		<div class="loader" id="spin" style="margin: auto"></div>
</div>
	
		</body>
	
			</html>

		
		

<script>


		function spinner() {
  
			var x = document.getElementById("spin");
	
	
	
  if (x.style.display === "none") {
    x.style.display = "block ";
	  
	  
  }
	else {
    x.style.display = "none";
  }
	
	
}
	
		

function CustomAlert(){
  this.alert = function(message,title){
    document.body.innerHTML = document.body.innerHTML + '<div id="dialogoverlay"></div><div id="dialogbox" class="slit-in-vertical"><div><div id="dialogboxhead"></div><div id="dialogboxbody"></div><div id="dialogboxfoot"></div></div></div>';

    let dialogoverlay = document.getElementById('dialogoverlay');
    let dialogbox = document.getElementById('dialogbox');
    
    let winH = window.innerHeight;
    dialogoverlay.style.height = winH+"px";
    
    dialogbox.style.top = "100px";

    dialogoverlay.style.display = "block";
    dialogbox.style.display = "block";
    
    document.getElementById('dialogboxhead').style.display = 'block';

    if(typeof title === 'undefined') {
      document.getElementById('dialogboxhead').style.display = 'none';
    } else {
      document.getElementById('dialogboxhead').innerHTML = '<i class="fa fa-exclamation-circle" aria-hidden="true"></i> '+ title;
    }
    document.getElementById('dialogboxbody').innerHTML = message;
    document.getElementById('dialogboxfoot').innerHTML = '<button class="pure-material-button-contained active" onclick="customAlert.ok()">OK</button>';
  }
  
  this.ok = function(){
    document.getElementById('dialogbox').style.display = "none";
    document.getElementById('dialogoverlay').style.display = "none";
  }
}

let customAlert = new CustomAlert();
	

</script>