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