You are here

function certificate_preview in Certificate 6

Same name and namespace in other branches
  1. 8.3 certificate.pages.inc \certificate_preview()
  2. 6.2 certificate.pages.inc \certificate_preview()
  3. 7.3 certificate.pages.inc \certificate_preview()
  4. 7.2 certificate.pages.inc \certificate_preview()
  5. 3.x certificate.pages.inc \certificate_preview()

Preview certificate.

@todo This code is copied from above, needs to be refactored to avoid copypasta.

1 string reference to 'certificate_preview'
certificate_menu in ./certificate.module
Implementation of hook_menu().

File

./certificate.pages.inc, line 248
Builds the module's user-facing pages.

Code

function certificate_preview($template_id) {
  $template = node_load($template_id);
  if ($template) {
    $output = theme('certificate_certificate', $account, $profile, $node, $group, $template);
  }
  $print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', '');
  if ($print_pdf_pdf_tool == '') {
    if ($user->uid == 1) {
      drupal_set_message('Certificate cannot be displayed because you have not selected a PDF generation tool in ' . l('Printer, e-mail and PDF versions', 'admin/settings/print/pdf') . '.', 'error');
    }
    else {
      drupal_set_message('PDF generation tool is not configured.');
    }
    return '';
  }
  module_load_include('pages.inc', 'print_pdf', 'print_pdf');

  // Rewrite image URLs using Print.
  $pattern = '!<(img\\s[^>]*?)>!is';
  $output = preg_replace_callback($pattern, '_print_rewrite_urls', $output);
  global $conf;
  $conf['print_pdf_page_orientation'] = $template->certificate['orientation'];
  if (basename($print_pdf_pdf_tool) == 'dompdf_config.inc.php') {
    $print_func = '_print_pdf_dompdf';
  }
  elseif (basename($print_pdf_pdf_tool) == 'tcpdf.php') {
    $print_func = '_print_pdf_tcpdf';
  }
  elseif (substr(basename($print_pdf_pdf_tool, '.exe'), 0, 11) == 'wkhtmltopdf') {
    $print_func = '_print_pdf_wkhtmltopdf';
  }
  $print_func(array(
    'node' => $template,
  ), $output, $template->title . '.pdf');
}