3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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
60 * Function to set variables up before form is built
65 function preProcess() {
68 // lineItem isn't set until Register postProcess
69 $this->_lineItem
= $this->get('lineItem');
71 $this->_params
= $this->get('params');
73 $this->_params
[0]['is_pay_later'] = $this->get('is_pay_later');
74 $this->assign('is_pay_later', $this->_params
[0]['is_pay_later']);
75 if ($this->_params
[0]['is_pay_later']) {
76 $this->assign('pay_later_receipt', $this->_values
['event']['pay_later_receipt']);
79 CRM_Utils_Hook
::eventDiscount($this, $this->_params
);
81 if (!empty($this->_params
[0]['discount']) && !empty($this->_params
[0]['discount']['applied'])) {
82 $this->set('hookDiscount', $this->_params
[0]['discount']);
83 $this->assign('hookDiscount', $this->_params
[0]['discount']);
86 if ($this->_contributeMode
== 'express') {
88 // rfp == redirect from paypal
89 $rfp = CRM_Utils_Request
::retrieve('rfp', 'Boolean',
90 CRM_Core_DAO
::$_nullObject, FALSE, NULL, 'GET'
93 //we lost rfp in case of additional participant. So set it explicitly.
94 if ($rfp || CRM_Utils_Array
::value('additional_participants', $this->_params
[0], FALSE)) {
95 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
96 $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.');
97 if (is_object($payment))
98 $expressParams = $payment->getExpressCheckoutDetails($this->get('token'));
100 CRM_Core_Error
::fatal($paymentObjError);
102 $params['payer'] = $expressParams['payer'];
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 $params['amount_level'] = $this->_params
[0]['amount_level'];
125 $params['currencyID'] = $this->_params
[0]['currencyID'];
126 $params['payment_action'] = 'Sale';
128 // also merge all the other values from the profile fields
129 $values = $this->controller
->exportValues('Register');
132 "street_address-{$this->_bltID}",
133 "city-{$this->_bltID}",
134 "state_province_id-{$this->_bltID}",
135 "postal_code-{$this->_bltID}",
136 "country_id-{$this->_bltID}",
139 foreach ($values as $name => $value) {
141 if (!in_array($name, $skipFields)) {
142 $params[$name] = $value;
145 $this->set('getExpressCheckoutDetails', $params);
148 $params = $this->get('getExpressCheckoutDetails');
150 $this->_params
[0] = $params;
151 $this->_params
[0]['is_primary'] = 1;
154 //process only primary participant params.
155 $registerParams = $this->_params
[0];
156 if (isset($registerParams["billing_state_province_id-{$this->_bltID}"])
157 && $registerParams["billing_state_province_id-{$this->_bltID}"]
159 $registerParams["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($registerParams["billing_state_province_id-{$this->_bltID}"]);
162 if (isset($registerParams["billing_country_id-{$this->_bltID}"]) && $registerParams["billing_country_id-{$this->_bltID}"]) {
163 $registerParams["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($registerParams["billing_country_id-{$this->_bltID}"]);
165 if (isset($registerParams['credit_card_exp_date'])) {
166 $registerParams['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($registerParams);
167 $registerParams['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($registerParams);
169 if ($this->_values
['event']['is_monetary']) {
170 $registerParams['ip_address'] = CRM_Utils_System
::ipAddress();
171 $registerParams['currencyID'] = $this->_params
[0]['currencyID'];
172 $registerParams['payment_action'] = 'Sale';
174 //assign back primary participant params.
175 $this->_params
[0] = $registerParams;
178 if ($this->_values
['event']['is_monetary']) {
179 $this->_params
[0]['invoiceID'] = $this->get('invoiceID');
181 $this->assign('defaultRole', FALSE);
182 if (CRM_Utils_Array
::value('defaultRole', $this->_params
[0]) == 1) {
183 $this->assign('defaultRole', TRUE);
186 if (empty($this->_params
[0]['participant_role_id']) &&
187 $this->_values
['event']['default_role_id']
189 $this->_params
[0]['participant_role_id'] = $this->_values
['event']['default_role_id'];
192 if (isset($this->_values
['event']['confirm_title'])) {
193 CRM_Utils_System
::setTitle($this->_values
['event']['confirm_title']);
197 $params = CRM_Contribute_Form_Contribution_Confirm
::processPcp($this, $this->_params
[0]);
198 $this->_params
[0] = $params;
201 $this->set('params', $this->_params
);
205 * overwrite action, since we are only showing elements in frozen mode
206 * no help display needed
211 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 * Function to build the form
226 public function buildQuickForm() {
227 $this->assignToTemplate();
229 if ($this->_values
['event']['is_monetary'] &&
230 ($this->_params
[0]['amount'] ||
$this->_params
[0]['amount'] == 0)
232 $this->_amount
= array();
234 foreach ($this->_params
as $k => $v) {
237 'first_name', 'last_name') as $name) {
238 if (isset($v['billing_' . $name]) &&
241 $v[$name] = $v['billing_' . $name];
245 if (!empty($v['first_name']) && !empty($v['last_name'])) {
246 $append = $v['first_name'] . ' ' . $v['last_name'];
249 //use an email if we have one
250 foreach ($v as $v_key => $v_val) {
251 if (substr($v_key, 0, 6) == 'email-') {
252 $append = $v[$v_key];
257 $this->_amount
[$k]['amount'] = $v['amount'];
258 if (!empty($v['discountAmount'])) {
259 $this->_amount
[$k]['amount'] -= $v['discountAmount'];
262 $this->_amount
[$k]['label'] = preg_replace('/\ 1/', '', $v['amount_level']) . ' - ' . $append;
263 $this->_part
[$k]['info'] = CRM_Utils_Array
::value('first_name', $v) . ' ' . CRM_Utils_Array
::value('last_name', $v);
264 if (empty($v['first_name'])) {
265 $this->_part
[$k]['info'] = $append;
267 $this->_totalAmount
= $this->_totalAmount +
$this->_amount
[$k]['amount'];
268 if (!empty($v['is_primary'])) {
269 $this->set('primaryParticipantAmount', $this->_amount
[$k]['amount']);
274 $this->assign('part', $this->_part
);
275 $this->set('part', $this->_part
);
276 $this->assign('amounts', $this->_amount
);
277 $this->assign('totalAmount', $this->_totalAmount
);
278 $this->set('totalAmount', $this->_totalAmount
);
281 if ($this->_priceSetId
&& !CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
282 $lineItemForTemplate = array();
283 foreach ($this->_lineItem
as $key => $value) {
284 if (!empty($value)) {
285 $lineItemForTemplate[$key] = $value;
288 if (!empty($lineItemForTemplate)) {
289 $this->assign('lineItem', $lineItemForTemplate);
293 //display additional participants profile.
294 self
::assignProfiles($this);
296 //consider total amount.
297 $this->assign('isAmountzero', ($this->_totalAmount
<= 0) ?
TRUE : FALSE);
299 if ($this->_paymentProcessor
['payment_processor_type'] == 'Google_Checkout' && empty($this->_params
[0]['is_pay_later']) && !($this->_params
[0]['amount'] == 0) &&
300 !$this->_allowWaitlist
&& !$this->_requireApproval
302 $this->_checkoutButtonName
= $this->getButtonName('next', 'checkout');
304 $this->_checkoutButtonName
,
305 $this->_paymentProcessor
['url_button'],
306 array('class' => 'form-submit')
309 $this->addButtons(array(
312 'name' => ts('<< Go Back'),
318 $contribButton = ts('Continue >>');
319 $this->addButtons(array(
322 'name' => ts('<< Go Back'),
326 'name' => $contribButton,
328 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name
. "','" . ts('Processing') . "');"),
336 if (!empty($this->_fields
)) {
337 foreach ($this->_fields
as $name => $dontCare) {
341 $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
342 foreach ($fields as $name => $dontCare) {
343 if (isset($this->_params
[0][$name])) {
344 $defaults[$name] = $this->_params
[0][$name];
345 if (substr($name, 0, 7) == 'custom_') {
346 $timeField = "{$name}_time";
347 if (isset($this->_params
[0][$timeField])) {
348 $defaults[$timeField] = $this->_params
[0][$timeField];
350 if (isset($this->_params
[0]["{$name}_id"])) {
351 $defaults["{$name}_id"] = $this->_params
[0]["{$name}_id"];
354 elseif (in_array($name, CRM_Contact_BAO_Contact
::$_greetingTypes)
355 && !empty($this->_params
[0][$name . '_custom'])
357 $defaults[$name . '_custom'] = $this->_params
[0][$name . '_custom'];
362 // now fix all state country selectors
363 CRM_Core_BAO_Address
::fixAllStateSelects($this, $defaults);
365 $this->setDefaults($defaults);
368 //lets give meaningful status message, CRM-4320.
369 $this->assign('isOnWaitlist', $this->_allowWaitlist
);
370 $this->assign('isRequireApproval', $this->_requireApproval
);
372 // Assign Participant Count to Lineitem Table
373 $this->assign('pricesetFieldsCount', CRM_Price_BAO_PriceSet
::getPricesetCount($this->_priceSetId
));
377 * Function to process the form
383 public function postProcess() {
384 $now = date('YmdHis');
386 $this->_params
= $this->get('params');
387 if (!empty($this->_params
[0]['contact_id'])) {
388 // unclear when this would be set & whether it could be checked in getContactID.
389 // perhaps it relates to when cid is in the url
390 //@todo someone who knows add comments on the various contactIDs in this form
391 $contactID = $this->_params
[0]['contact_id'];
394 $contactID = $this->getContactID();
397 // if a discount has been applied, lets now deduct it from the amount
398 // and fix the fee level
399 if (!empty($this->_params
[0]['discount']) && !empty($this->_params
[0]['discount']['applied'])) {
400 foreach ($this->_params
as $k => $v) {
401 if (CRM_Utils_Array
::value('amount', $this->_params
[$k]) > 0 && !empty($this->_params
[$k]['discountAmount'])) {
402 $this->_params
[$k]['amount'] -= $this->_params
[$k]['discountAmount'];
403 $this->_params
[$k]['amount_level'] .= CRM_Utils_Array
::value('discountMessage', $this->_params
[$k]);
406 $this->set('params', $this->_params
);
409 // CRM-4320, lets build array of cancelled additional participant ids
410 // those are drop or skip by primary at the time of confirmation.
411 // get all in and then unset those we want to process.
412 $cancelledIds = $this->_additionalParticipantIds
;
414 $params = $this->_params
;
415 if ($this->_values
['event']['is_monetary']) {
416 $this->set('finalAmount', $this->_amount
);
418 $participantCount = array();
420 //unset the skip participant from params.
421 //build the $participantCount array.
422 //maintain record for all participants.
423 foreach ($params as $participantNum => $record) {
424 if ($record == 'skip') {
425 unset($params[$participantNum]);
426 $participantCount[$participantNum] = 'skip';
428 elseif ($participantNum) {
429 $participantCount[$participantNum] = 'participant';
432 //lets get additional participant id to cancel.
433 if ($this->_allowConfirmation
&& is_array($cancelledIds)) {
434 $additonalId = CRM_Utils_Array
::value('participant_id', $record);
435 if ($additonalId && $key = array_search($additonalId, $cancelledIds)) {
436 unset($cancelledIds[$key]);
441 $payment = $registerByID = $primaryCurrencyID = $contribution = NULL;
442 $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.');
444 $this->participantIDS
= array();
446 foreach ($params as $key => $value) {
447 CRM_Event_Form_Registration_Confirm
::fixLocationFields($value, $fields, $this);
448 //unset the billing parameters if it is pay later mode
449 //to avoid creation of billing location
450 if ($this->_allowWaitlist ||
$this->_requireApproval ||
!empty($value['is_pay_later']) ||
empty($value['is_primary'])) {
451 $billingFields = array(
452 "email-{$this->_bltID}",
453 'billing_first_name',
454 'billing_middle_name',
456 "billing_street_address-{$this->_bltID}",
457 "billing_city-{$this->_bltID}",
458 "billing_state_province-{$this->_bltID}",
459 "billing_state_province_id-{$this->_bltID}",
460 "billing_postal_code-{$this->_bltID}",
461 "billing_country-{$this->_bltID}",
462 "billing_country_id-{$this->_bltID}",
463 "address_name-{$this->_bltID}",
465 foreach ($billingFields as $field) {
466 unset($value[$field]);
468 if (!empty($value['is_pay_later'])) {
469 $this->_values
['params']['is_pay_later'] = TRUE;
473 //Unset ContactID for additional participants and set RegisterBy Id.
474 if (empty($value['is_primary'])) {
475 $contactID = CRM_Utils_Array
::value('contact_id', $value);
476 $registerByID = $this->get('registerByID');
478 $value['registered_by_id'] = $registerByID;
482 $value['amount'] = $this->_totalAmount
;
485 $contactID = CRM_Event_Form_Registration_Confirm
::updateContactFields($contactID, $value, $fields, $this);
487 // lets store the contactID in the session
488 // we dont store in userID in case the user is doing multiple
490 // for things like tell a friend
491 if (!$this->getContactID() && !empty($value['is_primary'])) {
492 $session = CRM_Core_Session
::singleton();
493 $session->set('transaction.userID', $contactID);
496 $value['description'] = ts('Online Event Registration') . ': ' . $this->_values
['event']['title'];
497 $value['accountingCode'] = CRM_Utils_Array
::value('accountingCode',
498 $this->_values
['event']
501 // required only if paid event
502 if ($this->_values
['event']['is_monetary']) {
503 if (is_array($this->_paymentProcessor
)) {
504 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
509 if ($this->_allowWaitlist ||
$this->_requireApproval
) {
510 //get the participant statuses.
511 $waitingStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
512 if ($this->_allowWaitlist
) {
513 $value['participant_status_id'] = $value['participant_status'] = array_search('On waitlist', $waitingStatuses);
516 $value['participant_status_id'] = $value['participant_status'] = array_search('Awaiting approval', $waitingStatuses);
519 //there might be case user seleted pay later and
520 //now becomes part of run time waiting list.
521 $value['is_pay_later'] = FALSE;
523 elseif (!empty($value['is_pay_later']) ||
524 $value['amount'] == 0 ||
525 $this->_contributeMode
== 'checkout' ||
526 $this->_contributeMode
== 'notify'
528 if ($value['amount'] != 0) {
530 //get the participant statuses.
531 $pendingStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Pending'");
532 $status = !empty($value['is_pay_later']) ?
'Pending from pay later' : 'Pending from incomplete transaction';
533 $value['participant_status_id'] = $value['participant_status'] = array_search($status, $pendingStatuses);
536 elseif ($this->_contributeMode
== 'express' && !empty($value['is_primary'])) {
537 if (is_object($payment))
538 $result = $payment->doExpressCheckout($value);
540 CRM_Core_Error
::fatal($paymentObjError);
542 elseif (!empty($value['is_primary'])) {
543 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $value, $value, TRUE);
544 // payment email param can be empty for _bltID mapping
545 // thus provide mapping for it with a different email value
546 if (empty($value['email'])) {
547 $value['email'] = CRM_Utils_Array
::valueByRegexKey('/^email-/', $value);
550 if (is_object($payment)) {
551 $result = $payment->doDirectPayment($value);
554 CRM_Core_Error
::fatal($paymentObjError);
558 if (is_a($result, 'CRM_Core_Error')) {
559 CRM_Core_Error
::displaySessionError($result);
560 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/event/register', "id={$this->_eventId}"));
564 $value = array_merge($value, $result);
567 $value['receive_date'] = $now;
568 if ($this->_allowConfirmation
) {
569 $value['participant_register_date'] = $this->_values
['participant']['register_date'];
572 $createContrib = ($value['amount'] != 0) ?
TRUE : FALSE;
573 // force to create zero amount contribution, CRM-5095
574 if (!$createContrib && ($value['amount'] == 0)
575 && $this->_priceSetId
&& $this->_lineItem
577 $createContrib = TRUE;
580 if ($createContrib && !empty($value['is_primary']) &&
581 !$this->_allowWaitlist
&& !$this->_requireApproval
583 // if paid event add a contribution record
584 //if primary participant contributing additional amount
585 //append (multiple participants) to its fee level. CRM-4196.
586 $isAdditionalAmount = FALSE;
587 if (count($params) > 1) {
588 $isAdditionalAmount = TRUE;
591 //passing contribution id is already registered.
593 self
::processContribution($this, $value, $result, $contactID, $pending, $isAdditionalAmount);
594 $value['contributionID'] = $contribution->id
;
595 $value['contributionTypeID'] = $contribution->financial_type_id
;
596 $value['receive_date'] = $contribution->receive_date
;
597 $value['trxn_id'] = $contribution->trxn_id
;
598 $value['contributionID'] = $contribution->id
;
599 $value['contributionTypeID'] = $contribution->financial_type_id
;
601 $value['contactID'] = $contactID;
602 $value['eventID'] = $this->_eventId
;
603 $value['item_name'] = $value['description'];
607 if (!empty($value['is_primary'])) {
608 $primaryCurrencyID = CRM_Utils_Array
::value('currencyID', $value);
610 if (empty($value['currencyID'])) {
611 $value['currencyID'] = $primaryCurrencyID;
614 // CRM-11182 - Confirmation page might not be monetary
615 if ($this->_values
['event']['is_monetary']) {
616 if (!$pending && !empty($value['is_primary']) &&
617 !$this->_allowWaitlist
&& !$this->_requireApproval
619 // transactionID & receive date required while building email template
620 $this->assign('trxn_id', $value['trxn_id']);
621 $this->assign('receive_date', CRM_Utils_Date
::mysqlToIso($value['receive_date']));
622 $this->set('receiveDate', CRM_Utils_Date
::mysqlToIso($value['receive_date']));
623 $this->set('trxnId', CRM_Utils_Array
::value('trxn_id', $value));
627 $value['fee_amount'] = CRM_Utils_Array
::value('amount', $value);
628 $this->set('value', $value);
630 // handle register date CRM-4320
631 if ($this->_allowConfirmation
) {
632 $registerDate = CRM_Utils_Array
::value( 'participant_register_date', $params );
634 elseif (!empty($params['participant_register_date']) &&
635 is_array($params['participant_register_date']) &&
636 !empty($params['participant_register_date'])
638 $registerDate = CRM_Utils_Date
::format($params['participant_register_date']);
641 $registerDate = date('YmdHis');
643 $this->assign('register_date', $registerDate);
645 $this->confirmPostProcess($contactID, $contribution, $payment);
648 //handle if no additional participant.
649 if (!$registerByID) {
650 $registerByID = $this->get('registerByID');
653 $this->set('participantIDs', $this->_participantIDS
);
655 // create line items, CRM-5313
656 if ($this->_priceSetId
&&
657 !empty($this->_lineItem
)
659 // take all processed participant ids.
660 $allParticipantIds = $this->_participantIDS
;
662 // when participant re-walk wizard.
663 if ($this->_allowConfirmation
&&
664 !empty($this->_additionalParticipantIds
)
666 $allParticipantIds = array_merge(array($registerByID), $this->_additionalParticipantIds
);
669 $entityTable = 'civicrm_participant';
670 foreach ($this->_lineItem
as $key => $value) {
671 if (($value != 'skip') &&
672 ($entityId = CRM_Utils_Array
::value($key, $allParticipantIds))
675 // do cleanup line items if participant re-walking wizard.
676 if ($this->_allowConfirmation
) {
677 CRM_Price_BAO_LineItem
::deleteLineItems($entityId, $entityTable);
679 $lineItem[$this->_priceSetId
] = $value;
680 CRM_Price_BAO_LineItem
::processPriceSet($entityId, $lineItem, $contribution, $entityTable);
685 //update status and send mail to cancelled additonal participants, CRM-4320
686 if ($this->_allowConfirmation
&& is_array($cancelledIds) && !empty($cancelledIds)) {
687 $cancelledId = array_search('Cancelled',
688 CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Negative'")
690 CRM_Event_BAO_Participant
::transitionParticipants($cancelledIds, $cancelledId);
694 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
698 // for Transfer checkout.
699 if (($this->_contributeMode
== 'checkout' ||
700 $this->_contributeMode
== 'notify'
701 ) && empty($params[0]['is_pay_later']) &&
702 !$this->_allowWaitlist
&& !$this->_requireApproval
&&
703 $this->_totalAmount
> 0
706 $primaryParticipant = $this->get('primaryParticipant');
708 if (empty($primaryParticipant['participantID'])) {
709 $primaryParticipant['participantID'] = $registerByID;
712 //build an array of custom profile and assigning it to template
713 $customProfile = CRM_Event_BAO_Event
::buildCustomProfile($registerByID, $this->_values
, NULL, $isTest);
714 if (count($customProfile)) {
715 $this->assign('customProfile', $customProfile);
716 $this->set('customProfile', $customProfile);
719 // do a transfer only if a monetary payment greater than 0
720 if ($this->_values
['event']['is_monetary'] && $primaryParticipant) {
721 if ($payment && is_object($payment)) {
722 // call postprocess hook before leaving
723 $this->postProcessHook();
724 // this does not return
725 $payment->doTransferCheckout($primaryParticipant, 'event');
728 CRM_Core_Error
::fatal($paymentObjError);
733 //otherwise send mail Confirmation/Receipt
734 $primaryContactId = $this->get('primaryContactId');
736 //build an array of cId/pId of participants
737 $additionalIDs = CRM_Event_BAO_Event
::buildCustomProfile($registerByID,
738 NULL, $primaryContactId, $isTest,
741 //lets send mails to all with meaningful text, CRM-4320.
742 $this->assign('isOnWaitlist', $this->_allowWaitlist
);
743 $this->assign('isRequireApproval', $this->_requireApproval
);
745 //need to copy, since we are unsetting on the way.
746 $copyParticipantCount = $participantCount;
748 //lets carry all paticipant params w/ values.
749 foreach ($additionalIDs as $participantID => $contactId) {
750 $participantNum = NULL;
751 if ($participantID == $registerByID) {
755 if ($participantNum = array_search('participant', $copyParticipantCount)) {
756 unset($copyParticipantCount[$participantNum]);
759 if ($participantNum === NULL)
762 //carry the participant submitted values.
763 $this->_values
['params'][$participantID] = $params[$participantNum];
766 foreach ($additionalIDs as $participantID => $contactId) {
768 if ($participantID == $registerByID) {
769 //set as Primary Participant
770 $this->assign('isPrimary', 1);
771 //build an array of custom profile and assigning it to template.
772 $customProfile = CRM_Event_BAO_Event
::buildCustomProfile($participantID, $this->_values
, NULL, $isTest);
774 if (count($customProfile)) {
775 $this->assign('customProfile', $customProfile);
776 $this->set('customProfile', $customProfile);
778 $this->_values
['params']['additionalParticipant'] = FALSE;
781 //take the Additional participant number.
782 if ($participantNum = array_search('participant', $participantCount)) {
783 unset($participantCount[$participantNum]);
785 $this->assign('isPrimary', 0);
786 $this->assign('customProfile', NULL);
787 //Additional Participant should get only it's payment information
788 if (!empty($this->_amount
)) {
790 $params = $this->get('params');
791 $amount[$participantNum]['label'] = preg_replace('/\ 1/', '', $params[$participantNum]['amount_level']);
792 $amount[$participantNum]['amount'] = $params[$participantNum]['amount'];
793 $this->assign('amounts', $amount);
795 if ($this->_lineItem
) {
796 $lineItems = $this->_lineItem
;
798 if ($lineItemValue = CRM_Utils_Array
::value($participantNum, $lineItems)) {
799 $lineItem[] = $lineItemValue;
801 $this->assign('lineItem', $lineItem);
803 $this->_values
['params']['additionalParticipant'] = TRUE;
804 $this->assign('isAdditionalParticipant', $this->_values
['params']['additionalParticipant']);
807 //pass these variables since these are run time calculated.
808 $this->_values
['params']['isOnWaitlist'] = $this->_allowWaitlist
;
809 $this->_values
['params']['isRequireApproval'] = $this->_requireApproval
;
811 //send mail to primary as well as additional participants.
812 $this->assign('contactID', $contactId);
813 $this->assign('participantID', $participantID);
814 CRM_Event_BAO_Event
::sendMail($contactId, $this->_values
, $participantID, $isTest);
821 * Process the contribution
827 * @param bool $pending
828 * @param bool $isAdditionalAmount
833 static function processContribution(&$form, $params, $result, $contactID,
834 $pending = FALSE, $isAdditionalAmount = FALSE
836 $transaction = new CRM_Core_Transaction();
838 $now = date('YmdHis');
841 if ($form->_values
['event']['is_email_confirm']) {
845 if ($isAdditionalAmount) {
846 $params['amount_level'] = $params['amount_level'] . ts(' (multiple participants)') . CRM_Core_DAO
::VALUE_SEPARATOR
;
849 $contribParams = array(
850 'contact_id' => $contactID,
851 'financial_type_id' => $form->_values
['event']['financial_type_id'] ?
852 $form->_values
['event']['financial_type_id'] : $params['financial_type_id'],
853 'receive_date' => $now,
854 'total_amount' => $params['amount'],
855 'amount_level' => $params['amount_level'],
856 'invoice_id' => $params['invoiceID'],
857 'currency' => $params['currencyID'],
858 'source' => $params['description'],
859 'is_pay_later' => CRM_Utils_Array
::value('is_pay_later', $params, 0),
860 'campaign_id' => CRM_Utils_Array
::value('campaign_id', $params),
863 if (empty($params['is_pay_later'])) {
864 $contribParams['payment_instrument_id'] = 1;
867 if (!$pending && $result) {
868 $contribParams +
= array(
869 'fee_amount' => CRM_Utils_Array
::value('fee_amount', $result),
870 'net_amount' => CRM_Utils_Array
::value('net_amount', $result, $params['amount']),
871 'trxn_id' => $result['trxn_id'],
872 'receipt_date' => $receiptDate,
876 $allStatuses = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
877 $contribParams['contribution_status_id'] = array_search('Completed', $allStatuses);
879 $contribParams['contribution_status_id'] = array_search('Pending', $allStatuses);
882 $contribParams['is_test'] = 0;
883 if ($form->_action
& CRM_Core_Action
::PREVIEW || CRM_Utils_Array
::value('mode', $params) == 'test') {
884 $contribParams['is_test'] = 1;
888 if (!empty($contribParams['invoice_id'])) {
889 $contribID = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_Contribution',
890 $contribParams['invoice_id'],
898 $ids['contribution'] = $contribID;
899 $contribParams['id'] = $contribID;
902 //create an contribution address
903 if ($form->_contributeMode
!= 'notify' && empty($params['is_pay_later'])) {
904 $contribParams['address_id'] = CRM_Contribute_BAO_Contribution
::createAddress($params, $form->_bltID
);
907 // Prepare soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
908 if (!empty($params['pcp_made_through_id']) ||
!empty($params['soft_credit_to'])) {
911 if (!empty($params['pcp_made_through_id'])) {
912 $contribSoftContactId = CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP',
913 $params['pcp_made_through_id'],
918 $contribSoftContactId = CRM_Utils_Array
::value('soft_credit_to', $params);
921 // Pass these details onto with the contribution to make them
922 // available at hook_post_process, CRM-8908
923 $contribParams['soft_credit_to'] = $params['soft_credit_to'] = $contribSoftContactId;
925 $contribParams['payment_processor'] = CRM_Utils_Array
::value('payment_processor', $params);
926 $contribParams['skipLineItem'] = 1;
927 // create contribution record
928 $contribution = CRM_Contribute_BAO_Contribution
::add($contribParams, $ids);
930 CRM_Event_BAO_Participant
::createDiscountTrxn($form->_eventId
, $contribParams, CRM_Utils_Array
::value('amount_priceset_level_radio', $params, NULL));
932 // process soft credit / pcp pages
933 CRM_Contribute_Form_Contribution_Confirm
::processPcpSoft($params, $contribution);
935 $transaction->commit();
937 return $contribution;
941 * Fix the Location Fields
950 public static function fixLocationFields(&$params, &$fields, &$form) {
951 if (!empty($form->_fields
)) {
952 foreach ($form->_fields
as $name => $dontCare) {
957 if (is_array($fields)) {
958 if (!array_key_exists('first_name', $fields)) {
959 $nameFields = array('first_name', 'middle_name', 'last_name');
960 foreach ($nameFields as $name) {
962 if (array_key_exists("billing_$name", $params)) {
963 $params[$name] = $params["billing_{$name}"];
964 $params['preserveDBName'] = TRUE;
970 // also add location name to the array
971 if ($form->_values
['event']['is_monetary']) {
972 $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);
973 $fields["address_name-{$form->_bltID}"] = 1;
975 $fields["email-{$form->_bltID}"] = 1;
976 $fields['email-Primary'] = 1;
978 //if its pay later or additional participant set email address as primary.
979 if ((!empty($params['is_pay_later']) ||
empty($params['is_primary']) ||
980 !$form->_values
['event']['is_monetary'] ||
981 $form->_allowWaitlist ||
982 $form->_requireApproval
983 ) && !empty($params["email-{$form->_bltID}"])) {
984 $params['email-Primary'] = $params["email-{$form->_bltID}"];
989 * function to update contact fields
999 public static function updateContactFields($contactID, $params, $fields, &$form) {
1000 //add the contact to group, if add to group is selected for a
1001 //particular uf group
1003 // get the add to groups
1004 $addToGroups = array();
1006 if (!empty($form->_fields
)) {
1007 foreach ($form->_fields
as $key => $value) {
1008 if (!empty($value['add_to_group_id'])) {
1009 $addToGroups[$value['add_to_group_id']] = $value['add_to_group_id'];
1014 // check for profile double opt-in and get groups to be subscribed
1015 $subscribeGroupIds = CRM_Core_BAO_UFGroup
::getDoubleOptInGroupIds($params, $contactID);
1017 foreach ($addToGroups as $k) {
1018 if (array_key_exists($k, $subscribeGroupIds)) {
1019 unset($addToGroups[$k]);
1023 // since we are directly adding contact to group lets unset it from mailing
1024 if (!empty($addToGroups)) {
1025 foreach ($addToGroups as $groupId) {
1026 if (isset($subscribeGroupIds[$groupId])) {
1027 unset($subscribeGroupIds[$groupId]);
1032 $ctype = CRM_Core_DAO
::getFieldValue(
1033 'CRM_Contact_DAO_Contact',
1038 if(array_key_exists('contact_id', $params) && empty($params['contact_id'])) {
1039 // we unset this here because the downstream function ignores the contactID we give it
1040 // if it is set & it is difficult to understand the implications of 'fixing' this downstream
1041 // but if we are passing a contact id into this function it's reasonable to assume we don't
1043 unset($params['contact_id']);
1046 $contactID = CRM_Contact_BAO_Contact
::createProfileContact(
1058 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
1059 if (!isset($params[$greeting . '_id'])) {
1060 $params[$greeting . '_id'] = CRM_Contact_BAO_Contact_Utils
::defaultGreeting('Individual', $greeting);
1064 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params,
1072 $form->set('contactID', $contactID);
1075 //get email primary first if exist
1076 $subscribtionEmail = array('email' => CRM_Utils_Array
::value('email-Primary', $params));
1077 if (!$subscribtionEmail['email']) {
1078 $subscribtionEmail['email'] = CRM_Utils_Array
::value("email-{$form->_bltID}", $params);
1080 // subscribing contact to groups
1081 if (!empty($subscribeGroupIds) && $subscribtionEmail['email']) {
1082 CRM_Mailing_Event_BAO_Subscribe
::commonSubscribe($subscribeGroupIds, $subscribtionEmail, $contactID);
1091 public static function assignProfiles(&$form) {
1092 $participantParams = $form->_params
;
1093 $formattedValues = $profileFields = array();
1095 foreach ($participantParams as $participantNum => $participantValue) {
1096 if ($participantNum) {
1097 $prefix1 = 'additional';
1098 $prefix2 = 'additional_';
1103 if ($participantValue != 'skip') {
1104 //get the customPre profile info
1105 if (!empty($form->_values
[$prefix2 . 'custom_pre_id'])) {
1106 $values = $groupName = array();
1107 CRM_Event_BAO_Event
::displayProfile($participantValue,
1108 $form->_values
[ $prefix2 . 'custom_pre_id'],
1114 if (count($values)) {
1115 $formattedValues[$count][$prefix1 . 'CustomPre'] = $values;
1117 $formattedValues[$count][$prefix1 . 'CustomPreGroupTitle'] = CRM_Utils_Array
::value('groupTitle', $groupName);
1119 //get the customPost profile info
1120 if (!empty($form->_values
[$prefix2 . 'custom_post_id'])) {
1121 $values = $groupName = array();
1122 foreach ($form->_values
[$prefix2 . 'custom_post_id'] as $gids) {
1124 CRM_Event_BAO_Event
::displayProfile($participantValue,
1130 $values[$gids] = $val;
1131 $groupName[$gids] = $group;
1134 if (count($values)) {
1135 $formattedValues[$count][$prefix1 . 'CustomPost'] = $values;
1138 if (isset($formattedValues[$count][$prefix1 . 'CustomPre'])) {
1139 $formattedValues[$count][$prefix1 . 'CustomPost'] = array_diff_assoc($formattedValues[$count][$prefix1 . 'CustomPost'],
1140 $formattedValues[$count][$prefix1 . 'CustomPre']
1144 $formattedValues[$count][$prefix1 . 'CustomPostGroupTitle'] = $groupName;
1148 $form->_fields
= $profileFields;
1150 if (!empty($formattedValues) ) {
1151 $form->assign('primaryParticipantProfile', $formattedValues[1]);
1152 $form->set('primaryParticipantProfile', $formattedValues[1]);
1154 unset($formattedValues[1]);
1155 $form->assign('addParticipantProfile', $formattedValues);
1156 $form->set('addParticipantProfile', $formattedValues);