3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
35 * This class provides the functionality to create PDF letter for a group of contacts or a single contact.
37 class CRM_Contribute_Form_Task_PDFLetter
extends CRM_Contribute_Form_Task
{
40 * All the existing templates in the system.
44 public $_templates = NULL;
46 public $_single = NULL;
51 * Build all the data structures needed to build the form.
53 public function preProcess() {
54 $this->skipOnHold
= $this->skipDeceased
= FALSE;
55 CRM_Contact_Form_Task_PDFLetterCommon
::preProcess($this);
56 // store case id if present
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
);
63 // retrieve contact ID if this is 'single' mode
64 $cid = CRM_Utils_Request
::retrieve('cid', 'CommaSeparatedIntegers', $this, FALSE);
66 $this->_activityId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE);
69 CRM_Contact_Form_Task_PDFLetterCommon
::preProcessSingle($this, $cid);
70 $this->_single
= TRUE;
75 $this->assign('single', $this->_single
);
79 * This virtual function is used to set the default values of
80 * various form elements
85 * reference to the array of default values
91 public function setDefaultValues() {
93 if (isset($this->_activityId
)) {
94 $params = ['id' => $this->_activityId
];
95 CRM_Activity_BAO_Activity
::retrieve($params, $defaults);
96 $defaults['html_message'] = CRM_Utils_Array
::value('details', $defaults);
99 $defaults['thankyou_update'] = 1;
101 $defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon
::setDefaultValues();
106 * Build the form object.
108 public function buildQuickForm() {
109 //enable form element
110 $this->assign('suppressForm', FALSE);
112 // Build common form elements
113 CRM_Contribute_Form_Task_PDFLetterCommon
::buildQuickForm($this);
115 // specific need for contributions
116 $this->add('static', 'more_options_header', NULL, ts('Thank-you Letter Options'));
117 $this->add('checkbox', 'receipt_update', ts('Update receipt dates for these contributions'), FALSE);
118 $this->add('checkbox', 'thankyou_update', ts('Update thank-you dates for these contributions'), FALSE);
120 // Group options for tokens are not yet implemented. dgg
122 '' => ts('- no grouping -'),
123 'contact_id' => ts('Contact'),
124 'contribution_recur_id' => ts('Contact and Recurring'),
125 'financial_type_id' => ts('Contact and Financial Type'),
126 'campaign_id' => ts('Contact and Campaign'),
127 'payment_instrument_id' => ts('Contact and Payment Method'),
129 $this->addElement('select', 'group_by', ts('Group contributions by'), $options, [], "<br/>", FALSE);
130 // this was going to be free-text but I opted for radio options in case there was a script injection risk
131 $separatorOptions = ['comma' => 'Comma', 'td' => 'Horizontal Table Cell', 'tr' => 'Vertical Table Cell', 'br' => 'Line Break'];
133 $this->addElement('select', 'group_by_separator', ts('Separator (grouped contributions)'), $separatorOptions);
135 '' => ts('Generate PDFs for printing (only)'),
136 'email' => ts('Send emails where possible. Generate printable PDFs for contacts who cannot receive email.'),
137 'both' => ts('Send emails where possible. Generate printable PDFs for all contacts.'),
139 if (CRM_Core_Config
::singleton()->doNotAttachPDFReceipt
) {
140 $emailOptions['pdfemail'] = ts('Send emails with an attached PDF where possible. Generate printable PDFs for contacts who cannot receive email.');
141 $emailOptions['pdfemail_both'] = ts('Send emails with an attached PDF where possible. Generate printable PDFs for all contacts.');
143 $this->addElement('select', 'email_options', ts('Print and email options'), $emailOptions, [], "<br/>", FALSE);
148 'name' => ts('Make Thank-you Letters'),
153 'name' => ts('Done'),
160 * Process the form after the input has been submitted and validated.
162 public function postProcess() {
163 CRM_Contribute_Form_Task_PDFLetterCommon
::postProcess($this);
167 * List available tokens for this form.
171 public function listTokens() {
172 $tokens = CRM_Core_SelectValues
::contactTokens();
173 $tokens = array_merge(CRM_Core_SelectValues
::contributionTokens(), $tokens);