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 | */ | |
45 | public $_useForMember; | |
46 | ||
47 | /** | |
100fef9d | 48 | * Set variables up before form is built |
6a488035 TO |
49 | * |
50 | * @return void | |
6a488035 TO |
51 | */ |
52 | public function preProcess() { | |
53 | parent::preProcess(); | |
54 | ||
55 | $this->_params = $this->get('params'); | |
56 | $this->_lineItem = $this->get('lineItem'); | |
57 | $is_deductible = $this->get('is_deductible'); | |
58 | $this->assign('is_deductible', $is_deductible); | |
59 | $this->assign('thankyou_title', CRM_Utils_Array::value('thankyou_title', $this->_values)); | |
60 | $this->assign('thankyou_text', CRM_Utils_Array::value('thankyou_text', $this->_values)); | |
61 | $this->assign('thankyou_footer', CRM_Utils_Array::value('thankyou_footer', $this->_values)); | |
62 | $this->assign('max_reminders', CRM_Utils_Array::value('max_reminders', $this->_values)); | |
63 | $this->assign('initial_reminder_day', CRM_Utils_Array::value('initial_reminder_day', $this->_values)); | |
64 | CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->_values)); | |
f4aaa82a | 65 | // Make the contributionPageID available to the template |
6a488035 TO |
66 | $this->assign('contributionPageID', $this->_id); |
67 | $this->assign('isShare', $this->_values['is_share']); | |
68 | ||
69 | $this->_params['is_pay_later'] = $this->get('is_pay_later'); | |
70 | $this->assign('is_pay_later', $this->_params['is_pay_later']); | |
71 | if ($this->_params['is_pay_later']) { | |
72 | $this->assign('pay_later_receipt', $this->_values['pay_later_receipt']); | |
73 | } | |
74 | } | |
75 | ||
76 | /** | |
100fef9d | 77 | * Overwrite action, since we are only showing elements in frozen mode |
6a488035 TO |
78 | * no help display needed |
79 | * | |
80 | * @return int | |
6a488035 | 81 | */ |
00be9182 | 82 | public function getAction() { |
6a488035 TO |
83 | if ($this->_action & CRM_Core_Action::PREVIEW) { |
84 | return CRM_Core_Action::VIEW | CRM_Core_Action::PREVIEW; | |
85 | } | |
86 | else { | |
87 | return CRM_Core_Action::VIEW; | |
88 | } | |
89 | } | |
90 | ||
91 | /** | |
c490a46a | 92 | * Build the form object |
6a488035 TO |
93 | * |
94 | * @return void | |
6a488035 TO |
95 | */ |
96 | public function buildQuickForm() { | |
97 | $this->assignToTemplate(); | |
98 | $productID = $this->get('productID'); | |
99 | $option = $this->get('option'); | |
100 | $membershipTypeID = $this->get('membershipTypeID'); | |
101 | $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values)); | |
102 | ||
103 | if ($productID) { | |
104 | CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option); | |
105 | } | |
9da8dc8c | 106 | if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) { |
6a488035 | 107 | $this->assign('lineItem', $this->_lineItem); |
0db6c3e1 TO |
108 | } |
109 | else { | |
6a488035 TO |
110 | if (is_array($membershipTypeID)) { |
111 | $membershipTypeID = current($membershipTypeID); | |
112 | } | |
113 | $this->assign('is_quick_config', 1); | |
114 | $this->_params['is_quick_config'] = 1; | |
115 | } | |
116 | $this->assign('priceSetID', $this->_priceSetId); | |
117 | $this->assign('useForMember', $this->get('useForMember')); | |
118 | ||
119 | $params = $this->_params; | |
874c9be7 | 120 | $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); |
03b412ae PB |
121 | $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); |
122 | if ($invoicing) { | |
123 | $getTaxDetails = FALSE; | |
124 | $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings); | |
125 | foreach ($this->_lineItem as $key => $value) { | |
126 | foreach ($value as $v) { | |
127 | if (isset($v['tax_rate'])) { | |
128 | if ($v['tax_rate'] != '') { | |
129 | $getTaxDetails = TRUE; | |
130 | } | |
131 | } | |
132 | } | |
133 | } | |
134 | $this->assign('getTaxDetails', $getTaxDetails); | |
135 | $this->assign('taxTerm', $taxTerm); | |
136 | $this->assign('totalTaxAmount', $params['tax_amount']); | |
137 | } | |
8af73472 | 138 | if ($this->_honor_block_is_active && !empty($params['soft_credit_type_id'])) { |
874c9be7 | 139 | $honorName = NULL; |
133e2c99 | 140 | $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); |
141 | ||
8af73472 | 142 | $this->assign('honor_block_is_active', $this->_honor_block_is_active); |
133e2c99 | 143 | $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]); |
1421174e | 144 | CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']); |
6a488035 | 145 | |
133e2c99 | 146 | $fieldTypes = array('Contact'); |
147 | $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']); | |
148 | $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes); | |
6a488035 TO |
149 | } |
150 | ||
151 | $qParams = "reset=1&id={$this->_id}"; | |
152 | //pcp elements | |
153 | if ($this->_pcpId) { | |
154 | $qParams .= "&pcpId={$this->_pcpId}"; | |
155 | $this->assign('pcpBlock', TRUE); | |
156 | foreach (array( | |
157 | 'pcp_display_in_roll', 'pcp_is_anonymous', 'pcp_roll_nickname', 'pcp_personal_note') as $val) { | |
a7488080 | 158 | if (!empty($this->_params[$val])) { |
6a488035 TO |
159 | $this->assign($val, $this->_params[$val]); |
160 | } | |
161 | } | |
162 | } | |
163 | ||
874c9be7 | 164 | $this->assign( 'qParams', $qParams ); |
6a488035 TO |
165 | |
166 | if ($membershipTypeID) { | |
167 | $transactionID = $this->get('membership_trx_id'); | |
168 | $membershipAmount = $this->get('membership_amount'); | |
169 | $renewalMode = $this->get('renewal_mode'); | |
170 | $this->assign('membership_trx_id', $transactionID); | |
171 | $this->assign('membership_amount', $membershipAmount); | |
172 | $this->assign('renewal_mode', $renewalMode); | |
173 | ||
174 | CRM_Member_BAO_Membership::buildMembershipBlock($this, | |
175 | $this->_id, | |
5b757295 | 176 | $this->_membershipContactID, |
6a488035 TO |
177 | FALSE, |
178 | $membershipTypeID, | |
5b757295 | 179 | TRUE, |
180 | NULL | |
6a488035 TO |
181 | ); |
182 | } | |
183 | ||
184 | $this->_separateMembershipPayment = $this->get('separateMembershipPayment'); | |
185 | $this->assign("is_separate_payment", $this->_separateMembershipPayment); | |
186 | ||
187 | $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE); | |
188 | $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE); | |
a7488080 | 189 | if (!empty($params['hidden_onbehalf_profile'])) { |
6a488035 TO |
190 | $ufJoinParams = array( |
191 | 'module' => 'onBehalf', | |
192 | 'entity_table' => 'civicrm_contribution_page', | |
193 | 'entity_id' => $this->_id, | |
194 | ); | |
195 | $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); | |
196 | $profileId = $OnBehalfProfile[0]; | |
197 | ||
198 | $fieldTypes = array('Contact', 'Organization'); | |
199 | $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); | |
200 | $fieldTypes = array_merge($fieldTypes, $contactSubType); | |
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 | ||
133e2c99 | 208 | $this->buildCustom($profileId, '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 | } | |
8cc574cf | 239 | elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) { |
6a488035 TO |
240 | $defaults[$name . '_custom'] = $contact[$name . '_custom']; |
241 | } | |
242 | } | |
243 | } | |
244 | ||
6a488035 TO |
245 | $this->_submitValues = array_merge($this->_submitValues, $defaults); |
246 | $this->setDefaults($defaults); | |
eea16664 | 247 | |
6a488035 TO |
248 | $values['entity_id'] = $this->_id; |
249 | $values['entity_table'] = 'civicrm_contribution_page'; | |
250 | ||
251 | CRM_Friend_BAO_Friend::retrieve($values, $data); | |
252 | $tellAFriend = FALSE; | |
253 | if ($this->_pcpId) { | |
254 | if ($this->_pcpBlock['is_tellfriend_enabled']) { | |
255 | $this->assign('friendText', ts('Tell a Friend')); | |
256 | $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp"; | |
257 | $tellAFriend = TRUE; | |
258 | } | |
259 | } | |
a7488080 | 260 | elseif (!empty($data['is_active'])) { |
6a488035 TO |
261 | $friendText = $data['title']; |
262 | $this->assign('friendText', $friendText); | |
263 | $subUrl = "eid={$this->_id}&pcomponent=contribute"; | |
264 | $tellAFriend = TRUE; | |
265 | } | |
266 | ||
267 | if ($tellAFriend) { | |
268 | if ($this->_action & CRM_Core_Action::PREVIEW) { | |
269 | $url = CRM_Utils_System::url("civicrm/friend", | |
270 | "reset=1&action=preview&{$subUrl}" | |
271 | ); | |
272 | } | |
273 | else { | |
274 | $url = CRM_Utils_System::url("civicrm/friend", | |
275 | "reset=1&{$subUrl}" | |
276 | ); | |
277 | } | |
278 | $this->assign('friendURL', $url); | |
279 | } | |
280 | ||
281 | $this->freeze(); | |
282 | ||
283 | // can we blow away the session now to prevent hackery | |
284 | // CRM-9491 | |
285 | $this->controller->reset(); | |
286 | } | |
287 | } |