<?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/promotion.php';
date_default_timezone_set('Asia/Rangoon');

$database = new Database();
$db = $database->getConnection();
 
$promotion = new Promotion($db);
$data = json_decode(file_get_contents("php://input"));

$promotion->city = $data->city;
$promotion->date = $data->date;
$promotion->package = $data->package;
$promotion->months = $data->months;

$stmt = $promotion->getPromotion();
$num = $stmt->rowCount();

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

if($num>0){
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        extract($row);
        $detail = array(
            "id" => $id,
			"city" => $city,
            "package" => $package,
            "name" => $name,
            "period_from" => $period_from,
            "period_to" => $period_to,
            "bandwidth" => $bandwidth,
            "package_price" => number_format($package_price),
            "installation_fees" => number_format($installation_fees),
            "extra_days" => $extra_days,
            "gift" => str_replace('|', ' <br>', $gift)
            // "is_delete" => (date("Y-m-d")==$date)?1:0
        );
        array_push($arr["records"], $detail);
    }
}
echo json_encode($arr);
?>