<?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();  
$form		=	new formClass();
					
$paction		=	(isset($_POST['action'])) ? stripslashes($_POST['action']) : "";
$pdefault		=	(isset($_POST['default'])) ? stripslashes($_POST['default']) : "";
$pproject		=	(isset($_POST['project'])) ? str_replace("_"," ",stripslashes($_POST['project'])) : "";
$pmodel			=	(isset($_POST['model'])) ? str_replace("_"," ",stripslashes($_POST['model'])) : "";
$preservation_date		=	(isset($_POST['reservation_date'])) ? stripslashes($_POST['reservation_date']) : "";
					 
					$action = $paction;
					$placeholder = 'Pricelist Date';
					$default = $pdefault;
					$project = str_replace("_"," ",$pproject);
					$model = strtoupper($pmodel);
					$reserveDate = date('Y-m-d', strtotime($preservation_date));  
					$price = $form->generatePricelist($action,$placeholder,$default,$project,$model,$reserveDate); 
		 $actionTask = ($action=="view") ? "disabled" : "";
		$html = '<select name="pricelist_date" class="form-control select2" id="pricelist_date" '.$actionTask.'>';
			if(!empty($placeholder)){
			$html .= '<option value="-">'.$placeholder.'</option>';
			} 
		 if(!empty($price)){
			for($c=0; $c<count($price); $c++){
				$value = $price[$c]['PricelistDate'];
				if ($value == $default){
					$html .= '<option value='.$value.' selected="selected">'.$value.'</option>';
				} else {
					$html .= '<option value='.$value.'>'.$value.'</option>';
				}
			}
		 }
		$html .= '</select>';
		 
$main				= array();
$main['pricelist']	= $html; 

$resultArr 						= array();
$resultArr['output']	  		= $main;  
echo json_encode($resultArr);
 		 
		 
exit();
ob_end_flush();