<?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(); 
//if(isset($_POST['checklist_submission_date'])){
$task					= isset($_POST['action'])						? trim($_POST['action']) : "";
$mainid					= isset($_POST['mainid'])						? trim($_POST['mainid']) : ""; 
$monitoringFolders		= isset($_POST['monitoring_folders']) 			? $_POST['monitoring_folders'] : "";
$borrowersValidation	= isset($_POST['borrowers_validation']) 		? $_POST['borrowers_validation'] : "";
$monitoring_pricelist_status	= isset($_POST['monitoring_pricelist_status']) 		? strip_tags($_POST['monitoring_pricelist_status']) : "";

$currentUser 	= $_SESSION['castalia_username'];
$timeStamp		= date('Y-m-d H:i:s');
//SAVING CHECKLIST DETAILS   
$mainArr	= array();
$output 	= "";



$mainArr['HouseConstruction']		= $monitoring_pricelist_status;
$mainArr['MonitoringFolderDetails']	= json_encode($monitoringFolders);
$mainArr['BorrowerValidation']		= date("Y-m-d", strtotime($borrowersValidation));
   
$condArr = array();
if($task=="edit"):
	$mainArr['UpdatedDate'] 	= $timeStamp;
	$mainArr['UpdatedBy'] 		= $currentUser;
	$condArr['ReservationId']	= $mainid;
	$output 					= $mecon->updateQuery($mainArr,"monitoring_folders",$condArr);
	
	
			$actArr['UserType']			= "documentation_staff,documentation_supervisor"; 
			$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 Monitoring of Folders to be Delivered : [$mainid] - $last_name , $first_name $middle_name";
			$actArr['Action']			= "edit";
			$actArr['ActionType']		= "monitoring_folders";
			$actArr['ActionContent']	= json_encode($mainArr);
			$actArr['ActionBy'] 		= $currentUser;	
			$actArr['ActionDate']		= $timeStamp;
			$actArr['TransId']			= $mainid;
			$utility->encodeActivityLog($actArr);	
if($_SESSION['castalia_user_type']=="documentation_staff"){
	if($monitoringFolders[0]=='req_completed' && $monitoringFolders[1]=='signed_loan_docs'){
			//LOG TASK 
			$actArr['UserType']			= "documentation_staff,documentation_supervisor"; 
			$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']			= "$last_name , $first_name $middle_name have req completed and signed loan docs";
			$actArr['Action']			= "edit";
			$actArr['ActionType']		= "monitoring_folders";
			$actArr['ActionContent']	= json_encode($mainArr);
			$actArr['ActionBy'] 		= $currentUser;	
			$actArr['ActionDate']		= $timeStamp;
			$actArr['TransId']			= $mainid;
			$utility->encodeActivityLog($actArr);	
	}  
}	
endif;

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

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