<?php 
	include '../config.inc.php';
	
	//$sql = "SELECT * FROM tblCafea;";

    $telefon = $_GET['telefon'];
    $ver = $_GET['ver'];
    //echo $telefon;

//    $sqlCount = "SELECT COUNT(ID) FROM `tblComenzi`WHERE Telefon = '+40755750931';";
    $sqlCount = "SELECT COUNT(ID) FROM `tblComenzi`WHERE Telefon = '".$telefon."';";
    $resultCount = mysqli_query($conn,$sqlCount);
    $rowCount = mysqli_fetch_array($resultCount);

//    echo $rowCount[0];

    if ($ver < $rowCount[0]) {
        //echo "NEED TO GET SQL";


	$sql = "
	SELECT
	c.ID,
	ca.denumire,
	c.DataAdd,
	c.OraAdd,
	c.Variatie,
	c.LapteSoya,
	c.ExtraShot,
	c.NivelLapte,
	c.NivelSpuma,
	c.Total
	 FROM tblComenzi c LEFT JOIN tblCafea ca ON ca.ID = c.IDCafea WHERE c.Telefon = '".$telefon."' ORDER BY c.ID ASC;
	";

//	echo $sql;

$result = mysqli_query($conn,$sql);
	
$response = array();


while ($row = mysqli_fetch_array($result))
	{
		array_push($response, array("ID"=>$row[0],
            "Denumire"=>$row[1],
            "Variatie"=>$row[4],
            "DataAdd"=>$row[2],
            "OraAdd"=>$row[3],
            "LapteSoya"=>$row[5],
            "ExtraShot"=>$row[6],
            "NivelLapte"=>$row[7],
            "NivelSpuma"=>$row[8],
            "Total"=>$row[9]));
	}

/*
    echo "<pre>";
	echo json_encode(array("server_response"=>$response), JSON_PRETTY_PRINT);
    echo "</pre>";*/

echo json_encode(array("server_response"=>$response));

	//echo json_encode($response);

    } else {

        $response = array();
        $response.array_push($response,array("ID"=>"same"));
        echo json_encode(array("server_response"=>$response));
    }
	mysqli_close($conn);

?>