Merge pull request #4812 from colemanw/CRM-15495
[civicrm-core.git] / CRM / Contribute / Form / Contribution / ThankYou.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
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 * form for thank-you / success page - 3rd step of online contribution process
38 */
39class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_ContributionBase {
40
41 /**
100fef9d 42 * Membership price set status
6a488035
TO
43 *
44 */
45 public $_useForMember;
46
47 /**
100fef9d 48 * Set variables up before form is built
6a488035
TO
49 *
50 * @return void
6a488035
TO
51 */
52 public function preProcess() {
53 parent::preProcess();
54
55 $this->_params = $this->get('params');
56 $this->_lineItem = $this->get('lineItem');
57 $is_deductible = $this->get('is_deductible');
58 $this->assign('is_deductible', $is_deductible);
59 $this->assign('thankyou_title', CRM_Utils_Array::value('thankyou_title', $this->_values));
60 $this->assign('thankyou_text', CRM_Utils_Array::value('thankyou_text', $this->_values));
61 $this->assign('thankyou_footer', CRM_Utils_Array::value('thankyou_footer', $this->_values));
62 $this->assign('max_reminders', CRM_Utils_Array::value('max_reminders', $this->_values));
63 $this->assign('initial_reminder_day', CRM_Utils_Array::value('initial_reminder_day', $this->_values));
64 CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->_values));
f4aaa82a 65 // Make the contributionPageID available to the template
6a488035
TO
66 $this->assign('contributionPageID', $this->_id);
67 $this->assign('isShare', $this->_values['is_share']);
68
69 $this->_params['is_pay_later'] = $this->get('is_pay_later');
70 $this->assign('is_pay_later', $this->_params['is_pay_later']);
71 if ($this->_params['is_pay_later']) {
72 $this->assign('pay_later_receipt', $this->_values['pay_later_receipt']);
73 }
74 }
75
76 /**
100fef9d 77 * Overwrite action, since we are only showing elements in frozen mode
6a488035
TO
78 * no help display needed
79 *
80 * @return int
6a488035 81 */
00be9182 82 public function getAction() {
6a488035
TO
83 if ($this->_action & CRM_Core_Action::PREVIEW) {
84 return CRM_Core_Action::VIEW | CRM_Core_Action::PREVIEW;
85 }
86 else {
87 return CRM_Core_Action::VIEW;
88 }
89 }
90
91 /**
c490a46a 92 * Build the form object
6a488035
TO
93 *
94 * @return void
6a488035
TO
95 */
96 public function buildQuickForm() {
97 $this->assignToTemplate();
98 $productID = $this->get('productID');
99 $option = $this->get('option');
100 $membershipTypeID = $this->get('membershipTypeID');
101 $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
102
103 if ($productID) {
104 CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option);
105 }
9da8dc8c 106 if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
6a488035
TO
107 $this->assign('lineItem', $this->_lineItem);
108 } else {
109 if (is_array($membershipTypeID)) {
110 $membershipTypeID = current($membershipTypeID);
111 }
112 $this->assign('is_quick_config', 1);
113 $this->_params['is_quick_config'] = 1;
114 }
115 $this->assign('priceSetID', $this->_priceSetId);
116 $this->assign('useForMember', $this->get('useForMember'));
117
118 $params = $this->_params;
03b412ae
PB
119 $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,'contribution_invoice_settings');
120 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
121 if ($invoicing) {
122 $getTaxDetails = FALSE;
123 $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
124 foreach ($this->_lineItem as $key => $value) {
125 foreach ($value as $v) {
126 if (isset($v['tax_rate'])) {
127 if ($v['tax_rate'] != '') {
128 $getTaxDetails = TRUE;
129 }
130 }
131 }
132 }
133 $this->assign('getTaxDetails', $getTaxDetails);
134 $this->assign('taxTerm', $taxTerm);
135 $this->assign('totalTaxAmount', $params['tax_amount']);
136 }
8af73472 137 if ($this->_honor_block_is_active && !empty($params['soft_credit_type_id'])) {
133e2c99 138 $honorName = null;
139 $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
140
8af73472 141 $this->assign('honor_block_is_active', $this->_honor_block_is_active);
133e2c99 142 $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]);
1421174e 143 CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']);
6a488035 144
133e2c99 145 $fieldTypes = array('Contact');
146 $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']);
147 $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
6a488035
TO
148 }
149
150 $qParams = "reset=1&amp;id={$this->_id}";
151 //pcp elements
152 if ($this->_pcpId) {
153 $qParams .= "&amp;pcpId={$this->_pcpId}";
154 $this->assign('pcpBlock', TRUE);
155 foreach (array(
156 'pcp_display_in_roll', 'pcp_is_anonymous', 'pcp_roll_nickname', 'pcp_personal_note') as $val) {
a7488080 157 if (!empty($this->_params[$val])) {
6a488035
TO
158 $this->assign($val, $this->_params[$val]);
159 }
160 }
161 }
162
163 $this->assign( 'qParams' , $qParams );
164
165 if ($membershipTypeID) {
166 $transactionID = $this->get('membership_trx_id');
167 $membershipAmount = $this->get('membership_amount');
168 $renewalMode = $this->get('renewal_mode');
169 $this->assign('membership_trx_id', $transactionID);
170 $this->assign('membership_amount', $membershipAmount);
171 $this->assign('renewal_mode', $renewalMode);
172
173 CRM_Member_BAO_Membership::buildMembershipBlock($this,
174 $this->_id,
5b757295 175 $this->_membershipContactID,
6a488035
TO
176 FALSE,
177 $membershipTypeID,
5b757295 178 TRUE,
179 NULL
6a488035
TO
180 );
181 }
182
183 $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
184 $this->assign("is_separate_payment", $this->_separateMembershipPayment);
185
186 $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
187 $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
a7488080 188 if (!empty($params['hidden_onbehalf_profile'])) {
6a488035
TO
189 $ufJoinParams = array(
190 'module' => 'onBehalf',
191 'entity_table' => 'civicrm_contribution_page',
192 'entity_id' => $this->_id,
193 );
194 $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
195 $profileId = $OnBehalfProfile[0];
196
197 $fieldTypes = array('Contact', 'Organization');
198 $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
199 $fieldTypes = array_merge($fieldTypes, $contactSubType);
200 if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) {
201 $fieldTypes = array_merge($fieldTypes, array('Membership'));
202 }
203 else {
204 $fieldTypes = array_merge($fieldTypes, array('Contribution'));
205 }
206
133e2c99 207 $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
6a488035
TO
208 }
209
210 $this->assign('trxn_id',
211 CRM_Utils_Array::value('trxn_id',
212 $this->_params
213 )
214 );
215 $this->assign('receive_date',
216 CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params))
217 );
218
219 $defaults = array();
220 $fields = array();
221 foreach ($this->_fields as $name => $dontCare) {
133e2c99 222 if ($name != 'onbehalf' || $name != 'honor') {
6a488035
TO
223 $fields[$name] = 1;
224 }
225 }
226 $fields['state_province'] = $fields['country'] = $fields['email'] = 1;
227 $contact = $this->_params = $this->controller->exportValues('Main');
228
229 foreach ($fields as $name => $dontCare) {
133e2c99 230 if (isset($contact[$name])) {
6a488035
TO
231 $defaults[$name] = $contact[$name];
232 if (substr($name, 0, 7) == 'custom_') {
233 $timeField = "{$name}_time";
234 if (isset($contact[$timeField])) {
235 $defaults[$timeField] = $contact[$timeField];
236 }
237 }
8cc574cf 238 elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) {
6a488035
TO
239 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
240 }
241 }
242 }
243
6a488035
TO
244 $this->_submitValues = array_merge($this->_submitValues, $defaults);
245 $this->setDefaults($defaults);
eea16664 246
6a488035
TO
247 $values['entity_id'] = $this->_id;
248 $values['entity_table'] = 'civicrm_contribution_page';
249
250 CRM_Friend_BAO_Friend::retrieve($values, $data);
251 $tellAFriend = FALSE;
252 if ($this->_pcpId) {
253 if ($this->_pcpBlock['is_tellfriend_enabled']) {
254 $this->assign('friendText', ts('Tell a Friend'));
255 $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp";
256 $tellAFriend = TRUE;
257 }
258 }
a7488080 259 elseif (!empty($data['is_active'])) {
6a488035
TO
260 $friendText = $data['title'];
261 $this->assign('friendText', $friendText);
262 $subUrl = "eid={$this->_id}&pcomponent=contribute";
263 $tellAFriend = TRUE;
264 }
265
266 if ($tellAFriend) {
267 if ($this->_action & CRM_Core_Action::PREVIEW) {
268 $url = CRM_Utils_System::url("civicrm/friend",
269 "reset=1&action=preview&{$subUrl}"
270 );
271 }
272 else {
273 $url = CRM_Utils_System::url("civicrm/friend",
274 "reset=1&{$subUrl}"
275 );
276 }
277 $this->assign('friendURL', $url);
278 }
279
280 $this->freeze();
281
282 // can we blow away the session now to prevent hackery
283 // CRM-9491
284 $this->controller->reset();
285 }
286}