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 * Function to set variables up before form is built
201 public function preProcess() {
202 $this->_showFeeBlock
= CRM_Utils_Array
::value('eventId', $_GET);
203 $this->assign('showFeeBlock', FALSE);
204 $this->assign('feeBlockPaid', FALSE);
206 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
207 $this->_mode
= CRM_Utils_Request
::retrieve('mode', 'String', $this);
208 $this->_eID
= CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
209 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this);
210 $this->assign('context', $this->_context
);
212 if ($this->_contactId
) {
213 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
214 $this->assign('displayName', $displayName);
215 // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
216 CRM_Utils_System
::setTitle(ts('Event Registration for') . ' ' . $displayName);
219 // check the current path, if search based, then dont get participantID
221 $path = CRM_Utils_System
::currentPath();
223 strpos($path, 'civicrm/contact/search') === 0 ||
224 strpos($path, 'civicrm/group/search') === 0
229 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
233 $this->assign('participantId', $this->_id
);
235 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
236 $this->_id
, 'id', 'participant_id'
239 $this->assign('hasPayment', $this->_paymentId
);
241 // CRM-12615 - Get payment information from the primary registration
242 if ((!$this->_paymentId
) && ($this->_action
== CRM_Core_Action
::UPDATE
)) {
243 $registered_by_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
244 $this->_id
, 'registered_by_id', 'id'
246 if ($registered_by_id) {
247 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
248 $registered_by_id, 'id', 'participant_id'
250 $this->assign('registeredByParticipantId', $registered_by_id);
255 // get the option value for custom data type
256 $this->_roleCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantRole', 'name');
257 $this->_eventNameCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantEventName', 'name');
258 $this->_eventTypeCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantEventType', 'name');
259 $this->assign('roleCustomDataTypeID', $this->_roleCustomDataTypeID
);
260 $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID
);
261 $this->assign('eventTypeCustomDataTypeID', $this->_eventTypeCustomDataTypeID
);
264 $this->assign('participantMode', $this->_mode
);
266 $this->_paymentProcessor
= array('billing_mode' => 1);
268 $validProcessors = array();
269 $processors = CRM_Core_PseudoConstant
::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )");
271 foreach ($processors as $ppID => $label) {
272 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getPayment($ppID, $this->_mode
);
273 if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) {
276 elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode
== 'live') {
280 $paymentObject = CRM_Core_Payment
::singleton($this->_mode
, $paymentProcessor, $this);
281 $error = $paymentObject->checkConfig();
283 $validProcessors[$ppID] = $label;
285 $paymentObject = NULL;
288 if (empty($validProcessors)) {
289 CRM_Core_Error
::fatal(ts('Could not find valid payment processor for this page'));
292 $this->_processors
= $validProcessors;
294 // also check for billing information
295 // get the billing location type
296 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
297 // CRM-8108 remove ts around Billing location type
298 //$this->_bltID = array_search( ts('Billing'), $locationTypes );
299 $this->_bltID
= array_search('Billing', $locationTypes);
300 if (!$this->_bltID
) {
301 CRM_Core_Error
::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
303 $this->set('bltID', $this->_bltID
);
304 $this->assign('bltID', $this->_bltID
);
306 $this->_fields
= array();
308 CRM_Core_Payment_Form
::setCreditCardFields($this);
310 // this required to show billing block
311 $this->assign_by_ref('paymentProcessor', $paymentProcessor);
312 $this->assign('hidePayPalExpress', TRUE);
315 if ($this->_showFeeBlock
) {
316 $this->assign('showFeeBlock', TRUE);
317 $isMonetary = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_showFeeBlock
, 'is_monetary');
319 $this->assign('feeBlockPaid', TRUE);
321 return CRM_Event_Form_EventFees
::preProcess($this);
324 //custom data related code
325 $this->_cdType
= CRM_Utils_Array
::value('type', $_GET);
326 $this->assign('cdType', FALSE);
327 if ($this->_cdType
) {
328 $this->assign('cdType', TRUE);
329 return CRM_Custom_Form_CustomData
::preProcess($this, NULL, NULL, NULL, NULL, NULL, TRUE);
332 //check the mode when this form is called either single or as
334 if ($this->_id ||
$this->_contactId ||
$this->_context
== 'standalone') {
335 $this->_single
= TRUE;
336 $this->assign('urlPath', 'civicrm/contact/view/participant');
337 if (!$this->_id
&& !$this->_contactId
) {
338 $breadCrumbs = array(array('title' => ts('CiviEvent Dashboard'),
339 'url' => CRM_Utils_System
::url('civicrm/event', 'reset=1'),
342 CRM_Utils_System
::appendBreadCrumb($breadCrumbs);
346 //set the appropriate action
347 $context = $this->get('context');
348 $urlString = 'civicrm/contact/search';
349 $this->_action
= CRM_Core_Action
::BASIC
;
352 $urlString = 'civicrm/contact/search/advanced';
353 $this->_action
= CRM_Core_Action
::ADVANCED
;
357 $urlString = 'civicrm/contact/search/builder';
358 $this->_action
= CRM_Core_Action
::PROFILE
;
362 $urlString = 'civicrm/contact/search/basic';
363 $this->_action
= CRM_Core_Action
::BASIC
;
367 $urlString = 'civicrm/contact/search/custom';
368 $this->_action
= CRM_Core_Action
::COPY
;
371 parent
::preProcess();
373 $this->_single
= FALSE;
374 $this->_contactId
= NULL;
376 //set ajax path, this used for custom data building
377 $this->assign('urlPath', $urlString);
378 $this->assign('urlPathVar', "_qf_Participant_display=true&qfKey={$this->controller->_key}");
381 $this->assign('single', $this->_single
);
384 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
386 $this->assign('action', $this->_action
);
388 // check for edit permission
389 if (!CRM_Core_Permission
::checkActionPermission('CiviEvent', $this->_action
)) {
390 CRM_Core_Error
::fatal(ts('You do not have permission to access this page'));
393 if ($this->_action
& CRM_Core_Action
::DELETE
) {
394 // check delete permission for contribution
395 if ($this->_id
&& $this->_paymentId
&& !CRM_Core_Permission
::checkActionPermission('CiviContribute', $this->_action
)) {
396 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."));
402 // assign participant id to the template
403 $this->assign('participantId', $this->_id
);
404 $this->_roleId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'role_id');
407 // when fee amount is included in form
408 if (!empty($_POST['hidden_feeblock']) ||
!empty($_POST['send_receipt'])) {
409 CRM_Event_Form_EventFees
::preProcess($this);
410 CRM_Event_Form_EventFees
::buildQuickForm($this);
411 CRM_Event_Form_EventFees
::setDefaultValues($this);
414 // when custom data is included in this page
415 if (!empty($_POST['hidden_custom'])) {
416 //custom data of type participant role
417 if (!empty($_POST['role_id'])) {
418 foreach ($_POST['role_id'] as $k => $val) {
420 CRM_Custom_Form_CustomData
::preProcess($this, $this->_roleCustomDataTypeID
, $k, 1, 'Participant', $this->_id
);
421 CRM_Custom_Form_CustomData
::buildQuickForm($this);
422 CRM_Custom_Form_CustomData
::setDefaultValues($this);
426 //custom data of type participant event
427 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventNameCustomDataTypeID
, $_POST['event_id'], 1, 'Participant', $this->_id
);
428 CRM_Custom_Form_CustomData
::buildQuickForm($this);
429 CRM_Custom_Form_CustomData
::setDefaultValues($this);
431 // custom data of type participant event type
433 if ($eventId = CRM_Utils_Array
::value('event_id', $_POST)) {
434 $eventTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'event_type_id', 'id');
436 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventTypeCustomDataTypeID
, $eventTypeId,
437 1, 'Participant', $this->_id
439 CRM_Custom_Form_CustomData
::buildQuickForm($this);
440 CRM_Custom_Form_CustomData
::setDefaultValues($this);
442 //custom data of type participant, ( we 'null' to reset subType and subName)
443 CRM_Custom_Form_CustomData
::preProcess($this, 'null', 'null', 1, 'Participant', $this->_id
);
444 CRM_Custom_Form_CustomData
::buildQuickForm($this);
445 CRM_Custom_Form_CustomData
::setDefaultValues($this);
448 // CRM-4395, get the online pending contribution id.
449 $this->_onlinePendingContributionId
= NULL;
450 if (!$this->_mode
&& $this->_id
&& ($this->_action
& CRM_Core_Action
::UPDATE
)) {
451 $this->_onlinePendingContributionId
= CRM_Contribute_BAO_Contribution
::checkOnlinePendingContribution($this->_id
,
455 $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId
);
459 * This function sets the default values for the form in edit/view mode
460 * the default values are retrieved from the database
466 public function setDefaultValues() {
467 if ($this->_showFeeBlock
) {
468 return CRM_Event_Form_EventFees
::setDefaultValues($this);
471 if ($this->_cdType
) {
472 return CRM_Custom_Form_CustomData
::setDefaultValues($this);
477 if ($this->_action
& CRM_Core_Action
::DELETE
) {
483 $params = array('id' => $this->_id
);
485 CRM_Event_BAO_Participant
::getValues($params, $defaults, $ids);
486 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
487 if ($defaults[$this->_id
]['role_id']) {
488 $roleIDs = explode($sep, $defaults[$this->_id
]['role_id']);
490 $this->_contactId
= $defaults[$this->_id
]['contact_id'];
491 $this->_statusId
= $defaults[$this->_id
]['participant_status_id'];
493 //set defaults for note
494 $noteDetails = CRM_Core_BAO_Note
::getNote($this->_id
, 'civicrm_participant');
495 $defaults[$this->_id
]['note'] = array_pop($noteDetails);
497 // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859)
498 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
499 $this->assign('additionalParticipants', CRM_Event_BAO_Participant
::getAdditionalParticipants($this->_id
));
502 // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
503 if (!empty($defaults[$this->_id
]['participant_registered_by_id'])) {
504 $registered_by_contact_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
505 $defaults[$this->_id
]['participant_registered_by_id'],
508 $this->assign('participant_registered_by_id', $defaults[$this->_id
]['participant_registered_by_id']);
509 $this->assign('registered_by_contact_id', $registered_by_contact_id);
510 $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact
::displayName($registered_by_contact_id));
514 if ($this->_action
& (CRM_Core_Action
::VIEW | CRM_Core_Action
::BROWSE
)) {
515 $inactiveNeeded = TRUE;
520 $inactiveNeeded = FALSE;
523 //setting default register date
524 if ($this->_action
== CRM_Core_Action
::ADD
) {
525 $statuses = array_flip($this->_participantStatuses
);
526 $defaults[$this->_id
]['status_id'] = CRM_Utils_Array
::value(ts('Registered'), $statuses);
527 if (!empty($defaults[$this->_id
]['event_id'])) {
528 $contributionTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
529 $defaults[$this->_id
]['event_id'],
532 if ($contributionTypeId) {
533 $defaults[$this->_id
]['financial_type_id'] = $contributionTypeId;
538 $fields["email-{$this->_bltID}"] = 1;
539 $fields['email-Primary'] = 1;
541 if ($this->_contactId
) {
542 CRM_Core_BAO_UFGroup
::setProfileDefaults($this->_contactId
, $fields, $defaults);
545 if (empty($defaults["email-{$this->_bltID}"]) &&
546 !empty($defaults['email-Primary'])
548 $defaults[$this->_id
]["email-{$this->_bltID}"] = $defaults['email-Primary'];
552 $submittedRole = $this->getElementValue('role_id');
553 if (!empty($submittedRole[0])) {
554 $roleID = $submittedRole[0];
556 $submittedEvent = $this->getElementValue('event_id');
557 if ($submittedEvent[0]) {
558 $eventID = $submittedEvent[0];
562 $defaults[$this->_id
]['record_contribution'] = 0;
564 if ($defaults[$this->_id
]['participant_is_pay_later']) {
565 $this->assign('participant_is_pay_later', TRUE);
568 $this->assign('participant_status_id', $defaults[$this->_id
]['participant_status_id']);
569 $eventID = $defaults[$this->_id
]['event_id'];
571 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
573 $this->_discountId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'discount_id');
574 if ($this->_discountId
) {
575 $this->set('discountId', $this->_discountId
);
579 list($defaults[$this->_id
]['register_date'],
580 $defaults[$this->_id
]['register_date_time']
581 ) = CRM_Utils_Date
::setDateDefaults(
582 CRM_Utils_Array
::value('register_date', $defaults[$this->_id
]), 'activityDateTime'
585 //assign event and role id, this is needed for Custom data building
586 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
587 if (!empty($defaults[$this->_id
]['participant_role_id'])) {
588 $roleIDs = explode($sep, $defaults[$this->_id
]['participant_role_id']);
590 if (isset($_POST['event_id'])) {
591 $eventID = $_POST['event_id'];
595 $eventID = $this->_eID
;
596 //@todo - rationalise the $this->_eID with $POST['event_id'], $this->_eid is set when eid=x is in the url
597 $roleID = CRM_Core_DAO
::getFieldValue(
598 'CRM_Event_DAO_Event',
602 if(empty($roleIDs)) {
603 $roleIDs = (array) $defaults[$this->_id
]['participant_role_id'] = $roleID;
605 $defaults[$this->_id
]['event_id'] = $eventID;
607 if (!empty($eventID)) {
608 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
610 //these should take precedence so we state them last
611 $urlRoleIDS = CRM_Utils_Request
::retrieve('roles', 'String');
613 $roleIDs = explode(',', $urlRoleIDS);
615 if (isset($roleIDs)) {
616 $defaults[$this->_id
]['role_id'] = implode(',', $roleIDs);
619 if (isset($eventID)) {
620 $this->assign('eventID', $eventID);
621 $this->set('eventId', $eventID);
624 if (isset($this->_eventTypeId
)) {
625 $this->assign('eventTypeID', $this->_eventTypeId
);
628 $this->assign('event_is_test', CRM_Utils_Array
::value('event_is_test', $defaults[$this->_id
]));
629 return $defaults[$this->_id
];
633 * Function to build the form
638 public function buildQuickForm() {
639 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
640 $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses);
641 $this->assign('partiallyPaidStatusId', $partiallyPaidStatusId);
643 if ($this->_showFeeBlock
) {
644 return CRM_Event_Form_EventFees
::buildQuickForm($this);
647 if ($this->_cdType
) {
648 return CRM_Custom_Form_CustomData
::buildQuickForm($this);
651 //need to assign custom data type to the template
652 $this->assign('customDataType', 'Participant');
654 $this->applyFilter('__ALL__', 'trim');
656 if ($this->_action
& CRM_Core_Action
::DELETE
) {
657 if ($this->_single
) {
658 $additionalParticipant = count(CRM_Event_BAO_Event
::buildCustomProfile($this->_id
,
664 if ($additionalParticipant) {
665 $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'),
666 2 => ts('Delete only this participant record.'),
668 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
669 $this->setDefaults(array('delete_participant' => 1));
670 $this->assign('additionalParticipant', $additionalParticipant);
673 $this->addButtons(array(
676 'name' => ts('Delete'),
677 'spacing' => ' ',
682 'name' => ts('Cancel'),
690 if ($this->_single
) {
691 $urlPath = 'civicrm/contact/view/participant';
692 $urlParams = "reset=1&cid={$this->_contactId}&context=participant";
693 if ($this->_context
== 'standalone') {
694 $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE), TRUE);
695 $urlParams = 'reset=1&context=standalone';
696 $urlPath = 'civicrm/participant/add';
700 $urlParams .= "&action=update&id={$this->_id}";
703 $urlParams .= "&action=add";
707 $urlParams .= "&mode={$this->_mode}";
710 $url = CRM_Utils_System
::url($urlPath, $urlParams,
715 $currentPath = CRM_Utils_System
::currentPath();
717 $url = CRM_Utils_System
::url($currentPath, '_qf_Participant_display=true',
722 $this->assign('refreshURL', $url);
724 $eventFieldParams = array(
726 'select' => array('minimumInputLength' => 0),
728 'extra' => array('campaign_id', 'default_role_id', 'event_type_id'),
733 // exclude events which are not monetary when credit card registration is used
734 $eventFieldParams['api']['params']['is_monetary'] = 1;
735 $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors
, TRUE);
738 $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE);
740 //frozen the field fix for CRM-4171
741 if ($this->_action
& CRM_Core_Action
::UPDATE
&& $this->_id
) {
742 if (CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
743 $this->_id
, 'contribution_id', 'participant_id'
749 //CRM-7362 --add campaigns.
752 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'campaign_id');
755 $eventId = CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
757 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
760 CRM_Campaign_BAO_Campaign
::addCampaign($this, $campaignId);
762 $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
765 $this->assign('entityID', $this->_id
);
768 $this->addSelect('role_id', array('multiple' => TRUE, 'class' => 'huge'), TRUE);
771 $checkCancelledJs = array('onchange' => "return sendNotification( );");
773 if ($this->_onlinePendingContributionId
) {
774 $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant
::participantStatus());
775 $cancelledContributionStatusId = array_search('Cancelled',
776 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
778 $checkCancelledJs = array(
780 "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});",
783 $participantStatusId = array_search('Pending from pay later',
784 CRM_Event_PseudoConstant
::participantStatus()
786 $contributionStatusId = array_search('Completed',
787 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
789 $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
792 // get the participant status names to build special status array which is used to show notification
793 // checkbox below participant status select
794 $participantStatusName = CRM_Event_PseudoConstant
::participantStatus();
795 $notificationStatuses = array(
797 'Pending from waitlist',
798 'Pending from approval',
802 // get the required status and then implode only ids
803 $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
804 $this->assign('notificationStatusIds', $notificationStatusIds);
806 $this->_participantStatuses
= CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label');
807 $this->addSelect('status_id', $checkCancelledJs +
array('option_url' => 'civicrm/admin/participant_status'), TRUE);
809 $enableCart = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::EVENT_PREFERENCES_NAME
,
812 $pendingInCartStatusId = array_search('Pending in cart', $participantStatusName);
813 $this->assign('pendingInCartStatusId', $pendingInCartStatusId);
814 $this->assign('enableCart', $enableCart);
815 $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
816 $this->assign('pendingRefundStatusId', $pendingRefundStatusId);
818 $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
820 $this->add('text', 'source', ts('Event Source'));
821 $noteAttributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Note');
822 $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
826 'name' => ts('Save'),
831 $path = CRM_Utils_System
::currentPath();
832 $excludeForPaths = array(
833 'civicrm/contact/search',
834 'civicrm/group/search'
836 if (!in_array($path, $excludeForPaths)) {
839 'name' => ts('Save and New'),
847 'name' => ts('Cancel'),
850 $this->addButtons($buttons);
851 if ($this->_action
== CRM_Core_Action
::VIEW
) {
857 * Add local and global form rules
863 function addRules() {
864 $this->addFormRule(array('CRM_Event_Form_Participant', 'formRule'), $this);
868 * global validation rules for the form
870 * @param array $fields posted values of the form
872 * @return array list of errors to be posted back to the form
876 static function formRule($values, $files, $self) {
877 // If $values['_qf_Participant_next'] is Delete or
878 // $values['event_id'] is empty, then return
879 // instead of proceeding further.
881 if ((CRM_Utils_Array
::value('_qf_Participant_next', $values) == 'Delete') ||
882 (!$values['event_id'])
889 if (!empty($values['payment_processor_id'])) {
890 // make sure that credit card number and cvv are valid
891 CRM_Core_Payment_Form
::validateCreditCard($values, $errorMsg);
894 if (!empty($values['record_contribution'])) {
895 if (empty($values['financial_type_id'])) {
896 $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
898 if (empty($values['payment_instrument_id'])) {
899 $errorMsg['payment_instrument_id'] = ts('Paid By is a required field.');
903 // validate contribution status for 'Failed'.
904 if ($self->_onlinePendingContributionId
&& !empty($values['record_contribution']) &&
905 (CRM_Utils_Array
::value('contribution_status_id', $values) ==
906 array_search('Failed', CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name'))
909 $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.');
912 // do the amount validations.
913 //skip for update mode since amount is freeze, CRM-6052
914 if ((!$self->_id
&& empty($values['total_amount']) &&
915 empty($self->_values
['line_items'])
917 ($self->_id
&& !$self->_paymentId
&& isset($self->_values
['line_items']) && is_array($self->_values
['line_items']))
919 if ($priceSetId = CRM_Utils_Array
::value('priceSetId', $values)) {
920 CRM_Price_BAO_PriceField
::priceSetValidation($priceSetId, $values, $errorMsg, TRUE);
923 return CRM_Utils_Array
::crmIsEmptyArray($errorMsg) ?
TRUE : $errorMsg;
927 * Function to process the form
931 public function postProcess() {
932 // get the submitted form values.
933 $params = $this->controller
->exportValues($this->_name
);
935 if ($this->_action
& CRM_Core_Action
::DELETE
) {
936 if (CRM_Utils_Array
::value('delete_participant', $params) == 2) {
937 $additionalId = (CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
));
938 $participantLinks = (CRM_Event_BAO_Participant
::getAdditionalParticipantUrl($additionalId));
940 if (CRM_Utils_Array
::value('delete_participant', $params) == 1) {
941 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
942 foreach ($additionalIds as $value) {
943 CRM_Event_BAO_Participant
::deleteParticipant($value);
946 CRM_Event_BAO_Participant
::deleteParticipant($this->_id
);
947 CRM_Core_Session
::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success');
948 if (!empty($participantLinks)) {
949 $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;
950 CRM_Core_Session
::setStatus($status, ts('Group Payment Deleted'));
955 $participantStatus = CRM_Event_PseudoConstant
::participantStatus();
956 // set the contact, when contact is selected
957 if (!empty($params['contact_id'])) {
958 $this->_contactId
= $params['contact_id'];
960 if ($this->_priceSetId
&& $isQuickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
961 $this->_quickConfig
= $isQuickConfig;
965 $params['id'] = $this->_id
;
968 $config = CRM_Core_Config
::singleton();
969 if ($this->_isPaidEvent
) {
971 $contributionParams = array();
973 $additionalParticipantDetails = array();
974 if (($this->_id
&& $this->_action
& CRM_Core_Action
::UPDATE
) && $this->_paymentId
) {
975 $participantBAO = new CRM_Event_BAO_Participant();
976 $participantBAO->id
= $this->_id
;
977 $participantBAO->find(TRUE);
978 $contributionParams['total_amount'] = $participantBAO->fee_amount
;
980 $params['discount_id'] = NULL;
981 //re-enter the values for UPDATE mode
982 $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level
;
983 $params['fee_amount'] = $participantBAO->fee_amount
;
984 if (isset($params['priceSetId'])) {
985 $lineItem[0] = CRM_Price_BAO_LineItem
::getLineItems($this->_id
);
987 //also add additional participant's fee level/priceset
988 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
989 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
990 $hasLineItems = CRM_Utils_Array
::value('priceSetId', $params, FALSE);
991 $additionalParticipantDetails = CRM_Event_BAO_Participant
::getFeeDetails($additionalIds,
998 //check if discount is selected
999 if (!empty($params['discount_id'])) {
1000 $discountId = $params['discount_id'];
1003 $discountId = $params['discount_id'] = 'null';
1006 //lets carry currency, CRM-4453
1007 $params['fee_currency'] = $config->defaultCurrency
;
1008 CRM_Price_BAO_PriceSet
::processAmount($this->_values
['fee'],
1009 $params, $lineItem[0]
1011 //CRM-11529 for quick config backoffice transactions
1012 //when financial_type_id is passed in form, update the
1013 //lineitems with the financial type selected in form
1014 $submittedFinancialType = CRM_Utils_Array
::value('financial_type_id', $params);
1015 $isPaymentRecorded = CRM_Utils_Array
::value('record_contribution', $params);
1016 if ($isPaymentRecorded && $this->_quickConfig
&& $submittedFinancialType) {
1017 foreach ($lineItem[0] as &$values) {
1018 $values['financial_type_id'] = $submittedFinancialType;
1022 $params['fee_level'] = $params['amount_level'];
1023 $contributionParams['total_amount'] = $params['amount'];
1024 if ($this->_quickConfig
&& !empty($params['total_amount']) &&
1025 $params['status_id'] != array_search('Partially paid', $participantStatus)) {
1026 $params['fee_amount'] = $params['total_amount'];
1029 $params['fee_amount'] = $params['amount'];
1033 if (isset($params['priceSetId'])) {
1034 if (!empty($lineItem[0])) {
1035 $this->set('lineItem', $lineItem);
1037 $this->_lineItem
= $lineItem;
1038 $lineItem = array_merge($lineItem, $additionalParticipantDetails);
1040 $participantCount = array();
1041 foreach ($lineItem as $k) {
1042 foreach ($k as $v) {
1043 if (CRM_Utils_Array
::value('participant_count', $v) > 0) {
1044 $participantCount[] = $v['participant_count'];
1049 if (isset($participantCount)) {
1050 $this->assign('pricesetFieldsCount', $participantCount);
1052 $this->assign('lineItem', empty($lineItem[0]) ||
$this->_quickConfig?
FALSE : $lineItem);
1055 $this->assign('amount_level', $params['amount_level']);
1059 $this->_params
= $params;
1061 if (isset($params['amount'])) {
1062 $amountOwed = $params['amount'];
1063 unset($params['amount']);
1065 $params['register_date'] = CRM_Utils_Date
::processDate($params['register_date'], $params['register_date_time']);
1066 $params['receive_date'] = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('receive_date', $params));
1067 $params['contact_id'] = $this->_contactId
;
1069 // overwrite actual payment amount if entered
1070 if (!empty($params['total_amount'])) {
1071 $contributionParams['total_amount'] = CRM_Utils_Array
::value('total_amount', $params);
1075 // Retrieve the name and email of the current user - this will be the FROM for the receipt email
1076 $session = CRM_Core_Session
::singleton();
1077 $userID = $session->get('userID');
1080 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($userID);
1082 if ($this->_contactId
) {
1083 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($this->_contactId
);
1087 if (!$this->_isPaidEvent
) {
1088 CRM_Core_Error
::fatal(ts('Selected Event is not Paid Event '));
1090 //modify params according to parameter used in create
1091 //participant method (addParticipant)
1092 $this->_params
['participant_status_id'] = $params['status_id'];
1093 $this->_params
['participant_role_id'] = explode(',', $params['role_id']);
1094 $this->_params
['participant_register_date'] = $params['register_date'];
1097 CRM_Core_DAO
::getFieldValue(
1098 'CRM_Event_DAO_Event',
1099 $params['event_id'],
1103 // set source if not set
1104 if (empty($params['source'])) {
1105 $this->_params
['participant_source'] = ts('Offline Registration for Event: %2 by: %1', array(1 => $userName, 2 => $eventTitle));
1108 $this->_params
['participant_source'] = $params['source'];
1110 $this->_params
['description'] = $this->_params
['participant_source'];
1112 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($this->_params
['payment_processor_id'],
1115 $now = date('YmdHis');
1118 // set email for primary location.
1119 $fields['email-Primary'] = 1;
1120 $params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail
;
1122 $params['register_date'] = $now;
1124 // now set the values for the billing location.
1125 foreach ($this->_fields
as $name => $dontCare) {
1129 // also add location name to the array
1130 $params["address_name-{$this->_bltID}"] =
1131 CRM_Utils_Array
::value('billing_first_name', $params) . ' ' .
1132 CRM_Utils_Array
::value('billing_middle_name', $params) . ' ' .
1133 CRM_Utils_Array
::value('billing_last_name', $params);
1135 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
1136 $fields["address_name-{$this->_bltID}"] = 1;
1137 $fields["email-{$this->_bltID}"] = 1;
1138 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'contact_type');
1140 $nameFields = array('first_name', 'middle_name', 'last_name');
1142 foreach ($nameFields as $name) {
1144 if (array_key_exists("billing_$name", $params)) {
1145 $params[$name] = $params["billing_{$name}"];
1146 $params['preserveDBName'] = TRUE;
1149 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params, $fields, $this->_contactId
, NULL, NULL, $ctype);
1152 if ($this->_params
['participant_role_id']) {
1153 foreach ($this->_params
['participant_role_id'] as $rkey) {
1154 $customFieldsRole = CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, $rkey, $this->_roleCustomDataTypeID
);
1155 $customFieldsEvent = CRM_Core_BAO_CustomField
::getFields('Participant',
1158 CRM_Utils_Array
::value('event_id', $params),
1159 $this->_eventNameCustomDataTypeID
1161 $customFieldsEventType = CRM_Core_BAO_CustomField
::getFields('Participant',
1164 $this->_eventTypeId
,
1165 $this->_eventTypeCustomDataTypeID
1167 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsRole,
1168 CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE)
1170 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEvent, $customFields);
1171 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEventType, $customFields);
1172 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
1180 //do cleanup line items if participant edit the Event Fee.
1181 if (($this->_lineItem ||
!isset($params['proceSetId'])) && !$this->_paymentId
&& $this->_id
) {
1182 CRM_Price_BAO_LineItem
::deleteLineItems($this->_id
, 'civicrm_participant');
1186 // add all the additioanl payment params we need
1187 $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}"]);
1188 $this->_params
["country-{$this->_bltID}"] = $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
1190 $this->_params
['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($this->_params
);
1191 $this->_params
['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($this->_params
);
1192 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
1193 $this->_params
['amount'] = $params['fee_amount'];
1194 $this->_params
['amount_level'] = $params['amount_level'];
1195 $this->_params
['currencyID'] = $config->defaultCurrency
;
1196 $this->_params
['payment_action'] = 'Sale';
1197 $this->_params
['invoiceID'] = md5(uniqid(rand(), TRUE));
1199 // at this point we've created a contact and stored its address etc
1200 // all the payment processors expect the name and address to be in the
1201 // so we copy stuff over to first_name etc.
1202 $paymentParams = $this->_params
;
1203 if (!empty($this->_params
['send_receipt'])) {
1204 $paymentParams['email'] = $this->_contributorEmail
;
1206 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $this->_params
, $paymentParams, TRUE);
1208 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
1210 $result = &$payment->doDirectPayment($paymentParams);
1212 if (is_a($result, 'CRM_Core_Error')) {
1213 CRM_Core_Error
::displaySessionError($result);
1214 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/view/participant',
1215 "reset=1&action=add&cid={$this->_contactId}&context=participant&mode={$this->_mode}"
1220 $this->_params
= array_merge($this->_params
, $result);
1223 $this->_params
['receive_date'] = $now;
1225 if (!empty($this->_params
['send_receipt'])) {
1226 $this->_params
['receipt_date'] = $now;
1229 $this->_params
['receipt_date'] = NULL;
1232 $this->set('params', $this->_params
);
1233 $this->assign('trxn_id', $result['trxn_id']);
1234 $this->assign('receive_date',
1235 CRM_Utils_Date
::processDate($this->_params
['receive_date'])
1238 //add contribution record
1239 $this->_params
['financial_type_id'] =
1240 CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
1241 $this->_params
['mode'] = $this->_mode
;
1243 //add contribution reocord
1244 $contributions[] = $contribution = CRM_Event_Form_Registration_Confirm
::processContribution($this, $this->_params
, $result, $contactID, FALSE);
1246 // add participant record
1247 $participants = array();
1248 if (!empty($this->_params
['participant_role_id']) && is_array($this->_params
['participant_role_id'])) {
1249 $this->_params
['participant_role_id'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1250 $this->_params
['participant_role_id']
1253 $participants[] = CRM_Event_Form_Registration
::addParticipant($this->_params
, $contactID);
1255 //add custom data for participant
1256 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
1257 CRM_Core_DAO
::$_nullArray,
1258 'civicrm_participant',
1259 $participants[0]->id
,
1262 //add participant payment
1263 $paymentParticipant = array(
1264 'participant_id' => $participants[0]->id
,
1265 'contribution_id' => $contribution->id
,
1269 CRM_Event_BAO_ParticipantPayment
::create($paymentParticipant, $ids);
1270 $this->_contactIds
[] = $this->_contactId
;
1273 $participants = array();
1274 if ($this->_single
) {
1275 if ($params['role_id']) {
1276 $params['role_id'] = str_replace(',', CRM_Core_DAO
::VALUE_SEPARATOR
, $params['role_id']);
1279 $params['role_id'] = 'NULL';
1281 $participants[] = CRM_Event_BAO_Participant
::create($params);
1284 foreach ($this->_contactIds
as $contactID) {
1285 $commonParams = $params;
1286 $commonParams['contact_id'] = $contactID;
1287 if ($commonParams['role_id']) {
1288 $commonParams['participant_role_id'] = $commonParams['role_id'] = str_replace(',', CRM_Core_DAO
::VALUE_SEPARATOR
, $params['role_id']);
1291 $commonParams['role_id'] = 'NULL';
1293 $participants[] = CRM_Event_BAO_Participant
::create($commonParams);
1297 if (isset($params['event_id'])) {
1298 $eventTitle = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
1299 $params['event_id'],
1304 if ($this->_single
) {
1305 $this->_contactIds
[] = $this->_contactId
;
1308 $contributions = array();
1309 if (!empty($params['record_contribution'])) {
1310 if (!empty($params['id'])) {
1311 if ($this->_onlinePendingContributionId
) {
1312 $ids['contribution'] = $this->_onlinePendingContributionId
;
1315 $ids['contribution'] = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1322 unset($params['note']);
1324 //build contribution params
1325 if (!$this->_onlinePendingContributionId
) {
1326 $contributionParams['source'] = "{$eventTitle}: Offline registration (by {$userName})";
1329 $contributionParams['currency'] = $config->defaultCurrency
;
1330 $contributionParams['non_deductible_amount'] = 'null';
1331 $contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array
::value('receive_date', $params) : 'null';
1333 $recordContribution = array( 'contact_id', 'financial_type_id',
1334 'payment_instrument_id', 'trxn_id',
1335 'contribution_status_id', 'receive_date',
1336 'check_number', 'campaign_id',
1339 foreach ($recordContribution as $f) {
1340 $contributionParams[$f] = CRM_Utils_Array
::value($f, $params);
1341 if ($f == 'trxn_id') {
1342 $this->assign('trxn_id', $contributionParams[$f]);
1346 //insert financial type name in receipt.
1347 $this->assign('contributionTypeName', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id']));
1348 $contributionParams['skipLineItem'] = 1;
1350 $contributionParams['contribution_mode'] = 'participant';
1351 $contributionParams['participant_id'] = $this->_id
;
1353 // Set is_pay_later flag for back-office offline Pending status contributions
1354 if ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup
::getValue('contribution_status', 'Pending', 'name')) {
1355 $contributionParams['is_pay_later'] = 1;
1358 if ($params['status_id'] == array_search('Partially paid', $participantStatus)) {
1359 if (!$amountOwed && $this->_action
& CRM_Core_Action
::UPDATE
) {
1360 $amountOwed = $params['fee_amount'];
1363 // if multiple participants are link, consider contribution total amount as the amount Owed
1364 if ($this->_id
&& CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
1365 $amountOwed = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_Contribution',
1366 $ids['contribution'],
1371 // CRM-13964 partial_payment_total
1372 if ($amountOwed > $params['total_amount']) {
1374 $contributionParams['partial_payment_total'] = $amountOwed;
1375 // the actual amount paid
1376 $contributionParams['partial_amount_pay'] = $params['total_amount'];
1380 if ($this->_single
) {
1384 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1388 foreach ($this->_contactIds
as $contactID) {
1389 $contributionParams['contact_id'] = $contactID;
1390 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1394 //insert payment record for this participation
1395 if (empty($ids['contribution'])) {
1396 foreach ($this->_contactIds
as $num => $contactID) {
1397 $ppDAO = new CRM_Event_DAO_ParticipantPayment();
1398 $ppDAO->participant_id
= $participants[$num]->id
;
1399 $ppDAO->contribution_id
= $contributions[$num]->id
;
1403 // next create the transaction record
1404 $transaction = new CRM_Core_Transaction();
1407 if ($this->_quickConfig
) {
1408 if (!empty($this->_params
['amount_priceset_level_radio'])) {
1409 $feeLevel = $this->_params
['amount_priceset_level_radio'];
1412 $feeLevel[] = $this->_params
['fee_level'] ;
1414 CRM_Event_BAO_Participant
::createDiscountTrxn($this->_eventId
, $contributionParams, $feeLevel);
1416 $transaction->commit();
1420 // also store lineitem stuff here
1421 if ((($this->_lineItem
& $this->_action
& CRM_Core_Action
::ADD
) ||
1422 ($this->_lineItem
&& CRM_Core_Action
::UPDATE
&& !$this->_paymentId
))
1424 foreach ($this->_contactIds
as $num => $contactID) {
1425 foreach ($this->_lineItem
as $key => $value) {
1426 if (is_array($value) && $value != 'skip') {
1427 foreach ($value as $lineKey => $line) {
1428 //10117 update the line items for participants if contribution amount is recorded
1429 if ($this->_quickConfig
&& !empty($params['total_amount']) &&
1430 ($params['status_id'] != array_search('Partially paid', $participantStatus))
1432 $line['unit_price'] = $line['line_total'] = $params['total_amount'];
1434 $lineItem[$this->_priceSetId
][$lineKey] = $line;
1436 CRM_Price_BAO_LineItem
::processPriceSet($participants[$num]->id
, $lineItem, CRM_Utils_Array
::value($num, $contributions, NULL), 'civicrm_participant');
1442 $updateStatusMsg = NULL;
1443 //send mail when participant status changed, CRM-4326
1444 if ($this->_id
&& $this->_statusId
&&
1445 $this->_statusId
!= CRM_Utils_Array
::value('status_id', $params) && !empty($params['is_notify'])) {
1447 $updateStatusMsg = CRM_Event_BAO_Participant
::updateStatusMessage($this->_id
,
1448 $params['status_id'],
1455 if (!empty($params['send_receipt'])) {
1456 if (array_key_exists($params['from_email_address'], $this->_fromEmails
['from_email_id'])) {
1457 $receiptFrom = $params['from_email_address'];
1460 $this->assign('module', 'Event Registration');
1461 //use of the message template below requires variables in different format
1462 $event = $events = array();
1463 $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
1465 //get all event details.
1466 CRM_Core_DAO
::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
1467 $event = $events[$params['event_id']];
1468 unset($event['start_date']);
1469 unset($event['end_date']);
1471 $role = CRM_Event_PseudoConstant
::participantRole();
1472 $participantRoles = CRM_Utils_Array
::value('role_id', $params);
1473 if (is_array($participantRoles)) {
1474 $selectedRoles = array();
1475 foreach (array_keys($participantRoles) as $roleId) {
1476 $selectedRoles[] = $role[$roleId];
1478 $event['participant_role'] = implode(', ', $selectedRoles);
1481 $event['participant_role'] = CRM_Utils_Array
::value($participantRoles, $role);
1483 $event['is_monetary'] = $this->_isPaidEvent
;
1485 if ($params['receipt_text']) {
1486 $event['confirm_email_text'] = $params['receipt_text'];
1489 $this->assign('isAmountzero', 1);
1490 $this->assign('event', $event);
1492 $this->assign('isShowLocation', $event['is_show_location']);
1493 if (CRM_Utils_Array
::value('is_show_location', $event) == 1) {
1494 $locationParams = array(
1495 'entity_id' => $params['event_id'],
1496 'entity_table' => 'civicrm_event',
1498 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
1499 $this->assign('location', $location);
1502 $status = CRM_Event_PseudoConstant
::participantStatus();
1503 if ($this->_isPaidEvent
) {
1504 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
1505 if (!$this->_mode
) {
1506 if (isset($params['payment_instrument_id'])) {
1507 $this->assign('paidBy',
1508 CRM_Utils_Array
::value($params['payment_instrument_id'],
1515 $this->assign('totalAmount', $contributionParams['total_amount']);
1516 if (isset($contributionParams['partial_payment_total'])) {
1518 $balanceAmount = $contributionParams['partial_payment_total'] - $contributionParams['partial_amount_pay'];
1519 $this->assign('balanceAmount', $balanceAmount );
1521 $this->assign('isPrimary', 1);
1522 $this->assign('checkNumber', CRM_Utils_Array
::value('check_number', $params));
1525 if (!empty($params['billing_first_name'])) {
1526 $name = $params['billing_first_name'];
1529 if (!empty($params['billing_middle_name'])) {
1530 $name .= " {$params['billing_middle_name']}";
1533 if (!empty($params['billing_last_name'])) {
1534 $name .= " {$params['billing_last_name']}";
1536 $this->assign('billingName', $name);
1538 // assign the address formatted up for display
1539 $addressParts = array(
1540 "street_address-{$this->_bltID}",
1541 "city-{$this->_bltID}",
1542 "postal_code-{$this->_bltID}",
1543 "state_province-{$this->_bltID}",
1544 "country-{$this->_bltID}",
1546 $addressFields = array();
1547 foreach ($addressParts as $part) {
1548 list($n, $id) = explode('-', $part);
1549 if (isset($this->_params
['billing_' . $part])) {
1550 $addressFields[$n] = $this->_params
['billing_' . $part];
1553 $this->assign('address', CRM_Utils_Address
::format($addressFields));
1555 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
1556 $date = CRM_Utils_Date
::mysqlToIso($date);
1557 $this->assign('credit_card_exp_date', $date);
1558 $this->assign('credit_card_number',
1559 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
1561 $this->assign('credit_card_type', $params['credit_card_type']);
1562 $this->assign('contributeMode', 'direct');
1563 $this->assign('isAmountzero', 0);
1564 $this->assign('is_pay_later', 0);
1565 $this->assign('isPrimary', 1);
1568 $this->assign('register_date', $params['register_date']);
1569 if ($params['receive_date']) {
1570 $this->assign('receive_date', $params['receive_date']);
1573 $participant = array(array('participant_id', '=', $participants[0]->id
, 0, 0));
1574 // check whether its a test drive ref CRM-3075
1575 if (!empty($this->_defaultValues
['is_test'])) {
1576 $participant[] = array('participant_test', '=', 1, 0, 0);
1579 $template = CRM_Core_Smarty
::singleton();
1580 $customGroup = array();
1581 //format submitted data
1582 foreach ($params['custom'] as $fieldID => $values) {
1583 foreach ($values as $fieldValue) {
1584 $customValue = array('data' => $fieldValue['value']);
1585 $customFields[$fieldID]['id'] = $fieldID;
1586 $formattedValue = CRM_Core_BAO_CustomGroup
::formatCustomValues($customValue, $customFields[$fieldID], TRUE);
1587 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace(' ', '', $formattedValue);
1591 foreach ($this->_contactIds
as $num => $contactID) {
1592 // Retrieve the name and email of the contact - this will be the TO for receipt email
1593 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($contactID);
1595 $this->_contributorDisplayName
= ($this->_contributorDisplayName
== ' ') ?
$this->_contributorEmail
: $this->_contributorDisplayName
;
1597 $waitStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
1598 if ($waitingStatus = CRM_Utils_Array
::value($params['status_id'], $waitStatus)) {
1599 $this->assign('isOnWaitlist', TRUE);
1602 $this->assign('customGroup', $customGroup);
1603 $this->assign('contactID', $contactID);
1604 $this->assign('participantID', $participants[$num]->id
);
1606 $this->_id
= $participants[$num]->id
;
1608 if ($this->_isPaidEvent
) {
1609 // fix amount for each of participants ( for bulk mode )
1610 $eventAmount = array();
1611 if (!empty($additionalParticipantDetails)) {
1612 $params['amount_level'] = preg_replace('/\ 1/', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName
;
1615 $eventAmount[$num] = array(
1616 'label' => preg_replace('/\ 1/', '', $params['amount_level']),
1617 'amount' => $params['fee_amount'],
1619 //as we are using same template for online & offline registration.
1620 //So we have to build amount as array.
1621 $eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
1622 $this->assign('amount', $eventAmount);
1625 $sendTemplateParams = array(
1626 'groupName' => 'msg_tpl_workflow_event',
1627 'valueName' => 'event_offline_receipt',
1628 'contactId' => $contactID,
1629 'isTest' => (bool) CRM_Utils_Array
::value('is_test', $this->_defaultValues
),
1630 'PDFFilename' => ts('confirmation').'.pdf',
1633 // try to send emails only if email id is present
1634 // and the do-not-email option is not checked for that contact
1635 if ($this->_contributorEmail
and !$this->_toDoNotEmail
) {
1636 $sendTemplateParams['from'] = $receiptFrom;
1637 $sendTemplateParams['toName'] = $this->_contributorDisplayName
;
1638 $sendTemplateParams['toEmail'] = $this->_contributorEmail
;
1639 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc', $this->_fromEmails
);
1640 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc', $this->_fromEmails
);
1643 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1645 $sent[] = $contactID;
1646 foreach ($participants as $ids => $values) {
1647 if ($values->contact_id
== $contactID) {
1648 CRM_Activity_BAO_Activity
::addActivity($values, 'Email');
1654 $notSent[] = $contactID;
1659 // set the participant id if it is not set
1661 $this->_id
= $participants[0]->id
;
1664 if (($this->_action
& CRM_Core_Action
::UPDATE
)) {
1665 $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contributorDisplayName
));
1666 if (!empty($params['send_receipt']) && count($sent)) {
1667 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', array(1 => $this->_contributorEmail
));
1670 if ($updateStatusMsg) {
1671 $statusMsg = "{$statusMsg} {$updateStatusMsg}";
1674 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
1675 if ($this->_single
) {
1676 $statusMsg = ts('Event registration for %1 has been added.', array(1 => $this->_contributorDisplayName
));
1677 if (!empty($params['send_receipt']) && count($sent)) {
1678 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $this->_contributorEmail
));
1682 $statusMsg = ts('Total Participant(s) added to event: %1.', array(1 => count($this->_contactIds
)));
1683 if (count($notSent) > 0) {
1684 $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)));
1686 elseif (isset($params['send_receipt'])) {
1687 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');
1691 CRM_Core_Session
::setStatus($statusMsg, ts('Saved'), 'success');
1693 $buttonName = $this->controller
->getButtonName();
1694 if ($this->_context
== 'standalone') {
1695 if ($buttonName == $this->getButtonName('upload', 'new')) {
1696 $urlParams = 'reset=1&action=add&context=standalone';
1698 $urlParams .= '&mode=' . $this->_mode
;
1701 $urlParams .= '&eid=' . $this->_eID
;
1703 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/participant/add', $urlParams));
1706 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
1707 "reset=1&cid={$this->_contactId}&selectedChild=participant"
1711 elseif ($buttonName == $this->getButtonName('upload', 'new')) {
1712 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view/participant',
1713 "reset=1&action=add&context={$this->_context}&cid={$this->_contactId}"