<?php
ob_clean();
$quotation_id = $_REQUEST["quotation_id"];
$instruction_to_proceed = $_REQUEST["instruction_to_proceed"];
$client_care_letter = $_REQUEST["client_care_letter"];
if(isset($instruction_to_proceed) && $instruction_to_proceed == 1){
	if(!file_exists("../../quotation_template/instruction_to_proceed_".$quotation_id.".pdf")){
		///////////////////// Curl to genrate member invoice ////////////////////////////
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$config->frontEndURL."/invoice/instruction_to_proceed.php");
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,"id=".base64_encode(base64_encode(base64_encode(base64_encode(base64_encode(base64_encode($quotation_id)))))));
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		$server_output = curl_exec ($ch);
		curl_close ($ch);
		////////////////////////////// End Curl /////////////////////////////////////////
	}

	$uploaddir = '../quotation_template/';			
	$document 	= "instruction_to_proceed_".$quotation_id.".pdf"; 
	$uploaded_file = $uploaddir . $document;
}else if(isset($client_care_letter) && $client_care_letter == 1){
	$job_id = $_REQUEST["job_id"];
	if(!file_exists("../../quotation_template/client_care_letter_".$quotation_id.".pdf")){
		///////////////////// Curl to genrate member invoice ////////////////////////////
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$config->frontEndURL."/invoice/client_care_letter.php");
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,"id=".base64_encode(base64_encode(base64_encode(base64_encode(base64_encode(base64_encode($job_id)))))));
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		$server_output = curl_exec ($ch);
		curl_close ($ch);
		////////////////////////////// End Curl /////////////////////////////////////////
	}

	$uploaddir = '../quotation_template/';			
	$document 	= "client_care_letter_".$job_id.".pdf"; 
	$uploaded_file = $uploaddir . $document;
}else{
	if(!file_exists("../../quotation_template/quotation_template_".$quotation_id.".pdf")){
		///////////////////// Curl to genrate member invoice ////////////////////////////
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$config->frontEndURL."/invoice/quotation_template.php");
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,"id=".base64_encode(base64_encode(base64_encode(base64_encode(base64_encode(base64_encode($quotation_id)))))));
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		$server_output = curl_exec ($ch);
		curl_close ($ch);
		////////////////////////////// End Curl /////////////////////////////////////////
	}

	$uploaddir = '../quotation_template/';			
	$document 	= "quotation_template_".$quotation_id.".pdf"; 
	$uploaded_file = $uploaddir . $document;
}
if (file_exists($uploaded_file)) {	
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.basename($uploaded_file).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($uploaded_file));
    readfile($uploaded_file);
    exit;
}
?>