<?php
// Include DB file for credentials and database connection 

include("db.php");


// User Create Method
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
	
	$return = array('success' => false, 'message' => 'Silence is gold');
	
	$data = json_decode(file_get_contents('php://input'), true);


	if($data['email'] != '' && $data['password'] != ''):
	
	   
	   $pass = md5($data['password']);
	    
	   $query = "SELECT *  FROM `tbl_user` WHERE `email` = '".addslashes($data['email'])."' AND `password` = '".$pass."'"; 
	   
	   $result =  $conn->query($query);
	   
	 
	    /*		
		$stmt = $conn->prepare("SELECT *  FROM `tbl_user` WHERE `email` = ? AND `password` = ?");
		
        $stmt->bind_param('ss', $data['email'], $pass);
		
		$stmt->execute();
		
		
		
		//print_r($stmt); die("hello");
		
		$result = $stmt->get_result();
		
		*/
		
		
		$rows  = [];
		
		
		
		if($result->num_rows == 1){ 
		    
			$row = $result->fetch_assoc();
			
			
			switch($row['status']) {
				case '0':
					$return = array('success' => false, 'message' => 'Your account is not activated yet. Please contact administrator to activate your account.');
					break;
				case '2':
					$return = array('success' => false, 'message' => 'Your account has been deleted. Please contact administrator to restore account.');
					break;
				default:
					$return = array('success' => true, 'message' => 'Successfully Logged In!');
			} 			
			
			
			
		} else {
			$return = array('success' => false, 'message' => 'Snap! Log In Failed!');
		}			

	endif;
	echo json_encode($return);
	
}
