3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2015
38 * This class generates form components for processing Event
41 class CRM_Event_Form_Registration_Confirm
extends CRM_Event_Form_Registration
{
44 * The values for the contribution db object.
58 * Set variables up before form is built.
62 public function preProcess() {
65 // lineItem isn't set until Register postProcess
66 $this->_lineItem
= $this->get('lineItem');
68 $this->_params
= $this->get('params');
69 $this->_params
[0]['tax_amount'] = $this->get('tax_amount');
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']);
77 CRM_Utils_Hook
::eventDiscount($this, $this->_params
);
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']);
84 if ($this->_contributeMode
== 'express') {
86 // rfp == redirect from paypal
87 $rfp = CRM_Utils_Request
::retrieve('rfp', 'Boolean',
88 CRM_Core_DAO
::$_nullObject, FALSE, NULL, 'GET'
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'));
99 CRM_Core_Error
::fatal($paymentObjError);
102 $params['payer'] = CRM_Utils_Array
::value('payer', $expressParams);
103 $params['payer_id'] = $expressParams['payer_id'];
104 $params['payer_status'] = $expressParams['payer_status'];
106 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $expressParams, $params, FALSE);
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}"]);
112 if (isset($params['billing_country_id'])) {
113 $params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($params["billing_country_id-{$this->_bltID}"]);
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'];
124 if (!empty($this->_params
[0]['amount_priceset_level_radio'])) {
125 $params['amount_priceset_level_radio'] = $this->_params
[0]['amount_priceset_level_radio'];
127 $params['amount_level'] = $this->_params
[0]['amount_level'];
128 $params['currencyID'] = $this->_params
[0]['currencyID'];
130 // also merge all the other values from the profile fields
131 $values = $this->controller
->exportValues('Register');
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}",
141 foreach ($values as $name => $value) {
143 if (!in_array($name, $skipFields)) {
144 $params[$name] = $value;
147 $this->set('getExpressCheckoutDetails', $params);
150 $params = $this->get('getExpressCheckoutDetails');
152 $this->_params
[0] = $params;
153 $this->_params
[0]['is_primary'] = 1;
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}"]
161 $registerParams["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($registerParams["billing_state_province_id-{$this->_bltID}"]);
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}"]);
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);
171 if ($this->_values
['event']['is_monetary']) {
172 $registerParams['ip_address'] = CRM_Utils_System
::ipAddress();
173 $registerParams['currencyID'] = $this->_params
[0]['currencyID'];
175 //assign back primary participant params.
176 $this->_params
[0] = $registerParams;
179 if ($this->_values
['event']['is_monetary']) {
180 $this->_params
[0]['invoiceID'] = $this->get('invoiceID');
182 $this->assign('defaultRole', FALSE);
183 if (CRM_Utils_Array
::value('defaultRole', $this->_params
[0]) == 1) {
184 $this->assign('defaultRole', TRUE);
187 if (empty($this->_params
[0]['participant_role_id']) &&
188 $this->_values
['event']['default_role_id']
190 $this->_params
[0]['participant_role_id'] = $this->_values
['event']['default_role_id'];
193 if (isset($this->_values
['event']['confirm_title'])) {
194 CRM_Utils_System
::setTitle($this->_values
['event']['confirm_title']);
198 $params = CRM_Contribute_Form_Contribution_Confirm
::processPcp($this, $this->_params
[0]);
199 $this->_params
[0] = $params;
202 $this->set('params', $this->_params
);
206 * Overwrite action, since we are only showing elements in frozen mode
207 * no help display needed
211 public function getAction() {
212 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
213 return CRM_Core_Action
::VIEW | CRM_Core_Action
::PREVIEW
;
216 return CRM_Core_Action
::VIEW
;
221 * Build the form object.
225 public function buildQuickForm() {
226 $this->assignToTemplate();
228 if ($this->_values
['event']['is_monetary'] &&
229 ($this->_params
[0]['amount'] ||
$this->_params
[0]['amount'] == 0)
231 $this->_amount
= array();
234 foreach ($this->_params
as $k => $v) {
235 $individualTaxAmount = 0;
236 //display tax amount on confirmation page
237 $taxAmount +
= $v['tax_amount'];
243 if (isset($v['billing_' . $name]) &&
246 $v[$name] = $v['billing_' . $name];
250 if (!empty($v['first_name']) && !empty($v['last_name'])) {
251 $append = $v['first_name'] . ' ' . $v['last_name'];
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];
262 $this->_amount
[$k]['amount'] = $v['amount'];
263 if (!empty($v['discountAmount'])) {
264 $this->_amount
[$k]['amount'] -= $v['discountAmount'];
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;
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']);
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);
287 $this->assign('totalTaxAmount', $taxAmount);
288 $this->assign('taxTerm', $taxTerm);
289 $this->assign('individual', $individual);
290 $this->set('individual', $individual);
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
);
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;
309 foreach ($value as $v) {
310 if (isset($v['tax_rate'])) {
311 $getTaxDetails = TRUE;
317 if (!empty($lineItemForTemplate)) {
318 $this->assign('lineItem', $lineItemForTemplate);
320 $this->assign('getTaxDetails', $getTaxDetails);
323 //display additional participants profile.
324 self
::assignProfiles($this);
326 //consider total amount.
327 $this->assign('isAmountzero', ($this->_totalAmount
<= 0) ?
TRUE : FALSE);
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
332 $this->_checkoutButtonName
= $this->getButtonName('next', 'checkout');
334 $this->_checkoutButtonName
,
335 $this->_paymentProcessor
['url_button'],
336 array('class' => 'crm-form-submit')
339 $this->addButtons(array(
342 'name' => ts('Go Back'),
348 $contribButton = ts('Continue');
349 $this->addButtons(array(
352 'name' => ts('Go Back'),
356 'name' => $contribButton,
358 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name
. "','" . ts('Processing') . "');"),
366 if (!empty($this->_fields
)) {
367 foreach ($this->_fields
as $name => $dontCare) {
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];
380 if (isset($this->_params
[0]["{$name}_id"])) {
381 $defaults["{$name}_id"] = $this->_params
[0]["{$name}_id"];
384 elseif (in_array($name, CRM_Contact_BAO_Contact
::$_greetingTypes)
385 && !empty($this->_params
[0][$name . '_custom'])
387 $defaults[$name . '_custom'] = $this->_params
[0][$name . '_custom'];
392 $this->setDefaults($defaults);
395 //lets give meaningful status message, CRM-4320.
396 $this->assign('isOnWaitlist', $this->_allowWaitlist
);
397 $this->assign('isRequireApproval', $this->_requireApproval
);
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);
411 public static function formRule($fields, $files, $self) {
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));
419 $self->_feeBlock
= $self->_values
['fee'];
420 CRM_Event_Form_Registration_Register
::formatFieldsForOptionFull($self);
422 if (!empty($self->_priceSetId
) &&
423 !$self->_requireApproval
&& !$self->_allowWaitlist
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']}"));
433 return empty($priceSetErrors) ?
TRUE : $priceSetErrors;
437 * Process the form submission.
442 public function postProcess() {
443 $now = date('YmdHis');
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'];
453 $contactID = $this->getContactID();
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]);
465 $this->set('params', $this->_params
);
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
;
473 $params = $this->_params
;
474 if ($this->_values
['event']['is_monetary']) {
475 $this->set('finalAmount', $this->_amount
);
477 $participantCount = array();
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';
487 elseif ($participantNum) {
488 $participantCount[$participantNum] = 'participant';
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]);
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.');
503 $this->participantIDS
= 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'])
514 $billingFields = array(
515 "email-{$this->_bltID}",
516 'billing_first_name',
517 'billing_middle_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}",
528 foreach ($billingFields as $field) {
529 unset($value[$field]);
531 if (!empty($value['is_pay_later'])) {
532 $this->_values
['params']['is_pay_later'] = TRUE;
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');
541 $value['registered_by_id'] = $registerByID;
545 $value['amount'] = $this->_totalAmount
;
548 $contactID = CRM_Event_Form_Registration_Confirm
::updateContactFields($contactID, $value, $fields, $this);
550 // lets store the contactID in the session
551 // we dont store in userID in case the user is doing multiple
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);
559 $value['description'] = ts('Online Event Registration') . ': ' . $this->_values
['event']['title'];
560 $value['accountingCode'] = CRM_Utils_Array
::value('accountingCode',
561 $this->_values
['event']
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);
572 $value['participant_status_id'] = $value['participant_status'] = array_search('Awaiting approval', $waitingStatuses);
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;
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'];
587 if (!empty($value['is_pay_later']) ||
588 $value['amount'] == 0 ||
589 $this->_contributeMode
== 'checkout' ||
590 $this->_contributeMode
== 'notify'
592 if ($value['amount'] != 0) {
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);
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);
608 if (is_object($payment)) {
610 $result = $payment->doPayment($value);
611 $value = array_merge($value, $result);
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}"));
619 CRM_Core_Error
::fatal($paymentObjError);
623 $value['receive_date'] = $now;
624 if ($this->_allowConfirmation
) {
625 $value['participant_register_date'] = $this->_values
['participant']['register_date'];
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
633 $createContrib = TRUE;
636 if ($createContrib && !empty($value['is_primary']) &&
637 !$this->_allowWaitlist
&& !$this->_requireApproval
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;
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
;
656 $value['contactID'] = $contactID;
657 $value['eventID'] = $this->_eventId
;
658 $value['item_name'] = $value['description'];
661 if (!empty($value['contributionID'])) {
662 $this->_values
['contributionId'] = $value['contributionID'];
666 if (!empty($value['is_primary'])) {
667 $primaryCurrencyID = CRM_Utils_Array
::value('currencyID', $value);
669 if (empty($value['currencyID'])) {
670 $value['currencyID'] = $primaryCurrencyID;
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
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));
686 $value['fee_amount'] = CRM_Utils_Array
::value('amount', $value);
687 $this->set('value', $value);
689 // handle register date CRM-4320
690 if ($this->_allowConfirmation
) {
691 $registerDate = CRM_Utils_Array
::value('participant_register_date', $params);
693 elseif (!empty($params['participant_register_date']) &&
694 is_array($params['participant_register_date']) &&
695 !empty($params['participant_register_date'])
697 $registerDate = CRM_Utils_Date
::format($params['participant_register_date']);
700 $registerDate = date('YmdHis');
702 $this->assign('register_date', $registerDate);
704 $this->confirmPostProcess($contactID, $contribution, $payment);
707 //handle if no additional participant.
708 if (!$registerByID) {
709 $registerByID = $this->get('registerByID');
712 $this->set('participantIDs', $this->_participantIDS
);
714 // create line items, CRM-5313
715 if ($this->_priceSetId
&&
716 !empty($this->_lineItem
)
718 // take all processed participant ids.
719 $allParticipantIds = $this->_participantIDS
;
721 // when participant re-walk wizard.
722 if ($this->_allowConfirmation
&&
723 !empty($this->_additionalParticipantIds
)
725 $allParticipantIds = array_merge(array($registerByID), $this->_additionalParticipantIds
);
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);
732 $dataArray = array();
733 foreach ($this->_lineItem
as $key => $value) {
734 if (($value != 'skip') &&
735 ($entityId = CRM_Utils_Array
::value($key, $allParticipantIds))
738 // do cleanup line items if participant re-walking wizard.
739 if ($this->_allowConfirmation
) {
740 CRM_Price_BAO_LineItem
::deleteLineItems($entityId, $entityTable);
742 $lineItem[$this->_priceSetId
] = $value;
743 CRM_Price_BAO_LineItem
::processPriceSet($entityId, $lineItem, $contribution, $entityTable);
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);
753 $dataArray[$line['tax_rate']] = CRM_Utils_Array
::value('tax_amount', $line);
760 $this->assign('dataArray', $dataArray);
761 $this->assign('totalTaxAmount', $totalTaxAmount);
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'")
770 CRM_Event_BAO_Participant
::transitionParticipants($cancelledIds, $cancelledId);
774 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
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
786 $primaryParticipant = $this->get('primaryParticipant');
788 if (empty($primaryParticipant['participantID'])) {
789 $primaryParticipant['participantID'] = $registerByID;
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);
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');
805 //build an array of cId/pId of participants
806 $additionalIDs = CRM_Event_BAO_Event
::buildCustomProfile($registerByID, NULL, $primaryContactId, $isTest, TRUE);
808 //need to copy, since we are unsetting on the way.
809 $copyParticipantCountLines = $participantCount;
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
819 if ($participantNum = array_search('participant', $copyParticipantCountLines)) {
820 //if no participant found break.
821 if ($participantNum === NULL) {
824 //unset current particpant so we don't check them again
825 unset($copyParticipantCountLines[$participantNum]);
828 // get values of line items
829 if ($this->_amount
) {
831 $amount[$participantNum]['label'] = preg_replace('/\ 1/', '', $params[$participantNum]['amount_level']);
832 $amount[$participantNum]['amount'] = $params[$participantNum]['amount'];
833 $params[$participantNum]['amounts'] = $amount;
836 if (!empty($this->_lineItem
)) {
837 $lineItems = $this->_lineItem
;
839 if ($lineItemValue = CRM_Utils_Array
::value($participantNum, $lineItems)) {
840 $lineItem[] = $lineItemValue;
842 $params[$participantNum]['lineItem'] = $lineItem;
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];
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;
855 // call postprocess hook before leaving
856 $this->postProcessHook();
857 // this does not return
858 $payment->doPayment($primaryParticipant, 'event');
861 CRM_Core_Error
::fatal($paymentObjError);
866 //otherwise send mail Confirmation/Receipt
867 $primaryContactId = $this->get('primaryContactId');
869 //build an array of cId/pId of participants
870 $additionalIDs = CRM_Event_BAO_Event
::buildCustomProfile($registerByID,
871 NULL, $primaryContactId, $isTest,
874 //lets send mails to all with meaningful text, CRM-4320.
875 $this->assign('isOnWaitlist', $this->_allowWaitlist
);
876 $this->assign('isRequireApproval', $this->_requireApproval
);
878 //need to copy, since we are unsetting on the way.
879 $copyParticipantCount = $participantCount;
881 //lets carry all paticipant params w/ values.
882 foreach ($additionalIDs as $participantID => $contactId) {
883 $participantNum = NULL;
884 if ($participantID == $registerByID) {
888 if ($participantNum = array_search('participant', $copyParticipantCount)) {
889 unset($copyParticipantCount[$participantNum]);
892 if ($participantNum === NULL) {
896 //carry the participant submitted values.
897 $this->_values
['params'][$participantID] = $params[$participantNum];
900 foreach ($additionalIDs as $participantID => $contactId) {
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);
908 if (count($customProfile)) {
909 $this->assign('customProfile', $customProfile);
910 $this->set('customProfile', $customProfile);
912 $this->_values
['params']['additionalParticipant'] = FALSE;
915 //take the Additional participant number.
916 if ($participantNum = array_search('participant', $participantCount)) {
917 unset($participantCount[$participantNum]);
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
)) {
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);
929 if ($this->_lineItem
) {
930 $lineItems = $this->_lineItem
;
932 if ($lineItemValue = CRM_Utils_Array
::value($participantNum, $lineItems)) {
933 $lineItem[] = $lineItemValue;
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]));
943 $this->assign('lineItem', $lineItem);
945 $this->_values
['params']['additionalParticipant'] = TRUE;
946 $this->assign('isAdditionalParticipant', $this->_values
['params']['additionalParticipant']);
949 //pass these variables since these are run time calculated.
950 $this->_values
['params']['isOnWaitlist'] = $this->_allowWaitlist
;
951 $this->_values
['params']['isRequireApproval'] = $this->_requireApproval
;
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);
962 * Process the contribution.
964 * @param CRM_Core_Form $form
965 * @param array $params
967 * @param int $contactID
968 * @param bool $pending
969 * @param bool $isAdditionalAmount
973 public static function processContribution(
974 &$form, $params, $result, $contactID,
975 $pending = FALSE, $isAdditionalAmount = FALSE
977 $transaction = new CRM_Core_Transaction();
979 $now = date('YmdHis');
982 if (!empty($form->_values
['event']['is_email_confirm'])) {
986 if ($isAdditionalAmount) {
987 $params['amount_level'] = $params['amount_level'] . ts(' (multiple participants)') . CRM_Core_DAO
::VALUE_SEPARATOR
;
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),
1004 if (empty($params['is_pay_later'])) {
1005 $contribParams['payment_instrument_id'] = 1;
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,
1017 $allStatuses = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
1018 $contribParams['contribution_status_id'] = array_search('Completed', $allStatuses);
1020 $contribParams['contribution_status_id'] = array_search('Pending', $allStatuses);
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;
1029 if (!empty($contribParams['invoice_id'])) {
1030 $contribID = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_Contribution',
1031 $contribParams['invoice_id'],
1039 $ids['contribution'] = $contribID;
1040 $contribParams['id'] = $contribID;
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
);
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'])) {
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'],
1059 $contribSoftContactId = CRM_Utils_Array
::value('soft_credit_to', $params);
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;
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);
1071 CRM_Event_BAO_Participant
::createDiscountTrxn($form->_eventId
, $contribParams, CRM_Utils_Array
::value('amount_priceset_level_radio', $params, NULL));
1073 // process soft credit / pcp pages
1074 CRM_Contribute_Form_Contribution_Confirm
::processPcpSoft($params, $contribution);
1076 $transaction->commit();
1078 return $contribution;
1082 * Fix the Location Fields.
1084 * @param array $params
1086 * @param CRM_Core_Form $form
1090 public static function fixLocationFields(&$params, &$fields, &$form) {
1091 if (!empty($form->_fields
)) {
1092 foreach ($form->_fields
as $name => $dontCare) {
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) {
1102 if (array_key_exists("billing_$name", $params)) {
1103 $params[$name] = $params["billing_{$name}"];
1104 $params['preserveDBName'] = TRUE;
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;
1115 $fields["email-{$form->_bltID}"] = 1;
1116 $fields['email-Primary'] = 1;
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}"])
1125 $params['email-Primary'] = $params["email-{$form->_bltID}"];
1130 * Update contact fields.
1132 * @param int $contactID
1133 * @param array $params
1135 * @param CRM_Core_Form $form
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
1143 // get the add to groups
1144 $addToGroups = array();
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'];
1154 // check for profile double opt-in and get groups to be subscribed
1155 $subscribeGroupIds = CRM_Core_BAO_UFGroup
::getDoubleOptInGroupIds($params, $contactID);
1157 foreach ($addToGroups as $k) {
1158 if (array_key_exists($k, $subscribeGroupIds)) {
1159 unset($addToGroups[$k]);
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]);
1172 $ctype = CRM_Core_DAO
::getFieldValue(
1173 'CRM_Contact_DAO_Contact',
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
1183 unset($params['contact_id']);
1186 $contactID = CRM_Contact_BAO_Contact
::createProfileContact(
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);
1204 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params,
1212 $form->set('contactID', $contactID);
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);
1220 // subscribing contact to groups
1221 if (!empty($subscribeGroupIds) && $subscribtionEmail['email']) {
1222 CRM_Mailing_Event_BAO_Subscribe
::commonSubscribe($subscribeGroupIds, $subscribtionEmail, $contactID);
1231 public static function assignProfiles(&$form) {
1232 $participantParams = $form->_params
;
1233 $formattedValues = $profileFields = array();
1235 foreach ($participantParams as $participantNum => $participantValue) {
1236 if ($participantNum) {
1237 $prefix1 = 'additional';
1238 $prefix2 = 'additional_';
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'],
1255 if (count($values)) {
1256 $formattedValues[$count][$prefix1 . 'CustomPre'] = $values;
1258 $formattedValues[$count][$prefix1 . 'CustomPreGroupTitle'] = CRM_Utils_Array
::value('groupTitle', $groupName);
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) {
1265 CRM_Event_BAO_Event
::displayProfile($participantValue,
1271 $values[$gids] = $val;
1272 $groupName[$gids] = $group;
1275 if (count($values)) {
1276 $formattedValues[$count][$prefix1 . 'CustomPost'] = $values;
1279 if (isset($formattedValues[$count][$prefix1 . 'CustomPre'])) {
1280 $formattedValues[$count][$prefix1 . 'CustomPost'] = array_diff_assoc($formattedValues[$count][$prefix1 . 'CustomPost'],
1281 $formattedValues[$count][$prefix1 . 'CustomPre']
1285 $formattedValues[$count][$prefix1 . 'CustomPostGroupTitle'] = $groupName;
1289 $form->_fields
= $profileFields;
1291 if (!empty($formattedValues)) {
1292 $form->assign('primaryParticipantProfile', $formattedValues[1]);
1293 $form->set('primaryParticipantProfile', $formattedValues[1]);
1295 unset($formattedValues[1]);
1296 $form->assign('addParticipantProfile', $formattedValues);
1297 $form->set('addParticipantProfile', $formattedValues);