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