3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
38 * This class generates form components for processing a participation
41 class CRM_Event_Form_Participant
extends CRM_Contact_Form_Task
{
44 * the values for the contribution db object
52 * the values for the quickconfig for priceset
57 public $_quickConfig = NULL;
60 * Price Set ID, if the new price set method is used
68 * Array of fields for the price set
76 * the id of the participation that we are proceessing
89 protected $_noteId = NULL;
92 * the id of the contact associated with this participation
100 * array of event values
108 * Are we operating in "single mode", i.e. adding / editing only
109 * one participant record, or is this a batch add operation
113 public $_single = FALSE;
116 * If event is paid or unpaid
118 public $_isPaidEvent;
128 protected $_roleId = NULL;
133 protected $_eventTypeId = NULL;
136 * participant status Id
138 protected $_statusId = NULL;
141 * cache all the participant statuses
143 protected $_participantStatuses;
148 public $_mode = NULL;
156 *Line Item for Price Set
159 public $_lineItem = NULL;
161 *Contribution mode for event registration for offline mode
164 public $_contributeMode = 'direct';
169 * store id of role custom data type ( option value )
171 protected $_roleCustomDataTypeID;
174 * store id of event Name custom data type ( option value)
176 protected $_eventNameCustomDataTypeID;
179 * selected discount id
181 public $_originalDiscountId = NULL;
186 public $_eventId = NULL;
189 * id of payment, if any
191 public $_paymentId = NULL;
194 * array of participant role custom data
196 public $_participantRoleIds = array();
199 * Function to set variables up before form is built
204 public function preProcess() {
205 $this->_showFeeBlock
= CRM_Utils_Array
::value('eventId', $_GET);
206 $this->assign('showFeeBlock', FALSE);
207 $this->assign('feeBlockPaid', FALSE);
209 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
210 $this->_mode
= CRM_Utils_Request
::retrieve('mode', 'String', $this);
211 $this->_eID
= CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
212 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this);
213 $this->assign('context', $this->_context
);
215 if ($this->_contactId
) {
216 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
217 $this->assign('displayName', $displayName);
218 // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
219 CRM_Utils_System
::setTitle(ts('Event Registration for') . ' ' . $displayName);
222 // check the current path, if search based, then dont get participantID
224 $path = CRM_Utils_System
::currentPath();
225 if (strpos($path, 'civicrm/contact/search') === 0) {
229 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
233 $this->assign('participantId', $this->_id
);
234 $statusId = CRM_Core_DAO
::getFieldValue('CRM_Event_BAO_Participant', $this->_id
, 'status_id', 'id');
236 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
237 $this->_id
, 'id', 'participant_id'
239 // CRM-12615 - Get payment information from the primary registration
240 if ((!$this->_paymentId
) && ($this->_action
== CRM_Core_Action
::UPDATE
)) {
241 $registered_by_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
242 $this->_id
, 'registered_by_id', 'id'
244 if ($registered_by_id) {
245 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
246 $registered_by_id, 'id', 'participant_id'
248 $this->assign('registeredByParticipantId', $registered_by_id);
253 // get the option value for custom data type
254 $this->_roleCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantRole', 'name');
255 $this->_eventNameCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantEventName', 'name');
256 $this->_eventTypeCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantEventType', 'name');
257 $this->assign('roleCustomDataTypeID', $this->_roleCustomDataTypeID
);
258 $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID
);
259 $this->assign('eventTypeCustomDataTypeID', $this->_eventTypeCustomDataTypeID
);
262 $this->assign('participantMode', $this->_mode
);
264 $this->_paymentProcessor
= array('billing_mode' => 1);
266 $validProcessors = array();
267 $processors = CRM_Core_PseudoConstant
::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )");
269 foreach ($processors as $ppID => $label) {
270 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getPayment($ppID, $this->_mode
);
271 if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) {
274 elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode
== 'live') {
278 $paymentObject = CRM_Core_Payment
::singleton($this->_mode
, $paymentProcessor, $this);
279 $error = $paymentObject->checkConfig();
281 $validProcessors[$ppID] = $label;
283 $paymentObject = NULL;
286 if (empty($validProcessors)) {
287 CRM_Core_Error
::fatal(ts('Could not find valid payment processor for this page'));
290 $this->_processors
= $validProcessors;
292 // also check for billing information
293 // get the billing location type
294 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
295 // CRM-8108 remove ts around Billing location type
296 //$this->_bltID = array_search( ts('Billing'), $locationTypes );
297 $this->_bltID
= array_search('Billing', $locationTypes);
298 if (!$this->_bltID
) {
299 CRM_Core_Error
::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
301 $this->set('bltID', $this->_bltID
);
302 $this->assign('bltID', $this->_bltID
);
304 $this->_fields
= array();
306 CRM_Core_Payment_Form
::setCreditCardFields($this);
308 // this required to show billing block
309 $this->assign_by_ref('paymentProcessor', $paymentProcessor);
310 $this->assign('hidePayPalExpress', TRUE);
313 if ($this->_showFeeBlock
) {
314 $this->assign('showFeeBlock', TRUE);
315 $isMonetary = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_showFeeBlock
, 'is_monetary');
317 $this->assign('feeBlockPaid', TRUE);
319 return CRM_Event_Form_EventFees
::preProcess($this);
322 //custom data related code
323 $this->_cdType
= CRM_Utils_Array
::value('type', $_GET);
324 $this->assign('cdType', FALSE);
325 if ($this->_cdType
) {
326 $this->assign('cdType', TRUE);
327 return CRM_Custom_Form_CustomData
::preProcess($this, NULL, NULL, NULL, NULL, NULL, TRUE);
330 //check the mode when this form is called either single or as
332 if ($this->_id ||
$this->_contactId ||
$this->_context
== 'standalone') {
333 $this->_single
= TRUE;
334 $this->assign('urlPath', 'civicrm/contact/view/participant');
335 if (!$this->_id
&& !$this->_contactId
) {
336 $breadCrumbs = array(array('title' => ts('CiviEvent Dashboard'),
337 'url' => CRM_Utils_System
::url('civicrm/event', 'reset=1'),
340 CRM_Utils_System
::appendBreadCrumb($breadCrumbs);
344 //set the appropriate action
345 $context = $this->get('context');
346 $urlString = 'civicrm/contact/search';
347 $this->_action
= CRM_Core_Action
::BASIC
;
350 $urlString = 'civicrm/contact/search/advanced';
351 $this->_action
= CRM_Core_Action
::ADVANCED
;
355 $urlString = 'civicrm/contact/search/builder';
356 $this->_action
= CRM_Core_Action
::PROFILE
;
360 $urlString = 'civicrm/contact/search/basic';
361 $this->_action
= CRM_Core_Action
::BASIC
;
365 $urlString = 'civicrm/contact/search/custom';
366 $this->_action
= CRM_Core_Action
::COPY
;
369 parent
::preProcess();
371 $this->_single
= FALSE;
372 $this->_contactId
= NULL;
374 //set ajax path, this used for custom data building
375 $this->assign('urlPath', $urlString);
376 $this->assign('urlPathVar', "_qf_Participant_display=true&qfKey={$this->controller->_key}");
379 $this->assign('single', $this->_single
);
382 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
384 $this->assign('action', $this->_action
);
386 // check for edit permission
387 if (!CRM_Core_Permission
::checkActionPermission('CiviEvent', $this->_action
)) {
388 CRM_Core_Error
::fatal(ts('You do not have permission to access this page'));
391 if ($this->_action
& CRM_Core_Action
::DELETE
) {
392 // check delete permission for contribution
393 if ($this->_id
&& $this->_paymentId
&& !CRM_Core_Permission
::checkActionPermission('CiviContribute', $this->_action
)) {
394 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."));
400 // assign participant id to the template
401 $this->assign('participantId', $this->_id
);
402 $this->_roleId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'role_id');
405 // when fee amount is included in form
406 if (!empty($_POST['hidden_feeblock']) ||
!empty($_POST['send_receipt'])) {
407 CRM_Event_Form_EventFees
::preProcess($this);
408 CRM_Event_Form_EventFees
::buildQuickForm($this);
409 CRM_Event_Form_EventFees
::setDefaultValues($this);
412 // when custom data is included in this page
413 if (!empty($_POST['hidden_custom'])) {
414 //custom data of type participant role
415 if (!empty($_POST['role_id'])) {
416 foreach ($_POST['role_id'] as $k => $val) {
418 CRM_Custom_Form_CustomData
::preProcess($this, $this->_roleCustomDataTypeID
, $k, 1, 'Participant', $this->_id
);
419 CRM_Custom_Form_CustomData
::buildQuickForm($this);
420 CRM_Custom_Form_CustomData
::setDefaultValues($this);
424 //custom data of type participant event
425 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventNameCustomDataTypeID
, $_POST['event_id'], 1, 'Participant', $this->_id
);
426 CRM_Custom_Form_CustomData
::buildQuickForm($this);
427 CRM_Custom_Form_CustomData
::setDefaultValues($this);
429 // custom data of type participant event type
431 if ($eventId = CRM_Utils_Array
::value('event_id', $_POST)) {
432 $eventTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'event_type_id', 'id');
434 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventTypeCustomDataTypeID
, $eventTypeId,
435 1, 'Participant', $this->_id
437 CRM_Custom_Form_CustomData
::buildQuickForm($this);
438 CRM_Custom_Form_CustomData
::setDefaultValues($this);
440 //custom data of type participant, ( we 'null' to reset subType and subName)
441 CRM_Custom_Form_CustomData
::preProcess($this, 'null', 'null', 1, 'Participant', $this->_id
);
442 CRM_Custom_Form_CustomData
::buildQuickForm($this);
443 CRM_Custom_Form_CustomData
::setDefaultValues($this);
446 // CRM-4395, get the online pending contribution id.
447 $this->_onlinePendingContributionId
= NULL;
448 if (!$this->_mode
&& $this->_id
&& ($this->_action
& CRM_Core_Action
::UPDATE
)) {
449 $this->_onlinePendingContributionId
= CRM_Contribute_BAO_Contribution
::checkOnlinePendingContribution($this->_id
,
453 $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId
);
454 $roleIds = CRM_Event_PseudoConstant
::participantRole();
456 if (!empty($roleIds)) {
458 SELECT civicrm_custom_group.name as name,
459 civicrm_custom_group.id as id,
460 extends_entity_column_value as value
461 FROM civicrm_custom_group
462 WHERE ( extends_entity_column_value REGEXP '[[:<:]]" . implode('[[:>:]]|[[:<:]]', array_keys($roleIds)) . "[[:>:]]'
463 OR extends_entity_column_value IS NULL )
464 AND extends_entity_column_id = '{$this->_roleCustomDataTypeID}'
465 AND extends = 'Participant'
468 $dao = CRM_Core_DAO
::executeQuery($query);
469 while ($dao->fetch()) {
471 $getRole = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $dao->value
);
472 foreach ($getRole as $r) {
476 if (isset($this->_participantRoleIds
[$r])) {
477 $this->_participantRoleIds
[$r] .= ',' . $dao->name
;
480 $this->_participantRoleIds
[$r] = $dao->name
;
485 if (isset($this->_participantRoleIds
[0])) {
486 $this->_participantRoleIds
[0] .= ',' . $dao->name
;
489 $this->_participantRoleIds
[0] = $dao->name
;
495 foreach ($roleIds as $k => $v) {
496 if (!isset($this->_participantRoleIds
[$k])) {
497 $this->_participantRoleIds
[$k] = '';
500 $this->assign('participantRoleIds', $this->_participantRoleIds
);
504 * This function sets the default values for the form in edit/view mode
505 * the default values are retrieved from the database
511 public function setDefaultValues() {
512 if ($this->_showFeeBlock
) {
513 return CRM_Event_Form_EventFees
::setDefaultValues($this);
516 if ($this->_cdType
) {
517 return CRM_Custom_Form_CustomData
::setDefaultValues($this);
522 if ($this->_action
& CRM_Core_Action
::DELETE
) {
528 $params = array('id' => $this->_id
);
530 CRM_Event_BAO_Participant
::getValues($params, $defaults, $ids);
531 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
532 if ($defaults[$this->_id
]['role_id']) {
533 foreach (explode($sep, $defaults[$this->_id
]['role_id']) as $k => $v) {
534 $defaults[$this->_id
]["role_id[{$v}]"] = 1;
536 unset($defaults[$this->_id
]['role_id']);
538 $this->_contactId
= $defaults[$this->_id
]['contact_id'];
539 $this->_statusId
= $defaults[$this->_id
]['participant_status_id'];
541 //set defaults for note
542 $noteDetails = CRM_Core_BAO_Note
::getNote($this->_id
, 'civicrm_participant');
543 $defaults[$this->_id
]['note'] = array_pop($noteDetails);
545 // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859)
546 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
547 $this->assign('additionalParticipants', CRM_Event_BAO_Participant
::getAdditionalParticipants($this->_id
));
550 // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
551 if (!empty($defaults[$this->_id
]['participant_registered_by_id'])) {
552 $registered_by_contact_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
553 $defaults[$this->_id
]['participant_registered_by_id'],
556 $this->assign('participant_registered_by_id', $defaults[$this->_id
]['participant_registered_by_id']);
557 $this->assign('registered_by_contact_id', $registered_by_contact_id);
558 $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact
::displayName($registered_by_contact_id));
562 if ($this->_action
& (CRM_Core_Action
::VIEW | CRM_Core_Action
::BROWSE
)) {
563 $inactiveNeeded = TRUE;
568 $inactiveNeeded = FALSE;
571 //setting default register date
572 if ($this->_action
== CRM_Core_Action
::ADD
) {
573 $statuses = array_flip($this->_participantStatuses
);
574 $defaults[$this->_id
]['status_id'] = CRM_Utils_Array
::value(ts('Registered'), $statuses);
575 if (!empty($defaults[$this->_id
]['event_id'])) {
576 $contributionTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
577 $defaults[$this->_id
]['event_id'],
580 if ($contributionTypeId) {
581 $defaults[$this->_id
]['financial_type_id'] = $contributionTypeId;
586 $fields["email-{$this->_bltID}"] = 1;
587 $fields['email-Primary'] = 1;
589 if ($this->_contactId
) {
590 CRM_Core_BAO_UFGroup
::setProfileDefaults($this->_contactId
, $fields, $defaults);
593 if (empty($defaults["email-{$this->_bltID}"]) &&
594 !empty($defaults['email-Primary'])
596 $defaults[$this->_id
]["email-{$this->_bltID}"] = $defaults['email-Primary'];
600 $submittedRole = $this->getElementValue('role_id');
601 if (!empty($submittedRole[0])) {
602 $roleID = $submittedRole[0];
604 $submittedEvent = $this->getElementValue('event_id');
605 if ($submittedEvent[0]) {
606 $eventID = $submittedEvent[0];
610 $defaults[$this->_id
]['record_contribution'] = 0;
612 if ($defaults[$this->_id
]['participant_is_pay_later']) {
613 $this->assign('participant_is_pay_later', TRUE);
616 $this->assign('participant_status_id', $defaults[$this->_id
]['participant_status_id']);
617 $roleID = $defaults[$this->_id
]['participant_role_id'];
618 $eventID = $defaults[$this->_id
]['event_id'];
620 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
622 $this->_discountId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'discount_id');
623 if ($this->_discountId
) {
624 $this->set('discountId', $this->_discountId
);
628 list($defaults[$this->_id
]['register_date'],
629 $defaults[$this->_id
]['register_date_time']
630 ) = CRM_Utils_Date
::setDateDefaults(
631 CRM_Utils_Array
::value('register_date', $defaults[$this->_id
]), 'activityDateTime'
634 //assign event and role id, this is needed for Custom data building
635 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
636 if (!empty($defaults[$this->_id
]['participant_role_id'])) {
637 $roleIDs = explode($sep, $defaults[$this->_id
]['participant_role_id']);
639 if (isset($roleIDs)) {
640 $this->assign('roleID', $roleIDs);
642 if (isset($_POST['event_id'])) {
643 $eventID = $_POST['event_id'];
645 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
649 if (isset($eventID)) {
650 $this->assign('eventID', $eventID);
651 $this->set('eventId', $eventID);
654 if (isset($this->_eventTypeId
)) {
655 $this->assign('eventTypeID', $this->_eventTypeId
);
658 $this->assign('event_is_test', CRM_Utils_Array
::value('event_is_test', $defaults[$this->_id
]));
659 return $defaults[$this->_id
];
663 * Function to build the form
668 public function buildQuickForm() {
669 CRM_Core_Resources
::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
670 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
671 $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses);
672 CRM_Core_Resources
::singleton()->addSetting(array('partiallyPaidStatusId' => $partiallyPaidStatusId));
674 if ($this->_showFeeBlock
) {
675 return CRM_Event_Form_EventFees
::buildQuickForm($this);
678 if ($this->_cdType
) {
679 return CRM_Custom_Form_CustomData
::buildQuickForm($this);
682 //need to assign custom data type to the template
683 $this->assign('customDataType', 'Participant');
685 $this->applyFilter('__ALL__', 'trim');
687 if ($this->_action
& CRM_Core_Action
::DELETE
) {
688 if ($this->_single
) {
689 $additionalParticipant = count(CRM_Event_BAO_Event
::buildCustomProfile($this->_id
,
695 if ($additionalParticipant) {
696 $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'),
697 2 => ts('Delete only this participant record.'),
699 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
700 $this->setDefaults(array('delete_participant' => 1));
701 $this->assign('additionalParticipant', $additionalParticipant);
704 $this->addButtons(array(
707 'name' => ts('Delete'),
708 'spacing' => ' ',
713 'name' => ts('Cancel'),
721 if ($this->_single
) {
722 $urlPath = 'civicrm/contact/view/participant';
723 $urlParams = "reset=1&cid={$this->_contactId}&context=participant";
724 if ($this->_context
== 'standalone') {
725 CRM_Contact_Form_NewContact
::buildQuickForm($this);
726 $urlParams = 'reset=1&context=standalone';
727 $urlPath = 'civicrm/participant/add';
731 $urlParams .= "&action=update&id={$this->_id}";
734 $urlParams .= "&action=add";
738 $urlParams .= "&mode={$this->_mode}";
741 $url = CRM_Utils_System
::url($urlPath, $urlParams,
746 $currentPath = CRM_Utils_System
::currentPath();
748 $url = CRM_Utils_System
::url($currentPath, '_qf_Participant_display=true',
753 $this->assign('refreshURL', $url);
755 $this->add('hidden', 'past_event');
759 $eventEndDate = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_eID
,'end_date');
761 $this->assign('past', 0);
762 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
763 $events = CRM_Event_BAO_Event
::getEvents(1, FALSE, FALSE);
765 elseif ($this->getElementValue('past_event') ||
(isset($eventEndDate) && (CRM_Utils_Date
::currentDBDate() > CRM_Utils_Date
::processDate($eventEndDate)))) {
766 $pastval = $this->getElementValue('past_event');
767 $events = CRM_Event_BAO_Event
::getEvents($pastval);
768 $this->assign('past', $pastval);
771 $events = CRM_Event_BAO_Event
::getEvents();
775 //unset the event which are not monetary when credit card
776 //event registration is used
777 foreach ($events as $key => $val) {
778 $isPaid = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $key, 'is_monetary');
780 unset($events[$key]);
783 $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors
, TRUE);
786 // build array(event -> eventType) mapper
788 SELECT civicrm_event.id as id, civicrm_event.event_type_id as event_type_id
790 WHERE civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0";
791 $dao = CRM_Core_DAO
::executeQuery($query);
792 $eventAndTypeMapping = array();
793 while ($dao->fetch()) {
794 $eventAndTypeMapping[$dao->id
] = $dao->event_type_id
;
796 $eventAndTypeMapping = json_encode($eventAndTypeMapping);
797 // building of mapping ends --
799 //inherit the campaign from event.
800 $eventCampaigns = array();
801 $allEventIds = array_keys($events);
802 if (!empty($allEventIds)) {
803 CRM_Core_PseudoConstant
::populate($eventCampaigns,
804 'CRM_Event_DAO_Event',
808 $eventCampaigns = json_encode($eventCampaigns);
810 $element = $this->add('select', 'event_id', ts('Event'),
812 '' => ts('- select -')) +
$events,
814 array('onchange' => "buildFeeBlock( this.value ); CRM.buildCustomData( 'Participant', this.value, {$this->_eventNameCustomDataTypeID} ); buildParticipantRole( this.value ); buildEventTypeCustomData( this.value, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' ); loadCampaign( this.value, {$eventCampaigns} );", 'class' => 'huge')
818 // note that embedding JS within PHP files is quite awful, IMO
819 // but we do the same for the onChange element and this form is complex
820 // and i did not want to break it late in the 3.2 cycle
821 $preloadJSSnippet = NULL;
822 if (!empty($_GET['reset']) && $this->_eID
) {
823 $preloadJSSnippet = "
825 cj('#event_id').val( '{$this->_eID}' );
826 buildFeeBlock( {$this->_eID} );
827 CRM.buildCustomData( 'Participant', {$this->_eID}, {$this->_eventNameCustomDataTypeID} );
828 buildEventTypeCustomData( {$this->_eID}, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' );
829 loadCampaign( {$this->_eID}, {$eventCampaigns} );
834 $this->assign('preloadJSSnippet', $preloadJSSnippet);
837 //frozen the field fix for CRM-4171
838 if ($this->_action
& CRM_Core_Action
::UPDATE
&& $this->_id
) {
839 if (CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
840 $this->_id
, 'contribution_id', 'participant_id'
846 //CRM-7362 --add campaigns.
849 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'campaign_id');
852 $eventId = CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
854 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
857 CRM_Campaign_BAO_Campaign
::addCampaign($this, $campaignId);
859 $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
862 $this->assign('entityID', $this->_id
);
865 $roleids = CRM_Event_PseudoConstant
::participantRole();
867 foreach ($roleids as $rolekey => $rolevalue) {
868 $roleTypes[] = $this->createElement('checkbox', $rolekey, NULL, $rolevalue,
869 array('onclick' => "showCustomData( 'Participant', {$rolekey}, {$this->_roleCustomDataTypeID} );")
873 $this->addGroup($roleTypes, 'role_id', ts('Participant Role'));
874 $this->addRule('role_id', ts('Role is required'), 'required');
877 $checkCancelledJs = array('onchange' => "return sendNotification( );");
879 if ($this->_onlinePendingContributionId
) {
880 $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant
::participantStatus());
881 $cancelledContributionStatusId = array_search('Cancelled',
882 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
884 $checkCancelledJs = array(
886 "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});",
889 $participantStatusId = array_search('Pending from pay later',
890 CRM_Event_PseudoConstant
::participantStatus()
892 $contributionStatusId = array_search('Completed',
893 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
895 $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
898 // get the participant status names to build special status array which is used to show notification
899 // checkbox below participant status select
900 $participantStatusName = CRM_Event_PseudoConstant
::participantStatus();
901 $notificationStatuses = array(
903 'Pending from waitlist',
904 'Pending from approval',
908 // get the required status and then implode only ids
909 $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
910 $this->assign('notificationStatusIds', $notificationStatusIds);
912 $this->_participantStatuses
= CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label');
913 $this->addSelect('status_id', $checkCancelledJs, TRUE);
915 $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
917 $this->add('text', 'source', ts('Event Source'));
918 $noteAttributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Note');
919 $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
923 'name' => ts('Save'),
928 $path = CRM_Utils_System
::currentPath();
929 $excludeForPaths = array(
930 'civicrm/contact/search',
931 'civicrm/group/search'
933 if (!in_array($path, $excludeForPaths)) {
936 'name' => ts('Save and New'),
944 'name' => ts('Cancel'),
947 $this->addButtons($buttons);
948 if ($this->_action
== CRM_Core_Action
::VIEW
) {
954 * Add local and global form rules
960 function addRules() {
961 $this->addFormRule(array('CRM_Event_Form_Participant', 'formRule'), $this);
965 * global validation rules for the form
967 * @param array $fields posted values of the form
969 * @return array list of errors to be posted back to the form
973 static function formRule($values, $files, $self) {
974 // If $values['_qf_Participant_next'] is Delete or
975 // $values['event_id'] is empty, then return
976 // instead of proceeding further.
978 if ((CRM_Utils_Array
::value('_qf_Participant_next', $values) == 'Delete') ||
979 (!$values['event_id'])
985 //check if contact is selected in standalone mode
986 if (isset($values['contact_select_id'][1]) && !$values['contact_select_id'][1]) {
987 $errorMsg['contact[1]'] = ts('Please select a contact or create new contact');
990 if (!empty($values['payment_processor_id'])) {
991 // make sure that credit card number and cvv are valid
992 CRM_Core_Payment_Form
::validateCreditCard($values, $errorMsg);
995 if (!empty($values['record_contribution'])) {
996 if (empty($values['financial_type_id'])) {
997 $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
999 if (empty($values['payment_instrument_id'])) {
1000 $errorMsg['payment_instrument_id'] = ts('Paid By is a required field.');
1004 // validate contribution status for 'Failed'.
1005 if ($self->_onlinePendingContributionId
&& !empty($values['record_contribution']) &&
1006 (CRM_Utils_Array
::value('contribution_status_id', $values) ==
1007 array_search('Failed', CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name'))
1010 $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.');
1013 // do the amount validations.
1014 //skip for update mode since amount is freeze, CRM-6052
1015 if ((!$self->_id
&& empty($values['total_amount']) &&
1016 empty($self->_values
['line_items'])
1018 ($self->_id
&& !$self->_paymentId
&& isset($self->_values
['line_items']) && is_array($self->_values
['line_items']))
1020 if ($priceSetId = CRM_Utils_Array
::value('priceSetId', $values)) {
1021 CRM_Price_BAO_PriceField
::priceSetValidation($priceSetId, $values, $errorMsg, TRUE);
1024 return CRM_Utils_Array
::crmIsEmptyArray($errorMsg) ?
TRUE : $errorMsg;
1028 * Function to process the form
1032 public function postProcess() {
1033 // get the submitted form values.
1034 $params = $this->controller
->exportValues($this->_name
);
1036 if ($this->_action
& CRM_Core_Action
::DELETE
) {
1037 if (CRM_Utils_Array
::value('delete_participant', $params) == 2) {
1038 $additionalId = (CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
));
1039 $participantLinks = (CRM_Event_BAO_Participant
::getAdditionalParticipantUrl($additionalId));
1041 if (CRM_Utils_Array
::value('delete_participant', $params) == 1) {
1042 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
1043 foreach ($additionalIds as $value) {
1044 CRM_Event_BAO_Participant
::deleteParticipant($value);
1047 CRM_Event_BAO_Participant
::deleteParticipant($this->_id
);
1048 CRM_Core_Session
::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success');
1049 if (!empty($participantLinks)) {
1050 $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;
1051 CRM_Core_Session
::setStatus($status, ts('Group Payment Deleted'));
1056 $participantStatus = CRM_Event_PseudoConstant
::participantStatus();
1057 // set the contact, when contact is selected
1058 if (!empty($params['contact_select_id'])) {
1059 $this->_contactId
= $params['contact_select_id'][1];
1061 if ($this->_priceSetId
&& $isQuickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
1062 $this->_quickConfig
= $isQuickConfig;
1066 $params['id'] = $this->_id
;
1069 $config = CRM_Core_Config
::singleton();
1070 if ($this->_isPaidEvent
) {
1072 $contributionParams = array();
1073 $lineItem = array();
1074 $additionalParticipantDetails = array();
1075 if (($this->_id
&& $this->_action
& CRM_Core_Action
::UPDATE
) && $this->_paymentId
) {
1076 $participantBAO = new CRM_Event_BAO_Participant();
1077 $participantBAO->id
= $this->_id
;
1078 $participantBAO->find(TRUE);
1079 $contributionParams['total_amount'] = $participantBAO->fee_amount
;
1081 $params['discount_id'] = NULL;
1082 //re-enter the values for UPDATE mode
1083 $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level
;
1084 $params['fee_amount'] = $participantBAO->fee_amount
;
1085 if (isset($params['priceSetId'])) {
1086 $lineItem[0] = CRM_Price_BAO_LineItem
::getLineItems($this->_id
);
1088 //also add additional participant's fee level/priceset
1089 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
1090 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
1091 $hasLineItems = CRM_Utils_Array
::value('priceSetId', $params, FALSE);
1092 $additionalParticipantDetails = CRM_Event_BAO_Participant
::getFeeDetails($additionalIds,
1099 //check if discount is selected
1100 if (!empty($params['discount_id'])) {
1101 $discountId = $params['discount_id'];
1104 $discountId = $params['discount_id'] = 'null';
1107 //lets carry currency, CRM-4453
1108 $params['fee_currency'] = $config->defaultCurrency
;
1109 CRM_Price_BAO_PriceSet
::processAmount($this->_values
['fee'],
1110 $params, $lineItem[0]
1112 //CRM-11529 for quick config backoffice transactions
1113 //when financial_type_id is passed in form, update the
1114 //lineitems with the financial type selected in form
1115 $submittedFinancialType = CRM_Utils_Array
::value('financial_type_id', $params);
1116 $isPaymentRecorded = CRM_Utils_Array
::value('record_contribution', $params);
1117 if ($isPaymentRecorded && $this->_quickConfig
&& $submittedFinancialType) {
1118 foreach ($lineItem[0] as &$values) {
1119 $values['financial_type_id'] = $submittedFinancialType;
1123 $params['fee_level'] = $params['amount_level'];
1124 $contributionParams['total_amount'] = $params['amount'];
1125 if ($this->_quickConfig
&& !empty($params['total_amount']) && $params['status_id'] != array_search('Partially paid', $participantStatus)) {
1126 $params['fee_amount'] = $params['total_amount'];
1129 $params['fee_amount'] = $params['amount'];
1133 if (isset($params['priceSetId'])) {
1134 if (!empty($lineItem[0])) {
1135 $this->set('lineItem', $lineItem);
1137 $this->_lineItem
= $lineItem;
1138 $lineItem = array_merge($lineItem, $additionalParticipantDetails);
1140 $participantCount = array();
1141 foreach ($lineItem as $k) {
1142 foreach ($k as $v) {
1143 if (CRM_Utils_Array
::value('participant_count', $v) > 0) {
1144 $participantCount[] = $v['participant_count'];
1149 if (isset($participantCount)) {
1150 $this->assign('pricesetFieldsCount', $participantCount);
1152 $this->assign('lineItem', empty($lineItem[0]) ||
$this->_quickConfig?
FALSE : $lineItem);
1155 $this->assign('amount_level', $params['amount_level']);
1159 $this->_params
= $params;
1161 if (isset($params['amount'])) {
1162 $amountOwed = $params['amount'];
1163 unset($params['amount']);
1165 $params['register_date'] = CRM_Utils_Date
::processDate($params['register_date'], $params['register_date_time']);
1166 $params['receive_date'] = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('receive_date', $params));
1167 $params['contact_id'] = $this->_contactId
;
1169 // overwrite actual payment amount if entered
1170 if (!empty($params['total_amount'])) {
1171 $contributionParams['total_amount'] = CRM_Utils_Array
::value('total_amount', $params);
1175 // Retrieve the name and email of the current user - this will be the FROM for the receipt email
1176 $session = CRM_Core_Session
::singleton();
1177 $userID = $session->get('userID');
1180 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($userID);
1182 if ($this->_contactId
) {
1183 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($this->_contactId
);
1187 if (!$this->_isPaidEvent
) {
1188 CRM_Core_Error
::fatal(ts('Selected Event is not Paid Event '));
1190 //modify params according to parameter used in create
1191 //participant method (addParticipant)
1192 $this->_params
['participant_status_id'] = $params['status_id'];
1193 $this->_params
['participant_role_id'] = $params['role_id'];
1194 $this->_params
['participant_register_date'] = $params['register_date'];
1197 CRM_Core_DAO
::getFieldValue(
1198 'CRM_Event_DAO_Event',
1199 $params['event_id'],
1203 // set source if not set
1204 if (empty($params['source'])) {
1205 $this->_params
['participant_source'] = ts('Offline Registration for Event: %2 by: %1', array(1 => $userName, 2 => $eventTitle));
1208 $this->_params
['participant_source'] = $params['source'];
1210 $this->_params
['description'] = $this->_params
['participant_source'];
1212 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($this->_params
['payment_processor_id'],
1215 $now = date('YmdHis');
1218 // set email for primary location.
1219 $fields['email-Primary'] = 1;
1220 $params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail
;
1222 $params['register_date'] = $now;
1224 // now set the values for the billing location.
1225 foreach ($this->_fields
as $name => $dontCare) {
1229 // also add location name to the array
1230 $params["address_name-{$this->_bltID}"] =
1231 CRM_Utils_Array
::value('billing_first_name', $params) . ' ' .
1232 CRM_Utils_Array
::value('billing_middle_name', $params) . ' ' .
1233 CRM_Utils_Array
::value('billing_last_name', $params);
1235 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
1236 $fields["address_name-{$this->_bltID}"] = 1;
1237 $fields["email-{$this->_bltID}"] = 1;
1238 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'contact_type');
1240 $nameFields = array('first_name', 'middle_name', 'last_name');
1242 foreach ($nameFields as $name) {
1244 if (array_key_exists("billing_$name", $params)) {
1245 $params[$name] = $params["billing_{$name}"];
1246 $params['preserveDBName'] = TRUE;
1249 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params, $fields, $this->_contactId
, NULL, NULL, $ctype);
1252 $roleAllIds = CRM_Utils_Array
::value('role_id', $params);
1254 foreach ($roleAllIds as $rkey => $rvalue) {
1255 $customFieldsRole = CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, $rkey, $this->_roleCustomDataTypeID
);
1256 $customFieldsEvent = CRM_Core_BAO_CustomField
::getFields('Participant',
1259 CRM_Utils_Array
::value('event_id', $params),
1260 $this->_eventNameCustomDataTypeID
1262 $customFieldsEventType = CRM_Core_BAO_CustomField
::getFields('Participant',
1265 $this->_eventTypeId
,
1266 $this->_eventTypeCustomDataTypeID
1268 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsRole,
1269 CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE)
1271 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEvent, $customFields);
1272 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEventType, $customFields);
1273 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
1281 //do cleanup line items if participant edit the Event Fee.
1282 if (($this->_lineItem ||
!isset($params['proceSetId'])) && !$this->_paymentId
&& $this->_id
) {
1283 CRM_Price_BAO_LineItem
::deleteLineItems($this->_id
, 'civicrm_participant');
1287 // add all the additioanl payment params we need
1288 $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}"]);
1289 $this->_params
["country-{$this->_bltID}"] = $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
1291 $this->_params
['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($this->_params
);
1292 $this->_params
['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($this->_params
);
1293 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
1294 $this->_params
['amount'] = $params['fee_amount'];
1295 $this->_params
['amount_level'] = $params['amount_level'];
1296 $this->_params
['currencyID'] = $config->defaultCurrency
;
1297 $this->_params
['payment_action'] = 'Sale';
1298 $this->_params
['invoiceID'] = md5(uniqid(rand(), TRUE));
1300 // at this point we've created a contact and stored its address etc
1301 // all the payment processors expect the name and address to be in the
1302 // so we copy stuff over to first_name etc.
1303 $paymentParams = $this->_params
;
1304 if (!empty($this->_params
['send_receipt'])) {
1305 $paymentParams['email'] = $this->_contributorEmail
;
1307 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $this->_params
, $paymentParams, TRUE);
1309 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
1311 $result = &$payment->doDirectPayment($paymentParams);
1313 if (is_a($result, 'CRM_Core_Error')) {
1314 CRM_Core_Error
::displaySessionError($result);
1315 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/view/participant',
1316 "reset=1&action=add&cid={$this->_contactId}&context=participant&mode={$this->_mode}"
1321 $this->_params
= array_merge($this->_params
, $result);
1324 $this->_params
['receive_date'] = $now;
1326 if (!empty($this->_params
['send_receipt'])) {
1327 $this->_params
['receipt_date'] = $now;
1330 $this->_params
['receipt_date'] = NULL;
1333 $this->set('params', $this->_params
);
1334 $this->assign('trxn_id', $result['trxn_id']);
1335 $this->assign('receive_date',
1336 CRM_Utils_Date
::processDate($this->_params
['receive_date'])
1339 //add contribution record
1340 $this->_params
['financial_type_id'] =
1341 CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
1342 $this->_params
['mode'] = $this->_mode
;
1344 //add contribution reocord
1345 $contributions[] = $contribution = CRM_Event_Form_Registration_Confirm
::processContribution($this, $this->_params
, $result, $contactID, FALSE);
1347 // add participant record
1348 $participants = array();
1349 if (!empty($this->_params
['participant_role_id']) && is_array($this->_params
['participant_role_id'])) {
1350 $this->_params
['participant_role_id'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1351 array_keys($this->_params
['participant_role_id'])
1354 $participants[] = CRM_Event_Form_Registration
::addParticipant($this->_params
, $contactID);
1356 //add custom data for participant
1357 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
1358 CRM_Core_DAO
::$_nullArray,
1359 'civicrm_participant',
1360 $participants[0]->id
,
1363 //add participant payment
1364 $paymentParticipant = array(
1365 'participant_id' => $participants[0]->id
,
1366 'contribution_id' => $contribution->id
,
1370 CRM_Event_BAO_ParticipantPayment
::create($paymentParticipant, $ids);
1371 $this->_contactIds
[] = $this->_contactId
;
1374 $participants = array();
1375 if ($this->_single
) {
1376 if ($params['role_id']) {
1377 foreach ($params['role_id'] as $k => $v) {
1380 $seperator = CRM_Core_DAO
::VALUE_SEPARATOR
;
1381 $params['role_id'] = implode($seperator, $rolesIDS);
1384 $params['role_id'] = 'NULL';
1386 $participants[] = CRM_Event_BAO_Participant
::create($params);
1389 foreach ($this->_contactIds
as $contactID) {
1390 $commonParams = $params;
1391 $commonParams['contact_id'] = $contactID;
1392 if ($commonParams['role_id']) {
1393 $rolesIDS = array();
1394 foreach ($commonParams['role_id'] as $k => $v) {
1397 $seperator = CRM_Core_DAO
::VALUE_SEPARATOR
;
1398 $commonParams['role_id'] = implode($seperator, $rolesIDS);
1399 $commonParams['participant_role_id'] = implode($seperator, $rolesIDS);
1402 $commonParams['role_id'] = 'NULL';
1404 $participants[] = CRM_Event_BAO_Participant
::create($commonParams);
1408 if (isset($params['event_id'])) {
1409 $eventTitle = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
1410 $params['event_id'],
1415 if ($this->_single
) {
1416 $this->_contactIds
[] = $this->_contactId
;
1419 $contributions = array();
1420 if (!empty($params['record_contribution'])) {
1421 if (!empty($params['id'])) {
1422 if ($this->_onlinePendingContributionId
) {
1423 $ids['contribution'] = $this->_onlinePendingContributionId
;
1426 $ids['contribution'] = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1433 unset($params['note']);
1435 //build contribution params
1436 if (!$this->_onlinePendingContributionId
) {
1437 $contributionParams['source'] = "{$eventTitle}: Offline registration (by {$userName})";
1440 $contributionParams['currency'] = $config->defaultCurrency
;
1441 $contributionParams['non_deductible_amount'] = 'null';
1442 $contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array
::value('receive_date', $params) : 'null';
1444 $recordContribution = array( 'contact_id', 'financial_type_id',
1445 'payment_instrument_id', 'trxn_id',
1446 'contribution_status_id', 'receive_date',
1447 'check_number', 'campaign_id',
1450 foreach ($recordContribution as $f) {
1451 $contributionParams[$f] = CRM_Utils_Array
::value($f, $params);
1452 if ($f == 'trxn_id') {
1453 $this->assign('trxn_id', $contributionParams[$f]);
1457 //insert financial type name in receipt.
1458 $this->assign('contributionTypeName', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id']));
1459 $contributionParams['skipLineItem'] = 1;
1461 $contributionParams['contribution_mode'] = 'participant';
1462 $contributionParams['participant_id'] = $this->_id
;
1464 // Set is_pay_later flag for back-office offline Pending status contributions
1465 if ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup
::getValue('contribution_status', 'Pending', 'name')) {
1466 $contributionParams['is_pay_later'] = 1;
1469 if ($params['status_id'] == array_search('Partially paid', $participantStatus)) {
1470 // CRM-13964 partial_payment_total
1471 if ($amountOwed > $params['total_amount']) {
1473 $contributionParams['partial_payment_total'] = $amountOwed;
1474 // the actual amount paid
1475 $contributionParams['partial_amount_pay'] = $params['total_amount'];
1478 if ($this->_single
) {
1482 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1486 foreach ($this->_contactIds
as $contactID) {
1487 $contributionParams['contact_id'] = $contactID;
1488 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1492 //insert payment record for this participation
1493 if (empty($ids['contribution'])) {
1494 foreach ($this->_contactIds
as $num => $contactID) {
1495 $ppDAO = new CRM_Event_DAO_ParticipantPayment();
1496 $ppDAO->participant_id
= $participants[$num]->id
;
1497 $ppDAO->contribution_id
= $contributions[$num]->id
;
1501 // next create the transaction record
1502 $transaction = new CRM_Core_Transaction();
1505 if ($this->_quickConfig
) {
1506 if (!empty($this->_params
['amount_priceset_level_radio'])) {
1507 $feeLevel = $this->_params
['amount_priceset_level_radio'];
1510 $feeLevel[] = $this->_params
['fee_level'] ;
1512 CRM_Event_BAO_Participant
::createDiscountTrxn($this->_eventId
, $contributionParams, $feeLevel);
1514 $transaction->commit();
1518 // also store lineitem stuff here
1519 if ((($this->_lineItem
& $this->_action
& CRM_Core_Action
::ADD
) ||
1520 ($this->_lineItem
&& CRM_Core_Action
::UPDATE
&& !$this->_paymentId
))
1522 foreach ($this->_contactIds
as $num => $contactID) {
1523 foreach ($this->_lineItem
as $key => $value) {
1524 if (is_array($value) && $value != 'skip') {
1525 foreach ($value as $lineKey => $line) {
1526 //10117 update the line items for participants if contribution amount is recorded
1527 if ($this->_quickConfig
&& !empty($params['total_amount']) && $params['status_id'] != array_search('Partially paid', $participantStatus)
1529 $line['unit_price'] = $line['line_total'] = $params['total_amount'];
1531 $lineItem[$this->_priceSetId
][$lineKey] = $line;
1533 CRM_Price_BAO_LineItem
::processPriceSet($participants[$num]->id
, $lineItem, CRM_Utils_Array
::value($num, $contributions, NULL), 'civicrm_participant');
1539 $updateStatusMsg = NULL;
1540 //send mail when participant status changed, CRM-4326
1541 if ($this->_id
&& $this->_statusId
&&
1542 $this->_statusId
!= CRM_Utils_Array
::value('status_id', $params) && !empty($params['is_notify'])) {
1544 $updateStatusMsg = CRM_Event_BAO_Participant
::updateStatusMessage($this->_id
,
1545 $params['status_id'],
1552 if (!empty($params['send_receipt'])) {
1553 if (array_key_exists($params['from_email_address'], $this->_fromEmails
['from_email_id'])) {
1554 $receiptFrom = $params['from_email_address'];
1557 $this->assign('module', 'Event Registration');
1558 //use of the message template below requires variables in different format
1559 $event = $events = array();
1560 $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
1562 //get all event details.
1563 CRM_Core_DAO
::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
1564 $event = $events[$params['event_id']];
1565 unset($event['start_date']);
1566 unset($event['end_date']);
1568 $role = CRM_Event_PseudoConstant
::participantRole();
1569 $participantRoles = CRM_Utils_Array
::value('role_id', $params);
1570 if (is_array($participantRoles)) {
1571 $selectedRoles = array();
1572 foreach (array_keys($participantRoles) as $roleId) {
1573 $selectedRoles[] = $role[$roleId];
1575 $event['participant_role'] = implode(', ', $selectedRoles);
1578 $event['participant_role'] = CRM_Utils_Array
::value($participantRoles, $role);
1580 $event['is_monetary'] = $this->_isPaidEvent
;
1582 if ($params['receipt_text']) {
1583 $event['confirm_email_text'] = $params['receipt_text'];
1586 $this->assign('isAmountzero', 1);
1587 $this->assign('event', $event);
1589 $this->assign('isShowLocation', $event['is_show_location']);
1590 if (CRM_Utils_Array
::value('is_show_location', $event) == 1) {
1591 $locationParams = array(
1592 'entity_id' => $params['event_id'],
1593 'entity_table' => 'civicrm_event',
1595 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
1596 $this->assign('location', $location);
1599 $status = CRM_Event_PseudoConstant
::participantStatus();
1600 if ($this->_isPaidEvent
) {
1601 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
1602 if (!$this->_mode
) {
1603 if (isset($params['payment_instrument_id'])) {
1604 $this->assign('paidBy',
1605 CRM_Utils_Array
::value($params['payment_instrument_id'],
1612 $this->assign('totalAmount', $contributionParams['total_amount']);
1614 $this->assign('isPrimary', 1);
1615 $this->assign('checkNumber', CRM_Utils_Array
::value('check_number', $params));
1618 if (!empty($params['billing_first_name'])) {
1619 $name = $params['billing_first_name'];
1622 if (!empty($params['billing_middle_name'])) {
1623 $name .= " {$params['billing_middle_name']}";
1626 if (!empty($params['billing_last_name'])) {
1627 $name .= " {$params['billing_last_name']}";
1629 $this->assign('billingName', $name);
1631 // assign the address formatted up for display
1632 $addressParts = array(
1633 "street_address-{$this->_bltID}",
1634 "city-{$this->_bltID}",
1635 "postal_code-{$this->_bltID}",
1636 "state_province-{$this->_bltID}",
1637 "country-{$this->_bltID}",
1639 $addressFields = array();
1640 foreach ($addressParts as $part) {
1641 list($n, $id) = explode('-', $part);
1642 if (isset($this->_params
['billing_' . $part])) {
1643 $addressFields[$n] = $this->_params
['billing_' . $part];
1646 $this->assign('address', CRM_Utils_Address
::format($addressFields));
1648 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
1649 $date = CRM_Utils_Date
::mysqlToIso($date);
1650 $this->assign('credit_card_exp_date', $date);
1651 $this->assign('credit_card_number',
1652 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
1654 $this->assign('credit_card_type', $params['credit_card_type']);
1655 $this->assign('contributeMode', 'direct');
1656 $this->assign('isAmountzero', 0);
1657 $this->assign('is_pay_later', 0);
1658 $this->assign('isPrimary', 1);
1661 $this->assign('register_date', $params['register_date']);
1662 if ($params['receive_date']) {
1663 $this->assign('receive_date', $params['receive_date']);
1666 $participant = array(array('participant_id', '=', $participants[0]->id
, 0, 0));
1667 // check whether its a test drive ref CRM-3075
1668 if (!empty($this->_defaultValues
['is_test'])) {
1669 $participant[] = array('participant_test', '=', 1, 0, 0);
1672 $template = CRM_Core_Smarty
::singleton();
1673 $customGroup = array();
1674 //format submitted data
1675 foreach ($params['custom'] as $fieldID => $values) {
1676 foreach ($values as $fieldValue) {
1677 $customValue = array('data' => $fieldValue['value']);
1678 $customFields[$fieldID]['id'] = $fieldID;
1679 $formattedValue = CRM_Core_BAO_CustomGroup
::formatCustomValues($customValue, $customFields[$fieldID], TRUE);
1680 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace(' ', '', $formattedValue);
1684 foreach ($this->_contactIds
as $num => $contactID) {
1685 // Retrieve the name and email of the contact - this will be the TO for receipt email
1686 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($contactID);
1688 $this->_contributorDisplayName
= ($this->_contributorDisplayName
== ' ') ?
$this->_contributorEmail
: $this->_contributorDisplayName
;
1690 $waitStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
1691 if ($waitingStatus = CRM_Utils_Array
::value($params['status_id'], $waitStatus)) {
1692 $this->assign('isOnWaitlist', TRUE);
1695 $this->assign('customGroup', $customGroup);
1696 $this->assign('contactID', $contactID);
1697 $this->assign('participantID', $participants[$num]->id
);
1699 $this->_id
= $participants[$num]->id
;
1701 if ($this->_isPaidEvent
) {
1702 // fix amount for each of participants ( for bulk mode )
1703 $eventAmount = array();
1704 if (!empty($additionalParticipantDetails)) {
1705 $params['amount_level'] = preg_replace('/\ 1/', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName
;
1708 $eventAmount[$num] = array(
1709 'label' => preg_replace('/\ 1/', '', $params['amount_level']),
1710 'amount' => $params['fee_amount'],
1712 //as we are using same template for online & offline registration.
1713 //So we have to build amount as array.
1714 $eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
1715 $this->assign('amount', $eventAmount);
1718 $sendTemplateParams = array(
1719 'groupName' => 'msg_tpl_workflow_event',
1720 'valueName' => 'event_offline_receipt',
1721 'contactId' => $contactID,
1722 'isTest' => (bool) CRM_Utils_Array
::value('is_test', $this->_defaultValues
),
1723 'PDFFilename' => ts('confirmation').'.pdf',
1726 // try to send emails only if email id is present
1727 // and the do-not-email option is not checked for that contact
1728 if ($this->_contributorEmail
and !$this->_toDoNotEmail
) {
1729 $sendTemplateParams['from'] = $receiptFrom;
1730 $sendTemplateParams['toName'] = $this->_contributorDisplayName
;
1731 $sendTemplateParams['toEmail'] = $this->_contributorEmail
;
1732 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc', $this->_fromEmails
);
1733 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc', $this->_fromEmails
);
1736 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1738 $sent[] = $contactID;
1739 foreach ($participants as $ids => $values) {
1740 if ($values->contact_id
== $contactID) {
1741 CRM_Activity_BAO_Activity
::addActivity($values, 'Email');
1747 $notSent[] = $contactID;
1752 // set the participant id if it is not set
1754 $this->_id
= $participants[0]->id
;
1757 if (($this->_action
& CRM_Core_Action
::UPDATE
)) {
1758 $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contributorDisplayName
));
1759 if (!empty($params['send_receipt']) && count($sent)) {
1760 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', array(1 => $this->_contributorEmail
));
1763 if ($updateStatusMsg) {
1764 $statusMsg = "{$statusMsg} {$updateStatusMsg}";
1767 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
1768 if ($this->_single
) {
1769 $statusMsg = ts('Event registration for %1 has been added.', array(1 => $this->_contributorDisplayName
));
1770 if (!empty($params['send_receipt']) && count($sent)) {
1771 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $this->_contributorEmail
));
1775 $statusMsg = ts('Total Participant(s) added to event: %1.', array(1 => count($this->_contactIds
)));
1776 if (count($notSent) > 0) {
1777 $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)));
1779 elseif (isset($params['send_receipt'])) {
1780 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');
1784 CRM_Core_Session
::setStatus($statusMsg, ts('Saved'), 'success');
1786 $buttonName = $this->controller
->getButtonName();
1787 if ($this->_context
== 'standalone') {
1788 if ($buttonName == $this->getButtonName('upload', 'new')) {
1789 $urlParams = 'reset=1&action=add&context=standalone';
1791 $urlParams .= '&mode=' . $this->_mode
;
1794 $urlParams .= '&eid=' . $this->_eID
;
1796 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/participant/add', $urlParams));
1799 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
1800 "reset=1&cid={$this->_contactId}&selectedChild=participant"
1804 elseif ($buttonName == $this->getButtonName('upload', 'new')) {
1805 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view/participant',
1806 "reset=1&action=add&context={$this->_context}&cid={$this->_contactId}"