
<?PHP

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


<a href="logout.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>';



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

   $fone = $_SESSION['fone'];

 $biz_name = $_SESSION['biz_name'];

 $city = $_SESSION['city'];

  $name = $_SESSION['name'];

  $pw = $_SESSION['L1'];










?>




<?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


//================================================================================





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

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

	$database = "lawpedc3_lbs_users";
	
	
	
	
	
	
	
	
	
	
	
	
	$db_found = new mysqli(DB_SERVER, DB_USER, DB_PASS, $database );
	
	
	
	
	
	if (is_numeric($pword) )
	
	
	{
		
		echo "number";
		
		
	}
	
	
	else if(!is_numeric($pword))
		
		
	{
		
		echo "not number";
		
	}
	
	
	
	
	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' WHERE pin = $pword";
	
	mysqli_query($db_found,$SQl_update);
								
								
								
								
								
								
								
								
								
								
								$SQl_update_login ="UPDATE `login` SET  `expiration_date`='$expiration_date' WHERE app_code ='$app_code'";
	
	mysqli_query($db_found,$SQl_update_login);
								
								
								
								
								
								
							//	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`='$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);
						
						
						$SQl_update_login ="UPDATE `login` SET  `activation_date`='$activation_da', `expiration_date`='$expiration_da' WHERE app_code ='$app_code'";
						
					
	mysqli_query($db_found,$SQl_update_login);
						
						
						
						
						
						$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 = "Product key has already been used <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");
		}
	}

	/*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); }
}
		
		</style>
		
		
		
		

<body onLoad=" spinner()">


	
	<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" style="margin: auto">
				<table style="width: 100%">
				
					<span> <?php echo $errorMessage; ?></span>
					
					<form METHOD ="POST" ACTION = "" style="width: inherit">
					
						<tr>
						
							<td>
							<label style="font-size: 70px;color: #ECE3E3" id="label"></label>
							
							</td>
						
						</tr>
				
							<tr>
							
								<td>  
								
									<div class="input-group mb-3">
											
										<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">

									</div>
					
									
									<div class="input-group mb-3">
  
										<div class="input-group-prepend">
    
										
  
										</div>
  
								
													<input type="hidden" class="form-control" placeholder="0.00" aria-label="Username" aria-describedby="basic-addon1" name="unit_c"  value = "">

									</div>
										
											
										
									
									<table>
									
								
										
										<tr>
										
											<td>
											
												<div class="input-group mb-3" style="">
  
													<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" name="add_amt" id="add_amt" >
														
															<input type="submit" value="Enter" onClick="spinner()" name = "A" style= "width:; height: inherit;; float: " class="btn btn-dark" >  
  
													</div>
  

												

												</div>	
												
											</td>
											
										</tr>
										
									</table>
									
									
										
					
								</td>
								 
					
							</tr>
			
					
						<tr>
						<td>
							
					
							
						<!--	<input type="submit" value="Enter" onClick="spinner()" name = "A" style= "width:; height: inherit;; float: " class="btn btn-dark" >  -->
							
							</td>
						
						
						</tr>
			


			</table>
				 
					
											
						
					</form>
		
				
			</div>
			
			
				<div class="col-md-4">
			
			</div>
			
			
		</div>
		
	
	
		
			
			</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>