<?

include("include/startup.php");


$id = utility::app_crypt($_REQUEST['po_id'], 'd');

$pdf_name = $_REQUEST['pdf_name'];
$pdf_name = $pdf_name.'-'.$id.'.pdf';


$frontEndURL = $config->frontEndURL;

$url = $frontEndURL."/admin/purchase_order/index?page=view_purchase_order_pdf&po_id=$id&hide_top=1&hide_left=1&create_pdf=1";
			
			
if(isset($_REQUEST['print_url'])){
	
	echo "<a target='_blank' href='$url'>$url</a>";
	die;
}
unlink("".ROOT_DIR_PATH."'purchase_order_pdfs/".$pdf_name);
$file_path = ROOT_DIR_PATH."/purchase_order_pdfs/".$pdf_name;
exec("/usr/local/bin/wkhtmltopdf '$url' '$file_path'");
sleep(1);

if(file_exists(ROOT_DIR_PATH."/purchase_order_pdfs/$pdf_name")){	
	ob_clean();
	header("Location: $frontEndURL"."purchase_order_pdfs/$pdf_name");
	exit;
}

?>