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