Merge pull request #6199 from eileenmcnaughton/CRM-16808
[civicrm-core.git] / CRM / Event / Form / Registration / Confirm.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 *
31 * @package CRM
32 * @copyright CiviCRM LLC (c) 2004-2015
33 * $Id$
34 *
35 */
36
37 /**
38 * This class generates form components for processing Event
39 *
40 */
41 class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
42
43 /**
44 * The values for the contribution db object.
45 *
46 * @var array
47 */
48 public $_values;
49
50 /**
51 * The total amount.
52 *
53 * @var float
54 */
55 public $_totalAmount;
56
57 /**
58 * Set variables up before form is built.
59 *
60 * @return void
61 */
62 public function preProcess() {
63 parent::preProcess();
64
65 // lineItem isn't set until Register postProcess
66 $this->_lineItem = $this->get('lineItem');
67
68 $this->_params = $this->get('params');
69 $this->_params[0]['tax_amount'] = $this->get('tax_amount');
70
71 $this->_params[0]['is_pay_later'] = $this->get('is_pay_later');
72 $this->assign('is_pay_later', $this->_params[0]['is_pay_later']);
73 if ($this->_params[0]['is_pay_later']) {
74 $this->assign('pay_later_receipt', $this->_values['event']['pay_later_receipt']);
75 }
76
77 CRM_Utils_Hook::eventDiscount($this, $this->_params);
78
79 if (!empty($this->_params[0]['discount']) && !empty($this->_params[0]['discount']['applied'])) {
80 $this->set('hookDiscount', $this->_params[0]['discount']);
81 $this->assign('hookDiscount', $this->_params[0]['discount']);
82 }
83
84 if ($this->_contributeMode == 'express') {
85 $params = array();
86 // rfp == redirect from paypal
87 $rfp = CRM_Utils_Request::retrieve('rfp', 'Boolean',
88 CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET'
89 );
90
91 //we lost rfp in case of additional participant. So set it explicitly.
92 if ($rfp || CRM_Utils_Array::value('additional_participants', $this->_params[0], FALSE)) {
93 $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
94 $paymentObjError = ts('The system did not record payment details for this payment and so could not process the transaction. Please report this error to the site administrator.');
95 if (is_object($payment)) {
96 $expressParams = $payment->getExpressCheckoutDetails($this->get('token'));
97 }
98 else {
99 CRM_Core_Error::fatal($paymentObjError);
100 }
101
102 $params['payer'] = CRM_Utils_Array::value('payer', $expressParams);
103 $params['payer_id'] = $expressParams['payer_id'];
104 $params['payer_status'] = $expressParams['payer_status'];
105
106 CRM_Core_Payment_Form::mapParams($this->_bltID, $expressParams, $params, FALSE);
107
108 // fix state and country id if present
109 if (isset($params["billing_state_province_id-{$this->_bltID}"])) {
110 $params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($params["billing_state_province_id-{$this->_bltID}"]);
111 }
112 if (isset($params['billing_country_id'])) {
113 $params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($params["billing_country_id-{$this->_bltID}"]);
114 }
115
116 // set a few other parameters for PayPal
117 $params['token'] = $this->get('token');
118 $params['amount'] = $this->_params[0]['amount'];
119 if (!empty($this->_params[0]['discount'])) {
120 $params['discount'] = $this->_params[0]['discount'];
121 $params['discountAmount'] = $this->_params[0]['discountAmount'];
122 $params['discountMessage'] = $this->_params[0]['discountMessage'];
123 }
124 if (!empty($this->_params[0]['amount_priceset_level_radio'])) {
125 $params['amount_priceset_level_radio'] = $this->_params[0]['amount_priceset_level_radio'];
126 }
127 $params['amount_level'] = $this->_params[0]['amount_level'];
128 $params['currencyID'] = $this->_params[0]['currencyID'];
129
130 // also merge all the other values from the profile fields
131 $values = $this->controller->exportValues('Register');
132 $skipFields = array(
133 'amount',
134 "street_address-{$this->_bltID}",
135 "city-{$this->_bltID}",
136 "state_province_id-{$this->_bltID}",
137 "postal_code-{$this->_bltID}",
138 "country_id-{$this->_bltID}",
139 );
140
141 foreach ($values as $name => $value) {
142 // skip amount field
143 if (!in_array($name, $skipFields)) {
144 $params[$name] = $value;
145 }
146 }
147 $this->set('getExpressCheckoutDetails', $params);
148 }
149 else {
150 $params = $this->get('getExpressCheckoutDetails');
151 }
152 $this->_params[0] = $params;
153 $this->_params[0]['is_primary'] = 1;
154 }
155 else {
156 //process only primary participant params.
157 $registerParams = $this->_params[0];
158 if (isset($registerParams["billing_state_province_id-{$this->_bltID}"])
159 && $registerParams["billing_state_province_id-{$this->_bltID}"]
160 ) {
161 $registerParams["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($registerParams["billing_state_province_id-{$this->_bltID}"]);
162 }
163
164 if (isset($registerParams["billing_country_id-{$this->_bltID}"]) && $registerParams["billing_country_id-{$this->_bltID}"]) {
165 $registerParams["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($registerParams["billing_country_id-{$this->_bltID}"]);
166 }
167 if (isset($registerParams['credit_card_exp_date'])) {
168 $registerParams['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($registerParams);
169 $registerParams['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($registerParams);
170 }
171 if ($this->_values['event']['is_monetary']) {
172 $registerParams['ip_address'] = CRM_Utils_System::ipAddress();
173 $registerParams['currencyID'] = $this->_params[0]['currencyID'];
174 }
175 //assign back primary participant params.
176 $this->_params[0] = $registerParams;
177 }
178
179 if ($this->_values['event']['is_monetary']) {
180 $this->_params[0]['invoiceID'] = $this->get('invoiceID');
181 }
182 $this->assign('defaultRole', FALSE);
183 if (CRM_Utils_Array::value('defaultRole', $this->_params[0]) == 1) {
184 $this->assign('defaultRole', TRUE);
185 }
186
187 if (empty($this->_params[0]['participant_role_id']) &&
188 $this->_values['event']['default_role_id']
189 ) {
190 $this->_params[0]['participant_role_id'] = $this->_values['event']['default_role_id'];
191 }
192
193 if (isset($this->_values['event']['confirm_title'])) {
194 CRM_Utils_System::setTitle($this->_values['event']['confirm_title']);
195 }
196
197 if ($this->_pcpId) {
198 $params = CRM_Contribute_Form_Contribution_Confirm::processPcp($this, $this->_params[0]);
199 $this->_params[0] = $params;
200 }
201
202 $this->set('params', $this->_params);
203 }
204
205 /**
206 * Overwrite action, since we are only showing elements in frozen mode
207 * no help display needed
208 *
209 * @return int
210 */
211 public function getAction() {
212 if ($this->_action & CRM_Core_Action::PREVIEW) {
213 return CRM_Core_Action::VIEW | CRM_Core_Action::PREVIEW;
214 }
215 else {
216 return CRM_Core_Action::VIEW;
217 }
218 }
219
220 /**
221 * Build the form object.
222 *
223 * @return void
224 */
225 public function buildQuickForm() {
226 $this->assignToTemplate();
227
228 if ($this->_values['event']['is_monetary'] &&
229 ($this->_params[0]['amount'] || $this->_params[0]['amount'] == 0)
230 ) {
231 $this->_amount = array();
232
233 $taxAmount = 0;
234 foreach ($this->_params as $k => $v) {
235 $individualTaxAmount = 0;
236 //display tax amount on confirmation page
237 $taxAmount += $v['tax_amount'];
238 if (is_array($v)) {
239 foreach (array(
240 'first_name',
241 'last_name',
242 ) as $name) {
243 if (isset($v['billing_' . $name]) &&
244 !isset($v[$name])
245 ) {
246 $v[$name] = $v['billing_' . $name];
247 }
248 }
249
250 if (!empty($v['first_name']) && !empty($v['last_name'])) {
251 $append = $v['first_name'] . ' ' . $v['last_name'];
252 }
253 else {
254 //use an email if we have one
255 foreach ($v as $v_key => $v_val) {
256 if (substr($v_key, 0, 6) == 'email-') {
257 $append = $v[$v_key];
258 }
259 }
260 }
261
262 $this->_amount[$k]['amount'] = $v['amount'];
263 if (!empty($v['discountAmount'])) {
264 $this->_amount[$k]['amount'] -= $v['discountAmount'];
265 }
266
267 $this->_amount[$k]['label'] = preg_replace('/\ 1/', '', $v['amount_level']) . ' - ' . $append;
268 $this->_part[$k]['info'] = CRM_Utils_Array::value('first_name', $v) . ' ' . CRM_Utils_Array::value('last_name', $v);
269 if (empty($v['first_name'])) {
270 $this->_part[$k]['info'] = $append;
271 }
272
273 /*CRM-16320 */
274 $individual[$k]['totalAmtWithTax'] = $this->_amount[$k]['amount'];
275 $individual[$k]['totalTaxAmt'] = $individualTaxAmount + $v['tax_amount'];
276 $this->_totalAmount = $this->_totalAmount + $this->_amount[$k]['amount'];
277 if (!empty($v['is_primary'])) {
278 $this->set('primaryParticipantAmount', $this->_amount[$k]['amount']);
279 }
280 }
281 }
282
283 $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
284 $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
285 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
286 if ($invoicing) {
287 $this->assign('totalTaxAmount', $taxAmount);
288 $this->assign('taxTerm', $taxTerm);
289 $this->assign('individual', $individual);
290 $this->set('individual', $individual);
291 }
292
293 $this->assign('part', $this->_part);
294 $this->set('part', $this->_part);
295 $this->assign('amounts', $this->_amount);
296 $this->assign('totalAmount', $this->_totalAmount);
297 $this->set('totalAmount', $this->_totalAmount);
298 }
299
300 if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
301 $lineItemForTemplate = array();
302 $getTaxDetails = FALSE;
303 if (!empty($this->_lineItem) && is_array($this->_lineItem)) {
304 foreach ($this->_lineItem as $key => $value) {
305 if (!empty($value)) {
306 $lineItemForTemplate[$key] = $value;
307 }
308 if ($invoicing) {
309 foreach ($value as $v) {
310 if (isset($v['tax_rate'])) {
311 $getTaxDetails = TRUE;
312 }
313 }
314 }
315 }
316 }
317 if (!empty($lineItemForTemplate)) {
318 $this->assign('lineItem', $lineItemForTemplate);
319 }
320 $this->assign('getTaxDetails', $getTaxDetails);
321 }
322
323 //display additional participants profile.
324 self::assignProfiles($this);
325
326 //consider total amount.
327 $this->assign('isAmountzero', ($this->_totalAmount <= 0) ? TRUE : FALSE);
328
329 if ($this->_paymentProcessor['payment_processor_type'] == 'Google_Checkout' && empty($this->_params[0]['is_pay_later']) && !($this->_params[0]['amount'] == 0) &&
330 !$this->_allowWaitlist && !$this->_requireApproval
331 ) {
332 $this->_checkoutButtonName = $this->getButtonName('next', 'checkout');
333 $this->add('image',
334 $this->_checkoutButtonName,
335 $this->_paymentProcessor['url_button'],
336 array('class' => 'crm-form-submit')
337 );
338
339 $this->addButtons(array(
340 array(
341 'type' => 'back',
342 'name' => ts('Go Back'),
343 ),
344 )
345 );
346 }
347 else {
348 $contribButton = ts('Continue');
349 $this->addButtons(array(
350 array(
351 'type' => 'back',
352 'name' => ts('Go Back'),
353 ),
354 array(
355 'type' => 'next',
356 'name' => $contribButton,
357 'isDefault' => TRUE,
358 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"),
359 ),
360 )
361 );
362 }
363
364 $defaults = array();
365 $fields = array();
366 if (!empty($this->_fields)) {
367 foreach ($this->_fields as $name => $dontCare) {
368 $fields[$name] = 1;
369 }
370 }
371 $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
372 foreach ($fields as $name => $dontCare) {
373 if (isset($this->_params[0][$name])) {
374 $defaults[$name] = $this->_params[0][$name];
375 if (substr($name, 0, 7) == 'custom_') {
376 $timeField = "{$name}_time";
377 if (isset($this->_params[0][$timeField])) {
378 $defaults[$timeField] = $this->_params[0][$timeField];
379 }
380 if (isset($this->_params[0]["{$name}_id"])) {
381 $defaults["{$name}_id"] = $this->_params[0]["{$name}_id"];
382 }
383 }
384 elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)
385 && !empty($this->_params[0][$name . '_custom'])
386 ) {
387 $defaults[$name . '_custom'] = $this->_params[0][$name . '_custom'];
388 }
389 }
390 }
391
392 $this->setDefaults($defaults);
393 $this->freeze();
394
395 //lets give meaningful status message, CRM-4320.
396 $this->assign('isOnWaitlist', $this->_allowWaitlist);
397 $this->assign('isRequireApproval', $this->_requireApproval);
398
399 // Assign Participant Count to Lineitem Table
400 $this->assign('pricesetFieldsCount', CRM_Price_BAO_PriceSet::getPricesetCount($this->_priceSetId));
401 $this->addFormRule(array('CRM_Event_Form_Registration_Confirm', 'formRule'), $this);
402 }
403
404 /**
405 * @param $fields
406 * @param $files
407 * @param $self
408 *
409 * @return array|bool
410 */
411 public static function formRule($fields, $files, $self) {
412 $errors = array();
413 $eventFull = CRM_Event_BAO_Participant::eventFull($self->_eventId, FALSE, CRM_Utils_Array::value('has_waitlist', $self->_values['event']));
414 if ($eventFull && empty($self->_allowConfirmation)) {
415 if (empty($self->_allowWaitlist)) {
416 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "reset=1&id={$self->_eventId}", FALSE, NULL, FALSE, TRUE));
417 }
418 }
419 $self->_feeBlock = $self->_values['fee'];
420 CRM_Event_Form_Registration_Register::formatFieldsForOptionFull($self);
421
422 if (!empty($self->_priceSetId) &&
423 !$self->_requireApproval && !$self->_allowWaitlist
424 ) {
425 $priceSetErrors = self::validatePriceSet($self, $self->_params);
426 if (!empty($priceSetErrors)) {
427 CRM_Core_Session::setStatus(ts('You have been returned to the start of the registration process and any sold out events have been removed from your selections. You will not be able to continue until you review your booking and select different events if you wish.'), ts('Unfortunately some of your options have now sold out for one or more participants.'), 'error');
428 CRM_Core_Session::setStatus(ts('Please note that the options which are marked or selected are sold out for participant being viewed.'), ts('Sold out:'), 'error');
429 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "_qf_Register_display=true&qfKey={$fields['qfKey']}"));
430 }
431 }
432
433 return empty($priceSetErrors) ? TRUE : $priceSetErrors;
434 }
435
436 /**
437 * Process the form submission.
438 *
439 *
440 * @return void
441 */
442 public function postProcess() {
443 $now = date('YmdHis');
444
445 $this->_params = $this->get('params');
446 if (!empty($this->_params[0]['contact_id'])) {
447 // unclear when this would be set & whether it could be checked in getContactID.
448 // perhaps it relates to when cid is in the url
449 //@todo someone who knows add comments on the various contactIDs in this form
450 $contactID = $this->_params[0]['contact_id'];
451 }
452 else {
453 $contactID = $this->getContactID();
454 }
455
456 // if a discount has been applied, lets now deduct it from the amount
457 // and fix the fee level
458 if (!empty($this->_params[0]['discount']) && !empty($this->_params[0]['discount']['applied'])) {
459 foreach ($this->_params as $k => $v) {
460 if (CRM_Utils_Array::value('amount', $this->_params[$k]) > 0 && !empty($this->_params[$k]['discountAmount'])) {
461 $this->_params[$k]['amount'] -= $this->_params[$k]['discountAmount'];
462 $this->_params[$k]['amount_level'] .= CRM_Utils_Array::value('discountMessage', $this->_params[$k]);
463 }
464 }
465 $this->set('params', $this->_params);
466 }
467
468 // CRM-4320, lets build array of cancelled additional participant ids
469 // those are drop or skip by primary at the time of confirmation.
470 // get all in and then unset those we want to process.
471 $cancelledIds = $this->_additionalParticipantIds;
472
473 $params = $this->_params;
474 if ($this->_values['event']['is_monetary']) {
475 $this->set('finalAmount', $this->_amount);
476 }
477 $participantCount = array();
478
479 //unset the skip participant from params.
480 //build the $participantCount array.
481 //maintain record for all participants.
482 foreach ($params as $participantNum => $record) {
483 if ($record == 'skip') {
484 unset($params[$participantNum]);
485 $participantCount[$participantNum] = 'skip';
486 }
487 elseif ($participantNum) {
488 $participantCount[$participantNum] = 'participant';
489 }
490
491 //lets get additional participant id to cancel.
492 if ($this->_allowConfirmation && is_array($cancelledIds)) {
493 $additonalId = CRM_Utils_Array::value('participant_id', $record);
494 if ($additonalId && $key = array_search($additonalId, $cancelledIds)) {
495 unset($cancelledIds[$key]);
496 }
497 }
498 }
499
500 $payment = $registerByID = $primaryCurrencyID = $contribution = NULL;
501 $paymentObjError = ts('The system did not record payment details for this payment and so could not process the transaction. Please report this error to the site administrator.');
502
503 $this->participantIDS = array();
504 $fields = array();
505 foreach ($params as $key => $value) {
506 CRM_Event_Form_Registration_Confirm::fixLocationFields($value, $fields, $this);
507 //unset the billing parameters if it is pay later mode
508 //to avoid creation of billing location
509 if ($this->_allowWaitlist
510 || $this->_requireApproval
511 || (!empty($value['is_pay_later']) && !$this->_isBillingAddressRequiredForPayLater)
512 || empty($value['is_primary'])
513 ) {
514 $billingFields = array(
515 "email-{$this->_bltID}",
516 'billing_first_name',
517 'billing_middle_name',
518 'billing_last_name',
519 "billing_street_address-{$this->_bltID}",
520 "billing_city-{$this->_bltID}",
521 "billing_state_province-{$this->_bltID}",
522 "billing_state_province_id-{$this->_bltID}",
523 "billing_postal_code-{$this->_bltID}",
524 "billing_country-{$this->_bltID}",
525 "billing_country_id-{$this->_bltID}",
526 "address_name-{$this->_bltID}",
527 );
528 foreach ($billingFields as $field) {
529 unset($value[$field]);
530 }
531 if (!empty($value['is_pay_later'])) {
532 $this->_values['params']['is_pay_later'] = TRUE;
533 }
534 }
535
536 //Unset ContactID for additional participants and set RegisterBy Id.
537 if (empty($value['is_primary'])) {
538 $contactID = CRM_Utils_Array::value('contact_id', $value);
539 $registerByID = $this->get('registerByID');
540 if ($registerByID) {
541 $value['registered_by_id'] = $registerByID;
542 }
543 }
544 else {
545 $value['amount'] = $this->_totalAmount;
546 }
547
548 $contactID = CRM_Event_Form_Registration_Confirm::updateContactFields($contactID, $value, $fields, $this);
549
550 // lets store the contactID in the session
551 // we dont store in userID in case the user is doing multiple
552 // transactions etc
553 // for things like tell a friend
554 if (!$this->getContactID() && !empty($value['is_primary'])) {
555 $session = CRM_Core_Session::singleton();
556 $session->set('transaction.userID', $contactID);
557 }
558
559 $value['description'] = ts('Online Event Registration') . ': ' . $this->_values['event']['title'];
560 $value['accountingCode'] = CRM_Utils_Array::value('accountingCode',
561 $this->_values['event']
562 );
563
564 $pending = FALSE;
565 if ($this->_allowWaitlist || $this->_requireApproval) {
566 //get the participant statuses.
567 $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'");
568 if ($this->_allowWaitlist) {
569 $value['participant_status_id'] = $value['participant_status'] = array_search('On waitlist', $waitingStatuses);
570 }
571 else {
572 $value['participant_status_id'] = $value['participant_status'] = array_search('Awaiting approval', $waitingStatuses);
573 }
574
575 //there might be case user seleted pay later and
576 //now becomes part of run time waiting list.
577 $value['is_pay_later'] = FALSE;
578 }
579
580 // required only if paid event
581 if ($this->_values['event']['is_monetary'] && !($this->_allowWaitlist || $this->_requireApproval)) {
582 if (is_array($this->_paymentProcessor)) {
583 $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
584 }
585 $result = NULL;
586
587 if (!empty($value['is_pay_later']) ||
588 $value['amount'] == 0 ||
589 $this->_contributeMode == 'checkout' ||
590 $this->_contributeMode == 'notify'
591 ) {
592 if ($value['amount'] != 0) {
593 $pending = TRUE;
594 //get the participant statuses.
595 $pendingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'");
596 $status = !empty($value['is_pay_later']) ? 'Pending from pay later' : 'Pending from incomplete transaction';
597 $value['participant_status_id'] = $value['participant_status'] = array_search($status, $pendingStatuses);
598 }
599 }
600 elseif ($this->_contributeMode == 'express' && !empty($value['is_primary'])) {
601 if (is_object($payment)) {
602 $result = $payment->doExpressCheckout($value);
603 }
604 else {
605 CRM_Core_Error::fatal($paymentObjError);
606 }
607 }
608 elseif (!empty($value['is_primary'])) {
609 CRM_Core_Payment_Form::mapParams($this->_bltID, $value, $value, TRUE);
610 // payment email param can be empty for _bltID mapping
611 // thus provide mapping for it with a different email value
612 if (empty($value['email'])) {
613 $value['email'] = CRM_Utils_Array::valueByRegexKey('/^email-/', $value);
614 }
615
616 if (is_object($payment)) {
617 $result = $payment->doDirectPayment($value);
618 }
619 else {
620 CRM_Core_Error::fatal($paymentObjError);
621 }
622 }
623
624 if (is_a($result, 'CRM_Core_Error')) {
625 CRM_Core_Error::displaySessionError($result);
626 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "id={$this->_eventId}"));
627 }
628
629 if ($result) {
630 $value = array_merge($value, $result);
631 }
632
633 $value['receive_date'] = $now;
634 if ($this->_allowConfirmation) {
635 $value['participant_register_date'] = $this->_values['participant']['register_date'];
636 }
637
638 $createContrib = ($value['amount'] != 0) ? TRUE : FALSE;
639 // force to create zero amount contribution, CRM-5095
640 if (!$createContrib && ($value['amount'] == 0)
641 && $this->_priceSetId && $this->_lineItem
642 ) {
643 $createContrib = TRUE;
644 }
645
646 if ($createContrib && !empty($value['is_primary']) &&
647 !$this->_allowWaitlist && !$this->_requireApproval
648 ) {
649 // if paid event add a contribution record
650 //if primary participant contributing additional amount
651 //append (multiple participants) to its fee level. CRM-4196.
652 $isAdditionalAmount = FALSE;
653 if (count($params) > 1) {
654 $isAdditionalAmount = TRUE;
655 }
656
657 //passing contribution id is already registered.
658 $contribution = self::processContribution($this, $value, $result, $contactID, $pending, $isAdditionalAmount);
659 $value['contributionID'] = $contribution->id;
660 $value['contributionTypeID'] = $contribution->financial_type_id;
661 $value['receive_date'] = $contribution->receive_date;
662 $value['trxn_id'] = $contribution->trxn_id;
663 $value['contributionID'] = $contribution->id;
664 $value['contributionTypeID'] = $contribution->financial_type_id;
665 }
666 $value['contactID'] = $contactID;
667 $value['eventID'] = $this->_eventId;
668 $value['item_name'] = $value['description'];
669 }
670
671 if (!empty($value['contributionID'])) {
672 $this->_values['contributionId'] = $value['contributionID'];
673 }
674
675 //CRM-4453.
676 if (!empty($value['is_primary'])) {
677 $primaryCurrencyID = CRM_Utils_Array::value('currencyID', $value);
678 }
679 if (empty($value['currencyID'])) {
680 $value['currencyID'] = $primaryCurrencyID;
681 }
682
683 // CRM-11182 - Confirmation page might not be monetary
684 if ($this->_values['event']['is_monetary']) {
685 if (!$pending && !empty($value['is_primary']) &&
686 !$this->_allowWaitlist && !$this->_requireApproval
687 ) {
688 // transactionID & receive date required while building email template
689 $this->assign('trxn_id', $value['trxn_id']);
690 $this->assign('receive_date', CRM_Utils_Date::mysqlToIso($value['receive_date']));
691 $this->set('receiveDate', CRM_Utils_Date::mysqlToIso($value['receive_date']));
692 $this->set('trxnId', CRM_Utils_Array::value('trxn_id', $value));
693 }
694 }
695
696 $value['fee_amount'] = CRM_Utils_Array::value('amount', $value);
697 $this->set('value', $value);
698
699 // handle register date CRM-4320
700 if ($this->_allowConfirmation) {
701 $registerDate = CRM_Utils_Array::value('participant_register_date', $params);
702 }
703 elseif (!empty($params['participant_register_date']) &&
704 is_array($params['participant_register_date']) &&
705 !empty($params['participant_register_date'])
706 ) {
707 $registerDate = CRM_Utils_Date::format($params['participant_register_date']);
708 }
709 else {
710 $registerDate = date('YmdHis');
711 }
712 $this->assign('register_date', $registerDate);
713
714 $this->confirmPostProcess($contactID, $contribution, $payment);
715 }
716
717 //handle if no additional participant.
718 if (!$registerByID) {
719 $registerByID = $this->get('registerByID');
720 }
721
722 $this->set('participantIDs', $this->_participantIDS);
723
724 // create line items, CRM-5313
725 if ($this->_priceSetId &&
726 !empty($this->_lineItem)
727 ) {
728 // take all processed participant ids.
729 $allParticipantIds = $this->_participantIDS;
730
731 // when participant re-walk wizard.
732 if ($this->_allowConfirmation &&
733 !empty($this->_additionalParticipantIds)
734 ) {
735 $allParticipantIds = array_merge(array($registerByID), $this->_additionalParticipantIds);
736 }
737
738 $entityTable = 'civicrm_participant';
739 $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
740 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
741 $totalTaxAmount = 0;
742 $dataArray = array();
743 foreach ($this->_lineItem as $key => $value) {
744 if (($value != 'skip') &&
745 ($entityId = CRM_Utils_Array::value($key, $allParticipantIds))
746 ) {
747
748 // do cleanup line items if participant re-walking wizard.
749 if ($this->_allowConfirmation) {
750 CRM_Price_BAO_LineItem::deleteLineItems($entityId, $entityTable);
751 }
752 $lineItem[$this->_priceSetId] = $value;
753 CRM_Price_BAO_LineItem::processPriceSet($entityId, $lineItem, $contribution, $entityTable);
754 }
755 if ($invoicing) {
756 foreach ($value as $line) {
757 if (isset($line['tax_amount']) && isset($line['tax_rate'])) {
758 $totalTaxAmount = $line['tax_amount'] + $totalTaxAmount;
759 if (isset($dataArray[$line['tax_rate']])) {
760 $dataArray[$line['tax_rate']] = $dataArray[$line['tax_rate']] + CRM_Utils_Array::value('tax_amount', $line);
761 }
762 else {
763 $dataArray[$line['tax_rate']] = CRM_Utils_Array::value('tax_amount', $line);
764 }
765 }
766 }
767 }
768 }
769 if ($invoicing) {
770 $this->assign('dataArray', $dataArray);
771 $this->assign('totalTaxAmount', $totalTaxAmount);
772 }
773 }
774
775 //update status and send mail to cancelled additional participants, CRM-4320
776 if ($this->_allowConfirmation && is_array($cancelledIds) && !empty($cancelledIds)) {
777 $cancelledId = array_search('Cancelled',
778 CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'")
779 );
780 CRM_Event_BAO_Participant::transitionParticipants($cancelledIds, $cancelledId);
781 }
782
783 $isTest = FALSE;
784 if ($this->_action & CRM_Core_Action::PREVIEW) {
785 $isTest = TRUE;
786 }
787
788 // for Transfer checkout.
789 if (($this->_contributeMode == 'checkout' ||
790 $this->_contributeMode == 'notify'
791 ) && empty($params[0]['is_pay_later']) &&
792 !$this->_allowWaitlist && !$this->_requireApproval &&
793 $this->_totalAmount > 0
794 ) {
795
796 $primaryParticipant = $this->get('primaryParticipant');
797
798 if (empty($primaryParticipant['participantID'])) {
799 $primaryParticipant['participantID'] = $registerByID;
800 }
801
802 //build an array of custom profile and assigning it to template
803 $customProfile = CRM_Event_BAO_Event::buildCustomProfile($registerByID, $this->_values, NULL, $isTest);
804 if (count($customProfile)) {
805 $this->assign('customProfile', $customProfile);
806 $this->set('customProfile', $customProfile);
807 }
808
809 // do a transfer only if a monetary payment greater than 0
810 if ($this->_values['event']['is_monetary'] && $primaryParticipant) {
811 if ($payment && is_object($payment)) {
812 //CRM 14512 provide line items of all participants to payment gateway
813 $primaryContactId = $this->get('primaryContactId');
814
815 //build an array of cId/pId of participants
816 $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID, NULL, $primaryContactId, $isTest, TRUE);
817
818 //need to copy, since we are unsetting on the way.
819 $copyParticipantCountLines = $participantCount;
820
821 //lets carry all participant params w/ values.
822 foreach ($additionalIDs as $participantID => $contactId) {
823 $participantNum = NULL;
824 $participantNum = $participantID;
825 if ($participantID == $registerByID) {
826 $participantNum = 0; // is primary particpant
827 }
828 else {
829 if ($participantNum = array_search('participant', $copyParticipantCountLines)) {
830 //if no participant found break.
831 if ($participantNum === NULL) {
832 break;
833 }
834 //unset current particpant so we don't check them again
835 unset($copyParticipantCountLines[$participantNum]);
836 }
837 }
838 // get values of line items
839 if ($this->_amount) {
840 $amount = array();
841 $amount[$participantNum]['label'] = preg_replace('/\ 1/', '', $params[$participantNum]['amount_level']);
842 $amount[$participantNum]['amount'] = $params[$participantNum]['amount'];
843 $params[$participantNum]['amounts'] = $amount;
844 }
845
846 if (!empty($this->_lineItem)) {
847 $lineItems = $this->_lineItem;
848 $lineItem = array();
849 if ($lineItemValue = CRM_Utils_Array::value($participantNum, $lineItems)) {
850 $lineItem[] = $lineItemValue;
851 }
852 $params[$participantNum]['lineItem'] = $lineItem;
853 }
854
855 //only add additional particpants and not the primary particpant as we already have that
856 //added to $primaryParticipant so that this change doesn't break or require changes to
857 //existing gateway implementations
858 $primaryParticipant['participants_info'][$participantID] = $params[$participantNum];
859 }
860
861 //get event custom field information
862 $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this, $this->_eventId, 0, $this->_values['event']['event_type_id']);
863 $primaryParticipant['eventCustomFields'] = $groupTree;
864
865 // call postprocess hook before leaving
866 $this->postProcessHook();
867 // this does not return
868 $payment->doTransferCheckout($primaryParticipant, 'event');
869 }
870 else {
871 CRM_Core_Error::fatal($paymentObjError);
872 }
873 }
874 }
875 else {
876 //otherwise send mail Confirmation/Receipt
877 $primaryContactId = $this->get('primaryContactId');
878
879 //build an array of cId/pId of participants
880 $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID,
881 NULL, $primaryContactId, $isTest,
882 TRUE
883 );
884 //lets send mails to all with meaningful text, CRM-4320.
885 $this->assign('isOnWaitlist', $this->_allowWaitlist);
886 $this->assign('isRequireApproval', $this->_requireApproval);
887
888 //need to copy, since we are unsetting on the way.
889 $copyParticipantCount = $participantCount;
890
891 //lets carry all paticipant params w/ values.
892 foreach ($additionalIDs as $participantID => $contactId) {
893 $participantNum = NULL;
894 if ($participantID == $registerByID) {
895 $participantNum = 0;
896 }
897 else {
898 if ($participantNum = array_search('participant', $copyParticipantCount)) {
899 unset($copyParticipantCount[$participantNum]);
900 }
901 }
902 if ($participantNum === NULL) {
903 break;
904 }
905
906 //carry the participant submitted values.
907 $this->_values['params'][$participantID] = $params[$participantNum];
908 }
909
910 foreach ($additionalIDs as $participantID => $contactId) {
911 $participantNum = 0;
912 if ($participantID == $registerByID) {
913 //set as Primary Participant
914 $this->assign('isPrimary', 1);
915 //build an array of custom profile and assigning it to template.
916 $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participantID, $this->_values, NULL, $isTest);
917
918 if (count($customProfile)) {
919 $this->assign('customProfile', $customProfile);
920 $this->set('customProfile', $customProfile);
921 }
922 $this->_values['params']['additionalParticipant'] = FALSE;
923 }
924 else {
925 //take the Additional participant number.
926 if ($participantNum = array_search('participant', $participantCount)) {
927 unset($participantCount[$participantNum]);
928 }
929 $this->assign('isPrimary', 0);
930 $this->assign('customProfile', NULL);
931 //Additional Participant should get only it's payment information
932 if (!empty($this->_amount)) {
933 $amount = array();
934 $params = $this->get('params');
935 $amount[$participantNum]['label'] = preg_replace('/\ 1/', '', $params[$participantNum]['amount_level']);
936 $amount[$participantNum]['amount'] = $params[$participantNum]['amount'];
937 $this->assign('amounts', $amount);
938 }
939 if ($this->_lineItem) {
940 $lineItems = $this->_lineItem;
941 $lineItem = array();
942 if ($lineItemValue = CRM_Utils_Array::value($participantNum, $lineItems)) {
943 $lineItem[] = $lineItemValue;
944 }
945 if ($invoicing) {
946 $individual = $this->get('individual');
947 $dataArray[key($dataArray)] = $individual[$participantNum]['totalTaxAmt'];
948 $this->assign('dataArray', $dataArray);
949 $this->assign('totalAmount', $individual[$participantNum]['totalAmtWithTax']);
950 $this->assign('totalTaxAmount', $individual[$participantNum]['totalTaxAmt']);
951 $this->assign('individual', array($individual[$participantNum]));
952 }
953 $this->assign('lineItem', $lineItem);
954 }
955 $this->_values['params']['additionalParticipant'] = TRUE;
956 $this->assign('isAdditionalParticipant', $this->_values['params']['additionalParticipant']);
957 }
958
959 //pass these variables since these are run time calculated.
960 $this->_values['params']['isOnWaitlist'] = $this->_allowWaitlist;
961 $this->_values['params']['isRequireApproval'] = $this->_requireApproval;
962
963 //send mail to primary as well as additional participants.
964 $this->assign('contactID', $contactId);
965 $this->assign('participantID', $participantID);
966 CRM_Event_BAO_Event::sendMail($contactId, $this->_values, $participantID, $isTest);
967 }
968 }
969 }
970
971 /**
972 * Process the contribution.
973 *
974 * @param CRM_Core_Form $form
975 * @param array $params
976 * @param $result
977 * @param int $contactID
978 * @param bool $pending
979 * @param bool $isAdditionalAmount
980 *
981 * @return void
982 */
983 public static function processContribution(
984 &$form, $params, $result, $contactID,
985 $pending = FALSE, $isAdditionalAmount = FALSE
986 ) {
987 $transaction = new CRM_Core_Transaction();
988
989 $now = date('YmdHis');
990 $receiptDate = NULL;
991
992 if (!empty($form->_values['event']['is_email_confirm'])) {
993 $receiptDate = $now;
994 }
995 //CRM-4196
996 if ($isAdditionalAmount) {
997 $params['amount_level'] = $params['amount_level'] . ts(' (multiple participants)') . CRM_Core_DAO::VALUE_SEPARATOR;
998 }
999
1000 $contribParams = array(
1001 'contact_id' => $contactID,
1002 'financial_type_id' => !empty($form->_values['event']['financial_type_id']) ? $form->_values['event']['financial_type_id'] : $params['financial_type_id'],
1003 'receive_date' => $now,
1004 'total_amount' => $params['amount'],
1005 'tax_amount' => $params['tax_amount'],
1006 'amount_level' => $params['amount_level'],
1007 'invoice_id' => $params['invoiceID'],
1008 'currency' => $params['currencyID'],
1009 'source' => !empty($params['participant_source']) ? $params['participant_source'] : $params['description'],
1010 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0),
1011 'campaign_id' => CRM_Utils_Array::value('campaign_id', $params),
1012 );
1013
1014 if (empty($params['is_pay_later'])) {
1015 $contribParams['payment_instrument_id'] = 1;
1016 }
1017
1018 if (!$pending && $result) {
1019 $contribParams += array(
1020 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result),
1021 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['amount']),
1022 'trxn_id' => $result['trxn_id'],
1023 'receipt_date' => $receiptDate,
1024 );
1025 }
1026
1027 $allStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
1028 $contribParams['contribution_status_id'] = array_search('Completed', $allStatuses);
1029 if ($pending) {
1030 $contribParams['contribution_status_id'] = array_search('Pending', $allStatuses);
1031 }
1032
1033 $contribParams['is_test'] = 0;
1034 if ($form->_action & CRM_Core_Action::PREVIEW || CRM_Utils_Array::value('mode', $params) == 'test') {
1035 $contribParams['is_test'] = 1;
1036 }
1037
1038 $contribID = NULL;
1039 if (!empty($contribParams['invoice_id'])) {
1040 $contribID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution',
1041 $contribParams['invoice_id'],
1042 'id',
1043 'invoice_id'
1044 );
1045 }
1046
1047 $ids = array();
1048 if ($contribID) {
1049 $ids['contribution'] = $contribID;
1050 $contribParams['id'] = $contribID;
1051 }
1052
1053 //create an contribution address
1054 if ($form->_contributeMode != 'notify' && empty($params['is_pay_later'])) {
1055 $contribParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $form->_bltID);
1056 }
1057
1058 // Prepare soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
1059 if (!empty($params['pcp_made_through_id']) || !empty($params['soft_credit_to'])) {
1060
1061 // if its due to pcp
1062 if (!empty($params['pcp_made_through_id'])) {
1063 $contribSoftContactId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP',
1064 $params['pcp_made_through_id'],
1065 'contact_id'
1066 );
1067 }
1068 else {
1069 $contribSoftContactId = CRM_Utils_Array::value('soft_credit_to', $params);
1070 }
1071
1072 // Pass these details onto with the contribution to make them
1073 // available at hook_post_process, CRM-8908
1074 $contribParams['soft_credit_to'] = $params['soft_credit_to'] = $contribSoftContactId;
1075 }
1076 $contribParams['payment_processor'] = CRM_Utils_Array::value('payment_processor', $params);
1077 $contribParams['skipLineItem'] = 1;
1078 // create contribution record
1079 $contribution = CRM_Contribute_BAO_Contribution::add($contribParams, $ids);
1080 // CRM-11124
1081 CRM_Event_BAO_Participant::createDiscountTrxn($form->_eventId, $contribParams, CRM_Utils_Array::value('amount_priceset_level_radio', $params, NULL));
1082
1083 // process soft credit / pcp pages
1084 CRM_Contribute_Form_Contribution_Confirm::processPcpSoft($params, $contribution);
1085
1086 $transaction->commit();
1087
1088 return $contribution;
1089 }
1090
1091 /**
1092 * Fix the Location Fields.
1093 *
1094 * @param array $params
1095 * @param $fields
1096 * @param CRM_Core_Form $form
1097 *
1098 * @return void
1099 */
1100 public static function fixLocationFields(&$params, &$fields, &$form) {
1101 if (!empty($form->_fields)) {
1102 foreach ($form->_fields as $name => $dontCare) {
1103 $fields[$name] = 1;
1104 }
1105 }
1106
1107 if (is_array($fields)) {
1108 if (!array_key_exists('first_name', $fields)) {
1109 $nameFields = array('first_name', 'middle_name', 'last_name');
1110 foreach ($nameFields as $name) {
1111 $fields[$name] = 1;
1112 if (array_key_exists("billing_$name", $params)) {
1113 $params[$name] = $params["billing_{$name}"];
1114 $params['preserveDBName'] = TRUE;
1115 }
1116 }
1117 }
1118 }
1119
1120 // also add location name to the array
1121 if ($form->_values['event']['is_monetary']) {
1122 $params["address_name-{$form->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params);
1123 $fields["address_name-{$form->_bltID}"] = 1;
1124 }
1125 $fields["email-{$form->_bltID}"] = 1;
1126 $fields['email-Primary'] = 1;
1127
1128 //if its pay later or additional participant set email address as primary.
1129 if ((!empty($params['is_pay_later']) || empty($params['is_primary']) ||
1130 !$form->_values['event']['is_monetary'] ||
1131 $form->_allowWaitlist ||
1132 $form->_requireApproval
1133 ) && !empty($params["email-{$form->_bltID}"])
1134 ) {
1135 $params['email-Primary'] = $params["email-{$form->_bltID}"];
1136 }
1137 }
1138
1139 /**
1140 * Update contact fields.
1141 *
1142 * @param int $contactID
1143 * @param array $params
1144 * @param $fields
1145 * @param CRM_Core_Form $form
1146 *
1147 * @return void
1148 */
1149 public static function updateContactFields($contactID, $params, $fields, &$form) {
1150 //add the contact to group, if add to group is selected for a
1151 //particular uf group
1152
1153 // get the add to groups
1154 $addToGroups = array();
1155
1156 if (!empty($form->_fields)) {
1157 foreach ($form->_fields as $key => $value) {
1158 if (!empty($value['add_to_group_id'])) {
1159 $addToGroups[$value['add_to_group_id']] = $value['add_to_group_id'];
1160 }
1161 }
1162 }
1163
1164 // check for profile double opt-in and get groups to be subscribed
1165 $subscribeGroupIds = CRM_Core_BAO_UFGroup::getDoubleOptInGroupIds($params, $contactID);
1166
1167 foreach ($addToGroups as $k) {
1168 if (array_key_exists($k, $subscribeGroupIds)) {
1169 unset($addToGroups[$k]);
1170 }
1171 }
1172
1173 // since we are directly adding contact to group lets unset it from mailing
1174 if (!empty($addToGroups)) {
1175 foreach ($addToGroups as $groupId) {
1176 if (isset($subscribeGroupIds[$groupId])) {
1177 unset($subscribeGroupIds[$groupId]);
1178 }
1179 }
1180 }
1181 if ($contactID) {
1182 $ctype = CRM_Core_DAO::getFieldValue(
1183 'CRM_Contact_DAO_Contact',
1184 $contactID,
1185 'contact_type'
1186 );
1187
1188 if (array_key_exists('contact_id', $params) && empty($params['contact_id'])) {
1189 // we unset this here because the downstream function ignores the contactID we give it
1190 // if it is set & it is difficult to understand the implications of 'fixing' this downstream
1191 // but if we are passing a contact id into this function it's reasonable to assume we don't
1192 // want it ignored
1193 unset($params['contact_id']);
1194 }
1195
1196 $contactID = CRM_Contact_BAO_Contact::createProfileContact(
1197 $params,
1198 $fields,
1199 $contactID,
1200 $addToGroups,
1201 NULL,
1202 $ctype,
1203 TRUE
1204 );
1205 }
1206 else {
1207
1208 foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
1209 if (!isset($params[$greeting . '_id'])) {
1210 $params[$greeting . '_id'] = CRM_Contact_BAO_Contact_Utils::defaultGreeting('Individual', $greeting);
1211 }
1212 }
1213
1214 $contactID = CRM_Contact_BAO_Contact::createProfileContact($params,
1215 $fields,
1216 NULL,
1217 $addToGroups,
1218 NULL,
1219 NULL,
1220 TRUE
1221 );
1222 $form->set('contactID', $contactID);
1223 }
1224
1225 //get email primary first if exist
1226 $subscribtionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params));
1227 if (!$subscribtionEmail['email']) {
1228 $subscribtionEmail['email'] = CRM_Utils_Array::value("email-{$form->_bltID}", $params);
1229 }
1230 // subscribing contact to groups
1231 if (!empty($subscribeGroupIds) && $subscribtionEmail['email']) {
1232 CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscribtionEmail, $contactID);
1233 }
1234
1235 return $contactID;
1236 }
1237
1238 /**
1239 * @param $form
1240 */
1241 public static function assignProfiles(&$form) {
1242 $participantParams = $form->_params;
1243 $formattedValues = $profileFields = array();
1244 $count = 1;
1245 foreach ($participantParams as $participantNum => $participantValue) {
1246 if ($participantNum) {
1247 $prefix1 = 'additional';
1248 $prefix2 = 'additional_';
1249 }
1250 else {
1251 $prefix1 = '';
1252 $prefix2 = '';
1253 }
1254 if ($participantValue != 'skip') {
1255 //get the customPre profile info
1256 if (!empty($form->_values[$prefix2 . 'custom_pre_id'])) {
1257 $values = $groupName = array();
1258 CRM_Event_BAO_Event::displayProfile($participantValue,
1259 $form->_values[$prefix2 . 'custom_pre_id'],
1260 $groupName,
1261 $values,
1262 $profileFields
1263 );
1264
1265 if (count($values)) {
1266 $formattedValues[$count][$prefix1 . 'CustomPre'] = $values;
1267 }
1268 $formattedValues[$count][$prefix1 . 'CustomPreGroupTitle'] = CRM_Utils_Array::value('groupTitle', $groupName);
1269 }
1270 //get the customPost profile info
1271 if (!empty($form->_values[$prefix2 . 'custom_post_id'])) {
1272 $values = $groupName = array();
1273 foreach ($form->_values[$prefix2 . 'custom_post_id'] as $gids) {
1274 $val = array();
1275 CRM_Event_BAO_Event::displayProfile($participantValue,
1276 $gids,
1277 $group,
1278 $val,
1279 $profileFields
1280 );
1281 $values[$gids] = $val;
1282 $groupName[$gids] = $group;
1283 }
1284
1285 if (count($values)) {
1286 $formattedValues[$count][$prefix1 . 'CustomPost'] = $values;
1287 }
1288
1289 if (isset($formattedValues[$count][$prefix1 . 'CustomPre'])) {
1290 $formattedValues[$count][$prefix1 . 'CustomPost'] = array_diff_assoc($formattedValues[$count][$prefix1 . 'CustomPost'],
1291 $formattedValues[$count][$prefix1 . 'CustomPre']
1292 );
1293 }
1294
1295 $formattedValues[$count][$prefix1 . 'CustomPostGroupTitle'] = $groupName;
1296 }
1297 $count++;
1298 }
1299 $form->_fields = $profileFields;
1300 }
1301 if (!empty($formattedValues)) {
1302 $form->assign('primaryParticipantProfile', $formattedValues[1]);
1303 $form->set('primaryParticipantProfile', $formattedValues[1]);
1304 if ($count > 2) {
1305 unset($formattedValues[1]);
1306 $form->assign('addParticipantProfile', $formattedValues);
1307 $form->set('addParticipantProfile', $formattedValues);
1308 }
1309 }
1310 }
1311
1312 }