[REF] Permit domain tokens being used within Thank You letters
[civicrm-core.git] / CRM / Contribute / Form / Task / PDFLetter.php
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 functionality to create PDF letter for a group of contacts or a single contact.
20 */
21 class CRM_Contribute_Form_Task_PDFLetter extends CRM_Contribute_Form_Task {
22
23 /**
24 * All the existing templates in the system.
25 *
26 * @var array
27 */
28 public $_templates = NULL;
29
30 public $_single = NULL;
31
32 public $_cid = NULL;
33
34 /**
35 * Build all the data structures needed to build the form.
36 */
37 public function preProcess() {
38 $this->skipOnHold = $this->skipDeceased = FALSE;
39 CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
40 // store case id if present
41 $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'CommaSeparatedIntegers', $this, FALSE);
42 if (!empty($this->_caseId) && strpos($this->_caseId, ',')) {
43 $this->_caseIds = explode(',', $this->_caseId);
44 unset($this->_caseId);
45 }
46
47 // retrieve contact ID if this is 'single' mode
48 $cid = CRM_Utils_Request::retrieve('cid', 'CommaSeparatedIntegers', $this, FALSE);
49
50 $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
51
52 if ($cid) {
53 CRM_Contact_Form_Task_PDFLetterCommon::preProcessSingle($this, $cid);
54 $this->_single = TRUE;
55 }
56 else {
57 parent::preProcess();
58 }
59 $this->assign('single', $this->_single);
60 }
61
62 /**
63 * This virtual function is used to set the default values of
64 * various form elements
65 *
66 * access public
67 *
68 * @return array
69 * reference to the array of default values
70 */
71
72 /**
73 * @return array
74 */
75 public function setDefaultValues() {
76 $defaults = [];
77 if (isset($this->_activityId)) {
78 $params = ['id' => $this->_activityId];
79 CRM_Activity_BAO_Activity::retrieve($params, $defaults);
80 $defaults['html_message'] = $defaults['details'] ?? NULL;
81 }
82 else {
83 $defaults['thankyou_update'] = 1;
84 }
85 $defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
86 return $defaults;
87 }
88
89 /**
90 * Build the form object.
91 */
92 public function buildQuickForm() {
93 //enable form element
94 $this->assign('suppressForm', FALSE);
95
96 // Build common form elements
97 CRM_Contribute_Form_Task_PDFLetterCommon::buildQuickForm($this);
98
99 // specific need for contributions
100 $this->add('static', 'more_options_header', NULL, ts('Thank-you Letter Options'));
101 $this->add('checkbox', 'receipt_update', ts('Update receipt dates for these contributions'), FALSE);
102 $this->add('checkbox', 'thankyou_update', ts('Update thank-you dates for these contributions'), FALSE);
103
104 // Group options for tokens are not yet implemented. dgg
105 $options = [
106 '' => ts('- no grouping -'),
107 'contact_id' => ts('Contact'),
108 'contribution_recur_id' => ts('Contact and Recurring'),
109 'financial_type_id' => ts('Contact and Financial Type'),
110 'campaign_id' => ts('Contact and Campaign'),
111 'payment_instrument_id' => ts('Contact and Payment Method'),
112 ];
113 $this->addElement('select', 'group_by', ts('Group contributions by'), $options, [], "<br/>", FALSE);
114 // this was going to be free-text but I opted for radio options in case there was a script injection risk
115 $separatorOptions = ['comma' => 'Comma', 'td' => 'Horizontal Table Cell', 'tr' => 'Vertical Table Cell', 'br' => 'Line Break'];
116
117 $this->addElement('select', 'group_by_separator', ts('Separator (grouped contributions)'), $separatorOptions);
118 $emailOptions = [
119 '' => ts('Generate PDFs for printing (only)'),
120 'email' => ts('Send emails where possible. Generate printable PDFs for contacts who cannot receive email.'),
121 'both' => ts('Send emails where possible. Generate printable PDFs for all contacts.'),
122 ];
123 if (CRM_Core_Config::singleton()->doNotAttachPDFReceipt) {
124 $emailOptions['pdfemail'] = ts('Send emails with an attached PDF where possible. Generate printable PDFs for contacts who cannot receive email.');
125 $emailOptions['pdfemail_both'] = ts('Send emails with an attached PDF where possible. Generate printable PDFs for all contacts.');
126 }
127 $this->addElement('select', 'email_options', ts('Print and email options'), $emailOptions, [], "<br/>", FALSE);
128
129 $this->addButtons([
130 [
131 'type' => 'upload',
132 'name' => ts('Make Thank-you Letters'),
133 'isDefault' => TRUE,
134 ],
135 [
136 'type' => 'cancel',
137 'name' => ts('Done'),
138 ],
139 ]);
140
141 }
142
143 /**
144 * Process the form after the input has been submitted and validated.
145 */
146 public function postProcess() {
147 CRM_Contribute_Form_Task_PDFLetterCommon::postProcess($this);
148 }
149
150 /**
151 * List available tokens for this form.
152 *
153 * @return array
154 */
155 public function listTokens() {
156 $tokens = CRM_Core_SelectValues::contactTokens();
157 $tokens = array_merge(CRM_Core_SelectValues::contributionTokens(), $tokens);
158 $tokens = array_merge(CRM_Core_SelectValues::domainTokens(), $tokens);
159 return $tokens;
160 }
161
162 }