3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class provides the functionality to create PDF letter for a group of contacts or a single contact.
21 class CRM_Contribute_Form_Task_PDFLetter
extends CRM_Contribute_Form_Task
{
24 * All the existing templates in the system.
28 public $_templates = NULL;
30 public $_single = NULL;
35 * Build all the data structures needed to build the form.
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
);
47 // retrieve contact ID if this is 'single' mode
48 $cid = CRM_Utils_Request
::retrieve('cid', 'CommaSeparatedIntegers', $this, FALSE);
50 $this->_activityId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE);
53 CRM_Contact_Form_Task_PDFLetterCommon
::preProcessSingle($this, $cid);
54 $this->_single
= TRUE;
59 $this->assign('single', $this->_single
);
63 * This virtual function is used to set the default values of
64 * various form elements
69 * reference to the array of default values
75 public function setDefaultValues() {
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;
83 $defaults['thankyou_update'] = 1;
85 $defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon
::setDefaultValues();
90 * Build the form object.
92 public function buildQuickForm() {
94 $this->assign('suppressForm', FALSE);
96 // Build common form elements
97 CRM_Contribute_Form_Task_PDFLetterCommon
::buildQuickForm($this);
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);
104 // Group options for tokens are not yet implemented. dgg
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'),
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'];
117 $this->addElement('select', 'group_by_separator', ts('Separator (grouped contributions)'), $separatorOptions);
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.'),
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.');
127 $this->addElement('select', 'email_options', ts('Print and email options'), $emailOptions, [], "<br/>", FALSE);
132 'name' => ts('Make Thank-you Letters'),
137 'name' => ts('Done'),
144 * Process the form after the input has been submitted and validated.
146 public function postProcess() {
147 CRM_Contribute_Form_Task_PDFLetterCommon
::postProcess($this);
151 * List available tokens for this form.
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);