3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
38 * This class generates form components for processing a participation
41 class CRM_Event_Form_Participant
extends CRM_Contribute_Form_AbstractEditPayment
{
43 public $useLivePageJS = TRUE;
46 * The values for the contribution db object.
53 * The values for the quickconfig for priceset.
57 public $_quickConfig = NULL;
60 * Price Set ID, if the new price set method is used
67 * Array of fields for the price set.
74 * The id of the participation that we are proceessing.
85 protected $_noteId = NULL;
90 * Use parent $this->contactID
92 * The id of the contact associated with this participation.
99 * Array of event values.
106 * Are we operating in "single mode", i.e. adding / editing only
107 * one participant record, or is this a batch add operation
111 public $_single = FALSE;
114 * If event is paid or unpaid.
116 public $_isPaidEvent;
126 protected $_roleId = NULL;
131 protected $_eventTypeId = NULL;
134 * Participant status Id.
136 protected $_statusId = NULL;
139 * Cache all the participant statuses.
141 protected $_participantStatuses;
146 public $_mode = NULL;
149 * Event ID preselect.
154 * Line Item for Price Set.
156 public $_lineItem = NULL;
159 * Contribution mode for event registration for offline mode.
163 public $_contributeMode = 'direct';
168 * Store id of role custom data type ( option value )
170 protected $_roleCustomDataTypeID;
173 * Store id of event Name custom data type ( option value)
175 protected $_eventNameCustomDataTypeID;
178 * Selected discount id.
180 public $_originalDiscountId = NULL;
185 public $_eventId = NULL;
188 * Id of payment, if any
190 public $_paymentId = NULL;
193 * @todo add explanatory note about this
196 public $_onlinePendingContributionId = NULL;
199 * Explicitly declare the entity api name.
201 public function getDefaultEntity() {
202 return 'Participant';
206 * Set variables up before form is built.
210 public function preProcess() {
211 parent
::preProcess();
212 $this->_showFeeBlock
= CRM_Utils_Array
::value('eventId', $_GET);
213 $this->assign('showFeeBlock', FALSE);
214 $this->assign('feeBlockPaid', FALSE);
216 // @todo eliminate this duplication.
217 $this->_contactId
= $this->_contactID
;
218 $this->_eID
= CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
219 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this);
220 $this->assign('context', $this->_context
);
222 if ($this->_contactID
) {
223 $this->setPageTitle(ts('Event Registration for %1', array(1 => $this->userDisplayName
)));
226 $this->setPageTitle(ts('Event Registration'));
229 // check the current path, if search based, then dont get participantID
231 $path = CRM_Utils_System
::currentPath();
233 strpos($path, 'civicrm/contact/search') === 0 ||
234 strpos($path, 'civicrm/group/search') === 0
239 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
243 $this->assign('participantId', $this->_id
);
245 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
246 $this->_id
, 'id', 'participant_id'
249 $this->assign('hasPayment', $this->_paymentId
);
250 $this->assign('componentId', $this->_id
);
251 $this->assign('component', 'event');
253 // CRM-12615 - Get payment information from the primary registration
254 if ((!$this->_paymentId
) && ($this->_action
== CRM_Core_Action
::UPDATE
)) {
255 $registered_by_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
256 $this->_id
, 'registered_by_id', 'id'
258 if ($registered_by_id) {
259 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
260 $registered_by_id, 'id', 'participant_id'
262 $this->assign('registeredByParticipantId', $registered_by_id);
266 $this->setCustomDataTypes();
269 $this->assign('participantMode', $this->_mode
);
272 if ($this->_showFeeBlock
) {
273 $this->assign('showFeeBlock', TRUE);
274 $isMonetary = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_showFeeBlock
, 'is_monetary');
276 $this->assign('feeBlockPaid', TRUE);
278 return CRM_Event_Form_EventFees
::preProcess($this);
281 //check the mode when this form is called either single or as
283 if ($this->_id ||
$this->_contactId ||
$this->_context
== 'standalone') {
284 $this->_single
= TRUE;
285 $this->assign('urlPath', 'civicrm/contact/view/participant');
286 if (!$this->_id
&& !$this->_contactId
) {
287 $breadCrumbs = array(
289 'title' => ts('CiviEvent Dashboard'),
290 'url' => CRM_Utils_System
::url('civicrm/event', 'reset=1'),
294 CRM_Utils_System
::appendBreadCrumb($breadCrumbs);
298 //set the appropriate action
299 $context = $this->get('context');
300 $urlString = 'civicrm/contact/search';
301 $this->_action
= CRM_Core_Action
::BASIC
;
304 $urlString = 'civicrm/contact/search/advanced';
305 $this->_action
= CRM_Core_Action
::ADVANCED
;
309 $urlString = 'civicrm/contact/search/builder';
310 $this->_action
= CRM_Core_Action
::PROFILE
;
314 $urlString = 'civicrm/contact/search/basic';
315 $this->_action
= CRM_Core_Action
::BASIC
;
319 $urlString = 'civicrm/contact/search/custom';
320 $this->_action
= CRM_Core_Action
::COPY
;
323 CRM_Contact_Form_Task
::preProcessCommon($this);
325 $this->_single
= FALSE;
326 $this->_contactId
= NULL;
328 //set ajax path, this used for custom data building
329 $this->assign('urlPath', $urlString);
330 $this->assign('urlPathVar', "_qf_Participant_display=true&qfKey={$this->controller->_key}");
333 $this->assign('single', $this->_single
);
336 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
338 $this->assign('action', $this->_action
);
340 // check for edit permission
341 if (!CRM_Core_Permission
::checkActionPermission('CiviEvent', $this->_action
)) {
342 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
345 if ($this->_action
& CRM_Core_Action
::DELETE
) {
346 // check delete permission for contribution
347 if ($this->_id
&& $this->_paymentId
&& !CRM_Core_Permission
::checkActionPermission('CiviContribute', $this->_action
)) {
348 CRM_Core_Error
::fatal(ts("This Participant is linked to a contribution. You must have 'delete in CiviContribute' permission in order to delete this record."));
354 // assign participant id to the template
355 $this->assign('participantId', $this->_id
);
356 $this->_roleId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'role_id');
359 // when fee amount is included in form
360 if (!empty($_POST['hidden_feeblock']) ||
!empty($_POST['send_receipt'])) {
361 CRM_Event_Form_EventFees
::preProcess($this);
362 CRM_Event_Form_EventFees
::buildQuickForm($this);
363 CRM_Event_Form_EventFees
::setDefaultValues($this);
366 // when custom data is included in this page
367 if (!empty($_POST['hidden_custom'])) {
368 // Custom data of type participant role
369 // Note: Some earlier commits imply $_POST['role_id'] could be a comma separated string,
370 // not sure if that ever really happens
371 if (!empty($_POST['role_id'])) {
372 foreach ($_POST['role_id'] as $roleID) {
373 CRM_Custom_Form_CustomData
::preProcess($this, $this->_roleCustomDataTypeID
, $roleID, 1, 'Participant', $this->_id
);
374 CRM_Custom_Form_CustomData
::buildQuickForm($this);
375 CRM_Custom_Form_CustomData
::setDefaultValues($this);
379 //custom data of type participant event
380 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventNameCustomDataTypeID
, $_POST['event_id'], 1, 'Participant', $this->_id
);
381 CRM_Custom_Form_CustomData
::buildQuickForm($this);
382 CRM_Custom_Form_CustomData
::setDefaultValues($this);
384 // custom data of type participant event type
386 if ($eventId = CRM_Utils_Array
::value('event_id', $_POST)) {
387 $eventTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'event_type_id', 'id');
389 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventTypeCustomDataTypeID
, $eventTypeId,
390 1, 'Participant', $this->_id
392 CRM_Custom_Form_CustomData
::buildQuickForm($this);
393 CRM_Custom_Form_CustomData
::setDefaultValues($this);
395 //custom data of type participant, ( we 'null' to reset subType and subName)
396 CRM_Custom_Form_CustomData
::preProcess($this, 'null', 'null', 1, 'Participant', $this->_id
);
397 CRM_Custom_Form_CustomData
::buildQuickForm($this);
398 CRM_Custom_Form_CustomData
::setDefaultValues($this);
401 // CRM-4395, get the online pending contribution id.
402 $this->_onlinePendingContributionId
= NULL;
403 if (!$this->_mode
&& $this->_id
&& ($this->_action
& CRM_Core_Action
::UPDATE
)) {
404 $this->_onlinePendingContributionId
= CRM_Contribute_BAO_Contribution
::checkOnlinePendingContribution($this->_id
,
408 $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId
);
412 * This function sets the default values for the form in edit/view mode
413 * the default values are retrieved from the database
418 public function setDefaultValues() {
419 if ($this->_showFeeBlock
) {
420 return CRM_Event_Form_EventFees
::setDefaultValues($this);
425 if ($this->_action
& CRM_Core_Action
::DELETE
) {
431 $params = array('id' => $this->_id
);
433 CRM_Event_BAO_Participant
::getValues($params, $defaults, $ids);
434 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
435 if ($defaults[$this->_id
]['role_id']) {
436 $roleIDs = explode($sep, $defaults[$this->_id
]['role_id']);
438 $this->_contactId
= $defaults[$this->_id
]['contact_id'];
439 $this->_statusId
= $defaults[$this->_id
]['participant_status_id'];
441 //set defaults for note
442 $noteDetails = CRM_Core_BAO_Note
::getNote($this->_id
, 'civicrm_participant');
443 $defaults[$this->_id
]['note'] = array_pop($noteDetails);
445 // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859)
446 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
447 $this->assign('additionalParticipants', CRM_Event_BAO_Participant
::getAdditionalParticipants($this->_id
));
450 // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
451 if (!empty($defaults[$this->_id
]['participant_registered_by_id'])) {
452 $registered_by_contact_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
453 $defaults[$this->_id
]['participant_registered_by_id'],
456 $this->assign('participant_registered_by_id', $defaults[$this->_id
]['participant_registered_by_id']);
457 $this->assign('registered_by_contact_id', $registered_by_contact_id);
458 $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact
::displayName($registered_by_contact_id));
462 if ($this->_action
& (CRM_Core_Action
::VIEW | CRM_Core_Action
::BROWSE
)) {
463 $inactiveNeeded = TRUE;
468 $inactiveNeeded = FALSE;
471 //setting default register date
472 if ($this->_action
== CRM_Core_Action
::ADD
) {
473 $statuses = array_flip(CRM_Event_PseudoConstant
::participantStatus());
474 $defaults[$this->_id
]['status_id'] = CRM_Utils_Array
::value('Registered', $statuses);
475 if (!empty($defaults[$this->_id
]['event_id'])) {
476 $contributionTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
477 $defaults[$this->_id
]['event_id'],
480 if ($contributionTypeId) {
481 $defaults[$this->_id
]['financial_type_id'] = $contributionTypeId;
486 $fields["email-{$this->_bltID}"] = 1;
487 $fields['email-Primary'] = 1;
489 if ($this->_contactId
) {
490 CRM_Core_BAO_UFGroup
::setProfileDefaults($this->_contactId
, $fields, $defaults);
493 if (empty($defaults["email-{$this->_bltID}"]) &&
494 !empty($defaults['email-Primary'])
496 $defaults[$this->_id
]["email-{$this->_bltID}"] = $defaults['email-Primary'];
500 $submittedRole = $this->getElementValue('role_id');
501 if (!empty($submittedRole[0])) {
502 $roleID = $submittedRole[0];
504 $submittedEvent = $this->getElementValue('event_id');
505 if (!empty($submittedEvent[0])) {
506 $eventID = $submittedEvent[0];
510 $defaults[$this->_id
]['record_contribution'] = 0;
512 if ($defaults[$this->_id
]['participant_is_pay_later']) {
513 $this->assign('participant_is_pay_later', TRUE);
516 $this->assign('participant_status_id', $defaults[$this->_id
]['participant_status_id']);
517 $eventID = $defaults[$this->_id
]['event_id'];
519 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
521 $this->_discountId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'discount_id');
522 if ($this->_discountId
) {
523 $this->set('discountId', $this->_discountId
);
527 list($defaults[$this->_id
]['register_date'], $defaults[$this->_id
]['register_date_time'])
528 = CRM_Utils_Date
::setDateDefaults(CRM_Utils_Array
::value('register_date', $defaults[$this->_id
]), 'activityDateTime');
530 //assign event and role id, this is needed for Custom data building
531 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
532 if (!empty($defaults[$this->_id
]['participant_role_id'])) {
533 $roleIDs = explode($sep, $defaults[$this->_id
]['participant_role_id']);
535 if (isset($_POST['event_id'])) {
536 $eventID = $_POST['event_id'];
540 $eventID = $this->_eID
;
541 //@todo - rationalise the $this->_eID with $POST['event_id'], $this->_eid is set when eid=x is in the url
542 $roleID = CRM_Core_DAO
::getFieldValue(
543 'CRM_Event_DAO_Event',
547 if (empty($roleIDs)) {
548 $roleIDs = (array) $defaults[$this->_id
]['participant_role_id'] = $roleID;
550 $defaults[$this->_id
]['event_id'] = $eventID;
552 if (!empty($eventID)) {
553 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
555 //these should take precedence so we state them last
556 $urlRoleIDS = CRM_Utils_Request
::retrieve('roles', 'String');
558 $roleIDs = explode(',', $urlRoleIDS);
560 if (isset($roleIDs)) {
561 $defaults[$this->_id
]['role_id'] = implode(',', $roleIDs);
564 if (isset($eventID)) {
565 $this->assign('eventID', $eventID);
566 $this->set('eventId', $eventID);
569 if (isset($this->_eventTypeId
)) {
570 $this->assign('eventTypeID', $this->_eventTypeId
);
573 $this->assign('event_is_test', CRM_Utils_Array
::value('event_is_test', $defaults[$this->_id
]));
574 return $defaults[$this->_id
];
578 * Build the form object.
582 public function buildQuickForm() {
583 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
584 $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses);
585 $this->assign('partiallyPaidStatusId', $partiallyPaidStatusId);
587 if ($this->_showFeeBlock
) {
588 return CRM_Event_Form_EventFees
::buildQuickForm($this);
591 //need to assign custom data type to the template
592 $this->assign('customDataType', 'Participant');
594 $this->applyFilter('__ALL__', 'trim');
596 if ($this->_action
& CRM_Core_Action
::DELETE
) {
597 if ($this->_single
) {
598 $additionalParticipant = count(CRM_Event_BAO_Event
::buildCustomProfile($this->_id
,
604 if ($additionalParticipant) {
605 $deleteParticipants = array(
606 1 => ts('Delete this participant record along with associated participant record(s).'),
607 2 => ts('Delete only this participant record.'),
609 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
610 $this->setDefaults(array('delete_participant' => 1));
611 $this->assign('additionalParticipant', $additionalParticipant);
614 $this->addButtons(array(
617 'name' => ts('Delete'),
618 'spacing' => ' ',
623 'name' => ts('Cancel'),
630 if ($this->_single
&& $this->_context
== 'standalone') {
631 $this->addEntityRef('contact_id', ts('Contact'), array(
633 'api' => array('extra' => array('email')),
637 $eventFieldParams = array(
639 'select' => array('minimumInputLength' => 0),
641 'extra' => array('campaign_id', 'default_role_id', 'event_type_id'),
646 // exclude events which are not monetary when credit card registration is used
647 $eventFieldParams['api']['params']['is_monetary'] = 1;
648 $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors
, TRUE);
651 $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE);
653 //frozen the field fix for CRM-4171
654 if ($this->_action
& CRM_Core_Action
::UPDATE
&& $this->_id
) {
655 if (CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
656 $this->_id
, 'contribution_id', 'participant_id'
663 //CRM-7362 --add campaigns.
666 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'campaign_id');
669 $eventId = CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
671 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
674 CRM_Campaign_BAO_Campaign
::addCampaign($this, $campaignId);
676 $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
679 $this->assign('entityID', $this->_id
);
682 $this->addSelect('role_id', array('multiple' => TRUE, 'class' => 'huge'), TRUE);
685 $checkCancelledJs = array('onchange' => "return sendNotification( );");
687 if ($this->_onlinePendingContributionId
) {
688 $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant
::participantStatus());
689 $cancelledContributionStatusId = array_search('Cancelled',
690 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
692 $checkCancelledJs = array(
693 'onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});",
696 $participantStatusId = array_search('Pending from pay later',
697 CRM_Event_PseudoConstant
::participantStatus()
699 $contributionStatusId = array_search('Completed',
700 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
702 $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
705 // get the participant status names to build special status array which is used to show notification
706 // checkbox below participant status select
707 $participantStatusName = CRM_Event_PseudoConstant
::participantStatus();
708 $notificationStatuses = array(
710 'Pending from waitlist',
711 'Pending from approval',
715 // get the required status and then implode only ids
716 $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
717 $this->assign('notificationStatusIds', $notificationStatusIds);
719 $this->_participantStatuses
= $statusOptions = CRM_Event_BAO_Participant
::buildOptions('status_id', 'create');
721 // Only show refund status when editing
722 if ($this->_action
& CRM_Core_Action
::ADD
) {
723 $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
724 if ($pendingRefundStatusId) {
725 unset($statusOptions[$pendingRefundStatusId]);
729 $this->addSelect('status_id', $checkCancelledJs +
array(
730 'options' => $statusOptions,
731 'option_url' => 'civicrm/admin/participant_status',
734 $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
736 $this->add('text', 'source', ts('Event Source'));
737 $noteAttributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Note');
738 $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
742 'name' => ts('Save'),
747 $path = CRM_Utils_System
::currentPath();
748 $excludeForPaths = array(
749 'civicrm/contact/search',
750 'civicrm/group/search',
752 if (!in_array($path, $excludeForPaths)) {
755 'name' => ts('Save and New'),
763 'name' => ts('Cancel'),
766 $this->addButtons($buttons);
767 if ($this->_action
== CRM_Core_Action
::VIEW
) {
773 * Add local and global form rules.
778 public function addRules() {
779 $this->addFormRule(array('CRM_Event_Form_Participant', 'formRule'), $this);
783 * Global validation rules for the form.
785 * @param array $values
786 * Posted values of the form.
791 * list of errors to be posted back to the form
793 public static function formRule($values, $files, $self) {
794 // If $values['_qf_Participant_next'] is Delete or
795 // $values['event_id'] is empty, then return
796 // instead of proceeding further.
798 if ((CRM_Utils_Array
::value('_qf_Participant_next', $values) == 'Delete') ||
799 (!$values['event_id'])
806 if (!empty($values['payment_processor_id'])) {
807 // make sure that payment instrument values (e.g. credit card number and cvv) are valid
808 CRM_Core_Payment_Form
::validatePaymentInstrument($values['payment_processor_id'], $values, $errorMsg, NULL);
811 if (!empty($values['record_contribution'])) {
812 if (empty($values['financial_type_id'])) {
813 $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
815 if (empty($values['payment_instrument_id'])) {
816 $errorMsg['payment_instrument_id'] = ts('Payment Method is a required field.');
818 if (!empty($values['priceSetId'])) {
819 CRM_Price_BAO_PriceField
::priceSetValidation($values['priceSetId'], $values, $errorMsg);
823 // validate contribution status for 'Failed'.
824 if ($self->_onlinePendingContributionId
&& !empty($values['record_contribution']) &&
825 (CRM_Utils_Array
::value('contribution_status_id', $values) ==
826 array_search('Failed', CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name'))
829 $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.');
832 // do the amount validations.
833 //skip for update mode since amount is freeze, CRM-6052
834 if ((!$self->_id
&& empty($values['total_amount']) &&
835 empty($self->_values
['line_items'])
837 ($self->_id
&& !$self->_paymentId
&& isset($self->_values
['line_items']) && is_array($self->_values
['line_items']))
839 if ($priceSetId = CRM_Utils_Array
::value('priceSetId', $values)) {
840 CRM_Price_BAO_PriceField
::priceSetValidation($priceSetId, $values, $errorMsg, TRUE);
843 // For single additions - show validation error if the contact has already been registered
845 if ($self->_single
&& ($self->_action
& CRM_Core_Action
::ADD
)) {
846 if ($self->_context
== 'standalone') {
847 $contactId = CRM_Utils_Array
::value('contact_id', $values);
850 $contactId = $self->_contactId
;
853 $eventId = CRM_Utils_Array
::value('event_id', $values);
854 if (!empty($contactId) && !empty($eventId)) {
855 $cancelledStatusID = CRM_Core_PseudoConstant
::getKey('CRM_Event_BAO_Participant', 'status_id', 'Cancelled');
856 $dupeCheck = new CRM_Event_BAO_Participant();
857 $dupeCheck->contact_id
= $contactId;
858 $dupeCheck->event_id
= $eventId;
859 $dupeCheck->whereAdd("status_id != {$cancelledStatusID} ");
860 $dupeCheck->find(TRUE);
861 if (!empty($dupeCheck->id
)) {
862 $errorMsg['event_id'] = ts("This contact has already been assigned to this event.");
866 return CRM_Utils_Array
::crmIsEmptyArray($errorMsg) ?
TRUE : $errorMsg;
870 * Process the form submission.
872 public function postProcess() {
873 // get the submitted form values.
874 $params = $this->controller
->exportValues($this->_name
);
876 if ($this->_action
& CRM_Core_Action
::DELETE
) {
877 if (CRM_Utils_Array
::value('delete_participant', $params) == 2) {
878 $additionalId = (CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
));
879 $participantLinks = (CRM_Event_BAO_Participant
::getAdditionalParticipantUrl($additionalId));
881 if (CRM_Utils_Array
::value('delete_participant', $params) == 1) {
882 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
883 foreach ($additionalIds as $value) {
884 CRM_Event_BAO_Participant
::deleteParticipant($value);
887 CRM_Event_BAO_Participant
::deleteParticipant($this->_id
);
888 CRM_Core_Session
::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success');
889 if (!empty($participantLinks)) {
890 $status = ts('The following participants no longer have an event fee recorded. You can edit their registration and record a replacement contribution by clicking the links below:') . '<br/>' . $participantLinks;
891 CRM_Core_Session
::setStatus($status, ts('Group Payment Deleted'));
895 // When adding a single contact, the formRule prevents you from adding duplicates
896 // (See above in formRule()). When adding more than one contact, the duplicates are
897 // removed automatically and the user receives one notification.
898 if ($this->_action
& CRM_Core_Action
::ADD
) {
899 $event_id = $this->_eventId
;
900 if (empty($event_id) && !empty($params['event_id'])) {
901 $event_id = $params['event_id'];
903 if (!$this->_single
&& !empty($event_id)) {
904 $duplicateContacts = 0;
905 while (list($k, $dupeCheckContactId) = each($this->_contactIds
)) {
906 // Eliminate contacts that have already been assigned to this event.
907 $dupeCheck = new CRM_Event_BAO_Participant();
908 $dupeCheck->contact_id
= $dupeCheckContactId;
909 $dupeCheck->event_id
= $event_id;
910 $dupeCheck->find(TRUE);
911 if (!empty($dupeCheck->id
)) {
912 $duplicateContacts++
;
913 unset($this->_contactIds
[$k]);
916 if ($duplicateContacts > 0) {
918 "%1 contacts have already been assigned to this event. They were not added a second time.",
919 array(1 => $duplicateContacts)
921 CRM_Core_Session
::setStatus($msg);
923 if (count($this->_contactIds
) == 0) {
924 CRM_Core_Session
::setStatus(ts("No participants were added."));
927 // We have to re-key $this->_contactIds so each contact has the same
928 // key as their corresponding record in the $participants array that
929 // will be created below.
930 $this->_contactIds
= array_values($this->_contactIds
);
934 $statusMsg = $this->submit($params);
935 CRM_Core_Session
::setStatus($statusMsg, ts('Saved'), 'success');
936 $session = CRM_Core_Session
::singleton();
937 $buttonName = $this->controller
->getButtonName();
938 if ($this->_context
== 'standalone') {
939 if ($buttonName == $this->getButtonName('upload', 'new')) {
940 $urlParams = 'reset=1&action=add&context=standalone';
942 $urlParams .= '&mode=' . $this->_mode
;
945 $urlParams .= '&eid=' . $this->_eID
;
947 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/participant/add', $urlParams));
950 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
951 "reset=1&cid={$this->_contactId}&selectedChild=participant"
955 elseif ($buttonName == $this->getButtonName('upload', 'new')) {
956 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view/participant',
957 "reset=1&action=add&context={$this->_context}&cid={$this->_contactId}"
965 * @param array $params
969 public function submit($params) {
970 $participantStatus = CRM_Event_PseudoConstant
::participantStatus();
971 // set the contact, when contact is selected
972 if (!empty($params['contact_id'])) {
973 $this->_contactID
= $this->_contactId
= $params['contact_id'];
975 if ($this->_priceSetId
&& $isQuickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
976 $this->_quickConfig
= $isQuickConfig;
980 $params['id'] = $this->_id
;
983 $config = CRM_Core_Config
::singleton();
984 if (isset($params['total_amount'])) {
985 $params['total_amount'] = CRM_Utils_Rule
::cleanMoney($params['total_amount']);
987 if ($this->_isPaidEvent
) {
989 $contributionParams = array();
991 $additionalParticipantDetails = array();
992 if (CRM_Contribute_BAO_Contribution
::checkContributeSettings('deferred_revenue_enabled')) {
993 $eventStartDate = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_eventId
, 'start_date');
994 if (strtotime($eventStartDate) > strtotime(date('Ymt'))) {
995 $contributionParams['revenue_recognition_date'] = date('Ymd', strtotime($eventStartDate));
998 if (($this->_id
&& $this->_action
& CRM_Core_Action
::UPDATE
) && $this->_paymentId
) {
999 $participantBAO = new CRM_Event_BAO_Participant();
1000 $participantBAO->id
= $this->_id
;
1001 $participantBAO->find(TRUE);
1002 $contributionParams['total_amount'] = $participantBAO->fee_amount
;
1004 $params['discount_id'] = NULL;
1005 //re-enter the values for UPDATE mode
1006 $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level
;
1007 $params['fee_amount'] = $participantBAO->fee_amount
;
1008 if (isset($params['priceSetId'])) {
1009 $lineItem[0] = CRM_Price_BAO_LineItem
::getLineItems($this->_id
);
1011 //also add additional participant's fee level/priceset
1012 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
1013 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
1014 $hasLineItems = CRM_Utils_Array
::value('priceSetId', $params, FALSE);
1015 $additionalParticipantDetails = CRM_Event_BAO_Participant
::getFeeDetails($additionalIds,
1022 //check if discount is selected
1023 if (!empty($params['discount_id'])) {
1024 $discountId = $params['discount_id'];
1027 $discountId = $params['discount_id'] = 'null';
1030 //lets carry currency, CRM-4453
1031 $params['fee_currency'] = $config->defaultCurrency
;
1032 CRM_Price_BAO_PriceSet
::processAmount($this->_values
['fee'],
1033 $params, $lineItem[0]
1035 //CRM-11529 for quick config backoffice transactions
1036 //when financial_type_id is passed in form, update the
1037 //lineitems with the financial type selected in form
1038 $submittedFinancialType = CRM_Utils_Array
::value('financial_type_id', $params);
1039 $isPaymentRecorded = CRM_Utils_Array
::value('record_contribution', $params);
1040 if ($isPaymentRecorded && $this->_quickConfig
&& $submittedFinancialType) {
1041 foreach ($lineItem[0] as &$values) {
1042 $values['financial_type_id'] = $submittedFinancialType;
1046 $params['fee_level'] = $params['amount_level'];
1047 $contributionParams['total_amount'] = $params['amount'];
1048 if ($this->_quickConfig
&& !empty($params['total_amount']) &&
1049 $params['status_id'] != array_search('Partially paid', $participantStatus)
1051 $params['fee_amount'] = $params['total_amount'];
1055 $params['fee_amount'] = $params['amount'];
1059 if (isset($params['priceSetId'])) {
1060 if (!empty($lineItem[0])) {
1061 $this->set('lineItem', $lineItem);
1063 $this->_lineItem
= $lineItem;
1064 $lineItem = array_merge($lineItem, $additionalParticipantDetails);
1066 $participantCount = array();
1067 foreach ($lineItem as $k) {
1068 foreach ($k as $v) {
1069 if (CRM_Utils_Array
::value('participant_count', $v) > 0) {
1070 $participantCount[] = $v['participant_count'];
1075 if (isset($participantCount)) {
1076 $this->assign('pricesetFieldsCount', $participantCount);
1078 $this->assign('lineItem', empty($lineItem[0]) ||
$this->_quickConfig ?
FALSE : $lineItem);
1081 $this->assign('amount_level', $params['amount_level']);
1085 $this->_params
= $params;
1086 parent
::beginPostProcess();
1088 if (isset($params['amount'])) {
1089 $amountOwed = $params['amount'];
1090 unset($params['amount']);
1092 $params['register_date'] = CRM_Utils_Date
::processDate($params['register_date'], $params['register_date_time']);
1093 $params['receive_date'] = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('receive_date', $params), CRM_Utils_Array
::value('receive_date_time', $params));
1094 $params['contact_id'] = $this->_contactId
;
1096 // overwrite actual payment amount if entered
1097 if (!empty($params['total_amount'])) {
1098 $contributionParams['total_amount'] = CRM_Utils_Array
::value('total_amount', $params);
1101 // Retrieve the name and email of the current user - this will be the FROM for the receipt email
1102 $userName = CRM_Core_Session
::singleton()->getLoggedInContactDisplayName();
1104 if ($this->_contactId
) {
1105 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($this->_contactId
);
1108 //modify params according to parameter used in create
1109 //participant method (addParticipant)
1110 $this->_params
['participant_status_id'] = $params['status_id'];
1111 $this->_params
['participant_role_id'] = is_array($params['role_id']) ?
$params['role_id'] : explode(',', $params['role_id']);
1112 $this->_params
['participant_register_date'] = $params['register_date'];
1113 $roleIdWithSeparator = implode(CRM_Core_DAO
::VALUE_SEPARATOR
, $this->_params
['participant_role_id']);
1116 if (!$this->_isPaidEvent
) {
1117 CRM_Core_Error
::fatal(ts('Selected Event is not Paid Event '));
1121 = CRM_Core_DAO
::getFieldValue(
1122 'CRM_Event_DAO_Event',
1123 $params['event_id'],
1127 // set source if not set
1128 if (empty($params['source'])) {
1129 $this->_params
['participant_source'] = ts('Offline Registration for Event: %2 by: %1', array(
1135 $this->_params
['participant_source'] = $params['source'];
1137 $this->_params
['description'] = $this->_params
['participant_source'];
1139 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($this->_params
['payment_processor_id'],
1142 $now = date('YmdHis');
1145 // set email for primary location.
1146 $fields['email-Primary'] = 1;
1147 $params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail
;
1149 $params['register_date'] = $now;
1151 // now set the values for the billing location.
1152 foreach ($this->_fields
as $name => $dontCare) {
1156 // also add location name to the array
1157 $params["address_name-{$this->_bltID}"]
1158 = CRM_Utils_Array
::value('billing_first_name', $params) . ' ' .
1159 CRM_Utils_Array
::value('billing_middle_name', $params) . ' ' .
1160 CRM_Utils_Array
::value('billing_last_name', $params);
1162 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
1163 $fields["address_name-{$this->_bltID}"] = 1;
1164 $fields["email-{$this->_bltID}"] = 1;
1165 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'contact_type');
1167 $nameFields = array('first_name', 'middle_name', 'last_name');
1169 foreach ($nameFields as $name) {
1171 if (array_key_exists("billing_$name", $params)) {
1172 $params[$name] = $params["billing_{$name}"];
1173 $params['preserveDBName'] = TRUE;
1176 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params, $fields, $this->_contactId
, NULL, NULL, $ctype);
1179 if (!empty($this->_params
['participant_role_id'])) {
1180 $customFieldsRole = array();
1181 foreach ($this->_params
['participant_role_id'] as $roleKey) {
1182 $customFieldsRole = CRM_Utils_Array
::crmArrayMerge(CRM_Core_BAO_CustomField
::getFields('Participant',
1183 FALSE, FALSE, $roleKey, $this->_roleCustomDataTypeID
), $customFieldsRole);
1185 $customFieldsEvent = CRM_Core_BAO_CustomField
::getFields('Participant',
1188 CRM_Utils_Array
::value('event_id', $params),
1189 $this->_eventNameCustomDataTypeID
1191 $customFieldsEventType = CRM_Core_BAO_CustomField
::getFields('Participant',
1194 $this->_eventTypeId
,
1195 $this->_eventTypeCustomDataTypeID
1197 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsRole,
1198 CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE)
1200 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEvent, $customFields);
1201 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEventType, $customFields);
1202 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
1208 //do cleanup line items if participant edit the Event Fee.
1209 if (($this->_lineItem ||
!isset($params['proceSetId'])) && !$this->_paymentId
&& $this->_id
) {
1210 CRM_Price_BAO_LineItem
::deleteLineItems($this->_id
, 'civicrm_participant');
1214 // add all the additional payment params we need
1215 $this->_params
["state_province-{$this->_bltID}"] = $this->_params
["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($this->_params
["billing_state_province_id-{$this->_bltID}"]);
1216 $this->_params
["country-{$this->_bltID}"] = $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
1218 $this->_params
['amount'] = $params['fee_amount'];
1219 $this->_params
['amount_level'] = $params['amount_level'];
1220 $this->_params
['currencyID'] = $config->defaultCurrency
;
1221 $this->_params
['invoiceID'] = md5(uniqid(rand(), TRUE));
1223 // at this point we've created a contact and stored its address etc
1224 // all the payment processors expect the name and address to be in the
1225 // so we copy stuff over to first_name etc.
1226 $paymentParams = $this->_params
;
1227 if (!empty($this->_params
['send_receipt'])) {
1228 $paymentParams['email'] = $this->_contributorEmail
;
1231 // The only reason for merging in the 'contact_id' rather than ensuring it is set
1232 // is that this patch is being done around the time of the stable release
1233 // so more conservative approach is called for.
1234 // In fact the use of $params and $this->_params & $this->_contactId vs $contactID
1235 // needs rationalising.
1236 $mapParams = array_merge(array('contact_id' => $contactID), $this->_params
);
1237 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $mapParams, $paymentParams, TRUE);
1239 $payment = $this->_paymentProcessor
['object'];
1241 // CRM-15622: fix for incorrect contribution.fee_amount
1242 $paymentParams['fee_amount'] = NULL;
1243 $result = $payment->doPayment($paymentParams);
1245 if (is_a($result, 'CRM_Core_Error')) {
1246 CRM_Core_Error
::displaySessionError($result);
1247 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/view/participant',
1248 "reset=1&action=add&cid={$this->_contactId}&context=participant&mode={$this->_mode}"
1253 $this->_params
= array_merge($this->_params
, $result);
1256 $this->_params
['receive_date'] = $now;
1258 if (!empty($this->_params
['send_receipt'])) {
1259 $this->_params
['receipt_date'] = $now;
1262 $this->_params
['receipt_date'] = NULL;
1265 $this->set('params', $this->_params
);
1266 $this->assign('trxn_id', $result['trxn_id']);
1267 $this->assign('receive_date',
1268 CRM_Utils_Date
::processDate($this->_params
['receive_date'])
1271 //add contribution record
1272 $this->_params
['financial_type_id']
1273 = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
1274 $this->_params
['mode'] = $this->_mode
;
1276 //add contribution record
1277 $contributions[] = $contribution = CRM_Event_Form_Registration_Confirm
::processContribution(
1278 $this, $this->_params
,
1279 $result, $contactID,
1281 $this->_paymentProcessor
1284 // add participant record
1285 $participants = array();
1286 if (!empty($this->_params
['role_id']) && is_array($this->_params
['role_id'])) {
1287 $this->_params
['role_id'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1288 $this->_params
['role_id']
1292 //CRM-15372 patch to fix fee amount replacing amount
1293 $this->_params
['fee_amount'] = $this->_params
['amount'];
1295 $participants[] = CRM_Event_Form_Registration
::addParticipant($this, $contactID);
1297 //add custom data for participant
1298 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
1299 'civicrm_participant',
1300 $participants[0]->id
,
1303 //add participant payment
1304 $paymentParticipant = array(
1305 'participant_id' => $participants[0]->id
,
1306 'contribution_id' => $contribution->id
,
1310 CRM_Event_BAO_ParticipantPayment
::create($paymentParticipant, $ids);
1311 $this->_contactIds
[] = $this->_contactId
;
1314 $participants = array();
1315 if ($this->_single
) {
1316 if ($params['role_id']) {
1317 $params['role_id'] = $roleIdWithSeparator;
1320 $params['role_id'] = 'NULL';
1322 $participants[] = CRM_Event_BAO_Participant
::create($params);
1325 foreach ($this->_contactIds
as $contactID) {
1326 $commonParams = $params;
1327 $commonParams['contact_id'] = $contactID;
1328 if ($commonParams['role_id']) {
1329 $commonParams['role_id'] = $commonParams['role_id'] = str_replace(',', CRM_Core_DAO
::VALUE_SEPARATOR
, $params['role_id']);
1332 $commonParams['role_id'] = 'NULL';
1334 $participants[] = CRM_Event_BAO_Participant
::create($commonParams);
1338 if (isset($params['event_id'])) {
1339 $eventTitle = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
1340 $params['event_id'],
1345 if ($this->_single
) {
1346 $this->_contactIds
[] = $this->_contactId
;
1349 $contributions = array();
1350 if (!empty($params['record_contribution'])) {
1351 if (!empty($params['id'])) {
1352 if ($this->_onlinePendingContributionId
) {
1353 $ids['contribution'] = $this->_onlinePendingContributionId
;
1356 $ids['contribution'] = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1363 unset($params['note']);
1365 //build contribution params
1366 if (!$this->_onlinePendingContributionId
) {
1367 if (empty($params['source'])) {
1368 $contributionParams['source'] = ts('%1 : Offline registration (by %2)', array(
1374 $contributionParams['source'] = $params['source'];
1378 $contributionParams['currency'] = $config->defaultCurrency
;
1379 $contributionParams['non_deductible_amount'] = 'null';
1380 $contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array
::value('receive_date', $params) : 'null';
1381 $contributionParams['contact_id'] = $this->_contactID
;
1382 // @todo change receive_date to datepicker field. Strip out all wrangling.
1383 $contributionParams['receive_date'] = $params['receive_date'];
1385 $recordContribution = array(
1386 'financial_type_id',
1387 'payment_instrument_id',
1389 'contribution_status_id',
1396 foreach ($recordContribution as $f) {
1397 $contributionParams[$f] = CRM_Utils_Array
::value($f, $this->_params
);
1398 if ($f == 'trxn_id') {
1399 $this->assign('trxn_id', $contributionParams[$f]);
1403 //insert financial type name in receipt.
1404 $this->assign('financialTypeName', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType',
1405 $contributionParams['financial_type_id']));
1407 $this->assign('contributionTypeName', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id']));
1408 $contributionParams['skipLineItem'] = 1;
1410 $contributionParams['contribution_mode'] = 'participant';
1411 $contributionParams['participant_id'] = $this->_id
;
1413 // Set is_pay_later flag for back-office offline Pending status contributions
1414 if ($contributionParams['contribution_status_id'] == CRM_Core_PseudoConstant
::getKey('CRM_Contribute_DAO_Contribution', 'contribution_status_id', 'Pending')) {
1415 $contributionParams['is_pay_later'] = 1;
1417 elseif ($contributionParams['contribution_status_id'] == CRM_Core_PseudoConstant
::getKey('CRM_Contribute_DAO_Contribution', 'contribution_status_id', 'Completed')) {
1418 $contributionParams['is_pay_later'] = 0;
1421 if ($params['status_id'] == array_search('Partially paid', $participantStatus)) {
1422 if (!$amountOwed && $this->_action
& CRM_Core_Action
::UPDATE
) {
1423 $amountOwed = $params['fee_amount'];
1426 // if multiple participants are link, consider contribution total amount as the amount Owed
1427 if ($this->_id
&& CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
1428 $amountOwed = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_Contribution',
1429 $ids['contribution'],
1434 // CRM-13964 partial_payment_total
1435 if ($amountOwed > $params['total_amount']) {
1437 $contributionParams['partial_payment_total'] = $amountOwed;
1438 // the actual amount paid
1439 $contributionParams['partial_amount_to_pay'] = $params['total_amount'];
1443 if (CRM_Utils_Array
::value('tax_amount', $this->_params
)) {
1444 $contributionParams['tax_amount'] = $this->_params
['tax_amount'];
1447 if ($this->_single
) {
1451 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1455 foreach ($this->_contactIds
as $contactID) {
1456 $contributionParams['contact_id'] = $contactID;
1457 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1461 //insert payment record for this participation
1462 if (empty($ids['contribution'])) {
1463 foreach ($this->_contactIds
as $num => $contactID) {
1464 $ppDAO = new CRM_Event_DAO_ParticipantPayment();
1465 $ppDAO->participant_id
= $participants[$num]->id
;
1466 $ppDAO->contribution_id
= $contributions[$num]->id
;
1470 // next create the transaction record
1471 $transaction = new CRM_Core_Transaction();
1474 if ($this->_params
['discount_id']) {
1475 CRM_Event_BAO_Participant
::createDiscountTrxn(
1477 $contributionParams,
1479 CRM_Price_BAO_PriceSet
::parseFirstPriceSetValueIDFromParams($this->_params
)
1482 $transaction->commit();
1486 // also store lineitem stuff here
1487 if ((($this->_lineItem
& $this->_action
& CRM_Core_Action
::ADD
) ||
1488 ($this->_lineItem
&& CRM_Core_Action
::UPDATE
&& !$this->_paymentId
))
1490 foreach ($this->_contactIds
as $num => $contactID) {
1491 foreach ($this->_lineItem
as $key => $value) {
1492 if (is_array($value) && $value != 'skip') {
1493 foreach ($value as $lineKey => $line) {
1494 //10117 update the line items for participants if contribution amount is recorded
1495 if ($this->_quickConfig
&& !empty($params['total_amount']) &&
1496 ($params['status_id'] != array_search('Partially paid', $participantStatus))
1498 $line['unit_price'] = $line['line_total'] = $params['total_amount'];
1499 if (!empty($params['tax_amount'])) {
1500 $line['unit_price'] = $line['unit_price'] - $params['tax_amount'];
1501 $line['line_total'] = $line['line_total'] - $params['tax_amount'];
1504 $lineItem[$this->_priceSetId
][$lineKey] = $line;
1506 CRM_Price_BAO_LineItem
::processPriceSet($participants[$num]->id
, $lineItem, CRM_Utils_Array
::value($num, $contributions, NULL), 'civicrm_participant');
1507 CRM_Contribute_BAO_Contribution
::addPayments($contributions);
1513 $updateStatusMsg = NULL;
1514 //send mail when participant status changed, CRM-4326
1515 if ($this->_id
&& $this->_statusId
&&
1516 $this->_statusId
!= CRM_Utils_Array
::value('status_id', $params) && !empty($params['is_notify'])
1519 $updateStatusMsg = CRM_Event_BAO_Participant
::updateStatusMessage($this->_id
,
1520 $params['status_id'],
1527 if (!empty($params['send_receipt'])) {
1528 if (array_key_exists($params['from_email_address'], $this->_fromEmails
['from_email_id'])) {
1529 $receiptFrom = $params['from_email_address'];
1532 $this->assign('module', 'Event Registration');
1533 //use of the message template below requires variables in different format
1534 $event = $events = array();
1535 $returnProperties = array('event_type_id', 'fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
1537 //get all event details.
1538 CRM_Core_DAO
::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
1539 $event = $events[$params['event_id']];
1540 unset($event['start_date']);
1541 unset($event['end_date']);
1543 $role = CRM_Event_PseudoConstant
::participantRole();
1544 $participantRoles = CRM_Utils_Array
::value('role_id', $params);
1545 if (is_array($participantRoles)) {
1546 $selectedRoles = array();
1547 foreach ($participantRoles as $roleId) {
1548 $selectedRoles[] = $role[$roleId];
1550 $event['participant_role'] = implode(', ', $selectedRoles);
1553 $event['participant_role'] = CRM_Utils_Array
::value($participantRoles, $role);
1555 $event['is_monetary'] = $this->_isPaidEvent
;
1557 if ($params['receipt_text']) {
1558 $event['confirm_email_text'] = $params['receipt_text'];
1561 $this->assign('isAmountzero', 1);
1562 $this->assign('event', $event);
1564 $this->assign('isShowLocation', $event['is_show_location']);
1565 if (CRM_Utils_Array
::value('is_show_location', $event) == 1) {
1566 $locationParams = array(
1567 'entity_id' => $params['event_id'],
1568 'entity_table' => 'civicrm_event',
1570 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
1571 $this->assign('location', $location);
1574 $status = CRM_Event_PseudoConstant
::participantStatus();
1575 if ($this->_isPaidEvent
) {
1576 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
1577 if (!$this->_mode
) {
1578 if (isset($params['payment_instrument_id'])) {
1579 $this->assign('paidBy',
1580 CRM_Utils_Array
::value($params['payment_instrument_id'],
1587 $this->assign('totalAmount', $contributionParams['total_amount']);
1588 if (isset($contributionParams['partial_payment_total'])) {
1590 $balanceAmount = $contributionParams['partial_payment_total'] - $contributionParams['partial_amount_to_pay'];
1591 $this->assign('balanceAmount', $balanceAmount);
1593 $this->assign('isPrimary', 1);
1594 $this->assign('checkNumber', CRM_Utils_Array
::value('check_number', $params));
1597 $this->assignBillingName($params);
1598 $this->assign('address', CRM_Utils_Address
::getFormattedBillingAddressFieldsFromParameters(
1603 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
1604 $date = CRM_Utils_Date
::mysqlToIso($date);
1605 $this->assign('credit_card_exp_date', $date);
1606 $this->assign('credit_card_number',
1607 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
1609 $this->assign('credit_card_type', $params['credit_card_type']);
1610 // The concept of contributeMode is deprecated.
1611 $this->assign('contributeMode', 'direct');
1612 $this->assign('isAmountzero', 0);
1613 $this->assign('is_pay_later', 0);
1614 $this->assign('isPrimary', 1);
1617 $this->assign('register_date', $params['register_date']);
1618 if ($params['receive_date']) {
1619 $this->assign('receive_date', $params['receive_date']);
1622 $participant = array(array('participant_id', '=', $participants[0]->id
, 0, 0));
1623 // check whether its a test drive ref CRM-3075
1624 if (!empty($this->_defaultValues
['is_test'])) {
1625 $participant[] = array('participant_test', '=', 1, 0, 0);
1628 $template = CRM_Core_Smarty
::singleton();
1629 $customGroup = array();
1630 //format submitted data
1631 foreach ($params['custom'] as $fieldID => $values) {
1632 foreach ($values as $fieldValue) {
1633 $isPublic = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomGroup', $fieldValue['custom_group_id'], 'is_public');
1635 $customFields[$fieldID]['id'] = $fieldID;
1636 $formattedValue = CRM_Core_BAO_CustomField
::displayValue($fieldValue['value'], $fieldID, $participants[0]->id
);
1637 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace(' ', '', $formattedValue);
1642 foreach ($this->_contactIds
as $num => $contactID) {
1643 // Retrieve the name and email of the contact - this will be the TO for receipt email
1644 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($contactID);
1646 $this->_contributorDisplayName
= ($this->_contributorDisplayName
== ' ') ?
$this->_contributorEmail
: $this->_contributorDisplayName
;
1648 $waitStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
1649 if ($waitingStatus = CRM_Utils_Array
::value($params['status_id'], $waitStatus)) {
1650 $this->assign('isOnWaitlist', TRUE);
1653 $this->assign('customGroup', $customGroup);
1654 $this->assign('contactID', $contactID);
1655 $this->assign('participantID', $participants[$num]->id
);
1657 $this->_id
= $participants[$num]->id
;
1659 if ($this->_isPaidEvent
) {
1660 // fix amount for each of participants ( for bulk mode )
1661 $eventAmount = array();
1662 $invoiceSettings = Civi
::settings()->get('contribution_invoice_settings');
1663 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
1664 $totalTaxAmount = 0;
1666 //add dataArray in the receipts in ADD and UPDATE condition
1667 $dataArray = array();
1668 if ($this->_action
& CRM_Core_Action
::ADD
) {
1669 $line = $lineItem[0];
1671 elseif ($this->_action
& CRM_Core_Action
::UPDATE
) {
1672 $line = $this->_values
['line_items'];
1675 foreach ($line as $key => $value) {
1676 if (isset($value['tax_amount'])) {
1677 $totalTaxAmount +
= $value['tax_amount'];
1678 if (isset($dataArray[(string) $value['tax_rate']])) {
1679 $dataArray[(string) $value['tax_rate']] = $dataArray[(string) $value['tax_rate']] + CRM_Utils_Array
::value('tax_amount', $value);
1682 $dataArray[(string) $value['tax_rate']] = CRM_Utils_Array
::value('tax_amount', $value);
1686 $this->assign('totalTaxAmount', $totalTaxAmount);
1687 $this->assign('taxTerm', CRM_Utils_Array
::value('tax_term', $invoiceSettings));
1688 $this->assign('dataArray', $dataArray);
1690 if (!empty($additionalParticipantDetails)) {
1691 $params['amount_level'] = preg_replace('/\ 1/', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName
;
1694 $eventAmount[$num] = array(
1695 'label' => preg_replace('/\ 1/', '', $params['amount_level']),
1696 'amount' => $params['fee_amount'],
1698 //as we are using same template for online & offline registration.
1699 //So we have to build amount as array.
1700 $eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
1701 $this->assign('amount', $eventAmount);
1704 $sendTemplateParams = array(
1705 'groupName' => 'msg_tpl_workflow_event',
1706 'valueName' => 'event_offline_receipt',
1707 'contactId' => $contactID,
1708 'isTest' => !empty($this->_defaultValues
['is_test']),
1709 'PDFFilename' => ts('confirmation') . '.pdf',
1712 // try to send emails only if email id is present
1713 // and the do-not-email option is not checked for that contact
1714 if ($this->_contributorEmail
and !$this->_toDoNotEmail
) {
1715 $sendTemplateParams['from'] = $receiptFrom;
1716 $sendTemplateParams['toName'] = $this->_contributorDisplayName
;
1717 $sendTemplateParams['toEmail'] = $this->_contributorEmail
;
1718 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc', $this->_fromEmails
);
1719 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc', $this->_fromEmails
);
1722 //send email with pdf invoice
1723 $template = CRM_Core_Smarty
::singleton();
1724 $taxAmt = $template->get_template_vars('dataArray');
1725 $contributionId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1726 $this->_id
, 'contribution_id', 'participant_id'
1728 $prefixValue = Civi
::settings()->get('contribution_invoice_settings');
1729 $invoicing = CRM_Utils_Array
::value('invoicing', $prefixValue);
1730 if (count($taxAmt) > 0 && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
1731 $sendTemplateParams['isEmailPdf'] = TRUE;
1732 $sendTemplateParams['contributionId'] = $contributionId;
1734 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1736 $sent[] = $contactID;
1737 foreach ($participants as $ids => $values) {
1738 if ($values->contact_id
== $contactID) {
1739 $values->details
= CRM_Utils_Array
::value('receipt_text', $params);
1740 CRM_Activity_BAO_Activity
::addActivity($values, 'Email');
1746 $notSent[] = $contactID;
1751 // set the participant id if it is not set
1753 $this->_id
= $participants[0]->id
;
1756 return $this->getStatusMsg($params, $sent, $updateStatusMsg, $notSent);
1760 * Set the various IDs relating to custom data types.
1762 public function setCustomDataTypes() {
1763 $customDataType = CRM_Core_OptionGroup
::values('custom_data_type', FALSE, FALSE, FALSE, NULL, 'name');
1764 $this->_roleCustomDataTypeID
= array_search('ParticipantRole', $customDataType);
1765 $this->_eventNameCustomDataTypeID
= array_search('ParticipantEventName', $customDataType);
1766 $this->_eventTypeCustomDataTypeID
= array_search('ParticipantEventType', $customDataType);
1767 $this->assign('roleCustomDataTypeID', $this->_roleCustomDataTypeID
);
1768 $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID
);
1769 $this->assign('eventTypeCustomDataTypeID', $this->_eventTypeCustomDataTypeID
);
1773 * Get status message
1775 * @param array $params
1777 * @param string $updateStatusMsg
1778 * @param int $notSent
1782 protected function getStatusMsg($params, $sent, $updateStatusMsg, $notSent) {
1784 if (($this->_action
& CRM_Core_Action
::UPDATE
)) {
1785 $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contributorDisplayName
));
1786 if (!empty($params['send_receipt']) && count($sent)) {
1787 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', array(1 => $this->_contributorEmail
));
1790 if ($updateStatusMsg) {
1791 $statusMsg = "{$statusMsg} {$updateStatusMsg}";
1794 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
1795 if ($this->_single
) {
1796 $statusMsg = ts('Event registration for %1 has been added.', array(1 => $this->_contributorDisplayName
));
1797 if (!empty($params['send_receipt']) && count($sent)) {
1798 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $this->_contributorEmail
));
1802 $statusMsg = ts('Total Participant(s) added to event: %1.', array(1 => count($this->_contactIds
)));
1803 if (count($notSent) > 0) {
1804 $statusMsg .= ' ' . ts('Email has NOT been sent to %1 contact(s) - communication preferences specify DO NOT EMAIL OR valid Email is NOT present. ', array(1 => count($notSent)));
1806 elseif (isset($params['send_receipt'])) {
1807 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');