<?php
require_once(dirname(__FILE__).'/../../config.php');
$t	=	$prepare->sanitize($_GET['t'],'input');


if ( $t	==	'auth' ){
	$user_email		=	$prepare->sanitize($_POST['email'],'input');
	$up				=	$prepare->sanitize($_POST['password'],'input');
	$user_password	=	md5($up);

	$validateUser = $db->Query("select user_id,user_email from users where user_email=? and user_password=?","ss",$user_email,$user_password);


	if ( empty ( $validateUser ) ) {
		$revalidate	= $db->Query("select user_id from junk_users where user_email=? and user_password=?","ss",$user_email,$user_password);

		if ( empty ( $revalidate ) ) {
			echo '<div id="mode">2</div><div id="message">'. $LANG["WBS_LOGIN_ERROR"] .'</div>';
		} else {
			echo '<div id="mode">2</div><div id="message">'. $LANG["WBS_LOGIN_VALIDATE_ACC"] .'</div>';
		}
	} else {
		session_destroy();
		session_start();
		//** CREATE SESSION AND SEND THE REDIRECT COMM **//
		$_SESSION[USER_SESSION] = $validateUser;
			echo '<div id="mode">1</div>';

$GET_IP			=	$prepare->get_client_ip();
$geolocation      = ip2c_geolocation($GET_IP);


		$lt_user	=	$validateUser['0']['user_id'];
		$lt_ip		=	$GET_IP;
		$lt_country	=	$geolocation['countryName'];
		$lt_date	=	strtotime("now");

		$db->NoQuery("INSERT INTO login_tracking VALUES(NULL,?,?,?,?)","ssss",$lt_user,$lt_ip,$lt_country,$lt_date);


	}

}


if ( $t	==	'out' ){
	session_destroy();
	echo '<div id="mode">1</div>';
}




?>