<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<title>Software Activation</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	 <link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/renew/css/960.css" />
	<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/renew/css/reset.css" />
	<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/renew/css/blue.css" />
	
    <link type="text/css" href="<?php echo base_url();?>css/renew/css/smoothness/ui.css" rel="stylesheet" /> 
	
</head>

<body>

<style>

#page-wrap {
	width: 860px;
	background: white;
	padding: 20px 50px 20px 50px;
	margin: 0px auto;
	min-height: 400px;
	height: auto !important;
}

#contact-area {
	width: 500px;
	margin-top: 25px;
}

#contact-area input, #contact-area textarea {
	padding: 5px;
	width: 420px;
	font-family: Helvetica, sans-serif;
	font-size: 1.4em;
	margin-left: 15px;
	border: 2px solid #ccc;
}

#contact-area textarea {
	height: 90px;
}

#contact-area textarea:focus, #contact-area input:focus {
	border: 2px solid #900;
}

#contact-area input.submit-button {
	width: 100px;
}

td.left {
	width: 150px;
	text-align: left;
	font-size: 1.4em;
}

#catpcha-area {
	margin-left: 10px;
}
.error {color: #FF0000;}
</style>


<?php
require_once('recaptchalib.php');
$error_message="";
$done_registration=0;
// define variables and set to empty values
$user_nameErr = $product_keyErr= $secret_noErr=$captchaErr= "";
$user_name= $product_key = $secret_no = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {

	$is_error=0;

	if (empty($_POST["user_name"])) {
		$user_nameErr = "User Name is required";
		$is_error=1;
	} else {
		$name = test_input($_POST["user_name"]);
	}

	if (empty($_POST["product_key"])) {
		$product_keyErr = "Product Key is required";
		$is_error=1;
	} else {
		$product_key = test_input($_POST["product_key"]);
	}
	if (empty($_POST["secret_no"])) {
		$secret_noErr = "Secret No is required";
		$is_error=1;
	} else {
		$secret_no = test_input($_POST["secret_no"]);
	}
	/*
	$privatekey = "6LdmigAAAAAAAPTBvc0XBOdlKn5dPyTgazNvmHBx";
	$resp = recaptcha_check_answer ($privatekey,
	$_SERVER["REMOTE_ADDR"],
	$_POST["recaptcha_challenge_field"],
	$_POST["recaptcha_response_field"]);

	if (!$resp->is_valid) {
	$captchaErr="The reCAPTCHA wasn't entered correctly.";
	$is_error=1;
	}*/


	//////ERROR/////////

	if($is_error==0){

		$user_name=$_POST["user_name"];
		$product_key=$_POST["product_key"];
		$secret_no=$_POST["secret_no"];


		include('application/config/server_config.php');

		ob_start();
		system('ipconfig /all');
		$mycom=ob_get_contents();
		ob_clean();
		$findme = "Physical";
		$pmac = strpos($mycom, $findme);
		$mac=substr($mycom,($pmac+36),17);

		$data = array();
		$data['product_key'] = $_POST["product_key"];
		$data['user_name'] = $_POST["user_name"];
		$data['secret_no'] = $_POST["secret_no"];
		$data['mac'] = $mac;



		$dataFinal = json_encode($data);
		$client = new SoapClient(LIVE_SERVER_PATH.'/services/services.php?wsdl');
		$result = $client->__soapCall('keyRegistration', array('data' => $dataFinal));
		$pass_stringArray = json_decode($result);

		if(count($pass_stringArray)){
			$pass_string=$pass_stringArray->record_string;
			$expire_date=$pass_stringArray->expire;
		}
		if(trim($pass_string)){
			///File modify date controll////////

			$current_directory=getcwd();
			$target_file = $current_directory."\application\controllers\permission.php";
			$file_content =$pass_string;
			@unlink($target_file);
			if($savetofile = fopen($target_file, "w")) {
				fputs($savetofile, $file_content);
				fclose($savetofile);
			}
			touch($target_file,$expire_date);

			///////////////////////Time has been modified////////////////////////////
			$datetime_modified_error=0;
			$current_directory=getcwd();
			$filename = $current_directory.'\application\controllers\access.php';


			if (file_exists($filename)) {
				$file_creation_date=strtotime(date ("F d Y H:i:s.", filemtime($filename)));
				$curren_time=strtotime(date ("F d Y H:i:s."));
				if($curren_time<$file_creation_date){
					$datetime_modified_error=1;
				}else{
					$fhandle = fopen($filename,"w");
					fwrite($fhandle,"DONE");
					fclose($fhandle);
				}
			}
			$done_registration=1;
			$this->load->view("home");
		}else{
			$error_message="Your registration is not completed due to error of invalid registration info OR internet connection error.";
		}
	}

}
function test_input($data) {
	$data = trim($data);
	$data = stripslashes($data);
	$data = htmlspecialchars($data);
	return $data;
}
?>

<?php

if($done_registration!=1){

$request_url=$_SERVER['REQUEST_URI'];

$request_urlArray=explode("/",$request_url);

$countArray=count($request_urlArray);

$check_url="";

if($countArray>=4){
	$check_url=$request_urlArray[$countArray-2]."/".$request_urlArray[$countArray-1];
}else{
	$check_url="";
}
$image_path="";


if(trim($check_url)){
	$image_path="../";
}
?>

<div class="container_16" id="wrapper">	
  	<!--LOGO-->
	<div class="grid_8" id="logo">
		&nbsp;
	</div>
    <div class="grid_8">
<!-- USER TOOLS START -->
    </div>
<!-- USER TOOLS END -->    
<div class="grid_16" id="header">
<!-- MENU START -->
<div id="menu">
	<ul class="group" id="menu_group_main">
	
	 	<table>
		    	<tbody>
			    	<tr>
			    		<td>
			    			<img src="<?php echo $image_path;?>images/company_logo.png" width="88" height="100" alt="">
			    		</td>
			    		<td width="760px;">
			    			<h1 style="font-size:20px; text-align:right;">RN Healthcare Pharma POS V-<?php echo $this->config->item('application_version'); ?></h1></br>
			    			<h1 style="font-size:40px; text-align:left;"><?php echo $this->config->item('company'); ?></h1>
			    			
			    		</td>
			    		
			    		<td>
			    			<img src="<?php echo $image_path;?>images/login/wfbdlogo.png" alt="">
			    		</td>
			    		
			    	</tr>
		    	</tbody>
		 </table>
    </ul>
</div>
</div>
<div class="clear"> </div>





	<div id="page-wrap">
	    <p style="text-align:center; font-size:25px; font-weight:bold;">Software Activation</p>
	    <?php if(trim($error_message)){?>
	    <p style="text-align:center; font-size:14px; color:#FF0000;"><?php echo $error_message?></p>
	    <?php }?>
		<div id="contact-area">
		<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
				<table style="width:950px;">
					<tr>
						<td class="left"><label for="UserName">User Name:</label></td>
						<td><input type="text" name="user_name" value="<?php echo $user_name;?>"></td>
						<td><span class="error">* <?php echo $user_nameErr;?></span></td>
					</tr>
					<tr>
						<td class="left"><label for="ProductKey">Product Key:</label></td>
						<td><input type="text" name="product_key" value="<?php echo $product_key;?>"></td>
						<td><span class="error">* <?php echo $product_keyErr;?></span></td>
					</tr>
					
					<tr>
						<td class="left"><label for="SecretNo">Secret No:</label></td>
						<td><input type="text" name="secret_no" value="<?php echo $secret_no;?>"></td>
						<td><span class="error">* <?php echo $secret_noErr;?></span></td>
					</tr>
					<tr>
						<td colspan="3"align="center">
							<div id="captcha-area">
								<?php

								$publickey = "6LdmigAAAAAAAHJEZiIdo6bYZtwReBZavbXxGacx";
								$privatekey = "6LdmigAAAAAAAPTBvc0XBOdlKn5dPyTgazNvmHBx";

								# the response from reCAPTCHA
								$resp = null;
								# the error code from reCAPTCHA, if any
								$error = null;

								# are we submitting the page?
								if ($_POST["submit"]) {
									$resp = recaptcha_check_answer ($privatekey,
									$_SERVER["REMOTE_ADDR"],
									$_POST["recaptcha_challenge_field"],
									$_POST["recaptcha_response_field"]);

									if ($resp->is_valid) {
										echo "You got it!";
										# in a real application, you should send an email, create an account, etc
									} else {
										# set the error code so that we can display it. You could also use
										# die ("reCAPTCHA failed"), but using the error message is
										# more user friendly
										$error = $resp->error;
									}
								}
								echo recaptcha_get_html($publickey, $error);
								echo $captchaErr;
								?>
								
							</div>
						</td>
					</tr>
					<tr>
						<td colspan="3" align="center">
							&nbsp;
						</td>
					</tr>
					<tr>
						<td colspan="3" align="center">
							<input type="submit" name="submit" value="Submit" class="submit-button" />
						</td>
					</tr>
					<tr>
						<td colspan="3" align="center">
							&nbsp;
						</td>
					</tr>
				</table>
			</form>
		</div>
	</div>
	
	

<div id="content_area_wrapper">
<div id="content_area">
<?php $this->load->view("partial/footer"); ?><br>
<?php }?>
</body>
</html>