Merge pull request #11956 from MiyaNoctem/CRM-50-sub-tabs-for-contributions
[civicrm-core.git] / CRM / Contribute / Form / Contribution / ThankYou.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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
31 * @copyright CiviCRM LLC (c) 2004-2018
32 */
33
34 /**
35 * Form for thank-you / success page - 3rd step of online contribution process.
36 */
37 class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_ContributionBase {
38
39 /**
40 * Membership price set status.
41 */
42 public $_useForMember;
43
44 /**
45 * Tranxaaction Id of the current contribution
46 */
47 public $_trxnId;
48
49 /**
50 * Set variables up before form is built.
51 */
52 public function preProcess() {
53 parent::preProcess();
54
55 $this->_params = $this->get('params');
56 $this->_lineItem = $this->get('lineItem');
57 $this->_useForMember = $this->get('useForMember');
58 $is_deductible = $this->get('is_deductible');
59 $this->assign('is_deductible', $is_deductible);
60 $this->assign('thankyou_title', CRM_Utils_Array::value('thankyou_title', $this->_values));
61 $this->assign('thankyou_text', CRM_Utils_Array::value('thankyou_text', $this->_values));
62 $this->assign('thankyou_footer', CRM_Utils_Array::value('thankyou_footer', $this->_values));
63 $this->assign('max_reminders', CRM_Utils_Array::value('max_reminders', $this->_values));
64 $this->assign('initial_reminder_day', CRM_Utils_Array::value('initial_reminder_day', $this->_values));
65 CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->_values));
66 // Make the contributionPageID available to the template
67 $this->assign('contributionPageID', $this->_id);
68 $this->assign('isShare', $this->_values['is_share']);
69
70 $this->_params['is_pay_later'] = $this->get('is_pay_later');
71 $this->assign('is_pay_later', $this->_params['is_pay_later']);
72 if ($this->_params['is_pay_later']) {
73 $this->assign('pay_later_receipt', $this->_values['pay_later_receipt']);
74 }
75 $this->assign('is_for_organization', CRM_Utils_Array::value('is_for_organization', $this->_params));
76 }
77
78 /**
79 * Overwrite action, since we are only showing elements in frozen mode
80 * no help display needed
81 *
82 * @return int
83 */
84 public function getAction() {
85 if ($this->_action & CRM_Core_Action::PREVIEW) {
86 return CRM_Core_Action::VIEW | CRM_Core_Action::PREVIEW;
87 }
88 else {
89 return CRM_Core_Action::VIEW;
90 }
91 }
92
93 /**
94 * Build the form object.
95 */
96 public function buildQuickForm() {
97 // FIXME: Some of this code is identical to Confirm.php and should be broken out into a shared function
98 $this->assignToTemplate();
99 $this->_ccid = $this->get('ccid');
100 $productID = $this->get('productID');
101 $option = $this->get('option');
102 $membershipTypeID = $this->get('membershipTypeID');
103 $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
104
105 if ($productID) {
106 CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option);
107 }
108
109 $params = $this->_params;
110 $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
111 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
112 // Make a copy of line items array to use for display only
113 $tplLineItems = $this->_lineItem;
114 if ($invoicing) {
115 $getTaxDetails = FALSE;
116 $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
117 foreach ($this->_lineItem as $key => $value) {
118 foreach ($value as $k => $v) {
119 if (isset($v['tax_rate'])) {
120 if ($v['tax_rate'] != '') {
121 $getTaxDetails = TRUE;
122 // Cast to float to display without trailing zero decimals
123 $tplLineItems[$key][$k]['tax_rate'] = (float) $v['tax_rate'];
124 }
125 }
126 }
127 }
128 $this->assign('getTaxDetails', $getTaxDetails);
129 $this->assign('taxTerm', $taxTerm);
130 $this->assign('totalTaxAmount', $params['tax_amount']);
131 }
132
133 if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
134 $this->assign('lineItem', $tplLineItems);
135 }
136 else {
137 if (is_array($membershipTypeID)) {
138 $membershipTypeID = current($membershipTypeID);
139 }
140 $this->assign('is_quick_config', 1);
141 $this->_params['is_quick_config'] = 1;
142 }
143 $this->assign('priceSetID', $this->_priceSetId);
144 $this->assign('useForMember', $this->get('useForMember'));
145
146 if (!empty($this->_values['honoree_profile_id']) && !empty($params['soft_credit_type_id'])) {
147 $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
148
149 $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]);
150 CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor']);
151
152 $fieldTypes = array('Contact');
153 $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($this->_values['honoree_profile_id']);
154 $this->buildCustom($this->_values['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
155 }
156
157 $qParams = "reset=1&amp;id={$this->_id}";
158 //pcp elements
159 if ($this->_pcpId) {
160 $qParams .= "&amp;pcpId={$this->_pcpId}";
161 $this->assign('pcpBlock', TRUE);
162 foreach (array(
163 'pcp_display_in_roll',
164 'pcp_is_anonymous',
165 'pcp_roll_nickname',
166 'pcp_personal_note',
167 ) as $val) {
168 if (!empty($this->_params[$val])) {
169 $this->assign($val, $this->_params[$val]);
170 }
171 }
172 }
173
174 $this->assign('qParams', $qParams);
175
176 if ($membershipTypeID) {
177 $transactionID = $this->get('membership_trx_id');
178 $membershipAmount = $this->get('membership_amount');
179 $renewalMode = $this->get('renewal_mode');
180 $this->assign('membership_trx_id', $transactionID);
181 $this->assign('membership_amount', $membershipAmount);
182 $this->assign('renewal_mode', $renewalMode);
183
184 $this->buildMembershipBlock(
185 $this->_membershipContactID,
186 FALSE,
187 $membershipTypeID,
188 TRUE,
189 NULL
190 );
191
192 if (!empty($params['auto_renew'])) {
193 $this->assign('auto_renew', TRUE);
194 }
195 }
196
197 $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
198 $this->assign("is_separate_payment", $this->_separateMembershipPayment);
199
200 if (empty($this->_ccid)) {
201 $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
202 $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
203 }
204 if (!empty($this->_values['onbehalf_profile_id']) &&
205 !empty($params['onbehalf']) &&
206 ($this->_values['is_for_organization'] == 2 ||
207 !empty($params['is_for_organization'])
208 ) && empty($this->_ccid)
209 ) {
210 $fieldTypes = array('Contact', 'Organization');
211 $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
212 $fieldTypes = array_merge($fieldTypes, $contactSubType);
213 if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) {
214 $fieldTypes = array_merge($fieldTypes, array('Membership'));
215 }
216 else {
217 $fieldTypes = array_merge($fieldTypes, array('Contribution'));
218 }
219
220 $this->buildCustom($this->_values['onbehalf_profile_id'], 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
221 }
222
223 $this->_trxnId = CRM_Utils_Array::value('trxn_id', $this->_params);
224
225 $this->assign('trxn_id', $this->_trxnId);
226
227 $this->assign('receive_date',
228 CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params))
229 );
230
231 $defaults = array();
232 $fields = array();
233 foreach ($this->_fields as $name => $dontCare) {
234 if ($name != 'onbehalf' || $name != 'honor') {
235 $fields[$name] = 1;
236 }
237 }
238 $fields['state_province'] = $fields['country'] = $fields['email'] = 1;
239 $contact = $this->_params = $this->controller->exportValues('Main');
240
241 foreach ($fields as $name => $dontCare) {
242 if (isset($contact[$name])) {
243 $defaults[$name] = $contact[$name];
244 if (substr($name, 0, 7) == 'custom_') {
245 $timeField = "{$name}_time";
246 if (isset($contact[$timeField])) {
247 $defaults[$timeField] = $contact[$timeField];
248 }
249 }
250 elseif (in_array($name, array(
251 'addressee',
252 'email_greeting',
253 'postal_greeting',
254 )) && !empty($contact[$name . '_custom'])
255 ) {
256 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
257 }
258 }
259 }
260
261 $this->_submitValues = array_merge($this->_submitValues, $defaults);
262
263 $this->setDefaults($defaults);
264
265 $values['entity_id'] = $this->_id;
266 $values['entity_table'] = 'civicrm_contribution_page';
267
268 CRM_Friend_BAO_Friend::retrieve($values, $data);
269 $tellAFriend = FALSE;
270 if ($this->_pcpId) {
271 if ($this->_pcpBlock['is_tellfriend_enabled']) {
272 $this->assign('friendText', ts('Tell a Friend'));
273 $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp";
274 $tellAFriend = TRUE;
275 }
276 }
277 elseif (!empty($data['is_active'])) {
278 $friendText = $data['title'];
279 $this->assign('friendText', $friendText);
280 $subUrl = "eid={$this->_id}&pcomponent=contribute";
281 $tellAFriend = TRUE;
282 }
283
284 if ($tellAFriend) {
285 if ($this->_action & CRM_Core_Action::PREVIEW) {
286 $url = CRM_Utils_System::url("civicrm/friend",
287 "reset=1&action=preview&{$subUrl}"
288 );
289 }
290 else {
291 $url = CRM_Utils_System::url("civicrm/friend",
292 "reset=1&{$subUrl}"
293 );
294 }
295 $this->assign('friendURL', $url);
296 }
297
298 $isPendingOutcome = TRUE;
299 try {
300 // A payment notification update could have come in at any time. Check at the last minute.
301 $contributionStatusID = civicrm_api3('Contribution', 'getvalue', array(
302 'id' => CRM_Utils_Array::value('contributionID', $params),
303 'return' => 'contribution_status_id',
304 'invoice_id' => CRM_Utils_Array::value('invoiceID', $params),
305 ));
306 if (CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contributionStatusID) === 'Pending'
307 && !empty($params['payment_processor_id'])
308 ) {
309 $isPendingOutcome = TRUE;
310 }
311 else {
312 $isPendingOutcome = FALSE;
313 }
314 }
315 catch (CiviCRM_API3_Exception $e) {
316
317 }
318 $this->assign('isPendingOutcome', $isPendingOutcome);
319
320 $this->freeze();
321
322 // can we blow away the session now to prevent hackery
323 // CRM-9491
324 $this->controller->reset();
325 }
326
327 }