Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
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 | */ | |
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)); | |
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 | } | |
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; | |
8af73472 | 122 | if ($this->_honor_block_is_active && !empty($params['soft_credit_type_id'])) { |
133e2c99 | 123 | $honorName = null; |
124 | $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); | |
125 | ||
8af73472 | 126 | $this->assign('honor_block_is_active', $this->_honor_block_is_active); |
133e2c99 | 127 | $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]); |
1421174e | 128 | CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']); |
6a488035 | 129 | |
133e2c99 | 130 | $fieldTypes = array('Contact'); |
131 | $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']); | |
132 | $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes); | |
6a488035 TO |
133 | } |
134 | ||
135 | $qParams = "reset=1&id={$this->_id}"; | |
136 | //pcp elements | |
137 | if ($this->_pcpId) { | |
138 | $qParams .= "&pcpId={$this->_pcpId}"; | |
139 | $this->assign('pcpBlock', TRUE); | |
140 | foreach (array( | |
141 | 'pcp_display_in_roll', 'pcp_is_anonymous', 'pcp_roll_nickname', 'pcp_personal_note') as $val) { | |
a7488080 | 142 | if (!empty($this->_params[$val])) { |
6a488035 TO |
143 | $this->assign($val, $this->_params[$val]); |
144 | } | |
145 | } | |
146 | } | |
147 | ||
148 | $this->assign( 'qParams' , $qParams ); | |
149 | ||
150 | if ($membershipTypeID) { | |
151 | $transactionID = $this->get('membership_trx_id'); | |
152 | $membershipAmount = $this->get('membership_amount'); | |
153 | $renewalMode = $this->get('renewal_mode'); | |
154 | $this->assign('membership_trx_id', $transactionID); | |
155 | $this->assign('membership_amount', $membershipAmount); | |
156 | $this->assign('renewal_mode', $renewalMode); | |
157 | ||
158 | CRM_Member_BAO_Membership::buildMembershipBlock($this, | |
159 | $this->_id, | |
5b757295 | 160 | $this->_membershipContactID, |
6a488035 TO |
161 | FALSE, |
162 | $membershipTypeID, | |
5b757295 | 163 | TRUE, |
164 | NULL | |
6a488035 TO |
165 | ); |
166 | } | |
167 | ||
168 | $this->_separateMembershipPayment = $this->get('separateMembershipPayment'); | |
169 | $this->assign("is_separate_payment", $this->_separateMembershipPayment); | |
170 | ||
171 | $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE); | |
172 | $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE); | |
a7488080 | 173 | if (!empty($params['hidden_onbehalf_profile'])) { |
6a488035 TO |
174 | $ufJoinParams = array( |
175 | 'module' => 'onBehalf', | |
176 | 'entity_table' => 'civicrm_contribution_page', | |
177 | 'entity_id' => $this->_id, | |
178 | ); | |
179 | $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); | |
180 | $profileId = $OnBehalfProfile[0]; | |
181 | ||
182 | $fieldTypes = array('Contact', 'Organization'); | |
183 | $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); | |
184 | $fieldTypes = array_merge($fieldTypes, $contactSubType); | |
185 | if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) { | |
186 | $fieldTypes = array_merge($fieldTypes, array('Membership')); | |
187 | } | |
188 | else { | |
189 | $fieldTypes = array_merge($fieldTypes, array('Contribution')); | |
190 | } | |
191 | ||
133e2c99 | 192 | $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes); |
6a488035 TO |
193 | } |
194 | ||
195 | $this->assign('trxn_id', | |
196 | CRM_Utils_Array::value('trxn_id', | |
197 | $this->_params | |
198 | ) | |
199 | ); | |
200 | $this->assign('receive_date', | |
201 | CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params)) | |
202 | ); | |
203 | ||
204 | $defaults = array(); | |
205 | $fields = array(); | |
206 | foreach ($this->_fields as $name => $dontCare) { | |
133e2c99 | 207 | if ($name != 'onbehalf' || $name != 'honor') { |
6a488035 TO |
208 | $fields[$name] = 1; |
209 | } | |
210 | } | |
211 | $fields['state_province'] = $fields['country'] = $fields['email'] = 1; | |
212 | $contact = $this->_params = $this->controller->exportValues('Main'); | |
213 | ||
214 | foreach ($fields as $name => $dontCare) { | |
133e2c99 | 215 | if (isset($contact[$name])) { |
6a488035 TO |
216 | $defaults[$name] = $contact[$name]; |
217 | if (substr($name, 0, 7) == 'custom_') { | |
218 | $timeField = "{$name}_time"; | |
219 | if (isset($contact[$timeField])) { | |
220 | $defaults[$timeField] = $contact[$timeField]; | |
221 | } | |
222 | } | |
8cc574cf | 223 | elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) { |
6a488035 TO |
224 | $defaults[$name . '_custom'] = $contact[$name . '_custom']; |
225 | } | |
226 | } | |
227 | } | |
228 | ||
229 | // now fix all state country selectors | |
230 | CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults); | |
231 | ||
232 | $this->_submitValues = array_merge($this->_submitValues, $defaults); | |
233 | $this->setDefaults($defaults); | |
eea16664 | 234 | |
6a488035 TO |
235 | $values['entity_id'] = $this->_id; |
236 | $values['entity_table'] = 'civicrm_contribution_page'; | |
237 | ||
238 | CRM_Friend_BAO_Friend::retrieve($values, $data); | |
239 | $tellAFriend = FALSE; | |
240 | if ($this->_pcpId) { | |
241 | if ($this->_pcpBlock['is_tellfriend_enabled']) { | |
242 | $this->assign('friendText', ts('Tell a Friend')); | |
243 | $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp"; | |
244 | $tellAFriend = TRUE; | |
245 | } | |
246 | } | |
a7488080 | 247 | elseif (!empty($data['is_active'])) { |
6a488035 TO |
248 | $friendText = $data['title']; |
249 | $this->assign('friendText', $friendText); | |
250 | $subUrl = "eid={$this->_id}&pcomponent=contribute"; | |
251 | $tellAFriend = TRUE; | |
252 | } | |
253 | ||
254 | if ($tellAFriend) { | |
255 | if ($this->_action & CRM_Core_Action::PREVIEW) { | |
256 | $url = CRM_Utils_System::url("civicrm/friend", | |
257 | "reset=1&action=preview&{$subUrl}" | |
258 | ); | |
259 | } | |
260 | else { | |
261 | $url = CRM_Utils_System::url("civicrm/friend", | |
262 | "reset=1&{$subUrl}" | |
263 | ); | |
264 | } | |
265 | $this->assign('friendURL', $url); | |
266 | } | |
267 | ||
268 | $this->freeze(); | |
269 | ||
270 | // can we blow away the session now to prevent hackery | |
271 | // CRM-9491 | |
272 | $this->controller->reset(); | |
273 | } | |
274 | } | |
275 |