Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
6a488035 | 29 | * @package CRM |
e7112fa7 | 30 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
31 | */ |
32 | ||
33 | /** | |
3bdf1f3a | 34 | * This class generates form components for processing Event. |
6a488035 TO |
35 | */ |
36 | class CRM_Event_Form_Registration extends CRM_Core_Form { | |
37 | ||
38 | /** | |
100fef9d | 39 | * How many locationBlocks should we display? |
6a488035 TO |
40 | * |
41 | * @var int | |
42 | * @const | |
43 | */ | |
7da04cde | 44 | const LOCATION_BLOCKS = 1; |
6a488035 TO |
45 | |
46 | /** | |
66f9e52b | 47 | * The id of the event we are proceessing. |
6a488035 TO |
48 | * |
49 | * @var int | |
6a488035 TO |
50 | */ |
51 | public $_eventId; | |
52 | ||
53 | /** | |
66f9e52b | 54 | * The array of ids of all the participant we are proceessing. |
6a488035 TO |
55 | * |
56 | * @var int | |
6a488035 TO |
57 | */ |
58 | protected $_participantIDS = NULL; | |
59 | ||
60 | /** | |
66f9e52b | 61 | * The id of the participant we are proceessing. |
6a488035 TO |
62 | * |
63 | * @var int | |
6a488035 TO |
64 | */ |
65 | protected $_participantId; | |
66 | ||
67 | /** | |
100fef9d | 68 | * Is participant able to walk registration wizard. |
6a488035 TO |
69 | * |
70 | * @var Boolean | |
6a488035 TO |
71 | */ |
72 | public $_allowConfirmation; | |
73 | ||
74 | /** | |
66f9e52b | 75 | * Is participant requires approval. |
6a488035 TO |
76 | * |
77 | * @var Boolean | |
6a488035 TO |
78 | */ |
79 | public $_requireApproval; | |
80 | ||
81 | /** | |
100fef9d | 82 | * Is event configured for waitlist. |
6a488035 TO |
83 | * |
84 | * @var Boolean | |
6a488035 TO |
85 | */ |
86 | public $_allowWaitlist; | |
87 | ||
88 | /** | |
66f9e52b | 89 | * Store additional participant ids. |
6a488035 TO |
90 | * when there are pre-registered. |
91 | * | |
92 | * @var array | |
6a488035 TO |
93 | */ |
94 | public $_additionalParticipantIds; | |
95 | ||
96 | /** | |
66f9e52b | 97 | * The mode that we are in. |
6a488035 TO |
98 | * |
99 | * @var string | |
100 | * @protect | |
101 | */ | |
102 | public $_mode; | |
103 | ||
104 | /** | |
66f9e52b | 105 | * The values for the contribution db object. |
6a488035 TO |
106 | * |
107 | * @var array | |
6a488035 TO |
108 | */ |
109 | public $_values; | |
110 | ||
111 | /** | |
66f9e52b | 112 | * The paymentProcessor attributes for this page. |
6a488035 TO |
113 | * |
114 | * @var array | |
6a488035 TO |
115 | */ |
116 | public $_paymentProcessor; | |
117 | ||
118 | /** | |
66f9e52b | 119 | * The params submitted by the form and computed by the app. |
6a488035 TO |
120 | * |
121 | * @var array | |
6a488035 TO |
122 | */ |
123 | protected $_params; | |
124 | ||
125 | /** | |
66f9e52b | 126 | * The fields involved in this contribution page. |
6a488035 TO |
127 | * |
128 | * @var array | |
6a488035 TO |
129 | */ |
130 | public $_fields; | |
131 | ||
132 | /** | |
66f9e52b | 133 | * The billing location id for this contribiution page. |
6a488035 TO |
134 | * |
135 | * @var int | |
6a488035 TO |
136 | */ |
137 | public $_bltID; | |
138 | ||
139 | /** | |
140 | * Price Set ID, if the new price set method is used | |
141 | * | |
142 | * @var int | |
6a488035 TO |
143 | */ |
144 | public $_priceSetId = NULL; | |
145 | ||
146 | /** | |
66f9e52b | 147 | * Array of fields for the price set. |
6a488035 TO |
148 | * |
149 | * @var array | |
6a488035 TO |
150 | */ |
151 | public $_priceSet; | |
152 | ||
153 | public $_action; | |
154 | ||
155 | public $_pcpId; | |
156 | ||
157 | /* Is event already full. | |
e70a7fc0 TO |
158 | * |
159 | * @var boolean | |
160 | */ | |
6a488035 TO |
161 | |
162 | public $_isEventFull; | |
163 | ||
164 | public $_lineItem; | |
165 | public $_lineItemParticipantsCount; | |
166 | public $_availableRegistrations; | |
167 | ||
168 | public $_forcePayement; | |
169 | ||
8ae4d0d3 | 170 | public $_isBillingAddressRequiredForPayLater; |
171 | ||
6a488035 | 172 | /** |
66f9e52b | 173 | * Set variables up before form is built. |
6a488035 | 174 | */ |
00be9182 | 175 | public function preProcess() { |
6a488035 TO |
176 | $this->_eventId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); |
177 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE); | |
178 | ||
179 | //CRM-4320 | |
180 | $this->_participantId = CRM_Utils_Request::retrieve('participantId', 'Positive', $this); | |
181 | ||
182 | // current mode | |
183 | $this->_mode = ($this->_action == 1024) ? 'test' : 'live'; | |
184 | ||
185 | $this->_values = $this->get('values'); | |
186 | $this->_fields = $this->get('fields'); | |
187 | $this->_bltID = $this->get('bltID'); | |
188 | $this->_paymentProcessor = $this->get('paymentProcessor'); | |
189 | $this->_priceSetId = $this->get('priceSetId'); | |
190 | $this->_priceSet = $this->get('priceSet'); | |
191 | $this->_lineItem = $this->get('lineItem'); | |
192 | $this->_isEventFull = $this->get('isEventFull'); | |
193 | $this->_lineItemParticipantsCount = $this->get('lineItemParticipants'); | |
194 | if (!is_array($this->_lineItem)) { | |
195 | $this->_lineItem = array(); | |
196 | } | |
197 | if (!is_array($this->_lineItemParticipantsCount)) { | |
198 | $this->_lineItemParticipantsCount = array(); | |
199 | } | |
200 | $this->_availableRegistrations = $this->get('availableRegistrations'); | |
6a488035 TO |
201 | $this->_participantIDS = $this->get('participantIDs'); |
202 | ||
203 | //check if participant allow to walk registration wizard. | |
204 | $this->_allowConfirmation = $this->get('allowConfirmation'); | |
205 | ||
206 | // check for Approval | |
207 | $this->_requireApproval = $this->get('requireApproval'); | |
208 | ||
209 | // check for waitlisting. | |
210 | $this->_allowWaitlist = $this->get('allowWaitlist'); | |
211 | ||
212 | $this->_forcePayement = $this->get('forcePayement'); | |
213 | ||
214 | //get the additional participant ids. | |
215 | $this->_additionalParticipantIds = $this->get('additionalParticipantIds'); | |
6a488035 TO |
216 | $config = CRM_Core_Config::singleton(); |
217 | ||
218 | if (!$this->_values) { | |
219 | // create redirect URL to send folks back to event info page is registration not available | |
96f7c53e | 220 | $infoUrl = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_eventId}", |
6a488035 TO |
221 | FALSE, NULL, FALSE, TRUE |
222 | ); | |
223 | ||
224 | // this is the first time we are hitting this, so check for permissions here | |
e2d09ab4 | 225 | if (!CRM_Core_Permission::event(CRM_Core_Permission::EDIT, $this->_eventId, 'register for events')) { |
6a488035 TO |
226 | CRM_Core_Error::statusBounce(ts('You do not have permission to register for this event'), $infoUrl); |
227 | } | |
228 | ||
229 | // get all the values from the dao object | |
96f7c53e | 230 | $this->_values = $this->_fields = array(); |
6a488035 TO |
231 | $this->_forcePayement = FALSE; |
232 | ||
233 | //retrieve event information | |
234 | $params = array('id' => $this->_eventId); | |
235 | CRM_Event_BAO_Event::retrieve($params, $this->_values['event']); | |
9ed3cd18 E |
236 | // check for is_monetary status |
237 | $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values['event']); | |
238 | // check for ability to add contributions of type | |
a8b59c2c | 239 | if ($isMonetary |
4323dc6c PN |
240 | && CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() |
241 | && !CRM_Core_Permission::check('add contributions of type ' . CRM_Contribute_PseudoConstant::financialType($this->_values['event']['financial_type_id'])) | |
242 | ) { | |
9ed3cd18 E |
243 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); |
244 | } | |
6a488035 TO |
245 | |
246 | $this->checkValidEvent($infoUrl); | |
6a488035 TO |
247 | // get the participant values, CRM-4320 |
248 | $this->_allowConfirmation = FALSE; | |
249 | if ($this->_participantId) { | |
250 | $this->processFirstParticipant($this->_participantId); | |
251 | } | |
6a488035 TO |
252 | //check for additional participants. |
253 | if ($this->_allowConfirmation && $this->_values['event']['is_multiple_registrations']) { | |
254 | $additionalParticipantIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_participantId); | |
255 | $cnt = 1; | |
256 | foreach ($additionalParticipantIds as $additionalParticipantId) { | |
257 | $this->_additionalParticipantIds[$cnt] = $additionalParticipantId; | |
258 | $cnt++; | |
259 | } | |
260 | $this->set('additionalParticipantIds', $this->_additionalParticipantIds); | |
261 | } | |
262 | ||
96f7c53e | 263 | $eventFull = CRM_Event_BAO_Participant::eventFull($this->_eventId, FALSE, |
6a488035 TO |
264 | CRM_Utils_Array::value('has_waitlist', $this->_values['event']) |
265 | ); | |
266 | ||
96f7c53e | 267 | $this->_allowWaitlist = $this->_isEventFull = FALSE; |
6a488035 TO |
268 | if ($eventFull && !$this->_allowConfirmation) { |
269 | $this->_isEventFull = TRUE; | |
270 | //lets redirecting to info only when to waiting list. | |
271 | $this->_allowWaitlist = CRM_Utils_Array::value('has_waitlist', $this->_values['event']); | |
272 | if (!$this->_allowWaitlist) { | |
273 | CRM_Utils_System::redirect($infoUrl); | |
274 | } | |
275 | } | |
276 | $this->set('isEventFull', $this->_isEventFull); | |
277 | $this->set('allowWaitlist', $this->_allowWaitlist); | |
278 | ||
279 | //check for require requires approval. | |
280 | $this->_requireApproval = FALSE; | |
a7488080 | 281 | if (!empty($this->_values['event']['requires_approval']) && !$this->_allowConfirmation) { |
6a488035 TO |
282 | $this->_requireApproval = TRUE; |
283 | } | |
284 | $this->set('requireApproval', $this->_requireApproval); | |
285 | ||
6a488035 TO |
286 | if (isset($this->_values['event']['default_role_id'])) { |
287 | $participant_role = CRM_Core_OptionGroup::values('participant_role'); | |
288 | $this->_values['event']['participant_role'] = $participant_role["{$this->_values['event']['default_role_id']}"]; | |
289 | } | |
96f7c53e | 290 | $isPayLater = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eventId, 'is_pay_later'); |
2c5311b9 | 291 | //check for various combinations for paylater, payment |
6a488035 | 292 | //process with paid event. |
8cc574cf | 293 | if ($isMonetary && (!$isPayLater || !empty($this->_values['event']['payment_processor']))) { |
2c5311b9 | 294 | $this->_paymentProcessorIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('payment_processor', |
6a488035 | 295 | $this->_values['event'] |
2c5311b9 | 296 | )); |
cbcb5b49 | 297 | $this->assignPaymentProcessor($isPayLater); |
6a488035 | 298 | |
6a488035 | 299 | } |
6a488035 | 300 | //init event fee. |
96f7c53e | 301 | self::initEventFee($this, $this->_eventId); |
6a488035 TO |
302 | |
303 | // get the profile ids | |
304 | $ufJoinParams = array( | |
305 | 'entity_table' => 'civicrm_event', | |
306 | // CRM-4377:Â CiviEvent for the main participant, CiviEvent_Additional for additional participants | |
307 | 'module' => 'CiviEvent', | |
308 | 'entity_id' => $this->_eventId, | |
309 | ); | |
310 | list($this->_values['custom_pre_id'], | |
311 | $this->_values['custom_post_id'] | |
353ffa53 | 312 | ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); |
6a488035 TO |
313 | |
314 | // set profiles for additional participants | |
315 | if ($this->_values['event']['is_multiple_registrations']) { | |
96f7c53e PJ |
316 | // CRM-4377:Â CiviEvent for the main participant, CiviEvent_Additional for additional participants |
317 | $ufJoinParams['module'] = 'CiviEvent_Additional'; | |
318 | ||
6a488035 TO |
319 | list($this->_values['additional_custom_pre_id'], |
320 | $this->_values['additional_custom_post_id'], $preActive, $postActive | |
353ffa53 | 321 | ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); |
6a488035 TO |
322 | |
323 | // CRM-4377:Â we need to maintain backward compatibility, hence if there is profile for main contact | |
324 | // set same profile for additional contacts. | |
325 | if ($this->_values['custom_pre_id'] && !$this->_values['additional_custom_pre_id']) { | |
326 | $this->_values['additional_custom_pre_id'] = $this->_values['custom_pre_id']; | |
327 | } | |
328 | ||
329 | if ($this->_values['custom_post_id'] && !$this->_values['additional_custom_post_id']) { | |
330 | $this->_values['additional_custom_post_id'] = $this->_values['custom_post_id']; | |
331 | } | |
6a488035 TO |
332 | // now check for no profile condition, in that case is_active = 0 |
333 | if (isset($preActive) && !$preActive) { | |
334 | unset($this->_values['additional_custom_pre_id']); | |
335 | } | |
6a488035 TO |
336 | if (isset($postActive) && !$postActive) { |
337 | unset($this->_values['additional_custom_post_id']); | |
338 | } | |
339 | } | |
8345c9d3 EM |
340 | |
341 | $this->assignBillingType(); | |
6a488035 | 342 | |
a6513ad5 EM |
343 | if ($this->_values['event']['is_monetary']) { |
344 | CRM_Core_Payment_Form::setPaymentFieldsByProcessor($this, $this->_paymentProcessor); | |
6a488035 | 345 | } |
6a488035 TO |
346 | $params = array('entity_id' => $this->_eventId, 'entity_table' => 'civicrm_event'); |
347 | $this->_values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE); | |
348 | ||
349 | $this->set('values', $this->_values); | |
350 | $this->set('fields', $this->_fields); | |
351 | ||
7c550ca0 WA |
352 | $this->_availableRegistrations |
353 | = CRM_Event_BAO_Participant::eventFull( | |
96f7c53e | 354 | $this->_values['event']['id'], TRUE, |
6a488035 TO |
355 | CRM_Utils_Array::value('has_waitlist', $this->_values['event']) |
356 | ); | |
357 | $this->set('availableRegistrations', $this->_availableRegistrations); | |
358 | } | |
6a488035 TO |
359 | $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor); |
360 | ||
361 | // check if this is a paypal auto return and redirect accordingly | |
362 | if (CRM_Core_Payment::paypalRedirect($this->_paymentProcessor)) { | |
363 | $url = CRM_Utils_System::url('civicrm/event/register', | |
364 | "_qf_ThankYou_display=1&qfKey={$this->controller->_key}" | |
365 | ); | |
366 | CRM_Utils_System::redirect($url); | |
367 | } | |
0f2b049e | 368 | // The concept of contributeMode is deprecated. |
6a488035 TO |
369 | $this->_contributeMode = $this->get('contributeMode'); |
370 | $this->assign('contributeMode', $this->_contributeMode); | |
371 | ||
372 | // setting CMS page title | |
373 | CRM_Utils_System::setTitle($this->_values['event']['title']); | |
374 | $this->assign('title', $this->_values['event']['title']); | |
375 | ||
376 | $this->assign('paidEvent', $this->_values['event']['is_monetary']); | |
377 | ||
378 | // we do not want to display recently viewed items on Registration pages | |
379 | $this->assign('displayRecent', FALSE); | |
380 | // Registration page values are cleared from session, so can't use normal Printer Friendly view. | |
381 | // Use Browser Print instead. | |
382 | $this->assign('browserPrint', TRUE); | |
383 | ||
384 | $isShowLocation = CRM_Utils_Array::value('is_show_location', $this->_values['event']); | |
385 | $this->assign('isShowLocation', $isShowLocation); | |
6a488035 TO |
386 | // Handle PCP |
387 | $pcpId = CRM_Utils_Request::retrieve('pcpId', 'Positive', $this); | |
388 | if ($pcpId) { | |
353ffa53 TO |
389 | $pcp = CRM_PCP_BAO_PCP::handlePcp($pcpId, 'event', $this->_values['event']); |
390 | $this->_pcpId = $pcp['pcpId']; | |
2fd5e617 | 391 | $this->_values['event']['intro_text'] = CRM_Utils_Array::value('intro_text', $pcp['pcpInfo']); |
6a488035 TO |
392 | } |
393 | ||
394 | // assign all event properties so wizard templates can display event info. | |
395 | $this->assign('event', $this->_values['event']); | |
396 | $this->assign('location', $this->_values['location']); | |
397 | $this->assign('bltID', $this->_bltID); | |
398 | $isShowLocation = CRM_Utils_Array::value('is_show_location', $this->_values['event']); | |
399 | $this->assign('isShowLocation', $isShowLocation); | |
6a488035 | 400 | //CRM-6907 |
96f7c53e | 401 | $config->defaultCurrency = CRM_Utils_Array::value('currency', $this->_values['event'], |
6a488035 TO |
402 | $config->defaultCurrency |
403 | ); | |
404 | ||
405 | //lets allow user to override campaign. | |
406 | $campID = CRM_Utils_Request::retrieve('campID', 'Positive', $this); | |
407 | if ($campID && CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) { | |
408 | $this->_values['event']['campaign_id'] = $campID; | |
409 | } | |
8ae4d0d3 | 410 | |
f48e6cf7 | 411 | // Set the same value for is_billing_required as contribution page so code can be shared. |
412 | $this->_values['is_billing_required'] = CRM_Utils_Array::value('is_billing_required', $this->_values['event']); | |
8ae4d0d3 | 413 | // check if billing block is required for pay later |
f48e6cf7 | 414 | // note that I have started removing the use of isBillingAddressRequiredForPayLater in favour of letting |
415 | // the CRM_Core_Payment_Manual class handle it - but there are ~300 references to it in the code base so only | |
416 | // removing in very limited cases. | |
8ae4d0d3 | 417 | if (CRM_Utils_Array::value('is_pay_later', $this->_values['event'])) { |
418 | $this->_isBillingAddressRequiredForPayLater = CRM_Utils_Array::value('is_billing_required', $this->_values['event']); | |
419 | $this->assign('isBillingAddressRequiredForPayLater', $this->_isBillingAddressRequiredForPayLater); | |
420 | } | |
6a488035 TO |
421 | } |
422 | ||
423 | /** | |
66f9e52b | 424 | * Assign the minimal set of variables to the template. |
6a488035 | 425 | */ |
00be9182 | 426 | public function assignToTemplate() { |
6a488035 TO |
427 | //process only primary participant params |
428 | $this->_params = $this->get('params'); | |
429 | if (isset($this->_params[0])) { | |
430 | $params = $this->_params[0]; | |
431 | } | |
432 | $name = ''; | |
a7488080 | 433 | if (!empty($params['billing_first_name'])) { |
6a488035 TO |
434 | $name = $params['billing_first_name']; |
435 | } | |
436 | ||
a7488080 | 437 | if (!empty($params['billing_middle_name'])) { |
6a488035 TO |
438 | $name .= " {$params['billing_middle_name']}"; |
439 | } | |
440 | ||
a7488080 | 441 | if (!empty($params['billing_last_name'])) { |
6a488035 TO |
442 | $name .= " {$params['billing_last_name']}"; |
443 | } | |
444 | $this->assign('billingName', $name); | |
445 | $this->set('name', $name); | |
446 | ||
447 | $vars = array( | |
353ffa53 TO |
448 | 'amount', |
449 | 'currencyID', | |
450 | 'credit_card_type', | |
451 | 'trxn_id', | |
452 | 'amount_level', | |
453 | 'receive_date', | |
6a488035 TO |
454 | ); |
455 | ||
456 | foreach ($vars as $v) { | |
a7488080 | 457 | if (!empty($params[$v])) { |
6a488035 TO |
458 | if ($v == 'receive_date') { |
459 | $this->assign($v, CRM_Utils_Date::mysqlToIso($params[$v])); | |
460 | } | |
461 | else { | |
462 | $this->assign($v, $params[$v]); | |
463 | } | |
464 | } | |
465 | elseif (CRM_Utils_Array::value('amount', $params) == 0) { | |
466 | $this->assign($v, CRM_Utils_Array::value($v, $params)); | |
467 | } | |
468 | } | |
469 | ||
470 | // assign the address formatted up for display | |
471 | $addressParts = array( | |
472 | "street_address-{$this->_bltID}", | |
473 | "city-{$this->_bltID}", | |
474 | "postal_code-{$this->_bltID}", | |
475 | "state_province-{$this->_bltID}", | |
476 | "country-{$this->_bltID}", | |
477 | ); | |
478 | $addressFields = array(); | |
479 | foreach ($addressParts as $part) { | |
480 | list($n, $id) = explode('-', $part); | |
481 | if (isset($params['billing_' . $part])) { | |
482 | $addressFields[$n] = CRM_Utils_Array::value('billing_' . $part, $params); | |
483 | } | |
484 | } | |
485 | ||
486 | $this->assign('address', CRM_Utils_Address::format($addressFields)); | |
487 | ||
0f2b049e | 488 | // The concept of contributeMode is deprecated. |
8cc574cf | 489 | if ($this->_contributeMode == 'direct' && empty($params['is_pay_later'])) { |
6a488035 TO |
490 | $date = CRM_Utils_Date::format(CRM_Utils_Array::value('credit_card_exp_date', $params)); |
491 | $date = CRM_Utils_Date::mysqlToIso($date); | |
492 | $this->assign('credit_card_exp_date', $date); | |
493 | $this->assign('credit_card_number', | |
494 | CRM_Utils_System::mungeCreditCard(CRM_Utils_Array::value('credit_card_number', $params)) | |
495 | ); | |
496 | } | |
497 | ||
498 | // get the email that the confirmation would have been sent to | |
499 | $session = CRM_Core_Session::singleton(); | |
500 | ||
501 | // assign is_email_confirm to templates | |
502 | if (isset($this->_values['event']['is_email_confirm'])) { | |
503 | $this->assign('is_email_confirm', $this->_values['event']['is_email_confirm']); | |
504 | } | |
505 | ||
506 | // assign pay later stuff | |
507 | $params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE); | |
508 | $this->assign('is_pay_later', $params['is_pay_later']); | |
509 | if ($params['is_pay_later']) { | |
510 | $this->assign('pay_later_text', $this->_values['event']['pay_later_text']); | |
511 | $this->assign('pay_later_receipt', $this->_values['event']['pay_later_receipt']); | |
512 | } | |
513 | ||
514 | // also assign all participantIDs to the template | |
515 | // useful in generating confirmation numbers if needed | |
516 | $this->assign('participantIDs', | |
517 | $this->_participantIDS | |
518 | ); | |
519 | } | |
520 | ||
521 | /** | |
66f9e52b | 522 | * Add the custom fields. |
6a488035 | 523 | * |
100fef9d CW |
524 | * @param int $id |
525 | * @param string $name | |
77b97be7 | 526 | * @param bool $viewOnly |
6a488035 | 527 | */ |
00be9182 | 528 | public function buildCustom($id, $name, $viewOnly = FALSE) { |
6a488035 | 529 | if ($id) { |
353ffa53 TO |
530 | $button = substr($this->controller->getButtonName(), -4); |
531 | $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this); | |
532 | $session = CRM_Core_Session::singleton(); | |
6a488035 TO |
533 | $contactID = $session->get('userID'); |
534 | ||
535 | // we don't allow conflicting fields to be | |
536 | // configured via profile | |
537 | $fieldsToIgnore = array( | |
538 | 'participant_fee_amount' => 1, | |
539 | 'participant_fee_level' => 1, | |
540 | ); | |
541 | if ($contactID) { | |
542 | //FIX CRM-9653 | |
543 | if (is_array($id)) { | |
544 | $fields = array(); | |
545 | foreach ($id as $profileID) { | |
546 | $field = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, CRM_Core_Action::ADD, | |
547 | NULL, NULL, FALSE, NULL, | |
548 | FALSE, NULL, CRM_Core_Permission::CREATE, | |
549 | 'field_name', TRUE | |
550 | ); | |
551 | $fields = array_merge($fields, $field); | |
552 | } | |
553 | } | |
554 | else { | |
555 | if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) { | |
556 | $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, | |
557 | NULL, NULL, FALSE, NULL, | |
558 | FALSE, NULL, CRM_Core_Permission::CREATE, | |
559 | 'field_name', TRUE | |
560 | ); | |
561 | } | |
562 | } | |
563 | } | |
564 | else { | |
565 | $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, | |
566 | NULL, NULL, FALSE, NULL, | |
567 | FALSE, NULL, CRM_Core_Permission::CREATE, | |
568 | 'field_name', TRUE | |
569 | ); | |
570 | } | |
571 | ||
572 | if (array_intersect_key($fields, $fieldsToIgnore)) { | |
573 | $fields = array_diff_key($fields, $fieldsToIgnore); | |
574 | CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.')); | |
575 | } | |
576 | $addCaptcha = FALSE; | |
a2149acc | 577 | |
578 | if (!empty($this->_fields)) { | |
579 | $fields = @array_diff_assoc($fields, $this->_fields); | |
580 | } | |
581 | ||
a7488080 | 582 | if (empty($this->_params[0]['additional_participants']) && |
6a488035 TO |
583 | is_null($cid) |
584 | ) { | |
585 | CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID); | |
586 | } | |
587 | $this->assign($name, $fields); | |
6a488035 TO |
588 | if (is_array($fields)) { |
589 | foreach ($fields as $key => $field) { | |
590 | if ($viewOnly && | |
591 | isset($field['data_type']) && | |
592 | $field['data_type'] == 'File' || ($viewOnly && $field['name'] == 'image_URL') | |
593 | ) { | |
594 | // ignore file upload fields | |
595 | continue; | |
596 | } | |
597 | //make the field optional if primary participant | |
598 | //have been skip the additional participant. | |
599 | if ($button == 'skip') { | |
600 | $field['is_required'] = FALSE; | |
da8d9879 | 601 | } |
71fc6ea4 | 602 | // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor |
353ffa53 | 603 | elseif ($field['add_captcha'] && !$contactID) { |
6a488035 TO |
604 | // only add captcha for first page |
605 | $addCaptcha = TRUE; | |
606 | } | |
6a488035 | 607 | list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2); |
6a488035 TO |
608 | CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE); |
609 | ||
610 | $this->_fields[$key] = $field; | |
611 | } | |
612 | } | |
4839c695 | 613 | |
6a488035 TO |
614 | if ($addCaptcha && !$viewOnly) { |
615 | $captcha = CRM_Utils_ReCAPTCHA::singleton(); | |
616 | $captcha->add($this); | |
617 | $this->assign('isCaptcha', TRUE); | |
618 | } | |
619 | } | |
620 | } | |
621 | ||
0cf587a7 | 622 | /** |
3bdf1f3a | 623 | * Initiate event fee. |
624 | * | |
c490a46a | 625 | * @param CRM_Core_Form $form |
100fef9d | 626 | * @param int $eventID |
0cf587a7 EM |
627 | * |
628 | * @throws Exception | |
629 | */ | |
00be9182 | 630 | public static function initEventFee(&$form, $eventID) { |
6a488035 TO |
631 | // get price info |
632 | ||
633 | // retrive all active price set fields. | |
634 | $discountId = CRM_Core_BAO_Discount::findSet($eventID, 'civicrm_event'); | |
8567d0f8 PN |
635 | if (property_exists($form, '_discountId') && $form->_discountId) { |
636 | $discountId = $form->_discountId; | |
637 | } | |
d4acad97 SB |
638 | |
639 | //CRM-16456 get all price field including expired one. | |
640 | $getAllPriceField = TRUE; | |
641 | $className = CRM_Utils_System::getClassName($form); | |
642 | if ($className == 'CRM_Event_Form_ParticipantFeeSelection' && $form->_action == CRM_Core_Action::UPDATE) { | |
643 | $getAllPriceField = FALSE; | |
644 | } | |
645 | ||
6a488035 TO |
646 | if ($discountId) { |
647 | $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id'); | |
d4acad97 | 648 | $price = CRM_Price_BAO_PriceSet::initSet($form, $eventID, 'civicrm_event', $getAllPriceField, $priceSetId); |
6a488035 TO |
649 | } |
650 | else { | |
d4acad97 | 651 | $price = CRM_Price_BAO_PriceSet::initSet($form, $eventID, 'civicrm_event', $getAllPriceField); |
6a488035 | 652 | } |
8ef12e64 | 653 | |
654 | if (property_exists($form, '_context') && ($form->_context == 'standalone' | |
353ffa53 TO |
655 | || $form->_context == 'participant') |
656 | ) { | |
8567d0f8 | 657 | $discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($eventID, 'civicrm_event'); |
481a74f4 | 658 | if (is_array($discountedEvent)) { |
8567d0f8 | 659 | foreach ($discountedEvent as $key => $priceSetId) { |
9da8dc8c | 660 | $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId); |
8567d0f8 PN |
661 | $priceSet = CRM_Utils_Array::value($priceSetId, $priceSet); |
662 | $form->_values['discount'][$key] = CRM_Utils_Array::value('fields', $priceSet); | |
663 | $fieldID = key($form->_values['discount'][$key]); | |
664 | $form->_values['discount'][$key][$fieldID]['name'] = CRM_Core_DAO::getFieldValue( | |
9da8dc8c | 665 | 'CRM_Price_DAO_PriceSet', |
8567d0f8 PN |
666 | $priceSetId, |
667 | 'title' | |
668 | ); | |
669 | } | |
670 | } | |
671 | } | |
6a488035 TO |
672 | $eventFee = CRM_Utils_Array::value('fee', $form->_values); |
673 | if (!is_array($eventFee) || empty($eventFee)) { | |
674 | $form->_values['fee'] = array(); | |
675 | } | |
676 | ||
677 | //fix for non-upgraded price sets.CRM-4256. | |
678 | if (isset($form->_isPaidEvent)) { | |
679 | $isPaidEvent = $form->_isPaidEvent; | |
680 | } | |
681 | else { | |
682 | $isPaidEvent = CRM_Utils_Array::value('is_monetary', $form->_values['event']); | |
683 | } | |
a8b59c2c | 684 | if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() |
4323dc6c PN |
685 | && !empty($form->_values['fee']) |
686 | ) { | |
b61d1bce | 687 | foreach ($form->_values['fee'] as $k => $fees) { |
9ed3cd18 E |
688 | foreach ($fees['options'] as $options) { |
689 | if (!CRM_Core_Permission::check('add contributions of type ' . CRM_Contribute_PseudoConstant::financialType($options['financial_type_id']))) { | |
b61d1bce | 690 | unset($form->_values['fee'][$k]); |
9ed3cd18 E |
691 | } |
692 | } | |
693 | } | |
694 | } | |
6a488035 TO |
695 | if ($isPaidEvent && empty($form->_values['fee'])) { |
696 | if (CRM_Utils_System::getClassName($form) != 'CRM_Event_Form_Participant') { | |
697 | CRM_Core_Error::fatal(ts('No Fee Level(s) or Price Set is configured for this event.<br />Click <a href=\'%1\'>CiviEvent >> Manage Event >> Configure >> Event Fees</a> to configure the Fee Level(s) or Price Set for this event.', array(1 => CRM_Utils_System::url('civicrm/event/manage/fee', 'reset=1&action=update&id=' . $form->_eventId)))); | |
698 | } | |
699 | } | |
700 | } | |
701 | ||
702 | /** | |
66f9e52b | 703 | * Handle process after the confirmation of payment by User. |
6a488035 | 704 | * |
100fef9d | 705 | * @param int $contactID |
2a6da8d7 EM |
706 | * @param null $contribution |
707 | * @param null $payment | |
6a488035 | 708 | */ |
00be9182 | 709 | public function confirmPostProcess($contactID = NULL, $contribution = NULL, $payment = NULL) { |
6a488035 TO |
710 | // add/update contact information |
711 | $fields = array(); | |
712 | unset($this->_params['note']); | |
713 | ||
714 | //to avoid conflict overwrite $this->_params | |
715 | $this->_params = $this->get('value'); | |
716 | ||
717 | //get the amount of primary participant | |
a7488080 | 718 | if (!empty($this->_params['is_primary'])) { |
6a488035 TO |
719 | $this->_params['fee_amount'] = $this->get('primaryParticipantAmount'); |
720 | } | |
721 | ||
722 | // add participant record | |
bf2c70af | 723 | $participant = CRM_Event_Form_Registration::addParticipant($this, $contactID); |
6a488035 TO |
724 | $this->_participantIDS[] = $participant->id; |
725 | ||
726 | //setting register_by_id field and primaryContactId | |
a7488080 | 727 | if (!empty($this->_params['is_primary'])) { |
6a488035 TO |
728 | $this->set('registerByID', $participant->id); |
729 | $this->set('primaryContactId', $contactID); | |
730 | ||
731 | // CRM-10032 | |
732 | $this->processFirstParticipant($participant->id); | |
733 | } | |
734 | ||
735 | CRM_Core_BAO_CustomValueTable::postProcess($this->_params, | |
6a488035 TO |
736 | 'civicrm_participant', |
737 | $participant->id, | |
738 | 'Participant' | |
739 | ); | |
740 | ||
741 | $createPayment = (CRM_Utils_Array::value('amount', $this->_params, 0) != 0) ? TRUE : FALSE; | |
742 | ||
743 | // force to create zero amount payment, CRM-5095 | |
744 | // we know the amout is zero since createPayment is false | |
745 | if (!$createPayment && | |
746 | (isset($contribution) && $contribution->id) && | |
747 | $this->_priceSetId && | |
748 | $this->_lineItem | |
749 | ) { | |
750 | $createPayment = TRUE; | |
751 | } | |
752 | ||
8cc574cf | 753 | if ($createPayment && $this->_values['event']['is_monetary'] && !empty($this->_params['contributionID'])) { |
6a488035 TO |
754 | $paymentParams = array( |
755 | 'participant_id' => $participant->id, | |
756 | 'contribution_id' => $contribution->id, | |
757 | ); | |
758 | $ids = array(); | |
759 | $paymentPartcipant = CRM_Event_BAO_ParticipantPayment::create($paymentParams, $ids); | |
760 | } | |
761 | ||
762 | //set only primary participant's params for transfer checkout. | |
0f2b049e | 763 | // The concept of contributeMode is deprecated. |
8cc574cf | 764 | if (($this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify') && !empty($this->_params['is_primary'])) { |
6a488035 TO |
765 | $this->_params['participantID'] = $participant->id; |
766 | $this->set('primaryParticipant', $this->_params); | |
767 | } | |
768 | ||
769 | $this->assign('action', $this->_action); | |
770 | ||
771 | // create CMS user | |
a7488080 | 772 | if (!empty($this->_params['cms_create_account'])) { |
6a488035 TO |
773 | $this->_params['contactID'] = $contactID; |
774 | ||
775 | if (array_key_exists('email-5', $this->_params)) { | |
353ffa53 | 776 | $mail = 'email-5'; |
0db6c3e1 TO |
777 | } |
778 | else { | |
6a488035 TO |
779 | foreach ($this->_params as $name => $dontCare) { |
780 | if (substr($name, 0, 5) == 'email') { | |
781 | $mail = $name; | |
782 | break; | |
783 | } | |
784 | } | |
785 | } | |
786 | ||
787 | // we should use primary email for | |
788 | // 1. free event registration. | |
789 | // 2. pay later participant. | |
790 | // 3. waiting list participant. | |
791 | // 4. require approval participant. | |
a7488080 | 792 | if (!empty($this->_params['is_pay_later']) || |
353ffa53 TO |
793 | $this->_allowWaitlist || $this->_requireApproval || empty($this->_values['event']['is_monetary']) |
794 | ) { | |
6a488035 TO |
795 | $mail = 'email-Primary'; |
796 | } | |
797 | ||
798 | if (!CRM_Core_BAO_CMSUser::create($this->_params, $mail)) { | |
799 | CRM_Core_Error::statusBounce(ts('Your profile is not saved and Account is not created.')); | |
800 | } | |
801 | } | |
802 | } | |
803 | ||
804 | /** | |
66f9e52b | 805 | * Process the participant. |
6a488035 | 806 | * |
3ab5efa9 | 807 | * @param CRM_Core_Form $form |
100fef9d | 808 | * @param int $contactID |
3bdf1f3a | 809 | * |
3ab5efa9 | 810 | * @return \CRM_Event_BAO_Participant |
6a488035 | 811 | */ |
bf2c70af | 812 | public static function addParticipant(&$form, $contactID) { |
813 | if (empty($form->_params)) { | |
7c550ca0 | 814 | return NULL; |
bf2c70af | 815 | } |
816 | $params = $form->_params; | |
6a488035 TO |
817 | $transaction = new CRM_Core_Transaction(); |
818 | ||
819 | $groupName = 'participant_role'; | |
820 | $query = " | |
821 | SELECT v.label as label ,v.value as value | |
822 | FROM civicrm_option_value v, | |
823 | civicrm_option_group g | |
824 | WHERE v.option_group_id = g.id | |
825 | AND g.name = %1 | |
826 | AND v.is_active = 1 | |
827 | AND g.is_active = 1 | |
828 | "; | |
829 | $p = array(1 => array($groupName, 'String')); | |
830 | ||
831 | $dao = CRM_Core_DAO::executeQuery($query, $p); | |
832 | if ($dao->fetch()) { | |
833 | $roleID = $dao->value; | |
834 | } | |
835 | ||
836 | // handle register date CRM-4320 | |
837 | $registerDate = NULL; | |
bf2c70af | 838 | if (!empty($form->_allowConfirmation) && $form->_participantId) { |
6a488035 TO |
839 | $registerDate = $params['participant_register_date']; |
840 | } | |
a7488080 | 841 | elseif (!empty($params['participant_register_date']) && |
6a488035 TO |
842 | is_array($params['participant_register_date']) && |
843 | !empty($params['participant_register_date']) | |
844 | ) { | |
845 | $registerDate = CRM_Utils_Date::format($params['participant_register_date']); | |
846 | } | |
847 | ||
6441bcc8 | 848 | $participantFields = CRM_Event_DAO_Participant::fields(); |
6ea503d4 TO |
849 | $participantParams = array( |
850 | 'id' => CRM_Utils_Array::value('participant_id', $params), | |
6a488035 | 851 | 'contact_id' => $contactID, |
bf2c70af | 852 | 'event_id' => $form->_eventId ? $form->_eventId : $params['event_id'], |
6a488035 TO |
853 | 'status_id' => CRM_Utils_Array::value('participant_status', |
854 | $params, 1 | |
855 | ), | |
856 | 'role_id' => CRM_Utils_Array::value('participant_role_id', | |
857 | $params, $roleID | |
858 | ), | |
859 | 'register_date' => ($registerDate) ? $registerDate : date('YmdHis'), | |
6441bcc8 | 860 | 'source' => CRM_Utils_String::ellipsify( |
7c550ca0 | 861 | isset($params['participant_source']) ? CRM_Utils_Array::value('participant_source', $params) : CRM_Utils_Array::value('description', $params), |
6441bcc8 NG |
862 | $participantFields['participant_source']['maxlength'] |
863 | ), | |
6a488035 TO |
864 | 'fee_level' => CRM_Utils_Array::value('amount_level', $params), |
865 | 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0), | |
866 | 'fee_amount' => CRM_Utils_Array::value('fee_amount', $params), | |
867 | 'registered_by_id' => CRM_Utils_Array::value('registered_by_id', $params), | |
868 | 'discount_id' => CRM_Utils_Array::value('discount_id', $params), | |
869 | 'fee_currency' => CRM_Utils_Array::value('currencyID', $params), | |
870 | 'campaign_id' => CRM_Utils_Array::value('campaign_id', $params), | |
871 | ); | |
872 | ||
bf2c70af | 873 | if ($form->_action & CRM_Core_Action::PREVIEW || CRM_Utils_Array::value('mode', $params) == 'test') { |
6a488035 TO |
874 | $participantParams['is_test'] = 1; |
875 | } | |
876 | else { | |
877 | $participantParams['is_test'] = 0; | |
878 | } | |
879 | ||
bf2c70af | 880 | if (!empty($form->_params['note'])) { |
881 | $participantParams['note'] = $form->_params['note']; | |
6a488035 | 882 | } |
bf2c70af | 883 | elseif (!empty($form->_params['participant_note'])) { |
884 | $participantParams['note'] = $form->_params['participant_note']; | |
6a488035 TO |
885 | } |
886 | ||
887 | // reuse id if one already exists for this one (can happen | |
888 | // with back button being hit etc) | |
8cc574cf | 889 | if (!$participantParams['id'] && !empty($params['contributionID'])) { |
6a488035 TO |
890 | $pID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', |
891 | $params['contributionID'], | |
892 | 'participant_id', | |
893 | 'contribution_id' | |
894 | ); | |
895 | $participantParams['id'] = $pID; | |
896 | } | |
bf2c70af | 897 | $participantParams['discount_id'] = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event'); |
6a488035 TO |
898 | |
899 | if (!$participantParams['discount_id']) { | |
900 | $participantParams['discount_id'] = "null"; | |
901 | } | |
902 | ||
903 | $participant = CRM_Event_BAO_Participant::create($participantParams); | |
904 | ||
905 | $transaction->commit(); | |
906 | ||
907 | return $participant; | |
908 | } | |
909 | ||
0cf587a7 | 910 | /** |
3bdf1f3a | 911 | * Calculate the total participant count as per params. |
912 | * | |
c490a46a CW |
913 | * @param CRM_Core_Form $form |
914 | * @param array $params | |
3bdf1f3a | 915 | * User params. |
0cf587a7 EM |
916 | * @param bool $skipCurrent |
917 | * | |
3bdf1f3a | 918 | * @return int |
0cf587a7 | 919 | */ |
6a488035 TO |
920 | public static function getParticipantCount(&$form, $params, $skipCurrent = FALSE) { |
921 | $totalCount = 0; | |
922 | if (!is_array($params) || empty($params)) { | |
923 | return $totalCount; | |
924 | } | |
925 | ||
353ffa53 TO |
926 | $priceSetId = $form->get('priceSetId'); |
927 | $addParticipantNum = substr($form->_name, 12); | |
928 | $priceSetFields = $priceSetDetails = array(); | |
6a488035 TO |
929 | $hasPriceFieldsCount = FALSE; |
930 | if ($priceSetId) { | |
931 | $priceSetDetails = $form->get('priceSet'); | |
932 | if (isset($priceSetDetails['optionsCountTotal']) | |
933 | && $priceSetDetails['optionsCountTotal'] | |
934 | ) { | |
935 | $hasPriceFieldsCount = TRUE; | |
936 | $priceSetFields = $priceSetDetails['optionsCountDetails']['fields']; | |
937 | } | |
938 | } | |
939 | ||
940 | $singleFormParams = FALSE; | |
941 | foreach ($params as $key => $val) { | |
942 | if (!is_numeric($key)) { | |
943 | $singleFormParams = TRUE; | |
944 | break; | |
945 | } | |
946 | } | |
947 | ||
948 | //first format the params. | |
949 | if ($singleFormParams) { | |
950 | $params = self::formatPriceSetParams($form, $params); | |
951 | $params = array($params); | |
952 | } | |
953 | ||
954 | foreach ($params as $key => $values) { | |
955 | if (!is_numeric($key) || | |
956 | $values == 'skip' || | |
957 | ($skipCurrent && ($addParticipantNum == $key)) | |
958 | ) { | |
959 | continue; | |
960 | } | |
961 | $count = 1; | |
962 | ||
963 | $usedCache = FALSE; | |
964 | $cacheCount = CRM_Utils_Array::value($key, $form->_lineItemParticipantsCount); | |
965 | if ($cacheCount && is_numeric($cacheCount)) { | |
966 | $count = $cacheCount; | |
967 | $usedCache = TRUE; | |
968 | } | |
969 | ||
970 | if (!$usedCache && $hasPriceFieldsCount) { | |
971 | $count = 0; | |
972 | foreach ($values as $valKey => $value) { | |
973 | if (strpos($valKey, 'price_') === FALSE) { | |
974 | continue; | |
975 | } | |
976 | $priceFieldId = substr($valKey, 6); | |
977 | if (!$priceFieldId || | |
978 | !is_array($value) || | |
979 | !array_key_exists($priceFieldId, $priceSetFields) | |
980 | ) { | |
981 | continue; | |
982 | } | |
983 | foreach ($value as $optId => $optVal) { | |
984 | $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal; | |
985 | if ($currentCount) { | |
986 | $count += $currentCount; | |
987 | } | |
988 | } | |
989 | } | |
990 | if (!$count) { | |
991 | $count = 1; | |
992 | } | |
993 | } | |
994 | $totalCount += $count; | |
995 | } | |
996 | if (!$totalCount) { | |
997 | $totalCount = 1; | |
998 | } | |
999 | ||
1000 | return $totalCount; | |
1001 | } | |
1002 | ||
3bdf1f3a | 1003 | /** |
1004 | * Format user submitted price set params. | |
1005 | * | |
6a488035 TO |
1006 | * Convert price set each param as an array. |
1007 | * | |
3bdf1f3a | 1008 | * @param CRM_Core_Form $form |
5a4f6742 | 1009 | * @param array $params |
d4dd1e85 | 1010 | * An array of user submitted params. |
6a488035 | 1011 | * |
a6c01b45 | 1012 | * @return array |
3bdf1f3a | 1013 | * Formatted price set params. |
0cf587a7 | 1014 | */ |
6a488035 TO |
1015 | public static function formatPriceSetParams(&$form, $params) { |
1016 | if (!is_array($params) || empty($params)) { | |
1017 | return $params; | |
1018 | } | |
1019 | ||
1020 | $priceSetId = $form->get('priceSetId'); | |
1021 | if (!$priceSetId) { | |
1022 | return $params; | |
1023 | } | |
1024 | $priceSetDetails = $form->get('priceSet'); | |
1025 | ||
1026 | foreach ($params as $key => & $value) { | |
1027 | $vals = array(); | |
1028 | if (strpos($key, 'price_') !== FALSE) { | |
1029 | $fieldId = substr($key, 6); | |
1030 | if (!array_key_exists($fieldId, $priceSetDetails['fields']) || | |
1031 | is_array($value) || | |
1032 | !$value | |
1033 | ) { | |
1034 | continue; | |
1035 | } | |
1036 | $field = $priceSetDetails['fields'][$fieldId]; | |
1037 | if ($field['html_type'] == 'Text') { | |
1038 | $fieldOption = current($field['options']); | |
1039 | $value = array($fieldOption['id'] => $value); | |
1040 | } | |
1041 | else { | |
1042 | $value = array($value => TRUE); | |
1043 | } | |
1044 | } | |
1045 | } | |
1046 | ||
1047 | return $params; | |
1048 | } | |
1049 | ||
3bdf1f3a | 1050 | /** |
1051 | * Calculate total count for each price set options. | |
6a488035 | 1052 | * |
3bdf1f3a | 1053 | * - currently selected by user. |
6a488035 | 1054 | * |
3bdf1f3a | 1055 | * @param CRM_Core_Form $form |
1056 | * Form object. | |
0cf587a7 EM |
1057 | * |
1058 | * @return array | |
3bdf1f3a | 1059 | * array of each option w/ count total. |
0cf587a7 | 1060 | */ |
169be3c1 | 1061 | public static function getPriceSetOptionCount(&$form) { |
353ffa53 TO |
1062 | $params = $form->get('params'); |
1063 | $priceSet = $form->get('priceSet'); | |
6a488035 TO |
1064 | $priceSetId = $form->get('priceSetId'); |
1065 | ||
1066 | $optionsCount = array(); | |
1067 | if (!$priceSetId || | |
1068 | !is_array($priceSet) || | |
1069 | empty($priceSet) || | |
1070 | !is_array($params) || | |
1071 | empty($params) | |
1072 | ) { | |
1073 | return $optionsCount; | |
1074 | } | |
1075 | ||
1076 | $priceSetFields = $priceMaxFieldDetails = array(); | |
a7488080 | 1077 | if (!empty($priceSet['optionsCountTotal'])) { |
6a488035 TO |
1078 | $priceSetFields = $priceSet['optionsCountDetails']['fields']; |
1079 | } | |
1080 | ||
a7488080 | 1081 | if (!empty($priceSet['optionsMaxValueTotal'])) { |
6a488035 TO |
1082 | $priceMaxFieldDetails = $priceSet['optionsMaxValueDetails']['fields']; |
1083 | } | |
1084 | ||
1085 | $addParticipantNum = substr($form->_name, 12); | |
1086 | foreach ($params as $pCnt => $values) { | |
1087 | if ($values == 'skip' || | |
79b152ac | 1088 | $pCnt === $addParticipantNum |
6a488035 TO |
1089 | ) { |
1090 | continue; | |
1091 | } | |
1092 | ||
1093 | foreach ($values as $valKey => $value) { | |
1094 | if (strpos($valKey, 'price_') === FALSE) { | |
1095 | continue; | |
1096 | } | |
1097 | ||
1098 | $priceFieldId = substr($valKey, 6); | |
1099 | if (!$priceFieldId || | |
1100 | !is_array($value) || | |
1101 | !(array_key_exists($priceFieldId, $priceSetFields) || array_key_exists($priceFieldId, $priceMaxFieldDetails)) | |
1102 | ) { | |
1103 | continue; | |
1104 | } | |
1105 | ||
1106 | foreach ($value as $optId => $optVal) { | |
1107 | if (CRM_Utils_Array::value('html_type', $priceSet['fields'][$priceFieldId]) == 'Text') { | |
1108 | $currentCount = $optVal; | |
1109 | } | |
1110 | else { | |
1111 | $currentCount = 1; | |
1112 | } | |
1113 | ||
1114 | if (isset($priceSetFields[$priceFieldId]) && isset($priceSetFields[$priceFieldId]['options'][$optId])) { | |
1115 | $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal; | |
1116 | } | |
1117 | ||
1118 | $optionsCount[$optId] = $currentCount + CRM_Utils_Array::value($optId, $optionsCount, 0); | |
1119 | } | |
1120 | } | |
1121 | } | |
1122 | ||
1123 | return $optionsCount; | |
1124 | } | |
1125 | ||
0cf587a7 | 1126 | /** |
3bdf1f3a | 1127 | * Check if template file exists. |
1128 | * | |
0cf587a7 EM |
1129 | * @param string $suffix |
1130 | * | |
1131 | * @return null|string | |
1132 | */ | |
00be9182 | 1133 | public function checkTemplateFileExists($suffix = '') { |
6a488035 TO |
1134 | if ($this->_eventId) { |
1135 | $templateName = $this->_name; | |
1136 | if (substr($templateName, 0, 12) == 'Participant_') { | |
1137 | $templateName = 'AdditionalParticipant'; | |
1138 | } | |
1139 | ||
1140 | $templateFile = "CRM/Event/Form/Registration/{$this->_eventId}/{$templateName}.{$suffix}tpl"; | |
1141 | $template = CRM_Core_Form::getTemplate(); | |
1142 | if ($template->template_exists($templateFile)) { | |
1143 | return $templateFile; | |
1144 | } | |
1145 | } | |
1146 | return NULL; | |
1147 | } | |
1148 | ||
0cf587a7 | 1149 | /** |
3bdf1f3a | 1150 | * Get template file name. |
1151 | * | |
0cf587a7 EM |
1152 | * @return null|string |
1153 | */ | |
00be9182 | 1154 | public function getTemplateFileName() { |
6a488035 TO |
1155 | $fileName = $this->checkTemplateFileExists(); |
1156 | return $fileName ? $fileName : parent::getTemplateFileName(); | |
1157 | } | |
1158 | ||
0cf587a7 | 1159 | /** |
3bdf1f3a | 1160 | * Override extra template name. |
1161 | * | |
0cf587a7 EM |
1162 | * @return null|string |
1163 | */ | |
00be9182 | 1164 | public function overrideExtraTemplateFileName() { |
6a488035 TO |
1165 | $fileName = $this->checkTemplateFileExists('extra.'); |
1166 | return $fileName ? $fileName : parent::overrideExtraTemplateFileName(); | |
1167 | } | |
1168 | ||
0dc0b759 | 1169 | /** |
1170 | * Reset values for all options those are full. | |
1171 | * | |
780422d7 | 1172 | * @param array $optionFullIds |
3bdf1f3a | 1173 | * @param CRM_Core_Form $form |
0dc0b759 | 1174 | */ |
1175 | public static function resetElementValue($optionFullIds = array(), &$form) { | |
1176 | if (!is_array($optionFullIds) || | |
1177 | empty($optionFullIds) || | |
1178 | !$form->isSubmitted() | |
1179 | ) { | |
1180 | return; | |
1181 | } | |
1182 | ||
1183 | foreach ($optionFullIds as $fldId => $optIds) { | |
1184 | $name = "price_$fldId"; | |
1185 | if (!$form->elementExists($name)) { | |
1186 | continue; | |
1187 | } | |
1188 | ||
1189 | $element = $form->getElement($name); | |
1190 | $eleType = $element->getType(); | |
1191 | ||
1192 | $resetSubmitted = FALSE; | |
1193 | switch ($eleType) { | |
1194 | case 'text': | |
1195 | if ($element->getValue() && $element->isFrozen()) { | |
1196 | $label = "{$element->getLabel()}<tt>(x)</tt>"; | |
1197 | $element->setLabel($label); | |
1198 | $element->setPersistantFreeze(); | |
1199 | $resetSubmitted = TRUE; | |
1200 | } | |
1201 | break; | |
1202 | ||
1203 | case 'group': | |
1204 | if (is_array($element->_elements)) { | |
1205 | foreach ($element->_elements as $child) { | |
1206 | $childType = $child->getType(); | |
1207 | $methodName = 'getName'; | |
1208 | if ($childType) { | |
1209 | $methodName = 'getValue'; | |
1210 | } | |
1211 | if (in_array($child->{$methodName}(), $optIds) && $child->isFrozen()) { | |
1212 | $resetSubmitted = TRUE; | |
1213 | $child->setPersistantFreeze(); | |
1214 | } | |
1215 | } | |
1216 | } | |
1217 | break; | |
1218 | ||
1219 | case 'select': | |
9d8d8fd0 | 1220 | $value = $element->getValue(); |
1221 | if (in_array($value[0], $optIds)) { | |
0dc0b759 | 1222 | foreach ($element->_options as $option) { |
d0ebccea | 1223 | if ($option['attr']['value'] === "crm_disabled_opt-{$value[0]}") { |
2ae4d103 | 1224 | $placeholder = html_entity_decode($option['text'], ENT_QUOTES, "UTF-8"); |
0dc0b759 | 1225 | $element->updateAttributes(array('placeholder' => $placeholder)); |
1226 | break; | |
1227 | } | |
1228 | } | |
1229 | $resetSubmitted = TRUE; | |
1230 | } | |
1231 | break; | |
1232 | } | |
1233 | ||
1234 | //finally unset values from submitted. | |
1235 | if ($resetSubmitted) { | |
1236 | self::resetSubmittedValue($name, $optIds, $form); | |
1237 | } | |
1238 | } | |
1239 | } | |
1240 | ||
1241 | /** | |
3bdf1f3a | 1242 | * Reset submitted value. |
1243 | * | |
0dc0b759 | 1244 | * @param string $elementName |
1245 | * @param array $optionIds | |
780422d7 | 1246 | * @param CRM_Core_form $form |
0dc0b759 | 1247 | */ |
1248 | public static function resetSubmittedValue($elementName, $optionIds = array(), &$form) { | |
1249 | if (empty($elementName) || | |
1250 | !$form->elementExists($elementName) || | |
1251 | !$form->getSubmitValue($elementName) | |
1252 | ) { | |
1253 | return; | |
1254 | } | |
1255 | foreach (array( | |
1256 | 'constantValues', | |
1257 | 'submitValues', | |
1258 | 'defaultValues', | |
1259 | ) as $val) { | |
1260 | $values = $form->{"_$val"}; | |
1261 | if (!is_array($values) || empty($values)) { | |
1262 | continue; | |
1263 | } | |
1264 | $eleVal = CRM_Utils_Array::value($elementName, $values); | |
1265 | if (empty($eleVal)) { | |
1266 | continue; | |
1267 | } | |
1268 | if (is_array($eleVal)) { | |
1269 | $found = FALSE; | |
1270 | foreach ($eleVal as $keyId => $ignore) { | |
1271 | if (in_array($keyId, $optionIds)) { | |
1272 | $found = TRUE; | |
1273 | unset($values[$elementName][$keyId]); | |
1274 | } | |
1275 | } | |
1276 | if ($found && empty($values[$elementName][$keyId])) { | |
1277 | $values[$elementName][$keyId] = NULL; | |
1278 | } | |
1279 | } | |
1280 | else { | |
1281 | if (!empty($keyId)) { | |
1282 | $values[$elementName][$keyId] = NULL; | |
1283 | } | |
1284 | } | |
1285 | } | |
1286 | } | |
1287 | ||
da8d9879 | 1288 | /** |
3bdf1f3a | 1289 | * Validate price set submitted params for price option limit. |
1290 | * | |
1291 | * User should select at least one price field option. | |
72b3a70c CW |
1292 | * |
1293 | * @param CRM_Core_Form $form | |
1294 | * @param array $params | |
1295 | * | |
1296 | * @return array | |
6a488035 | 1297 | */ |
00be9182 | 1298 | public static function validatePriceSet(&$form, $params) { |
6a488035 TO |
1299 | $errors = array(); |
1300 | $hasOptMaxValue = FALSE; | |
1301 | if (!is_array($params) || empty($params)) { | |
1302 | return $errors; | |
1303 | } | |
1304 | ||
1305 | $currentParticipantNum = substr($form->_name, 12); | |
1306 | if (!$currentParticipantNum) { | |
1307 | $currentParticipantNum = 0; | |
1308 | } | |
1309 | ||
1310 | $priceSetId = $form->get('priceSetId'); | |
1311 | $priceSetDetails = $form->get('priceSet'); | |
1312 | if ( | |
1313 | !$priceSetId || | |
1314 | !is_array($priceSetDetails) || | |
1315 | empty($priceSetDetails) | |
1316 | ) { | |
1317 | return $errors; | |
1318 | } | |
1319 | ||
1320 | $optionsCountDetails = $optionsMaxValueDetails = array(); | |
1321 | if ( | |
1322 | isset($priceSetDetails['optionsMaxValueTotal']) | |
1323 | && $priceSetDetails['optionsMaxValueTotal'] | |
1324 | ) { | |
1325 | $hasOptMaxValue = TRUE; | |
1326 | $optionsMaxValueDetails = $priceSetDetails['optionsMaxValueDetails']['fields']; | |
1327 | } | |
1328 | if ( | |
1329 | isset($priceSetDetails['optionsCountTotal']) | |
1330 | && $priceSetDetails['optionsCountTotal'] | |
1331 | ) { | |
1332 | $hasOptCount = TRUE; | |
1333 | $optionsCountDetails = $priceSetDetails['optionsCountDetails']['fields']; | |
1334 | } | |
1335 | $feeBlock = $form->_feeBlock; | |
1336 | ||
1337 | if (empty($feeBlock)) { | |
1338 | $feeBlock = $priceSetDetails['fields']; | |
1339 | } | |
1340 | ||
1341 | $optionMaxValues = $fieldSelected = array(); | |
1342 | foreach ($params as $pNum => $values) { | |
1343 | if (!is_array($values) || $values == 'skip') { | |
1344 | continue; | |
1345 | } | |
1346 | ||
1347 | foreach ($values as $valKey => $value) { | |
1348 | if (strpos($valKey, 'price_') === FALSE) { | |
1349 | continue; | |
1350 | } | |
1351 | $priceFieldId = substr($valKey, 6); | |
1352 | $noneOptionValueSelected = FALSE; | |
1353 | if (!$feeBlock[$priceFieldId]['is_required'] && $value == 0) { | |
1354 | $noneOptionValueSelected = TRUE; | |
1355 | } | |
1356 | ||
1357 | if ( | |
1358 | !$priceFieldId || | |
1359 | (!$noneOptionValueSelected && !is_array($value)) | |
1360 | ) { | |
1361 | continue; | |
1362 | } | |
1363 | ||
1364 | $fieldSelected[$pNum] = TRUE; | |
1365 | ||
1366 | if (!$hasOptMaxValue || !is_array($value)) { | |
1367 | continue; | |
1368 | } | |
1369 | ||
1370 | foreach ($value as $optId => $optVal) { | |
1371 | if (CRM_Utils_Array::value('html_type', $feeBlock[$priceFieldId]) == 'Text') { | |
1372 | $currentMaxValue = $optVal; | |
1373 | } | |
1374 | else { | |
1375 | $currentMaxValue = 1; | |
1376 | } | |
1377 | ||
1378 | if (isset($optionsCountDetails[$priceFieldId]) && isset($optionsCountDetails[$priceFieldId]['options'][$optId])) { | |
1379 | $currentMaxValue = $optionsCountDetails[$priceFieldId]['options'][$optId] * $optVal; | |
1380 | } | |
1381 | if (empty($optionMaxValues)) { | |
1382 | $optionMaxValues[$priceFieldId][$optId] = $currentMaxValue; | |
1383 | } | |
1384 | else { | |
7c550ca0 WA |
1385 | $optionMaxValues[$priceFieldId][$optId] |
1386 | = $currentMaxValue + CRM_Utils_Array::value($optId, CRM_Utils_Array::value($priceFieldId, $optionMaxValues), 0); | |
6a488035 | 1387 | } |
0dc0b759 | 1388 | $soldOutPnum[$optId] = $pNum; |
6a488035 TO |
1389 | } |
1390 | } | |
0dc0b759 | 1391 | |
1392 | //validate for price field selection. | |
1393 | if (empty($fieldSelected[$pNum])) { | |
1394 | $errors[$pNum]['_qf_default'] = ts('Select at least one option from Event Fee(s).'); | |
1395 | } | |
6a488035 TO |
1396 | } |
1397 | ||
1398 | //validate for option max value. | |
1399 | foreach ($optionMaxValues as $fieldId => $values) { | |
1400 | $options = CRM_Utils_Array::value('options', $feeBlock[$fieldId], array()); | |
1401 | foreach ($values as $optId => $total) { | |
1402 | $optMax = $optionsMaxValueDetails[$fieldId]['options'][$optId]; | |
1403 | $opDbCount = CRM_Utils_Array::value('db_total_count', $options[$optId], 0); | |
1404 | $total += $opDbCount; | |
0dc0b759 | 1405 | if ($optMax && ($total > $optMax)) { |
6a488035 | 1406 | if ($opDbCount && ($opDbCount >= $optMax)) { |
0dc0b759 | 1407 | $errors[$soldOutPnum[$optId]]["price_{$fieldId}"] |
7c550ca0 | 1408 | = ts('Sorry, this option is currently sold out.'); |
6a488035 TO |
1409 | } |
1410 | elseif (($optMax - $opDbCount) == 1) { | |
0dc0b759 | 1411 | $errors[$soldOutPnum[$optId]]["price_{$fieldId}"] |
a3fdddaa | 1412 | = ts('Sorry, currently only a single space is available for this option.', array(1 => ($optMax - $opDbCount))); |
6a488035 TO |
1413 | } |
1414 | else { | |
0dc0b759 | 1415 | $errors[$soldOutPnum[$optId]]["price_{$fieldId}"] |
a3fdddaa | 1416 | = ts('Sorry, currently only %1 spaces are available for this option.', array(1 => ($optMax - $opDbCount))); |
6a488035 TO |
1417 | } |
1418 | } | |
1419 | } | |
1420 | } | |
6a488035 TO |
1421 | return $errors; |
1422 | } | |
1423 | ||
0cf587a7 | 1424 | /** |
3bdf1f3a | 1425 | * Set the first participant ID if not set. |
1426 | * | |
1427 | * CRM-10032. | |
72b3a70c | 1428 | * |
100fef9d | 1429 | * @param int $participantID |
0cf587a7 | 1430 | */ |
00be9182 | 1431 | public function processFirstParticipant($participantID) { |
6a488035 TO |
1432 | $this->_participantId = $participantID; |
1433 | $this->set('participantId', $this->_participantId); | |
1434 | ||
1435 | $ids = $participantValues = array(); | |
1436 | $participantParams = array('id' => $this->_participantId); | |
1437 | CRM_Event_BAO_Participant::getValues($participantParams, $participantValues, $ids); | |
1438 | $this->_values['participant'] = $participantValues[$this->_participantId]; | |
1439 | $this->set('values', $this->_values); | |
1440 | ||
1441 | // also set the allow confirmation stuff | |
1442 | if (array_key_exists( | |
353ffa53 TO |
1443 | $this->_values['participant']['status_id'], |
1444 | CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'") | |
1445 | )) { | |
6a488035 TO |
1446 | $this->_allowConfirmation = TRUE; |
1447 | $this->set('allowConfirmation', TRUE); | |
1448 | } | |
1449 | } | |
1450 | ||
e2d09ab4 | 1451 | /** |
3bdf1f3a | 1452 | * Check if event is valid. |
1453 | * | |
e2d09ab4 EM |
1454 | * @todo - combine this with CRM_Event_BAO_Event::validRegistrationRequest |
1455 | * (probably extract relevant values here & call that with them & handle bounces & redirects here -as | |
1456 | * those belong in the form layer) | |
1457 | * | |
1458 | * @param string $redirect | |
1459 | */ | |
00be9182 | 1460 | public function checkValidEvent($redirect = NULL) { |
6a488035 TO |
1461 | // is the event active (enabled)? |
1462 | if (!$this->_values['event']['is_active']) { | |
1463 | // form is inactive, die a fatal death | |
1464 | CRM_Core_Error::statusBounce(ts('The event you requested is currently unavailable (contact the site administrator for assistance).')); | |
1465 | } | |
1466 | ||
1467 | // is online registration is enabled? | |
1468 | if (!$this->_values['event']['is_online_registration']) { | |
1469 | CRM_Core_Error::statusBounce(ts('Online registration is not currently available for this event (contact the site administrator for assistance).'), $redirect); | |
1470 | } | |
1471 | ||
1472 | // is this an event template ? | |
a7488080 | 1473 | if (!empty($this->_values['event']['is_template'])) { |
6a488035 TO |
1474 | CRM_Core_Error::statusBounce(ts('Event templates are not meant to be registered.'), $redirect); |
1475 | } | |
1476 | ||
1477 | $now = date('YmdHis'); | |
1478 | $startDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('registration_start_date', | |
353ffa53 TO |
1479 | $this->_values['event'] |
1480 | )); | |
6a488035 TO |
1481 | |
1482 | if ( | |
1483 | $startDate && | |
1484 | $startDate >= $now | |
1485 | ) { | |
1486 | CRM_Core_Error::statusBounce(ts('Registration for this event begins on %1', array(1 => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('registration_start_date', $this->_values['event'])))), $redirect); | |
1487 | } | |
1488 | ||
ce5694b5 | 1489 | $regEndDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('registration_end_date', |
353ffa53 TO |
1490 | $this->_values['event'] |
1491 | )); | |
4bd9b7a9 | 1492 | $eventEndDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('event_end_date', $this->_values['event'])); |
b612d89b | 1493 | if (($regEndDate && ($regEndDate < $now)) || (empty($regEndDate) && !empty($eventEndDate) && ($eventEndDate < $now))) { |
ce5694b5 | 1494 | $endDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('registration_end_date', $this->_values['event'])); |
1495 | if (empty($regEndDate)) { | |
1496 | $endDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('event_end_date', $this->_values['event'])); | |
1497 | } | |
1498 | CRM_Core_Error::statusBounce(ts('Registration for this event ended on %1', array(1 => $endDate)), $redirect); | |
6a488035 TO |
1499 | } |
1500 | } | |
96025800 | 1501 | |
c039f658 | 1502 | /** |
1503 | * Get the amount level for the event payment. | |
1504 | * | |
1505 | * The amount level is the string stored on the contribution record that describes the purchase. | |
1506 | * | |
1507 | * @param array $params | |
1508 | * @param int|null $discountID | |
1509 | * | |
1510 | * @return string | |
1511 | */ | |
1512 | protected function getAmountLevel($params, $discountID) { | |
1513 | // @todo move handling of discount ID to the BAO function - preferably by converting it to a price_set with | |
1514 | // time settings. | |
1515 | if (!empty($this->_values['discount'][$discountID])) { | |
1516 | return $this->_values['discount'][$discountID][$params['amount']]['label']; | |
1517 | } | |
e173279c | 1518 | if (empty($params['priceSetId'])) { |
1519 | // CRM-17509 An example of this is where the person is being waitlisted & there is no payment. | |
1520 | // ideally we would have calculated amount first & only call this is there is an | |
1521 | // amount but the flow needs more changes for that. | |
1522 | return ''; | |
1523 | } | |
c039f658 | 1524 | return CRM_Price_BAO_PriceSet::getAmountLevelText($params); |
1525 | } | |
1526 | ||
3033e657 | 1527 | /** |
1528 | * Process Registration of free event. | |
1529 | * | |
1530 | * @param array $params | |
1531 | * Form values. | |
1532 | * @param int $contactID | |
1533 | */ | |
1534 | public function processRegistration($params, $contactID = NULL) { | |
1535 | $session = CRM_Core_Session::singleton(); | |
1536 | $this->_participantInfo = array(); | |
1537 | ||
1538 | // CRM-4320, lets build array of cancelled additional participant ids | |
1539 | // those are drop or skip by primary at the time of confirmation. | |
1540 | // get all in and then unset those are confirmed. | |
1541 | $cancelledIds = $this->_additionalParticipantIds; | |
1542 | ||
1543 | $participantCount = array(); | |
1544 | foreach ($params as $participantNum => $record) { | |
1545 | if ($record == 'skip') { | |
1546 | $participantCount[$participantNum] = 'skip'; | |
1547 | } | |
1548 | elseif ($participantNum) { | |
1549 | $participantCount[$participantNum] = 'participant'; | |
1550 | } | |
1551 | } | |
1552 | ||
1553 | $registerByID = NULL; | |
1554 | foreach ($params as $key => $value) { | |
1555 | if ($value != 'skip') { | |
1556 | $fields = NULL; | |
1557 | ||
1558 | // setting register by Id and unset contactId. | |
1559 | if (empty($value['is_primary'])) { | |
1560 | $contactID = NULL; | |
1561 | $registerByID = $this->get('registerByID'); | |
1562 | if ($registerByID) { | |
1563 | $value['registered_by_id'] = $registerByID; | |
1564 | } | |
1565 | // get an email if one exists for the participant | |
1566 | $participantEmail = ''; | |
1567 | foreach (array_keys($value) as $valueName) { | |
1568 | if (substr($valueName, 0, 6) == 'email-') { | |
1569 | $participantEmail = $value[$valueName]; | |
1570 | } | |
1571 | } | |
1572 | if ($participantEmail) { | |
1573 | $this->_participantInfo[] = $participantEmail; | |
1574 | } | |
1575 | else { | |
1576 | $this->_participantInfo[] = $value['first_name'] . ' ' . $value['last_name']; | |
1577 | } | |
1578 | } | |
1579 | elseif (!empty($value['contact_id'])) { | |
1580 | $contactID = $value['contact_id']; | |
1581 | } | |
1582 | else { | |
1583 | $contactID = $this->getContactID(); | |
1584 | } | |
1585 | ||
1586 | CRM_Event_Form_Registration_Confirm::fixLocationFields($value, $fields, $this); | |
1587 | //for free event or additional participant, dont create billing email address. | |
1588 | if (empty($value['is_primary']) || !$this->_values['event']['is_monetary']) { | |
1589 | unset($value["email-{$this->_bltID}"]); | |
1590 | } | |
1591 | ||
1592 | $contactID = CRM_Event_Form_Registration_Confirm::updateContactFields($contactID, $value, $fields, $this); | |
1593 | ||
1594 | // lets store the contactID in the session | |
1595 | // we dont store in userID in case the user is doing multiple | |
1596 | // transactions etc | |
1597 | // for things like tell a friend | |
1598 | if (!$this->getContactID() && !empty($value['is_primary'])) { | |
1599 | $session->set('transaction.userID', $contactID); | |
1600 | } | |
1601 | ||
1602 | //lets get the status if require approval or waiting. | |
1603 | ||
1604 | $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'"); | |
1605 | if ($this->_allowWaitlist && !$this->_allowConfirmation) { | |
1606 | $value['participant_status_id'] = $value['participant_status'] = array_search('On waitlist', $waitingStatuses); | |
1607 | } | |
1608 | elseif ($this->_requireApproval && !$this->_allowConfirmation) { | |
1609 | $value['participant_status_id'] = $value['participant_status'] = array_search('Awaiting approval', $waitingStatuses); | |
1610 | } | |
1611 | ||
1612 | $this->set('value', $value); | |
1613 | $this->confirmPostProcess($contactID, NULL, NULL); | |
1614 | ||
1615 | //lets get additional participant id to cancel. | |
1616 | if ($this->_allowConfirmation && is_array($cancelledIds)) { | |
1617 | $additonalId = CRM_Utils_Array::value('participant_id', $value); | |
1618 | if ($additonalId && $key = array_search($additonalId, $cancelledIds)) { | |
1619 | unset($cancelledIds[$key]); | |
1620 | } | |
1621 | } | |
1622 | } | |
1623 | } | |
1624 | ||
1625 | // update status and send mail to cancelled additional participants, CRM-4320 | |
1626 | if ($this->_allowConfirmation && is_array($cancelledIds) && !empty($cancelledIds)) { | |
1627 | $cancelledId = array_search('Cancelled', | |
1628 | CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'") | |
1629 | ); | |
1630 | CRM_Event_BAO_Participant::transitionParticipants($cancelledIds, $cancelledId); | |
1631 | } | |
1632 | ||
1633 | //set information about additional participants if exists | |
1634 | if (count($this->_participantInfo)) { | |
1635 | $this->set('participantInfo', $this->_participantInfo); | |
1636 | } | |
1637 | ||
1638 | //send mail Confirmation/Receipt | |
1639 | if ($this->_contributeMode != 'checkout' || | |
1640 | $this->_contributeMode != 'notify' | |
1641 | ) { | |
1642 | $isTest = FALSE; | |
1643 | if ($this->_action & CRM_Core_Action::PREVIEW) { | |
1644 | $isTest = TRUE; | |
1645 | } | |
1646 | ||
1647 | //handle if no additional participant. | |
1648 | if (!$registerByID) { | |
1649 | $registerByID = $this->get('registerByID'); | |
1650 | } | |
1651 | $primaryContactId = $this->get('primaryContactId'); | |
1652 | ||
1653 | //build an array of custom profile and assigning it to template. | |
1654 | $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID, NULL, | |
1655 | $primaryContactId, $isTest, TRUE | |
1656 | ); | |
1657 | ||
1658 | //lets carry all participant params w/ values. | |
1659 | foreach ($additionalIDs as $participantID => $contactId) { | |
1660 | $participantNum = NULL; | |
1661 | if ($participantID == $registerByID) { | |
1662 | $participantNum = 0; | |
1663 | } | |
1664 | else { | |
1665 | if ($participantNum = array_search('participant', $participantCount)) { | |
1666 | unset($participantCount[$participantNum]); | |
1667 | } | |
1668 | } | |
1669 | ||
1670 | if ($participantNum === NULL) { | |
1671 | break; | |
1672 | } | |
1673 | ||
1674 | //carry the participant submitted values. | |
1675 | $this->_values['params'][$participantID] = $params[$participantNum]; | |
1676 | } | |
1677 | ||
1678 | //lets send mails to all with meanigful text, CRM-4320. | |
1679 | $this->assign('isOnWaitlist', $this->_allowWaitlist); | |
1680 | $this->assign('isRequireApproval', $this->_requireApproval); | |
1681 | ||
1682 | foreach ($additionalIDs as $participantID => $contactId) { | |
1683 | if ($participantID == $registerByID) { | |
1684 | //set as Primary Participant | |
1685 | $this->assign('isPrimary', 1); | |
1686 | ||
1687 | $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participantID, $this->_values, NULL, $isTest); | |
1688 | ||
1689 | if (count($customProfile)) { | |
1690 | $this->assign('customProfile', $customProfile); | |
1691 | $this->set('customProfile', $customProfile); | |
1692 | } | |
1693 | } | |
1694 | else { | |
1695 | $this->assign('isPrimary', 0); | |
1696 | $this->assign('customProfile', NULL); | |
1697 | } | |
1698 | ||
1699 | //send Confirmation mail to Primary & additional Participants if exists | |
1700 | CRM_Event_BAO_Event::sendMail($contactId, $this->_values, $participantID, $isTest); | |
1701 | } | |
1702 | } | |
1703 | } | |
1704 | ||
6a488035 | 1705 | } |