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