Пример #1
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     if ($this->_action & CRM_Core_Action::DELETE) {
         $formatName = CRM_Core_BAO_PdfFormat::getFieldValue('CRM_Core_BAO_PdfFormat', $this->_id, 'name');
         $this->assign('formatName', $formatName);
         return;
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_BAO_PdfFormat');
     $this->add('text', 'name', ts('Name'), $attributes['name'], TRUE);
     $this->add('text', 'description', ts('Description'), array('size' => CRM_Utils_Type::HUGE));
     $this->add('checkbox', 'is_default', ts('Is this PDF Page Format the default?'));
     $this->add('select', 'paper_size', ts('Paper Size'), array(0 => ts('- default -')) + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE, array('onChange' => "selectPaper( this.value );"));
     $this->add('static', 'paper_dimensions', NULL, ts('Width x Height'));
     $this->add('select', 'orientation', ts('Orientation'), CRM_Core_BAO_PdfFormat::getPageOrientations(), FALSE, array('onChange' => "updatePaperDimensions();"));
     $this->add('select', 'metric', ts('Unit of Measure'), CRM_Core_BAO_PdfFormat::getUnits(), FALSE, array('onChange' => "selectMetric( this.value );"));
     $this->add('text', 'margin_left', ts('Left Margin'), array('size' => 8, 'maxlength' => 8), TRUE);
     $this->add('text', 'margin_right', ts('Right Margin'), array('size' => 8, 'maxlength' => 8), TRUE);
     $this->add('text', 'margin_top', ts('Top Margin'), array('size' => 8, 'maxlength' => 8), TRUE);
     $this->add('text', 'margin_bottom', ts('Bottom Margin'), array('size' => 8, 'maxlength' => 8), TRUE);
     $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_BAO_PdfFormat', 'weight'), TRUE);
     $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array('CRM_Core_BAO_PdfFormat', $this->_id));
     $this->addRule('margin_left', ts('Margin must be numeric'), 'numeric');
     $this->addRule('margin_right', ts('Margin must be numeric'), 'numeric');
     $this->addRule('margin_top', ts('Margin must be numeric'), 'numeric');
     $this->addRule('margin_bottom', ts('Margin must be numeric'), 'numeric');
     $this->addRule('weight', ts('Weight must be integer'), 'integer');
 }
 /**
  * Build the form
  *
  * @access public
  *
  * @return void
  */
 static function buildQuickForm(&$form)
 {
     $form->add('static', 'pdf_format_header', NULL, ts('Page Format'));
     $form->add('select', 'format_id', ts('Select Format'), array(0 => ts('- default -')) + CRM_Core_BAO_PdfFormat::getList(TRUE), FALSE, array('onChange' => "selectFormat( this.value, false );"));
     $form->add('select', 'paper_size', ts('Paper Size'), array(0 => ts('- default -')) + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE, array('onChange' => "selectPaper( this.value ); showUpdateFormatChkBox();"));
     $form->add('static', 'paper_dimensions', NULL, ts('Width x Height'));
     $form->add('select', 'orientation', ts('Orientation'), CRM_Core_BAO_PdfFormat::getPageOrientations(), FALSE, array('onChange' => "updatePaperDimensions(); showUpdateFormatChkBox();"));
     $form->add('select', 'metric', ts('Unit of Measure'), CRM_Core_BAO_PdfFormat::getUnits(), FALSE, array('onChange' => "selectMetric( this.value );"));
     $form->add('text', 'margin_left', ts('Left Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $form->add('text', 'margin_right', ts('Right Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $form->add('text', 'margin_top', ts('Top Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $form->add('text', 'margin_bottom', ts('Bottom Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $form->add('checkbox', 'bind_format', ts('Always use this Page Format with the selected Template'));
     $form->add('checkbox', 'update_format', ts('Update Page Format (this will affect all templates that use this format)'));
     $form->assign('useThisPageFormat', ts('Always use this Page Format with the new template?'));
     $form->assign('useSelectedPageFormat', ts('Should the new template always use the selected Page Format?'));
     $form->assign('totalSelectedContacts', count($form->_contactIds));
     CRM_Mailing_BAO_Mailing::commonLetterCompose($form);
     if ($form->_single) {
         $cancelURL = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$form->_cid}&selectedChild=activity", FALSE, NULL, FALSE);
         if ($form->get('action') == CRM_Core_Action::VIEW) {
             $form->addButtons(array(array('type' => 'cancel', 'name' => ts('Done'), 'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"))));
         } else {
             $form->addButtons(array(array('type' => 'submit', 'name' => ts('Make PDF Letter'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Done'), 'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"))));
         }
     } else {
         $form->addDefaultButtons(ts('Make PDF Letters'));
     }
     $form->addFormRule(array('CRM_Contact_Form_Task_PDFLetterCommon', 'formRule'), $form);
 }
Пример #3
0
 /**
  * Get Option Group ID for Paper Sizes.
  *
  * @return int
  *   Group ID (null if Group ID doesn't exist)
  */
 private static function _getGid()
 {
     if (!self::$_gid) {
         self::$_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'paper_size', 'id', 'name');
         if (!self::$_gid) {
             CRM_Core_Error::fatal(ts('Paper Size Option Group not found in database.'));
         }
     }
     return self::$_gid;
 }
Пример #4
0
 /**
  * @param $text
  * @param string $fileName
  * @param bool $output
  * @param null $pdfFormat
  *
  * @return string|void
  */
 public static function html2pdf(&$text, $fileName = 'civicrm.pdf', $output = FALSE, $pdfFormat = NULL)
 {
     if (is_array($text)) {
         $pages =& $text;
     } else {
         $pages = array($text);
     }
     // Get PDF Page Format
     $format = CRM_Core_BAO_PdfFormat::getDefaultValues();
     if (is_array($pdfFormat)) {
         // PDF Page Format parameters passed in
         $format = array_merge($format, $pdfFormat);
     } else {
         // PDF Page Format ID passed in
         $format = CRM_Core_BAO_PdfFormat::getById($pdfFormat);
     }
     $paperSize = CRM_Core_BAO_PaperSize::getByName($format['paper_size']);
     $paper_width = self::convertMetric($paperSize['width'], $paperSize['metric'], 'pt');
     $paper_height = self::convertMetric($paperSize['height'], $paperSize['metric'], 'pt');
     // dompdf requires dimensions in points
     $paper_size = array(0, 0, $paper_width, $paper_height);
     $orientation = CRM_Core_BAO_PdfFormat::getValue('orientation', $format);
     $metric = CRM_Core_BAO_PdfFormat::getValue('metric', $format);
     $t = CRM_Core_BAO_PdfFormat::getValue('margin_top', $format);
     $r = CRM_Core_BAO_PdfFormat::getValue('margin_right', $format);
     $b = CRM_Core_BAO_PdfFormat::getValue('margin_bottom', $format);
     $l = CRM_Core_BAO_PdfFormat::getValue('margin_left', $format);
     $stationery_path_partial = CRM_Core_BAO_PdfFormat::getValue('stationery', $format);
     $stationery_path = NULL;
     if (strlen($stationery_path_partial)) {
         $doc_root = $_SERVER['DOCUMENT_ROOT'];
         $stationery_path = $doc_root . "/" . $stationery_path_partial;
     }
     $margins = array($metric, $t, $r, $b, $l);
     $config = CRM_Core_Config::singleton();
     // Add a special region for the HTML header of PDF files:
     $pdfHeaderRegion = CRM_Core_Region::instance('export-document-header', FALSE);
     $htmlHeader = $pdfHeaderRegion ? $pdfHeaderRegion->render('', FALSE) : '';
     $html = "\n<html>\n  <head>\n    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n    <style>@page { margin: {$t}{$metric} {$r}{$metric} {$b}{$metric} {$l}{$metric}; }</style>\n    <style type=\"text/css\">@import url({$config->userFrameworkResourceURL}css/print.css);</style>\n    {$htmlHeader}\n  </head>\n  <body>\n    <div id=\"crm-container\">\n";
     // Strip <html>, <header>, and <body> tags from each page
     $htmlElementstoStrip = array('@<head[^>]*?>.*?</head>@siu', '@<script[^>]*?>.*?</script>@siu', '@<body>@siu', '@</body>@siu', '@<html[^>]*?>@siu', '@</html>@siu', '@<!DOCTYPE[^>]*?>@siu');
     $htmlElementsInstead = array('', '', '', '', '', '');
     foreach ($pages as &$page) {
         $page = preg_replace($htmlElementstoStrip, $htmlElementsInstead, $page);
     }
     // Glue the pages together
     $html .= implode("\n<div style=\"page-break-after: always\"></div>\n", $pages);
     $html .= "\n    </div>\n  </body>\n</html>";
     if ($config->wkhtmltopdfPath) {
         return self::_html2pdf_wkhtmltopdf($paper_size, $orientation, $margins, $html, $output, $fileName);
     } else {
         return self::_html2pdf_dompdf($paper_size, $orientation, $html, $output, $fileName);
         //return self::_html2pdf_tcpdf($paper_size, $orientation, $margins, $html, $output, $fileName,  $stationery_path);
     }
 }
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::COPY)) {
         $formatName = CRM_Core_BAO_LabelFormat::getFieldValue('CRM_Core_BAO_LabelFormat', $this->_id, 'label');
         $this->assign('formatName', $formatName);
         return;
     }
     $disabled = array();
     $required = TRUE;
     $is_reserved = $this->_id ? CRM_Core_BAO_LabelFormat::getFieldValue('CRM_Core_BAO_LabelFormat', $this->_id, 'is_reserved') : FALSE;
     if ($is_reserved) {
         $disabled['disabled'] = 'disabled';
         $required = FALSE;
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_BAO_LabelFormat');
     $this->add('text', 'label', ts('Name'), $attributes['label'] + $disabled, $required);
     $this->add('text', 'description', ts('Description'), array('size' => CRM_Utils_Type::HUGE));
     $this->add('checkbox', 'is_default', ts('Is this Label Format the default?'));
     $this->add('select', 'paper_size', ts('Sheet Size'), array(0 => ts('- default -')) + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE, array('onChange' => "selectPaper( this.value );") + $disabled);
     $this->add('static', 'paper_dimensions', NULL, ts('Sheet Size (w x h)'));
     $this->add('select', 'orientation', ts('Orientation'), CRM_Core_BAO_LabelFormat::getPageOrientations(), FALSE, array('onChange' => "updatePaperDimensions();") + $disabled);
     $this->add('select', 'font_name', ts('Font Name'), CRM_Core_BAO_LabelFormat::getFontNames());
     $this->add('select', 'font_size', ts('Font Size'), CRM_Core_BAO_LabelFormat::getFontSizes());
     $this->add('static', 'font_style', ts('Font Style'));
     $this->add('checkbox', 'bold', ts('Bold'));
     $this->add('checkbox', 'italic', ts('Italic'));
     $this->add('select', 'metric', ts('Unit of Measure'), CRM_Core_BAO_LabelFormat::getUnits(), FALSE, array('onChange' => "selectMetric( this.value );"));
     $this->add('text', 'width', ts('Label Width'), array('size' => 8, 'maxlength' => 8) + $disabled, $required);
     $this->add('text', 'height', ts('Label Height'), array('size' => 8, 'maxlength' => 8) + $disabled, $required);
     $this->add('text', 'NX', ts('Labels Per Row'), array('size' => 3, 'maxlength' => 3) + $disabled, $required);
     $this->add('text', 'NY', ts('Labels Per Column'), array('size' => 3, 'maxlength' => 3) + $disabled, $required);
     $this->add('text', 'tMargin', ts('Top Margin'), array('size' => 8, 'maxlength' => 8) + $disabled, $required);
     $this->add('text', 'lMargin', ts('Left Margin'), array('size' => 8, 'maxlength' => 8) + $disabled, $required);
     $this->add('text', 'SpaceX', ts('Horizontal Spacing'), array('size' => 8, 'maxlength' => 8) + $disabled, $required);
     $this->add('text', 'SpaceY', ts('Vertical Spacing'), array('size' => 8, 'maxlength' => 8) + $disabled, $required);
     $this->add('text', 'lPadding', ts('Left Padding'), array('size' => 8, 'maxlength' => 8), $required);
     $this->add('text', 'tPadding', ts('Top Padding'), array('size' => 8, 'maxlength' => 8), $required);
     $this->add('text', 'weight', ts('Weight'), CRM_Core_DAO::getAttribute('CRM_Core_BAO_LabelFormat', 'weight'), TRUE);
     $this->addRule('label', ts('Name already exists in Database.'), 'objectExists', array('CRM_Core_BAO_LabelFormat', $this->_id));
     $this->addRule('NX', ts('Must be an integer'), 'integer');
     $this->addRule('NY', ts('Must be an integer'), 'integer');
     $this->addRule('tMargin', ts('Must be numeric'), 'numeric');
     $this->addRule('lMargin', ts('Must be numeric'), 'numeric');
     $this->addRule('SpaceX', ts('Must be numeric'), 'numeric');
     $this->addRule('SpaceY', ts('Must be numeric'), 'numeric');
     $this->addRule('lPadding', ts('Must be numeric'), 'numeric');
     $this->addRule('tPadding', ts('Must be numeric'), 'numeric');
     $this->addRule('width', ts('Must be numeric'), 'numeric');
     $this->addRule('height', ts('Must be numeric'), 'numeric');
     $this->addRule('weight', ts('Weight must be integer'), 'integer');
 }
Пример #6
0
 /**
  * Build the form object.
  *
  * @var CRM_Core_Form $form
  */
 public static function buildQuickForm(&$form)
 {
     // This form outputs a file so should never be submitted via ajax
     $form->preventAjaxSubmit();
     //Added for CRM-12682: Add activity subject and campaign fields
     CRM_Campaign_BAO_Campaign::addCampaign($form);
     $form->add('text', 'subject', ts('Activity Subject'), array('size' => 45, 'maxlength' => 255), FALSE);
     $form->add('static', 'pdf_format_header', NULL, ts('Page Format: %1', array(1 => '<span class="pdf-format-header-label"></span>')));
     $form->addSelect('format_id', array('label' => ts('Select Format'), 'placeholder' => ts('Default'), 'entity' => 'message_template', 'field' => 'pdf_format_id', 'option_url' => 'civicrm/admin/pdfFormats'));
     $form->add('select', 'paper_size', ts('Paper Size'), array(0 => ts('- default -')) + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE, array('onChange' => "selectPaper( this.value ); showUpdateFormatChkBox();"));
     $form->add('static', 'paper_dimensions', NULL, ts('Width x Height'));
     $form->add('select', 'orientation', ts('Orientation'), CRM_Core_BAO_PdfFormat::getPageOrientations(), FALSE, array('onChange' => "updatePaperDimensions(); showUpdateFormatChkBox();"));
     $form->add('select', 'metric', ts('Unit of Measure'), CRM_Core_BAO_PdfFormat::getUnits(), FALSE, array('onChange' => "selectMetric( this.value );"));
     $form->add('text', 'margin_left', ts('Left Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $form->add('text', 'margin_right', ts('Right Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $form->add('text', 'margin_top', ts('Top Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $form->add('text', 'margin_bottom', ts('Bottom Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $config = CRM_Core_Config::singleton();
     /** CRM-15883 Suppressing Stationery path field until we switch from DOMPDF to a library that supports it.
         if ($config->wkhtmltopdfPath == FALSE) {
         $form->add(
         'text',
         'stationery',
         ts('Stationery (relative path to PDF you wish to use as the background)'),
         array('size' => 25, 'maxlength' => 900, 'onkeyup' => "showUpdateFormatChkBox();"),
         FALSE
         );
         }
          */
     $form->add('checkbox', 'bind_format', ts('Always use this Page Format with the selected Template'));
     $form->add('checkbox', 'update_format', ts('Update Page Format (this will affect all templates that use this format)'));
     $form->assign('useThisPageFormat', ts('Always use this Page Format with the new template?'));
     $form->assign('useSelectedPageFormat', ts('Should the new template always use the selected Page Format?'));
     $form->assign('totalSelectedContacts', count($form->_contactIds));
     $form->add('select', 'document_type', ts('Document Type'), CRM_Core_SelectValues::documentFormat());
     $documentTypes = implode(',', CRM_Core_SelectValues::documentApplicationType());
     $form->addElement('file', "document_file", 'Upload Document', 'size=30 maxlength=255 accept="' . $documentTypes . '"');
     $form->addUploadElement("document_file");
     CRM_Mailing_BAO_Mailing::commonCompose($form);
     $buttons = array();
     if ($form->get('action') != CRM_Core_Action::VIEW) {
         $buttons[] = array('type' => 'upload', 'name' => ts('Download Document'), 'isDefault' => TRUE, 'icon' => 'fa-download');
         $buttons[] = array('type' => 'submit', 'name' => ts('Preview'), 'subName' => 'preview', 'icon' => 'fa-search', 'isDefault' => FALSE);
     }
     $buttons[] = array('type' => 'cancel', 'name' => $form->get('action') == CRM_Core_Action::VIEW ? ts('Done') : ts('Cancel'));
     $form->addButtons($buttons);
     $form->addFormRule(array('CRM_Contact_Form_Task_PDFLetterCommon', 'formRule'), $form);
 }
Пример #7
0
 static function html2pdf(&$text, $fileName = 'civicrm.pdf', $output = FALSE, $pdfFormat = NULL)
 {
     if (is_array($text)) {
         $pages =& $text;
     } else {
         $pages = array($text);
     }
     // Get PDF Page Format
     $format = CRM_Core_BAO_PdfFormat::getDefaultValues();
     if (is_array($pdfFormat)) {
         // PDF Page Format parameters passed in
         $format = array_merge($format, $pdfFormat);
     } else {
         // PDF Page Format ID passed in
         $format = CRM_Core_BAO_PdfFormat::getById($pdfFormat);
     }
     $paperSize = CRM_Core_BAO_PaperSize::getByName($format['paper_size']);
     $paper_width = self::convertMetric($paperSize['width'], $paperSize['metric'], 'pt');
     $paper_height = self::convertMetric($paperSize['height'], $paperSize['metric'], 'pt');
     // dompdf requires dimensions in points
     $paper_size = array(0, 0, $paper_width, $paper_height);
     $orientation = CRM_Core_BAO_PdfFormat::getValue('orientation', $format);
     $metric = CRM_Core_BAO_PdfFormat::getValue('metric', $format);
     $t = CRM_Core_BAO_PdfFormat::getValue('margin_top', $format);
     $r = CRM_Core_BAO_PdfFormat::getValue('margin_right', $format);
     $b = CRM_Core_BAO_PdfFormat::getValue('margin_bottom', $format);
     $l = CRM_Core_BAO_PdfFormat::getValue('margin_left', $format);
     $config = CRM_Core_Config::singleton();
     $html = "\n<html>\n  <head>\n    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n    <style>@page { margin: {$t}{$metric} {$r}{$metric} {$b}{$metric} {$l}{$metric}; }</style>\n    <style type=\"text/css\">@import url({$config->userFrameworkResourceURL}css/print.css);</style>\n  </head>\n  <body>\n    <div id=\"crm-container\">\n";
     // Strip <html>, <header>, and <body> tags from each page
     $htmlElementstoStrip = array('@<head[^>]*?>.*?</head>@siu', '@<body>@siu', '@</body>@siu', '@<html[^>]*?>@siu', '@</html>@siu', '@<!DOCTYPE[^>]*?>@siu');
     $htmlElementsInstead = array('', '', '', '', '', '');
     foreach ($pages as &$page) {
         $page = preg_replace($htmlElementstoStrip, $htmlElementsInstead, $page);
     }
     // Glue the pages together
     $html .= implode("\n<div style=\"page-break-after: always\"></div>\n", $pages);
     $html .= "\n    </div>\n  </body>\n</html>";
     if ($config->wkhtmltopdfPath) {
         return self::_html2pdf_wkhtmltopdf($paper_size, $orientation, $html, $output, $fileName);
     } else {
         return self::_html2pdf_dompdf($paper_size, $orientation, $html, $output, $fileName);
     }
 }
Пример #8
0
 /**
  * @param array $pages
  * @param string $fileName
  * @param array|int $format
  */
 public static function html2doc($pages, $fileName, $format = array())
 {
     if (is_array($format)) {
         // PDF Page Format parameters passed in - merge with defaults
         $format += CRM_Core_BAO_PdfFormat::getDefaultValues();
     } else {
         // PDF Page Format ID passed in
         $format = CRM_Core_BAO_PdfFormat::getById($format);
     }
     $paperSize = CRM_Core_BAO_PaperSize::getByName($format['paper_size']);
     $metric = CRM_Core_BAO_PdfFormat::getValue('metric', $format);
     $pageStyle = array('orientation' => CRM_Core_BAO_PdfFormat::getValue('orientation', $format), 'pageSizeW' => self::toTwip($paperSize['width'], $paperSize['metric']), 'pageSizeH' => self::toTwip($paperSize['height'], $paperSize['metric']), 'marginTop' => self::toTwip(CRM_Core_BAO_PdfFormat::getValue('margin_top', $format), $metric), 'marginRight' => self::toTwip(CRM_Core_BAO_PdfFormat::getValue('margin_right', $format), $metric), 'marginBottom' => self::toTwip(CRM_Core_BAO_PdfFormat::getValue('margin_bottom', $format), $metric), 'marginLeft' => self::toTwip(CRM_Core_BAO_PdfFormat::getValue('margin_left', $format), $metric));
     $ext = pathinfo($fileName, PATHINFO_EXTENSION);
     $phpWord = new \PhpOffice\PhpWord\PhpWord();
     $phpWord->getDocInfo()->setCreator(CRM_Core_DAO::getFieldValue('CRM_Contact_BAO_Contact', CRM_Core_Session::getLoggedInContactID(), 'display_name'));
     foreach ((array) $pages as $page => $html) {
         $section = $phpWord->addSection($pageStyle + array('breakType' => 'nextPage'));
         \PhpOffice\PhpWord\Shared\Html::addHtml($section, $html);
     }
     self::printDoc($phpWord, $ext, $fileName);
 }
Пример #9
0
 /**
  * Retrieve Paper Size dimensions.
  */
 public static function paperSize()
 {
     $paperSizeName = CRM_Utils_Type::escape($_REQUEST['paperSizeName'], 'String');
     $paperSize = CRM_Core_BAO_PaperSize::getByName($paperSizeName);
     CRM_Utils_JSON::output($paperSize);
 }
Пример #10
0
 /**
  * initialize label format settings.
  *
  * @param $format
  * @param $unit
  */
 public function LabelSetFormat(&$format, $unit)
 {
     $this->defaults = CRM_Core_BAO_LabelFormat::getDefaultValues();
     $this->format =& $format;
     $this->formatName = $this->getFormatValue('name');
     $this->paperSize = $this->getFormatValue('paper-size');
     $this->orientation = $this->getFormatValue('orientation');
     $this->fontName = $this->getFormatValue('font-name');
     $this->charSize = $this->getFormatValue('font-size');
     $this->fontStyle = $this->getFormatValue('font-style');
     $this->xNumber = $this->getFormatValue('NX');
     $this->yNumber = $this->getFormatValue('NY');
     $this->metricDoc = $unit;
     $this->marginLeft = $this->getFormatValue('lMargin', TRUE);
     $this->marginTop = $this->getFormatValue('tMargin', TRUE);
     $this->xSpace = $this->getFormatValue('SpaceX', TRUE);
     $this->ySpace = $this->getFormatValue('SpaceY', TRUE);
     $this->width = $this->getFormatValue('width', TRUE);
     $this->height = $this->getFormatValue('height', TRUE);
     $this->paddingLeft = $this->getFormatValue('lPadding', TRUE);
     $this->paddingTop = $this->getFormatValue('tPadding', TRUE);
     $paperSize = CRM_Core_BAO_PaperSize::getByName($this->paperSize);
     $w = CRM_Utils_PDF_Utils::convertMetric($paperSize['width'], $paperSize['metric'], $this->metricDoc);
     $h = CRM_Utils_PDF_Utils::convertMetric($paperSize['height'], $paperSize['metric'], $this->metricDoc);
     $this->paper_dimensions = array($w, $h);
 }
Пример #11
0
 /**
  * Function to retrieve Paper Size dimensions
  */
 function paperSize()
 {
     $paperSizeName = CRM_Utils_Type::escape($_POST['paperSizeName'], 'String');
     $paperSize = CRM_Core_BAO_PaperSize::getByName($paperSizeName);
     echo json_encode($paperSize);
     CRM_Utils_System::civiExit();
 }
 /**
  * Build the form
  *
  * @var CRM_Core_Form $form
  *
  * @return void
  */
 static function buildQuickForm(&$form)
 {
     // This form outputs a file so should never be submitted via ajax
     $form->preventAjaxSubmit();
     //Added for CRM-12682: Add activity subject and campaign fields
     CRM_Campaign_BAO_Campaign::addCampaign($form);
     $form->add('text', 'subject', ts('Activity Subject'), array('size' => 45, 'maxlength' => 255), FALSE);
     $form->add('static', 'pdf_format_header', NULL, ts('Page Format: %1', array(1 => '<span class="pdf-format-header-label"></span>')));
     $form->addSelect('format_id', array('label' => ts('Select Format'), 'placeholder' => ts('Default'), 'entity' => 'message_template', 'field' => 'pdf_format_id', 'option_url' => 'civicrm/admin/pdfFormats'));
     $form->add('select', 'paper_size', ts('Paper Size'), array(0 => ts('- default -')) + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE, array('onChange' => "selectPaper( this.value ); showUpdateFormatChkBox();"));
     $form->add('static', 'paper_dimensions', NULL, ts('Width x Height'));
     $form->add('select', 'orientation', ts('Orientation'), CRM_Core_BAO_PdfFormat::getPageOrientations(), FALSE, array('onChange' => "updatePaperDimensions(); showUpdateFormatChkBox();"));
     $form->add('select', 'metric', ts('Unit of Measure'), CRM_Core_BAO_PdfFormat::getUnits(), FALSE, array('onChange' => "selectMetric( this.value );"));
     $form->add('text', 'margin_left', ts('Left Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $form->add('text', 'margin_right', ts('Right Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $form->add('text', 'margin_top', ts('Top Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $form->add('text', 'margin_bottom', ts('Bottom Margin'), array('size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"), TRUE);
     $config = CRM_Core_Config::singleton();
     if ($config->wkhtmltopdfPath == false) {
         $form->add('text', 'stationery', ts('Stationery (relative path to PDF you wish to use as the background)'), array('size' => 25, 'maxlength' => 900, 'onkeyup' => "showUpdateFormatChkBox();"), FALSE);
     }
     $form->add('checkbox', 'bind_format', ts('Always use this Page Format with the selected Template'));
     $form->add('checkbox', 'update_format', ts('Update Page Format (this will affect all templates that use this format)'));
     $form->assign('useThisPageFormat', ts('Always use this Page Format with the new template?'));
     $form->assign('useSelectedPageFormat', ts('Should the new template always use the selected Page Format?'));
     $form->assign('totalSelectedContacts', count($form->_contactIds));
     CRM_Mailing_BAO_Mailing::commonLetterCompose($form);
     if ($form->_single) {
         $cancelURL = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$form->_cid}&selectedChild=activity", FALSE, NULL, FALSE);
         if ($form->get('action') == CRM_Core_Action::VIEW) {
             $form->addButtons(array(array('type' => 'cancel', 'name' => ts('Done'), 'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"))));
         } else {
             $form->addButtons(array(array('type' => 'submit', 'name' => ts('Make PDF Letter'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Done'), 'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"))));
         }
     } else {
         $form->addButtons(array(array('type' => 'submit', 'name' => ts('Make PDF Letters'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Done'))));
     }
     $form->addFormRule(array('CRM_Contact_Form_Task_PDFLetterCommon', 'formRule'), $form);
 }