Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
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 | /** | |
42 | * membership price set status | |
43 | * | |
44 | */ | |
45 | public $_useForMember; | |
46 | ||
47 | /** | |
48 | * Function to set variables up before form is built | |
49 | * | |
50 | * @return void | |
51 | * @access public | |
52 | */ | |
53 | public function preProcess() { | |
54 | parent::preProcess(); | |
55 | ||
56 | $this->_params = $this->get('params'); | |
57 | $this->_lineItem = $this->get('lineItem'); | |
58 | $is_deductible = $this->get('is_deductible'); | |
59 | $this->assign('is_deductible', $is_deductible); | |
60 | $this->assign('thankyou_title', CRM_Utils_Array::value('thankyou_title', $this->_values)); | |
61 | $this->assign('thankyou_text', CRM_Utils_Array::value('thankyou_text', $this->_values)); | |
62 | $this->assign('thankyou_footer', CRM_Utils_Array::value('thankyou_footer', $this->_values)); | |
63 | $this->assign('max_reminders', CRM_Utils_Array::value('max_reminders', $this->_values)); | |
64 | $this->assign('initial_reminder_day', CRM_Utils_Array::value('initial_reminder_day', $this->_values)); | |
65 | CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->_values)); | |
f4aaa82a | 66 | // Make the contributionPageID available to the template |
6a488035 TO |
67 | $this->assign('contributionPageID', $this->_id); |
68 | $this->assign('isShare', $this->_values['is_share']); | |
69 | ||
70 | $this->_params['is_pay_later'] = $this->get('is_pay_later'); | |
71 | $this->assign('is_pay_later', $this->_params['is_pay_later']); | |
72 | if ($this->_params['is_pay_later']) { | |
73 | $this->assign('pay_later_receipt', $this->_values['pay_later_receipt']); | |
74 | } | |
75 | } | |
76 | ||
77 | /** | |
78 | * overwrite action, since we are only showing elements in frozen mode | |
79 | * no help display needed | |
80 | * | |
81 | * @return int | |
82 | * @access public | |
83 | */ | |
84 | function getAction() { | |
85 | if ($this->_action & CRM_Core_Action::PREVIEW) { | |
86 | return CRM_Core_Action::VIEW | CRM_Core_Action::PREVIEW; | |
87 | } | |
88 | else { | |
89 | return CRM_Core_Action::VIEW; | |
90 | } | |
91 | } | |
92 | ||
93 | /** | |
94 | * Function to actually build the form | |
95 | * | |
96 | * @return void | |
97 | * @access public | |
98 | */ | |
99 | public function buildQuickForm() { | |
100 | $this->assignToTemplate(); | |
101 | $productID = $this->get('productID'); | |
102 | $option = $this->get('option'); | |
103 | $membershipTypeID = $this->get('membershipTypeID'); | |
104 | $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values)); | |
105 | ||
106 | if ($productID) { | |
107 | CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option); | |
108 | } | |
9da8dc8c | 109 | if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) { |
6a488035 TO |
110 | $this->assign('lineItem', $this->_lineItem); |
111 | } else { | |
112 | if (is_array($membershipTypeID)) { | |
113 | $membershipTypeID = current($membershipTypeID); | |
114 | } | |
115 | $this->assign('is_quick_config', 1); | |
116 | $this->_params['is_quick_config'] = 1; | |
117 | } | |
118 | $this->assign('priceSetID', $this->_priceSetId); | |
119 | $this->assign('useForMember', $this->get('useForMember')); | |
120 | ||
121 | $params = $this->_params; | |
03b412ae PB |
122 | $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,'contribution_invoice_settings'); |
123 | $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); | |
124 | if ($invoicing) { | |
125 | $getTaxDetails = FALSE; | |
126 | $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings); | |
127 | foreach ($this->_lineItem as $key => $value) { | |
128 | foreach ($value as $v) { | |
129 | if (isset($v['tax_rate'])) { | |
130 | if ($v['tax_rate'] != '') { | |
131 | $getTaxDetails = TRUE; | |
132 | } | |
133 | } | |
134 | } | |
135 | } | |
136 | $this->assign('getTaxDetails', $getTaxDetails); | |
137 | $this->assign('taxTerm', $taxTerm); | |
138 | $this->assign('totalTaxAmount', $params['tax_amount']); | |
139 | } | |
8af73472 | 140 | if ($this->_honor_block_is_active && !empty($params['soft_credit_type_id'])) { |
133e2c99 | 141 | $honorName = null; |
142 | $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); | |
143 | ||
8af73472 | 144 | $this->assign('honor_block_is_active', $this->_honor_block_is_active); |
133e2c99 | 145 | $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]); |
1421174e | 146 | CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']); |
6a488035 | 147 | |
133e2c99 | 148 | $fieldTypes = array('Contact'); |
149 | $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']); | |
150 | $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes); | |
6a488035 TO |
151 | } |
152 | ||
153 | $qParams = "reset=1&id={$this->_id}"; | |
154 | //pcp elements | |
155 | if ($this->_pcpId) { | |
156 | $qParams .= "&pcpId={$this->_pcpId}"; | |
157 | $this->assign('pcpBlock', TRUE); | |
158 | foreach (array( | |
159 | 'pcp_display_in_roll', 'pcp_is_anonymous', 'pcp_roll_nickname', 'pcp_personal_note') as $val) { | |
a7488080 | 160 | if (!empty($this->_params[$val])) { |
6a488035 TO |
161 | $this->assign($val, $this->_params[$val]); |
162 | } | |
163 | } | |
164 | } | |
165 | ||
166 | $this->assign( 'qParams' , $qParams ); | |
167 | ||
168 | if ($membershipTypeID) { | |
169 | $transactionID = $this->get('membership_trx_id'); | |
170 | $membershipAmount = $this->get('membership_amount'); | |
171 | $renewalMode = $this->get('renewal_mode'); | |
172 | $this->assign('membership_trx_id', $transactionID); | |
173 | $this->assign('membership_amount', $membershipAmount); | |
174 | $this->assign('renewal_mode', $renewalMode); | |
175 | ||
176 | CRM_Member_BAO_Membership::buildMembershipBlock($this, | |
177 | $this->_id, | |
5b757295 | 178 | $this->_membershipContactID, |
6a488035 TO |
179 | FALSE, |
180 | $membershipTypeID, | |
5b757295 | 181 | TRUE, |
182 | NULL | |
6a488035 TO |
183 | ); |
184 | } | |
185 | ||
186 | $this->_separateMembershipPayment = $this->get('separateMembershipPayment'); | |
187 | $this->assign("is_separate_payment", $this->_separateMembershipPayment); | |
188 | ||
189 | $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE); | |
190 | $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE); | |
a7488080 | 191 | if (!empty($params['hidden_onbehalf_profile'])) { |
6a488035 TO |
192 | $ufJoinParams = array( |
193 | 'module' => 'onBehalf', | |
194 | 'entity_table' => 'civicrm_contribution_page', | |
195 | 'entity_id' => $this->_id, | |
196 | ); | |
197 | $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); | |
198 | $profileId = $OnBehalfProfile[0]; | |
199 | ||
200 | $fieldTypes = array('Contact', 'Organization'); | |
201 | $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); | |
202 | $fieldTypes = array_merge($fieldTypes, $contactSubType); | |
203 | if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) { | |
204 | $fieldTypes = array_merge($fieldTypes, array('Membership')); | |
205 | } | |
206 | else { | |
207 | $fieldTypes = array_merge($fieldTypes, array('Contribution')); | |
208 | } | |
209 | ||
133e2c99 | 210 | $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes); |
6a488035 TO |
211 | } |
212 | ||
213 | $this->assign('trxn_id', | |
214 | CRM_Utils_Array::value('trxn_id', | |
215 | $this->_params | |
216 | ) | |
217 | ); | |
218 | $this->assign('receive_date', | |
219 | CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params)) | |
220 | ); | |
221 | ||
222 | $defaults = array(); | |
223 | $fields = array(); | |
224 | foreach ($this->_fields as $name => $dontCare) { | |
133e2c99 | 225 | if ($name != 'onbehalf' || $name != 'honor') { |
6a488035 TO |
226 | $fields[$name] = 1; |
227 | } | |
228 | } | |
229 | $fields['state_province'] = $fields['country'] = $fields['email'] = 1; | |
230 | $contact = $this->_params = $this->controller->exportValues('Main'); | |
231 | ||
232 | foreach ($fields as $name => $dontCare) { | |
133e2c99 | 233 | if (isset($contact[$name])) { |
6a488035 TO |
234 | $defaults[$name] = $contact[$name]; |
235 | if (substr($name, 0, 7) == 'custom_') { | |
236 | $timeField = "{$name}_time"; | |
237 | if (isset($contact[$timeField])) { | |
238 | $defaults[$timeField] = $contact[$timeField]; | |
239 | } | |
240 | } | |
8cc574cf | 241 | elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) { |
6a488035 TO |
242 | $defaults[$name . '_custom'] = $contact[$name . '_custom']; |
243 | } | |
244 | } | |
245 | } | |
246 | ||
247 | // now fix all state country selectors | |
248 | CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults); | |
249 | ||
250 | $this->_submitValues = array_merge($this->_submitValues, $defaults); | |
251 | $this->setDefaults($defaults); | |
eea16664 | 252 | |
6a488035 TO |
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 | } | |
a7488080 | 265 | elseif (!empty($data['is_active'])) { |
6a488035 TO |
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 | $this->freeze(); | |
287 | ||
288 | // can we blow away the session now to prevent hackery | |
289 | // CRM-9491 | |
290 | $this->controller->reset(); | |
291 | } | |
292 | } | |
293 |