<?php
include '../admin/config.php';
$conn = new mysqli($HostName, $HostUser, $HostPass, $DatabaseName);
 
	$email = $_POST["email"];   
	$pass = $_POST["pass"];   
	$nowDate = strtotime(date("Y-m-d H:i"));
	$Date = date("Y-m-d H:i");
	
	$response = array();
	$response["success"] = false ;

    	$query = "SELECT fullname, point, energe, code, postive, negative, lastlogin FROM USERS WHERE email='$email' AND pass='$pass' ";
        $result = mysqli_query($conn,$query);
         if($row = mysqli_fetch_array($result)) { 
	
	          $response["success"] = true ;
			  $response["fullname"] = $row['fullname'] ;
	          $response["point"] = $row['point'] ;
		      $response["postive"] = $row['postive'] ;
		      $response["negative"] = $row['negative'] ;
	          $energe  = $row['energe'] ;
			  $lastlogin =  $row['lastlogin'] ;
			  
			  $response["code"] = $row['code'] ;
			  $response["r_url"] = "http://igli92.com/?code=".$response["code"] ; // رابط موقع الإحالات
				
			  $response["v"] = 4 ; // version code android
			  $response["url_update"] = "https://play.google.com/store/apps/details?id=com.tooroq.qodorate" ; // تحديث التطبيق
			  
			  $response["join_url"] = "https://www.facebook.com/%D9%82%D8%AF%D8%B1%D8%A7%D8%AA-%D9%85%D8%A8%D8%AF%D8%B9-mobdi3-626162014690994" ;
			  
			  
	          $valuEnerg = $energe  ;
	          $DatePlus1 = strtotime("$lastlogin +1 Hour" );
	          $DatePlus2 = strtotime("$lastlogin +2 Hour" );
	          $DatePlus3 = strtotime("$lastlogin +3 Hour" );
	          $DatePlus4 = strtotime("$lastlogin +4 Hour" );
	          $DatePlus5 = strtotime("$lastlogin +5 Hour" );
	          
	          if($nowDate > $DatePlus1){
                     $energe = $energe + 1 ;
                      }
                 if($nowDate > $DatePlus2){
                     $energe = $energe + 1 ;
                      }
                 if($nowDate > $DatePlus3){
                     $energe = $energe + 1 ;
                      }
                 if($nowDate > $DatePlus4){
                     $energe = $energe + 1 ;
                      }
                 if($nowDate > $DatePlus5){
                     $energe = $energe + 1 ;
                      }
	          
	          $response["energe"] = $energe;
	          
	        }else{
	         $response["success"] = "البريد الالكتروني او كلمة المرور غير صحيحة" ; 
			}				


    if ($energe > $valuEnerg){
	     $sql = "UPDATE USERS SET  energe='$energe' , log=CONCAT(log, '$Date ubdate Unergy \n') , lastlogin='$Date' WHERE email='$email' "; // إضافة النقاط والسجل للمستخدم
         $response["success"] = $conn->query($sql);
       }


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

?>

