<?php

// Created by Ibrohimjon Ahmadjonov Ilhomjon o'g'li on 21.06.2022
header('Content-type: text/html; charset=UTF-8');
require "connect.php";


$umum_soni = 0;
$dos_id = $_POST['dos_id'];
$agent_id = $_POST['agent_id'];

$sql = "SELECT Id, kontr_id, kontr_nomi, kontr_tel, document, vaqti, holati, doc_id, lat, lang FROM zakazlar WHERE agent_id = '".$agent_id."' AND holati IN (0,1) ";

mysqli_set_charset($conn,"utf8");
$result = mysqli_query($conn,"SET NAMES utf8");

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

$count=1;

$list_zakaz = array();

if ($result !== false && $result->num_rows > 0) {
	while($row=mysqli_fetch_array($result)){

		$Id=$row['Id'];
		$kontr_id=$row['kontr_id'];
        $kontr_nomi=$row['kontr_nomi'];
        $kontr_tel=$row['kontr_tel'];
		$document=$row['document'];
		$vaqti=$row['vaqti'];
        $holati=$row['holati'];
		$doc_id=$row['doc_id'];
		$lat=$row['lat'];
		$lang=$row['lang'];

		// echo ''.$Id.'^'.$kontr_id.'^'.$document.'^'.$vaqti.'^'.$doc_id.'^'.$lat.'^'.$lang.'~';

         array_push($list_zakaz,
                array(
                        'Id' => $Id,
                        'kontr_id' => $kontr_id,
                        'kontr_nomi' => $kontr_nomi,
                        'kontr_tel' => $kontr_tel,
                        'document' => $document,
                        'vaqti' => $vaqti,
                        'holati' => $holati,
                        'doc_id' => $doc_id,
                        'lat' => $lat,
                        'lang' => $lang,
                     )
                  );

		$count++;

	}
 echo json_encode($list_zakaz);
  if($count > 1){
		$conn->close();
		return;
	}
}

if($count == 1){

	echo "no_c";
	$conn->close();
	return;
} else{

	$conn->close();
	return;
}

$conn->close();
?>
