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