<?php
include '../admin/config.php';
$conn = new mysqli($HostName, $HostUser, $HostPass, $DatabaseName);
	
	
		$email = $_POST["email"];
	    $pass = $_POST["pass"];			 
        $date =  date("Y-m-d h:i") ;


	    $query = "SELECT id, point, log FROM USERS WHERE email='$email' AND pass='$pass' ";
        $result = mysqli_query($conn,$query);
           if($row = mysqli_fetch_array($result)) {
			    $id_user = $row['id'] ;
		         $point = $row['point'] ;
				  $log = $row['log'] ;
             }
			 

	    $query = "SELECT id_user FROM ARCHIVE WHERE email='$email' ";
        $result = mysqli_query($conn,$query);
           if($row = mysqli_fetch_array($result)) {
			   $sql = "UPDATE ARCHIVE SET point='$point' , log=CONCAT(log, '\n $log')  ,date='$date' WHERE email='$email' "; // إضافة النقاط والسجل للمستخدم
               $conn->query($sql);
			   
			   $sql = "UPDATE USERS SET log='Return $date' WHERE email='$email' "; // إضافة النقاط والسجل للمستخدم
               $response["success"] = $conn->query($sql);
             }else{
			   $sql = "INSERT INTO ARCHIVE (id_user, email, point, log, date ) VALUES('$id_user', '$email', '$point', '$log', '$date' )";
               $conn->query($sql);
			   
			   $sql = "UPDATE USERS SET log='Return $date \n' WHERE email='$email' "; // إضافة النقاط والسجل للمستخدم
               $response["success"] = $conn->query($sql);
			 }
			 	 
	
	
  $conn->close();  
  echo json_encode($response);
	
?>