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