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