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

$myJSON["orders"]=array();
$myJSON['success']="0";
if(isset($_POST["nekot"]) && isset($_POST["an1d"])
	&& isset($_POST["from"]) && isset($_POST["to"])
	&& isset($_POST["yek"])&& isset($_POST["dow"])
	&& isset($_POST["se"])&& isset($_POST["chhar"]))
{
	$frm = ($_POST["from"]);
	$to = ($_POST["to"]);
	$yek = ($_POST["yek"]);
	$dow = ($_POST["dow"]);
	$se = ($_POST["se"]);
	$chhar = ($_POST["chhar"]);

    $connect = @mysqli_connect($hostname,$username,$password,$database);
    if($connect)
    {
		@mysqli_query($connect,"SET CHARACTER SET utf8;");
		$query_all = "SELECT tbl_orderstate.ordstate,".$tbl_orders.".id,".$tbl_orders.".C_id,".$tbl_orders.".orderLat,".$tbl_orders.".orderLng,".$tbl_orders.".V_id,".$tbl_orders.".endprice,".$tbl_orders.".emergency,".$tbl_orders.".localed,".$tbl_orders.".visited,".$tbl_customer.".C_name,".$tbl_customer.".lat,".$tbl_customer.".lng,".$tbl_customer.".address,".$tbl_customer.".phone,".$tbl_customer.".C_mobile,".$tbl_customer.".shop_name,".$tbl_visitors.".V_name,".$tbl_orders.".date FROM tbl_orderstate, ".$tbl_visitors.", ".$tbl_orders.", ".$tbl_customer." WHERE ".$tbl_orders.".C_id = ".$tbl_customer.".id AND ".$tbl_orders.".V_id = ".$tbl_visitors.".id AND ".$tbl_orders.".localed = tbl_orderstate.id AND "/*STRCMP(".$tbl_orders.".date ,".$from.") > 0 AND STRCMP(".$tbl_orders.".date ,".$to.") < 0 AND*/."(".$tbl_orders.".localed = ".$yek." OR ".$tbl_orders.".localed = ".$dow." OR ".$tbl_orders.".localed = ".$se." OR ".$tbl_orders.".localed = ".$chhar.") ORDER BY ".$tbl_orders.".localed,".$tbl_orders.".visited,".$tbl_orders.".emergency,".$tbl_orders.".emergency,".$tbl_orders.".date DESC";
		$result = @mysqli_query($connect,$query_all);
		if($result){
			while($row = @mysqli_fetch_assoc($result))	{
				array_push($myJSON["orders"], $row);
			}
			$myJSON['success']="200";
			if($yek == 0){
				$qordeers = "DELETE FROM tbl_notifications WHERE type = 'A' AND message ='SEFARESH'";
				@mysqli_query($connect,$qordeers);
			}
		}
			else {
				$myJSON['success']=@mysqli_error($connect);
			}
	}
	 else
		 $myJSON['success']="402";
}
echo json_encode($myJSON);
?>
