<?php

header('Content-Type: application/json');
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(1);
ini_set("log_errors", 1);
ini_set("error_log", "php-error.log");

date_default_timezone_set('Asia/Kolkata');


require_once('database.php');

$data = json_decode(trim(file_get_contents("php://input")),true);

/*$data['memberID'] = $_REQUEST['memberID'];
$data['password'] = $_REQUEST['password'];*/

if(!isset($data['memberID']) || $data['memberID']  == '') {
	$validationErr = "Please enter the Member ID!";
} 

else if(!isset($data['password']) || $data['password']  == '') {
	$validationErr = "Please enter the password!";
} 


else
{


	$referID = $data['memberID'];
	$password = md5($data['password']);

	$conn = new Database;
	$db = $conn->getConnection();
	$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

	$stmt = $db->prepare("select * from my_registration where refer_id='$referID' and password = '$password'");
	$stmt->execute();
	$resultData = $stmt->fetch(PDO::FETCH_ASSOC);
	$db = null;
	$result = array();

	if($resultData['refer_id'] != NULL)
	{
		$result['success'] = true;
		$result['message'] = 'Login Successful!';
		$result['user_id'] = $resultData['id'];
		$result['refer_id'] = $resultData['refer_id'];
		$result['username'] = $resultData['name']. " ".$resultData['last_name'];
		$result['mobile_number'] = $resultData['mobile_number'];
		if($result['refer_id'] == "123123629" || $result['refer_id'] =="413302901")
		  $result['email_address'] = $resultData['email_address'];

		else
			$result['email_address'] = $resultData['refer_id'] . "@mybooster.biz";
	}


	else
	{
		$result['success'] = false;
		$result['message'] = 'Invalid Login Credentials!';
	}


	print $return = json_encode($result);
	exit;
}

if($validationErr != '') {

	$result = array();
	$result['success'] = false;
	$result['message'] = $validationErr;
	print $return = json_encode($result);
	exit;

} 


?> 
