3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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-2016
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;
88 * The id of the contact associated with this participation.
95 * Array of event values.
102 * Are we operating in "single mode", i.e. adding / editing only
103 * one participant record, or is this a batch add operation
107 public $_single = FALSE;
110 * If event is paid or unpaid.
112 public $_isPaidEvent;
122 protected $_roleId = NULL;
127 protected $_eventTypeId = NULL;
130 * Participant status Id.
132 protected $_statusId = NULL;
135 * Cache all the participant statuses.
137 protected $_participantStatuses;
142 public $_mode = NULL;
145 * Event ID preselect.
150 * Line Item for Price Set.
152 public $_lineItem = NULL;
155 * Contribution mode for event registration for offline mode.
159 public $_contributeMode = 'direct';
164 * Store id of role custom data type ( option value )
166 protected $_roleCustomDataTypeID;
169 * Store id of event Name custom data type ( option value)
171 protected $_eventNameCustomDataTypeID;
174 * Selected discount id.
176 public $_originalDiscountId = NULL;
181 public $_eventId = NULL;
184 * Id of payment, if any
186 public $_paymentId = NULL;
189 * @todo add explanatory note about this
192 public $_onlinePendingContributionId = NULL;
195 * Explicitly declare the entity api name.
197 public function getDefaultEntity() {
198 return 'Participant';
202 * Set variables up before form is built.
206 public function preProcess() {
207 $this->_showFeeBlock
= CRM_Utils_Array
::value('eventId', $_GET);
208 $this->assign('showFeeBlock', FALSE);
209 $this->assign('feeBlockPaid', FALSE);
211 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
212 $this->_mode
= CRM_Utils_Request
::retrieve('mode', 'String', $this);
213 $this->_eID
= CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
214 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this);
215 $this->assign('context', $this->_context
);
217 if ($this->_contactId
) {
218 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
219 $this->assign('displayName', $displayName);
220 $this->setPageTitle(ts('Event Registration for %1', array(1 => $displayName)));
223 $this->setPageTitle(ts('Event Registration'));
226 // check the current path, if search based, then dont get participantID
228 $path = CRM_Utils_System
::currentPath();
230 strpos($path, 'civicrm/contact/search') === 0 ||
231 strpos($path, 'civicrm/group/search') === 0
236 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
240 $this->assign('participantId', $this->_id
);
242 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
243 $this->_id
, 'id', 'participant_id'
246 $this->assign('hasPayment', $this->_paymentId
);
248 // CRM-12615 - Get payment information from the primary registration
249 if ((!$this->_paymentId
) && ($this->_action
== CRM_Core_Action
::UPDATE
)) {
250 $registered_by_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
251 $this->_id
, 'registered_by_id', 'id'
253 if ($registered_by_id) {
254 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
255 $registered_by_id, 'id', 'participant_id'
257 $this->assign('registeredByParticipantId', $registered_by_id);
262 // get the option value for custom data type
263 $this->_roleCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantRole', 'name');
264 $this->_eventNameCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantEventName', 'name');
265 $this->_eventTypeCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantEventType', 'name');
266 $this->assign('roleCustomDataTypeID', $this->_roleCustomDataTypeID
);
267 $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID
);
268 $this->assign('eventTypeCustomDataTypeID', $this->_eventTypeCustomDataTypeID
);
271 $this->assign('participantMode', $this->_mode
);
272 $this->assignPaymentRelatedVariables();
275 if ($this->_showFeeBlock
) {
276 $this->assign('showFeeBlock', TRUE);
277 $isMonetary = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_showFeeBlock
, 'is_monetary');
279 $this->assign('feeBlockPaid', TRUE);
281 return CRM_Event_Form_EventFees
::preProcess($this);
284 //check the mode when this form is called either single or as
286 if ($this->_id ||
$this->_contactId ||
$this->_context
== 'standalone') {
287 $this->_single
= TRUE;
288 $this->assign('urlPath', 'civicrm/contact/view/participant');
289 if (!$this->_id
&& !$this->_contactId
) {
290 $breadCrumbs = array(
292 'title' => ts('CiviEvent Dashboard'),
293 'url' => CRM_Utils_System
::url('civicrm/event', 'reset=1'),
297 CRM_Utils_System
::appendBreadCrumb($breadCrumbs);
301 //set the appropriate action
302 $context = $this->get('context');
303 $urlString = 'civicrm/contact/search';
304 $this->_action
= CRM_Core_Action
::BASIC
;
307 $urlString = 'civicrm/contact/search/advanced';
308 $this->_action
= CRM_Core_Action
::ADVANCED
;
312 $urlString = 'civicrm/contact/search/builder';
313 $this->_action
= CRM_Core_Action
::PROFILE
;
317 $urlString = 'civicrm/contact/search/basic';
318 $this->_action
= CRM_Core_Action
::BASIC
;
322 $urlString = 'civicrm/contact/search/custom';
323 $this->_action
= CRM_Core_Action
::COPY
;
326 CRM_Contact_Form_Task
::preProcessCommon($this);
328 $this->_single
= FALSE;
329 $this->_contactId
= NULL;
331 //set ajax path, this used for custom data building
332 $this->assign('urlPath', $urlString);
333 $this->assign('urlPathVar', "_qf_Participant_display=true&qfKey={$this->controller->_key}");
336 $this->assign('single', $this->_single
);
339 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
341 $this->assign('action', $this->_action
);
343 // check for edit permission
344 if (!CRM_Core_Permission
::checkActionPermission('CiviEvent', $this->_action
)) {
345 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
348 if ($this->_action
& CRM_Core_Action
::DELETE
) {
349 // check delete permission for contribution
350 if ($this->_id
&& $this->_paymentId
&& !CRM_Core_Permission
::checkActionPermission('CiviContribute', $this->_action
)) {
351 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."));
357 // assign participant id to the template
358 $this->assign('participantId', $this->_id
);
359 $this->_roleId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'role_id');
362 // when fee amount is included in form
363 if (!empty($_POST['hidden_feeblock']) ||
!empty($_POST['send_receipt'])) {
364 CRM_Event_Form_EventFees
::preProcess($this);
365 CRM_Event_Form_EventFees
::buildQuickForm($this);
366 CRM_Event_Form_EventFees
::setDefaultValues($this);
369 // when custom data is included in this page
370 if (!empty($_POST['hidden_custom'])) {
371 // Custom data of type participant role
372 // Note: Some earlier commits imply $_POST['role_id'] could be a comma separated string,
373 // not sure if that ever really happens
374 if (!empty($_POST['role_id'])) {
375 foreach ($_POST['role_id'] as $roleID) {
376 CRM_Custom_Form_CustomData
::preProcess($this, $this->_roleCustomDataTypeID
, $roleID, 1, 'Participant', $this->_id
);
377 CRM_Custom_Form_CustomData
::buildQuickForm($this);
378 CRM_Custom_Form_CustomData
::setDefaultValues($this);
382 //custom data of type participant event
383 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventNameCustomDataTypeID
, $_POST['event_id'], 1, 'Participant', $this->_id
);
384 CRM_Custom_Form_CustomData
::buildQuickForm($this);
385 CRM_Custom_Form_CustomData
::setDefaultValues($this);
387 // custom data of type participant event type
389 if ($eventId = CRM_Utils_Array
::value('event_id', $_POST)) {
390 $eventTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'event_type_id', 'id');
392 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventTypeCustomDataTypeID
, $eventTypeId,
393 1, 'Participant', $this->_id
395 CRM_Custom_Form_CustomData
::buildQuickForm($this);
396 CRM_Custom_Form_CustomData
::setDefaultValues($this);
398 //custom data of type participant, ( we 'null' to reset subType and subName)
399 CRM_Custom_Form_CustomData
::preProcess($this, 'null', 'null', 1, 'Participant', $this->_id
);
400 CRM_Custom_Form_CustomData
::buildQuickForm($this);
401 CRM_Custom_Form_CustomData
::setDefaultValues($this);
404 // CRM-4395, get the online pending contribution id.
405 $this->_onlinePendingContributionId
= NULL;
406 if (!$this->_mode
&& $this->_id
&& ($this->_action
& CRM_Core_Action
::UPDATE
)) {
407 $this->_onlinePendingContributionId
= CRM_Contribute_BAO_Contribution
::checkOnlinePendingContribution($this->_id
,
411 $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId
);
415 * This function sets the default values for the form in edit/view mode
416 * the default values are retrieved from the database
421 public function setDefaultValues() {
422 if ($this->_showFeeBlock
) {
423 return CRM_Event_Form_EventFees
::setDefaultValues($this);
428 if ($this->_action
& CRM_Core_Action
::DELETE
) {
434 $params = array('id' => $this->_id
);
436 CRM_Event_BAO_Participant
::getValues($params, $defaults, $ids);
437 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
438 if ($defaults[$this->_id
]['role_id']) {
439 $roleIDs = explode($sep, $defaults[$this->_id
]['role_id']);
441 $this->_contactId
= $defaults[$this->_id
]['contact_id'];
442 $this->_statusId
= $defaults[$this->_id
]['participant_status_id'];
444 //set defaults for note
445 $noteDetails = CRM_Core_BAO_Note
::getNote($this->_id
, 'civicrm_participant');
446 $defaults[$this->_id
]['note'] = array_pop($noteDetails);
448 // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859)
449 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
450 $this->assign('additionalParticipants', CRM_Event_BAO_Participant
::getAdditionalParticipants($this->_id
));
453 // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
454 if (!empty($defaults[$this->_id
]['participant_registered_by_id'])) {
455 $registered_by_contact_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
456 $defaults[$this->_id
]['participant_registered_by_id'],
459 $this->assign('participant_registered_by_id', $defaults[$this->_id
]['participant_registered_by_id']);
460 $this->assign('registered_by_contact_id', $registered_by_contact_id);
461 $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact
::displayName($registered_by_contact_id));
465 if ($this->_action
& (CRM_Core_Action
::VIEW | CRM_Core_Action
::BROWSE
)) {
466 $inactiveNeeded = TRUE;
471 $inactiveNeeded = FALSE;
474 //setting default register date
475 if ($this->_action
== CRM_Core_Action
::ADD
) {
476 $statuses = array_flip($this->_participantStatuses
);
477 $defaults[$this->_id
]['status_id'] = CRM_Utils_Array
::value(ts('Registered'), $statuses);
478 if (!empty($defaults[$this->_id
]['event_id'])) {
479 $contributionTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
480 $defaults[$this->_id
]['event_id'],
483 if ($contributionTypeId) {
484 $defaults[$this->_id
]['financial_type_id'] = $contributionTypeId;
489 $fields["email-{$this->_bltID}"] = 1;
490 $fields['email-Primary'] = 1;
492 if ($this->_contactId
) {
493 CRM_Core_BAO_UFGroup
::setProfileDefaults($this->_contactId
, $fields, $defaults);
496 if (empty($defaults["email-{$this->_bltID}"]) &&
497 !empty($defaults['email-Primary'])
499 $defaults[$this->_id
]["email-{$this->_bltID}"] = $defaults['email-Primary'];
503 $submittedRole = $this->getElementValue('role_id');
504 if (!empty($submittedRole[0])) {
505 $roleID = $submittedRole[0];
507 $submittedEvent = $this->getElementValue('event_id');
508 if (!empty($submittedEvent[0])) {
509 $eventID = $submittedEvent[0];
513 $defaults[$this->_id
]['record_contribution'] = 0;
515 if ($defaults[$this->_id
]['participant_is_pay_later']) {
516 $this->assign('participant_is_pay_later', TRUE);
519 $this->assign('participant_status_id', $defaults[$this->_id
]['participant_status_id']);
520 $eventID = $defaults[$this->_id
]['event_id'];
522 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
524 $this->_discountId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'discount_id');
525 if ($this->_discountId
) {
526 $this->set('discountId', $this->_discountId
);
530 list($defaults[$this->_id
]['register_date'], $defaults[$this->_id
]['register_date_time'])
531 = CRM_Utils_Date
::setDateDefaults(CRM_Utils_Array
::value('register_date', $defaults[$this->_id
]), 'activityDateTime');
533 //assign event and role id, this is needed for Custom data building
534 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
535 if (!empty($defaults[$this->_id
]['participant_role_id'])) {
536 $roleIDs = explode($sep, $defaults[$this->_id
]['participant_role_id']);
538 if (isset($_POST['event_id'])) {
539 $eventID = $_POST['event_id'];
543 $eventID = $this->_eID
;
544 //@todo - rationalise the $this->_eID with $POST['event_id'], $this->_eid is set when eid=x is in the url
545 $roleID = CRM_Core_DAO
::getFieldValue(
546 'CRM_Event_DAO_Event',
550 if (empty($roleIDs)) {
551 $roleIDs = (array) $defaults[$this->_id
]['participant_role_id'] = $roleID;
553 $defaults[$this->_id
]['event_id'] = $eventID;
555 if (!empty($eventID)) {
556 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
558 //these should take precedence so we state them last
559 $urlRoleIDS = CRM_Utils_Request
::retrieve('roles', 'String');
561 $roleIDs = explode(',', $urlRoleIDS);
563 if (isset($roleIDs)) {
564 $defaults[$this->_id
]['role_id'] = implode(',', $roleIDs);
567 if (isset($eventID)) {
568 $this->assign('eventID', $eventID);
569 $this->set('eventId', $eventID);
572 if (isset($this->_eventTypeId
)) {
573 $this->assign('eventTypeID', $this->_eventTypeId
);
576 $this->assign('event_is_test', CRM_Utils_Array
::value('event_is_test', $defaults[$this->_id
]));
577 return $defaults[$this->_id
];
581 * Build the form object.
585 public function buildQuickForm() {
586 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
587 $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses);
588 $this->assign('partiallyPaidStatusId', $partiallyPaidStatusId);
590 if ($this->_showFeeBlock
) {
591 return CRM_Event_Form_EventFees
::buildQuickForm($this);
594 //need to assign custom data type to the template
595 $this->assign('customDataType', 'Participant');
597 $this->applyFilter('__ALL__', 'trim');
599 if ($this->_action
& CRM_Core_Action
::DELETE
) {
600 if ($this->_single
) {
601 $additionalParticipant = count(CRM_Event_BAO_Event
::buildCustomProfile($this->_id
,
607 if ($additionalParticipant) {
608 $deleteParticipants = array(
609 1 => ts('Delete this participant record along with associated participant record(s).'),
610 2 => ts('Delete only this participant record.'),
612 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
613 $this->setDefaults(array('delete_participant' => 1));
614 $this->assign('additionalParticipant', $additionalParticipant);
617 $this->addButtons(array(
620 'name' => ts('Delete'),
621 'spacing' => ' ',
626 'name' => ts('Cancel'),
633 if ($this->_single
&& $this->_context
== 'standalone') {
634 $this->addEntityRef('contact_id', ts('Contact'), array(
636 'api' => array('extra' => array('email')),
640 $eventFieldParams = array(
642 'select' => array('minimumInputLength' => 0),
644 'extra' => array('campaign_id', 'default_role_id', 'event_type_id'),
649 // exclude events which are not monetary when credit card registration is used
650 $eventFieldParams['api']['params']['is_monetary'] = 1;
651 $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors
, TRUE);
654 $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE);
656 //frozen the field fix for CRM-4171
657 if ($this->_action
& CRM_Core_Action
::UPDATE
&& $this->_id
) {
658 if (CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
659 $this->_id
, 'contribution_id', 'participant_id'
666 //CRM-7362 --add campaigns.
669 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'campaign_id');
672 $eventId = CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
674 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
677 CRM_Campaign_BAO_Campaign
::addCampaign($this, $campaignId);
679 $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
682 $this->assign('entityID', $this->_id
);
685 $this->addSelect('role_id', array('multiple' => TRUE, 'class' => 'huge'), TRUE);
688 $checkCancelledJs = array('onchange' => "return sendNotification( );");
690 if ($this->_onlinePendingContributionId
) {
691 $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant
::participantStatus());
692 $cancelledContributionStatusId = array_search('Cancelled',
693 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
695 $checkCancelledJs = array(
696 'onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});",
699 $participantStatusId = array_search('Pending from pay later',
700 CRM_Event_PseudoConstant
::participantStatus()
702 $contributionStatusId = array_search('Completed',
703 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
705 $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
708 // get the participant status names to build special status array which is used to show notification
709 // checkbox below participant status select
710 $participantStatusName = CRM_Event_PseudoConstant
::participantStatus();
711 $notificationStatuses = array(
713 'Pending from waitlist',
714 'Pending from approval',
718 // get the required status and then implode only ids
719 $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
720 $this->assign('notificationStatusIds', $notificationStatusIds);
722 $this->_participantStatuses
= $statusOptions = CRM_Event_BAO_Participant
::buildOptions('status_id', 'create');
724 // Only show refund status when editing
725 if ($this->_action
& CRM_Core_Action
::ADD
) {
726 $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
727 if ($pendingRefundStatusId) {
728 unset($statusOptions[$pendingRefundStatusId]);
732 $this->addSelect('status_id', $checkCancelledJs +
array(
733 'options' => $statusOptions,
734 'option_url' => 'civicrm/admin/participant_status',
737 $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
739 $this->add('text', 'source', ts('Event Source'));
740 $noteAttributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Note');
741 $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
745 'name' => ts('Save'),
750 $path = CRM_Utils_System
::currentPath();
751 $excludeForPaths = array(
752 'civicrm/contact/search',
753 'civicrm/group/search',
755 if (!in_array($path, $excludeForPaths)) {
758 'name' => ts('Save and New'),
766 'name' => ts('Cancel'),
769 $this->addButtons($buttons);
770 if ($this->_action
== CRM_Core_Action
::VIEW
) {
776 * Add local and global form rules.
781 public function addRules() {
782 $this->addFormRule(array('CRM_Event_Form_Participant', 'formRule'), $this);
786 * Global validation rules for the form.
788 * @param array $values
789 * Posted values of the form.
794 * list of errors to be posted back to the form
796 public static function formRule($values, $files, $self) {
797 // If $values['_qf_Participant_next'] is Delete or
798 // $values['event_id'] is empty, then return
799 // instead of proceeding further.
801 if ((CRM_Utils_Array
::value('_qf_Participant_next', $values) == 'Delete') ||
802 (!$values['event_id'])
809 if (!empty($values['payment_processor_id'])) {
810 // make sure that payment instrument values (e.g. credit card number and cvv) are valid
811 CRM_Core_Payment_Form
::validatePaymentInstrument($values['payment_processor_id'], $values, $errorMsg, NULL);
814 if (!empty($values['record_contribution'])) {
815 if (empty($values['financial_type_id'])) {
816 $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
818 if (empty($values['payment_instrument_id'])) {
819 $errorMsg['payment_instrument_id'] = ts('Payment Method is a required field.');
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 $dupeCheck = new CRM_Event_BAO_Participant();
856 $dupeCheck->contact_id
= $contactId;
857 $dupeCheck->event_id
= $eventId;
858 $dupeCheck->find(TRUE);
859 if (!empty($dupeCheck->id
)) {
860 $errorMsg['event_id'] = ts("This contact has already been assigned to this event.");
864 return CRM_Utils_Array
::crmIsEmptyArray($errorMsg) ?
TRUE : $errorMsg;
868 * Process the form submission.
870 public function postProcess() {
871 // get the submitted form values.
872 $params = $this->controller
->exportValues($this->_name
);
874 if ($this->_action
& CRM_Core_Action
::DELETE
) {
875 if (CRM_Utils_Array
::value('delete_participant', $params) == 2) {
876 $additionalId = (CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
));
877 $participantLinks = (CRM_Event_BAO_Participant
::getAdditionalParticipantUrl($additionalId));
879 if (CRM_Utils_Array
::value('delete_participant', $params) == 1) {
880 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
881 foreach ($additionalIds as $value) {
882 CRM_Event_BAO_Participant
::deleteParticipant($value);
885 CRM_Event_BAO_Participant
::deleteParticipant($this->_id
);
886 CRM_Core_Session
::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success');
887 if (!empty($participantLinks)) {
888 $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;
889 CRM_Core_Session
::setStatus($status, ts('Group Payment Deleted'));
893 // When adding a single contact, the formRule prevents you from adding duplicates
894 // (See above in formRule()). When adding more than one contact, the duplicates are
895 // removed automatically and the user receives one notification.
896 if ($this->_action
& CRM_Core_Action
::ADD
) {
897 $event_id = $this->_eventId
;
898 if (empty($event_id) && !empty($params['event_id'])) {
899 $event_id = $params['event_id'];
901 if (!$this->_single
&& !empty($event_id)) {
902 $duplicateContacts = 0;
903 while (list($k, $dupeCheckContactId) = each($this->_contactIds
)) {
904 // Eliminate contacts that have already been assigned to this event.
905 $dupeCheck = new CRM_Event_BAO_Participant();
906 $dupeCheck->contact_id
= $dupeCheckContactId;
907 $dupeCheck->event_id
= $event_id;
908 $dupeCheck->find(TRUE);
909 if (!empty($dupeCheck->id
)) {
910 $duplicateContacts++
;
911 unset($this->_contactIds
[$k]);
914 if ($duplicateContacts > 0) {
916 "%1 contacts have already been assigned to this event. They were not added a second time.",
917 array(1 => $duplicateContacts)
919 CRM_Core_Session
::setStatus($msg);
921 if (count($this->_contactIds
) == 0) {
922 CRM_Core_Session
::setStatus(ts("No participants were added."));
925 // We have to re-key $this->_contactIds so each contact has the same
926 // key as their corresponding record in the $participants array that
927 // will be created below.
928 $this->_contactIds
= array_values($this->_contactIds
);
932 $participantStatus = CRM_Event_PseudoConstant
::participantStatus();
933 // set the contact, when contact is selected
934 if (!empty($params['contact_id'])) {
935 $this->_contactId
= $params['contact_id'];
937 if ($this->_priceSetId
&& $isQuickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
938 $this->_quickConfig
= $isQuickConfig;
942 $params['id'] = $this->_id
;
945 $config = CRM_Core_Config
::singleton();
946 if ($this->_isPaidEvent
) {
948 $contributionParams = array();
950 $additionalParticipantDetails = array();
951 if (CRM_Contribute_BAO_Contribution
::checkContributeSettings('deferred_revenue_enabled')) {
952 $eventStartDate = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_eventId
, 'start_date');
953 if ($eventStartDate) {
954 $contributionParams['revenue_recognition_date'] = date('Ymd', strtotime($eventStartDate));
957 if (($this->_id
&& $this->_action
& CRM_Core_Action
::UPDATE
) && $this->_paymentId
) {
958 $participantBAO = new CRM_Event_BAO_Participant();
959 $participantBAO->id
= $this->_id
;
960 $participantBAO->find(TRUE);
961 $contributionParams['total_amount'] = $participantBAO->fee_amount
;
963 $params['discount_id'] = NULL;
964 //re-enter the values for UPDATE mode
965 $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level
;
966 $params['fee_amount'] = $participantBAO->fee_amount
;
967 if (isset($params['priceSetId'])) {
968 $lineItem[0] = CRM_Price_BAO_LineItem
::getLineItems($this->_id
);
970 //also add additional participant's fee level/priceset
971 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
972 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
973 $hasLineItems = CRM_Utils_Array
::value('priceSetId', $params, FALSE);
974 $additionalParticipantDetails = CRM_Event_BAO_Participant
::getFeeDetails($additionalIds,
981 //check if discount is selected
982 if (!empty($params['discount_id'])) {
983 $discountId = $params['discount_id'];
986 $discountId = $params['discount_id'] = 'null';
989 //lets carry currency, CRM-4453
990 $params['fee_currency'] = $config->defaultCurrency
;
991 CRM_Price_BAO_PriceSet
::processAmount($this->_values
['fee'],
992 $params, $lineItem[0]
994 //CRM-11529 for quick config backoffice transactions
995 //when financial_type_id is passed in form, update the
996 //lineitems with the financial type selected in form
997 $submittedFinancialType = CRM_Utils_Array
::value('financial_type_id', $params);
998 $isPaymentRecorded = CRM_Utils_Array
::value('record_contribution', $params);
999 if ($isPaymentRecorded && $this->_quickConfig
&& $submittedFinancialType) {
1000 foreach ($lineItem[0] as &$values) {
1001 $values['financial_type_id'] = $submittedFinancialType;
1005 $params['fee_level'] = $params['amount_level'];
1006 $contributionParams['total_amount'] = $params['amount'];
1007 if ($this->_quickConfig
&& !empty($params['total_amount']) &&
1008 $params['status_id'] != array_search('Partially paid', $participantStatus)
1010 $params['fee_amount'] = $params['total_amount'];
1014 $params['fee_amount'] = $params['amount'];
1018 if (isset($params['priceSetId'])) {
1019 if (!empty($lineItem[0])) {
1020 $this->set('lineItem', $lineItem);
1022 $this->_lineItem
= $lineItem;
1023 $lineItem = array_merge($lineItem, $additionalParticipantDetails);
1025 $participantCount = array();
1026 foreach ($lineItem as $k) {
1027 foreach ($k as $v) {
1028 if (CRM_Utils_Array
::value('participant_count', $v) > 0) {
1029 $participantCount[] = $v['participant_count'];
1034 if (isset($participantCount)) {
1035 $this->assign('pricesetFieldsCount', $participantCount);
1037 $this->assign('lineItem', empty($lineItem[0]) ||
$this->_quickConfig ?
FALSE : $lineItem);
1040 $this->assign('amount_level', $params['amount_level']);
1044 $this->_params
= $params;
1046 if (isset($params['amount'])) {
1047 $amountOwed = $params['amount'];
1048 unset($params['amount']);
1050 $params['register_date'] = CRM_Utils_Date
::processDate($params['register_date'], $params['register_date_time']);
1051 $params['receive_date'] = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('receive_date', $params), CRM_Utils_Array
::value('receive_date_time', $params));
1052 $params['contact_id'] = $this->_contactId
;
1054 // overwrite actual payment amount if entered
1055 if (!empty($params['total_amount'])) {
1056 $contributionParams['total_amount'] = CRM_Utils_Array
::value('total_amount', $params);
1059 // Retrieve the name and email of the current user - this will be the FROM for the receipt email
1060 $userName = CRM_Core_Session
::singleton()->getLoggedInContactDisplayName();
1062 if ($this->_contactId
) {
1063 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($this->_contactId
);
1066 //modify params according to parameter used in create
1067 //participant method (addParticipant)
1068 $this->_params
['participant_status_id'] = $params['status_id'];
1069 $this->_params
['participant_role_id'] = is_array($params['role_id']) ?
$params['role_id'] : explode(',', $params['role_id']);
1070 $this->_params
['participant_register_date'] = $params['register_date'];
1071 $roleIdWithSeparator = implode(CRM_Core_DAO
::VALUE_SEPARATOR
, $this->_params
['participant_role_id']);
1074 if (!$this->_isPaidEvent
) {
1075 CRM_Core_Error
::fatal(ts('Selected Event is not Paid Event '));
1079 = CRM_Core_DAO
::getFieldValue(
1080 'CRM_Event_DAO_Event',
1081 $params['event_id'],
1085 // set source if not set
1086 if (empty($params['source'])) {
1087 $this->_params
['participant_source'] = ts('Offline Registration for Event: %2 by: %1', array(
1093 $this->_params
['participant_source'] = $params['source'];
1095 $this->_params
['description'] = $this->_params
['participant_source'];
1097 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($this->_params
['payment_processor_id'],
1100 $now = date('YmdHis');
1103 // set email for primary location.
1104 $fields['email-Primary'] = 1;
1105 $params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail
;
1107 $params['register_date'] = $now;
1109 // now set the values for the billing location.
1110 foreach ($this->_fields
as $name => $dontCare) {
1114 // also add location name to the array
1115 $params["address_name-{$this->_bltID}"]
1116 = CRM_Utils_Array
::value('billing_first_name', $params) . ' ' .
1117 CRM_Utils_Array
::value('billing_middle_name', $params) . ' ' .
1118 CRM_Utils_Array
::value('billing_last_name', $params);
1120 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
1121 $fields["address_name-{$this->_bltID}"] = 1;
1122 $fields["email-{$this->_bltID}"] = 1;
1123 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'contact_type');
1125 $nameFields = array('first_name', 'middle_name', 'last_name');
1127 foreach ($nameFields as $name) {
1129 if (array_key_exists("billing_$name", $params)) {
1130 $params[$name] = $params["billing_{$name}"];
1131 $params['preserveDBName'] = TRUE;
1134 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params, $fields, $this->_contactId
, NULL, NULL, $ctype);
1137 if (!empty($this->_params
['participant_role_id'])) {
1138 $customFieldsRole = array();
1139 foreach ($this->_params
['participant_role_id'] as $roleKey) {
1140 $customFieldsRole = CRM_Utils_Array
::crmArrayMerge(CRM_Core_BAO_CustomField
::getFields('Participant',
1141 FALSE, FALSE, $roleKey, $this->_roleCustomDataTypeID
), $customFieldsRole);
1143 $customFieldsEvent = CRM_Core_BAO_CustomField
::getFields('Participant',
1146 CRM_Utils_Array
::value('event_id', $params),
1147 $this->_eventNameCustomDataTypeID
1149 $customFieldsEventType = CRM_Core_BAO_CustomField
::getFields('Participant',
1152 $this->_eventTypeId
,
1153 $this->_eventTypeCustomDataTypeID
1155 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsRole,
1156 CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE)
1158 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEvent, $customFields);
1159 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEventType, $customFields);
1160 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
1166 //do cleanup line items if participant edit the Event Fee.
1167 if (($this->_lineItem ||
!isset($params['proceSetId'])) && !$this->_paymentId
&& $this->_id
) {
1168 CRM_Price_BAO_LineItem
::deleteLineItems($this->_id
, 'civicrm_participant');
1172 // add all the additional payment params we need
1173 $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}"]);
1174 $this->_params
["country-{$this->_bltID}"] = $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
1176 $this->_params
['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($this->_params
);
1177 $this->_params
['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($this->_params
);
1178 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
1179 $this->_params
['amount'] = $params['fee_amount'];
1180 $this->_params
['amount_level'] = $params['amount_level'];
1181 $this->_params
['currencyID'] = $config->defaultCurrency
;
1182 $this->_params
['invoiceID'] = md5(uniqid(rand(), TRUE));
1184 // at this point we've created a contact and stored its address etc
1185 // all the payment processors expect the name and address to be in the
1186 // so we copy stuff over to first_name etc.
1187 $paymentParams = $this->_params
;
1188 if (!empty($this->_params
['send_receipt'])) {
1189 $paymentParams['email'] = $this->_contributorEmail
;
1192 // The only reason for merging in the 'contact_id' rather than ensuring it is set
1193 // is that this patch is being done around the time of the stable release
1194 // so more conservative approach is called for.
1195 // In fact the use of $params and $this->_params & $this->_contactId vs $contactID
1196 // needs rationalising.
1197 $mapParams = array_merge(array('contact_id' => $contactID), $this->_params
);
1198 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $mapParams, $paymentParams, TRUE);
1200 $payment = $this->_paymentProcessor
['object'];
1202 // CRM-15622: fix for incorrect contribution.fee_amount
1203 $paymentParams['fee_amount'] = NULL;
1204 $result = $payment->doPayment($paymentParams);
1206 if (is_a($result, 'CRM_Core_Error')) {
1207 CRM_Core_Error
::displaySessionError($result);
1208 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/view/participant',
1209 "reset=1&action=add&cid={$this->_contactId}&context=participant&mode={$this->_mode}"
1214 $this->_params
= array_merge($this->_params
, $result);
1217 $this->_params
['receive_date'] = $now;
1219 if (!empty($this->_params
['send_receipt'])) {
1220 $this->_params
['receipt_date'] = $now;
1223 $this->_params
['receipt_date'] = NULL;
1226 $this->set('params', $this->_params
);
1227 $this->assign('trxn_id', $result['trxn_id']);
1228 $this->assign('receive_date',
1229 CRM_Utils_Date
::processDate($this->_params
['receive_date'])
1232 //add contribution record
1233 $this->_params
['financial_type_id']
1234 = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
1235 $this->_params
['mode'] = $this->_mode
;
1237 //add contribution record
1238 $contributions[] = $contribution = CRM_Event_Form_Registration_Confirm
::processContribution($this, $this->_params
, $result, $contactID, FALSE);
1240 // add participant record
1241 $participants = array();
1242 if (!empty($this->_params
['role_id']) && is_array($this->_params
['role_id'])) {
1243 $this->_params
['role_id'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1244 $this->_params
['role_id']
1248 //CRM-15372 patch to fix fee amount replacing amount
1249 $this->_params
['fee_amount'] = $this->_params
['amount'];
1251 $participants[] = CRM_Event_Form_Registration
::addParticipant($this, $contactID);
1253 //add custom data for participant
1254 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
1255 'civicrm_participant',
1256 $participants[0]->id
,
1259 //add participant payment
1260 $paymentParticipant = array(
1261 'participant_id' => $participants[0]->id
,
1262 'contribution_id' => $contribution->id
,
1266 CRM_Event_BAO_ParticipantPayment
::create($paymentParticipant, $ids);
1267 $this->_contactIds
[] = $this->_contactId
;
1270 $participants = array();
1271 if ($this->_single
) {
1272 if ($params['role_id']) {
1273 $params['role_id'] = $roleIdWithSeparator;
1276 $params['role_id'] = 'NULL';
1278 $participants[] = CRM_Event_BAO_Participant
::create($params);
1281 foreach ($this->_contactIds
as $contactID) {
1282 $commonParams = $params;
1283 $commonParams['contact_id'] = $contactID;
1284 if ($commonParams['role_id']) {
1285 $commonParams['role_id'] = $commonParams['role_id'] = str_replace(',', CRM_Core_DAO
::VALUE_SEPARATOR
, $params['role_id']);
1288 $commonParams['role_id'] = 'NULL';
1290 $participants[] = CRM_Event_BAO_Participant
::create($commonParams);
1294 if (isset($params['event_id'])) {
1295 $eventTitle = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
1296 $params['event_id'],
1301 if ($this->_single
) {
1302 $this->_contactIds
[] = $this->_contactId
;
1305 $contributions = array();
1306 if (!empty($params['record_contribution'])) {
1307 if (!empty($params['id'])) {
1308 if ($this->_onlinePendingContributionId
) {
1309 $ids['contribution'] = $this->_onlinePendingContributionId
;
1312 $ids['contribution'] = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1319 unset($params['note']);
1321 //build contribution params
1322 if (!$this->_onlinePendingContributionId
) {
1323 if (empty($params['source'])) {
1324 $contributionParams['source'] = ts('%1 : Offline registration (by %2)', array(
1330 $contributionParams['source'] = $params['source'];
1334 $contributionParams['currency'] = $config->defaultCurrency
;
1335 $contributionParams['non_deductible_amount'] = 'null';
1336 $contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array
::value('receive_date', $params) : 'null';
1338 $recordContribution = array(
1340 'financial_type_id',
1341 'payment_instrument_id',
1343 'contribution_status_id',
1349 foreach ($recordContribution as $f) {
1350 $contributionParams[$f] = CRM_Utils_Array
::value($f, $params);
1351 if ($f == 'trxn_id') {
1352 $this->assign('trxn_id', $contributionParams[$f]);
1356 //insert financial type name in receipt.
1357 $this->assign('financialTypeName', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType',
1358 $contributionParams['financial_type_id']));
1360 $this->assign('contributionTypeName', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id']));
1361 $contributionParams['skipLineItem'] = 1;
1363 $contributionParams['contribution_mode'] = 'participant';
1364 $contributionParams['participant_id'] = $this->_id
;
1366 // Set is_pay_later flag for back-office offline Pending status contributions
1367 if ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup
::getValue('contribution_status', 'Pending', 'name')) {
1368 $contributionParams['is_pay_later'] = 1;
1370 elseif ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup
::getValue('contribution_status', 'Completed', 'name')) {
1371 $contributionParams['is_pay_later'] = 0;
1374 if ($params['status_id'] == array_search('Partially paid', $participantStatus)) {
1375 if (!$amountOwed && $this->_action
& CRM_Core_Action
::UPDATE
) {
1376 $amountOwed = $params['fee_amount'];
1379 // if multiple participants are link, consider contribution total amount as the amount Owed
1380 if ($this->_id
&& CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
1381 $amountOwed = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_Contribution',
1382 $ids['contribution'],
1387 // CRM-13964 partial_payment_total
1388 if ($amountOwed > $params['total_amount']) {
1390 $contributionParams['partial_payment_total'] = $amountOwed;
1391 // the actual amount paid
1392 $contributionParams['partial_amount_pay'] = $params['total_amount'];
1396 if (CRM_Utils_Array
::value('tax_amount', $this->_params
)) {
1397 $contributionParams['tax_amount'] = $this->_params
['tax_amount'];
1400 if ($this->_single
) {
1404 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1408 foreach ($this->_contactIds
as $contactID) {
1409 $contributionParams['contact_id'] = $contactID;
1410 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1414 //insert payment record for this participation
1415 if (empty($ids['contribution'])) {
1416 foreach ($this->_contactIds
as $num => $contactID) {
1417 $ppDAO = new CRM_Event_DAO_ParticipantPayment();
1418 $ppDAO->participant_id
= $participants[$num]->id
;
1419 $ppDAO->contribution_id
= $contributions[$num]->id
;
1423 // next create the transaction record
1424 $transaction = new CRM_Core_Transaction();
1427 if ($this->_params
['discount_id']) {
1428 CRM_Event_BAO_Participant
::createDiscountTrxn(
1430 $contributionParams,
1432 CRM_Price_BAO_PriceSet
::parseFirstPriceSetValueIDFromParams($this->_params
)
1435 $transaction->commit();
1439 // also store lineitem stuff here
1440 if ((($this->_lineItem
& $this->_action
& CRM_Core_Action
::ADD
) ||
1441 ($this->_lineItem
&& CRM_Core_Action
::UPDATE
&& !$this->_paymentId
))
1443 foreach ($this->_contactIds
as $num => $contactID) {
1444 foreach ($this->_lineItem
as $key => $value) {
1445 if (is_array($value) && $value != 'skip') {
1446 foreach ($value as $lineKey => $line) {
1447 //10117 update the line items for participants if contribution amount is recorded
1448 if ($this->_quickConfig
&& !empty($params['total_amount']) &&
1449 ($params['status_id'] != array_search('Partially paid', $participantStatus))
1451 $line['unit_price'] = $line['line_total'] = $params['total_amount'];
1452 if (!empty($params['tax_amount'])) {
1453 $line['unit_price'] = $line['unit_price'] - $params['tax_amount'];
1454 $line['line_total'] = $line['line_total'] - $params['tax_amount'];
1457 $lineItem[$this->_priceSetId
][$lineKey] = $line;
1459 CRM_Price_BAO_LineItem
::processPriceSet($participants[$num]->id
, $lineItem, CRM_Utils_Array
::value($num, $contributions, NULL), 'civicrm_participant');
1460 CRM_Contribute_BAO_Contribution
::addPayments($value, $contributions);
1466 $updateStatusMsg = NULL;
1467 //send mail when participant status changed, CRM-4326
1468 if ($this->_id
&& $this->_statusId
&&
1469 $this->_statusId
!= CRM_Utils_Array
::value('status_id', $params) && !empty($params['is_notify'])
1472 $updateStatusMsg = CRM_Event_BAO_Participant
::updateStatusMessage($this->_id
,
1473 $params['status_id'],
1480 if (!empty($params['send_receipt'])) {
1481 if (array_key_exists($params['from_email_address'], $this->_fromEmails
['from_email_id'])) {
1482 $receiptFrom = $params['from_email_address'];
1485 $this->assign('module', 'Event Registration');
1486 //use of the message template below requires variables in different format
1487 $event = $events = array();
1488 $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
1490 //get all event details.
1491 CRM_Core_DAO
::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
1492 $event = $events[$params['event_id']];
1493 unset($event['start_date']);
1494 unset($event['end_date']);
1496 $role = CRM_Event_PseudoConstant
::participantRole();
1497 $participantRoles = CRM_Utils_Array
::value('role_id', $params);
1498 if (is_array($participantRoles)) {
1499 $selectedRoles = array();
1500 foreach ($participantRoles as $roleId) {
1501 $selectedRoles[] = $role[$roleId];
1503 $event['participant_role'] = implode(', ', $selectedRoles);
1506 $event['participant_role'] = CRM_Utils_Array
::value($participantRoles, $role);
1508 $event['is_monetary'] = $this->_isPaidEvent
;
1510 if ($params['receipt_text']) {
1511 $event['confirm_email_text'] = $params['receipt_text'];
1514 $this->assign('isAmountzero', 1);
1515 $this->assign('event', $event);
1517 $this->assign('isShowLocation', $event['is_show_location']);
1518 if (CRM_Utils_Array
::value('is_show_location', $event) == 1) {
1519 $locationParams = array(
1520 'entity_id' => $params['event_id'],
1521 'entity_table' => 'civicrm_event',
1523 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
1524 $this->assign('location', $location);
1527 $status = CRM_Event_PseudoConstant
::participantStatus();
1528 if ($this->_isPaidEvent
) {
1529 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
1530 if (!$this->_mode
) {
1531 if (isset($params['payment_instrument_id'])) {
1532 $this->assign('paidBy',
1533 CRM_Utils_Array
::value($params['payment_instrument_id'],
1540 $this->assign('totalAmount', $contributionParams['total_amount']);
1541 if (isset($contributionParams['partial_payment_total'])) {
1543 $balanceAmount = $contributionParams['partial_payment_total'] - $contributionParams['partial_amount_pay'];
1544 $this->assign('balanceAmount', $balanceAmount);
1546 $this->assign('isPrimary', 1);
1547 $this->assign('checkNumber', CRM_Utils_Array
::value('check_number', $params));
1550 $this->assignBillingName($params);
1551 $this->assign('address', CRM_Utils_Address
::getFormattedBillingAddressFieldsFromParameters(
1556 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
1557 $date = CRM_Utils_Date
::mysqlToIso($date);
1558 $this->assign('credit_card_exp_date', $date);
1559 $this->assign('credit_card_number',
1560 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
1562 $this->assign('credit_card_type', $params['credit_card_type']);
1563 // The concept of contributeMode is deprecated.
1564 $this->assign('contributeMode', 'direct');
1565 $this->assign('isAmountzero', 0);
1566 $this->assign('is_pay_later', 0);
1567 $this->assign('isPrimary', 1);
1570 $this->assign('register_date', $params['register_date']);
1571 if ($params['receive_date']) {
1572 $this->assign('receive_date', $params['receive_date']);
1575 $participant = array(array('participant_id', '=', $participants[0]->id
, 0, 0));
1576 // check whether its a test drive ref CRM-3075
1577 if (!empty($this->_defaultValues
['is_test'])) {
1578 $participant[] = array('participant_test', '=', 1, 0, 0);
1581 $template = CRM_Core_Smarty
::singleton();
1582 $customGroup = array();
1583 //format submitted data
1584 foreach ($params['custom'] as $fieldID => $values) {
1585 foreach ($values as $fieldValue) {
1586 $customFields[$fieldID]['id'] = $fieldID;
1587 $formattedValue = CRM_Core_BAO_CustomField
::displayValue($fieldValue['value'], $fieldID, $participants[0]->id
);
1588 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace(' ', '', $formattedValue);
1592 foreach ($this->_contactIds
as $num => $contactID) {
1593 // Retrieve the name and email of the contact - this will be the TO for receipt email
1594 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($contactID);
1596 $this->_contributorDisplayName
= ($this->_contributorDisplayName
== ' ') ?
$this->_contributorEmail
: $this->_contributorDisplayName
;
1598 $waitStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
1599 if ($waitingStatus = CRM_Utils_Array
::value($params['status_id'], $waitStatus)) {
1600 $this->assign('isOnWaitlist', TRUE);
1603 $this->assign('customGroup', $customGroup);
1604 $this->assign('contactID', $contactID);
1605 $this->assign('participantID', $participants[$num]->id
);
1607 $this->_id
= $participants[$num]->id
;
1609 if ($this->_isPaidEvent
) {
1610 // fix amount for each of participants ( for bulk mode )
1611 $eventAmount = array();
1612 $invoiceSettings = Civi
::settings()->get('contribution_invoice_settings');
1613 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
1614 $totalTaxAmount = 0;
1616 //add dataArray in the receipts in ADD and UPDATE condition
1617 $dataArray = array();
1618 if ($this->_action
& CRM_Core_Action
::ADD
) {
1619 $line = $lineItem[0];
1621 elseif ($this->_action
& CRM_Core_Action
::UPDATE
) {
1622 $line = $this->_values
['line_items'];
1625 foreach ($line as $key => $value) {
1626 if (isset($value['tax_amount'])) {
1627 $totalTaxAmount +
= $value['tax_amount'];
1628 if (isset($dataArray[(string) $value['tax_rate']])) {
1629 $dataArray[(string) $value['tax_rate']] = $dataArray[(string) $value['tax_rate']] + CRM_Utils_Array
::value('tax_amount', $value);
1632 $dataArray[(string) $value['tax_rate']] = CRM_Utils_Array
::value('tax_amount', $value);
1636 $this->assign('totalTaxAmount', $totalTaxAmount);
1637 $this->assign('taxTerm', CRM_Utils_Array
::value('tax_term', $invoiceSettings));
1638 $this->assign('dataArray', $dataArray);
1640 if (!empty($additionalParticipantDetails)) {
1641 $params['amount_level'] = preg_replace('/\ 1/', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName
;
1644 $eventAmount[$num] = array(
1645 'label' => preg_replace('/\ 1/', '', $params['amount_level']),
1646 'amount' => $params['fee_amount'],
1648 //as we are using same template for online & offline registration.
1649 //So we have to build amount as array.
1650 $eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
1651 $this->assign('amount', $eventAmount);
1654 $sendTemplateParams = array(
1655 'groupName' => 'msg_tpl_workflow_event',
1656 'valueName' => 'event_offline_receipt',
1657 'contactId' => $contactID,
1658 'isTest' => !empty($this->_defaultValues
['is_test']),
1659 'PDFFilename' => ts('confirmation') . '.pdf',
1662 // try to send emails only if email id is present
1663 // and the do-not-email option is not checked for that contact
1664 if ($this->_contributorEmail
and !$this->_toDoNotEmail
) {
1665 $sendTemplateParams['from'] = $receiptFrom;
1666 $sendTemplateParams['toName'] = $this->_contributorDisplayName
;
1667 $sendTemplateParams['toEmail'] = $this->_contributorEmail
;
1668 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc', $this->_fromEmails
);
1669 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc', $this->_fromEmails
);
1672 //send email with pdf invoice
1673 $template = CRM_Core_Smarty
::singleton();
1674 $taxAmt = $template->get_template_vars('dataArray');
1675 $contributionId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1676 $this->_id
, 'contribution_id', 'participant_id'
1678 $prefixValue = Civi
::settings()->get('contribution_invoice_settings');
1679 $invoicing = CRM_Utils_Array
::value('invoicing', $prefixValue);
1680 if (count($taxAmt) > 0 && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
1681 $sendTemplateParams['isEmailPdf'] = TRUE;
1682 $sendTemplateParams['contributionId'] = $contributionId;
1684 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1686 $sent[] = $contactID;
1687 foreach ($participants as $ids => $values) {
1688 if ($values->contact_id
== $contactID) {
1689 $values->details
= CRM_Utils_Array
::value('receipt_text', $params);
1690 CRM_Activity_BAO_Activity
::addActivity($values, 'Email');
1696 $notSent[] = $contactID;
1701 // set the participant id if it is not set
1703 $this->_id
= $participants[0]->id
;
1706 if (($this->_action
& CRM_Core_Action
::UPDATE
)) {
1707 $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contributorDisplayName
));
1708 if (!empty($params['send_receipt']) && count($sent)) {
1709 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', array(1 => $this->_contributorEmail
));
1712 if ($updateStatusMsg) {
1713 $statusMsg = "{$statusMsg} {$updateStatusMsg}";
1716 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
1717 if ($this->_single
) {
1718 $statusMsg = ts('Event registration for %1 has been added.', array(1 => $this->_contributorDisplayName
));
1719 if (!empty($params['send_receipt']) && count($sent)) {
1720 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $this->_contributorEmail
));
1724 $statusMsg = ts('Total Participant(s) added to event: %1.', array(1 => count($this->_contactIds
)));
1725 if (count($notSent) > 0) {
1726 $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)));
1728 elseif (isset($params['send_receipt'])) {
1729 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');
1733 CRM_Core_Session
::setStatus($statusMsg, ts('Saved'), 'success');
1734 $session = CRM_Core_Session
::singleton();
1735 $buttonName = $this->controller
->getButtonName();
1736 if ($this->_context
== 'standalone') {
1737 if ($buttonName == $this->getButtonName('upload', 'new')) {
1738 $urlParams = 'reset=1&action=add&context=standalone';
1740 $urlParams .= '&mode=' . $this->_mode
;
1743 $urlParams .= '&eid=' . $this->_eID
;
1745 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/participant/add', $urlParams));
1748 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
1749 "reset=1&cid={$this->_contactId}&selectedChild=participant"
1753 elseif ($buttonName == $this->getButtonName('upload', 'new')) {
1754 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view/participant',
1755 "reset=1&action=add&context={$this->_context}&cid={$this->_contactId}"