<?php
include '../admin/config.php';
$conn = new mysqli($HostName, $HostUser, $HostPass, $DatabaseName);
 
	$email = $_POST["email"];   
	$pass = $_POST["pass"];  
	$DateLast = $_POST["DateLast"]; // Ex: "2020-06-30 01:01";
	
	
	$response = array();
	$response["success"] = false ;
		
		if ( strtotime(date("Y-m-d H:i:s")) < strtotime("$DateLast + 15 Second" ) ){
		   $response["success"] = "خطأ" ; 
	       echo json_encode($response); 	
		   return ;
		}
		
		
    	$query = "SELECT energe FROM USERS WHERE email='$email' AND pass='$pass' ";
        $result = mysqli_query($conn,$query);
         if($row = mysqli_fetch_array($result)) {
             $energe = $row['energe'] ;
           }else{
			 $response["success"] = "البريد الالكتروني او كلمة المرور غير صحيحة" ; 
	         echo json_encode($response); 
	         return ;
		   }
		   
  
  
       $sql = "UPDATE USERS SET  log=CONCAT(log, 'Tadrib true \n'), energe=energe+1  WHERE email='$email' ";
       $response["success"] = $conn->query($sql);
	   $response["DateLast"] = date("Y-m-d H:i:s");


    $conn->close();
    echo json_encode($response);

?>
	 
	 
	 
