You are here

function _invoice_get_html in Invoice 7

Same name and namespace in other branches
  1. 6 invoice_helpers.inc \_invoice_get_html()

Helper function to get the invoice in HTML format

Parameters

integer $invoice_number:

object $node:

string $type:

1 call to _invoice_get_html()
invoice_view_pdf in ./invoice.module
Display the invoice in PDF format

File

./invoice_helpers.inc, line 325
Invoice module

Code

function _invoice_get_html($invoice_number, $node = NULL, $type = 'print') {
  if (is_null($node)) {
    $nid = db_query("SELECT nid FROM {invoice_invoices} WHERE iid = :iid", array(
      ':iid' => $invoice_number,
    ))
      ->fetchField();
    $node = node_load($nid);
  }
  $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"' . ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . "\n";
  $html .= '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" dir="ltr">' . "\n";
  $html .= '<head>' . "\n";
  $html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . "\n";
  $protocol = _invoice_get_transfer_protocol() . '://';
  $stylesheetPath = drupal_get_path('module', 'invoice') . '/templates/' . $node->invoice['template'] . '.css';
  if ($type == 'pdf') {
    $html .= '<style type="text/css">';
    $html .= "\n" . file_get_contents(DRUPAL_ROOT . '/' . $stylesheetPath) . "\n";
    $html .= '</style>' . "\n";
  }
  else {
    $html .= '<link type="text/css" rel="stylesheet" media="all" href="' . $protocol . $_SERVER['HTTP_HOST'] . base_path() . $stylesheetPath . '" />' . "\n";
  }
  $html .= '</head><body class="' . $type . '">';
  $html .= theme('invoice_body', array(
    'node' => $node,
    'type' => $type,
  ));

  // The eurosign is not supported as applicable character, so replace it with a ascii code
  $html = str_replace('€', '&#0128;', $html);
  $html .= '</body></html>';
  return $html;
}