Set version to 5.13.beta1
[civicrm-core.git] / CRM / Contribute / Form / Task / PDFLetter.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
6b83d5bd 31 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
32 */
33
34/**
07f8d162 35 * This class provides the functionality to create PDF letter for a group of contacts or a single contact.
6a488035
TO
36 */
37class CRM_Contribute_Form_Task_PDFLetter extends CRM_Contribute_Form_Task {
38
39 /**
fe482240 40 * All the existing templates in the system.
6a488035
TO
41 *
42 * @var array
43 */
44 public $_templates = NULL;
45
46 public $_single = NULL;
47
48 public $_cid = NULL;
49
50 /**
fe482240 51 * Build all the data structures needed to build the form.
ed106721 52 */
00be9182 53 public function preProcess() {
6a488035
TO
54 $this->skipOnHold = $this->skipDeceased = FALSE;
55 CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
6a488035 56 // store case id if present
fe61faf3
CW
57 $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'CommaSeparatedIntegers', $this, FALSE);
58 if (!empty($this->_caseId) && strpos($this->_caseId, ',')) {
59 $this->_caseIds = explode(',', $this->_caseId);
60 unset($this->_caseId);
61 }
6a488035
TO
62
63 // retrieve contact ID if this is 'single' mode
fe61faf3 64 $cid = CRM_Utils_Request::retrieve('cid', 'CommaSeparatedIntegers', $this, FALSE);
6a488035
TO
65
66 $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
67
68 if ($cid) {
69 CRM_Contact_Form_Task_PDFLetterCommon::preProcessSingle($this, $cid);
70 $this->_single = TRUE;
6a488035
TO
71 }
72 else {
73 parent::preProcess();
74 }
75 $this->assign('single', $this->_single);
76 }
77
186c9c17
EM
78 /**
79 * This virtual function is used to set the default values of
80 * various form elements
81 *
82 * access public
83 *
a6c01b45
CW
84 * @return array
85 * reference to the array of default values
186c9c17
EM
86 */
87 /**
88 * @return array
89 */
00be9182 90 public function setDefaultValues() {
be2fb01f 91 $defaults = [];
6a488035 92 if (isset($this->_activityId)) {
be2fb01f 93 $params = ['id' => $this->_activityId];
6a488035 94 CRM_Activity_BAO_Activity::retrieve($params, $defaults);
e7ddc2f9 95 $defaults['html_message'] = CRM_Utils_Array::value('details', $defaults);
6a488035 96 }
b5fd2bef
CW
97 else {
98 $defaults['thankyou_update'] = 1;
99 }
6a488035
TO
100 $defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
101 return $defaults;
102 }
103
104 /**
fe482240 105 * Build the form object.
6a488035
TO
106 */
107 public function buildQuickForm() {
108 //enable form element
109 $this->assign('suppressForm', FALSE);
110
99ad38df
MW
111 // Build common form elements
112 CRM_Contribute_Form_Task_PDFLetterCommon::buildQuickForm($this);
6a488035
TO
113
114 // specific need for contributions
383c047b 115 $this->add('static', 'more_options_header', NULL, ts('Thank-you Letter Options'));
6a488035
TO
116 $this->add('checkbox', 'receipt_update', ts('Update receipt dates for these contributions'), FALSE);
117 $this->add('checkbox', 'thankyou_update', ts('Update thank-you dates for these contributions'), FALSE);
6a488035
TO
118
119 // Group options for tokens are not yet implemented. dgg
be2fb01f 120 $options = [
383c047b
DG
121 '' => ts('- no grouping -'),
122 'contact_id' => ts('Contact'),
123 'contribution_recur_id' => ts('Contact and Recurring'),
124 'financial_type_id' => ts('Contact and Financial Type'),
125 'campaign_id' => ts('Contact and Campaign'),
536f0e02 126 'payment_instrument_id' => ts('Contact and Payment Method'),
be2fb01f
CW
127 ];
128 $this->addElement('select', 'group_by', ts('Group contributions by'), $options, [], "<br/>", FALSE);
383c047b 129 // this was going to be free-text but I opted for radio options in case there was a script injection risk
be2fb01f 130 $separatorOptions = ['comma' => 'Comma', 'td' => 'Horizontal Table Cell', 'tr' => 'Vertical Table Cell', 'br' => 'Line Break'];
698253db 131
383c047b 132 $this->addElement('select', 'group_by_separator', ts('Separator (grouped contributions)'), $separatorOptions);
be2fb01f 133 $emailOptions = [
383c047b
DG
134 '' => ts('Generate PDFs for printing (only)'),
135 'email' => ts('Send emails where possible. Generate printable PDFs for contacts who cannot receive email.'),
136 'both' => ts('Send emails where possible. Generate printable PDFs for all contacts.'),
be2fb01f 137 ];
353ffa53 138 if (CRM_Core_Config::singleton()->doNotAttachPDFReceipt) {
97eaa51b
EM
139 $emailOptions['pdfemail'] = ts('Send emails with an attached PDF where possible. Generate printable PDFs for contacts who cannot receive email.');
140 $emailOptions['pdfemail_both'] = ts('Send emails with an attached PDF where possible. Generate printable PDFs for all contacts.');
141 }
be2fb01f 142 $this->addElement('select', 'email_options', ts('Print and email options'), $emailOptions, [], "<br/>", FALSE);
ed106721 143
be2fb01f
CW
144 $this->addButtons([
145 [
59d861cb 146 'type' => 'upload',
6a488035
TO
147 'name' => ts('Make Thank-you Letters'),
148 'isDefault' => TRUE,
be2fb01f
CW
149 ],
150 [
6a488035
TO
151 'type' => 'cancel',
152 'name' => ts('Done'),
be2fb01f
CW
153 ],
154 ]
6a488035
TO
155 );
156
157 }
158
159 /**
fe482240 160 * Process the form after the input has been submitted and validated.
6a488035
TO
161 */
162 public function postProcess() {
6a488035
TO
163 CRM_Contribute_Form_Task_PDFLetterCommon::postProcess($this);
164 }
96025800 165
5ec6b0ad
TM
166 /**
167 * List available tokens for this form.
168 *
169 * @return array
170 */
171 public function listTokens() {
172 $tokens = CRM_Core_SelectValues::contactTokens();
8ee05f69 173 $tokens = array_merge(CRM_Core_SelectValues::contributionTokens(), $tokens);
5ec6b0ad
TM
174 return $tokens;
175 }
176
6a488035 177}