<?php 
	$secret='6LcHKfMUAAAAAE1GFq_SLfcgsqkOk9ngMP-fWR0c';
	$response=$_POST['g-recaptcha-response'];
	$ip=$_SERVER["REMOTE_ADDR"];
	$url='https://www.google.com/recaptcha/api/siteverify';
	$finalresponse = file_get_contents($url.'?'.'secret='.$secret.'&response='.$response);
	$retorno=json_decode($finalresponse);
	 
     if($retorno->{'success'}){
	 	$nombre=_caracterborra($_POST['nombre']);
		$email= _caracterborra($_POST['email']);
		$clave= _caracterborra($_POST['clave']);
	 }
     else{ die( '{"error":"1","msg":"Capcha no valido"}');}

$error_num='0';
$error_msg='';
$sig_sql='select count(*) as sig_id from usrt0 where usrt_email="'.$email.'"';
$sig_res=$lynk_demo->query($sig_sql);
$sig_id=mysqli_result($sig_res,0,'sig_id');;

if($sig_id!=0){die( '{"error":"4","msg":"Email esta asociada a otra cuenta"}');}

$sig_sql='insert into usrt0 (
			usrt_descri,
			usrt_email,
			usrt_clave,
			usrt_idate)
			values(
			"'.$nombre.'",
			"'.$email.'",
			"'.$clave.'",
			now()
			)';
//echo $sig_sql;


if($lynk_demo->query($sig_sql)){
	
	$sig_sql='select max(usrt_codigo)as sig_id from usrt0 where 
	usrt_descri="'.$nombre.'" and
	usrt_email="'.$email.'"
	';
	$sig_res=$lynk_demo->query($sig_sql);
	$sig_id=mysqli_result($sig_res,0,'sig_id');;
	
	$error_msg='Registro Exitoso';
	$error_num='0';
	$mensaje='<a href="http://'.$empr_codigo.'vcrxol.com/carrito/activate.php?idx='.$sig_id.'" >Para terminar de registrarte en '.$empr_codigo.'.vcrxol.com da click</a> <br />
				o copia el siguiente enlace <br />
				http://'.$empr_codigo.'.vcrxol.com/carrito/activate.php?idx='.$sig_id.'
			';	
	$para=$email;
	$titulo=$empr_codigo.' Requiere tu confirmacion';
	//$headers='MIME-Version: 1.0' . "\r\n";
	//$headers.='Content-type: text/html; charset=utf-8' . "\r\n";
	//$headers.="From: Info <".$empr_email."> \r\n";
	//$headers_cc= 'Cc: ' .$cli_email . "\r\n";
	//$headers_r="Return-Path: Info {".$empr_email."};";  
	$headers_r='';
	if(!mail($para, $titulo,$mensaje, $headers.$headers_r)){$error_msg='Error de envio de correo';$error_num='2';}

}
else{$error_msg='Error de Registro '.$sig_sql;$error_num='3';}
echo '{"error":"'.$error_num.'","msg":"'.$error_msg.'"}';
$lynk_demo->close();
unset($sig_sql);
unset($error_num);
unset($error_msg);

?>