<?php
error_reporting(0);
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();
$utility	=	new utilityClass(); 
$task				= isset($_POST['action'])					? trim($_POST['action']) : "";
$mainid				= isset($_POST['mainid'])					? trim($_POST['mainid']) : ""; 
$reservedDate		= isset($_POST['bsm_reservation_date']) 	? trim(strip_tags($_POST['bsm_reservation_date'])) : ""; 
$orientationDate	= isset($_POST['bsm_orientation_date']) 	? trim(strip_tags($_POST['bsm_orientation_date'])) : ""; 
$conducted			= isset($_POST['bsm_conducted']) 			? trim(strip_tags($_POST['bsm_conducted'])) : "";  
$takeoutDate		= isset($_POST['bsm_pagibig_takeout_date']) ? trim(strip_tags($_POST['bsm_pagibig_takeout_date'])) : "";
$homeownerDate		= isset($_POST['bsm_homeowner_orientation']) ? trim(strip_tags($_POST['bsm_homeowner_orientation'])) : "";
$inspection			= isset($_POST['bsm_inspection']) 		? trim(strip_tags($_POST['bsm_inspection'])) : "";  
$reinspection		= isset($_POST['bsm_reinspection']) 	? trim(strip_tags($_POST['bsm_reinspection'])) : "";  
$letterSents			= isset($_POST['bsm_letter_sent']) 		? trim(strip_tags($_POST['bsm_letter_sent'])) : "";  
$houseAcceptance	= isset($_POST['bsm_house_acceptance']) ? trim(strip_tags($_POST['bsm_house_acceptance'])) : "";  
$permitToOccupy		= isset($_POST['bsm_permit_to_occupy']) ? trim(strip_tags($_POST['bsm_permit_to_occupy'])) : "";  
$permitToOccupyNumber	= isset($_POST['bsm_permit_to_occupy_number']) ? trim(strip_tags($_POST['bsm_permit_to_occupy_number'])) : "";  
$pto					= isset($_POST['bsm_pto']) ? trim(strip_tags($_POST['bsm_pto'])) : "";  

$currentUser 		= $_SESSION['danvillee_username'];
$timeStamp		= date('Y-m-d H:i:s');
$mainArr			= array();
$output 			= "";
$mainArr['BuyerOrientationDate'] 		= date('Y-m-d', strtotime($orientationDate));
$mainArr['Conducted'] 					= $conducted;
$mainArr['PagibigTakeOutDate'] 			= date('Y-m-d', strtotime($takeoutDate));
$mainArr['HomeownerOrientation'] 		= date('Y-m-d', strtotime($homeownerDate));
$mainArr['Inspection'] 					= date('Y-m-d', strtotime($inspection));
$mainArr['Reinspection'] 				= date('Y-m-d', strtotime($reinspection));
$mainArr['LetterSent'] 					= date('Y-m-d', strtotime($letterSents));
$mainArr['HouseAcceptance'] 			= date('Y-m-d', strtotime($houseAcceptance));
$mainArr['PermitToOccupy']	 			= date('Y-m-d', strtotime($permitToOccupy)); 
$mainArr['PermitToOccupyNumber']	 	= $permitToOccupyNumber;
$mainArr['PTOStatus']				 	= $pto;

$condArr = array();
if($task=="edit"):
	$mainArr['UpdatedDate'] 	= $timeStamp;
	$mainArr['UpdatedBy'] 		= $currentUser;
	$condArr['ReservationId']	= $mainid;
	$output 					= $mecon->updateQuery($mainArr,"buyer_status_monitoring",$condArr);
	
	
	//LOG TASK 
			$actArr['UserType']			= "assistant_accountant,accountant"; 
			$first_name 	= $utility->getFieldId("FirstName","Id",$mainid,"reservation");
			$last_name 		= $utility->getFieldId("LastName","Id",$mainid,"reservation");
			$middle_name 	= $utility->getFieldId("MiddleName","Id",$mainid,"reservation");
			$actArr['Remarks']			= "Updated Buyer Status Monitoring : [$mainid] - $last_name , $first_name $middle_name";
			$actArr['TransId']			= $mainid; 
			$actArr['Action']			= "edit";
			$actArr['ActionType']		= "buyer_status_monitoring";
			$actArr['ActionContent']	= json_encode($mainArr);
			$actArr['ActionBy'] 		= $currentUser;	
			$actArr['ActionDate']		= $timeStamp; 
			$utility->encodeActivityLog($actArr);
endif;

$resultArr 						= array();
$resultArr['output']	  		= $output;

echo json_encode($resultArr); 
exit();
ob_end_flush();