Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
0f03f337 | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
0f03f337 | 31 | * @copyright CiviCRM LLC (c) 2004-2017 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
95cdcc0f | 35 | * Form for thank-you / success page - 3rd step of online contribution process. |
6a488035 TO |
36 | */ |
37 | class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_ContributionBase { | |
38 | ||
39 | /** | |
fe482240 | 40 | * Membership price set status. |
6a488035 TO |
41 | */ |
42 | public $_useForMember; | |
43 | ||
44 | /** | |
fe482240 | 45 | * Set variables up before form is built. |
6a488035 TO |
46 | */ |
47 | public function preProcess() { | |
48 | parent::preProcess(); | |
49 | ||
353ffa53 | 50 | $this->_params = $this->get('params'); |
6a488035 | 51 | $this->_lineItem = $this->get('lineItem'); |
353ffa53 | 52 | $is_deductible = $this->get('is_deductible'); |
6a488035 TO |
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)); | |
f4aaa82a | 60 | // Make the contributionPageID available to the template |
6a488035 TO |
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 | } | |
de5ce535 | 69 | $this->assign('is_for_organization', CRM_Utils_Array::value('is_for_organization', $this->_params)); |
6a488035 TO |
70 | } |
71 | ||
72 | /** | |
100fef9d | 73 | * Overwrite action, since we are only showing elements in frozen mode |
6a488035 TO |
74 | * no help display needed |
75 | * | |
76 | * @return int | |
6a488035 | 77 | */ |
00be9182 | 78 | public function getAction() { |
6a488035 TO |
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 | /** | |
fe482240 | 88 | * Build the form object. |
6a488035 TO |
89 | */ |
90 | public function buildQuickForm() { | |
91 | $this->assignToTemplate(); | |
2f44fc96 | 92 | $this->_ccid = $this->get('ccid'); |
353ffa53 TO |
93 | $productID = $this->get('productID'); |
94 | $option = $this->get('option'); | |
6a488035 TO |
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 | } | |
9da8dc8c | 101 | if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) { |
6a488035 | 102 | $this->assign('lineItem', $this->_lineItem); |
0db6c3e1 TO |
103 | } |
104 | else { | |
6a488035 TO |
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; | |
aaffa79f | 115 | $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); |
03b412ae PB |
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 $key => $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 | } | |
4779abb3 | 133 | if (!empty($this->_values['honoree_profile_id']) && !empty($params['soft_credit_type_id'])) { |
874c9be7 | 134 | $honorName = NULL; |
133e2c99 | 135 | $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); |
136 | ||
133e2c99 | 137 | $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]); |
4779abb3 | 138 | CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor']); |
6a488035 | 139 | |
133e2c99 | 140 | $fieldTypes = array('Contact'); |
4779abb3 | 141 | $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($this->_values['honoree_profile_id']); |
142 | $this->buildCustom($this->_values['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes); | |
6a488035 TO |
143 | } |
144 | ||
145 | $qParams = "reset=1&id={$this->_id}"; | |
146 | //pcp elements | |
147 | if ($this->_pcpId) { | |
148 | $qParams .= "&pcpId={$this->_pcpId}"; | |
149 | $this->assign('pcpBlock', TRUE); | |
150 | foreach (array( | |
353ffa53 TO |
151 | 'pcp_display_in_roll', |
152 | 'pcp_is_anonymous', | |
153 | 'pcp_roll_nickname', | |
389bcebf | 154 | 'pcp_personal_note', |
353ffa53 | 155 | ) as $val) { |
a7488080 | 156 | if (!empty($this->_params[$val])) { |
6a488035 TO |
157 | $this->assign($val, $this->_params[$val]); |
158 | } | |
159 | } | |
160 | } | |
161 | ||
481a74f4 | 162 | $this->assign('qParams', $qParams); |
6a488035 TO |
163 | |
164 | if ($membershipTypeID) { | |
353ffa53 | 165 | $transactionID = $this->get('membership_trx_id'); |
6a488035 | 166 | $membershipAmount = $this->get('membership_amount'); |
353ffa53 | 167 | $renewalMode = $this->get('renewal_mode'); |
6a488035 TO |
168 | $this->assign('membership_trx_id', $transactionID); |
169 | $this->assign('membership_amount', $membershipAmount); | |
170 | $this->assign('renewal_mode', $renewalMode); | |
171 | ||
42e3a033 | 172 | $this->buildMembershipBlock( |
5b757295 | 173 | $this->_membershipContactID, |
6a488035 TO |
174 | FALSE, |
175 | $membershipTypeID, | |
5b757295 | 176 | TRUE, |
177 | NULL | |
6a488035 | 178 | ); |
9cc96227 | 179 | |
180 | if (!empty($params['auto_renew'])) { | |
181 | $this->assign('auto_renew', TRUE); | |
182 | } | |
6a488035 TO |
183 | } |
184 | ||
185 | $this->_separateMembershipPayment = $this->get('separateMembershipPayment'); | |
186 | $this->assign("is_separate_payment", $this->_separateMembershipPayment); | |
187 | ||
2f44fc96 | 188 | if (empty($this->_ccid)) { |
189 | $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE); | |
190 | $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE); | |
191 | } | |
2454bb63 | 192 | if (!empty($this->_values['onbehalf_profile_id']) && |
193 | !empty($params['onbehalf']) && | |
194 | ($this->_values['is_for_organization'] == 2 || | |
195 | !empty($params['is_for_organization']) | |
2f44fc96 | 196 | ) && empty($this->_ccid) |
2454bb63 | 197 | ) { |
353ffa53 | 198 | $fieldTypes = array('Contact', 'Organization'); |
6a488035 | 199 | $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); |
353ffa53 | 200 | $fieldTypes = array_merge($fieldTypes, $contactSubType); |
6a488035 TO |
201 | if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) { |
202 | $fieldTypes = array_merge($fieldTypes, array('Membership')); | |
203 | } | |
204 | else { | |
205 | $fieldTypes = array_merge($fieldTypes, array('Contribution')); | |
206 | } | |
207 | ||
4779abb3 | 208 | $this->buildCustom($this->_values['onbehalf_profile_id'], 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes); |
6a488035 TO |
209 | } |
210 | ||
211 | $this->assign('trxn_id', | |
212 | CRM_Utils_Array::value('trxn_id', | |
213 | $this->_params | |
214 | ) | |
215 | ); | |
216 | $this->assign('receive_date', | |
217 | CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params)) | |
218 | ); | |
219 | ||
220 | $defaults = array(); | |
221 | $fields = array(); | |
222 | foreach ($this->_fields as $name => $dontCare) { | |
133e2c99 | 223 | if ($name != 'onbehalf' || $name != 'honor') { |
6a488035 TO |
224 | $fields[$name] = 1; |
225 | } | |
226 | } | |
227 | $fields['state_province'] = $fields['country'] = $fields['email'] = 1; | |
228 | $contact = $this->_params = $this->controller->exportValues('Main'); | |
229 | ||
230 | foreach ($fields as $name => $dontCare) { | |
133e2c99 | 231 | if (isset($contact[$name])) { |
6a488035 TO |
232 | $defaults[$name] = $contact[$name]; |
233 | if (substr($name, 0, 7) == 'custom_') { | |
234 | $timeField = "{$name}_time"; | |
235 | if (isset($contact[$timeField])) { | |
236 | $defaults[$timeField] = $contact[$timeField]; | |
237 | } | |
238 | } | |
353ffa53 TO |
239 | elseif (in_array($name, array( |
240 | 'addressee', | |
241 | 'email_greeting', | |
389bcebf | 242 | 'postal_greeting', |
353ffa53 TO |
243 | )) && !empty($contact[$name . '_custom']) |
244 | ) { | |
6a488035 TO |
245 | $defaults[$name . '_custom'] = $contact[$name . '_custom']; |
246 | } | |
247 | } | |
248 | } | |
249 | ||
6a488035 | 250 | $this->_submitValues = array_merge($this->_submitValues, $defaults); |
6cc679d2 | 251 | |
6a488035 | 252 | $this->setDefaults($defaults); |
eea16664 | 253 | |
6a488035 TO |
254 | $values['entity_id'] = $this->_id; |
255 | $values['entity_table'] = 'civicrm_contribution_page'; | |
256 | ||
257 | CRM_Friend_BAO_Friend::retrieve($values, $data); | |
258 | $tellAFriend = FALSE; | |
259 | if ($this->_pcpId) { | |
260 | if ($this->_pcpBlock['is_tellfriend_enabled']) { | |
261 | $this->assign('friendText', ts('Tell a Friend')); | |
262 | $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp"; | |
263 | $tellAFriend = TRUE; | |
264 | } | |
265 | } | |
a7488080 | 266 | elseif (!empty($data['is_active'])) { |
6a488035 TO |
267 | $friendText = $data['title']; |
268 | $this->assign('friendText', $friendText); | |
269 | $subUrl = "eid={$this->_id}&pcomponent=contribute"; | |
270 | $tellAFriend = TRUE; | |
271 | } | |
272 | ||
273 | if ($tellAFriend) { | |
274 | if ($this->_action & CRM_Core_Action::PREVIEW) { | |
275 | $url = CRM_Utils_System::url("civicrm/friend", | |
276 | "reset=1&action=preview&{$subUrl}" | |
277 | ); | |
278 | } | |
279 | else { | |
280 | $url = CRM_Utils_System::url("civicrm/friend", | |
281 | "reset=1&{$subUrl}" | |
282 | ); | |
283 | } | |
284 | $this->assign('friendURL', $url); | |
285 | } | |
286 | ||
287 | $this->freeze(); | |
288 | ||
289 | // can we blow away the session now to prevent hackery | |
290 | // CRM-9491 | |
291 | $this->controller->reset(); | |
292 | } | |
96025800 | 293 | |
6a488035 | 294 | } |