'NL', 'BE' => 'NL', 'US' => 'US', 'GB' => 'US', 'DE' => 'DE', 'FR' => 'FR', 'ES' => 'ES' ]; $invoice_language = 'US'; // Default if (!empty($invoice_data['customer']['language'])) { $invoice_language = strtoupper($invoice_data['customer']['language']); } elseif (!empty($invoice_data['customer']['country']) && isset($available_languages[strtoupper($invoice_data['customer']['country'])])) { $invoice_language = $available_languages[strtoupper($invoice_data['customer']['country'])]; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // Generate invoice HTML //+++++++++++++++++++++++++++++++++++++++++++++++++++++ list($message,$pdf, $customer_email, $order_id) = generateSoftwareInvoice($invoice_data, $order_number, $invoice_language); //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // Check for HTML output request //+++++++++++++++++++++++++++++++++++++++++++++++++++++ if (isset($_GET['output']) && $_GET['output'] === 'html') { // Output HTML directly to browser echo $message; exit; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // Initialize DomPDF //+++++++++++++++++++++++++++++++++++++++++++++++++++++ use Dompdf\Dompdf; use Dompdf\Options; $options = new Options(); $options->set('isRemoteEnabled', true); $dompdf = new Dompdf($options); // Load HTML content $dompdf->loadHtml($pdf); // Setup paper size and orientation $dompdf->setPaper('A4', 'portrait'); // Render the HTML as PDF $dompdf->render(); $file_name = 'Factuur - ' . $order_id; //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // Handle different actions //+++++++++++++++++++++++++++++++++++++++++++++++++++++ // Email invoice to customer if (isset($_POST['email_invoice'])) { $to = $customer_email; $subject = 'Factuur - ' . $order_id; $attachment = $dompdf->output(); $attachment_name = $file_name . '.pdf'; $header_redirect = 'Location: index.php?page=order&txn_id=' . $order_id . '&success=invoice_sent'; // Send to PHPMailer send_mail($to, $subject, $message, $attachment, $attachment_name); header($header_redirect); exit; } // Email invoice to admin/bookkeeping if (isset($_POST['email_invoice_to_admin'])) { $to = $customer_email; $subject = 'Factuur - ' . $order_id; $attachment = $dompdf->output(); $attachment_name = $file_name . '.pdf'; $header_redirect = 'Location: index.php?page=order&txn_id=' . $order_id . '&success=invoice_sent_admin'; // Send to bookkeeping if configured if (invoice_bookkeeping && email_bookkeeping) { send_mail(email_bookkeeping, $subject, $message, $attachment, $attachment_name); } header($header_redirect); exit; } // Show invoice in browser if (isset($_GET['show_invoice'])) { // Clean output buffer to prevent corrupted PDF if (ob_get_level()) { ob_end_clean(); } // Stream PDF to browser $dompdf->stream($file_name . ".pdf", array("Attachment" => false)); exit; } // If no action specified, redirect back header('Location: index.php?page=order&txn_id=' . $order_number); exit; ?>