<?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");

include_once '../config/database.php';
include_once '../objects/ont.php';
date_default_timezone_set('Asia/Rangoon');
session_start();
$database = new Database();
$db = $database->getConnection();
 
$ont = new ONT($db);
$data = json_decode(file_get_contents("php://input"));

// $ont->expire_date = $data->expire_date;   
$ont->id_no = $data->id_no;
$ont->customer_name = $data->customer_name;
$ont->city = $data->city;
$ont->status_ = $data->status_;
$stmt = $ont->search();
$num = $stmt->rowCount();

$arr=array();
$arr["records"]=array();

if($num>0){
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        extract($row);

        if($ss==0){
            $sts = "New";
        }else if($ss==1){
            $sts = "Active";
        }else if($ss==2){
            $sts = "Inactive";
        }else if($ss==3){
            $sts = "Terminate";
        }

        $detail=array( 
            "id" => $id,
            "id_no" => $id_no,
            "customer_name" => ($name)?$name:"",
            "package" => ($package)?$package:"",
            "ont_snno" => ($ont_snno)?$ont_snno:"",	
			"port" => ($port==null)?"":$port,	     
            "ont_id" => ($ont_id==null)?"":$ont_id,	
            "mme_id" => ($mme_id)?$mme_id:"",
            "pppoe_name" => ($pppoe_name)?$pppoe_name:"",
            "ont_password" => ($ont_password)?$ont_password:"",
            "sts" => $sts,
            "status" => $ss
            // "expire" => ($expire_date>=date("Y-m-d"))?0:1
        );  
        array_push($arr["records"], $detail);
    }
}
echo json_encode($arr);
?>