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

$myJSON['success']="0";
if(isset($_POST["nekot"]) && isset($_POST["an1d"]) &&isset($_POST["metod"]))
{
	$method = $_POST["metod"];
    $id =$_POST["an1d"];
    $connect = @mysqli_connect($hostname,$username,$password,$database);
    if($connect)
    {
        @mysqli_query($connect,"SET CHARACTER SET utf8;");
			if($method == 0){
				$myJSON['routdt'] = array();
				$query_all = "SELECT ".$tbl_customer.".address,".$tbl_customer.".C_id,".$tbl_customer.".C_Code,".$tbl_customer.".C_name,".$tbl_customer.".id,".$tbl_customer.".img,".$tbl_customer.".last_visit,".$tbl_customer.".phone,".$tbl_customer.".shop_name,".$tbl_customer.".lat,".$tbl_customer.".lng,".$tbl_routdtl.".rdtid,".$tbl_routdtl.".sort FROM ".$tbl_customer." , ".$tbl_routdtl." WHERE ".$tbl_routdtl.".R_id='".$id."' AND ".$tbl_customer.".id = ".$tbl_routdtl.".C_id ORDER BY ".$tbl_routdtl.".sort" ;
				$allres = @mysqli_query($connect,$query_all);
				if($allres){
				 while($row = @mysqli_fetch_assoc($allres))
					array_push($myJSON["routdt"], $row);
					$myJSON['success']="200";
				}
				else echo @mysqli_error($connect);
			}
			else{
				$myJSON['customer'] = array();

				$query_all = "SELECT * FROM ".$tbl_customer." WHERE routed = 0" ;
				$allres = @mysqli_query($connect,$query_all);
				if($allres){
				 while($row = @mysqli_fetch_assoc($allres))
						array_push($myJSON["customer"], $row);
				$myJSON['success']="200";
			}

				}
			}
				else echo @mysqli_error($connect);
			}

	 else
		 $myJSON['success']="402";

echo json_encode($myJSON);
?>
