<?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'] != ''):
	
	    		
		//$stmt = $conn->prepare("SELECT *  FROM `tbl_user` WHERE `email` = ? AND `password` = ?");
		$pass = md5($data['password']);
        //$stmt->bind_param('ss', $data['email'], $pass);
		//$stmt->execute();
		//$result = $stmt->get_result();
		$sql = "SELECT *  FROM `tbl_user` WHERE `email` = '" . $data['email'] . "' AND `password` = '" . $pass . "'";
		$result = $conn->query($sql);
				
		$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);
	
}
