<?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);

//var_dump($data['refer_id']);

$_REQUEST['admin_user_id']   = $data['admin_user_id'];
$_REQUEST['admin_username']  = $data['admin_username'];

$validationErr = "";
$result = array();


if(!isset($_REQUEST['admin_user_id']) || $_REQUEST['admin_user_id']  == '') {
	$validationErr = "Please enter the the User ID!";
} 

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

else
{
	$userID = $_REQUEST['admin_user_id'];
	$userName= $_REQUEST['admin_username'];

	if(verifyMemberID($userID, $userName))
	{
		$data = getProfile($userID);
		if($data == null)
		{
			$result['success'] = true;
			$result['message'] = "Data Found!";
			$result['profile_data'] = 0;
		}


		else
		{
			$result['success'] = true;
			$result['message'] = "No Data found";
			$result['profile_data'] = $data;
		}

	}

	else
	{
		$result['success'] = false;
		$result['message']="Invalid Member ID!";

	}

}

if($validationErr != '') {

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

} 


	function verifyMemberID($userID, $userName)
	{
		$conn = new Database;
		$db = $conn->getConnection();
		$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    	$stmt = $db->prepare("select id from my_admin_users where id='$userID' and username='$userName'");
		$stmt->execute();
		$result = $stmt->fetch(PDO::FETCH_ASSOC);
		$db = null;

		if($result['id'] != NULL)
			return 1;

		else
			return 0;
		
	}


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

		$stmt = $db->prepare("select * from my_admin_users where id='$userID'");
		$stmt->execute();
		$result = $stmt->fetchAll(PDO::FETCH_ASSOC);

		$db = null;
		return $result;
	}

	

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


?>