3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
36 * This class provides the functionality to email a group of
39 class CRM_Contribute_Form_Task_PDF
extends CRM_Contribute_Form_Task
{
42 * Are we operating in "single mode", i.e. updating the task of only
43 * one specific contribution?
47 public $_single = FALSE;
52 * build all the data structures needed to build the form
56 */ function preProcess() {
57 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
62 $this->_contributionIds
= array($id);
63 $this->_componentClause
= " civicrm_contribution.id IN ( $id ) ";
64 $this->_single
= TRUE;
65 $this->assign('totalSelectedContributions', 1);
71 // check that all the contribution ids have pending status
74 FROM civicrm_contribution
75 WHERE contribution_status_id != 1
76 AND {$this->_componentClause}";
77 $count = CRM_Core_DAO
::singleValueQuery($query);
79 CRM_Core_Error
::statusBounce("Please select only online contributions with Completed status.");
82 // we have all the contribution ids, so now we get the contact ids
83 parent
::setContactIDs();
84 $this->assign('single', $this->_single
);
86 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', $this);
87 $urlParams = 'force=1';
88 if (CRM_Utils_Rule
::qfKey($qfKey)) {
89 $urlParams .= "&qfKey=$qfKey";
92 $url = CRM_Utils_System
::url('civicrm/contribute/search', $urlParams);
95 'title' => ts('Search Results'),
98 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
99 CRM_Utils_System
::setTitle(ts('Print Contribution Receipts'));
109 public function buildQuickForm() {
111 $this->addElement('radio', 'output', NULL, ts('Email Receipts'), 'email_receipt',
112 array('onClick' => "document.getElementById('selectPdfFormat').style.display = 'none';")
114 $this->addElement('radio', 'output', NULL, ts('PDF Receipts'), 'pdf_receipt',
115 array('onClick' => "document.getElementById('selectPdfFormat').style.display = 'block';")
117 $this->addRule('output', ts('Selection required'), 'required');
119 $this->add('select', 'pdf_format_id', ts('Page Format'),
120 array(0 => ts('- default -')) + CRM_Core_BAO_PdfFormat
::getList(TRUE)
123 $this->addButtons(array(
126 'name' => ts('Process Receipt(s)'),
131 'name' => ts('Cancel'),
140 function setDefaultValues() {
141 $defaultFormat = CRM_Core_BAO_PdfFormat
::getDefaultValues();
142 return array('pdf_format_id' => $defaultFormat['id']);
146 * process the form after the input has been submitted and validated
152 public function postProcess() {
153 // get all the details needed to generate a receipt
154 $contribIDs = implode(',', $this->_contributionIds
);
156 $details = CRM_Contribute_Form_Task_Status
::getDetails($contribIDs);
158 $baseIPN = new CRM_Core_Payment_BaseIPN();
161 $template = CRM_Core_Smarty
::singleton();
163 $params = $this->controller
->exportValues($this->_name
);
166 if ($params['output'] == "pdf_receipt") {
170 $excludeContactIds = array();
172 $returnProperties = array(
179 list($contactDetails) = CRM_Utils_Token
::getTokenDetails($this->_contactIds
, $returnProperties, FALSE, FALSE);
180 $suppressedEmails = 0;
181 foreach ($contactDetails as $id => $values) {
182 if (empty($values['email']) ||
!empty($values['do_not_email']) ||
183 CRM_Utils_Array
::value('is_deceased', $values) ||
!empty($values['on_hold'])) {
185 $excludeContactIds[] = $values['contact_id'];
190 foreach ($details as $contribID => $detail) {
191 $input = $ids = $objects = array();
193 if (in_array($detail['contact'], $excludeContactIds)) {
197 $input['component'] = $detail['component'];
199 $ids['contact'] = $detail['contact'];
200 $ids['contribution'] = $contribID;
201 $ids['contributionRecur'] = NULL;
202 $ids['contributionPage'] = NULL;
203 $ids['membership'] = CRM_Utils_Array
::value('membership', $detail);
204 $ids['participant'] = CRM_Utils_Array
::value('participant', $detail);
205 $ids['event'] = CRM_Utils_Array
::value('event', $detail);
207 if (!$baseIPN->validateData($input, $ids, $objects, FALSE)) {
208 CRM_Core_Error
::fatal();
211 $contribution = &$objects['contribution'];
212 // CRM_Core_Error::debug('o',$objects);
215 // set some fake input values so we can reuse IPN code
216 $input['amount'] = $contribution->total_amount
;
217 $input['is_test'] = $contribution->is_test
;
218 $input['fee_amount'] = $contribution->fee_amount
;
219 $input['net_amount'] = $contribution->net_amount
;
220 $input['trxn_id'] = $contribution->trxn_id
;
221 $input['trxn_date'] = isset($contribution->trxn_date
) ?
$contribution->trxn_date
: NULL;
223 // CRM_Contribute_BAO_Contribution::composeMessageArray expects mysql formatted date
224 $objects['contribution']->receive_date
= CRM_Utils_Date
::isoToMysql($objects['contribution']->receive_date
);
226 // CRM_Core_Error::debug('input',$input);
229 $mail = $baseIPN->sendMail($input, $ids, $objects, $values, FALSE, $createPdf);
232 $message[] = $mail['html'];
235 $message[] = nl2br($mail['body']);
238 // reset template values before processing next transactions
239 $template->clearTemplateVars();
242 CRM_Utils_PDF_Utils
::html2pdf($message,
243 'civicrmContributionReceipt.pdf',
245 $params['pdf_format_id']
247 CRM_Utils_System
::civiExit();
250 if ($suppressedEmails) {
251 $status = ts('Email was NOT sent to %1 contacts (no email address on file, or communication preferences specify DO NOT EMAIL, or contact is deceased).', array(1 => $suppressedEmails));
252 $msgTitle = ts('Email Error');
256 $status = ts('Your mail has been sent.');
257 $msgTitle = ts('Sent');
258 $msgType = 'success';
260 CRM_Core_Session
::setStatus($status, $msgTitle, $msgType);