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