Merge pull request #5593 from relldoesphp/CRM-15992
[civicrm-core.git] / CRM / Contribute / Form / Task / PDFLetter.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
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.
6a488035
TO
52 *
53 * @return void
ed106721 54 */
00be9182 55 public function preProcess() {
6a488035
TO
56 $this->skipOnHold = $this->skipDeceased = FALSE;
57 CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
6a488035
TO
58 // store case id if present
59 $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'Positive', $this, FALSE);
60
61 // retrieve contact ID if this is 'single' mode
62 $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
63
64 $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
65
66 if ($cid) {
67 CRM_Contact_Form_Task_PDFLetterCommon::preProcessSingle($this, $cid);
68 $this->_single = TRUE;
69 $this->_cid = $cid;
70 }
71 else {
72 parent::preProcess();
73 }
74 $this->assign('single', $this->_single);
75 }
76
186c9c17
EM
77 /**
78 * This virtual function is used to set the default values of
79 * various form elements
80 *
81 * access public
82 *
a6c01b45
CW
83 * @return array
84 * reference to the array of default values
186c9c17
EM
85 */
86 /**
87 * @return array
88 */
00be9182 89 public function setDefaultValues() {
6a488035
TO
90 $defaults = array();
91 if (isset($this->_activityId)) {
92 $params = array('id' => $this->_activityId);
93 CRM_Activity_BAO_Activity::retrieve($params, $defaults);
e7ddc2f9 94 $defaults['html_message'] = CRM_Utils_Array::value('details', $defaults);
6a488035 95 }
b5fd2bef
CW
96 else {
97 $defaults['thankyou_update'] = 1;
98 }
6a488035
TO
99 $defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
100 return $defaults;
101 }
102
103 /**
fe482240 104 * Build the form object.
6a488035 105 *
6a488035
TO
106 *
107 * @return void
108 */
109 public function buildQuickForm() {
110 //enable form element
111 $this->assign('suppressForm', FALSE);
112
113 // use contact form as a base
114 CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this);
115
116 // specific need for contributions
383c047b 117 $this->add('static', 'more_options_header', NULL, ts('Thank-you Letter Options'));
6a488035
TO
118 $this->add('checkbox', 'receipt_update', ts('Update receipt dates for these contributions'), FALSE);
119 $this->add('checkbox', 'thankyou_update', ts('Update thank-you dates for these contributions'), FALSE);
6a488035
TO
120
121 // Group options for tokens are not yet implemented. dgg
383c047b
DG
122 $options = array(
123 '' => ts('- no grouping -'),
124 'contact_id' => ts('Contact'),
125 'contribution_recur_id' => ts('Contact and Recurring'),
126 'financial_type_id' => ts('Contact and Financial Type'),
127 'campaign_id' => ts('Contact and Campaign'),
128 'payment_instrument_id' => 'Contact and Payment Instrument',
129 );
130 $this->addElement('select', 'group_by', ts('Group contributions by'), $options, array(), "<br/>", FALSE);
131 // this was going to be free-text but I opted for radio options in case there was a script injection risk
481a74f4 132 $separatorOptions = array('comma' => 'Comma', 'td' => 'Table Cell');
383c047b
DG
133 $this->addElement('select', 'group_by_separator', ts('Separator (grouped contributions)'), $separatorOptions);
134 $emailOptions = array(
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.'),
383c047b 138 );
353ffa53 139 if (CRM_Core_Config::singleton()->doNotAttachPDFReceipt) {
97eaa51b
EM
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.');
142 }
383c047b 143 $this->addElement('select', 'email_options', ts('Print and email options'), $emailOptions, array(), "<br/>", FALSE);
ed106721 144
6a488035
TO
145 $this->addButtons(array(
146 array(
147 'type' => 'submit',
148 'name' => ts('Make Thank-you Letters'),
149 'isDefault' => TRUE,
150 ),
151 array(
152 'type' => 'cancel',
153 'name' => ts('Done'),
154 ),
155 )
156 );
157
158 }
159
160 /**
fe482240 161 * Process the form after the input has been submitted and validated.
6a488035 162 *
6a488035 163 *
355ba699 164 * @return void
6a488035
TO
165 */
166 public function postProcess() {
6a488035
TO
167 CRM_Contribute_Form_Task_PDFLetterCommon::postProcess($this);
168 }
96025800 169
6a488035 170}