function preDisplay() { parent::preDisplay(); $tour = new Tour(); $html = file_get_contents("custom/modules/Tours/tpls/basic_pdf.tpl"); $html = str_replace("{NAME}", $this->bean->name, $html); $desc = html_entity_decode_utf8($this->bean->description); $desc = $tour->removeHtmlTags($desc); $html = str_replace("{TOUR_NOTE}", $desc, $html); $picture = '<img width="627" height="312" src="modules/images/' . $this->bean->picture . '">'; $html = str_replace("{PICTURE}", $picture, $html); $html = str_replace("{CODE}", $this->bean->tour_code, $html); $html = str_replace("{DURATION}", $this->bean->duration, $html); $html = str_replace("{TRANSPORT}", $this->bean->transport2, $html); $html = str_replace("{START_DATE}", $this->bean->start_date, $html); $program = html_entity_decode_utf8($tour->get_data_to_export2pdf($_GET['record'])); $html = str_replace("{TOUR_PROGRAM_LINES}", $program, $html); // Xuat ra pdf $mpdf = new mPDF("vi"); $mpdf->SetFooter('{PAGENO}'); $mpdf->WriteHTML($html); $mpdf->Output("Tour.pdf", "D"); exit; }
public function preDisplay() { parent::preDisplay(); // settings for disable smarty php tags $this->ss->security_settings['PHP_TAGS'] = false; $this->ss->security = true; if (defined('SUGAR_SHADOW_PATH')) { $this->ss->secure_dir[] = SUGAR_SHADOW_PATH; } // header/footer settings $this->setPrintHeader(false); $this->setPrintFooter(true); // always print page number at least if (!empty($_REQUEST['pdf_template_id'])) { $pdfTemplate = BeanFactory::newBean('PdfManager'); if ($pdfTemplate->retrieve($_REQUEST['pdf_template_id'], false) !== null) { $previewMode = FALSE; if (!empty($_REQUEST['pdf_preview']) && $_REQUEST['pdf_preview'] == 1) { $previewMode = true; $this->bean = BeanFactory::newBean($pdfTemplate->base_module); } $this->SetCreator(PDF_CREATOR); $this->SetAuthor($pdfTemplate->author); $this->SetTitle($pdfTemplate->title); $this->SetSubject($pdfTemplate->subject); $this->SetKeywords($pdfTemplate->keywords); $this->templateLocation = $this->buildTemplateFile($pdfTemplate, $previewMode); $headerLogo = ''; if (!empty($pdfTemplate->header_logo)) { // Create a temporary copy of the header logo // and append the original filename, so TCPDF can figure the extension $headerLogo = 'upload/' . $pdfTemplate->id . $pdfTemplate->header_logo; copy('upload/' . $pdfTemplate->id, $headerLogo); } if (!empty($pdfTemplate->header_logo) || !empty($pdfTemplate->header_title) || !empty($pdfTemplate->header_text)) { $this->setHeaderData($headerLogo, PDF_HEADER_LOGO_WIDTH, $pdfTemplate->header_title, $pdfTemplate->header_text); $this->setPrintHeader(true); } if (!empty($pdfTemplate->footer_text)) { $this->footerText = $pdfTemplate->footer_text; } $filenameParts = array(); if (!empty($this->bean) && !empty($this->bean->name)) { $filenameParts[] = $this->bean->name; } if (!empty($pdfTemplate->name)) { $filenameParts[] = $pdfTemplate->name; } $cr = array(' ', "\r", "\n", "/"); $this->pdfFilename = str_replace($cr, '_', implode("_", $filenameParts) . ".pdf"); } } if ($previewMode === FALSE) { require_once 'modules/PdfManager/PdfManagerHelper.php'; $fields = PdfManagerHelper::parseBeanFields($this->bean, true); } else { $fields = array(); } if ($this->module == 'Quotes' && $previewMode === FALSE) { global $locale; require_once 'modules/Quotes/Quote.php'; require_once 'modules/Quotes/config.php'; require_once 'modules/Currencies/Currency.php'; $currency = BeanFactory::getBean('Currencies'); $format_number_array = array('currency_symbol' => true, 'type' => 'sugarpdf', 'currency_id' => $this->bean->currency_id, 'charset_convert' => true); $currency->retrieve($this->bean->currency_id); $fields['currency_iso'] = $currency->iso4217; // Adding Tax Rate Field $fields['taxrate_value'] = format_number_sugarpdf($this->bean->taxrate_value, $locale->getPrecision(), $locale->getPrecision(), array('percentage' => true)); $this->bean->load_relationship('product_bundles'); $product_bundle_list = $this->bean->product_bundles->getBeans(); usort($product_bundle_list, array('ProductBundle', 'compareProductBundlesByIndex')); $bundles = array(); $count = 0; foreach ($product_bundle_list as $ordered_bundle) { $bundleFields = PdfManagerHelper::parseBeanFields($ordered_bundle, true); $bundleFields['products'] = array(); $product_bundle_line_items = $ordered_bundle->get_product_bundle_line_items(); foreach ($product_bundle_line_items as $product_bundle_line_item) { $bundleFields['products'][$count] = PdfManagerHelper::parseBeanFields($product_bundle_line_item, true); if ($product_bundle_line_item->object_name == "ProductBundleNote") { $bundleFields['products'][$count]['name'] = $bundleFields['products'][$count]['description']; } else { // Special case about discount amount if ($product_bundle_line_item->discount_select) { $bundleFields['products'][$count]['discount_amount'] = format_number($product_bundle_line_item->discount_amount, $locale->getPrecision(), $locale->getPrecision()) . '%'; } // Special case about ext price $bundleFields['products'][$count]['ext_price'] = format_number_sugarpdf($product_bundle_line_item->discount_price * $product_bundle_line_item->quantity, $locale->getPrecision(), $locale->getPrecision(), $format_number_array); } $count++; } $bundles[] = $bundleFields; } $this->ss->assign('product_bundles', $bundles); } $this->ss->assign('fields', $fields); }