Commit | Line | Data |
---|---|---|
fc34a273 EM |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | Copyright CiviCRM LLC. All rights reserved. | | |
5 | | | | |
6 | | This work is published under the GNU AGPLv3 license with some | | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
9 | +--------------------------------------------------------------------+ | |
10 | */ | |
11 | ||
12 | /** | |
13 | * | |
14 | * @package CRM | |
15 | * @copyright CiviCRM LLC https://civicrm.org/licensing | |
16 | */ | |
17 | ||
18 | /** | |
19 | * This class provides the common functionality for tasks that send emails. | |
20 | */ | |
21 | trait CRM_Contact_Form_Task_PDFTrait { | |
22 | ||
23 | /** | |
24 | * Set defaults for the pdf. | |
25 | * | |
26 | * @return array | |
27 | */ | |
28 | public function setDefaultValues(): array { | |
29 | return $this->getPDFDefaultValues(); | |
30 | } | |
31 | ||
32 | /** | |
33 | * Set default values. | |
34 | */ | |
35 | protected function getPDFDefaultValues(): array { | |
36 | $defaultFormat = CRM_Core_BAO_PdfFormat::getDefaultValues(); | |
37 | $defaultFormat['format_id'] = $defaultFormat['id']; | |
38 | return $defaultFormat; | |
39 | } | |
40 | ||
053c1a4b EM |
41 | /** |
42 | * Build the form object. | |
43 | * | |
44 | * @throws \CRM_Core_Exception | |
45 | */ | |
46 | public function buildQuickForm(): void { | |
47 | $this->addPDFElementsToForm(); | |
48 | } | |
49 | ||
50 | /** | |
51 | * Build the form object. | |
52 | * | |
53 | * @throws \CRM_Core_Exception | |
54 | */ | |
55 | public function addPDFElementsToForm(): void { | |
56 | $form = $this; | |
57 | // This form outputs a file so should never be submitted via ajax | |
58 | $form->preventAjaxSubmit(); | |
59 | ||
60 | //Added for CRM-12682: Add activity subject and campaign fields | |
61 | CRM_Campaign_BAO_Campaign::addCampaign($form); | |
62 | $form->add( | |
63 | 'text', | |
64 | 'subject', | |
65 | ts('Activity Subject'), | |
66 | ['size' => 45, 'maxlength' => 255], | |
67 | FALSE | |
68 | ); | |
69 | ||
70 | // Added for core#2121, | |
71 | // To support sending a custom pdf filename before downloading. | |
72 | $form->addElement('hidden', 'pdf_file_name'); | |
73 | ||
74 | $form->addSelect('format_id', [ | |
75 | 'label' => ts('Select Format'), | |
76 | 'placeholder' => ts('Default'), | |
77 | 'entity' => 'message_template', | |
78 | 'field' => 'pdf_format_id', | |
79 | 'option_url' => 'civicrm/admin/pdfFormats', | |
80 | ]); | |
81 | $form->add( | |
82 | 'select', | |
83 | 'paper_size', | |
84 | ts('Paper Size'), | |
85 | [0 => ts('- default -')] + CRM_Core_BAO_PaperSize::getList(TRUE), | |
86 | FALSE, | |
87 | ['onChange' => "selectPaper( this.value ); showUpdateFormatChkBox();"] | |
88 | ); | |
89 | $form->add( | |
90 | 'select', | |
91 | 'orientation', | |
92 | ts('Orientation'), | |
93 | CRM_Core_BAO_PdfFormat::getPageOrientations(), | |
94 | FALSE, | |
95 | ['onChange' => "updatePaperDimensions(); showUpdateFormatChkBox();"] | |
96 | ); | |
97 | $form->add( | |
98 | 'select', | |
99 | 'metric', | |
100 | ts('Unit of Measure'), | |
101 | CRM_Core_BAO_PdfFormat::getUnits(), | |
102 | FALSE, | |
103 | ['onChange' => "selectMetric( this.value );"] | |
104 | ); | |
105 | $form->add( | |
106 | 'text', | |
107 | 'margin_left', | |
108 | ts('Left Margin'), | |
109 | ['size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"], | |
110 | TRUE | |
111 | ); | |
112 | $form->add( | |
113 | 'text', | |
114 | 'margin_right', | |
115 | ts('Right Margin'), | |
116 | ['size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"], | |
117 | TRUE | |
118 | ); | |
119 | $form->add( | |
120 | 'text', | |
121 | 'margin_top', | |
122 | ts('Top Margin'), | |
123 | ['size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"], | |
124 | TRUE | |
125 | ); | |
126 | $form->add( | |
127 | 'text', | |
128 | 'margin_bottom', | |
129 | ts('Bottom Margin'), | |
130 | ['size' => 8, 'maxlength' => 8, 'onkeyup' => "showUpdateFormatChkBox();"], | |
131 | TRUE | |
132 | ); | |
133 | ||
134 | $config = CRM_Core_Config::singleton(); | |
135 | /** CRM-15883 Suppressing Stationery path field until we switch from DOMPDF to a library that supports it. | |
136 | * if ($config->wkhtmltopdfPath == FALSE) { | |
137 | * $form->add( | |
138 | * 'text', | |
139 | * 'stationery', | |
140 | * ts('Stationery (relative path to PDF you wish to use as the background)'), | |
141 | * array('size' => 25, 'maxlength' => 900, 'onkeyup' => "showUpdateFormatChkBox();"), | |
142 | * FALSE | |
143 | * ); | |
144 | * } | |
145 | */ | |
146 | $form->add('checkbox', 'bind_format', ts('Always use this Page Format with the selected Template')); | |
147 | $form->add('checkbox', 'update_format', ts('Update Page Format (this will affect all templates that use this format)')); | |
148 | ||
149 | $form->assign('useThisPageFormat', ts('Always use this Page Format with the new template?')); | |
150 | $form->assign('useSelectedPageFormat', ts('Should the new template always use the selected Page Format?')); | |
151 | $form->assign('totalSelectedContacts', !is_null($form->_contactIds) ? count($form->_contactIds) : 0); | |
152 | ||
153 | $form->add('select', 'document_type', ts('Document Type'), CRM_Core_SelectValues::documentFormat()); | |
154 | ||
155 | $documentTypes = implode(',', CRM_Core_SelectValues::documentApplicationType()); | |
156 | $form->addElement('file', "document_file", 'Upload Document', 'size=30 maxlength=255 accept="' . $documentTypes . '"'); | |
157 | $form->addUploadElement("document_file"); | |
158 | ||
159 | CRM_Mailing_BAO_Mailing::commonCompose($form); | |
160 | ||
161 | $buttons = []; | |
162 | if ($form->get('action') != CRM_Core_Action::VIEW) { | |
163 | $buttons[] = [ | |
164 | 'type' => 'upload', | |
165 | 'name' => ts('Download Document'), | |
166 | 'isDefault' => TRUE, | |
167 | 'icon' => 'fa-download', | |
168 | ]; | |
169 | $buttons[] = [ | |
170 | 'type' => 'submit', | |
171 | 'name' => ts('Preview'), | |
172 | 'subName' => 'preview', | |
173 | 'icon' => 'fa-search', | |
174 | 'isDefault' => FALSE, | |
175 | ]; | |
176 | } | |
177 | $buttons[] = [ | |
178 | 'type' => 'cancel', | |
179 | 'name' => $form->get('action') == CRM_Core_Action::VIEW ? ts('Done') : ts('Cancel'), | |
180 | ]; | |
181 | $form->addButtons($buttons); | |
182 | ||
183 | $form->addFormRule(['CRM_Core_Form_Task_PDFLetterCommon', 'formRule'], $form); | |
184 | } | |
185 | ||
c97bfeff EM |
186 | /** |
187 | * Prepare form. | |
188 | */ | |
189 | public function preProcessPDF(): void { | |
190 | $form = $this; | |
191 | $defaults = []; | |
192 | $form->_fromEmails = CRM_Core_BAO_Email::getFromEmail(); | |
193 | if (is_numeric(key($form->_fromEmails))) { | |
194 | $emailID = (int) key($form->_fromEmails); | |
195 | $defaults = CRM_Core_BAO_Email::getEmailSignatureDefaults($emailID); | |
196 | } | |
197 | if (!Civi::settings()->get('allow_mail_from_logged_in_contact')) { | |
198 | $defaults['from_email_address'] = current(CRM_Core_BAO_Domain::getNameAndEmail(FALSE, TRUE)); | |
199 | } | |
200 | $form->setDefaults($defaults); | |
201 | $form->setTitle('Print/Merge Document'); | |
202 | } | |
203 | ||
fc34a273 | 204 | } |