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

$myJSON["ordetail"]=array();
$myJSON['date']="0";
$myJSON['tasvie']="0";
$myJSON['comment']="0";
$myJSON['success']="0";
if(isset($_POST["nekot"]) && isset($_POST["an1d"]))
{
	$id = $_POST["an1d"];
	
$myJSON['date']="1";
$myJSON['tasvie']="1";
$myJSON['comment']="1";
$myJSON['success']="1";
    $connect = @mysqli_connect($hostname,$username,$password,$database);
    if($connect)
    {
        @mysqli_query($connect,"SET CHARACTER SET utf8;");
		
			$query_all = "SELECT date,paytype,comment,price,off FROM  ".$tbl_orders." WHERE id = '".$id."'";
			$result = @mysqli_query($connect,$query_all);
			if($result){
				$count = 0;
				while($row = @mysqli_fetch_assoc($result))	{			
					$myJSON['date']=$row['date'];
					$myJSON['tasvie']=$row['paytype'];
					$myJSON['comment']=$row['comment'];
					$count ++;
				}
				if($count>0){
					$query_all = "SELECT ".$tbl_orderdtl.".id, ".$tbl_orderdtl.".count,".$tbl_orderdtl.".price,".$tbl_orderdtl.".total,".$tbl_orderdtl.".off,".$tbl_products.".P_name FROM  ".$tbl_orderdtl.",".$tbl_products." WHERE ".$tbl_orderdtl.".O_id = '".$id."' AND ".$tbl_orderdtl.".P_id =".$tbl_products.".id";
					$result = @mysqli_query($connect,$query_all);
					if($result)
					{
						while($rowdt = @mysqli_fetch_assoc($result))	{
						 array_push($myJSON["ordetail"],$rowdt);
						}
						$query_all = "UPDATE ".$tbl_orders." SET visited = '1' WHERE id = '".$id."'";
						$result = @mysqli_query($connect,$query_all);
						if($result)
							$myJSON['success']="200";
						else
							$myJSON['success']=@mysqli_error($connect);
					}
				}
			}
				else 
					$myJSON['success']=@mysqli_error($connect);
			 
				
			
		
		
	}
	 else
		 $myJSON['success']="402";
}
echo json_encode($myJSON);
?>