<?php
require_once(dirname(__FILE__).'/../../config.php');

$t	=	$prepare->sanitize($_GET['t'],'input');

if ( $t	==	'new' ){
	//** users **//
	$user_email		=	$prepare->sanitize($_POST['email'],'input');
	$u_password		=	$prepare->sanitize($_POST['password'],'input');
	$user_password	=	md5($u_password);
	$user_status	=	md5($user_password.strtotime("now").rand().rand());

		$validate 			= $db->Query("SELECT `user_email` FROM users where user_email=?","s",$user_email);
		$validatePending 	= $db->Query("SELECT `user_email` FROM junk_users where user_email=?","s",$user_email);


	if ( empty ( $validate ) && empty ( $validatePending ) ) {
		$insert = $db->NoQuery("INSERT INTO junk_users VALUES(NULL,?,?,?)","sss",$user_email,$user_password,$user_status);
		if ( $insert ) {
			$user_id	=	$db->LastID();
		
			//** users_address **//
			$ua_user_id		=	$user_id;
			$ua_country		=	$prepare->sanitize($_POST['location'],'input');
			$ua_state		=	'';
			$ua_city		=	'';
			$ua_zip			=	'';
			$ua_address		=	'';
			$db->NoQuery("INSERT INTO junk_users_address VALUES(?,?,?,?,?,?)","isssss",$ua_user_id,$ua_country,$ua_state,$ua_city,$ua_zip,$ua_address);
		
			//** users_profiles **//
			$up_user_id		=	$user_id;
			$up_first_name	=	$prepare->sanitize($_POST['fname'],'input');
			$up_last_name	=	$prepare->sanitize($_POST['lname'],'input');
			
			$month			=	$prepare->sanitize($_POST['month'],'input');
			$day			=	$prepare->sanitize($_POST['day'],'input');
			$year			=	$prepare->sanitize($_POST['year'],'input');
			
			$up_birthday	=	strtotime(date('Y-m-d', strtotime($year.'-'.$month.'-'.$day)));
			$up_phone		=	'';
			$up_tax_id		=	'';

			$db->NoQuery("INSERT INTO junk_users_profiles VALUES(?,?,?,?,?,?)","ssssss",$up_user_id,$up_first_name,$up_last_name,$up_birthday,$up_phone,$up_tax_id);

	/********************* start submiting email *********************/
$details =$LANG["WBS_REGM_1"]."

".$LANG["WBS_REGM_2"]."

".$LANG["WBS_REGM_3"]." ".HTTP_MASTER."activation/".$user_status."

".$LANG["WBS_REGM_4"]."

".$LANG["WBS_REGM_5"]."

".$LANG["WBS_REGM_7"]."
".$LANG["WBS_REGM_8"];

	$fromEmail = NO_REPLY;
	$headers = "MIME-Version: 1.0" . "\r\n";
	$headers .= "Content-Type: text/plain; charset=utf-8" . "\r\n";
	$headers .= "From: ".$fromEmail. "\r\n";
	$subject = $LANG["WBS_REGM_SUBJECT"];
	mail($user_email,$subject,$details,$headers);
	/********************* end submiting email *********************/

	echo '<div id="mode">1</div>';


		} else {
				echo '<div id="mode">2</div>';
		}
	} else {
				echo '<div id="mode">3</div>';
	}


}



if ( $t	== 'new-code' ) {
	$email	=	$prepare->sanitize($_POST['email'],'input');
	
	$validate = $db->Query("select user_status from junk_users where user_email=?","s",$email);
	
	if ( empty ( $validate ) ) {

		echo '<div id="mode">2</div><div id="message">'.$LANG["WBS_REQ_DOESNT_EXIST"].'</div>';
	} else {
	

	/********************* start submiting email *********************/
$details =$LANG["WBS_REQ_1"]."

".$LANG["WBS_REQ_3"]." ".HTTP_MASTER."activation/".$validate['0']['user_status']."

".$LANG["WBS_REQ_4"]."

".$LANG["WBS_REQ_5"]."

".$LANG["WBS_REQ_7"]."
".$LANG["WBS_REQ_8"];

	$fromEmail = NO_REPLY;
	$headers = "MIME-Version: 1.0" . "\r\n";
	$headers .= "Content-Type: text/plain; charset=utf-8" . "\r\n";
	$headers .= "From: ".$fromEmail. "\r\n";
	$subject = $LANG["WBS_REQ_SUBJECT"];
	mail($email,$subject,$details,$headers);
	/********************* end submiting email *********************/


		echo '<div id="mode">1</div><div id="message">'.$LANG["WBS_REQ_EMAIL_SENT"].'</div>';
	}
}



if ( $t	== 'new-password' ) {
	$email	=	$prepare->sanitize($_POST['email'],'input');
	$newPw	=	$prepare->create_password();
	$md5Pw	=	md5($newPw);
	$validate = $db->Query("select user_email from users where user_email=?","s",$email);
	
	if ( empty ( $validate ) ) {

		echo '<div id="mode">2</div><div id="message">'.$LANG["WBS_REQP_DOESNT_EXIST"].'</div>';
	} else {
	

	/********************* start submiting email *********************/
$details =$LANG["WBS_REQP_1"]."

".$LANG["WBS_REQP_3"]." ".$newPw."

".$LANG["WBS_REQP_4"]."

".$LANG["WBS_REQP_5"]."

".$LANG["WBS_REQP_7"]."
".$LANG["WBS_REQP_8"];

	$fromEmail = NO_REPLY;
	$headers = "MIME-Version: 1.0" . "\r\n";
	$headers .= "Content-Type: text/plain; charset=utf-8" . "\r\n";
	$headers .= "From: ".$fromEmail. "\r\n";
	$subject = $LANG["WBS_REQP_SUBJECT"];
	mail($email,$subject,$details,$headers);
	/********************* end submiting email *********************/
	$db->NoQuery("UPDATE users SET user_password=? WHERE user_email=?","ss",$md5Pw,$email);

		echo '<div id="mode">1</div><div id="message">'.$LANG["WBS_REQP_EMAIL_SENT"].'</div>';
	}
}













?>