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 = 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'));
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 = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
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 ($this->_contributeMode
== 'express' && !empty($value['is_primary'])) {
601 if (is_object($payment)) {
602 $result = $payment->doExpressCheckout($value);
605 CRM_Core_Error
::fatal($paymentObjError);
608 elseif (!empty($value['is_primary'])) {
609 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $value, $value, TRUE);
610 // payment email param can be empty for _bltID mapping
611 // thus provide mapping for it with a different email value
612 if (empty($value['email'])) {
613 $value['email'] = CRM_Utils_Array
::valueByRegexKey('/^email-/', $value);
616 if (is_object($payment)) {
617 $result = $payment->doDirectPayment($value);
620 CRM_Core_Error
::fatal($paymentObjError);
624 if (is_a($result, 'CRM_Core_Error')) {
625 CRM_Core_Error
::displaySessionError($result);
626 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/event/register', "id={$this->_eventId}"));
630 $value = array_merge($value, $result);
633 $value['receive_date'] = $now;
634 if ($this->_allowConfirmation
) {
635 $value['participant_register_date'] = $this->_values
['participant']['register_date'];
638 $createContrib = ($value['amount'] != 0) ?
TRUE : FALSE;
639 // force to create zero amount contribution, CRM-5095
640 if (!$createContrib && ($value['amount'] == 0)
641 && $this->_priceSetId
&& $this->_lineItem
643 $createContrib = TRUE;
646 if ($createContrib && !empty($value['is_primary']) &&
647 !$this->_allowWaitlist
&& !$this->_requireApproval
649 // if paid event add a contribution record
650 //if primary participant contributing additional amount
651 //append (multiple participants) to its fee level. CRM-4196.
652 $isAdditionalAmount = FALSE;
653 if (count($params) > 1) {
654 $isAdditionalAmount = TRUE;
657 //passing contribution id is already registered.
658 $contribution = self
::processContribution($this, $value, $result, $contactID, $pending, $isAdditionalAmount);
659 $value['contributionID'] = $contribution->id
;
660 $value['contributionTypeID'] = $contribution->financial_type_id
;
661 $value['receive_date'] = $contribution->receive_date
;
662 $value['trxn_id'] = $contribution->trxn_id
;
663 $value['contributionID'] = $contribution->id
;
664 $value['contributionTypeID'] = $contribution->financial_type_id
;
666 $value['contactID'] = $contactID;
667 $value['eventID'] = $this->_eventId
;
668 $value['item_name'] = $value['description'];
671 if (!empty($value['contributionID'])) {
672 $this->_values
['contributionId'] = $value['contributionID'];
676 if (!empty($value['is_primary'])) {
677 $primaryCurrencyID = CRM_Utils_Array
::value('currencyID', $value);
679 if (empty($value['currencyID'])) {
680 $value['currencyID'] = $primaryCurrencyID;
683 // CRM-11182 - Confirmation page might not be monetary
684 if ($this->_values
['event']['is_monetary']) {
685 if (!$pending && !empty($value['is_primary']) &&
686 !$this->_allowWaitlist
&& !$this->_requireApproval
688 // transactionID & receive date required while building email template
689 $this->assign('trxn_id', $value['trxn_id']);
690 $this->assign('receive_date', CRM_Utils_Date
::mysqlToIso($value['receive_date']));
691 $this->set('receiveDate', CRM_Utils_Date
::mysqlToIso($value['receive_date']));
692 $this->set('trxnId', CRM_Utils_Array
::value('trxn_id', $value));
696 $value['fee_amount'] = CRM_Utils_Array
::value('amount', $value);
697 $this->set('value', $value);
699 // handle register date CRM-4320
700 if ($this->_allowConfirmation
) {
701 $registerDate = CRM_Utils_Array
::value('participant_register_date', $params);
703 elseif (!empty($params['participant_register_date']) &&
704 is_array($params['participant_register_date']) &&
705 !empty($params['participant_register_date'])
707 $registerDate = CRM_Utils_Date
::format($params['participant_register_date']);
710 $registerDate = date('YmdHis');
712 $this->assign('register_date', $registerDate);
714 $this->confirmPostProcess($contactID, $contribution, $payment);
717 //handle if no additional participant.
718 if (!$registerByID) {
719 $registerByID = $this->get('registerByID');
722 $this->set('participantIDs', $this->_participantIDS
);
724 // create line items, CRM-5313
725 if ($this->_priceSetId
&&
726 !empty($this->_lineItem
)
728 // take all processed participant ids.
729 $allParticipantIds = $this->_participantIDS
;
731 // when participant re-walk wizard.
732 if ($this->_allowConfirmation
&&
733 !empty($this->_additionalParticipantIds
)
735 $allParticipantIds = array_merge(array($registerByID), $this->_additionalParticipantIds
);
738 $entityTable = 'civicrm_participant';
739 $invoiceSettings = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
740 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
742 $dataArray = array();
743 foreach ($this->_lineItem
as $key => $value) {
744 if (($value != 'skip') &&
745 ($entityId = CRM_Utils_Array
::value($key, $allParticipantIds))
748 // do cleanup line items if participant re-walking wizard.
749 if ($this->_allowConfirmation
) {
750 CRM_Price_BAO_LineItem
::deleteLineItems($entityId, $entityTable);
752 $lineItem[$this->_priceSetId
] = $value;
753 CRM_Price_BAO_LineItem
::processPriceSet($entityId, $lineItem, $contribution, $entityTable);
756 foreach ($value as $line) {
757 if (isset($line['tax_amount']) && isset($line['tax_rate'])) {
758 $totalTaxAmount = $line['tax_amount'] +
$totalTaxAmount;
759 if (isset($dataArray[$line['tax_rate']])) {
760 $dataArray[$line['tax_rate']] = $dataArray[$line['tax_rate']] + CRM_Utils_Array
::value('tax_amount', $line);
763 $dataArray[$line['tax_rate']] = CRM_Utils_Array
::value('tax_amount', $line);
770 $this->assign('dataArray', $dataArray);
771 $this->assign('totalTaxAmount', $totalTaxAmount);
775 //update status and send mail to cancelled additional participants, CRM-4320
776 if ($this->_allowConfirmation
&& is_array($cancelledIds) && !empty($cancelledIds)) {
777 $cancelledId = array_search('Cancelled',
778 CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Negative'")
780 CRM_Event_BAO_Participant
::transitionParticipants($cancelledIds, $cancelledId);
784 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
788 // for Transfer checkout.
789 if (($this->_contributeMode
== 'checkout' ||
790 $this->_contributeMode
== 'notify'
791 ) && empty($params[0]['is_pay_later']) &&
792 !$this->_allowWaitlist
&& !$this->_requireApproval
&&
793 $this->_totalAmount
> 0
796 $primaryParticipant = $this->get('primaryParticipant');
798 if (empty($primaryParticipant['participantID'])) {
799 $primaryParticipant['participantID'] = $registerByID;
802 //build an array of custom profile and assigning it to template
803 $customProfile = CRM_Event_BAO_Event
::buildCustomProfile($registerByID, $this->_values
, NULL, $isTest);
804 if (count($customProfile)) {
805 $this->assign('customProfile', $customProfile);
806 $this->set('customProfile', $customProfile);
809 // do a transfer only if a monetary payment greater than 0
810 if ($this->_values
['event']['is_monetary'] && $primaryParticipant) {
811 if ($payment && is_object($payment)) {
812 //CRM 14512 provide line items of all participants to payment gateway
813 $primaryContactId = $this->get('primaryContactId');
815 //build an array of cId/pId of participants
816 $additionalIDs = CRM_Event_BAO_Event
::buildCustomProfile($registerByID, NULL, $primaryContactId, $isTest, TRUE);
818 //need to copy, since we are unsetting on the way.
819 $copyParticipantCountLines = $participantCount;
821 //lets carry all participant params w/ values.
822 foreach ($additionalIDs as $participantID => $contactId) {
823 $participantNum = NULL;
824 $participantNum = $participantID;
825 if ($participantID == $registerByID) {
826 $participantNum = 0; // is primary particpant
829 if ($participantNum = array_search('participant', $copyParticipantCountLines)) {
830 //if no participant found break.
831 if ($participantNum === NULL) {
834 //unset current particpant so we don't check them again
835 unset($copyParticipantCountLines[$participantNum]);
838 // get values of line items
839 if ($this->_amount
) {
841 $amount[$participantNum]['label'] = preg_replace('/\ 1/', '', $params[$participantNum]['amount_level']);
842 $amount[$participantNum]['amount'] = $params[$participantNum]['amount'];
843 $params[$participantNum]['amounts'] = $amount;
846 if (!empty($this->_lineItem
)) {
847 $lineItems = $this->_lineItem
;
849 if ($lineItemValue = CRM_Utils_Array
::value($participantNum, $lineItems)) {
850 $lineItem[] = $lineItemValue;
852 $params[$participantNum]['lineItem'] = $lineItem;
855 //only add additional particpants and not the primary particpant as we already have that
856 //added to $primaryParticipant so that this change doesn't break or require changes to
857 //existing gateway implementations
858 $primaryParticipant['participants_info'][$participantID] = $params[$participantNum];
861 //get event custom field information
862 $groupTree = CRM_Core_BAO_CustomGroup
::getTree('Event', $this, $this->_eventId
, 0, $this->_values
['event']['event_type_id']);
863 $primaryParticipant['eventCustomFields'] = $groupTree;
865 // call postprocess hook before leaving
866 $this->postProcessHook();
867 // this does not return
868 $payment->doTransferCheckout($primaryParticipant, 'event');
871 CRM_Core_Error
::fatal($paymentObjError);
876 //otherwise send mail Confirmation/Receipt
877 $primaryContactId = $this->get('primaryContactId');
879 //build an array of cId/pId of participants
880 $additionalIDs = CRM_Event_BAO_Event
::buildCustomProfile($registerByID,
881 NULL, $primaryContactId, $isTest,
884 //lets send mails to all with meaningful text, CRM-4320.
885 $this->assign('isOnWaitlist', $this->_allowWaitlist
);
886 $this->assign('isRequireApproval', $this->_requireApproval
);
888 //need to copy, since we are unsetting on the way.
889 $copyParticipantCount = $participantCount;
891 //lets carry all paticipant params w/ values.
892 foreach ($additionalIDs as $participantID => $contactId) {
893 $participantNum = NULL;
894 if ($participantID == $registerByID) {
898 if ($participantNum = array_search('participant', $copyParticipantCount)) {
899 unset($copyParticipantCount[$participantNum]);
902 if ($participantNum === NULL) {
906 //carry the participant submitted values.
907 $this->_values
['params'][$participantID] = $params[$participantNum];
910 foreach ($additionalIDs as $participantID => $contactId) {
912 if ($participantID == $registerByID) {
913 //set as Primary Participant
914 $this->assign('isPrimary', 1);
915 //build an array of custom profile and assigning it to template.
916 $customProfile = CRM_Event_BAO_Event
::buildCustomProfile($participantID, $this->_values
, NULL, $isTest);
918 if (count($customProfile)) {
919 $this->assign('customProfile', $customProfile);
920 $this->set('customProfile', $customProfile);
922 $this->_values
['params']['additionalParticipant'] = FALSE;
925 //take the Additional participant number.
926 if ($participantNum = array_search('participant', $participantCount)) {
927 unset($participantCount[$participantNum]);
929 $this->assign('isPrimary', 0);
930 $this->assign('customProfile', NULL);
931 //Additional Participant should get only it's payment information
932 if (!empty($this->_amount
)) {
934 $params = $this->get('params');
935 $amount[$participantNum]['label'] = preg_replace('/\ 1/', '', $params[$participantNum]['amount_level']);
936 $amount[$participantNum]['amount'] = $params[$participantNum]['amount'];
937 $this->assign('amounts', $amount);
939 if ($this->_lineItem
) {
940 $lineItems = $this->_lineItem
;
942 if ($lineItemValue = CRM_Utils_Array
::value($participantNum, $lineItems)) {
943 $lineItem[] = $lineItemValue;
946 $individual = $this->get('individual');
947 $dataArray[key($dataArray)] = $individual[$participantNum]['totalTaxAmt'];
948 $this->assign('dataArray', $dataArray);
949 $this->assign('totalAmount', $individual[$participantNum]['totalAmtWithTax']);
950 $this->assign('totalTaxAmount', $individual[$participantNum]['totalTaxAmt']);
951 $this->assign('individual', array($individual[$participantNum]));
953 $this->assign('lineItem', $lineItem);
955 $this->_values
['params']['additionalParticipant'] = TRUE;
956 $this->assign('isAdditionalParticipant', $this->_values
['params']['additionalParticipant']);
959 //pass these variables since these are run time calculated.
960 $this->_values
['params']['isOnWaitlist'] = $this->_allowWaitlist
;
961 $this->_values
['params']['isRequireApproval'] = $this->_requireApproval
;
963 //send mail to primary as well as additional participants.
964 $this->assign('contactID', $contactId);
965 $this->assign('participantID', $participantID);
966 CRM_Event_BAO_Event
::sendMail($contactId, $this->_values
, $participantID, $isTest);
972 * Process the contribution.
974 * @param CRM_Core_Form $form
975 * @param array $params
977 * @param int $contactID
978 * @param bool $pending
979 * @param bool $isAdditionalAmount
983 public static function processContribution(
984 &$form, $params, $result, $contactID,
985 $pending = FALSE, $isAdditionalAmount = FALSE
987 $transaction = new CRM_Core_Transaction();
989 $now = date('YmdHis');
992 if (!empty($form->_values
['event']['is_email_confirm'])) {
996 if ($isAdditionalAmount) {
997 $params['amount_level'] = $params['amount_level'] . ts(' (multiple participants)') . CRM_Core_DAO
::VALUE_SEPARATOR
;
1000 $contribParams = array(
1001 'contact_id' => $contactID,
1002 'financial_type_id' => !empty($form->_values
['event']['financial_type_id']) ?
$form->_values
['event']['financial_type_id'] : $params['financial_type_id'],
1003 'receive_date' => $now,
1004 'total_amount' => $params['amount'],
1005 'tax_amount' => $params['tax_amount'],
1006 'amount_level' => $params['amount_level'],
1007 'invoice_id' => $params['invoiceID'],
1008 'currency' => $params['currencyID'],
1009 'source' => !empty($params['participant_source']) ?
$params['participant_source'] : $params['description'],
1010 'is_pay_later' => CRM_Utils_Array
::value('is_pay_later', $params, 0),
1011 'campaign_id' => CRM_Utils_Array
::value('campaign_id', $params),
1014 if (empty($params['is_pay_later'])) {
1015 $contribParams['payment_instrument_id'] = 1;
1018 if (!$pending && $result) {
1019 $contribParams +
= array(
1020 'fee_amount' => CRM_Utils_Array
::value('fee_amount', $result),
1021 'net_amount' => CRM_Utils_Array
::value('net_amount', $result, $params['amount']),
1022 'trxn_id' => $result['trxn_id'],
1023 'receipt_date' => $receiptDate,
1027 $allStatuses = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
1028 $contribParams['contribution_status_id'] = array_search('Completed', $allStatuses);
1030 $contribParams['contribution_status_id'] = array_search('Pending', $allStatuses);
1033 $contribParams['is_test'] = 0;
1034 if ($form->_action
& CRM_Core_Action
::PREVIEW || CRM_Utils_Array
::value('mode', $params) == 'test') {
1035 $contribParams['is_test'] = 1;
1039 if (!empty($contribParams['invoice_id'])) {
1040 $contribID = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_Contribution',
1041 $contribParams['invoice_id'],
1049 $ids['contribution'] = $contribID;
1050 $contribParams['id'] = $contribID;
1053 //create an contribution address
1054 if ($form->_contributeMode
!= 'notify' && empty($params['is_pay_later'])) {
1055 $contribParams['address_id'] = CRM_Contribute_BAO_Contribution
::createAddress($params, $form->_bltID
);
1058 // Prepare soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
1059 if (!empty($params['pcp_made_through_id']) ||
!empty($params['soft_credit_to'])) {
1061 // if its due to pcp
1062 if (!empty($params['pcp_made_through_id'])) {
1063 $contribSoftContactId = CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP',
1064 $params['pcp_made_through_id'],
1069 $contribSoftContactId = CRM_Utils_Array
::value('soft_credit_to', $params);
1072 // Pass these details onto with the contribution to make them
1073 // available at hook_post_process, CRM-8908
1074 $contribParams['soft_credit_to'] = $params['soft_credit_to'] = $contribSoftContactId;
1076 $contribParams['payment_processor'] = CRM_Utils_Array
::value('payment_processor', $params);
1077 $contribParams['skipLineItem'] = 1;
1078 // create contribution record
1079 $contribution = CRM_Contribute_BAO_Contribution
::add($contribParams, $ids);
1081 CRM_Event_BAO_Participant
::createDiscountTrxn($form->_eventId
, $contribParams, CRM_Utils_Array
::value('amount_priceset_level_radio', $params, NULL));
1083 // process soft credit / pcp pages
1084 CRM_Contribute_Form_Contribution_Confirm
::processPcpSoft($params, $contribution);
1086 $transaction->commit();
1088 return $contribution;
1092 * Fix the Location Fields.
1094 * @param array $params
1096 * @param CRM_Core_Form $form
1100 public static function fixLocationFields(&$params, &$fields, &$form) {
1101 if (!empty($form->_fields
)) {
1102 foreach ($form->_fields
as $name => $dontCare) {
1107 if (is_array($fields)) {
1108 if (!array_key_exists('first_name', $fields)) {
1109 $nameFields = array('first_name', 'middle_name', 'last_name');
1110 foreach ($nameFields as $name) {
1112 if (array_key_exists("billing_$name", $params)) {
1113 $params[$name] = $params["billing_{$name}"];
1114 $params['preserveDBName'] = TRUE;
1120 // also add location name to the array
1121 if ($form->_values
['event']['is_monetary']) {
1122 $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);
1123 $fields["address_name-{$form->_bltID}"] = 1;
1125 $fields["email-{$form->_bltID}"] = 1;
1126 $fields['email-Primary'] = 1;
1128 //if its pay later or additional participant set email address as primary.
1129 if ((!empty($params['is_pay_later']) ||
empty($params['is_primary']) ||
1130 !$form->_values
['event']['is_monetary'] ||
1131 $form->_allowWaitlist ||
1132 $form->_requireApproval
1133 ) && !empty($params["email-{$form->_bltID}"])
1135 $params['email-Primary'] = $params["email-{$form->_bltID}"];
1140 * Update contact fields.
1142 * @param int $contactID
1143 * @param array $params
1145 * @param CRM_Core_Form $form
1149 public static function updateContactFields($contactID, $params, $fields, &$form) {
1150 //add the contact to group, if add to group is selected for a
1151 //particular uf group
1153 // get the add to groups
1154 $addToGroups = array();
1156 if (!empty($form->_fields
)) {
1157 foreach ($form->_fields
as $key => $value) {
1158 if (!empty($value['add_to_group_id'])) {
1159 $addToGroups[$value['add_to_group_id']] = $value['add_to_group_id'];
1164 // check for profile double opt-in and get groups to be subscribed
1165 $subscribeGroupIds = CRM_Core_BAO_UFGroup
::getDoubleOptInGroupIds($params, $contactID);
1167 foreach ($addToGroups as $k) {
1168 if (array_key_exists($k, $subscribeGroupIds)) {
1169 unset($addToGroups[$k]);
1173 // since we are directly adding contact to group lets unset it from mailing
1174 if (!empty($addToGroups)) {
1175 foreach ($addToGroups as $groupId) {
1176 if (isset($subscribeGroupIds[$groupId])) {
1177 unset($subscribeGroupIds[$groupId]);
1182 $ctype = CRM_Core_DAO
::getFieldValue(
1183 'CRM_Contact_DAO_Contact',
1188 if (array_key_exists('contact_id', $params) && empty($params['contact_id'])) {
1189 // we unset this here because the downstream function ignores the contactID we give it
1190 // if it is set & it is difficult to understand the implications of 'fixing' this downstream
1191 // but if we are passing a contact id into this function it's reasonable to assume we don't
1193 unset($params['contact_id']);
1196 $contactID = CRM_Contact_BAO_Contact
::createProfileContact(
1208 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
1209 if (!isset($params[$greeting . '_id'])) {
1210 $params[$greeting . '_id'] = CRM_Contact_BAO_Contact_Utils
::defaultGreeting('Individual', $greeting);
1214 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params,
1222 $form->set('contactID', $contactID);
1225 //get email primary first if exist
1226 $subscribtionEmail = array('email' => CRM_Utils_Array
::value('email-Primary', $params));
1227 if (!$subscribtionEmail['email']) {
1228 $subscribtionEmail['email'] = CRM_Utils_Array
::value("email-{$form->_bltID}", $params);
1230 // subscribing contact to groups
1231 if (!empty($subscribeGroupIds) && $subscribtionEmail['email']) {
1232 CRM_Mailing_Event_BAO_Subscribe
::commonSubscribe($subscribeGroupIds, $subscribtionEmail, $contactID);
1241 public static function assignProfiles(&$form) {
1242 $participantParams = $form->_params
;
1243 $formattedValues = $profileFields = array();
1245 foreach ($participantParams as $participantNum => $participantValue) {
1246 if ($participantNum) {
1247 $prefix1 = 'additional';
1248 $prefix2 = 'additional_';
1254 if ($participantValue != 'skip') {
1255 //get the customPre profile info
1256 if (!empty($form->_values
[$prefix2 . 'custom_pre_id'])) {
1257 $values = $groupName = array();
1258 CRM_Event_BAO_Event
::displayProfile($participantValue,
1259 $form->_values
[$prefix2 . 'custom_pre_id'],
1265 if (count($values)) {
1266 $formattedValues[$count][$prefix1 . 'CustomPre'] = $values;
1268 $formattedValues[$count][$prefix1 . 'CustomPreGroupTitle'] = CRM_Utils_Array
::value('groupTitle', $groupName);
1270 //get the customPost profile info
1271 if (!empty($form->_values
[$prefix2 . 'custom_post_id'])) {
1272 $values = $groupName = array();
1273 foreach ($form->_values
[$prefix2 . 'custom_post_id'] as $gids) {
1275 CRM_Event_BAO_Event
::displayProfile($participantValue,
1281 $values[$gids] = $val;
1282 $groupName[$gids] = $group;
1285 if (count($values)) {
1286 $formattedValues[$count][$prefix1 . 'CustomPost'] = $values;
1289 if (isset($formattedValues[$count][$prefix1 . 'CustomPre'])) {
1290 $formattedValues[$count][$prefix1 . 'CustomPost'] = array_diff_assoc($formattedValues[$count][$prefix1 . 'CustomPost'],
1291 $formattedValues[$count][$prefix1 . 'CustomPre']
1295 $formattedValues[$count][$prefix1 . 'CustomPostGroupTitle'] = $groupName;
1299 $form->_fields
= $profileFields;
1301 if (!empty($formattedValues)) {
1302 $form->assign('primaryParticipantProfile', $formattedValues[1]);
1303 $form->set('primaryParticipantProfile', $formattedValues[1]);
1305 unset($formattedValues[1]);
1306 $form->assign('addParticipantProfile', $formattedValues);
1307 $form->set('addParticipantProfile', $formattedValues);