Esempio n. 1
0
 /**
  * Generates and outputs label-formatted PDF version of search results using DOMPDF
  */
 protected function _genLabels($po_result, $ps_label_code, $ps_output_filename, $ps_title = null)
 {
     if ((bool) $this->request->config->get('use_legacy_print_labels_generator')) {
         return $this->_genLabelsLegacy($po_result, $ps_label_code, $ps_output_filename, $ps_title);
     }
     $vs_border = (bool) $this->request->config->get('add_print_label_borders') ? "border: 1px dotted #000000; " : "";
     //
     // PDF output
     //
     $va_template_info = caGetPrintTemplateDetails('labels', substr($ps_label_code, 5));
     if (!is_array($va_template_info)) {
         $this->postError(3110, _t("Could not find view for PDF"), "BaseFindController->_genPDF()");
         return;
     }
     try {
         $this->view->setVar('title', $ps_title);
         $this->view->setVar('base_path', $vs_base_path = pathinfo($va_template_info['path'], PATHINFO_DIRNAME));
         $this->view->addViewPath(array($vs_base_path, "{$vs_base_path}/local"));
         $vs_content = $this->render("pdfStart.php");
         // render labels
         $vn_width = caConvertMeasurementToPoints(caGetOption('labelWidth', $va_template_info, null));
         $vn_height = caConvertMeasurementToPoints(caGetOption('labelHeight', $va_template_info, null));
         $vn_top_margin = caConvertMeasurementToPoints(caGetOption('marginTop', $va_template_info, null));
         $vn_bottom_margin = caConvertMeasurementToPoints(caGetOption('marginBottom', $va_template_info, null));
         $vn_left_margin = caConvertMeasurementToPoints(caGetOption('marginLeft', $va_template_info, null));
         $vn_right_margin = caConvertMeasurementToPoints(caGetOption('marginRight', $va_template_info, null));
         $vn_horizontal_gutter = caConvertMeasurementToPoints(caGetOption('horizontalGutter', $va_template_info, null));
         $vn_vertical_gutter = caConvertMeasurementToPoints(caGetOption('verticalGutter', $va_template_info, null));
         $va_page_size = CPDF_Adapter::$PAPER_SIZES[caGetOption('pageSize', $va_template_info, null)];
         $vn_page_width = $va_page_size[2] - $va_page_size[0];
         $vn_page_height = $va_page_size[3] - $va_page_size[1];
         $vn_label_count = 0;
         $vn_left = $vn_left_margin;
         $vn_top = $vn_top_margin;
         $va_defined_vars = array_keys($this->view->getAllVars());
         // get list defined vars (we don't want to copy over them)
         $va_tag_list = $this->getTagListForView($va_template_info['path']);
         // get list of tags in view
         $va_barcode_files_to_delete = array();
         while ($po_result->nextHit()) {
             $va_barcode_files_to_delete += caDoPrintViewTagSubstitution($this->view, $po_result, $va_template_info['path'], array('checkAccess' => $this->opa_access_values));
             $vs_content .= "<div style=\"{$vs_border} position: absolute; width: {$vn_width}px; height: {$vn_height}px; left: {$vn_left}px; top: {$vn_top}px; overflow: hidden;\">";
             $vs_content .= $this->render($va_template_info['path']);
             $vs_content .= "</div>\n";
             $vn_label_count++;
             $vn_left += $vn_vertical_gutter + $vn_width;
             if ($vn_left + $vn_width > $vn_page_width) {
                 $vn_left = $vn_left_margin;
                 $vn_top += $vn_horizontal_gutter + $vn_height;
             }
             if ($vn_top + $vn_height > $vn_page_height) {
                 // next page
                 if ($vn_label_count < $po_result->numHits()) {
                     $vs_content .= "<div class=\"pageBreak\">&nbsp;</div>\n";
                 }
                 $vn_left = $vn_left_margin;
                 $vn_top = $vn_top_margin;
             }
         }
         $vs_content .= $this->render("pdfEnd.php");
         $o_dompdf = new DOMPDF();
         $o_dompdf->load_html($vs_content);
         $o_dompdf->set_paper(caGetOption('pageSize', $va_template_info, 'letter'), caGetOption('pageOrientation', $va_template_info, 'portrait'));
         $o_dompdf->set_base_path(caGetPrintTemplateDirectoryPath('labels'));
         $o_dompdf->render();
         $o_dompdf->stream(caGetOption('filename', $va_template_info, 'labels.pdf'));
         $vb_printed_properly = true;
         foreach ($va_barcode_files_to_delete as $vs_tmp) {
             @unlink($vs_tmp);
         }
     } catch (Exception $e) {
         foreach ($va_barcode_files_to_delete as $vs_tmp) {
             @unlink($vs_tmp);
         }
         $vb_printed_properly = false;
         $this->postError(3100, _t("Could not generate PDF"), "BaseFindController->PrintSummary()");
     }
 }
 /**
  * Generates and outputs label-formatted PDF version of search results 
  */
 protected function _genLabels($po_result, $ps_label_code, $ps_output_filename, $ps_title = null)
 {
     if ((bool) $this->request->config->get('use_legacy_print_labels_generator')) {
         return $this->_genLabelsLegacy($po_result, $ps_label_code, $ps_output_filename, $ps_title);
     }
     $vs_border = (bool) $this->request->config->get('add_print_label_borders') ? "border: 1px dotted #000000; " : "";
     //
     // PDF output
     //
     $va_template_info = caGetPrintTemplateDetails('labels', substr($ps_label_code, 5));
     if (!is_array($va_template_info)) {
         $this->postError(3110, _t("Could not find view for PDF"), "BaseFindController->_genPDF()");
         return;
     }
     try {
         $this->view->setVar('title', $ps_title);
         $this->view->setVar('base_path', $vs_base_path = pathinfo($va_template_info['path'], PATHINFO_DIRNAME) . '/');
         $this->view->addViewPath(array($vs_base_path, "{$vs_base_path}/local"));
         $o_pdf = new PDFRenderer();
         $this->view->setVar('PDFRenderer', $vs_renderer = $o_pdf->getCurrentRendererCode());
         // render labels
         $vn_width = caConvertMeasurement(caGetOption('labelWidth', $va_template_info, null), 'mm');
         $vn_height = caConvertMeasurement(caGetOption('labelHeight', $va_template_info, null), 'mm');
         $vn_top_margin = caConvertMeasurement(caGetOption('marginTop', $va_template_info, null), 'mm');
         $vn_bottom_margin = caConvertMeasurement(caGetOption('marginBottom', $va_template_info, null), 'mm');
         $vn_left_margin = caConvertMeasurement(caGetOption('marginLeft', $va_template_info, null), 'mm');
         $vn_right_margin = caConvertMeasurement(caGetOption('marginRight', $va_template_info, null), 'mm');
         $vn_horizontal_gutter = caConvertMeasurement(caGetOption('horizontalGutter', $va_template_info, null), 'mm');
         $vn_vertical_gutter = caConvertMeasurement(caGetOption('verticalGutter', $va_template_info, null), 'mm');
         $va_page_size = PDFRenderer::getPageSize(caGetOption('pageSize', $va_template_info, 'letter'), 'mm', caGetOption('pageOrientation', $va_template_info, 'portrait'));
         $vn_page_width = $va_page_size['width'];
         $vn_page_height = $va_page_size['height'];
         $vn_label_count = 0;
         $vn_left = $vn_left_margin;
         $vn_top = $vn_top_margin;
         $this->view->setVar('pageWidth', "{$vn_page_width}mm");
         $this->view->setVar('pageHeight', "{$vn_page_height}mm");
         $this->view->setVar('marginTop', caGetOption('marginTop', $va_template_info, '0mm'));
         $this->view->setVar('marginRight', caGetOption('marginRight', $va_template_info, '0mm'));
         $this->view->setVar('marginBottom', caGetOption('marginBottom', $va_template_info, '0mm'));
         $this->view->setVar('marginLeft', caGetOption('marginLeft', $va_template_info, '0mm'));
         $vs_content = $this->render("pdfStart.php");
         $va_defined_vars = array_keys($this->view->getAllVars());
         // get list defined vars (we don't want to copy over them)
         $va_tag_list = $this->getTagListForView($va_template_info['path']);
         // get list of tags in view
         $va_barcode_files_to_delete = array();
         $vn_page_count = 0;
         while ($po_result->nextHit()) {
             $va_barcode_files_to_delete = array_merge($va_barcode_files_to_delete, caDoPrintViewTagSubstitution($this->view, $po_result, $va_template_info['path'], array('checkAccess' => $this->opa_access_values)));
             $vs_content .= "<div style=\"{$vs_border} position: absolute; width: {$vn_width}mm; height: {$vn_height}mm; left: {$vn_left}mm; top: {$vn_top}mm; overflow: hidden; padding: 0; margin: 0;\">";
             $vs_content .= $this->render($va_template_info['path']);
             $vs_content .= "</div>\n";
             $vn_label_count++;
             $vn_left += $vn_vertical_gutter + $vn_width;
             if ($vn_left + $vn_width > $vn_page_width) {
                 $vn_left = $vn_left_margin;
                 $vn_top += $vn_horizontal_gutter + $vn_height;
             }
             if ($vn_top + $vn_height > ($vn_page_count + 1) * $vn_page_height) {
                 // next page
                 if ($vn_label_count < $po_result->numHits()) {
                     $vs_content .= "<div class=\"pageBreak\">&nbsp;</div>\n";
                 }
                 $vn_left = $vn_left_margin;
                 switch ($vs_renderer) {
                     case 'PhantomJS':
                     case 'wkhtmltopdf':
                         // WebKit based renderers (PhantomJS, wkhtmltopdf) want things numbered relative to the top of the document (Eg. the upper left hand corner of the first page is 0,0, the second page is 0,792, Etc.)
                         $vn_page_count++;
                         $vn_top = $vn_page_count * $vn_page_height + $vn_top_margin;
                         break;
                     case 'domPDF':
                     default:
                         // domPDF wants things positioned in a per-page coordinate space (Eg. the upper left hand corner of each page is 0,0)
                         $vn_top = $vn_top_margin;
                         break;
                 }
             }
         }
         $vs_content .= $this->render("pdfEnd.php");
         $o_pdf->setPage(caGetOption('pageSize', $va_template_info, 'letter'), caGetOption('pageOrientation', $va_template_info, 'portrait'));
         $o_pdf->render($vs_content, array('stream' => true, 'filename' => caGetOption('filename', $va_template_info, 'labels.pdf')));
         $vb_printed_properly = true;
         foreach ($va_barcode_files_to_delete as $vs_tmp) {
             @unlink($vs_tmp);
             @unlink("{$vs_tmp}.png");
         }
     } catch (Exception $e) {
         foreach ($va_barcode_files_to_delete as $vs_tmp) {
             @unlink($vs_tmp);
             @unlink("{$vs_tmp}.png");
         }
         $vb_printed_properly = false;
         $this->postError(3100, _t("Could not generate PDF"), "BaseFindController->PrintSummary()");
     }
 }
 /**
  * Generates display for specific bundle or (optionally) a specific repetition in a bundle
  * ** Right now only attribute bundles are supported for printing **
  *
  * @param array $pa_options Array of options passed through to _initView 
  */
 public function PrintBundle($pa_options = null)
 {
     list($vn_subject_id, $t_subject) = $this->_initView($pa_options);
     if (!$this->_checkAccess($t_subject)) {
         return false;
     }
     //
     // PDF output
     //
     $vs_template = substr($this->request->getParameter('template', pString), 5);
     // get rid of _pdf_ prefix
     if (!is_array($va_template_info = caGetPrintTemplateDetails('bundles', $vs_template))) {
         $this->postError(3110, _t("Could not find view for PDF"), "BaseEditorController->PrintBundle()");
         return;
     }
     // Element code to display
     $vs_element = $this->request->getParameter('element_code', pString);
     $vn_attribute_id = $this->request->getParameter('attribute_id', pString);
     // Does user have access to this element?
     if ($this->request->user->getBundleAccessLevel($t_subject->tableName(), $vs_element) == __CA_BUNDLE_ACCESS_NONE__) {
         $this->postError(2320, _t("No access to element"), "BaseEditorController->PrintBundle()");
         return;
     }
     // Add raw array of values to view
     if ($vn_attribute_id > 0) {
         $o_attr = $t_subject->getAttributeByID($vn_attribute_id);
         if ((int) $o_attr->getRowID() !== (int) $vn_subject_id || (int) $o_attr->getTableNum() !== (int) $t_subject->tableNum()) {
             $this->postError(2320, _t("Element is not part of current item"), "BaseEditorController->PrintBundle()");
             return;
         }
         $this->view->setVar('valuesAsAttributeInstances', $va_values = array($o_attr));
     } else {
         $this->view->setVar('valuesAsAttributeInstances', $va_values = $t_subject->getAttributesByElement($vs_element));
     }
     // Extract values into array for easier view processing
     $va_extracted_values = array();
     foreach ($va_values as $o_value) {
         $va_extracted_values[] = $o_value->getDisplayValues();
     }
     $this->view->setVar('valuesAsElementCodeArrays', $va_extracted_values);
     $va_barcode_files_to_delete = array();
     try {
         $this->view->setVar('base_path', $vs_base_path = pathinfo($va_template_info['path'], PATHINFO_DIRNAME));
         $this->view->addViewPath(array($vs_base_path, "{$vs_base_path}/local"));
         $va_barcode_files_to_delete += caDoPrintViewTagSubstitution($this->view, $t_subject, $va_template_info['path'], array('checkAccess' => $this->opa_access_values));
         $vs_content = $this->render($va_template_info['path']);
         $o_dompdf = new DOMPDF();
         $o_dompdf->load_html($vs_content);
         $o_dompdf->set_paper(caGetOption('pageSize', $va_template_info, 'letter'), caGetOption('pageOrientation', $va_template_info, 'portrait'));
         $o_dompdf->set_base_path(caGetPrintTemplateDirectoryPath('summary'));
         $o_dompdf->render();
         $o_dompdf->stream(caGetOption('filename', $va_template_info, 'print_bundles.pdf'));
         $vb_printed_properly = true;
         foreach ($va_barcode_files_to_delete as $vs_tmp) {
             @unlink($vs_tmp);
         }
     } catch (Exception $e) {
         foreach ($va_barcode_files_to_delete as $vs_tmp) {
             @unlink($vs_tmp);
         }
         $vb_printed_properly = false;
         $this->postError(3100, _t("Could not generate PDF"), "BaseEditorController->PrintBundle()");
     }
 }
 /**
  * Generates display summary of record data based upon a bundle display for print (PDF)
  *
  * @param array $pa_options Array of options passed through to _initView 
  */
 public function PrintSummary($pa_options = null)
 {
     AssetLoadManager::register('tableList');
     list($vn_subject_id, $t_subject) = $this->_initView($pa_options);
     if (!$this->_checkAccess($t_subject)) {
         return false;
     }
     $t_display = new ca_bundle_displays();
     $va_displays = $t_display->getBundleDisplays(array('table' => $t_subject->tableNum(), 'user_id' => $this->request->getUserID(), 'access' => __CA_BUNDLE_DISPLAY_READ_ACCESS__, 'restrictToTypes' => array($t_subject->getTypeID())));
     if (!($vn_display_id = $this->request->getParameter('display_id', pInteger)) || !isset($va_displays[$vn_display_id])) {
         if (!($vn_display_id = $this->request->user->getVar($t_subject->tableName() . '_summary_display_id')) || !isset($va_displays[$vn_display_id])) {
             $va_tmp = array_keys($va_displays);
             $vn_display_id = $va_tmp[0];
         }
     }
     $this->view->setVar('t_display', $t_display);
     $this->view->setVar('bundle_displays', $va_displays);
     // Check validity and access of specified display
     if ($t_display->load($vn_display_id) && $t_display->haveAccessToDisplay($this->request->getUserID(), __CA_BUNDLE_DISPLAY_READ_ACCESS__)) {
         $this->view->setVar('display_id', $vn_display_id);
         $va_placements = $t_display->getPlacements(array('returnAllAvailableIfEmpty' => true, 'table' => $t_subject->tableNum(), 'user_id' => $this->request->getUserID(), 'access' => __CA_BUNDLE_DISPLAY_READ_ACCESS__, 'no_tooltips' => true, 'format' => 'simple', 'settingsOnly' => true));
         $va_display_list = array();
         foreach ($va_placements as $vn_placement_id => $va_display_item) {
             $va_settings = caUnserializeForDatabase($va_display_item['settings']);
             // get column header text
             $vs_header = $va_display_item['display'];
             if (isset($va_settings['label']) && is_array($va_settings['label'])) {
                 if ($vs_tmp = array_shift(caExtractValuesByUserLocale(array($va_settings['label'])))) {
                     $vs_header = $vs_tmp;
                 }
             }
             $va_display_list[$vn_placement_id] = array('placement_id' => $vn_placement_id, 'bundle_name' => $va_display_item['bundle_name'], 'display' => $vs_header, 'settings' => $va_settings);
         }
         $this->view->setVar('placements', $va_display_list);
         $this->request->user->setVar($t_subject->tableName() . '_summary_display_id', $vn_display_id);
         $vs_format = $this->request->config->get("summary_print_format");
     } else {
         $this->view->setVar('display_id', null);
         $this->view->setVar('placements', array());
     }
     //
     // PDF output
     //
     if (!is_array($va_template_info = caGetPrintTemplateDetails('summary', "{$this->ops_table_name}_summary"))) {
         if (!is_array($va_template_info = caGetPrintTemplateDetails('summary', "summary"))) {
             $this->postError(3110, _t("Could not find view for PDF"), "BaseEditorController->PrintSummary()");
             return;
         }
     }
     $va_barcode_files_to_delete = array();
     try {
         $this->view->setVar('base_path', $vs_base_path = pathinfo($va_template_info['path'], PATHINFO_DIRNAME));
         $this->view->addViewPath(array($vs_base_path, "{$vs_base_path}/local"));
         $va_barcode_files_to_delete += caDoPrintViewTagSubstitution($this->view, $t_subject, $va_template_info['path'], array('checkAccess' => $this->opa_access_values));
         $vs_content = $this->render($va_template_info['path']);
         $o_dompdf = new DOMPDF();
         $o_dompdf->load_html($vs_content);
         $o_dompdf->set_paper(caGetOption('pageSize', $va_template_info, 'letter'), caGetOption('pageOrientation', $va_template_info, 'portrait'));
         $o_dompdf->set_base_path(caGetPrintTemplateDirectoryPath('summary'));
         $o_dompdf->render();
         $o_dompdf->stream(caGetOption('filename', $va_template_info, 'print_summary.pdf'));
         $vb_printed_properly = true;
         foreach ($va_barcode_files_to_delete as $vs_tmp) {
             @unlink($vs_tmp);
         }
     } catch (Exception $e) {
         foreach ($va_barcode_files_to_delete as $vs_tmp) {
             @unlink($vs_tmp);
         }
         $vb_printed_properly = false;
         $this->postError(3100, _t("Could not generate PDF"), "BaseEditorController->PrintSummary()");
     }
 }