preliminary whitespace cleanup
[civicrm-core.git] / CRM / Contribute / Form / Contribution / ThankYou.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35
36/**
37 * form for thank-you / success page - 3rd step of online contribution process
38 */
39class 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));
66 // Make the contributionPageID avilable to the template
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 }
109 if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId, 'is_quick_config')) {
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;
122 $honor_block_is_active = $this->get('honor_block_is_active');
123 if ($honor_block_is_active &&
124 ((!empty($params["honor_first_name"]) && !empty($params["honor_last_name"])) ||
125 (!empty($params["honor_email"]))
126 )
127 ) {
128 $this->assign('honor_block_is_active', $honor_block_is_active);
129 $this->assign('honor_block_title', CRM_Utils_Array::value('honor_block_title', $this->_values));
130
e6c4755b 131 $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
cbf48754 132 $honor = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id');
6a488035
TO
133 $this->assign('honor_type', $honor[$params["honor_type_id"]]);
134 $this->assign('honor_prefix', ($params["honor_prefix_id"]) ? $prefix[$params["honor_prefix_id"]] : ' ');
135 $this->assign('honor_first_name', $params["honor_first_name"]);
136 $this->assign('honor_last_name', $params["honor_last_name"]);
137 $this->assign('honor_email', $params["honor_email"]);
138 }
139
140 $qParams = "reset=1&amp;id={$this->_id}";
141 //pcp elements
142 if ($this->_pcpId) {
143 $qParams .= "&amp;pcpId={$this->_pcpId}";
144 $this->assign('pcpBlock', TRUE);
145 foreach (array(
146 'pcp_display_in_roll', 'pcp_is_anonymous', 'pcp_roll_nickname', 'pcp_personal_note') as $val) {
147 if (CRM_Utils_Array::value($val, $this->_params)) {
148 $this->assign($val, $this->_params[$val]);
149 }
150 }
151 }
152
153 $this->assign( 'qParams' , $qParams );
154
155 if ($membershipTypeID) {
156 $transactionID = $this->get('membership_trx_id');
157 $membershipAmount = $this->get('membership_amount');
158 $renewalMode = $this->get('renewal_mode');
159 $this->assign('membership_trx_id', $transactionID);
160 $this->assign('membership_amount', $membershipAmount);
161 $this->assign('renewal_mode', $renewalMode);
162
163 CRM_Member_BAO_Membership::buildMembershipBlock($this,
164 $this->_id,
165 FALSE,
166 $membershipTypeID,
167 TRUE, NULL,
168 $this->_membershipContactID
169 );
170 }
171
172 $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
173 $this->assign("is_separate_payment", $this->_separateMembershipPayment);
174
175 $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
176 $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
177 if (CRM_Utils_Array::value('hidden_onbehalf_profile', $params)) {
178 $ufJoinParams = array(
179 'module' => 'onBehalf',
180 'entity_table' => 'civicrm_contribution_page',
181 'entity_id' => $this->_id,
182 );
183 $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
184 $profileId = $OnBehalfProfile[0];
185
186 $fieldTypes = array('Contact', 'Organization');
187 $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
188 $fieldTypes = array_merge($fieldTypes, $contactSubType);
189 if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) {
190 $fieldTypes = array_merge($fieldTypes, array('Membership'));
191 }
192 else {
193 $fieldTypes = array_merge($fieldTypes, array('Contribution'));
194 }
195
196 $this->buildCustom($profileId, 'onbehalfProfile', TRUE, TRUE, $fieldTypes);
197 }
198
199 $this->assign('trxn_id',
200 CRM_Utils_Array::value('trxn_id',
201 $this->_params
202 )
203 );
204 $this->assign('receive_date',
205 CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params))
206 );
207
208 $defaults = array();
209 $fields = array();
210 foreach ($this->_fields as $name => $dontCare) {
211 if ($name == 'onbehalf') {
212 foreach ($dontCare as $key => $value) {
213 $fields['onbehalf'][$key] = 1;
214 }
215 }
216 else {
217 $fields[$name] = 1;
218 }
219 }
220 $fields['state_province'] = $fields['country'] = $fields['email'] = 1;
221 $contact = $this->_params = $this->controller->exportValues('Main');
222
223 foreach ($fields as $name => $dontCare) {
224 if ($name == 'onbehalf') {
225 foreach ($dontCare as $key => $value) {
226 //$defaults[$key] = $contact['onbehalf'][$key];
227 if (isset($contact['onbehalf'][$key])) {
228 $defaults[$key] = $contact['onbehalf'][$key];
229 }
230 if (isset($contact['onbehalf']["{$key}_id"])) {
231 $defaults["{$key}_id"] = $contact['onbehalf']["{$key}_id"];
232 }
233
234 }
235 }
236 elseif (isset($contact[$name])) {
237 $defaults[$name] = $contact[$name];
238 if (substr($name, 0, 7) == 'custom_') {
239 $timeField = "{$name}_time";
240 if (isset($contact[$timeField])) {
241 $defaults[$timeField] = $contact[$timeField];
242 }
243 }
244 elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting'))
245 && CRM_Utils_Array::value($name . '_custom', $contact)
246 ) {
247 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
248 }
249 }
250 }
251
252 // now fix all state country selectors
253 CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
254
255 $this->_submitValues = array_merge($this->_submitValues, $defaults);
256 $this->setDefaults($defaults);
eea16664 257
6a488035
TO
258 $values['entity_id'] = $this->_id;
259 $values['entity_table'] = 'civicrm_contribution_page';
260
261 CRM_Friend_BAO_Friend::retrieve($values, $data);
262 $tellAFriend = FALSE;
263 if ($this->_pcpId) {
264 if ($this->_pcpBlock['is_tellfriend_enabled']) {
265 $this->assign('friendText', ts('Tell a Friend'));
266 $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp";
267 $tellAFriend = TRUE;
268 }
269 }
270 elseif (CRM_Utils_Array::value('is_active', $data)) {
271 $friendText = $data['title'];
272 $this->assign('friendText', $friendText);
273 $subUrl = "eid={$this->_id}&pcomponent=contribute";
274 $tellAFriend = TRUE;
275 }
276
277 if ($tellAFriend) {
278 if ($this->_action & CRM_Core_Action::PREVIEW) {
279 $url = CRM_Utils_System::url("civicrm/friend",
280 "reset=1&action=preview&{$subUrl}"
281 );
282 }
283 else {
284 $url = CRM_Utils_System::url("civicrm/friend",
285 "reset=1&{$subUrl}"
286 );
287 }
288 $this->assign('friendURL', $url);
289 }
290
291 $this->freeze();
292
293 // can we blow away the session now to prevent hackery
294 // CRM-9491
295 $this->controller->reset();
296 }
297}
298