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
) {
700 $urlPath = 'civicrm/contact/view/participant';
701 $urlParams = "reset=1&cid={$this->_contactId}&context=participant";
702 if ($this->_context
== 'standalone') {
703 $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE), TRUE);
704 $urlParams = 'reset=1&context=standalone';
705 $urlPath = 'civicrm/participant/add';
709 $urlParams .= "&action=update&id={$this->_id}";
712 $urlParams .= "&action=add";
716 $urlParams .= "&mode={$this->_mode}";
719 $url = CRM_Utils_System
::url($urlPath, $urlParams,
724 $currentPath = CRM_Utils_System
::currentPath();
726 $url = CRM_Utils_System
::url($currentPath, '_qf_Participant_display=true',
731 $this->assign('refreshURL', $url);
733 $eventFieldParams = array(
735 'select' => array('minimumInputLength' => 0),
737 'extra' => array('campaign_id', 'default_role_id', 'event_type_id'),
742 // exclude events which are not monetary when credit card registration is used
743 $eventFieldParams['api']['params']['is_monetary'] = 1;
744 $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors
, TRUE);
747 $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE);
749 //frozen the field fix for CRM-4171
750 if ($this->_action
& CRM_Core_Action
::UPDATE
&& $this->_id
) {
751 if (CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
752 $this->_id
, 'contribution_id', 'participant_id'
758 //CRM-7362 --add campaigns.
761 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'campaign_id');
764 $eventId = CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
766 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
769 CRM_Campaign_BAO_Campaign
::addCampaign($this, $campaignId);
771 $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
774 $this->assign('entityID', $this->_id
);
777 $this->addSelect('role_id', array('multiple' => TRUE, 'class' => 'huge'), TRUE);
780 $checkCancelledJs = array('onchange' => "return sendNotification( );");
782 if ($this->_onlinePendingContributionId
) {
783 $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant
::participantStatus());
784 $cancelledContributionStatusId = array_search('Cancelled',
785 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
787 $checkCancelledJs = array(
789 "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});",
792 $participantStatusId = array_search('Pending from pay later',
793 CRM_Event_PseudoConstant
::participantStatus()
795 $contributionStatusId = array_search('Completed',
796 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
798 $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
801 // get the participant status names to build special status array which is used to show notification
802 // checkbox below participant status select
803 $participantStatusName = CRM_Event_PseudoConstant
::participantStatus();
804 $notificationStatuses = array(
806 'Pending from waitlist',
807 'Pending from approval',
811 // get the required status and then implode only ids
812 $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
813 $this->assign('notificationStatusIds', $notificationStatusIds);
815 $this->_participantStatuses
= CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label');
816 $this->addSelect('status_id', $checkCancelledJs +
array('option_url' => 'civicrm/admin/participant_status'), TRUE);
818 $enableCart = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::EVENT_PREFERENCES_NAME
,
821 $pendingInCartStatusId = array_search('Pending in cart', $participantStatusName);
822 $this->assign('pendingInCartStatusId', $pendingInCartStatusId);
823 $this->assign('enableCart', $enableCart);
824 $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
825 $this->assign('pendingRefundStatusId', $pendingRefundStatusId);
827 $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
829 $this->add('text', 'source', ts('Event Source'));
830 $noteAttributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Note');
831 $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
835 'name' => ts('Save'),
840 $path = CRM_Utils_System
::currentPath();
841 $excludeForPaths = array(
842 'civicrm/contact/search',
843 'civicrm/group/search'
845 if (!in_array($path, $excludeForPaths)) {
848 'name' => ts('Save and New'),
856 'name' => ts('Cancel'),
859 $this->addButtons($buttons);
860 if ($this->_action
== CRM_Core_Action
::VIEW
) {
866 * Add local and global form rules
872 function addRules() {
873 $this->addFormRule(array('CRM_Event_Form_Participant', 'formRule'), $this);
877 * global validation rules for the form
883 * @internal param array $fields posted values of the form
885 * @return array list of errors to be posted back to the form
889 static function formRule($values, $files, $self) {
890 // If $values['_qf_Participant_next'] is Delete or
891 // $values['event_id'] is empty, then return
892 // instead of proceeding further.
894 if ((CRM_Utils_Array
::value('_qf_Participant_next', $values) == 'Delete') ||
895 (!$values['event_id'])
902 if (!empty($values['payment_processor_id'])) {
903 // make sure that credit card number and cvv are valid
904 CRM_Core_Payment_Form
::validateCreditCard($values, $errorMsg);
907 if (!empty($values['record_contribution'])) {
908 if (empty($values['financial_type_id'])) {
909 $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
911 if (empty($values['payment_instrument_id'])) {
912 $errorMsg['payment_instrument_id'] = ts('Paid By is a required field.');
916 // validate contribution status for 'Failed'.
917 if ($self->_onlinePendingContributionId
&& !empty($values['record_contribution']) &&
918 (CRM_Utils_Array
::value('contribution_status_id', $values) ==
919 array_search('Failed', CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name'))
922 $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.');
925 // do the amount validations.
926 //skip for update mode since amount is freeze, CRM-6052
927 if ((!$self->_id
&& empty($values['total_amount']) &&
928 empty($self->_values
['line_items'])
930 ($self->_id
&& !$self->_paymentId
&& isset($self->_values
['line_items']) && is_array($self->_values
['line_items']))
932 if ($priceSetId = CRM_Utils_Array
::value('priceSetId', $values)) {
933 CRM_Price_BAO_PriceField
::priceSetValidation($priceSetId, $values, $errorMsg, TRUE);
936 // For single additions - show validation error if the contact has already been registered
937 // for this event with the same role.
938 if($self->_single
&& ($self->_action
& CRM_Core_Action
::ADD
)) {
939 $contactId = $self->_contactId
;
940 $eventId = CRM_Utils_Array
::value('event_id', $values);
941 if(!empty($contactId) && !empty($eventId)) {
942 $dupeCheck = new CRM_Event_BAO_Participant
;
943 $dupeCheck->contact_id
= $contactId;
944 $dupeCheck->event_id
= $eventId;
945 $dupeCheck->find(TRUE);
946 if(!empty($dupeCheck->id
)) {
947 $errorMsg['event_id'] = ts("This contact has already been assigned to this event.");
951 return CRM_Utils_Array
::crmIsEmptyArray($errorMsg) ?
TRUE : $errorMsg;
955 * Function to process the form
959 public function postProcess() {
960 // get the submitted form values.
961 $params = $this->controller
->exportValues($this->_name
);
963 if ($this->_action
& CRM_Core_Action
::DELETE
) {
964 if (CRM_Utils_Array
::value('delete_participant', $params) == 2) {
965 $additionalId = (CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
));
966 $participantLinks = (CRM_Event_BAO_Participant
::getAdditionalParticipantUrl($additionalId));
968 if (CRM_Utils_Array
::value('delete_participant', $params) == 1) {
969 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
970 foreach ($additionalIds as $value) {
971 CRM_Event_BAO_Participant
::deleteParticipant($value);
974 CRM_Event_BAO_Participant
::deleteParticipant($this->_id
);
975 CRM_Core_Session
::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success');
976 if (!empty($participantLinks)) {
977 $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;
978 CRM_Core_Session
::setStatus($status, ts('Group Payment Deleted'));
982 // When adding a single contact, the formRule prevents you from adding duplicates
983 // (See above in formRule()). When adding more than one contact, the duplicates are
984 // removed automatically and the user receives one notification.
985 if ($this->_action
& CRM_Core_Action
::ADD
) {
986 if(!$this->_single
&& !empty($this->_eventId
)) {
987 $duplicateContacts = 0;
988 while(list($k,$dupeCheckContactId) = each($this->_contactIds
)) {
989 // Eliminate contacts that have already been assigned to this event.
990 $dupeCheck = new CRM_Event_BAO_Participant
;
991 $dupeCheck->contact_id
= $dupeCheckContactId;
992 $dupeCheck->event_id
= $this->_eventId
;
993 $dupeCheck->find(TRUE);
994 if(!empty($dupeCheck->id
)) {
995 $duplicateContacts++
;
996 unset($this->_contactIds
[$k]);
999 if($duplicateContacts > 0) {
1001 "%1 contacts have already been assigned to this event. They were not added a second time.",
1002 array(1 => $duplicateContacts)
1004 CRM_Core_Session
::setStatus($msg);
1006 if(count($this->_contactIds
) == 0) {
1007 CRM_Core_Session
::setStatus(ts("No participants were added."));
1010 // We have to re-key $this->_contactIds so each contact has the same
1011 // key as their corresponding record in the $participants array that
1012 // will be created below.
1013 $this->_contactIds
= array_values($this->_contactIds
);
1018 $participantStatus = CRM_Event_PseudoConstant
::participantStatus();
1019 // set the contact, when contact is selected
1020 if (!empty($params['contact_id'])) {
1021 $this->_contactId
= $params['contact_id'];
1023 if ($this->_priceSetId
&& $isQuickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
1024 $this->_quickConfig
= $isQuickConfig;
1028 $params['id'] = $this->_id
;
1031 $config = CRM_Core_Config
::singleton();
1032 if ($this->_isPaidEvent
) {
1034 $contributionParams = array();
1035 $lineItem = array();
1036 $additionalParticipantDetails = array();
1037 if (($this->_id
&& $this->_action
& CRM_Core_Action
::UPDATE
) && $this->_paymentId
) {
1038 $participantBAO = new CRM_Event_BAO_Participant();
1039 $participantBAO->id
= $this->_id
;
1040 $participantBAO->find(TRUE);
1041 $contributionParams['total_amount'] = $participantBAO->fee_amount
;
1043 $params['discount_id'] = NULL;
1044 //re-enter the values for UPDATE mode
1045 $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level
;
1046 $params['fee_amount'] = $participantBAO->fee_amount
;
1047 if (isset($params['priceSetId'])) {
1048 $lineItem[0] = CRM_Price_BAO_LineItem
::getLineItems($this->_id
);
1050 //also add additional participant's fee level/priceset
1051 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
1052 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
1053 $hasLineItems = CRM_Utils_Array
::value('priceSetId', $params, FALSE);
1054 $additionalParticipantDetails = CRM_Event_BAO_Participant
::getFeeDetails($additionalIds,
1061 //check if discount is selected
1062 if (!empty($params['discount_id'])) {
1063 $discountId = $params['discount_id'];
1066 $discountId = $params['discount_id'] = 'null';
1069 //lets carry currency, CRM-4453
1070 $params['fee_currency'] = $config->defaultCurrency
;
1071 CRM_Price_BAO_PriceSet
::processAmount($this->_values
['fee'],
1072 $params, $lineItem[0]
1074 //CRM-11529 for quick config backoffice transactions
1075 //when financial_type_id is passed in form, update the
1076 //lineitems with the financial type selected in form
1077 $submittedFinancialType = CRM_Utils_Array
::value('financial_type_id', $params);
1078 $isPaymentRecorded = CRM_Utils_Array
::value('record_contribution', $params);
1079 if ($isPaymentRecorded && $this->_quickConfig
&& $submittedFinancialType) {
1080 foreach ($lineItem[0] as &$values) {
1081 $values['financial_type_id'] = $submittedFinancialType;
1085 $params['fee_level'] = $params['amount_level'];
1086 $contributionParams['total_amount'] = $params['amount'];
1087 if ($this->_quickConfig
&& !empty($params['total_amount']) &&
1088 $params['status_id'] != array_search('Partially paid', $participantStatus)) {
1089 $params['fee_amount'] = $params['total_amount'];
1092 $params['fee_amount'] = $params['amount'];
1096 if (isset($params['priceSetId'])) {
1097 if (!empty($lineItem[0])) {
1098 $this->set('lineItem', $lineItem);
1100 $this->_lineItem
= $lineItem;
1101 $lineItem = array_merge($lineItem, $additionalParticipantDetails);
1103 $participantCount = array();
1104 foreach ($lineItem as $k) {
1105 foreach ($k as $v) {
1106 if (CRM_Utils_Array
::value('participant_count', $v) > 0) {
1107 $participantCount[] = $v['participant_count'];
1112 if (isset($participantCount)) {
1113 $this->assign('pricesetFieldsCount', $participantCount);
1115 $this->assign('lineItem', empty($lineItem[0]) ||
$this->_quickConfig?
FALSE : $lineItem);
1118 $this->assign('amount_level', $params['amount_level']);
1122 $this->_params
= $params;
1124 if (isset($params['amount'])) {
1125 $amountOwed = $params['amount'];
1126 unset($params['amount']);
1128 $params['register_date'] = CRM_Utils_Date
::processDate($params['register_date'], $params['register_date_time']);
1129 $params['receive_date'] = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('receive_date', $params));
1130 $params['contact_id'] = $this->_contactId
;
1132 // overwrite actual payment amount if entered
1133 if (!empty($params['total_amount'])) {
1134 $contributionParams['total_amount'] = CRM_Utils_Array
::value('total_amount', $params);
1138 // Retrieve the name and email of the current user - this will be the FROM for the receipt email
1139 $session = CRM_Core_Session
::singleton();
1140 $userID = $session->get('userID');
1143 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($userID);
1145 if ($this->_contactId
) {
1146 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($this->_contactId
);
1149 //modify params according to parameter used in create
1150 //participant method (addParticipant)
1151 $this->_params
['participant_status_id'] = $params['status_id'];
1152 $this->_params
['participant_role_id'] = is_array($params['role_id']) ?
$params['role_id'] : explode(',', $params['role_id']);
1153 $this->_params
['participant_register_date'] = $params['register_date'];
1154 $roleIdWithSeparator = implode(CRM_Core_DAO
::VALUE_SEPARATOR
, $this->_params
['participant_role_id']);
1157 if (!$this->_isPaidEvent
) {
1158 CRM_Core_Error
::fatal(ts('Selected Event is not Paid Event '));
1162 CRM_Core_DAO
::getFieldValue(
1163 'CRM_Event_DAO_Event',
1164 $params['event_id'],
1168 // set source if not set
1169 if (empty($params['source'])) {
1170 $this->_params
['participant_source'] = ts('Offline Registration for Event: %2 by: %1', array(1 => $userName, 2 => $eventTitle));
1173 $this->_params
['participant_source'] = $params['source'];
1175 $this->_params
['description'] = $this->_params
['participant_source'];
1177 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($this->_params
['payment_processor_id'],
1180 $now = date('YmdHis');
1183 // set email for primary location.
1184 $fields['email-Primary'] = 1;
1185 $params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail
;
1187 $params['register_date'] = $now;
1189 // now set the values for the billing location.
1190 foreach ($this->_fields
as $name => $dontCare) {
1194 // also add location name to the array
1195 $params["address_name-{$this->_bltID}"] =
1196 CRM_Utils_Array
::value('billing_first_name', $params) . ' ' .
1197 CRM_Utils_Array
::value('billing_middle_name', $params) . ' ' .
1198 CRM_Utils_Array
::value('billing_last_name', $params);
1200 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
1201 $fields["address_name-{$this->_bltID}"] = 1;
1202 $fields["email-{$this->_bltID}"] = 1;
1203 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'contact_type');
1205 $nameFields = array('first_name', 'middle_name', 'last_name');
1207 foreach ($nameFields as $name) {
1209 if (array_key_exists("billing_$name", $params)) {
1210 $params[$name] = $params["billing_{$name}"];
1211 $params['preserveDBName'] = TRUE;
1214 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params, $fields, $this->_contactId
, NULL, NULL, $ctype);
1217 if (!empty($this->_params
['participant_role_id'])) {
1218 $customFieldsRole = array();
1219 foreach ($this->_params
['participant_role_id'] as $roleKey) {
1220 $customFieldsRole = CRM_Utils_Array
::crmArrayMerge(CRM_Core_BAO_CustomField
::getFields('Participant',
1221 FALSE, FALSE, $roleKey, $this->_roleCustomDataTypeID
), $customFieldsRole);
1223 $customFieldsEvent = CRM_Core_BAO_CustomField
::getFields('Participant',
1226 CRM_Utils_Array
::value('event_id', $params),
1227 $this->_eventNameCustomDataTypeID
1229 $customFieldsEventType = CRM_Core_BAO_CustomField
::getFields('Participant',
1232 $this->_eventTypeId
,
1233 $this->_eventTypeCustomDataTypeID
1235 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsRole,
1236 CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE)
1238 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEvent, $customFields);
1239 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEventType, $customFields);
1240 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
1247 //do cleanup line items if participant edit the Event Fee.
1248 if (($this->_lineItem ||
!isset($params['proceSetId'])) && !$this->_paymentId
&& $this->_id
) {
1249 CRM_Price_BAO_LineItem
::deleteLineItems($this->_id
, 'civicrm_participant');
1253 // add all the additional payment params we need
1254 $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}"]);
1255 $this->_params
["country-{$this->_bltID}"] = $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
1257 $this->_params
['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($this->_params
);
1258 $this->_params
['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($this->_params
);
1259 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
1260 $this->_params
['amount'] = $params['fee_amount'];
1261 $this->_params
['amount_level'] = $params['amount_level'];
1262 $this->_params
['currencyID'] = $config->defaultCurrency
;
1263 $this->_params
['payment_action'] = 'Sale';
1264 $this->_params
['invoiceID'] = md5(uniqid(rand(), TRUE));
1266 // at this point we've created a contact and stored its address etc
1267 // all the payment processors expect the name and address to be in the
1268 // so we copy stuff over to first_name etc.
1269 $paymentParams = $this->_params
;
1270 if (!empty($this->_params
['send_receipt'])) {
1271 $paymentParams['email'] = $this->_contributorEmail
;
1273 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $this->_params
, $paymentParams, TRUE);
1275 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
1277 $result = &$payment->doDirectPayment($paymentParams);
1279 if (is_a($result, 'CRM_Core_Error')) {
1280 CRM_Core_Error
::displaySessionError($result);
1281 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/view/participant',
1282 "reset=1&action=add&cid={$this->_contactId}&context=participant&mode={$this->_mode}"
1287 $this->_params
= array_merge($this->_params
, $result);
1290 $this->_params
['receive_date'] = $now;
1292 if (!empty($this->_params
['send_receipt'])) {
1293 $this->_params
['receipt_date'] = $now;
1296 $this->_params
['receipt_date'] = NULL;
1299 $this->set('params', $this->_params
);
1300 $this->assign('trxn_id', $result['trxn_id']);
1301 $this->assign('receive_date',
1302 CRM_Utils_Date
::processDate($this->_params
['receive_date'])
1305 //add contribution record
1306 $this->_params
['financial_type_id'] =
1307 CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
1308 $this->_params
['mode'] = $this->_mode
;
1310 //add contribution reocord
1311 $contributions[] = $contribution = CRM_Event_Form_Registration_Confirm
::processContribution($this, $this->_params
, $result, $contactID, FALSE);
1313 // add participant record
1314 $participants = array();
1315 if (!empty($this->_params
['role_id']) && is_array($this->_params
['role_id'])) {
1316 $this->_params
['role_id'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1317 $this->_params
['role_id']
1320 $participants[] = CRM_Event_Form_Registration
::addParticipant($this->_params
, $contactID);
1322 //add custom data for participant
1323 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
1324 CRM_Core_DAO
::$_nullArray,
1325 'civicrm_participant',
1326 $participants[0]->id
,
1329 //add participant payment
1330 $paymentParticipant = array(
1331 'participant_id' => $participants[0]->id
,
1332 'contribution_id' => $contribution->id
,
1336 CRM_Event_BAO_ParticipantPayment
::create($paymentParticipant, $ids);
1337 $this->_contactIds
[] = $this->_contactId
;
1340 $participants = array();
1341 if ($this->_single
) {
1342 if ($params['role_id']) {
1343 $params['role_id'] = $roleIdWithSeparator;
1346 $params['role_id'] = 'NULL';
1348 $participants[] = CRM_Event_BAO_Participant
::create($params);
1351 foreach ($this->_contactIds
as $contactID) {
1352 $commonParams = $params;
1353 $commonParams['contact_id'] = $contactID;
1354 if ($commonParams['role_id']) {
1355 $commonParams['role_id'] = $commonParams['role_id'] = str_replace(',', CRM_Core_DAO
::VALUE_SEPARATOR
, $params['role_id']);
1358 $commonParams['role_id'] = 'NULL';
1360 $participants[] = CRM_Event_BAO_Participant
::create($commonParams);
1364 if (isset($params['event_id'])) {
1365 $eventTitle = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
1366 $params['event_id'],
1371 if ($this->_single
) {
1372 $this->_contactIds
[] = $this->_contactId
;
1375 $contributions = array();
1376 if (!empty($params['record_contribution'])) {
1377 if (!empty($params['id'])) {
1378 if ($this->_onlinePendingContributionId
) {
1379 $ids['contribution'] = $this->_onlinePendingContributionId
;
1382 $ids['contribution'] = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1389 unset($params['note']);
1391 //build contribution params
1392 if (!$this->_onlinePendingContributionId
) {
1393 $contributionParams['source'] = "{$eventTitle}: Offline registration (by {$userName})";
1396 $contributionParams['currency'] = $config->defaultCurrency
;
1397 $contributionParams['non_deductible_amount'] = 'null';
1398 $contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array
::value('receive_date', $params) : 'null';
1400 $recordContribution = array( 'contact_id', 'financial_type_id',
1401 'payment_instrument_id', 'trxn_id',
1402 'contribution_status_id', 'receive_date',
1403 'check_number', 'campaign_id',
1406 foreach ($recordContribution as $f) {
1407 $contributionParams[$f] = CRM_Utils_Array
::value($f, $params);
1408 if ($f == 'trxn_id') {
1409 $this->assign('trxn_id', $contributionParams[$f]);
1413 //insert financial type name in receipt.
1414 $this->assign('contributionTypeName', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id']));
1415 $contributionParams['skipLineItem'] = 1;
1417 $contributionParams['contribution_mode'] = 'participant';
1418 $contributionParams['participant_id'] = $this->_id
;
1420 // Set is_pay_later flag for back-office offline Pending status contributions
1421 if ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup
::getValue('contribution_status', 'Pending', 'name')) {
1422 $contributionParams['is_pay_later'] = 1;
1425 if ($params['status_id'] == array_search('Partially paid', $participantStatus)) {
1426 if (!$amountOwed && $this->_action
& CRM_Core_Action
::UPDATE
) {
1427 $amountOwed = $params['fee_amount'];
1430 // if multiple participants are link, consider contribution total amount as the amount Owed
1431 if ($this->_id
&& CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
1432 $amountOwed = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_Contribution',
1433 $ids['contribution'],
1438 // CRM-13964 partial_payment_total
1439 if ($amountOwed > $params['total_amount']) {
1441 $contributionParams['partial_payment_total'] = $amountOwed;
1442 // the actual amount paid
1443 $contributionParams['partial_amount_pay'] = $params['total_amount'];
1447 if ($this->_single
) {
1451 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1455 foreach ($this->_contactIds
as $contactID) {
1456 $contributionParams['contact_id'] = $contactID;
1457 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1461 //insert payment record for this participation
1462 if (empty($ids['contribution'])) {
1463 foreach ($this->_contactIds
as $num => $contactID) {
1464 $ppDAO = new CRM_Event_DAO_ParticipantPayment();
1465 $ppDAO->participant_id
= $participants[$num]->id
;
1466 $ppDAO->contribution_id
= $contributions[$num]->id
;
1470 // next create the transaction record
1471 $transaction = new CRM_Core_Transaction();
1474 if ($this->_quickConfig
) {
1475 if (!empty($this->_params
['amount_priceset_level_radio'])) {
1476 $feeLevel = $this->_params
['amount_priceset_level_radio'];
1479 $feeLevel[] = $this->_params
['fee_level'] ;
1481 CRM_Event_BAO_Participant
::createDiscountTrxn($this->_eventId
, $contributionParams, $feeLevel);
1483 $transaction->commit();
1487 // also store lineitem stuff here
1488 if ((($this->_lineItem
& $this->_action
& CRM_Core_Action
::ADD
) ||
1489 ($this->_lineItem
&& CRM_Core_Action
::UPDATE
&& !$this->_paymentId
))
1491 foreach ($this->_contactIds
as $num => $contactID) {
1492 foreach ($this->_lineItem
as $key => $value) {
1493 if (is_array($value) && $value != 'skip') {
1494 foreach ($value as $lineKey => $line) {
1495 //10117 update the line items for participants if contribution amount is recorded
1496 if ($this->_quickConfig
&& !empty($params['total_amount']) &&
1497 ($params['status_id'] != array_search('Partially paid', $participantStatus))
1499 $line['unit_price'] = $line['line_total'] = $params['total_amount'];
1501 $lineItem[$this->_priceSetId
][$lineKey] = $line;
1503 CRM_Price_BAO_LineItem
::processPriceSet($participants[$num]->id
, $lineItem, CRM_Utils_Array
::value($num, $contributions, NULL), 'civicrm_participant');
1509 $updateStatusMsg = NULL;
1510 //send mail when participant status changed, CRM-4326
1511 if ($this->_id
&& $this->_statusId
&&
1512 $this->_statusId
!= CRM_Utils_Array
::value('status_id', $params) && !empty($params['is_notify'])) {
1514 $updateStatusMsg = CRM_Event_BAO_Participant
::updateStatusMessage($this->_id
,
1515 $params['status_id'],
1522 if (!empty($params['send_receipt'])) {
1523 if (array_key_exists($params['from_email_address'], $this->_fromEmails
['from_email_id'])) {
1524 $receiptFrom = $params['from_email_address'];
1527 $this->assign('module', 'Event Registration');
1528 //use of the message template below requires variables in different format
1529 $event = $events = array();
1530 $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
1532 //get all event details.
1533 CRM_Core_DAO
::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
1534 $event = $events[$params['event_id']];
1535 unset($event['start_date']);
1536 unset($event['end_date']);
1538 $role = CRM_Event_PseudoConstant
::participantRole();
1539 $participantRoles = CRM_Utils_Array
::value('role_id', $params);
1540 if (is_array($participantRoles)) {
1541 $selectedRoles = array();
1542 foreach ($participantRoles as $roleId) {
1543 $selectedRoles[] = $role[$roleId];
1545 $event['participant_role'] = implode(', ', $selectedRoles);
1548 $event['participant_role'] = CRM_Utils_Array
::value($participantRoles, $role);
1550 $event['is_monetary'] = $this->_isPaidEvent
;
1552 if ($params['receipt_text']) {
1553 $event['confirm_email_text'] = $params['receipt_text'];
1556 $this->assign('isAmountzero', 1);
1557 $this->assign('event', $event);
1559 $this->assign('isShowLocation', $event['is_show_location']);
1560 if (CRM_Utils_Array
::value('is_show_location', $event) == 1) {
1561 $locationParams = array(
1562 'entity_id' => $params['event_id'],
1563 'entity_table' => 'civicrm_event',
1565 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
1566 $this->assign('location', $location);
1569 $status = CRM_Event_PseudoConstant
::participantStatus();
1570 if ($this->_isPaidEvent
) {
1571 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
1572 if (!$this->_mode
) {
1573 if (isset($params['payment_instrument_id'])) {
1574 $this->assign('paidBy',
1575 CRM_Utils_Array
::value($params['payment_instrument_id'],
1582 $this->assign('totalAmount', $contributionParams['total_amount']);
1583 if (isset($contributionParams['partial_payment_total'])) {
1585 $balanceAmount = $contributionParams['partial_payment_total'] - $contributionParams['partial_amount_pay'];
1586 $this->assign('balanceAmount', $balanceAmount );
1588 $this->assign('isPrimary', 1);
1589 $this->assign('checkNumber', CRM_Utils_Array
::value('check_number', $params));
1592 if (!empty($params['billing_first_name'])) {
1593 $name = $params['billing_first_name'];
1596 if (!empty($params['billing_middle_name'])) {
1597 $name .= " {$params['billing_middle_name']}";
1600 if (!empty($params['billing_last_name'])) {
1601 $name .= " {$params['billing_last_name']}";
1603 $this->assign('billingName', $name);
1605 // assign the address formatted up for display
1606 $addressParts = array(
1607 "street_address-{$this->_bltID}",
1608 "city-{$this->_bltID}",
1609 "postal_code-{$this->_bltID}",
1610 "state_province-{$this->_bltID}",
1611 "country-{$this->_bltID}",
1613 $addressFields = array();
1614 foreach ($addressParts as $part) {
1615 list($n, $id) = explode('-', $part);
1616 if (isset($this->_params
['billing_' . $part])) {
1617 $addressFields[$n] = $this->_params
['billing_' . $part];
1620 $this->assign('address', CRM_Utils_Address
::format($addressFields));
1622 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
1623 $date = CRM_Utils_Date
::mysqlToIso($date);
1624 $this->assign('credit_card_exp_date', $date);
1625 $this->assign('credit_card_number',
1626 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
1628 $this->assign('credit_card_type', $params['credit_card_type']);
1629 $this->assign('contributeMode', 'direct');
1630 $this->assign('isAmountzero', 0);
1631 $this->assign('is_pay_later', 0);
1632 $this->assign('isPrimary', 1);
1635 $this->assign('register_date', $params['register_date']);
1636 if ($params['receive_date']) {
1637 $this->assign('receive_date', $params['receive_date']);
1640 $participant = array(array('participant_id', '=', $participants[0]->id
, 0, 0));
1641 // check whether its a test drive ref CRM-3075
1642 if (!empty($this->_defaultValues
['is_test'])) {
1643 $participant[] = array('participant_test', '=', 1, 0, 0);
1646 $template = CRM_Core_Smarty
::singleton();
1647 $customGroup = array();
1648 //format submitted data
1649 foreach ($params['custom'] as $fieldID => $values) {
1650 foreach ($values as $fieldValue) {
1651 $customValue = array('data' => $fieldValue['value']);
1652 $customFields[$fieldID]['id'] = $fieldID;
1653 $formattedValue = CRM_Core_BAO_CustomGroup
::formatCustomValues($customValue, $customFields[$fieldID], TRUE);
1654 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace(' ', '', $formattedValue);
1658 foreach ($this->_contactIds
as $num => $contactID) {
1659 // Retrieve the name and email of the contact - this will be the TO for receipt email
1660 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($contactID);
1662 $this->_contributorDisplayName
= ($this->_contributorDisplayName
== ' ') ?
$this->_contributorEmail
: $this->_contributorDisplayName
;
1664 $waitStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
1665 if ($waitingStatus = CRM_Utils_Array
::value($params['status_id'], $waitStatus)) {
1666 $this->assign('isOnWaitlist', TRUE);
1669 $this->assign('customGroup', $customGroup);
1670 $this->assign('contactID', $contactID);
1671 $this->assign('participantID', $participants[$num]->id
);
1673 $this->_id
= $participants[$num]->id
;
1675 if ($this->_isPaidEvent
) {
1676 // fix amount for each of participants ( for bulk mode )
1677 $eventAmount = array();
1678 if (!empty($additionalParticipantDetails)) {
1679 $params['amount_level'] = preg_replace('/\ 1/', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName
;
1682 $eventAmount[$num] = array(
1683 'label' => preg_replace('/\ 1/', '', $params['amount_level']),
1684 'amount' => $params['fee_amount'],
1686 //as we are using same template for online & offline registration.
1687 //So we have to build amount as array.
1688 $eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
1689 $this->assign('amount', $eventAmount);
1692 $sendTemplateParams = array(
1693 'groupName' => 'msg_tpl_workflow_event',
1694 'valueName' => 'event_offline_receipt',
1695 'contactId' => $contactID,
1696 'isTest' => (bool) CRM_Utils_Array
::value('is_test', $this->_defaultValues
),
1697 'PDFFilename' => ts('confirmation').'.pdf',
1700 // try to send emails only if email id is present
1701 // and the do-not-email option is not checked for that contact
1702 if ($this->_contributorEmail
and !$this->_toDoNotEmail
) {
1703 $sendTemplateParams['from'] = $receiptFrom;
1704 $sendTemplateParams['toName'] = $this->_contributorDisplayName
;
1705 $sendTemplateParams['toEmail'] = $this->_contributorEmail
;
1706 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc', $this->_fromEmails
);
1707 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc', $this->_fromEmails
);
1710 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1712 $sent[] = $contactID;
1713 foreach ($participants as $ids => $values) {
1714 if ($values->contact_id
== $contactID) {
1715 $values->details
= CRM_Utils_Array
::value('receipt_text', $params);
1716 CRM_Activity_BAO_Activity
::addActivity($values, 'Email');
1722 $notSent[] = $contactID;
1727 // set the participant id if it is not set
1729 $this->_id
= $participants[0]->id
;
1732 if (($this->_action
& CRM_Core_Action
::UPDATE
)) {
1733 $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contributorDisplayName
));
1734 if (!empty($params['send_receipt']) && count($sent)) {
1735 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', array(1 => $this->_contributorEmail
));
1738 if ($updateStatusMsg) {
1739 $statusMsg = "{$statusMsg} {$updateStatusMsg}";
1742 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
1743 if ($this->_single
) {
1744 $statusMsg = ts('Event registration for %1 has been added.', array(1 => $this->_contributorDisplayName
));
1745 if (!empty($params['send_receipt']) && count($sent)) {
1746 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $this->_contributorEmail
));
1750 $statusMsg = ts('Total Participant(s) added to event: %1.', array(1 => count($this->_contactIds
)));
1751 if (count($notSent) > 0) {
1752 $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)));
1754 elseif (isset($params['send_receipt'])) {
1755 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');
1759 CRM_Core_Session
::setStatus($statusMsg, ts('Saved'), 'success');
1761 $buttonName = $this->controller
->getButtonName();
1762 if ($this->_context
== 'standalone') {
1763 if ($buttonName == $this->getButtonName('upload', 'new')) {
1764 $urlParams = 'reset=1&action=add&context=standalone';
1766 $urlParams .= '&mode=' . $this->_mode
;
1769 $urlParams .= '&eid=' . $this->_eID
;
1771 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/participant/add', $urlParams));
1774 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
1775 "reset=1&cid={$this->_contactId}&selectedChild=participant"
1779 elseif ($buttonName == $this->getButtonName('upload', 'new')) {
1780 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view/participant',
1781 "reset=1&action=add&context={$this->_context}&cid={$this->_contactId}"