<?php 

require __dir__ . '/init.php';

$_GET = help::sanitize($_GET, true);

$tx = $link->query( "
	SELECT * FROM tbl_transaction
	WHERE tx_no = '{$_GET['id']}'
" )->fetch_assoc();

if( !$tx ):
	template::$BLANK_PAGE = TRUE;
	template::get_header();
?>

	<div class='text-center mt-5'>
		<div class='row'>
			<div class='col-lg-7 m-auto'>
				<h2>Receipt Error</h2>
				<hr>
				<p>
					The receipt could not be downloaded <br/>
					There was an error printing the document
				</p>
			</div>
		</div>
	</div>
	
<?php 
	template::get_footer();

else: 

	require CLASS_DIR . '/TCPDF/tcpdf.php';
	
	// Create The HTML Content
	
	$HTML = "";
	
	foreach(['style.css', 'bootstrap-utilities.css'] as $cssfile) {
		$style = file_get_contents( TEMP_DIR . '/receipt/' . $cssfile );
		$HTML .= "<style>{$style}</style>\n";
	}
	
	$HTML .= "
		<style>
			@font-face {
				font-family: SourceSansPro;
				src: url('../config/template/receipt/SourceSansPro-Regular.ttf');
			}
		</style>
	";
	
	ob_start();
		REQUIRE_ONCE TEMP_DIR . '/receipt/index.php';
	$HTML .= ob_get_clean();
	
	$HTML = str_replace("\\", "\\\\", $HTML);
	
	$mpdf = new \Mpdf\Mpdf();
	$mpdf->WriteHTML($HTML);
	$mpdf->Output( "receipt-{$tx['tx_no']}.pdf", 'D' );

endif;
?>