<?php

$secret = '6LfRrhUUAAAAAHsp1xXnji5FOnGh2Q_hjVL3p82d';
    $response = $_POST['g-recaptcha-response'];
    $remoteip = $_SERVER['REMOTE_ADDR'];

    $url = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=$response&remoteip=$remoteip");
    $result = json_decode($url, TRUE);
    if ($result['success'] == 1) {
include('../includes/con2pma3.php');
include ('../Email-pm/email.php');
$Fname =  $_POST['fname'];
$Lname =  $_POST['lname'];
$contactName = $Fname.' '.$Lname;
$Profession =$_POST['profession'];
$email =  $_POST['email1'];
$email2 =  $_POST['email2'];
$DateOfBirth =  $_POST['dob'];

$RegistrationType =  1000;

$PasswordHint =  $_POST['PasswordHint'];
$Password =  $_POST['ps1'];
$Password2 =  $_POST['ps2'];
$testWord =  md5(uniqid(rand()));
$userName =  $_POST['username'];

$desig = $_POST['desig'];
$webURL = $_POST['web'];
$phone = $_POST['phone'];
$mobile = $_POST['mobile'];
$fax = $_POST['fax'];
$street = $_POST['street'];
$city = $_POST['city'];
$Country = $_POST['Country'];
$companyname1 = $_POST['companyname1'];
$companyname2 = $_POST['companyname2'];
$curr = $_POST['curr'];

$savedate = date('Y-m-d');

//echo $email;

$date3MonthAdded = strtotime(date("Y-m-d", strtotime($savedate)) . "+3 month");
$expiryDate = date('Y-m-d', $date3MonthAdded);
$e = mysql_query("select * from login where emailAddressOne = '$email'");
if($_POST['EditId']){
	if(mysql_query("update login set user_mobile = '".$mobile."', user_phone = '".$phone."', emailAddressOne = '".$email."', emailAddressTwo = '".$email2."', profession = '".$Profession."', registrationType = '".$RegistrationType."', passwordHint = '".$PasswordHint."', password = '".$Password."' where  loginId = '".$_POST['EditId']."'")){
	if(mysql_query("update company set `website` = '".$webURL."', `abbreviation` = '$companyname1', `city` = '".$city."', `email` = '".$emailAddressOne."', `phone`= '".$phone."', `fax` = '".$fax."', `mobile` = '".$mobile."', `street` = '".$street."' where `serial` = '".$_POST['EditId']."'")){
	header("location: ../Interface/01-home/Register.php?Edit=".$_POST['EditId']."&msg=Record is updated successfully");
	}
	else{
		header("location: ../Interface/01-home/Register.php?Edit=".$_POST['EditId']."&msg=Record is not updated");
	}
	}
	else {
		header("location: ../Interface/01-home/Register.php?Edit=".$_POST['EditId']."&msg=Record is not updated");
	}
}
else if(mysql_num_rows($e)>=1)
{
	
	header("location: ../Interface/01-home/Register.php?msg=EMAIL ALREADY EXISTS. PLEASE TRY WITH ANY OTHER EMAIL ADDRESS.");
	
	}
	else
	{


if(mysql_query("insert into login set designation = '".$desig."', user_mobile = '".$mobile."', user_phone = '".$phone."', firstName = '".$Fname."', lastName = '".$Lname."', emailAddressOne = '".$email."', emailAddressTwo = '".$email2."', profession = '".$Profession."', registrationType = '".$RegistrationType."', birthdate = '".$DateOfBirth."', passwordHint = '".$PasswordHint."', UserName = '".$userName."', password = '".$Password."', testWord = '".$testWord."', registrationDate = '".$savedate."', status = '0', ExpiryDate = '".$expiryDate."'"))
{
		$cid = mysql_insert_id();
		
		
		mysql_query("insert into company set `serial` = '".$cid."',`website` = '".$webURL."',`currency` = '".$curr."',`city` = '".$city."',`Country` = '".$Country."',`contactName` = '".$contactName."', `email` = '".$emailAddressOne."', `phone`= '".$phone."', `fax` = '".$fax."', `mobile` = '".$mobile."', `creationDate` = '".$savedate."', `companyName` = '".$companyname2."', `street` = '".$street."', `abbreviation` ='".$companyname1."'");
		
	//$headers  = "MIME-Version: 1.0\r\n";
					//$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
					//$headers .= "From:<info@pmanywhere.co>\r\n";
					$to = $email;
					$subject .= "PManywhere - Email Confirmation";
					$message = "Dear New User ($userName), <br/>The registration process is complete. \n You can now login by clicking on the link or copy-paste the URL in your browser.
. <br/> <br/>  <a href='http://pm4.pmanywhere.co/DB/emailconfirmDB.php?cid=$cid&verify=$testWord'>Activate PManywhere Account</a> <br/> <br/> http://pm4.pmanywhere.co/DB/emailconfirmDB.php?cid=$cid&verify=$testWord <br/><br/>Thank you. <br/>
PManywhere Support Team.";
					
					if(sendEmail($to,"",$subject,$message))
					{
						header("location: ../Interface/index.php?msg=A message has been sent to the email address provided. Please check the spam folder also to verify before logging in.");
					}
					else
					{
						header("location: ../Interface/index.php?msg=EMAIL SENT ERROR. PLEASE RETRY.&m=no email send");
					}
}

else
{
	header("location: ../Interface/01-home/Register.php?msg=INVALIED ENTRY : USER NAME ALREADY EXIST");
}
	}
	}
	else
	echo "You are not human";
?> 