3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2014
38 * This class generates form components for processing a participation
41 class CRM_Event_Form_Participant
extends CRM_Contact_Form_Task
{
43 public $useLivePageJS = TRUE;
46 * the values for the contribution db object
54 * the values for the quickconfig for priceset
59 public $_quickConfig = NULL;
62 * Price Set ID, if the new price set method is used
70 * Array of fields for the price set
78 * the id of the participation that we are proceessing
91 protected $_noteId = NULL;
94 * the id of the contact associated with this participation
102 * array of event values
110 * Are we operating in "single mode", i.e. adding / editing only
111 * one participant record, or is this a batch add operation
115 public $_single = FALSE;
118 * If event is paid or unpaid
120 public $_isPaidEvent;
130 protected $_roleId = NULL;
135 protected $_eventTypeId = NULL;
138 * participant status Id
140 protected $_statusId = NULL;
143 * cache all the participant statuses
145 protected $_participantStatuses;
150 public $_mode = NULL;
158 *Line Item for Price Set
161 public $_lineItem = NULL;
163 *Contribution mode for event registration for offline mode
166 public $_contributeMode = 'direct';
171 * store id of role custom data type ( option value )
173 protected $_roleCustomDataTypeID;
176 * store id of event Name custom data type ( option value)
178 protected $_eventNameCustomDataTypeID;
181 * selected discount id
183 public $_originalDiscountId = NULL;
188 public $_eventId = NULL;
191 * id of payment, if any
193 public $_paymentId = NULL;
196 * @todo add explanatory note about this
199 public $_onlinePendingContributionId = NULL;
202 * Function to set variables up before form is built
207 public function preProcess() {
208 $this->_showFeeBlock
= CRM_Utils_Array
::value('eventId', $_GET);
209 $this->assign('showFeeBlock', FALSE);
210 $this->assign('feeBlockPaid', FALSE);
212 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
213 $this->_mode
= CRM_Utils_Request
::retrieve('mode', 'String', $this);
214 $this->_eID
= CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
215 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this);
216 $this->assign('context', $this->_context
);
218 if ($this->_contactId
) {
219 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
220 $this->assign('displayName', $displayName);
221 $this->setPageTitle(ts('Event Registration for %1', array(1 => $displayName)));
224 $this->setPageTitle(ts('Event Registration'));
227 // check the current path, if search based, then dont get participantID
229 $path = CRM_Utils_System
::currentPath();
231 strpos($path, 'civicrm/contact/search') === 0 ||
232 strpos($path, 'civicrm/group/search') === 0
237 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
241 $this->assign('participantId', $this->_id
);
243 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
244 $this->_id
, 'id', 'participant_id'
247 $this->assign('hasPayment', $this->_paymentId
);
249 // CRM-12615 - Get payment information from the primary registration
250 if ((!$this->_paymentId
) && ($this->_action
== CRM_Core_Action
::UPDATE
)) {
251 $registered_by_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
252 $this->_id
, 'registered_by_id', 'id'
254 if ($registered_by_id) {
255 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
256 $registered_by_id, 'id', 'participant_id'
258 $this->assign('registeredByParticipantId', $registered_by_id);
263 // get the option value for custom data type
264 $this->_roleCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantRole', 'name');
265 $this->_eventNameCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantEventName', 'name');
266 $this->_eventTypeCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantEventType', 'name');
267 $this->assign('roleCustomDataTypeID', $this->_roleCustomDataTypeID
);
268 $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID
);
269 $this->assign('eventTypeCustomDataTypeID', $this->_eventTypeCustomDataTypeID
);
272 $this->assign('participantMode', $this->_mode
);
274 $this->_paymentProcessor
= array('billing_mode' => 1);
276 $validProcessors = array();
277 $processors = CRM_Core_PseudoConstant
::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )");
279 foreach ($processors as $ppID => $label) {
280 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getPayment($ppID, $this->_mode
);
281 if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) {
284 elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode
== 'live') {
288 $paymentObject = CRM_Core_Payment
::singleton($this->_mode
, $paymentProcessor, $this);
289 $error = $paymentObject->checkConfig();
291 $validProcessors[$ppID] = $label;
293 $paymentObject = NULL;
296 if (empty($validProcessors)) {
297 CRM_Core_Error
::fatal(ts('Could not find valid payment processor for this page'));
300 $this->_processors
= $validProcessors;
302 // also check for billing information
303 // get the billing location type
304 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
305 // CRM-8108 remove ts around Billing location type
306 //$this->_bltID = array_search( ts('Billing'), $locationTypes );
307 $this->_bltID
= array_search('Billing', $locationTypes);
308 if (!$this->_bltID
) {
309 CRM_Core_Error
::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
311 $this->set('bltID', $this->_bltID
);
312 $this->assign('bltID', $this->_bltID
);
314 $this->_fields
= array();
316 CRM_Core_Payment_Form
::setCreditCardFields($this);
318 // this required to show billing block
319 $this->assign_by_ref('paymentProcessor', $paymentProcessor);
320 $this->assign('hidePayPalExpress', TRUE);
323 if ($this->_showFeeBlock
) {
324 $this->assign('showFeeBlock', TRUE);
325 $isMonetary = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_showFeeBlock
, 'is_monetary');
327 $this->assign('feeBlockPaid', TRUE);
329 return CRM_Event_Form_EventFees
::preProcess($this);
332 //custom data related code
333 $this->_cdType
= CRM_Utils_Array
::value('type', $_GET);
334 $this->assign('cdType', FALSE);
335 if ($this->_cdType
) {
336 $this->assign('cdType', TRUE);
337 return CRM_Custom_Form_CustomData
::preProcess($this, NULL, NULL, NULL, NULL, NULL, TRUE);
340 //check the mode when this form is called either single or as
342 if ($this->_id ||
$this->_contactId ||
$this->_context
== 'standalone') {
343 $this->_single
= TRUE;
344 $this->assign('urlPath', 'civicrm/contact/view/participant');
345 if (!$this->_id
&& !$this->_contactId
) {
346 $breadCrumbs = array(array('title' => ts('CiviEvent Dashboard'),
347 'url' => CRM_Utils_System
::url('civicrm/event', 'reset=1'),
350 CRM_Utils_System
::appendBreadCrumb($breadCrumbs);
354 //set the appropriate action
355 $context = $this->get('context');
356 $urlString = 'civicrm/contact/search';
357 $this->_action
= CRM_Core_Action
::BASIC
;
360 $urlString = 'civicrm/contact/search/advanced';
361 $this->_action
= CRM_Core_Action
::ADVANCED
;
365 $urlString = 'civicrm/contact/search/builder';
366 $this->_action
= CRM_Core_Action
::PROFILE
;
370 $urlString = 'civicrm/contact/search/basic';
371 $this->_action
= CRM_Core_Action
::BASIC
;
375 $urlString = 'civicrm/contact/search/custom';
376 $this->_action
= CRM_Core_Action
::COPY
;
379 parent
::preProcess();
381 $this->_single
= FALSE;
382 $this->_contactId
= NULL;
384 //set ajax path, this used for custom data building
385 $this->assign('urlPath', $urlString);
386 $this->assign('urlPathVar', "_qf_Participant_display=true&qfKey={$this->controller->_key}");
389 $this->assign('single', $this->_single
);
392 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
394 $this->assign('action', $this->_action
);
396 // check for edit permission
397 if (!CRM_Core_Permission
::checkActionPermission('CiviEvent', $this->_action
)) {
398 CRM_Core_Error
::fatal(ts('You do not have permission to access this page'));
401 if ($this->_action
& CRM_Core_Action
::DELETE
) {
402 // check delete permission for contribution
403 if ($this->_id
&& $this->_paymentId
&& !CRM_Core_Permission
::checkActionPermission('CiviContribute', $this->_action
)) {
404 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."));
410 // assign participant id to the template
411 $this->assign('participantId', $this->_id
);
412 $this->_roleId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'role_id');
415 // when fee amount is included in form
416 if (!empty($_POST['hidden_feeblock']) ||
!empty($_POST['send_receipt'])) {
417 CRM_Event_Form_EventFees
::preProcess($this);
418 CRM_Event_Form_EventFees
::buildQuickForm($this);
419 CRM_Event_Form_EventFees
::setDefaultValues($this);
422 // when custom data is included in this page
423 if (!empty($_POST['hidden_custom'])) {
424 // Custom data of type participant role
425 // Note: Some earlier commits imply $_POST['role_id'] could be a comma separated string,
426 // not sure if that ever really happens
427 if (!empty($_POST['role_id'])) {
428 foreach ($_POST['role_id'] as $roleID) {
429 CRM_Custom_Form_CustomData
::preProcess($this, $this->_roleCustomDataTypeID
, $roleID, 1, 'Participant', $this->_id
);
430 CRM_Custom_Form_CustomData
::buildQuickForm($this);
431 CRM_Custom_Form_CustomData
::setDefaultValues($this);
435 //custom data of type participant event
436 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventNameCustomDataTypeID
, $_POST['event_id'], 1, 'Participant', $this->_id
);
437 CRM_Custom_Form_CustomData
::buildQuickForm($this);
438 CRM_Custom_Form_CustomData
::setDefaultValues($this);
440 // custom data of type participant event type
442 if ($eventId = CRM_Utils_Array
::value('event_id', $_POST)) {
443 $eventTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'event_type_id', 'id');
445 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventTypeCustomDataTypeID
, $eventTypeId,
446 1, 'Participant', $this->_id
448 CRM_Custom_Form_CustomData
::buildQuickForm($this);
449 CRM_Custom_Form_CustomData
::setDefaultValues($this);
451 //custom data of type participant, ( we 'null' to reset subType and subName)
452 CRM_Custom_Form_CustomData
::preProcess($this, 'null', 'null', 1, 'Participant', $this->_id
);
453 CRM_Custom_Form_CustomData
::buildQuickForm($this);
454 CRM_Custom_Form_CustomData
::setDefaultValues($this);
457 // CRM-4395, get the online pending contribution id.
458 $this->_onlinePendingContributionId
= NULL;
459 if (!$this->_mode
&& $this->_id
&& ($this->_action
& CRM_Core_Action
::UPDATE
)) {
460 $this->_onlinePendingContributionId
= CRM_Contribute_BAO_Contribution
::checkOnlinePendingContribution($this->_id
,
464 $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId
);
468 * This function sets the default values for the form in edit/view mode
469 * the default values are retrieved from the database
475 public function setDefaultValues() {
476 if ($this->_showFeeBlock
) {
477 return CRM_Event_Form_EventFees
::setDefaultValues($this);
480 if ($this->_cdType
) {
481 return CRM_Custom_Form_CustomData
::setDefaultValues($this);
486 if ($this->_action
& CRM_Core_Action
::DELETE
) {
492 $params = array('id' => $this->_id
);
494 CRM_Event_BAO_Participant
::getValues($params, $defaults, $ids);
495 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
496 if ($defaults[$this->_id
]['role_id']) {
497 $roleIDs = explode($sep, $defaults[$this->_id
]['role_id']);
499 $this->_contactId
= $defaults[$this->_id
]['contact_id'];
500 $this->_statusId
= $defaults[$this->_id
]['participant_status_id'];
502 //set defaults for note
503 $noteDetails = CRM_Core_BAO_Note
::getNote($this->_id
, 'civicrm_participant');
504 $defaults[$this->_id
]['note'] = array_pop($noteDetails);
506 // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859)
507 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
508 $this->assign('additionalParticipants', CRM_Event_BAO_Participant
::getAdditionalParticipants($this->_id
));
511 // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
512 if (!empty($defaults[$this->_id
]['participant_registered_by_id'])) {
513 $registered_by_contact_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
514 $defaults[$this->_id
]['participant_registered_by_id'],
517 $this->assign('participant_registered_by_id', $defaults[$this->_id
]['participant_registered_by_id']);
518 $this->assign('registered_by_contact_id', $registered_by_contact_id);
519 $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact
::displayName($registered_by_contact_id));
523 if ($this->_action
& (CRM_Core_Action
::VIEW | CRM_Core_Action
::BROWSE
)) {
524 $inactiveNeeded = TRUE;
529 $inactiveNeeded = FALSE;
532 //setting default register date
533 if ($this->_action
== CRM_Core_Action
::ADD
) {
534 $statuses = array_flip($this->_participantStatuses
);
535 $defaults[$this->_id
]['status_id'] = CRM_Utils_Array
::value(ts('Registered'), $statuses);
536 if (!empty($defaults[$this->_id
]['event_id'])) {
537 $contributionTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
538 $defaults[$this->_id
]['event_id'],
541 if ($contributionTypeId) {
542 $defaults[$this->_id
]['financial_type_id'] = $contributionTypeId;
547 $fields["email-{$this->_bltID}"] = 1;
548 $fields['email-Primary'] = 1;
550 if ($this->_contactId
) {
551 CRM_Core_BAO_UFGroup
::setProfileDefaults($this->_contactId
, $fields, $defaults);
554 if (empty($defaults["email-{$this->_bltID}"]) &&
555 !empty($defaults['email-Primary'])
557 $defaults[$this->_id
]["email-{$this->_bltID}"] = $defaults['email-Primary'];
561 $submittedRole = $this->getElementValue('role_id');
562 if (!empty($submittedRole[0])) {
563 $roleID = $submittedRole[0];
565 $submittedEvent = $this->getElementValue('event_id');
566 if (!empty($submittedEvent[0])) {
567 $eventID = $submittedEvent[0];
571 $defaults[$this->_id
]['record_contribution'] = 0;
573 if ($defaults[$this->_id
]['participant_is_pay_later']) {
574 $this->assign('participant_is_pay_later', TRUE);
577 $this->assign('participant_status_id', $defaults[$this->_id
]['participant_status_id']);
578 $eventID = $defaults[$this->_id
]['event_id'];
580 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
582 $this->_discountId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'discount_id');
583 if ($this->_discountId
) {
584 $this->set('discountId', $this->_discountId
);
588 list($defaults[$this->_id
]['register_date'],
589 $defaults[$this->_id
]['register_date_time']
590 ) = CRM_Utils_Date
::setDateDefaults(
591 CRM_Utils_Array
::value('register_date', $defaults[$this->_id
]), 'activityDateTime'
594 //assign event and role id, this is needed for Custom data building
595 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
596 if (!empty($defaults[$this->_id
]['participant_role_id'])) {
597 $roleIDs = explode($sep, $defaults[$this->_id
]['participant_role_id']);
599 if (isset($_POST['event_id'])) {
600 $eventID = $_POST['event_id'];
604 $eventID = $this->_eID
;
605 //@todo - rationalise the $this->_eID with $POST['event_id'], $this->_eid is set when eid=x is in the url
606 $roleID = CRM_Core_DAO
::getFieldValue(
607 'CRM_Event_DAO_Event',
611 if(empty($roleIDs)) {
612 $roleIDs = (array) $defaults[$this->_id
]['participant_role_id'] = $roleID;
614 $defaults[$this->_id
]['event_id'] = $eventID;
616 if (!empty($eventID)) {
617 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
619 //these should take precedence so we state them last
620 $urlRoleIDS = CRM_Utils_Request
::retrieve('roles', 'String');
622 $roleIDs = explode(',', $urlRoleIDS);
624 if (isset($roleIDs)) {
625 $defaults[$this->_id
]['role_id'] = implode(',', $roleIDs);
628 if (isset($eventID)) {
629 $this->assign('eventID', $eventID);
630 $this->set('eventId', $eventID);
633 if (isset($this->_eventTypeId
)) {
634 $this->assign('eventTypeID', $this->_eventTypeId
);
637 $this->assign('event_is_test', CRM_Utils_Array
::value('event_is_test', $defaults[$this->_id
]));
638 return $defaults[$this->_id
];
642 * Function to build the form
647 public function buildQuickForm() {
648 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
649 $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses);
650 $this->assign('partiallyPaidStatusId', $partiallyPaidStatusId);
652 if ($this->_showFeeBlock
) {
653 return CRM_Event_Form_EventFees
::buildQuickForm($this);
656 if ($this->_cdType
) {
657 return CRM_Custom_Form_CustomData
::buildQuickForm($this);
660 //need to assign custom data type to the template
661 $this->assign('customDataType', 'Participant');
663 $this->applyFilter('__ALL__', 'trim');
665 if ($this->_action
& CRM_Core_Action
::DELETE
) {
666 if ($this->_single
) {
667 $additionalParticipant = count(CRM_Event_BAO_Event
::buildCustomProfile($this->_id
,
673 if ($additionalParticipant) {
674 $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'),
675 2 => ts('Delete only this participant record.'),
677 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
678 $this->setDefaults(array('delete_participant' => 1));
679 $this->assign('additionalParticipant', $additionalParticipant);
682 $this->addButtons(array(
685 'name' => ts('Delete'),
686 'spacing' => ' ',
691 'name' => ts('Cancel'),
699 if ($this->_single
&& $this->_context
== 'standalone') {
700 $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
703 $eventFieldParams = array(
705 'select' => array('minimumInputLength' => 0),
707 'extra' => array('campaign_id', 'default_role_id', 'event_type_id'),
712 // exclude events which are not monetary when credit card registration is used
713 $eventFieldParams['api']['params']['is_monetary'] = 1;
714 $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors
, TRUE);
717 $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE);
719 //frozen the field fix for CRM-4171
720 if ($this->_action
& CRM_Core_Action
::UPDATE
&& $this->_id
) {
721 if (CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
722 $this->_id
, 'contribution_id', 'participant_id'
728 //CRM-7362 --add campaigns.
731 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'campaign_id');
734 $eventId = CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
736 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
739 CRM_Campaign_BAO_Campaign
::addCampaign($this, $campaignId);
741 $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
744 $this->assign('entityID', $this->_id
);
747 $this->addSelect('role_id', array('multiple' => TRUE, 'class' => 'huge'), TRUE);
750 $checkCancelledJs = array('onchange' => "return sendNotification( );");
752 if ($this->_onlinePendingContributionId
) {
753 $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant
::participantStatus());
754 $cancelledContributionStatusId = array_search('Cancelled',
755 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
757 $checkCancelledJs = array(
759 "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});",
762 $participantStatusId = array_search('Pending from pay later',
763 CRM_Event_PseudoConstant
::participantStatus()
765 $contributionStatusId = array_search('Completed',
766 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
768 $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
771 // get the participant status names to build special status array which is used to show notification
772 // checkbox below participant status select
773 $participantStatusName = CRM_Event_PseudoConstant
::participantStatus();
774 $notificationStatuses = array(
776 'Pending from waitlist',
777 'Pending from approval',
781 // get the required status and then implode only ids
782 $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
783 $this->assign('notificationStatusIds', $notificationStatusIds);
785 $this->_participantStatuses
= $statusOptions = CRM_Event_BAO_Participant
::buildOptions('status_id', 'create');
787 // Only show refund status when editing
788 if ($this->_action
& CRM_Core_Action
::ADD
) {
789 $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
790 if ($pendingRefundStatusId) {
791 unset($statusOptions[$pendingRefundStatusId]);
795 $this->addSelect('status_id', $checkCancelledJs +
array('options' => $statusOptions, 'option_url' => 'civicrm/admin/participant_status'), TRUE);
797 $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
799 $this->add('text', 'source', ts('Event Source'));
800 $noteAttributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Note');
801 $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
805 'name' => ts('Save'),
810 $path = CRM_Utils_System
::currentPath();
811 $excludeForPaths = array(
812 'civicrm/contact/search',
813 'civicrm/group/search'
815 if (!in_array($path, $excludeForPaths)) {
818 'name' => ts('Save and New'),
826 'name' => ts('Cancel'),
829 $this->addButtons($buttons);
830 if ($this->_action
== CRM_Core_Action
::VIEW
) {
836 * Add local and global form rules
842 function addRules() {
843 $this->addFormRule(array('CRM_Event_Form_Participant', 'formRule'), $this);
847 * global validation rules for the form
853 * @internal param array $fields posted values of the form
855 * @return array list of errors to be posted back to the form
859 static function formRule($values, $files, $self) {
860 // If $values['_qf_Participant_next'] is Delete or
861 // $values['event_id'] is empty, then return
862 // instead of proceeding further.
864 if ((CRM_Utils_Array
::value('_qf_Participant_next', $values) == 'Delete') ||
865 (!$values['event_id'])
872 if (!empty($values['payment_processor_id'])) {
873 // make sure that credit card number and cvv are valid
874 CRM_Core_Payment_Form
::validateCreditCard($values, $errorMsg);
877 if (!empty($values['record_contribution'])) {
878 if (empty($values['financial_type_id'])) {
879 $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
881 if (empty($values['payment_instrument_id'])) {
882 $errorMsg['payment_instrument_id'] = ts('Paid By is a required field.');
886 // validate contribution status for 'Failed'.
887 if ($self->_onlinePendingContributionId
&& !empty($values['record_contribution']) &&
888 (CRM_Utils_Array
::value('contribution_status_id', $values) ==
889 array_search('Failed', CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name'))
892 $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.');
895 // do the amount validations.
896 //skip for update mode since amount is freeze, CRM-6052
897 if ((!$self->_id
&& empty($values['total_amount']) &&
898 empty($self->_values
['line_items'])
900 ($self->_id
&& !$self->_paymentId
&& isset($self->_values
['line_items']) && is_array($self->_values
['line_items']))
902 if ($priceSetId = CRM_Utils_Array
::value('priceSetId', $values)) {
903 CRM_Price_BAO_PriceField
::priceSetValidation($priceSetId, $values, $errorMsg, TRUE);
906 // For single additions - show validation error if the contact has already been registered
907 // for this event with the same role.
908 if($self->_single
&& ($self->_action
& CRM_Core_Action
::ADD
)) {
909 $contactId = $self->_contactId
;
910 $eventId = CRM_Utils_Array
::value('event_id', $values);
911 if(!empty($contactId) && !empty($eventId)) {
912 $dupeCheck = new CRM_Event_BAO_Participant
;
913 $dupeCheck->contact_id
= $contactId;
914 $dupeCheck->event_id
= $eventId;
915 $dupeCheck->find(TRUE);
916 if(!empty($dupeCheck->id
)) {
917 $errorMsg['event_id'] = ts("This contact has already been assigned to this event.");
921 return CRM_Utils_Array
::crmIsEmptyArray($errorMsg) ?
TRUE : $errorMsg;
925 * Function to process the form
929 public function postProcess() {
930 // get the submitted form values.
931 $params = $this->controller
->exportValues($this->_name
);
933 if ($this->_action
& CRM_Core_Action
::DELETE
) {
934 if (CRM_Utils_Array
::value('delete_participant', $params) == 2) {
935 $additionalId = (CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
));
936 $participantLinks = (CRM_Event_BAO_Participant
::getAdditionalParticipantUrl($additionalId));
938 if (CRM_Utils_Array
::value('delete_participant', $params) == 1) {
939 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
940 foreach ($additionalIds as $value) {
941 CRM_Event_BAO_Participant
::deleteParticipant($value);
944 CRM_Event_BAO_Participant
::deleteParticipant($this->_id
);
945 CRM_Core_Session
::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success');
946 if (!empty($participantLinks)) {
947 $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;
948 CRM_Core_Session
::setStatus($status, ts('Group Payment Deleted'));
952 // When adding a single contact, the formRule prevents you from adding duplicates
953 // (See above in formRule()). When adding more than one contact, the duplicates are
954 // removed automatically and the user receives one notification.
955 if ($this->_action
& CRM_Core_Action
::ADD
) {
956 $event_id = $this->_eventId
;
957 if(empty($event_id) && !empty($params['event_id'])) {
958 $event_id = $params['event_id'];
960 if(!$this->_single
&& !empty($event_id)) {
961 $duplicateContacts = 0;
962 while(list($k,$dupeCheckContactId) = each($this->_contactIds
)) {
963 // Eliminate contacts that have already been assigned to this event.
964 $dupeCheck = new CRM_Event_BAO_Participant
;
965 $dupeCheck->contact_id
= $dupeCheckContactId;
966 $dupeCheck->event_id
= $event_id;
967 $dupeCheck->find(TRUE);
968 if(!empty($dupeCheck->id
)) {
969 $duplicateContacts++
;
970 unset($this->_contactIds
[$k]);
973 if($duplicateContacts > 0) {
975 "%1 contacts have already been assigned to this event. They were not added a second time.",
976 array(1 => $duplicateContacts)
978 CRM_Core_Session
::setStatus($msg);
980 if(count($this->_contactIds
) == 0) {
981 CRM_Core_Session
::setStatus(ts("No participants were added."));
984 // We have to re-key $this->_contactIds so each contact has the same
985 // key as their corresponding record in the $participants array that
986 // will be created below.
987 $this->_contactIds
= array_values($this->_contactIds
);
992 $participantStatus = CRM_Event_PseudoConstant
::participantStatus();
993 // set the contact, when contact is selected
994 if (!empty($params['contact_id'])) {
995 $this->_contactId
= $params['contact_id'];
997 if ($this->_priceSetId
&& $isQuickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
998 $this->_quickConfig
= $isQuickConfig;
1002 $params['id'] = $this->_id
;
1005 $config = CRM_Core_Config
::singleton();
1006 if ($this->_isPaidEvent
) {
1008 $contributionParams = array();
1009 $lineItem = array();
1010 $additionalParticipantDetails = array();
1011 if (($this->_id
&& $this->_action
& CRM_Core_Action
::UPDATE
) && $this->_paymentId
) {
1012 $participantBAO = new CRM_Event_BAO_Participant();
1013 $participantBAO->id
= $this->_id
;
1014 $participantBAO->find(TRUE);
1015 $contributionParams['total_amount'] = $participantBAO->fee_amount
;
1017 $params['discount_id'] = NULL;
1018 //re-enter the values for UPDATE mode
1019 $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level
;
1020 $params['fee_amount'] = $participantBAO->fee_amount
;
1021 if (isset($params['priceSetId'])) {
1022 $lineItem[0] = CRM_Price_BAO_LineItem
::getLineItems($this->_id
);
1024 //also add additional participant's fee level/priceset
1025 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
1026 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
1027 $hasLineItems = CRM_Utils_Array
::value('priceSetId', $params, FALSE);
1028 $additionalParticipantDetails = CRM_Event_BAO_Participant
::getFeeDetails($additionalIds,
1035 //check if discount is selected
1036 if (!empty($params['discount_id'])) {
1037 $discountId = $params['discount_id'];
1040 $discountId = $params['discount_id'] = 'null';
1043 //lets carry currency, CRM-4453
1044 $params['fee_currency'] = $config->defaultCurrency
;
1045 CRM_Price_BAO_PriceSet
::processAmount($this->_values
['fee'],
1046 $params, $lineItem[0]
1048 //CRM-11529 for quick config backoffice transactions
1049 //when financial_type_id is passed in form, update the
1050 //lineitems with the financial type selected in form
1051 $submittedFinancialType = CRM_Utils_Array
::value('financial_type_id', $params);
1052 $isPaymentRecorded = CRM_Utils_Array
::value('record_contribution', $params);
1053 if ($isPaymentRecorded && $this->_quickConfig
&& $submittedFinancialType) {
1054 foreach ($lineItem[0] as &$values) {
1055 $values['financial_type_id'] = $submittedFinancialType;
1059 $params['fee_level'] = $params['amount_level'];
1060 $contributionParams['total_amount'] = $params['amount'];
1061 if ($this->_quickConfig
&& !empty($params['total_amount']) &&
1062 $params['status_id'] != array_search('Partially paid', $participantStatus)) {
1063 $params['fee_amount'] = $params['total_amount'];
1066 $params['fee_amount'] = $params['amount'];
1070 if (isset($params['priceSetId'])) {
1071 if (!empty($lineItem[0])) {
1072 $this->set('lineItem', $lineItem);
1074 $this->_lineItem
= $lineItem;
1075 $lineItem = array_merge($lineItem, $additionalParticipantDetails);
1077 $participantCount = array();
1078 foreach ($lineItem as $k) {
1079 foreach ($k as $v) {
1080 if (CRM_Utils_Array
::value('participant_count', $v) > 0) {
1081 $participantCount[] = $v['participant_count'];
1086 if (isset($participantCount)) {
1087 $this->assign('pricesetFieldsCount', $participantCount);
1089 $this->assign('lineItem', empty($lineItem[0]) ||
$this->_quickConfig?
FALSE : $lineItem);
1092 $this->assign('amount_level', $params['amount_level']);
1096 $this->_params
= $params;
1098 if (isset($params['amount'])) {
1099 $amountOwed = $params['amount'];
1100 unset($params['amount']);
1102 $params['register_date'] = CRM_Utils_Date
::processDate($params['register_date'], $params['register_date_time']);
1103 $params['receive_date'] = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('receive_date', $params));
1104 $params['contact_id'] = $this->_contactId
;
1106 // overwrite actual payment amount if entered
1107 if (!empty($params['total_amount'])) {
1108 $contributionParams['total_amount'] = CRM_Utils_Array
::value('total_amount', $params);
1112 // Retrieve the name and email of the current user - this will be the FROM for the receipt email
1113 $session = CRM_Core_Session
::singleton();
1114 $userID = $session->get('userID');
1117 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($userID);
1119 if ($this->_contactId
) {
1120 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($this->_contactId
);
1123 //modify params according to parameter used in create
1124 //participant method (addParticipant)
1125 $this->_params
['participant_status_id'] = $params['status_id'];
1126 $this->_params
['participant_role_id'] = is_array($params['role_id']) ?
$params['role_id'] : explode(',', $params['role_id']);
1127 $this->_params
['participant_register_date'] = $params['register_date'];
1128 $roleIdWithSeparator = implode(CRM_Core_DAO
::VALUE_SEPARATOR
, $this->_params
['participant_role_id']);
1131 if (!$this->_isPaidEvent
) {
1132 CRM_Core_Error
::fatal(ts('Selected Event is not Paid Event '));
1136 CRM_Core_DAO
::getFieldValue(
1137 'CRM_Event_DAO_Event',
1138 $params['event_id'],
1142 // set source if not set
1143 if (empty($params['source'])) {
1144 $this->_params
['participant_source'] = ts('Offline Registration for Event: %2 by: %1', array(1 => $userName, 2 => $eventTitle));
1147 $this->_params
['participant_source'] = $params['source'];
1149 $this->_params
['description'] = $this->_params
['participant_source'];
1151 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($this->_params
['payment_processor_id'],
1154 $now = date('YmdHis');
1157 // set email for primary location.
1158 $fields['email-Primary'] = 1;
1159 $params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail
;
1161 $params['register_date'] = $now;
1163 // now set the values for the billing location.
1164 foreach ($this->_fields
as $name => $dontCare) {
1168 // also add location name to the array
1169 $params["address_name-{$this->_bltID}"] =
1170 CRM_Utils_Array
::value('billing_first_name', $params) . ' ' .
1171 CRM_Utils_Array
::value('billing_middle_name', $params) . ' ' .
1172 CRM_Utils_Array
::value('billing_last_name', $params);
1174 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
1175 $fields["address_name-{$this->_bltID}"] = 1;
1176 $fields["email-{$this->_bltID}"] = 1;
1177 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'contact_type');
1179 $nameFields = array('first_name', 'middle_name', 'last_name');
1181 foreach ($nameFields as $name) {
1183 if (array_key_exists("billing_$name", $params)) {
1184 $params[$name] = $params["billing_{$name}"];
1185 $params['preserveDBName'] = TRUE;
1188 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params, $fields, $this->_contactId
, NULL, NULL, $ctype);
1191 if (!empty($this->_params
['participant_role_id'])) {
1192 $customFieldsRole = array();
1193 foreach ($this->_params
['participant_role_id'] as $roleKey) {
1194 $customFieldsRole = CRM_Utils_Array
::crmArrayMerge(CRM_Core_BAO_CustomField
::getFields('Participant',
1195 FALSE, FALSE, $roleKey, $this->_roleCustomDataTypeID
), $customFieldsRole);
1197 $customFieldsEvent = CRM_Core_BAO_CustomField
::getFields('Participant',
1200 CRM_Utils_Array
::value('event_id', $params),
1201 $this->_eventNameCustomDataTypeID
1203 $customFieldsEventType = CRM_Core_BAO_CustomField
::getFields('Participant',
1206 $this->_eventTypeId
,
1207 $this->_eventTypeCustomDataTypeID
1209 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsRole,
1210 CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE)
1212 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEvent, $customFields);
1213 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEventType, $customFields);
1214 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
1221 //do cleanup line items if participant edit the Event Fee.
1222 if (($this->_lineItem ||
!isset($params['proceSetId'])) && !$this->_paymentId
&& $this->_id
) {
1223 CRM_Price_BAO_LineItem
::deleteLineItems($this->_id
, 'civicrm_participant');
1227 // add all the additional payment params we need
1228 $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}"]);
1229 $this->_params
["country-{$this->_bltID}"] = $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
1231 $this->_params
['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($this->_params
);
1232 $this->_params
['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($this->_params
);
1233 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
1234 $this->_params
['amount'] = $params['fee_amount'];
1235 $this->_params
['amount_level'] = $params['amount_level'];
1236 $this->_params
['currencyID'] = $config->defaultCurrency
;
1237 $this->_params
['payment_action'] = 'Sale';
1238 $this->_params
['invoiceID'] = md5(uniqid(rand(), TRUE));
1240 // at this point we've created a contact and stored its address etc
1241 // all the payment processors expect the name and address to be in the
1242 // so we copy stuff over to first_name etc.
1243 $paymentParams = $this->_params
;
1244 if (!empty($this->_params
['send_receipt'])) {
1245 $paymentParams['email'] = $this->_contributorEmail
;
1247 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $this->_params
, $paymentParams, TRUE);
1249 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
1251 // CRM-15622: fix for incorrect contribution.fee_amount
1252 $paymentParams['fee_amount'] = NULL;
1253 $result = $payment->doDirectPayment($paymentParams);
1255 if (is_a($result, 'CRM_Core_Error')) {
1256 CRM_Core_Error
::displaySessionError($result);
1257 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/view/participant',
1258 "reset=1&action=add&cid={$this->_contactId}&context=participant&mode={$this->_mode}"
1263 $this->_params
= array_merge($this->_params
, $result);
1266 $this->_params
['receive_date'] = $now;
1268 if (!empty($this->_params
['send_receipt'])) {
1269 $this->_params
['receipt_date'] = $now;
1272 $this->_params
['receipt_date'] = NULL;
1275 $this->set('params', $this->_params
);
1276 $this->assign('trxn_id', $result['trxn_id']);
1277 $this->assign('receive_date',
1278 CRM_Utils_Date
::processDate($this->_params
['receive_date'])
1281 //add contribution record
1282 $this->_params
['financial_type_id'] =
1283 CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
1284 $this->_params
['mode'] = $this->_mode
;
1286 //add contribution reocord
1287 $contributions[] = $contribution = CRM_Event_Form_Registration_Confirm
::processContribution($this, $this->_params
, $result, $contactID, FALSE);
1289 // add participant record
1290 $participants = array();
1291 if (!empty($this->_params
['role_id']) && is_array($this->_params
['role_id'])) {
1292 $this->_params
['role_id'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1293 $this->_params
['role_id']
1297 //CRM-15372 patch to fix fee amount replacing amount
1298 $this->_params
['fee_amount'] = $this->_params
['amount'];
1300 $participants[] = CRM_Event_Form_Registration
::addParticipant($this, $contactID);
1302 //add custom data for participant
1303 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
1304 CRM_Core_DAO
::$_nullArray,
1305 'civicrm_participant',
1306 $participants[0]->id
,
1309 //add participant payment
1310 $paymentParticipant = array(
1311 'participant_id' => $participants[0]->id
,
1312 'contribution_id' => $contribution->id
,
1316 CRM_Event_BAO_ParticipantPayment
::create($paymentParticipant, $ids);
1317 $this->_contactIds
[] = $this->_contactId
;
1320 $participants = array();
1321 if ($this->_single
) {
1322 if ($params['role_id']) {
1323 $params['role_id'] = $roleIdWithSeparator;
1326 $params['role_id'] = 'NULL';
1328 $participants[] = CRM_Event_BAO_Participant
::create($params);
1331 foreach ($this->_contactIds
as $contactID) {
1332 $commonParams = $params;
1333 $commonParams['contact_id'] = $contactID;
1334 if ($commonParams['role_id']) {
1335 $commonParams['role_id'] = $commonParams['role_id'] = str_replace(',', CRM_Core_DAO
::VALUE_SEPARATOR
, $params['role_id']);
1338 $commonParams['role_id'] = 'NULL';
1340 $participants[] = CRM_Event_BAO_Participant
::create($commonParams);
1344 if (isset($params['event_id'])) {
1345 $eventTitle = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
1346 $params['event_id'],
1351 if ($this->_single
) {
1352 $this->_contactIds
[] = $this->_contactId
;
1355 $contributions = array();
1356 if (!empty($params['record_contribution'])) {
1357 if (!empty($params['id'])) {
1358 if ($this->_onlinePendingContributionId
) {
1359 $ids['contribution'] = $this->_onlinePendingContributionId
;
1362 $ids['contribution'] = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1369 unset($params['note']);
1371 //build contribution params
1372 if (!$this->_onlinePendingContributionId
) {
1373 $contributionParams['source'] = "{$eventTitle}: Offline registration (by {$userName})";
1376 $contributionParams['currency'] = $config->defaultCurrency
;
1377 $contributionParams['non_deductible_amount'] = 'null';
1378 $contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array
::value('receive_date', $params) : 'null';
1380 $recordContribution = array( 'contact_id', 'financial_type_id',
1381 'payment_instrument_id', 'trxn_id',
1382 'contribution_status_id', 'receive_date',
1383 'check_number', 'campaign_id',
1386 foreach ($recordContribution as $f) {
1387 $contributionParams[$f] = CRM_Utils_Array
::value($f, $params);
1388 if ($f == 'trxn_id') {
1389 $this->assign('trxn_id', $contributionParams[$f]);
1393 //insert financial type name in receipt.
1394 $this->assign('contributionTypeName', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id']));
1395 $contributionParams['skipLineItem'] = 1;
1397 $contributionParams['contribution_mode'] = 'participant';
1398 $contributionParams['participant_id'] = $this->_id
;
1400 // Set is_pay_later flag for back-office offline Pending status contributions
1401 if ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup
::getValue('contribution_status', 'Pending', 'name')) {
1402 $contributionParams['is_pay_later'] = 1;
1404 elseif ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup
::getValue('contribution_status', 'Completed', 'name')) {
1405 $contributionParams['is_pay_later'] = 0;
1408 if ($params['status_id'] == array_search('Partially paid', $participantStatus)) {
1409 if (!$amountOwed && $this->_action
& CRM_Core_Action
::UPDATE
) {
1410 $amountOwed = $params['fee_amount'];
1413 // if multiple participants are link, consider contribution total amount as the amount Owed
1414 if ($this->_id
&& CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
1415 $amountOwed = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_Contribution',
1416 $ids['contribution'],
1421 // CRM-13964 partial_payment_total
1422 if ($amountOwed > $params['total_amount']) {
1424 $contributionParams['partial_payment_total'] = $amountOwed;
1425 // the actual amount paid
1426 $contributionParams['partial_amount_pay'] = $params['total_amount'];
1430 if ($this->_single
) {
1434 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1438 foreach ($this->_contactIds
as $contactID) {
1439 $contributionParams['contact_id'] = $contactID;
1440 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1444 //insert payment record for this participation
1445 if (empty($ids['contribution'])) {
1446 foreach ($this->_contactIds
as $num => $contactID) {
1447 $ppDAO = new CRM_Event_DAO_ParticipantPayment();
1448 $ppDAO->participant_id
= $participants[$num]->id
;
1449 $ppDAO->contribution_id
= $contributions[$num]->id
;
1453 // next create the transaction record
1454 $transaction = new CRM_Core_Transaction();
1457 if ($this->_quickConfig
) {
1458 if (!empty($this->_params
['amount_priceset_level_radio'])) {
1459 $feeLevel = $this->_params
['amount_priceset_level_radio'];
1462 $feeLevel[] = $this->_params
['fee_level'] ;
1464 CRM_Event_BAO_Participant
::createDiscountTrxn($this->_eventId
, $contributionParams, $feeLevel);
1466 $transaction->commit();
1470 // also store lineitem stuff here
1471 if ((($this->_lineItem
& $this->_action
& CRM_Core_Action
::ADD
) ||
1472 ($this->_lineItem
&& CRM_Core_Action
::UPDATE
&& !$this->_paymentId
))
1474 foreach ($this->_contactIds
as $num => $contactID) {
1475 foreach ($this->_lineItem
as $key => $value) {
1476 if (is_array($value) && $value != 'skip') {
1477 foreach ($value as $lineKey => $line) {
1478 //10117 update the line items for participants if contribution amount is recorded
1479 if ($this->_quickConfig
&& !empty($params['total_amount']) &&
1480 ($params['status_id'] != array_search('Partially paid', $participantStatus))
1482 $line['unit_price'] = $line['line_total'] = $params['total_amount'];
1484 $lineItem[$this->_priceSetId
][$lineKey] = $line;
1486 CRM_Price_BAO_LineItem
::processPriceSet($participants[$num]->id
, $lineItem, CRM_Utils_Array
::value($num, $contributions, NULL), 'civicrm_participant');
1492 $updateStatusMsg = NULL;
1493 //send mail when participant status changed, CRM-4326
1494 if ($this->_id
&& $this->_statusId
&&
1495 $this->_statusId
!= CRM_Utils_Array
::value('status_id', $params) && !empty($params['is_notify'])) {
1497 $updateStatusMsg = CRM_Event_BAO_Participant
::updateStatusMessage($this->_id
,
1498 $params['status_id'],
1505 if (!empty($params['send_receipt'])) {
1506 if (array_key_exists($params['from_email_address'], $this->_fromEmails
['from_email_id'])) {
1507 $receiptFrom = $params['from_email_address'];
1510 $this->assign('module', 'Event Registration');
1511 //use of the message template below requires variables in different format
1512 $event = $events = array();
1513 $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
1515 //get all event details.
1516 CRM_Core_DAO
::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
1517 $event = $events[$params['event_id']];
1518 unset($event['start_date']);
1519 unset($event['end_date']);
1521 $role = CRM_Event_PseudoConstant
::participantRole();
1522 $participantRoles = CRM_Utils_Array
::value('role_id', $params);
1523 if (is_array($participantRoles)) {
1524 $selectedRoles = array();
1525 foreach ($participantRoles as $roleId) {
1526 $selectedRoles[] = $role[$roleId];
1528 $event['participant_role'] = implode(', ', $selectedRoles);
1531 $event['participant_role'] = CRM_Utils_Array
::value($participantRoles, $role);
1533 $event['is_monetary'] = $this->_isPaidEvent
;
1535 if ($params['receipt_text']) {
1536 $event['confirm_email_text'] = $params['receipt_text'];
1539 $this->assign('isAmountzero', 1);
1540 $this->assign('event', $event);
1542 $this->assign('isShowLocation', $event['is_show_location']);
1543 if (CRM_Utils_Array
::value('is_show_location', $event) == 1) {
1544 $locationParams = array(
1545 'entity_id' => $params['event_id'],
1546 'entity_table' => 'civicrm_event',
1548 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
1549 $this->assign('location', $location);
1552 $status = CRM_Event_PseudoConstant
::participantStatus();
1553 if ($this->_isPaidEvent
) {
1554 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
1555 if (!$this->_mode
) {
1556 if (isset($params['payment_instrument_id'])) {
1557 $this->assign('paidBy',
1558 CRM_Utils_Array
::value($params['payment_instrument_id'],
1565 $this->assign('totalAmount', $contributionParams['total_amount']);
1566 if (isset($contributionParams['partial_payment_total'])) {
1568 $balanceAmount = $contributionParams['partial_payment_total'] - $contributionParams['partial_amount_pay'];
1569 $this->assign('balanceAmount', $balanceAmount );
1571 $this->assign('isPrimary', 1);
1572 $this->assign('checkNumber', CRM_Utils_Array
::value('check_number', $params));
1575 if (!empty($params['billing_first_name'])) {
1576 $name = $params['billing_first_name'];
1579 if (!empty($params['billing_middle_name'])) {
1580 $name .= " {$params['billing_middle_name']}";
1583 if (!empty($params['billing_last_name'])) {
1584 $name .= " {$params['billing_last_name']}";
1586 $this->assign('billingName', $name);
1588 // assign the address formatted up for display
1589 $addressParts = array(
1590 "street_address-{$this->_bltID}",
1591 "city-{$this->_bltID}",
1592 "postal_code-{$this->_bltID}",
1593 "state_province-{$this->_bltID}",
1594 "country-{$this->_bltID}",
1596 $addressFields = array();
1597 foreach ($addressParts as $part) {
1598 list($n, $id) = explode('-', $part);
1599 if (isset($this->_params
['billing_' . $part])) {
1600 $addressFields[$n] = $this->_params
['billing_' . $part];
1603 $this->assign('address', CRM_Utils_Address
::format($addressFields));
1605 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
1606 $date = CRM_Utils_Date
::mysqlToIso($date);
1607 $this->assign('credit_card_exp_date', $date);
1608 $this->assign('credit_card_number',
1609 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
1611 $this->assign('credit_card_type', $params['credit_card_type']);
1612 $this->assign('contributeMode', 'direct');
1613 $this->assign('isAmountzero', 0);
1614 $this->assign('is_pay_later', 0);
1615 $this->assign('isPrimary', 1);
1618 $this->assign('register_date', $params['register_date']);
1619 if ($params['receive_date']) {
1620 $this->assign('receive_date', $params['receive_date']);
1623 $participant = array(array('participant_id', '=', $participants[0]->id
, 0, 0));
1624 // check whether its a test drive ref CRM-3075
1625 if (!empty($this->_defaultValues
['is_test'])) {
1626 $participant[] = array('participant_test', '=', 1, 0, 0);
1629 $template = CRM_Core_Smarty
::singleton();
1630 $customGroup = array();
1631 //format submitted data
1632 foreach ($params['custom'] as $fieldID => $values) {
1633 foreach ($values as $fieldValue) {
1634 $customValue = array('data' => $fieldValue['value']);
1635 $customFields[$fieldID]['id'] = $fieldID;
1636 $formattedValue = CRM_Core_BAO_CustomGroup
::formatCustomValues($customValue, $customFields[$fieldID], TRUE);
1637 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace(' ', '', $formattedValue);
1641 foreach ($this->_contactIds
as $num => $contactID) {
1642 // Retrieve the name and email of the contact - this will be the TO for receipt email
1643 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($contactID);
1645 $this->_contributorDisplayName
= ($this->_contributorDisplayName
== ' ') ?
$this->_contributorEmail
: $this->_contributorDisplayName
;
1647 $waitStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
1648 if ($waitingStatus = CRM_Utils_Array
::value($params['status_id'], $waitStatus)) {
1649 $this->assign('isOnWaitlist', TRUE);
1652 $this->assign('customGroup', $customGroup);
1653 $this->assign('contactID', $contactID);
1654 $this->assign('participantID', $participants[$num]->id
);
1656 $this->_id
= $participants[$num]->id
;
1658 if ($this->_isPaidEvent
) {
1659 // fix amount for each of participants ( for bulk mode )
1660 $eventAmount = array();
1661 if (!empty($additionalParticipantDetails)) {
1662 $params['amount_level'] = preg_replace('/\ 1/', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName
;
1665 $eventAmount[$num] = array(
1666 'label' => preg_replace('/\ 1/', '', $params['amount_level']),
1667 'amount' => $params['fee_amount'],
1669 //as we are using same template for online & offline registration.
1670 //So we have to build amount as array.
1671 $eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
1672 $this->assign('amount', $eventAmount);
1675 $sendTemplateParams = array(
1676 'groupName' => 'msg_tpl_workflow_event',
1677 'valueName' => 'event_offline_receipt',
1678 'contactId' => $contactID,
1679 'isTest' => (bool) CRM_Utils_Array
::value('is_test', $this->_defaultValues
),
1680 'PDFFilename' => ts('confirmation').'.pdf',
1683 // try to send emails only if email id is present
1684 // and the do-not-email option is not checked for that contact
1685 if ($this->_contributorEmail
and !$this->_toDoNotEmail
) {
1686 $sendTemplateParams['from'] = $receiptFrom;
1687 $sendTemplateParams['toName'] = $this->_contributorDisplayName
;
1688 $sendTemplateParams['toEmail'] = $this->_contributorEmail
;
1689 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc', $this->_fromEmails
);
1690 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc', $this->_fromEmails
);
1693 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1695 $sent[] = $contactID;
1696 foreach ($participants as $ids => $values) {
1697 if ($values->contact_id
== $contactID) {
1698 $values->details
= CRM_Utils_Array
::value('receipt_text', $params);
1699 CRM_Activity_BAO_Activity
::addActivity($values, 'Email');
1705 $notSent[] = $contactID;
1710 // set the participant id if it is not set
1712 $this->_id
= $participants[0]->id
;
1715 if (($this->_action
& CRM_Core_Action
::UPDATE
)) {
1716 $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contributorDisplayName
));
1717 if (!empty($params['send_receipt']) && count($sent)) {
1718 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', array(1 => $this->_contributorEmail
));
1721 if ($updateStatusMsg) {
1722 $statusMsg = "{$statusMsg} {$updateStatusMsg}";
1725 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
1726 if ($this->_single
) {
1727 $statusMsg = ts('Event registration for %1 has been added.', array(1 => $this->_contributorDisplayName
));
1728 if (!empty($params['send_receipt']) && count($sent)) {
1729 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $this->_contributorEmail
));
1733 $statusMsg = ts('Total Participant(s) added to event: %1.', array(1 => count($this->_contactIds
)));
1734 if (count($notSent) > 0) {
1735 $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)));
1737 elseif (isset($params['send_receipt'])) {
1738 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');
1742 CRM_Core_Session
::setStatus($statusMsg, ts('Saved'), 'success');
1744 $buttonName = $this->controller
->getButtonName();
1745 if ($this->_context
== 'standalone') {
1746 if ($buttonName == $this->getButtonName('upload', 'new')) {
1747 $urlParams = 'reset=1&action=add&context=standalone';
1749 $urlParams .= '&mode=' . $this->_mode
;
1752 $urlParams .= '&eid=' . $this->_eID
;
1754 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/participant/add', $urlParams));
1757 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
1758 "reset=1&cid={$this->_contactId}&selectedChild=participant"
1762 elseif ($buttonName == $this->getButtonName('upload', 'new')) {
1763 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view/participant',
1764 "reset=1&action=add&context={$this->_context}&cid={$this->_contactId}"