



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


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






<?php


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

//$errorMessage = "";


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


			session_start();


/*

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>';

  $activation_d =  @ $_GET['activation_date'];



echo '<br>';





// $expiration_d = $_SESSION['expiration_date'];



  $expiration_d =  $_GET['expiration_date'];







echo '<br>';



 // $app_code = $_SESSION['app_code'];

$app_code =  @ $_GET['app_code'];


 // $fone = $_SESSION['fone'];
  $fone =  @ $_GET['fone'];

 //$biz_name = $_SESSION['biz_name'];
 $biz_name =@ $_GET['biz_name'];

 //$city = $_SESSION['city'];
  $city = @ $_GET['city'];

 // $name = $_SESSION['name'];
  $name = @ $_GET['name'];

 // $pw = $_SESSION['L1'];
  $pw = @ $_GET['L1'];



$key_update = @ $_GET['key_update'];

$product_key = @ $_GET['product_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 = "lawpedc3_lbs_users";
	$db_found = new mysqli(DB_SERVER, DB_USER, DB_PASS, $database );
	

$db_foun = new mysqli(DB_SERVER, DB_USER, DB_PASS, $database );



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'];

	
	
	
	
	
	
	$SQL = $db_foun->prepare('SELECT * FROM product_key WHERE app_code = ?');
	$SQL->bind_param('s', $app_code);
	$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'];
			
			
			
		//exit();
			
			
			//=================================================================================
				
			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`='$app_code', `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);
								
								
							//	header ("Location: http://127.0.0.1:23456/LBS/pin_sqlite.php?activation_date=$activation_date&expiration_date=$expiration_date&duration=$duration");
								
								
							//	header ("Location: https://heserver/LBS/pin_sqlite.php?activation_date=$activation_date&expiration_date=$expiration_date&duration=$duration");

								
								//	header ("Location: https://heserver/LBS/pin_sqlite.php?activation_date=$activation_date&expiration_date=$expiration_date&duration=$duration");

								
									header ("Location: https://heserver/LBS/pin_sqlite.php?activation_date=$activation_date&expiration_date=$expiration_date&duration=$duration&product_key=$product_key");


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

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

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

echo "<br>";

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

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

						
						//	$_SESSION['expiration_date']= $expiration_dat;	
						
						
						//	$_SESSION['duration']= $duration;	
						
						
						
						
					/*	
						
						$SQl_update ="UPDATE `login` SET `activation_date`='$activation_dat',`expiration_date`='$expiration_dat' 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 txn_table SET customers_name = '$c_name' WHERE 370";
	
	mysqli_query($db_found,$SQl_update);
						
						
						$errorMessage = $duration."days activation is successful";
						
						//	header ("Location: http://127.0.0.1:23456/LBS/pin_sqlite.php");
						
						
					//	header ("Location: http://127.0.0.1:23456/LBS/pin_sqlite.php?activation_date=$activation_dat&expiration_date=$expiration_dat&duration=$duration");
						
						header ("Location: https://heserver/LBS/pin_sqlite.php?activation_date=$activation_dat&expiration_date=$expiration_dat&duration=$duration&product_key=$product_key");
						
		
//	header ("Location: dash_exp.php");

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

	
			
			
			//end of code validation pin
			
			
			
			
		}
		
		
		else{
			
			$errorMessage =  "operation failed, You have not activate your app <br> please purchase a New product key from our Vendors";
			
			
				echo '<script>';
			
			echo 'window.alert( "'.$errorMessage.'")';
			
			echo '</script>';
			
		}
			
			
			
			
			
		}
	
	
	
	
	
	
	else if (!is_numeric($pword) ) {
			
			
	
		
		if ($result->num_rows ) 
		{
			
			$errorMessage =  "Your App ".$app_code." has already been activated. Buy a subscription key to continue using your App";
			
			
				echo '<script>';
			
			echo 'window.alert( "'.$errorMessage.'")';
			
			echo '</script>';
		}
		
	else{
		
		
				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'];
			
			
			
			
			//=================================================================================
				
			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`='$app_code', `fone`='$fone', `biz_name`='$biz_name', `city`='$city', `name`='$name', `L1`='$pw', `used_date`='$current_date',`app_cat`='standalone' WHERE pin = '$pword'";
	
	mysqli_query($db_found,$SQl_update);
								
								
								//header ("Location: http://127.0.0.1:23456/LBS/pin_sqlite.php?activation_date=$activation_date&expiration_date=$expiration_date&duration=$duration");

								
								header ("Location: https://heserver/LBS/pin_sqlite.php?activation_date=$activation_date&expiration_date=$expiration_date&duration=$duration&product_key=$pword");

	

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

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

echo "<br>";

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

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

						
						//	$_SESSION['expiration_date']= $expiration_dat;	
						
						
						//	$_SESSION['duration']= $duration;	
						
						
						
						
					/*	
						
						$SQl_update ="UPDATE `login` SET `activation_date`='$activation_dat',`expiration_date`='$expiration_dat' 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 txn_table SET customers_name = '$c_name' WHERE 370";
	
	mysqli_query($db_found,$SQl_update);
						
							$errorMessage = "Your App ".$app_code." has been Activated successfully with ".$duration."days subscription cycle";
					//	$errorMessage = $duration."days activation is successful";
						
						//	header ("Location: http://127.0.0.1:23456/LBS/pin_sqlite.php");
						
						
					//	header ("Location: http://127.0.0.1:23456/LBS/pin_sqlite.php?activation_date=$activation_dat&expiration_date=$expiration_dat&duration=$duration");
		
							header ("Location: https://heserver/LBS/pin_sqlite.php?activation_date=$activation_dat&expiration_date=$expiration_dat&duration=$duration&product_key=$pword");
						
						
//	header ("Location: dash_exp.php");

	//subscription is over due
													
							}
						
						
					
					}
				
				
				else{
					
					
					
				 $errorMessage = "Operation Failed:This Product key as been used <br>".'Please Purchase a New Key';
					
					
					
						echo '<script>';
			
			echo 'window.alert( "'.$errorMessage.'")';
			
			echo '</script>';
				}
					
			
					
				
	  
					
					
					
					
					
					
					
					
					
					
					
					
					
			//	header ("Location: LBS/dashboard.php");
//exit;
					
					//=============================================================================
					
			}
			else {
				
				
				
	echo	$errorMessage = "invalid Product Key ";
				
				
					echo '<script>';
			
			echo 'window.alert( "'.$errorMessage.'")';
			
			echo '</script>';
				
				
			}
		}
	
		else {
		//	header ("Location: http://127.0.0.1:23456/LBS/dashboard.php");
			
		  $errorMessage = "invalid Product Key";
			
			
			echo '<script>';
			
			echo 'window.alert( "'.$errorMessage.'")';
			
			echo '</script>';
			
			
			
			//header ("Location: LBS/pin_mgt.php");
		}
	}
		
		
		
		
		}
		
		
			
		}
	
	
	
	
	
	
	
	
	
	
	
}
	
	
	














?>


  



	<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>
		
				body, html {
background-color: #2A2A2B;
}
			
		
			
			
		
				.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); }
}
		
		</style>
		
		
		
		

<body onLoad=" spinner()">


	

	<div class="jumbotron" style="text-align: center;background-color:; margin: auto" >
		
		
					<div class="row">
		
						<div class="col-4"></div>
						<div class="col-4">
						
						<table style="margin: auto">
						
						<form METHOD ="POST" ACTION = "" style="width: inherit">							
										
												
												
													
												<span style="text-align: center;color: #F9F5F6;text-align: center">  	<?php echo $errorMessage;?> 	<p>   </span>
													
												
													<div class="input-group-prepend">
    
														
														<span class="input-group-text" id="basic-addon1" >   Key  </span>
														
						
														
														<input type="text" class="form-control" placeholder="0.00" aria-label="Username" aria-describedby="basic-addon1" style="background-color:#6D54F0;color: white" 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="Enter" onClick="spinner()" name = "A" style= "width:; height: inherit;; float: " class="btn btn-dark" >  
														
														
														
														</form>
						
														
														</table>
							
							
							
						
						</div>
							
							
							
							
							
							

						<div class="col-4"></div>
		
		
		
					</row>								
												
												
												
					
  
		
		
			
			</div>
			
	
		<div class="loader" id="spin" style="margin: auto"></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>