comment fixes
[civicrm-core.git] / CRM / Contribute / Form / Task / PDFLetter.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
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
TO
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
186c9c17
EM
75 /**
76 * This virtual function is used to set the default values of
77 * various form elements
78 *
79 * access public
80 *
a6c01b45
CW
81 * @return array
82 * reference to the array of default values
186c9c17
EM
83 */
84 /**
85 * @return array
86 */
00be9182 87 public function setDefaultValues() {
6a488035
TO
88 $defaults = array();
89 if (isset($this->_activityId)) {
90 $params = array('id' => $this->_activityId);
91 CRM_Activity_BAO_Activity::retrieve($params, $defaults);
e7ddc2f9 92 $defaults['html_message'] = CRM_Utils_Array::value('details', $defaults);
6a488035 93 }
b5fd2bef
CW
94 else {
95 $defaults['thankyou_update'] = 1;
96 }
6a488035
TO
97 $defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
98 return $defaults;
99 }
100
101 /**
fe482240 102 * Build the form object.
6a488035
TO
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
383c047b 112 $this->add('static', 'more_options_header', NULL, ts('Thank-you Letter Options'));
6a488035
TO
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);
6a488035
TO
115
116 // Group options for tokens are not yet implemented. dgg
383c047b
DG
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'),
536f0e02 123 'payment_instrument_id' => ts('Contact and Payment Method'),
383c047b
DG
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
481a74f4 127 $separatorOptions = array('comma' => 'Comma', 'td' => 'Table Cell');
383c047b
DG
128 $this->addElement('select', 'group_by_separator', ts('Separator (grouped contributions)'), $separatorOptions);
129 $emailOptions = array(
130 '' => ts('Generate PDFs for printing (only)'),
131 'email' => ts('Send emails where possible. Generate printable PDFs for contacts who cannot receive email.'),
132 'both' => ts('Send emails where possible. Generate printable PDFs for all contacts.'),
383c047b 133 );
353ffa53 134 if (CRM_Core_Config::singleton()->doNotAttachPDFReceipt) {
97eaa51b
EM
135 $emailOptions['pdfemail'] = ts('Send emails with an attached PDF where possible. Generate printable PDFs for contacts who cannot receive email.');
136 $emailOptions['pdfemail_both'] = ts('Send emails with an attached PDF where possible. Generate printable PDFs for all contacts.');
137 }
383c047b 138 $this->addElement('select', 'email_options', ts('Print and email options'), $emailOptions, array(), "<br/>", FALSE);
ed106721 139
6a488035
TO
140 $this->addButtons(array(
141 array(
142 'type' => 'submit',
143 'name' => ts('Make Thank-you Letters'),
144 'isDefault' => TRUE,
145 ),
146 array(
147 'type' => 'cancel',
148 'name' => ts('Done'),
149 ),
150 )
151 );
152
153 }
154
155 /**
fe482240 156 * Process the form after the input has been submitted and validated.
6a488035
TO
157 */
158 public function postProcess() {
6a488035
TO
159 CRM_Contribute_Form_Task_PDFLetterCommon::postProcess($this);
160 }
96025800 161
5ec6b0ad
TM
162 /**
163 * List available tokens for this form.
164 *
165 * @return array
166 */
167 public function listTokens() {
168 $tokens = CRM_Core_SelectValues::contactTokens();
169 return $tokens;
170 }
171
6a488035 172}