<?php
require_once ("varables.php");

$myJSON['message'] = "0";
$myJSON['mmm'] = array();
if( isset($_POST["an1d"]) && isset($_POST["nekot"])&& isset($_POST["cid"])&& isset($_POST["date"]))
{
	$myJSON['message'] = "1";
    $date = $_POST["date"];
	$toke = $_POST["nekot"];
	$cid =  $_POST["cid"];
	$user_id = $_POST["an1d"];
	
    $connect = @mysqli_connect($hostname,$username,$password,$database);
    if($connect)
    {
        @mysqli_query($connect,"SET CHARACTER SET utf8;");
        $query_token = "SELECT id FROM ".$tbl_sessions." WHERE token = '".$toke."' AND uid ='".$user_id."' AND type ='V' LIMIT 1";
		$tokres=@mysqli_query($connect,$query_token);
        if (!$tokres) {
            $myJSON['message']= "400" ;
			
        }
		else{
			$countoft = 0;
            while($rowt = @mysqli_fetch_assoc($tokres)){
				array_push($myJSON['mmm'], $rowt);
                $countoft++;
			}
			if($countoft == 0){
				$myJSON['message']= "405" ;
			}
			else{
				$update_q = "UPDATE ".$tbl_customer." SET last_order = '".$date."' WHERE id ='".$cid."'";
				$upres=@mysqli_query($connect,$update_q);
				if(!$upres){
					$myJSON['message']= "404" ;
				}
				else
					$myJSON['message']= "200" ;
			}
		}
	}
	 else
		 $myJSON['message']="402";
}
    echo  json_encode($myJSON);

?>