<?php
	// required headers
	header("Access-Control-Allow-Origin: *");
	header("Content-Type: application/json; charset=UTF-8");
	header("Access-Control-Allow-Methods: POST");
	header("Access-Control-Max-Age: 3600");
	header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
	session_start();
	// include database and object files
	include_once '../config/database.php';
	include_once '../objects/ont.php';
	// include_once '../objects/sales.php';
	date_default_timezone_set('Asia/Rangoon'); 
	// instantiate database
	$database = new Database();
	$db = $database->getConnection();
	 
	$ont = new ONT($db);
	$data = json_decode(file_get_contents("php://input"));
	// $sales = new Sales($db);
	$ont->city = $data->city;
	$stmt = $ont->getAllRows();
	$num = $stmt->rowCount();
	$arr=array();
	$arr["records"]=array();
	// $arr["sales_no"]=array();
	if($num>0){


		while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
			extract($row);
			$item=array(
				"id" => (int)$id,
				"id_no" => ($id_no)?$id_no:"",
				"customer_name" => ($customer_name)?$customer_name:"",
				"ont_snno" => ($ont_snno)?$ont_snno:"",
				"mme_id" => ($mme_id)?$mme_id:"",
				"pppoe_name" =>($pppoe_name)?$pppoe_name:"",
				"ont_password" => ($ont_password)?$ont_password:"",
			);
			array_push($arr["records"], $item);
		}
	 

	}
	// array_push($arr["sales_no"], $sales->getGenerateSalesNo(date("ymd")));
	echo json_encode($arr);
?>