<?php /** * this file displays an invoice, as generated by the Online-Store * * PHP version 5 * * @category None * @package None * @author Kae Verens <*****@*****.**> * @license GPL 2.0 * @link None */ require_once $_SERVER['DOCUMENT_ROOT'] . '/ww.incs/basics.php'; require_once dirname(__FILE__) . '/../api.php'; if (!isset($_REQUEST['id'])) { Core_quit(); } $id = (int) $_REQUEST['id']; echo OnlineStore_invoiceGet($id);
/** * get a PDF version of the invoice * * @return null */ function OnlineStore_invoicePdf() { $id = (int) $_REQUEST['id']; $order = dbRow('select invoice, meta, user_id from online_store_orders where id=' . $id); $ok = false; if ($order) { if ($order['user_id'] == $_SESSION['userdata']['id']) { $ok = true; } $meta = json_decode($order['meta'], true); if (isset($_REQUEST['auth']) && isset($meta['auth-md5']) && $meta['auth-md5'] == $_REQUEST['auth']) { $ok = true; } } if (!$ok) { Core_quit(); } $inv = $order['invoice']; // { check if it's already stored as a PDF if (isset($meta['invoice-type']) && $meta['invoice-type'] == 'pdf') { $pdf = base64_decode($inv); header('Content-type: application/pdf'); echo $pdf; Core_quit(); } // } // { else generate a PDF and output it $pdfFile = USERBASE . '/ww.cache/online-store/invoice-pdf-' . $id; if (!file_exists($pdfFile)) { $html = OnlineStore_invoiceGet($id); require_once $_SERVER['DOCUMENT_ROOT'] . '/ww.incs/dompdf/dompdf_config.inc.php'; $dompdf = new DOMPDF(); $dompdf->set_base_path($_SERVER['DOCUMENT_ROOT']); $dompdf->load_html(utf8_decode(str_replace('€', '€', $html)), 'UTF-8'); $dompdf->set_paper('a4'); $dompdf->render(); file_put_contents($pdfFile, $dompdf->output()); } header('Content-type: application/pdf'); $fp = fopen($pdfFile, 'r'); fpassthru($fp); fclose($fp); Core_quit(); // } }