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