Merge pull request #10021 from jitendrapurohit/CRM-20246
[civicrm-core.git] / CRM / Contribute / Form / Contribution / ThankYou.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
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 * Set variables up before form is built.
46 */
47 public function preProcess() {
48 parent::preProcess();
49
50 $this->_params = $this->get('params');
51 $this->_lineItem = $this->get('lineItem');
52 $is_deductible = $this->get('is_deductible');
53 $this->assign('is_deductible', $is_deductible);
54 $this->assign('thankyou_title', CRM_Utils_Array::value('thankyou_title', $this->_values));
55 $this->assign('thankyou_text', CRM_Utils_Array::value('thankyou_text', $this->_values));
56 $this->assign('thankyou_footer', CRM_Utils_Array::value('thankyou_footer', $this->_values));
57 $this->assign('max_reminders', CRM_Utils_Array::value('max_reminders', $this->_values));
58 $this->assign('initial_reminder_day', CRM_Utils_Array::value('initial_reminder_day', $this->_values));
59 CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->_values));
60 // Make the contributionPageID available to the template
61 $this->assign('contributionPageID', $this->_id);
62 $this->assign('isShare', $this->_values['is_share']);
63
64 $this->_params['is_pay_later'] = $this->get('is_pay_later');
65 $this->assign('is_pay_later', $this->_params['is_pay_later']);
66 if ($this->_params['is_pay_later']) {
67 $this->assign('pay_later_receipt', $this->_values['pay_later_receipt']);
68 }
69 $this->assign('is_for_organization', CRM_Utils_Array::value('is_for_organization', $this->_params));
70 }
71
72 /**
73 * Overwrite action, since we are only showing elements in frozen mode
74 * no help display needed
75 *
76 * @return int
77 */
78 public function getAction() {
79 if ($this->_action & CRM_Core_Action::PREVIEW) {
80 return CRM_Core_Action::VIEW | CRM_Core_Action::PREVIEW;
81 }
82 else {
83 return CRM_Core_Action::VIEW;
84 }
85 }
86
87 /**
88 * Build the form object.
89 */
90 public function buildQuickForm() {
91 $this->assignToTemplate();
92 $this->_ccid = $this->get('ccid');
93 $productID = $this->get('productID');
94 $option = $this->get('option');
95 $membershipTypeID = $this->get('membershipTypeID');
96 $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
97
98 if ($productID) {
99 CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option);
100 }
101 if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
102 $this->assign('lineItem', $this->_lineItem);
103 }
104 else {
105 if (is_array($membershipTypeID)) {
106 $membershipTypeID = current($membershipTypeID);
107 }
108 $this->assign('is_quick_config', 1);
109 $this->_params['is_quick_config'] = 1;
110 }
111 $this->assign('priceSetID', $this->_priceSetId);
112 $this->assign('useForMember', $this->get('useForMember'));
113
114 $params = $this->_params;
115 $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
116 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
117 if ($invoicing) {
118 $getTaxDetails = FALSE;
119 $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
120 foreach ($this->_lineItem as $value) {
121 foreach ($value as $v) {
122 if (isset($v['tax_rate'])) {
123 if ($v['tax_rate'] != '') {
124 $getTaxDetails = TRUE;
125 }
126 }
127 }
128 }
129 $this->assign('getTaxDetails', $getTaxDetails);
130 $this->assign('taxTerm', $taxTerm);
131 $this->assign('totalTaxAmount', $params['tax_amount']);
132 }
133 if (!empty($this->_values['honoree_profile_id']) && !empty($params['soft_credit_type_id'])) {
134 $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
135
136 $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]);
137 CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor']);
138
139 $fieldTypes = array('Contact');
140 $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($this->_values['honoree_profile_id']);
141 $this->buildCustom($this->_values['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
142 }
143
144 $qParams = "reset=1&amp;id={$this->_id}";
145 //pcp elements
146 if ($this->_pcpId) {
147 $qParams .= "&amp;pcpId={$this->_pcpId}";
148 $this->assign('pcpBlock', TRUE);
149 foreach (array(
150 'pcp_display_in_roll',
151 'pcp_is_anonymous',
152 'pcp_roll_nickname',
153 'pcp_personal_note',
154 ) as $val) {
155 if (!empty($this->_params[$val])) {
156 $this->assign($val, $this->_params[$val]);
157 }
158 }
159 }
160
161 $this->assign('qParams', $qParams);
162
163 if ($membershipTypeID) {
164 $transactionID = $this->get('membership_trx_id');
165 $membershipAmount = $this->get('membership_amount');
166 $renewalMode = $this->get('renewal_mode');
167 $this->assign('membership_trx_id', $transactionID);
168 $this->assign('membership_amount', $membershipAmount);
169 $this->assign('renewal_mode', $renewalMode);
170
171 $this->buildMembershipBlock(
172 $this->_membershipContactID,
173 FALSE,
174 $membershipTypeID,
175 TRUE,
176 NULL
177 );
178
179 if (!empty($params['auto_renew'])) {
180 $this->assign('auto_renew', TRUE);
181 }
182 }
183
184 $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
185 $this->assign("is_separate_payment", $this->_separateMembershipPayment);
186
187 if (empty($this->_ccid)) {
188 $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
189 $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
190 }
191 if (!empty($this->_values['onbehalf_profile_id']) &&
192 !empty($params['onbehalf']) &&
193 ($this->_values['is_for_organization'] == 2 ||
194 !empty($params['is_for_organization'])
195 ) && empty($this->_ccid)
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
207 $this->buildCustom($this->_values['onbehalf_profile_id'], 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
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) {
222 if ($name != 'onbehalf' || $name != 'honor') {
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) {
230 if (isset($contact[$name])) {
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 }
238 elseif (in_array($name, array(
239 'addressee',
240 'email_greeting',
241 'postal_greeting',
242 )) && !empty($contact[$name . '_custom'])
243 ) {
244 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
245 }
246 }
247 }
248
249 $this->_submitValues = array_merge($this->_submitValues, $defaults);
250
251 $this->setDefaults($defaults);
252
253 $values['entity_id'] = $this->_id;
254 $values['entity_table'] = 'civicrm_contribution_page';
255
256 CRM_Friend_BAO_Friend::retrieve($values, $data);
257 $tellAFriend = FALSE;
258 if ($this->_pcpId) {
259 if ($this->_pcpBlock['is_tellfriend_enabled']) {
260 $this->assign('friendText', ts('Tell a Friend'));
261 $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp";
262 $tellAFriend = TRUE;
263 }
264 }
265 elseif (!empty($data['is_active'])) {
266 $friendText = $data['title'];
267 $this->assign('friendText', $friendText);
268 $subUrl = "eid={$this->_id}&pcomponent=contribute";
269 $tellAFriend = TRUE;
270 }
271
272 if ($tellAFriend) {
273 if ($this->_action & CRM_Core_Action::PREVIEW) {
274 $url = CRM_Utils_System::url("civicrm/friend",
275 "reset=1&action=preview&{$subUrl}"
276 );
277 }
278 else {
279 $url = CRM_Utils_System::url("civicrm/friend",
280 "reset=1&{$subUrl}"
281 );
282 }
283 $this->assign('friendURL', $url);
284 }
285
286 $isPendingOutcome = TRUE;
287 try {
288 // A payment notification update could have come in at any time. Check at the last minute.
289 $contributionStatusID = civicrm_api3('Contribution', 'getvalue', array(
290 'id' => CRM_Utils_Array::value('contributionID', $params),
291 'return' => 'contribution_status_id',
292 'invoice_id' => CRM_Utils_Array::value('invoiceID', $params),
293 ));
294 if (CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contributionStatusID) === 'Pending'
295 && !empty($params['payment_processor_id'])
296 ) {
297 $isPendingOutcome = TRUE;
298 }
299 else {
300 $isPendingOutcome = FALSE;
301 }
302 }
303 catch (CiviCRM_API3_Exception $e) {
304
305 }
306 $this->assign('isPendingOutcome', $isPendingOutcome);
307
308 $this->freeze();
309
310 // can we blow away the session now to prevent hackery
311 // CRM-9491
312 $this->controller->reset();
313 }
314
315 }