<?php
error_reporting(0); //7dec25
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start();
session_start();
session_cache_limiter('private');
$cache_limiter 	= session_cache_limiter();
session_cache_expire(60);
$cache_expire 	= session_cache_expire(); 
date_default_timezone_set('Asia/Manila'); 
$CURRENT_DATE 	= date('Y-m-d H:i:s');
include_once('../config/minho.php');
include_once('../config/autoloadClass.php');
$autoload	=	new autoloadClass();
$mecon		=	new condbClass();
$formClass	=	new formClass();
$main		=	array();
$main2		=	array();
$arr3		=	array();
$main3		=	array();
$main4		=	array();
$mainId		=	(isset($_POST['mainid'])) ? $_POST['mainid'] : "";
$mecon->query("SELECT r.Id as Id, CONCAT(r.LastName,', ',r.FirstName,' ',r.MiddleName) as FullName, r.EmployeeType as EmployeeType, r.Phase as Phase, r.Block as Block, r.Lot as Lot, m.MonitoringFolderDetails, m.BorrowerValidation, r.PricelistDate as PricelistDate, r.Model as Model, r.Project as Project, m.HouseConstruction as HouseConstruction FROM reservation r LEFT JOIN monitoring_folders m ON m.ReservationId=r.Id WHERE r.Status = :status AND r.Id = :id ORDER BY r.Id DESC");
$mecon->bind(':status', 'active');
$mecon->bind(':id', $mainId);
$main = $mecon->resultset(); 
$counter = count($main); 
$arr1 = array();
$arr2 = array();
$arr3 = array(); 
$userType	=	$_SESSION['danvilles_user_type'];
for($a=0; $a<$counter; $a++){ 
		
		$models		=	$main[$a]['Model']; 
		$project	=	$main[$a]['Project']; 
		$pricedate	=	$main[$a]['PricelistDate']; 
		$phase		=	$main[$a]['Phase']; 
		$block		=	$main[$a]['Block']; 
		$lot		=	$main[$a]['Lot']; 
		$other 		=	$formClass->getOtherDetails($pricedate,$models,$project,$phase,$block,$lot);		
		$lot_size	=	$other['lot_size'];
		$floor_area	=	$other['floor_area'];
		//$pricelist_status	=	(!empty($main[$a]['HouseConstruction'])) ?  trim(html_entity_decode(stripslashes($main[$a]['HouseConstruction']))) : $other['pricelist_status'];
		$pricelist_status	=	(!empty($main[$a]['HouseConstruction'])) ?  trim(html_entity_decode(stripslashes($main[$a]['HouseConstruction']))) : "";

		$arr1['id']					= $main[$a]['Id']; 
		$arr1['monitoring_folders'] = $main[$a]['MonitoringFolderDetails'];
		$arr1['block']				= trim(html_entity_decode(stripslashes($main[$a]['Block']))); 
		$arr1['lot']				= trim(html_entity_decode(stripslashes($main[$a]['Lot']))); 
		$arr1['full_name']			= trim(html_entity_decode(stripslashes($main[$a]['FullName']))); 
		$arr1['borrower_validation']	= (($main[$a]['BorrowerValidation']=='1970-01-01') || ($main[$a]['BorrowerValidation']=='')) ? "" : date('m/d/Y', strtotime($main[$a]['BorrowerValidation']));
		//date("m/d/Y", strtotime($main[$a]['BorrowerValidation'])); 
		$arr1['user_type']			= $userType; 
		
		$arr1['lot_size']				= $lot_size;
		$arr1['floor_area']				= $floor_area; 
		$arr1['pricelist_status']		= $pricelist_status; 
		$arr1['phase']					= $main[$a]['Phase']; 
		$arr1['block']					= $main[$a]['Block']; 
		$arr1['lot']					= $main[$a]['Lot']; 
	$arr2[] = $arr1;
}
$arr3['data'] = $arr2;
echo json_encode($arr3); 
exit();
ob_end_flush();