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 // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
222 CRM_Utils_System
::setTitle(ts('Event Registration for') . ' ' . $displayName);
225 // check the current path, if search based, then dont get participantID
227 $path = CRM_Utils_System
::currentPath();
229 strpos($path, 'civicrm/contact/search') === 0 ||
230 strpos($path, 'civicrm/group/search') === 0
235 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
239 $this->assign('participantId', $this->_id
);
241 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
242 $this->_id
, 'id', 'participant_id'
245 $this->assign('hasPayment', $this->_paymentId
);
247 // CRM-12615 - Get payment information from the primary registration
248 if ((!$this->_paymentId
) && ($this->_action
== CRM_Core_Action
::UPDATE
)) {
249 $registered_by_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
250 $this->_id
, 'registered_by_id', 'id'
252 if ($registered_by_id) {
253 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
254 $registered_by_id, 'id', 'participant_id'
256 $this->assign('registeredByParticipantId', $registered_by_id);
261 // get the option value for custom data type
262 $this->_roleCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantRole', 'name');
263 $this->_eventNameCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantEventName', 'name');
264 $this->_eventTypeCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantEventType', 'name');
265 $this->assign('roleCustomDataTypeID', $this->_roleCustomDataTypeID
);
266 $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID
);
267 $this->assign('eventTypeCustomDataTypeID', $this->_eventTypeCustomDataTypeID
);
270 $this->assign('participantMode', $this->_mode
);
272 $this->_paymentProcessor
= array('billing_mode' => 1);
274 $validProcessors = array();
275 $processors = CRM_Core_PseudoConstant
::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )");
277 foreach ($processors as $ppID => $label) {
278 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getPayment($ppID, $this->_mode
);
279 if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) {
282 elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode
== 'live') {
286 $paymentObject = CRM_Core_Payment
::singleton($this->_mode
, $paymentProcessor, $this);
287 $error = $paymentObject->checkConfig();
289 $validProcessors[$ppID] = $label;
291 $paymentObject = NULL;
294 if (empty($validProcessors)) {
295 CRM_Core_Error
::fatal(ts('Could not find valid payment processor for this page'));
298 $this->_processors
= $validProcessors;
300 // also check for billing information
301 // get the billing location type
302 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
303 // CRM-8108 remove ts around Billing location type
304 //$this->_bltID = array_search( ts('Billing'), $locationTypes );
305 $this->_bltID
= array_search('Billing', $locationTypes);
306 if (!$this->_bltID
) {
307 CRM_Core_Error
::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
309 $this->set('bltID', $this->_bltID
);
310 $this->assign('bltID', $this->_bltID
);
312 $this->_fields
= array();
314 CRM_Core_Payment_Form
::setCreditCardFields($this);
316 // this required to show billing block
317 $this->assign_by_ref('paymentProcessor', $paymentProcessor);
318 $this->assign('hidePayPalExpress', TRUE);
321 if ($this->_showFeeBlock
) {
322 $this->assign('showFeeBlock', TRUE);
323 $isMonetary = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_showFeeBlock
, 'is_monetary');
325 $this->assign('feeBlockPaid', TRUE);
327 return CRM_Event_Form_EventFees
::preProcess($this);
330 //custom data related code
331 $this->_cdType
= CRM_Utils_Array
::value('type', $_GET);
332 $this->assign('cdType', FALSE);
333 if ($this->_cdType
) {
334 $this->assign('cdType', TRUE);
335 return CRM_Custom_Form_CustomData
::preProcess($this, NULL, NULL, NULL, NULL, NULL, TRUE);
338 //check the mode when this form is called either single or as
340 if ($this->_id ||
$this->_contactId ||
$this->_context
== 'standalone') {
341 $this->_single
= TRUE;
342 $this->assign('urlPath', 'civicrm/contact/view/participant');
343 if (!$this->_id
&& !$this->_contactId
) {
344 $breadCrumbs = array(array('title' => ts('CiviEvent Dashboard'),
345 'url' => CRM_Utils_System
::url('civicrm/event', 'reset=1'),
348 CRM_Utils_System
::appendBreadCrumb($breadCrumbs);
352 //set the appropriate action
353 $context = $this->get('context');
354 $urlString = 'civicrm/contact/search';
355 $this->_action
= CRM_Core_Action
::BASIC
;
358 $urlString = 'civicrm/contact/search/advanced';
359 $this->_action
= CRM_Core_Action
::ADVANCED
;
363 $urlString = 'civicrm/contact/search/builder';
364 $this->_action
= CRM_Core_Action
::PROFILE
;
368 $urlString = 'civicrm/contact/search/basic';
369 $this->_action
= CRM_Core_Action
::BASIC
;
373 $urlString = 'civicrm/contact/search/custom';
374 $this->_action
= CRM_Core_Action
::COPY
;
377 parent
::preProcess();
379 $this->_single
= FALSE;
380 $this->_contactId
= NULL;
382 //set ajax path, this used for custom data building
383 $this->assign('urlPath', $urlString);
384 $this->assign('urlPathVar', "_qf_Participant_display=true&qfKey={$this->controller->_key}");
387 $this->assign('single', $this->_single
);
390 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
392 $this->assign('action', $this->_action
);
394 // check for edit permission
395 if (!CRM_Core_Permission
::checkActionPermission('CiviEvent', $this->_action
)) {
396 CRM_Core_Error
::fatal(ts('You do not have permission to access this page'));
399 if ($this->_action
& CRM_Core_Action
::DELETE
) {
400 // check delete permission for contribution
401 if ($this->_id
&& $this->_paymentId
&& !CRM_Core_Permission
::checkActionPermission('CiviContribute', $this->_action
)) {
402 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."));
408 // assign participant id to the template
409 $this->assign('participantId', $this->_id
);
410 $this->_roleId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'role_id');
413 // when fee amount is included in form
414 if (!empty($_POST['hidden_feeblock']) ||
!empty($_POST['send_receipt'])) {
415 CRM_Event_Form_EventFees
::preProcess($this);
416 CRM_Event_Form_EventFees
::buildQuickForm($this);
417 CRM_Event_Form_EventFees
::setDefaultValues($this);
420 // when custom data is included in this page
421 if (!empty($_POST['hidden_custom'])) {
422 //custom data of type participant role
423 if (!empty($_POST['role_id'])) {
424 foreach ($_POST['role_id'] as $k => $val) {
426 CRM_Custom_Form_CustomData
::preProcess($this, $this->_roleCustomDataTypeID
, $k, 1, 'Participant', $this->_id
);
427 CRM_Custom_Form_CustomData
::buildQuickForm($this);
428 CRM_Custom_Form_CustomData
::setDefaultValues($this);
432 //custom data of type participant event
433 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventNameCustomDataTypeID
, $_POST['event_id'], 1, 'Participant', $this->_id
);
434 CRM_Custom_Form_CustomData
::buildQuickForm($this);
435 CRM_Custom_Form_CustomData
::setDefaultValues($this);
437 // custom data of type participant event type
439 if ($eventId = CRM_Utils_Array
::value('event_id', $_POST)) {
440 $eventTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'event_type_id', 'id');
442 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventTypeCustomDataTypeID
, $eventTypeId,
443 1, 'Participant', $this->_id
445 CRM_Custom_Form_CustomData
::buildQuickForm($this);
446 CRM_Custom_Form_CustomData
::setDefaultValues($this);
448 //custom data of type participant, ( we 'null' to reset subType and subName)
449 CRM_Custom_Form_CustomData
::preProcess($this, 'null', 'null', 1, 'Participant', $this->_id
);
450 CRM_Custom_Form_CustomData
::buildQuickForm($this);
451 CRM_Custom_Form_CustomData
::setDefaultValues($this);
454 // CRM-4395, get the online pending contribution id.
455 $this->_onlinePendingContributionId
= NULL;
456 if (!$this->_mode
&& $this->_id
&& ($this->_action
& CRM_Core_Action
::UPDATE
)) {
457 $this->_onlinePendingContributionId
= CRM_Contribute_BAO_Contribution
::checkOnlinePendingContribution($this->_id
,
461 $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId
);
465 * This function sets the default values for the form in edit/view mode
466 * the default values are retrieved from the database
472 public function setDefaultValues() {
473 if ($this->_showFeeBlock
) {
474 return CRM_Event_Form_EventFees
::setDefaultValues($this);
477 if ($this->_cdType
) {
478 return CRM_Custom_Form_CustomData
::setDefaultValues($this);
483 if ($this->_action
& CRM_Core_Action
::DELETE
) {
489 $params = array('id' => $this->_id
);
491 CRM_Event_BAO_Participant
::getValues($params, $defaults, $ids);
492 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
493 if ($defaults[$this->_id
]['role_id']) {
494 $roleIDs = explode($sep, $defaults[$this->_id
]['role_id']);
496 $this->_contactId
= $defaults[$this->_id
]['contact_id'];
497 $this->_statusId
= $defaults[$this->_id
]['participant_status_id'];
499 //set defaults for note
500 $noteDetails = CRM_Core_BAO_Note
::getNote($this->_id
, 'civicrm_participant');
501 $defaults[$this->_id
]['note'] = array_pop($noteDetails);
503 // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859)
504 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
505 $this->assign('additionalParticipants', CRM_Event_BAO_Participant
::getAdditionalParticipants($this->_id
));
508 // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
509 if (!empty($defaults[$this->_id
]['participant_registered_by_id'])) {
510 $registered_by_contact_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
511 $defaults[$this->_id
]['participant_registered_by_id'],
514 $this->assign('participant_registered_by_id', $defaults[$this->_id
]['participant_registered_by_id']);
515 $this->assign('registered_by_contact_id', $registered_by_contact_id);
516 $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact
::displayName($registered_by_contact_id));
520 if ($this->_action
& (CRM_Core_Action
::VIEW | CRM_Core_Action
::BROWSE
)) {
521 $inactiveNeeded = TRUE;
526 $inactiveNeeded = FALSE;
529 //setting default register date
530 if ($this->_action
== CRM_Core_Action
::ADD
) {
531 $statuses = array_flip($this->_participantStatuses
);
532 $defaults[$this->_id
]['status_id'] = CRM_Utils_Array
::value(ts('Registered'), $statuses);
533 if (!empty($defaults[$this->_id
]['event_id'])) {
534 $contributionTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
535 $defaults[$this->_id
]['event_id'],
538 if ($contributionTypeId) {
539 $defaults[$this->_id
]['financial_type_id'] = $contributionTypeId;
544 $fields["email-{$this->_bltID}"] = 1;
545 $fields['email-Primary'] = 1;
547 if ($this->_contactId
) {
548 CRM_Core_BAO_UFGroup
::setProfileDefaults($this->_contactId
, $fields, $defaults);
551 if (empty($defaults["email-{$this->_bltID}"]) &&
552 !empty($defaults['email-Primary'])
554 $defaults[$this->_id
]["email-{$this->_bltID}"] = $defaults['email-Primary'];
558 $submittedRole = $this->getElementValue('role_id');
559 if (!empty($submittedRole[0])) {
560 $roleID = $submittedRole[0];
562 $submittedEvent = $this->getElementValue('event_id');
563 if ($submittedEvent[0]) {
564 $eventID = $submittedEvent[0];
568 $defaults[$this->_id
]['record_contribution'] = 0;
570 if ($defaults[$this->_id
]['participant_is_pay_later']) {
571 $this->assign('participant_is_pay_later', TRUE);
574 $this->assign('participant_status_id', $defaults[$this->_id
]['participant_status_id']);
575 $eventID = $defaults[$this->_id
]['event_id'];
577 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
579 $this->_discountId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'discount_id');
580 if ($this->_discountId
) {
581 $this->set('discountId', $this->_discountId
);
585 list($defaults[$this->_id
]['register_date'],
586 $defaults[$this->_id
]['register_date_time']
587 ) = CRM_Utils_Date
::setDateDefaults(
588 CRM_Utils_Array
::value('register_date', $defaults[$this->_id
]), 'activityDateTime'
591 //assign event and role id, this is needed for Custom data building
592 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
593 if (!empty($defaults[$this->_id
]['participant_role_id'])) {
594 $roleIDs = explode($sep, $defaults[$this->_id
]['participant_role_id']);
596 if (isset($_POST['event_id'])) {
597 $eventID = $_POST['event_id'];
601 $eventID = $this->_eID
;
602 //@todo - rationalise the $this->_eID with $POST['event_id'], $this->_eid is set when eid=x is in the url
603 $roleID = CRM_Core_DAO
::getFieldValue(
604 'CRM_Event_DAO_Event',
608 if(empty($roleIDs)) {
609 $roleIDs = (array) $defaults[$this->_id
]['participant_role_id'] = $roleID;
611 $defaults[$this->_id
]['event_id'] = $eventID;
613 if (!empty($eventID)) {
614 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
616 //these should take precedence so we state them last
617 $urlRoleIDS = CRM_Utils_Request
::retrieve('roles', 'String');
619 $roleIDs = explode(',', $urlRoleIDS);
621 if (isset($roleIDs)) {
622 $defaults[$this->_id
]['role_id'] = implode(',', $roleIDs);
625 if (isset($eventID)) {
626 $this->assign('eventID', $eventID);
627 $this->set('eventId', $eventID);
630 if (isset($this->_eventTypeId
)) {
631 $this->assign('eventTypeID', $this->_eventTypeId
);
634 $this->assign('event_is_test', CRM_Utils_Array
::value('event_is_test', $defaults[$this->_id
]));
635 return $defaults[$this->_id
];
639 * Function to build the form
644 public function buildQuickForm() {
645 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
646 $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses);
647 $this->assign('partiallyPaidStatusId', $partiallyPaidStatusId);
649 if ($this->_showFeeBlock
) {
650 return CRM_Event_Form_EventFees
::buildQuickForm($this);
653 if ($this->_cdType
) {
654 return CRM_Custom_Form_CustomData
::buildQuickForm($this);
657 //need to assign custom data type to the template
658 $this->assign('customDataType', 'Participant');
660 $this->applyFilter('__ALL__', 'trim');
662 if ($this->_action
& CRM_Core_Action
::DELETE
) {
663 if ($this->_single
) {
664 $additionalParticipant = count(CRM_Event_BAO_Event
::buildCustomProfile($this->_id
,
670 if ($additionalParticipant) {
671 $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'),
672 2 => ts('Delete only this participant record.'),
674 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
675 $this->setDefaults(array('delete_participant' => 1));
676 $this->assign('additionalParticipant', $additionalParticipant);
679 $this->addButtons(array(
682 'name' => ts('Delete'),
683 'spacing' => ' ',
688 'name' => ts('Cancel'),
696 if ($this->_single
) {
697 $urlPath = 'civicrm/contact/view/participant';
698 $urlParams = "reset=1&cid={$this->_contactId}&context=participant";
699 if ($this->_context
== 'standalone') {
700 $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE), TRUE);
701 $urlParams = 'reset=1&context=standalone';
702 $urlPath = 'civicrm/participant/add';
706 $urlParams .= "&action=update&id={$this->_id}";
709 $urlParams .= "&action=add";
713 $urlParams .= "&mode={$this->_mode}";
716 $url = CRM_Utils_System
::url($urlPath, $urlParams,
721 $currentPath = CRM_Utils_System
::currentPath();
723 $url = CRM_Utils_System
::url($currentPath, '_qf_Participant_display=true',
728 $this->assign('refreshURL', $url);
730 $eventFieldParams = array(
732 'select' => array('minimumInputLength' => 0),
734 'extra' => array('campaign_id', 'default_role_id', 'event_type_id'),
739 // exclude events which are not monetary when credit card registration is used
740 $eventFieldParams['api']['params']['is_monetary'] = 1;
741 $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors
, TRUE);
744 $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE);
746 //frozen the field fix for CRM-4171
747 if ($this->_action
& CRM_Core_Action
::UPDATE
&& $this->_id
) {
748 if (CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
749 $this->_id
, 'contribution_id', 'participant_id'
755 //CRM-7362 --add campaigns.
758 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'campaign_id');
761 $eventId = CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
763 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
766 CRM_Campaign_BAO_Campaign
::addCampaign($this, $campaignId);
768 $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
771 $this->assign('entityID', $this->_id
);
774 $this->addSelect('role_id', array('multiple' => TRUE, 'class' => 'huge'), TRUE);
777 $checkCancelledJs = array('onchange' => "return sendNotification( );");
779 if ($this->_onlinePendingContributionId
) {
780 $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant
::participantStatus());
781 $cancelledContributionStatusId = array_search('Cancelled',
782 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
784 $checkCancelledJs = array(
786 "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});",
789 $participantStatusId = array_search('Pending from pay later',
790 CRM_Event_PseudoConstant
::participantStatus()
792 $contributionStatusId = array_search('Completed',
793 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
795 $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
798 // get the participant status names to build special status array which is used to show notification
799 // checkbox below participant status select
800 $participantStatusName = CRM_Event_PseudoConstant
::participantStatus();
801 $notificationStatuses = array(
803 'Pending from waitlist',
804 'Pending from approval',
808 // get the required status and then implode only ids
809 $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
810 $this->assign('notificationStatusIds', $notificationStatusIds);
812 $this->_participantStatuses
= CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label');
813 $this->addSelect('status_id', $checkCancelledJs +
array('option_url' => 'civicrm/admin/participant_status'), TRUE);
815 $enableCart = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::EVENT_PREFERENCES_NAME
,
818 $pendingInCartStatusId = array_search('Pending in cart', $participantStatusName);
819 $this->assign('pendingInCartStatusId', $pendingInCartStatusId);
820 $this->assign('enableCart', $enableCart);
821 $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
822 $this->assign('pendingRefundStatusId', $pendingRefundStatusId);
824 $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
826 $this->add('text', 'source', ts('Event Source'));
827 $noteAttributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Note');
828 $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
832 'name' => ts('Save'),
837 $path = CRM_Utils_System
::currentPath();
838 $excludeForPaths = array(
839 'civicrm/contact/search',
840 'civicrm/group/search'
842 if (!in_array($path, $excludeForPaths)) {
845 'name' => ts('Save and New'),
853 'name' => ts('Cancel'),
856 $this->addButtons($buttons);
857 if ($this->_action
== CRM_Core_Action
::VIEW
) {
863 * Add local and global form rules
869 function addRules() {
870 $this->addFormRule(array('CRM_Event_Form_Participant', 'formRule'), $this);
874 * global validation rules for the form
876 * @param array $fields posted values of the form
878 * @return array list of errors to be posted back to the form
882 static function formRule($values, $files, $self) {
883 // If $values['_qf_Participant_next'] is Delete or
884 // $values['event_id'] is empty, then return
885 // instead of proceeding further.
887 if ((CRM_Utils_Array
::value('_qf_Participant_next', $values) == 'Delete') ||
888 (!$values['event_id'])
895 if (!empty($values['payment_processor_id'])) {
896 // make sure that credit card number and cvv are valid
897 CRM_Core_Payment_Form
::validateCreditCard($values, $errorMsg);
900 if (!empty($values['record_contribution'])) {
901 if (empty($values['financial_type_id'])) {
902 $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
904 if (empty($values['payment_instrument_id'])) {
905 $errorMsg['payment_instrument_id'] = ts('Paid By is a required field.');
909 // validate contribution status for 'Failed'.
910 if ($self->_onlinePendingContributionId
&& !empty($values['record_contribution']) &&
911 (CRM_Utils_Array
::value('contribution_status_id', $values) ==
912 array_search('Failed', CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name'))
915 $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.');
918 // do the amount validations.
919 //skip for update mode since amount is freeze, CRM-6052
920 if ((!$self->_id
&& empty($values['total_amount']) &&
921 empty($self->_values
['line_items'])
923 ($self->_id
&& !$self->_paymentId
&& isset($self->_values
['line_items']) && is_array($self->_values
['line_items']))
925 if ($priceSetId = CRM_Utils_Array
::value('priceSetId', $values)) {
926 CRM_Price_BAO_PriceField
::priceSetValidation($priceSetId, $values, $errorMsg, TRUE);
929 return CRM_Utils_Array
::crmIsEmptyArray($errorMsg) ?
TRUE : $errorMsg;
933 * Function to process the form
937 public function postProcess() {
938 // get the submitted form values.
939 $params = $this->controller
->exportValues($this->_name
);
941 if ($this->_action
& CRM_Core_Action
::DELETE
) {
942 if (CRM_Utils_Array
::value('delete_participant', $params) == 2) {
943 $additionalId = (CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
));
944 $participantLinks = (CRM_Event_BAO_Participant
::getAdditionalParticipantUrl($additionalId));
946 if (CRM_Utils_Array
::value('delete_participant', $params) == 1) {
947 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
948 foreach ($additionalIds as $value) {
949 CRM_Event_BAO_Participant
::deleteParticipant($value);
952 CRM_Event_BAO_Participant
::deleteParticipant($this->_id
);
953 CRM_Core_Session
::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success');
954 if (!empty($participantLinks)) {
955 $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;
956 CRM_Core_Session
::setStatus($status, ts('Group Payment Deleted'));
961 $participantStatus = CRM_Event_PseudoConstant
::participantStatus();
962 // set the contact, when contact is selected
963 if (!empty($params['contact_id'])) {
964 $this->_contactId
= $params['contact_id'];
966 if ($this->_priceSetId
&& $isQuickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
967 $this->_quickConfig
= $isQuickConfig;
971 $params['id'] = $this->_id
;
974 $config = CRM_Core_Config
::singleton();
975 if ($this->_isPaidEvent
) {
977 $contributionParams = array();
979 $additionalParticipantDetails = array();
980 if (($this->_id
&& $this->_action
& CRM_Core_Action
::UPDATE
) && $this->_paymentId
) {
981 $participantBAO = new CRM_Event_BAO_Participant();
982 $participantBAO->id
= $this->_id
;
983 $participantBAO->find(TRUE);
984 $contributionParams['total_amount'] = $participantBAO->fee_amount
;
986 $params['discount_id'] = NULL;
987 //re-enter the values for UPDATE mode
988 $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level
;
989 $params['fee_amount'] = $participantBAO->fee_amount
;
990 if (isset($params['priceSetId'])) {
991 $lineItem[0] = CRM_Price_BAO_LineItem
::getLineItems($this->_id
);
993 //also add additional participant's fee level/priceset
994 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
995 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
996 $hasLineItems = CRM_Utils_Array
::value('priceSetId', $params, FALSE);
997 $additionalParticipantDetails = CRM_Event_BAO_Participant
::getFeeDetails($additionalIds,
1004 //check if discount is selected
1005 if (!empty($params['discount_id'])) {
1006 $discountId = $params['discount_id'];
1009 $discountId = $params['discount_id'] = 'null';
1012 //lets carry currency, CRM-4453
1013 $params['fee_currency'] = $config->defaultCurrency
;
1014 CRM_Price_BAO_PriceSet
::processAmount($this->_values
['fee'],
1015 $params, $lineItem[0]
1017 //CRM-11529 for quick config backoffice transactions
1018 //when financial_type_id is passed in form, update the
1019 //lineitems with the financial type selected in form
1020 $submittedFinancialType = CRM_Utils_Array
::value('financial_type_id', $params);
1021 $isPaymentRecorded = CRM_Utils_Array
::value('record_contribution', $params);
1022 if ($isPaymentRecorded && $this->_quickConfig
&& $submittedFinancialType) {
1023 foreach ($lineItem[0] as &$values) {
1024 $values['financial_type_id'] = $submittedFinancialType;
1028 $params['fee_level'] = $params['amount_level'];
1029 $contributionParams['total_amount'] = $params['amount'];
1030 if ($this->_quickConfig
&& !empty($params['total_amount']) &&
1031 $params['status_id'] != array_search('Partially paid', $participantStatus)) {
1032 $params['fee_amount'] = $params['total_amount'];
1035 $params['fee_amount'] = $params['amount'];
1039 if (isset($params['priceSetId'])) {
1040 if (!empty($lineItem[0])) {
1041 $this->set('lineItem', $lineItem);
1043 $this->_lineItem
= $lineItem;
1044 $lineItem = array_merge($lineItem, $additionalParticipantDetails);
1046 $participantCount = array();
1047 foreach ($lineItem as $k) {
1048 foreach ($k as $v) {
1049 if (CRM_Utils_Array
::value('participant_count', $v) > 0) {
1050 $participantCount[] = $v['participant_count'];
1055 if (isset($participantCount)) {
1056 $this->assign('pricesetFieldsCount', $participantCount);
1058 $this->assign('lineItem', empty($lineItem[0]) ||
$this->_quickConfig?
FALSE : $lineItem);
1061 $this->assign('amount_level', $params['amount_level']);
1065 $this->_params
= $params;
1067 if (isset($params['amount'])) {
1068 $amountOwed = $params['amount'];
1069 unset($params['amount']);
1071 $params['register_date'] = CRM_Utils_Date
::processDate($params['register_date'], $params['register_date_time']);
1072 $params['receive_date'] = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('receive_date', $params));
1073 $params['contact_id'] = $this->_contactId
;
1075 // overwrite actual payment amount if entered
1076 if (!empty($params['total_amount'])) {
1077 $contributionParams['total_amount'] = CRM_Utils_Array
::value('total_amount', $params);
1081 // Retrieve the name and email of the current user - this will be the FROM for the receipt email
1082 $session = CRM_Core_Session
::singleton();
1083 $userID = $session->get('userID');
1086 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($userID);
1088 if ($this->_contactId
) {
1089 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($this->_contactId
);
1093 if (!$this->_isPaidEvent
) {
1094 CRM_Core_Error
::fatal(ts('Selected Event is not Paid Event '));
1096 //modify params according to parameter used in create
1097 //participant method (addParticipant)
1098 $this->_params
['participant_status_id'] = $params['status_id'];
1099 $this->_params
['participant_role_id'] = explode(',', $params['role_id']);
1100 $this->_params
['participant_register_date'] = $params['register_date'];
1103 CRM_Core_DAO
::getFieldValue(
1104 'CRM_Event_DAO_Event',
1105 $params['event_id'],
1109 // set source if not set
1110 if (empty($params['source'])) {
1111 $this->_params
['participant_source'] = ts('Offline Registration for Event: %2 by: %1', array(1 => $userName, 2 => $eventTitle));
1114 $this->_params
['participant_source'] = $params['source'];
1116 $this->_params
['description'] = $this->_params
['participant_source'];
1118 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($this->_params
['payment_processor_id'],
1121 $now = date('YmdHis');
1124 // set email for primary location.
1125 $fields['email-Primary'] = 1;
1126 $params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail
;
1128 $params['register_date'] = $now;
1130 // now set the values for the billing location.
1131 foreach ($this->_fields
as $name => $dontCare) {
1135 // also add location name to the array
1136 $params["address_name-{$this->_bltID}"] =
1137 CRM_Utils_Array
::value('billing_first_name', $params) . ' ' .
1138 CRM_Utils_Array
::value('billing_middle_name', $params) . ' ' .
1139 CRM_Utils_Array
::value('billing_last_name', $params);
1141 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
1142 $fields["address_name-{$this->_bltID}"] = 1;
1143 $fields["email-{$this->_bltID}"] = 1;
1144 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'contact_type');
1146 $nameFields = array('first_name', 'middle_name', 'last_name');
1148 foreach ($nameFields as $name) {
1150 if (array_key_exists("billing_$name", $params)) {
1151 $params[$name] = $params["billing_{$name}"];
1152 $params['preserveDBName'] = TRUE;
1155 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params, $fields, $this->_contactId
, NULL, NULL, $ctype);
1158 if ($this->_params
['role_id']) {
1159 foreach ($this->_params
['role_id'] as $rkey) {
1160 $customFieldsRole = CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, $rkey, $this->_roleCustomDataTypeID
);
1161 $customFieldsEvent = CRM_Core_BAO_CustomField
::getFields('Participant',
1164 CRM_Utils_Array
::value('event_id', $params),
1165 $this->_eventNameCustomDataTypeID
1167 $customFieldsEventType = CRM_Core_BAO_CustomField
::getFields('Participant',
1170 $this->_eventTypeId
,
1171 $this->_eventTypeCustomDataTypeID
1173 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsRole,
1174 CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE)
1176 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEvent, $customFields);
1177 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEventType, $customFields);
1178 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
1186 //do cleanup line items if participant edit the Event Fee.
1187 if (($this->_lineItem ||
!isset($params['proceSetId'])) && !$this->_paymentId
&& $this->_id
) {
1188 CRM_Price_BAO_LineItem
::deleteLineItems($this->_id
, 'civicrm_participant');
1192 // add all the additional payment params we need
1193 $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}"]);
1194 $this->_params
["country-{$this->_bltID}"] = $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
1196 $this->_params
['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($this->_params
);
1197 $this->_params
['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($this->_params
);
1198 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
1199 $this->_params
['amount'] = $params['fee_amount'];
1200 $this->_params
['amount_level'] = $params['amount_level'];
1201 $this->_params
['currencyID'] = $config->defaultCurrency
;
1202 $this->_params
['payment_action'] = 'Sale';
1203 $this->_params
['invoiceID'] = md5(uniqid(rand(), TRUE));
1205 // at this point we've created a contact and stored its address etc
1206 // all the payment processors expect the name and address to be in the
1207 // so we copy stuff over to first_name etc.
1208 $paymentParams = $this->_params
;
1209 if (!empty($this->_params
['send_receipt'])) {
1210 $paymentParams['email'] = $this->_contributorEmail
;
1212 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $this->_params
, $paymentParams, TRUE);
1214 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
1216 $result = &$payment->doDirectPayment($paymentParams);
1218 if (is_a($result, 'CRM_Core_Error')) {
1219 CRM_Core_Error
::displaySessionError($result);
1220 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/view/participant',
1221 "reset=1&action=add&cid={$this->_contactId}&context=participant&mode={$this->_mode}"
1226 $this->_params
= array_merge($this->_params
, $result);
1229 $this->_params
['receive_date'] = $now;
1231 if (!empty($this->_params
['send_receipt'])) {
1232 $this->_params
['receipt_date'] = $now;
1235 $this->_params
['receipt_date'] = NULL;
1238 $this->set('params', $this->_params
);
1239 $this->assign('trxn_id', $result['trxn_id']);
1240 $this->assign('receive_date',
1241 CRM_Utils_Date
::processDate($this->_params
['receive_date'])
1244 //add contribution record
1245 $this->_params
['financial_type_id'] =
1246 CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
1247 $this->_params
['mode'] = $this->_mode
;
1249 //add contribution reocord
1250 $contributions[] = $contribution = CRM_Event_Form_Registration_Confirm
::processContribution($this, $this->_params
, $result, $contactID, FALSE);
1252 // add participant record
1253 $participants = array();
1254 if (!empty($this->_params
['role_id']) && is_array($this->_params
['role_id'])) {
1255 $this->_params
['role_id'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1256 $this->_params
['role_id']
1259 $participants[] = CRM_Event_Form_Registration
::addParticipant($this->_params
, $contactID);
1261 //add custom data for participant
1262 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
1263 CRM_Core_DAO
::$_nullArray,
1264 'civicrm_participant',
1265 $participants[0]->id
,
1268 //add participant payment
1269 $paymentParticipant = array(
1270 'participant_id' => $participants[0]->id
,
1271 'contribution_id' => $contribution->id
,
1275 CRM_Event_BAO_ParticipantPayment
::create($paymentParticipant, $ids);
1276 $this->_contactIds
[] = $this->_contactId
;
1279 $participants = array();
1280 if ($this->_single
) {
1281 if ($params['role_id']) {
1282 $params['role_id'] = str_replace(',', CRM_Core_DAO
::VALUE_SEPARATOR
, $params['role_id']);
1285 $params['role_id'] = 'NULL';
1287 $participants[] = CRM_Event_BAO_Participant
::create($params);
1290 foreach ($this->_contactIds
as $contactID) {
1291 $commonParams = $params;
1292 $commonParams['contact_id'] = $contactID;
1293 if ($commonParams['role_id']) {
1294 $commonParams['role_id'] = $commonParams['role_id'] = str_replace(',', CRM_Core_DAO
::VALUE_SEPARATOR
, $params['role_id']);
1297 $commonParams['role_id'] = 'NULL';
1299 $participants[] = CRM_Event_BAO_Participant
::create($commonParams);
1303 if (isset($params['event_id'])) {
1304 $eventTitle = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
1305 $params['event_id'],
1310 if ($this->_single
) {
1311 $this->_contactIds
[] = $this->_contactId
;
1314 $contributions = array();
1315 if (!empty($params['record_contribution'])) {
1316 if (!empty($params['id'])) {
1317 if ($this->_onlinePendingContributionId
) {
1318 $ids['contribution'] = $this->_onlinePendingContributionId
;
1321 $ids['contribution'] = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1328 unset($params['note']);
1330 //build contribution params
1331 if (!$this->_onlinePendingContributionId
) {
1332 $contributionParams['source'] = "{$eventTitle}: Offline registration (by {$userName})";
1335 $contributionParams['currency'] = $config->defaultCurrency
;
1336 $contributionParams['non_deductible_amount'] = 'null';
1337 $contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array
::value('receive_date', $params) : 'null';
1339 $recordContribution = array( 'contact_id', 'financial_type_id',
1340 'payment_instrument_id', 'trxn_id',
1341 'contribution_status_id', 'receive_date',
1342 'check_number', 'campaign_id',
1345 foreach ($recordContribution as $f) {
1346 $contributionParams[$f] = CRM_Utils_Array
::value($f, $params);
1347 if ($f == 'trxn_id') {
1348 $this->assign('trxn_id', $contributionParams[$f]);
1352 //insert financial type name in receipt.
1353 $this->assign('contributionTypeName', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id']));
1354 $contributionParams['skipLineItem'] = 1;
1356 $contributionParams['contribution_mode'] = 'participant';
1357 $contributionParams['participant_id'] = $this->_id
;
1359 // Set is_pay_later flag for back-office offline Pending status contributions
1360 if ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup
::getValue('contribution_status', 'Pending', 'name')) {
1361 $contributionParams['is_pay_later'] = 1;
1364 if ($params['status_id'] == array_search('Partially paid', $participantStatus)) {
1365 if (!$amountOwed && $this->_action
& CRM_Core_Action
::UPDATE
) {
1366 $amountOwed = $params['fee_amount'];
1369 // if multiple participants are link, consider contribution total amount as the amount Owed
1370 if ($this->_id
&& CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
1371 $amountOwed = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_Contribution',
1372 $ids['contribution'],
1377 // CRM-13964 partial_payment_total
1378 if ($amountOwed > $params['total_amount']) {
1380 $contributionParams['partial_payment_total'] = $amountOwed;
1381 // the actual amount paid
1382 $contributionParams['partial_amount_pay'] = $params['total_amount'];
1386 if ($this->_single
) {
1390 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1394 foreach ($this->_contactIds
as $contactID) {
1395 $contributionParams['contact_id'] = $contactID;
1396 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1400 //insert payment record for this participation
1401 if (empty($ids['contribution'])) {
1402 foreach ($this->_contactIds
as $num => $contactID) {
1403 $ppDAO = new CRM_Event_DAO_ParticipantPayment();
1404 $ppDAO->participant_id
= $participants[$num]->id
;
1405 $ppDAO->contribution_id
= $contributions[$num]->id
;
1409 // next create the transaction record
1410 $transaction = new CRM_Core_Transaction();
1413 if ($this->_quickConfig
) {
1414 if (!empty($this->_params
['amount_priceset_level_radio'])) {
1415 $feeLevel = $this->_params
['amount_priceset_level_radio'];
1418 $feeLevel[] = $this->_params
['fee_level'] ;
1420 CRM_Event_BAO_Participant
::createDiscountTrxn($this->_eventId
, $contributionParams, $feeLevel);
1422 $transaction->commit();
1426 // also store lineitem stuff here
1427 if ((($this->_lineItem
& $this->_action
& CRM_Core_Action
::ADD
) ||
1428 ($this->_lineItem
&& CRM_Core_Action
::UPDATE
&& !$this->_paymentId
))
1430 foreach ($this->_contactIds
as $num => $contactID) {
1431 foreach ($this->_lineItem
as $key => $value) {
1432 if (is_array($value) && $value != 'skip') {
1433 foreach ($value as $lineKey => $line) {
1434 //10117 update the line items for participants if contribution amount is recorded
1435 if ($this->_quickConfig
&& !empty($params['total_amount']) &&
1436 ($params['status_id'] != array_search('Partially paid', $participantStatus))
1438 $line['unit_price'] = $line['line_total'] = $params['total_amount'];
1440 $lineItem[$this->_priceSetId
][$lineKey] = $line;
1442 CRM_Price_BAO_LineItem
::processPriceSet($participants[$num]->id
, $lineItem, CRM_Utils_Array
::value($num, $contributions, NULL), 'civicrm_participant');
1448 $updateStatusMsg = NULL;
1449 //send mail when participant status changed, CRM-4326
1450 if ($this->_id
&& $this->_statusId
&&
1451 $this->_statusId
!= CRM_Utils_Array
::value('status_id', $params) && !empty($params['is_notify'])) {
1453 $updateStatusMsg = CRM_Event_BAO_Participant
::updateStatusMessage($this->_id
,
1454 $params['status_id'],
1461 if (!empty($params['send_receipt'])) {
1462 if (array_key_exists($params['from_email_address'], $this->_fromEmails
['from_email_id'])) {
1463 $receiptFrom = $params['from_email_address'];
1466 $this->assign('module', 'Event Registration');
1467 //use of the message template below requires variables in different format
1468 $event = $events = array();
1469 $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
1471 //get all event details.
1472 CRM_Core_DAO
::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
1473 $event = $events[$params['event_id']];
1474 unset($event['start_date']);
1475 unset($event['end_date']);
1477 $role = CRM_Event_PseudoConstant
::participantRole();
1478 $participantRoles = CRM_Utils_Array
::value('role_id', $params);
1479 if (is_array($participantRoles)) {
1480 $selectedRoles = array();
1481 foreach (array_keys($participantRoles) as $roleId) {
1482 $selectedRoles[] = $role[$roleId];
1484 $event['participant_role'] = implode(', ', $selectedRoles);
1487 $event['participant_role'] = CRM_Utils_Array
::value($participantRoles, $role);
1489 $event['is_monetary'] = $this->_isPaidEvent
;
1491 if ($params['receipt_text']) {
1492 $event['confirm_email_text'] = $params['receipt_text'];
1495 $this->assign('isAmountzero', 1);
1496 $this->assign('event', $event);
1498 $this->assign('isShowLocation', $event['is_show_location']);
1499 if (CRM_Utils_Array
::value('is_show_location', $event) == 1) {
1500 $locationParams = array(
1501 'entity_id' => $params['event_id'],
1502 'entity_table' => 'civicrm_event',
1504 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
1505 $this->assign('location', $location);
1508 $status = CRM_Event_PseudoConstant
::participantStatus();
1509 if ($this->_isPaidEvent
) {
1510 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
1511 if (!$this->_mode
) {
1512 if (isset($params['payment_instrument_id'])) {
1513 $this->assign('paidBy',
1514 CRM_Utils_Array
::value($params['payment_instrument_id'],
1521 $this->assign('totalAmount', $contributionParams['total_amount']);
1522 if (isset($contributionParams['partial_payment_total'])) {
1524 $balanceAmount = $contributionParams['partial_payment_total'] - $contributionParams['partial_amount_pay'];
1525 $this->assign('balanceAmount', $balanceAmount );
1527 $this->assign('isPrimary', 1);
1528 $this->assign('checkNumber', CRM_Utils_Array
::value('check_number', $params));
1531 if (!empty($params['billing_first_name'])) {
1532 $name = $params['billing_first_name'];
1535 if (!empty($params['billing_middle_name'])) {
1536 $name .= " {$params['billing_middle_name']}";
1539 if (!empty($params['billing_last_name'])) {
1540 $name .= " {$params['billing_last_name']}";
1542 $this->assign('billingName', $name);
1544 // assign the address formatted up for display
1545 $addressParts = array(
1546 "street_address-{$this->_bltID}",
1547 "city-{$this->_bltID}",
1548 "postal_code-{$this->_bltID}",
1549 "state_province-{$this->_bltID}",
1550 "country-{$this->_bltID}",
1552 $addressFields = array();
1553 foreach ($addressParts as $part) {
1554 list($n, $id) = explode('-', $part);
1555 if (isset($this->_params
['billing_' . $part])) {
1556 $addressFields[$n] = $this->_params
['billing_' . $part];
1559 $this->assign('address', CRM_Utils_Address
::format($addressFields));
1561 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
1562 $date = CRM_Utils_Date
::mysqlToIso($date);
1563 $this->assign('credit_card_exp_date', $date);
1564 $this->assign('credit_card_number',
1565 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
1567 $this->assign('credit_card_type', $params['credit_card_type']);
1568 $this->assign('contributeMode', 'direct');
1569 $this->assign('isAmountzero', 0);
1570 $this->assign('is_pay_later', 0);
1571 $this->assign('isPrimary', 1);
1574 $this->assign('register_date', $params['register_date']);
1575 if ($params['receive_date']) {
1576 $this->assign('receive_date', $params['receive_date']);
1579 $participant = array(array('participant_id', '=', $participants[0]->id
, 0, 0));
1580 // check whether its a test drive ref CRM-3075
1581 if (!empty($this->_defaultValues
['is_test'])) {
1582 $participant[] = array('participant_test', '=', 1, 0, 0);
1585 $template = CRM_Core_Smarty
::singleton();
1586 $customGroup = array();
1587 //format submitted data
1588 foreach ($params['custom'] as $fieldID => $values) {
1589 foreach ($values as $fieldValue) {
1590 $customValue = array('data' => $fieldValue['value']);
1591 $customFields[$fieldID]['id'] = $fieldID;
1592 $formattedValue = CRM_Core_BAO_CustomGroup
::formatCustomValues($customValue, $customFields[$fieldID], TRUE);
1593 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace(' ', '', $formattedValue);
1597 foreach ($this->_contactIds
as $num => $contactID) {
1598 // Retrieve the name and email of the contact - this will be the TO for receipt email
1599 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($contactID);
1601 $this->_contributorDisplayName
= ($this->_contributorDisplayName
== ' ') ?
$this->_contributorEmail
: $this->_contributorDisplayName
;
1603 $waitStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
1604 if ($waitingStatus = CRM_Utils_Array
::value($params['status_id'], $waitStatus)) {
1605 $this->assign('isOnWaitlist', TRUE);
1608 $this->assign('customGroup', $customGroup);
1609 $this->assign('contactID', $contactID);
1610 $this->assign('participantID', $participants[$num]->id
);
1612 $this->_id
= $participants[$num]->id
;
1614 if ($this->_isPaidEvent
) {
1615 // fix amount for each of participants ( for bulk mode )
1616 $eventAmount = array();
1617 if (!empty($additionalParticipantDetails)) {
1618 $params['amount_level'] = preg_replace('/\ 1/', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName
;
1621 $eventAmount[$num] = array(
1622 'label' => preg_replace('/\ 1/', '', $params['amount_level']),
1623 'amount' => $params['fee_amount'],
1625 //as we are using same template for online & offline registration.
1626 //So we have to build amount as array.
1627 $eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
1628 $this->assign('amount', $eventAmount);
1631 $sendTemplateParams = array(
1632 'groupName' => 'msg_tpl_workflow_event',
1633 'valueName' => 'event_offline_receipt',
1634 'contactId' => $contactID,
1635 'isTest' => (bool) CRM_Utils_Array
::value('is_test', $this->_defaultValues
),
1636 'PDFFilename' => ts('confirmation').'.pdf',
1639 // try to send emails only if email id is present
1640 // and the do-not-email option is not checked for that contact
1641 if ($this->_contributorEmail
and !$this->_toDoNotEmail
) {
1642 $sendTemplateParams['from'] = $receiptFrom;
1643 $sendTemplateParams['toName'] = $this->_contributorDisplayName
;
1644 $sendTemplateParams['toEmail'] = $this->_contributorEmail
;
1645 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc', $this->_fromEmails
);
1646 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc', $this->_fromEmails
);
1649 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1651 $sent[] = $contactID;
1652 foreach ($participants as $ids => $values) {
1653 if ($values->contact_id
== $contactID) {
1654 CRM_Activity_BAO_Activity
::addActivity($values, 'Email');
1660 $notSent[] = $contactID;
1665 // set the participant id if it is not set
1667 $this->_id
= $participants[0]->id
;
1670 if (($this->_action
& CRM_Core_Action
::UPDATE
)) {
1671 $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contributorDisplayName
));
1672 if (!empty($params['send_receipt']) && count($sent)) {
1673 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', array(1 => $this->_contributorEmail
));
1676 if ($updateStatusMsg) {
1677 $statusMsg = "{$statusMsg} {$updateStatusMsg}";
1680 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
1681 if ($this->_single
) {
1682 $statusMsg = ts('Event registration for %1 has been added.', array(1 => $this->_contributorDisplayName
));
1683 if (!empty($params['send_receipt']) && count($sent)) {
1684 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $this->_contributorEmail
));
1688 $statusMsg = ts('Total Participant(s) added to event: %1.', array(1 => count($this->_contactIds
)));
1689 if (count($notSent) > 0) {
1690 $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)));
1692 elseif (isset($params['send_receipt'])) {
1693 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');
1697 CRM_Core_Session
::setStatus($statusMsg, ts('Saved'), 'success');
1699 $buttonName = $this->controller
->getButtonName();
1700 if ($this->_context
== 'standalone') {
1701 if ($buttonName == $this->getButtonName('upload', 'new')) {
1702 $urlParams = 'reset=1&action=add&context=standalone';
1704 $urlParams .= '&mode=' . $this->_mode
;
1707 $urlParams .= '&eid=' . $this->_eID
;
1709 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/participant/add', $urlParams));
1712 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
1713 "reset=1&cid={$this->_contactId}&selectedChild=participant"
1717 elseif ($buttonName == $this->getButtonName('upload', 'new')) {
1718 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view/participant',
1719 "reset=1&action=add&context={$this->_context}&cid={$this->_contactId}"