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);
231 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
234 $this->assign('participantId', $this->_id
);
235 $statusId = CRM_Core_DAO
::getFieldValue('CRM_Event_BAO_Participant', $this->_id
, 'status_id', 'id');
237 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
238 $this->_id
, 'id', 'participant_id'
240 // CRM-12615 - Get payment information from the primary registration
241 if ((!$this->_paymentId
) && ($this->_action
== CRM_Core_Action
::UPDATE
)) {
242 $registered_by_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
243 $this->_id
, 'registered_by_id', 'id'
245 if ($registered_by_id) {
246 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
247 $registered_by_id, 'id', 'participant_id'
249 $this->assign('registeredByParticipantId', $registered_by_id);
254 // get the option value for custom data type
255 $this->_roleCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantRole', 'name');
256 $this->_eventNameCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantEventName', 'name');
257 $this->_eventTypeCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantEventType', 'name');
258 $this->assign('roleCustomDataTypeID', $this->_roleCustomDataTypeID
);
259 $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID
);
260 $this->assign('eventTypeCustomDataTypeID', $this->_eventTypeCustomDataTypeID
);
262 $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses);
263 $this->assign('partiallyPaidStatusId', $partiallyPaidStatusId);
266 $this->assign('participantMode', $this->_mode
);
268 $this->_paymentProcessor
= array('billing_mode' => 1);
270 $validProcessors = array();
271 $processors = CRM_Core_PseudoConstant
::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )");
273 foreach ($processors as $ppID => $label) {
274 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getPayment($ppID, $this->_mode
);
275 if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) {
278 elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode
== 'live') {
282 $paymentObject = CRM_Core_Payment
::singleton($this->_mode
, $paymentProcessor, $this);
283 $error = $paymentObject->checkConfig();
285 $validProcessors[$ppID] = $label;
287 $paymentObject = NULL;
290 if (empty($validProcessors)) {
291 CRM_Core_Error
::fatal(ts('Could not find valid payment processor for this page'));
294 $this->_processors
= $validProcessors;
296 // also check for billing information
297 // get the billing location type
298 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
299 // CRM-8108 remove ts around Billing location type
300 //$this->_bltID = array_search( ts('Billing'), $locationTypes );
301 $this->_bltID
= array_search('Billing', $locationTypes);
302 if (!$this->_bltID
) {
303 CRM_Core_Error
::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
305 $this->set('bltID', $this->_bltID
);
306 $this->assign('bltID', $this->_bltID
);
308 $this->_fields
= array();
310 CRM_Core_Payment_Form
::setCreditCardFields($this);
312 // this required to show billing block
313 $this->assign_by_ref('paymentProcessor', $paymentProcessor);
314 $this->assign('hidePayPalExpress', TRUE);
317 if ($this->_showFeeBlock
) {
318 $this->assign('showFeeBlock', TRUE);
319 $isMonetary = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_showFeeBlock
, 'is_monetary');
321 $this->assign('feeBlockPaid', TRUE);
323 return CRM_Event_Form_EventFees
::preProcess($this);
326 //custom data related code
327 $this->_cdType
= CRM_Utils_Array
::value('type', $_GET);
328 $this->assign('cdType', FALSE);
329 if ($this->_cdType
) {
330 $this->assign('cdType', TRUE);
331 return CRM_Custom_Form_CustomData
::preProcess($this, NULL, NULL, NULL, NULL, NULL, TRUE);
334 //check the mode when this form is called either single or as
336 if ($this->_id ||
$this->_contactId ||
$this->_context
== 'standalone') {
337 $this->_single
= TRUE;
338 $this->assign('urlPath', 'civicrm/contact/view/participant');
339 if (!$this->_id
&& !$this->_contactId
) {
340 $breadCrumbs = array(array('title' => ts('CiviEvent Dashboard'),
341 'url' => CRM_Utils_System
::url('civicrm/event', 'reset=1'),
344 CRM_Utils_System
::appendBreadCrumb($breadCrumbs);
348 //set the appropriate action
349 $context = $this->get('context');
350 $urlString = 'civicrm/contact/search';
351 $this->_action
= CRM_Core_Action
::BASIC
;
354 $urlString = 'civicrm/contact/search/advanced';
355 $this->_action
= CRM_Core_Action
::ADVANCED
;
359 $urlString = 'civicrm/contact/search/builder';
360 $this->_action
= CRM_Core_Action
::PROFILE
;
364 $urlString = 'civicrm/contact/search/basic';
365 $this->_action
= CRM_Core_Action
::BASIC
;
369 $urlString = 'civicrm/contact/search/custom';
370 $this->_action
= CRM_Core_Action
::COPY
;
373 parent
::preProcess();
375 $this->_single
= FALSE;
376 $this->_contactId
= NULL;
378 //set ajax path, this used for custom data building
379 $this->assign('urlPath', $urlString);
380 $this->assign('urlPathVar', "_qf_Participant_display=true&qfKey={$this->controller->_key}");
383 $this->assign('single', $this->_single
);
386 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
388 $this->assign('action', $this->_action
);
390 // check for edit permission
391 if (!CRM_Core_Permission
::checkActionPermission('CiviEvent', $this->_action
)) {
392 CRM_Core_Error
::fatal(ts('You do not have permission to access this page'));
395 if ($this->_action
& CRM_Core_Action
::DELETE
) {
396 // check delete permission for contribution
397 if ($this->_id
&& $this->_paymentId
&& !CRM_Core_Permission
::checkActionPermission('CiviContribute', $this->_action
)) {
398 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."));
404 // assign participant id to the template
405 $this->assign('participantId', $this->_id
);
406 $this->_roleId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'role_id');
409 // when fee amount is included in form
410 if (CRM_Utils_Array
::value('hidden_feeblock', $_POST)
411 || CRM_Utils_Array
::value('send_receipt', $_POST)
413 CRM_Event_Form_EventFees
::preProcess($this);
414 CRM_Event_Form_EventFees
::buildQuickForm($this);
415 CRM_Event_Form_EventFees
::setDefaultValues($this);
418 // when custom data is included in this page
419 if (CRM_Utils_Array
::value('hidden_custom', $_POST)) {
420 //custom data of type participant role
421 if (CRM_Utils_Array
::value('role_id', $_POST)) {
422 foreach ($_POST['role_id'] as $k => $val) {
424 CRM_Custom_Form_CustomData
::preProcess($this, $this->_roleCustomDataTypeID
, $k, 1, 'Participant', $this->_id
);
425 CRM_Custom_Form_CustomData
::buildQuickForm($this);
426 CRM_Custom_Form_CustomData
::setDefaultValues($this);
430 //custom data of type participant event
431 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventNameCustomDataTypeID
, $_POST['event_id'], 1, 'Participant', $this->_id
);
432 CRM_Custom_Form_CustomData
::buildQuickForm($this);
433 CRM_Custom_Form_CustomData
::setDefaultValues($this);
435 // custom data of type participant event type
437 if ($eventId = CRM_Utils_Array
::value('event_id', $_POST)) {
438 $eventTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'event_type_id', 'id');
440 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventTypeCustomDataTypeID
, $eventTypeId,
441 1, 'Participant', $this->_id
443 CRM_Custom_Form_CustomData
::buildQuickForm($this);
444 CRM_Custom_Form_CustomData
::setDefaultValues($this);
446 //custom data of type participant, ( we 'null' to reset subType and subName)
447 CRM_Custom_Form_CustomData
::preProcess($this, 'null', 'null', 1, 'Participant', $this->_id
);
448 CRM_Custom_Form_CustomData
::buildQuickForm($this);
449 CRM_Custom_Form_CustomData
::setDefaultValues($this);
452 // CRM-4395, get the online pending contribution id.
453 $this->_onlinePendingContributionId
= NULL;
454 if (!$this->_mode
&& $this->_id
&& ($this->_action
& CRM_Core_Action
::UPDATE
)) {
455 $this->_onlinePendingContributionId
= CRM_Contribute_BAO_Contribution
::checkOnlinePendingContribution($this->_id
,
459 $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId
);
460 $roleIds = CRM_Event_PseudoConstant
::participantRole();
462 if (!empty($roleIds)) {
464 SELECT civicrm_custom_group.name as name,
465 civicrm_custom_group.id as id,
466 extends_entity_column_value as value
467 FROM civicrm_custom_group
468 WHERE ( extends_entity_column_value REGEXP '[[:<:]]" . implode('[[:>:]]|[[:<:]]', array_keys($roleIds)) . "[[:>:]]'
469 OR extends_entity_column_value IS NULL )
470 AND extends_entity_column_id = '{$this->_roleCustomDataTypeID}'
471 AND extends = 'Participant'
474 $dao = CRM_Core_DAO
::executeQuery($query);
475 while ($dao->fetch()) {
477 $getRole = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $dao->value
);
478 foreach ($getRole as $r) {
482 if (isset($this->_participantRoleIds
[$r])) {
483 $this->_participantRoleIds
[$r] .= ',' . $dao->name
;
486 $this->_participantRoleIds
[$r] = $dao->name
;
491 if (isset($this->_participantRoleIds
[0])) {
492 $this->_participantRoleIds
[0] .= ',' . $dao->name
;
495 $this->_participantRoleIds
[0] = $dao->name
;
501 foreach ($roleIds as $k => $v) {
502 if (!isset($this->_participantRoleIds
[$k])) {
503 $this->_participantRoleIds
[$k] = '';
506 $this->assign('participantRoleIds', $this->_participantRoleIds
);
510 * This function sets the default values for the form in edit/view mode
511 * the default values are retrieved from the database
517 public function setDefaultValues() {
518 if ($this->_showFeeBlock
) {
519 return CRM_Event_Form_EventFees
::setDefaultValues($this);
522 if ($this->_cdType
) {
523 return CRM_Custom_Form_CustomData
::setDefaultValues($this);
528 if ($this->_action
& CRM_Core_Action
::DELETE
) {
534 $params = array('id' => $this->_id
);
536 CRM_Event_BAO_Participant
::getValues($params, $defaults, $ids);
537 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
538 if ($defaults[$this->_id
]['role_id']) {
539 foreach (explode($sep, $defaults[$this->_id
]['role_id']) as $k => $v) {
540 $defaults[$this->_id
]["role_id[{$v}]"] = 1;
542 unset($defaults[$this->_id
]['role_id']);
544 $this->_contactId
= $defaults[$this->_id
]['contact_id'];
545 $this->_statusId
= $defaults[$this->_id
]['participant_status_id'];
547 //set defaults for note
548 $noteDetails = CRM_Core_BAO_Note
::getNote($this->_id
, 'civicrm_participant');
549 $defaults[$this->_id
]['note'] = array_pop($noteDetails);
551 // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859)
552 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
553 $this->assign('additionalParticipants', CRM_Event_BAO_Participant
::getAdditionalParticipants($this->_id
));
556 // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
557 if (CRM_Utils_Array
::value('participant_registered_by_id', $defaults[$this->_id
])) {
558 $registered_by_contact_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
559 $defaults[$this->_id
]['participant_registered_by_id'],
562 $this->assign('participant_registered_by_id', $defaults[$this->_id
]['participant_registered_by_id']);
563 $this->assign('registered_by_contact_id', $registered_by_contact_id);
564 $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact
::displayName($registered_by_contact_id));
568 if ($this->_action
& (CRM_Core_Action
::VIEW | CRM_Core_Action
::BROWSE
)) {
569 $inactiveNeeded = TRUE;
574 $inactiveNeeded = FALSE;
577 //setting default register date
578 if ($this->_action
== CRM_Core_Action
::ADD
) {
579 $statuses = array_flip($this->_participantStatuses
);
580 $defaults[$this->_id
]['status_id'] = CRM_Utils_Array
::value(ts('Registered'), $statuses);
581 if (CRM_Utils_Array
::value('event_id', $defaults[$this->_id
])) {
582 $contributionTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
583 $defaults[$this->_id
]['event_id'],
586 if ($contributionTypeId) {
587 $defaults[$this->_id
]['financial_type_id'] = $contributionTypeId;
592 $fields["email-{$this->_bltID}"] = 1;
593 $fields['email-Primary'] = 1;
595 if ($this->_contactId
) {
596 CRM_Core_BAO_UFGroup
::setProfileDefaults($this->_contactId
, $fields, $defaults);
599 if (empty($defaults["email-{$this->_bltID}"]) &&
600 !empty($defaults['email-Primary'])
602 $defaults[$this->_id
]["email-{$this->_bltID}"] = $defaults['email-Primary'];
606 $submittedRole = $this->getElementValue('role_id');
607 if (CRM_Utils_Array
::value(0, $submittedRole)) {
608 $roleID = $submittedRole[0];
610 $submittedEvent = $this->getElementValue('event_id');
611 if ($submittedEvent[0]) {
612 $eventID = $submittedEvent[0];
616 $defaults[$this->_id
]['record_contribution'] = 0;
618 if ($defaults[$this->_id
]['participant_is_pay_later']) {
619 $this->assign('participant_is_pay_later', TRUE);
622 $this->assign('participant_status_id', $defaults[$this->_id
]['participant_status_id']);
623 $roleID = $defaults[$this->_id
]['participant_role_id'];
624 $eventID = $defaults[$this->_id
]['event_id'];
626 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
628 $this->_discountId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'discount_id');
629 if ($this->_discountId
) {
630 $this->set('discountId', $this->_discountId
);
634 list($defaults[$this->_id
]['register_date'],
635 $defaults[$this->_id
]['register_date_time']
636 ) = CRM_Utils_Date
::setDateDefaults(
637 CRM_Utils_Array
::value('register_date', $defaults[$this->_id
]), 'activityDateTime'
640 //assign event and role id, this is needed for Custom data building
641 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
642 if (CRM_Utils_Array
::value('participant_role_id', $defaults[$this->_id
])) {
643 $roleIDs = explode($sep, $defaults[$this->_id
]['participant_role_id']);
645 if (isset($roleIDs)) {
646 $this->assign('roleID', $roleIDs);
648 if (isset($_POST['event_id'])) {
649 $eventID = $_POST['event_id'];
651 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
655 if (isset($eventID)) {
656 $this->assign('eventID', $eventID);
657 $this->set('eventId', $eventID);
660 if (isset($this->_eventTypeId
)) {
661 $this->assign('eventTypeID', $this->_eventTypeId
);
664 $this->assign('event_is_test', CRM_Utils_Array
::value('event_is_test', $defaults[$this->_id
]));
665 return $defaults[$this->_id
];
669 * Function to build the form
674 public function buildQuickForm() {
675 CRM_Core_Resources
::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
676 if ($this->_showFeeBlock
) {
677 return CRM_Event_Form_EventFees
::buildQuickForm($this);
680 if ($this->_cdType
) {
681 return CRM_Custom_Form_CustomData
::buildQuickForm($this);
684 //need to assign custom data type to the template
685 $this->assign('customDataType', 'Participant');
687 $this->applyFilter('__ALL__', 'trim');
689 if ($this->_action
& CRM_Core_Action
::DELETE
) {
690 if ($this->_single
) {
691 $additionalParticipant = count(CRM_Event_BAO_Event
::buildCustomProfile($this->_id
,
697 if ($additionalParticipant) {
698 $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'),
699 2 => ts('Delete only this participant record.'),
701 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
702 $this->setDefaults(array('delete_participant' => 1));
703 $this->assign('additionalParticipant', $additionalParticipant);
706 $this->addButtons(array(
709 'name' => ts('Delete'),
710 'spacing' => ' ',
715 'name' => ts('Cancel'),
723 if ($this->_single
) {
724 $urlPath = 'civicrm/contact/view/participant';
725 $urlParams = "reset=1&cid={$this->_contactId}&context=participant";
726 if ($this->_context
== 'standalone') {
727 CRM_Contact_Form_NewContact
::buildQuickForm($this);
728 $urlParams = 'reset=1&context=standalone';
729 $urlPath = 'civicrm/participant/add';
733 $urlParams .= "&action=update&id={$this->_id}";
736 $urlParams .= "&action=add";
740 $urlParams .= "&mode={$this->_mode}";
743 $url = CRM_Utils_System
::url($urlPath, $urlParams,
748 $currentPath = CRM_Utils_System
::currentPath();
750 $url = CRM_Utils_System
::url($currentPath, '_qf_Participant_display=true',
755 $this->assign('refreshURL', $url);
757 $this->add('hidden', 'past_event');
761 $eventEndDate = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_eID
,'end_date');
763 $this->assign('past', 0);
764 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
765 $events = CRM_Event_BAO_Event
::getEvents(1, FALSE, FALSE);
767 elseif ($this->getElementValue('past_event') ||
(isset($eventEndDate) && (CRM_Utils_Date
::currentDBDate() > CRM_Utils_Date
::processDate($eventEndDate)))) {
768 $pastval = $this->getElementValue('past_event');
769 $events = CRM_Event_BAO_Event
::getEvents($pastval);
770 $this->assign('past', $pastval);
773 $events = CRM_Event_BAO_Event
::getEvents();
777 //unset the event which are not monetary when credit card
778 //event registration is used
779 foreach ($events as $key => $val) {
780 $isPaid = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $key, 'is_monetary');
782 unset($events[$key]);
785 $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors
, TRUE);
788 // build array(event -> eventType) mapper
790 SELECT civicrm_event.id as id, civicrm_event.event_type_id as event_type_id
792 WHERE civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0";
793 $dao = CRM_Core_DAO
::executeQuery($query);
794 $eventAndTypeMapping = array();
795 while ($dao->fetch()) {
796 $eventAndTypeMapping[$dao->id
] = $dao->event_type_id
;
798 $eventAndTypeMapping = json_encode($eventAndTypeMapping);
799 // building of mapping ends --
801 //inherit the campaign from event.
802 $eventCampaigns = array();
803 $allEventIds = array_keys($events);
804 if (!empty($allEventIds)) {
805 CRM_Core_PseudoConstant
::populate($eventCampaigns,
806 'CRM_Event_DAO_Event',
810 $eventCampaigns = json_encode($eventCampaigns);
812 $element = $this->add('select', 'event_id', ts('Event'),
814 '' => ts('- select -')) +
$events,
816 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')
820 // note that embedding JS within PHP files is quite awful, IMO
821 // but we do the same for the onChange element and this form is complex
822 // and i did not want to break it late in the 3.2 cycle
823 $preloadJSSnippet = NULL;
824 if (CRM_Utils_Array
::value('reset', $_GET) && $this->_eID
) {
825 $preloadJSSnippet = "
827 cj('#event_id').val( '{$this->_eID}' );
828 buildFeeBlock( {$this->_eID} );
829 CRM.buildCustomData( 'Participant', {$this->_eID}, {$this->_eventNameCustomDataTypeID} );
830 buildEventTypeCustomData( {$this->_eID}, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' );
831 loadCampaign( {$this->_eID}, {$eventCampaigns} );
836 $this->assign('preloadJSSnippet', $preloadJSSnippet);
839 //frozen the field fix for CRM-4171
840 if ($this->_action
& CRM_Core_Action
::UPDATE
&& $this->_id
) {
841 if (CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
842 $this->_id
, 'contribution_id', 'participant_id'
848 //CRM-7362 --add campaigns.
851 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'campaign_id');
854 $eventId = CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
856 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
859 CRM_Campaign_BAO_Campaign
::addCampaign($this, $campaignId);
861 $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
864 $this->assign('entityID', $this->_id
);
867 $roleids = CRM_Event_PseudoConstant
::participantRole();
869 foreach ($roleids as $rolekey => $rolevalue) {
870 $roleTypes[] = $this->createElement('checkbox', $rolekey, NULL, $rolevalue,
871 array('onclick' => "showCustomData( 'Participant', {$rolekey}, {$this->_roleCustomDataTypeID} );")
875 $this->addGroup($roleTypes, 'role_id', ts('Participant Role'));
876 $this->addRule('role_id', ts('Role is required'), 'required');
879 $checkCancelledJs = array('onchange' => "return sendNotification( );");
881 if ($this->_onlinePendingContributionId
) {
882 $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant
::participantStatus());
883 $cancelledContributionStatusId = array_search('Cancelled',
884 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
886 $checkCancelledJs = array(
888 "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});",
891 $participantStatusId = array_search('Pending from pay later',
892 CRM_Event_PseudoConstant
::participantStatus()
894 $contributionStatusId = array_search('Completed',
895 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
897 $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
900 // get the participant status names to build special status array which is used to show notification
901 // checkbox below participant status select
902 $participantStatusName = CRM_Event_PseudoConstant
::participantStatus();
903 $notificationStatuses = array(
905 'Pending from waitlist',
906 'Pending from approval',
910 // get the required status and then implode only ids
911 $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
912 $this->assign('notificationStatusIds', $notificationStatusIds);
914 $this->_participantStatuses
= CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label');
915 $this->add('select', 'status_id', ts('Participant Status'),
917 '' => ts('- select -')) +
$this->_participantStatuses
,
922 $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
924 $this->add('text', 'source', ts('Event Source'));
925 $noteAttributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Note');
926 $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
930 'name' => ts('Save'),
935 $path = CRM_Utils_System
::currentPath();
936 $excludeForPaths = array(
937 'civicrm/contact/search',
938 'civicrm/group/search'
940 if (!in_array($path, $excludeForPaths)) {
943 'name' => ts('Save and New'),
951 'name' => ts('Cancel'),
954 $this->addButtons($buttons);
955 if ($this->_action
== CRM_Core_Action
::VIEW
) {
961 * Add local and global form rules
967 function addRules() {
968 $this->addFormRule(array('CRM_Event_Form_Participant', 'formRule'), $this);
972 * global validation rules for the form
974 * @param array $fields posted values of the form
976 * @return array list of errors to be posted back to the form
980 static function formRule($values, $files, $self) {
981 // If $values['_qf_Participant_next'] is Delete or
982 // $values['event_id'] is empty, then return
983 // instead of proceeding further.
985 if ((CRM_Utils_Array
::value('_qf_Participant_next', $values) == 'Delete') ||
986 (!$values['event_id'])
992 //check if contact is selected in standalone mode
993 if (isset($values['contact_select_id'][1]) && !$values['contact_select_id'][1]) {
994 $errorMsg['contact[1]'] = ts('Please select a contact or create new contact');
997 if (CRM_Utils_Array
::value('payment_processor_id', $values)) {
998 // make sure that credit card number and cvv are valid
999 CRM_Core_Payment_Form
::validateCreditCard($values, $errorMsg);
1002 if (CRM_Utils_Array
::value('record_contribution', $values)) {
1003 if (!CRM_Utils_Array
::value('financial_type_id', $values)) {
1004 $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
1006 if (!CRM_Utils_Array
::value('payment_instrument_id', $values)) {
1007 $errorMsg['payment_instrument_id'] = ts('Paid By is a required field.');
1011 // validate contribution status for 'Failed'.
1012 if ($self->_onlinePendingContributionId
&&
1013 CRM_Utils_Array
::value('record_contribution', $values) &&
1014 (CRM_Utils_Array
::value('contribution_status_id', $values) ==
1015 array_search('Failed', CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name'))
1018 $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.');
1021 // do the amount validations.
1022 //skip for update mode since amount is freeze, CRM-6052
1024 !CRM_Utils_Array
::value('total_amount', $values) &&
1025 empty($self->_values
['line_items'])
1027 ($self->_id
&& !$self->_paymentId
&& isset($self->_values
['line_items']) && is_array($self->_values
['line_items']))
1029 if ($priceSetId = CRM_Utils_Array
::value('priceSetId', $values)) {
1030 CRM_Price_BAO_PriceField
::priceSetValidation($priceSetId, $values, $errorMsg, TRUE);
1033 return CRM_Utils_Array
::crmIsEmptyArray($errorMsg) ?
TRUE : $errorMsg;
1037 * Function to process the form
1041 public function postProcess() {
1042 // get the submitted form values.
1043 $params = $this->controller
->exportValues($this->_name
);
1045 if ($this->_action
& CRM_Core_Action
::DELETE
) {
1046 if (CRM_Utils_Array
::value('delete_participant', $params) == 2) {
1047 $additionalId = (CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
));
1048 $participantLinks = (CRM_Event_BAO_Participant
::getAdditionalParticipantUrl($additionalId));
1050 if (CRM_Utils_Array
::value('delete_participant', $params) == 1) {
1051 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
1052 foreach ($additionalIds as $value) {
1053 CRM_Event_BAO_Participant
::deleteParticipant($value);
1056 CRM_Event_BAO_Participant
::deleteParticipant($this->_id
);
1057 CRM_Core_Session
::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success');
1058 if (!empty($participantLinks)) {
1059 $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;
1060 CRM_Core_Session
::setStatus($status, ts('Group Payment Deleted'));
1065 $participantStatus = CRM_Event_PseudoConstant
::participantStatus();
1066 // set the contact, when contact is selected
1067 if (CRM_Utils_Array
::value('contact_select_id', $params)) {
1068 $this->_contactId
= $params['contact_select_id'][1];
1070 if ($this->_priceSetId
&& $isQuickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
1071 $this->_quickConfig
= $isQuickConfig;
1075 $params['id'] = $this->_id
;
1078 $config = CRM_Core_Config
::singleton();
1079 if ($this->_isPaidEvent
) {
1081 $contributionParams = array();
1082 $lineItem = array();
1083 $additionalParticipantDetails = array();
1084 if (($this->_id
&& $this->_action
& CRM_Core_Action
::UPDATE
) && $this->_paymentId
) {
1085 $participantBAO = new CRM_Event_BAO_Participant();
1086 $participantBAO->id
= $this->_id
;
1087 $participantBAO->find(TRUE);
1088 $contributionParams['total_amount'] = $participantBAO->fee_amount
;
1090 $params['discount_id'] = NULL;
1091 //re-enter the values for UPDATE mode
1092 $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level
;
1093 $params['fee_amount'] = $participantBAO->fee_amount
;
1094 if (isset($params['priceSetId'])) {
1095 $lineItem[0] = CRM_Price_BAO_LineItem
::getLineItems($this->_id
);
1097 //also add additional participant's fee level/priceset
1098 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
1099 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
1100 $hasLineItems = CRM_Utils_Array
::value('priceSetId', $params, FALSE);
1101 $additionalParticipantDetails = CRM_Event_BAO_Participant
::getFeeDetails($additionalIds,
1108 //check if discount is selected
1109 if (CRM_Utils_Array
::value('discount_id', $params)) {
1110 $discountId = $params['discount_id'];
1113 $discountId = $params['discount_id'] = 'null';
1116 //lets carry currency, CRM-4453
1117 $params['fee_currency'] = $config->defaultCurrency
;
1118 CRM_Price_BAO_PriceSet
::processAmount($this->_values
['fee'],
1119 $params, $lineItem[0]
1121 //CRM-11529 for quick config backoffice transactions
1122 //when financial_type_id is passed in form, update the
1123 //lineitems with the financial type selected in form
1124 $submittedFinancialType = CRM_Utils_Array
::value('financial_type_id', $params);
1125 $isPaymentRecorded = CRM_Utils_Array
::value('record_contribution', $params);
1126 if ($isPaymentRecorded && $this->_quickConfig
&& $submittedFinancialType) {
1127 foreach ($lineItem[0] as &$values) {
1128 $values['financial_type_id'] = $submittedFinancialType;
1132 $params['fee_level'] = $params['amount_level'];
1133 $contributionParams['total_amount'] = $params['amount'];
1134 if ($this->_quickConfig
&& CRM_Utils_Array
::value('total_amount', $params)
1135 && $params['status_id'] != array_search('Partially paid', $participantStatus)) {
1136 $params['fee_amount'] = $params['total_amount'];
1139 $params['fee_amount'] = $params['amount'];
1143 if (isset($params['priceSetId'])) {
1144 if (!empty($lineItem[0])) {
1145 $this->set('lineItem', $lineItem);
1147 $this->_lineItem
= $lineItem;
1148 $lineItem = array_merge($lineItem, $additionalParticipantDetails);
1150 $participantCount = array();
1151 foreach ($lineItem as $k) {
1152 foreach ($k as $v) {
1153 if (CRM_Utils_Array
::value('participant_count', $v) > 0) {
1154 $participantCount[] = $v['participant_count'];
1159 if (isset($participantCount)) {
1160 $this->assign('pricesetFieldsCount', $participantCount);
1162 $this->assign('lineItem', empty($lineItem[0]) ||
$this->_quickConfig?
FALSE : $lineItem);
1165 $this->assign('amount_level', $params['amount_level']);
1169 $this->_params
= $params;
1171 if (isset($params['amount'])) {
1172 $amountOwed = $params['amount'];
1173 unset($params['amount']);
1175 $params['register_date'] = CRM_Utils_Date
::processDate($params['register_date'], $params['register_date_time']);
1176 $params['receive_date'] = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('receive_date', $params));
1177 $params['contact_id'] = $this->_contactId
;
1179 // overwrite actual payment amount if entered
1180 if (CRM_Utils_Array
::value('total_amount', $params)) {
1181 $contributionParams['total_amount'] = CRM_Utils_Array
::value('total_amount', $params);
1185 // Retrieve the name and email of the current user - this will be the FROM for the receipt email
1186 $session = CRM_Core_Session
::singleton();
1187 $userID = $session->get('userID');
1190 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($userID);
1192 if ($this->_contactId
) {
1193 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($this->_contactId
);
1197 if (!$this->_isPaidEvent
) {
1198 CRM_Core_Error
::fatal(ts('Selected Event is not Paid Event '));
1200 //modify params according to parameter used in create
1201 //participant method (addParticipant)
1202 $this->_params
['participant_status_id'] = $params['status_id'];
1203 $this->_params
['participant_role_id'] = $params['role_id'];
1204 $this->_params
['participant_register_date'] = $params['register_date'];
1207 CRM_Core_DAO
::getFieldValue(
1208 'CRM_Event_DAO_Event',
1209 $params['event_id'],
1213 // set source if not set
1214 if (empty($params['source'])) {
1215 $this->_params
['participant_source'] = ts('Offline Registration for Event: %2 by: %1', array(1 => $userName, 2 => $eventTitle));
1218 $this->_params
['participant_source'] = $params['source'];
1220 $this->_params
['description'] = $this->_params
['participant_source'];
1222 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($this->_params
['payment_processor_id'],
1225 $now = date('YmdHis');
1228 // set email for primary location.
1229 $fields['email-Primary'] = 1;
1230 $params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail
;
1232 $params['register_date'] = $now;
1234 // now set the values for the billing location.
1235 foreach ($this->_fields
as $name => $dontCare) {
1239 // also add location name to the array
1240 $params["address_name-{$this->_bltID}"] =
1241 CRM_Utils_Array
::value('billing_first_name', $params) . ' ' .
1242 CRM_Utils_Array
::value('billing_middle_name', $params) . ' ' .
1243 CRM_Utils_Array
::value('billing_last_name', $params);
1245 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
1246 $fields["address_name-{$this->_bltID}"] = 1;
1247 $fields["email-{$this->_bltID}"] = 1;
1248 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'contact_type');
1250 $nameFields = array('first_name', 'middle_name', 'last_name');
1252 foreach ($nameFields as $name) {
1254 if (array_key_exists("billing_$name", $params)) {
1255 $params[$name] = $params["billing_{$name}"];
1256 $params['preserveDBName'] = TRUE;
1259 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params, $fields, $this->_contactId
, NULL, NULL, $ctype);
1262 $roleAllIds = CRM_Utils_Array
::value('role_id', $params);
1264 foreach ($roleAllIds as $rkey => $rvalue) {
1265 $customFieldsRole = CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, $rkey, $this->_roleCustomDataTypeID
);
1266 $customFieldsEvent = CRM_Core_BAO_CustomField
::getFields('Participant',
1269 CRM_Utils_Array
::value('event_id', $params),
1270 $this->_eventNameCustomDataTypeID
1272 $customFieldsEventType = CRM_Core_BAO_CustomField
::getFields('Participant',
1275 $this->_eventTypeId
,
1276 $this->_eventTypeCustomDataTypeID
1278 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsRole,
1279 CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE)
1281 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEvent, $customFields);
1282 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEventType, $customFields);
1283 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
1291 //do cleanup line items if participant edit the Event Fee.
1292 if (($this->_lineItem ||
!isset($params['proceSetId'])) && !$this->_paymentId
&& $this->_id
) {
1293 CRM_Price_BAO_LineItem
::deleteLineItems($this->_id
, 'civicrm_participant');
1297 // add all the additioanl payment params we need
1298 $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}"]);
1299 $this->_params
["country-{$this->_bltID}"] = $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
1301 $this->_params
['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($this->_params
);
1302 $this->_params
['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($this->_params
);
1303 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
1304 $this->_params
['amount'] = $params['fee_amount'];
1305 $this->_params
['amount_level'] = $params['amount_level'];
1306 $this->_params
['currencyID'] = $config->defaultCurrency
;
1307 $this->_params
['payment_action'] = 'Sale';
1308 $this->_params
['invoiceID'] = md5(uniqid(rand(), TRUE));
1310 // at this point we've created a contact and stored its address etc
1311 // all the payment processors expect the name and address to be in the
1312 // so we copy stuff over to first_name etc.
1313 $paymentParams = $this->_params
;
1314 if (CRM_Utils_Array
::value('send_receipt', $this->_params
)) {
1315 $paymentParams['email'] = $this->_contributorEmail
;
1317 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $this->_params
, $paymentParams, TRUE);
1319 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
1321 $result = &$payment->doDirectPayment($paymentParams);
1323 if (is_a($result, 'CRM_Core_Error')) {
1324 CRM_Core_Error
::displaySessionError($result);
1325 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/view/participant',
1326 "reset=1&action=add&cid={$this->_contactId}&context=participant&mode={$this->_mode}"
1331 $this->_params
= array_merge($this->_params
, $result);
1334 $this->_params
['receive_date'] = $now;
1336 if (CRM_Utils_Array
::value('send_receipt', $this->_params
)) {
1337 $this->_params
['receipt_date'] = $now;
1340 $this->_params
['receipt_date'] = NULL;
1343 $this->set('params', $this->_params
);
1344 $this->assign('trxn_id', $result['trxn_id']);
1345 $this->assign('receive_date',
1346 CRM_Utils_Date
::processDate($this->_params
['receive_date'])
1349 //add contribution record
1350 $this->_params
['financial_type_id'] =
1351 CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
1352 $this->_params
['mode'] = $this->_mode
;
1354 //add contribution reocord
1355 $contributions[] = $contribution = CRM_Event_Form_Registration_Confirm
::processContribution($this, $this->_params
, $result, $contactID, FALSE);
1357 // add participant record
1358 $participants = array();
1359 if (CRM_Utils_Array
::value('participant_role_id', $this->_params
) && is_array($this->_params
['participant_role_id'])) {
1360 $this->_params
['participant_role_id'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1361 array_keys($this->_params
['participant_role_id'])
1364 $participants[] = CRM_Event_Form_Registration
::addParticipant($this->_params
, $contactID);
1366 //add custom data for participant
1367 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
1368 CRM_Core_DAO
::$_nullArray,
1369 'civicrm_participant',
1370 $participants[0]->id
,
1373 //add participant payment
1374 $paymentParticipant = array(
1375 'participant_id' => $participants[0]->id
,
1376 'contribution_id' => $contribution->id
,
1380 CRM_Event_BAO_ParticipantPayment
::create($paymentParticipant, $ids);
1381 $this->_contactIds
[] = $this->_contactId
;
1384 $participants = array();
1385 if ($this->_single
) {
1386 if ($params['role_id']) {
1387 foreach ($params['role_id'] as $k => $v) {
1390 $seperator = CRM_Core_DAO
::VALUE_SEPARATOR
;
1391 $params['role_id'] = implode($seperator, $rolesIDS);
1394 $params['role_id'] = 'NULL';
1396 $participants[] = CRM_Event_BAO_Participant
::create($params);
1399 foreach ($this->_contactIds
as $contactID) {
1400 $commonParams = $params;
1401 $commonParams['contact_id'] = $contactID;
1402 if ($commonParams['role_id']) {
1403 $rolesIDS = array();
1404 foreach ($commonParams['role_id'] as $k => $v) {
1407 $seperator = CRM_Core_DAO
::VALUE_SEPARATOR
;
1408 $commonParams['role_id'] = implode($seperator, $rolesIDS);
1409 $commonParams['participant_role_id'] = implode($seperator, $rolesIDS);
1412 $commonParams['role_id'] = 'NULL';
1414 $participants[] = CRM_Event_BAO_Participant
::create($commonParams);
1418 if (isset($params['event_id'])) {
1419 $eventTitle = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
1420 $params['event_id'],
1425 if ($this->_single
) {
1426 $this->_contactIds
[] = $this->_contactId
;
1429 $contributions = array();
1430 if (CRM_Utils_Array
::value('record_contribution', $params)) {
1431 if (CRM_Utils_Array
::value('id', $params)) {
1432 if ($this->_onlinePendingContributionId
) {
1433 $ids['contribution'] = $this->_onlinePendingContributionId
;
1436 $ids['contribution'] = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1443 unset($params['note']);
1445 //build contribution params
1446 if (!$this->_onlinePendingContributionId
) {
1447 $contributionParams['source'] = "{$eventTitle}: Offline registration (by {$userName})";
1450 $contributionParams['currency'] = $config->defaultCurrency
;
1451 $contributionParams['non_deductible_amount'] = 'null';
1452 $contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array
::value('receive_date', $params) : 'null';
1454 $recordContribution = array( 'contact_id', 'financial_type_id',
1455 'payment_instrument_id', 'trxn_id',
1456 'contribution_status_id', 'receive_date',
1457 'check_number', 'campaign_id',
1460 foreach ($recordContribution as $f) {
1461 $contributionParams[$f] = CRM_Utils_Array
::value($f, $params);
1462 if ($f == 'trxn_id') {
1463 $this->assign('trxn_id', $contributionParams[$f]);
1467 //insert financial type name in receipt.
1468 $this->assign('contributionTypeName', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id']));
1469 $contributionParams['skipLineItem'] = 1;
1471 $contributionParams['contribution_mode'] = 'participant';
1472 $contributionParams['participant_id'] = $this->_id
;
1474 // Set is_pay_later flag for back-office offline Pending status contributions
1475 if ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup
::getValue('contribution_status', 'Pending', 'name')) {
1476 $contributionParams['is_pay_later'] = 1;
1479 if ($params['status_id'] == array_search('Partially paid', $participantStatus)) {
1480 // CRM-13964 partial_payment_total
1481 if ($amountOwed > $params['total_amount']) {
1483 $contributionParams['partial_payment_total'] = $amountOwed;
1484 // the actual amount paid
1485 $contributionParams['partial_amount_pay'] = $params['total_amount'];
1488 if ($this->_single
) {
1492 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1496 foreach ($this->_contactIds
as $contactID) {
1497 $contributionParams['contact_id'] = $contactID;
1498 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1502 //insert payment record for this participation
1503 if (empty($ids['contribution'])) {
1504 foreach ($this->_contactIds
as $num => $contactID) {
1505 $ppDAO = new CRM_Event_DAO_ParticipantPayment();
1506 $ppDAO->participant_id
= $participants[$num]->id
;
1507 $ppDAO->contribution_id
= $contributions[$num]->id
;
1511 // next create the transaction record
1512 $transaction = new CRM_Core_Transaction();
1515 if ($this->_quickConfig
) {
1516 if (CRM_Utils_Array
::value('amount_priceset_level_radio', $this->_params
)) {
1517 $feeLevel = $this->_params
['amount_priceset_level_radio'];
1520 $feeLevel[] = $this->_params
['fee_level'] ;
1522 CRM_Event_BAO_Participant
::createDiscountTrxn($this->_eventId
, $contributionParams, $feeLevel);
1524 $transaction->commit();
1528 // also store lineitem stuff here
1529 if ((($this->_lineItem
& $this->_action
& CRM_Core_Action
::ADD
) ||
1530 ($this->_lineItem
&& CRM_Core_Action
::UPDATE
&& !$this->_paymentId
))
1532 foreach ($this->_contactIds
as $num => $contactID) {
1533 foreach ($this->_lineItem
as $key => $value) {
1534 if (is_array($value) && $value != 'skip') {
1535 foreach ($value as $lineKey => $line) {
1536 //10117 update the line items for participants if contribution amount is recorded
1537 if ($this->_quickConfig
&& CRM_Utils_Array
::value('total_amount', $params )
1538 && $params['status_id'] != array_search('Partially paid', $participantStatus)
1540 $line['unit_price'] = $line['line_total'] = $params['total_amount'];
1542 $lineItem[$this->_priceSetId
][$lineKey] = $line;
1544 CRM_Price_BAO_LineItem
::processPriceSet($participants[$num]->id
, $lineItem, CRM_Utils_Array
::value($num, $contributions, NULL), 'civicrm_participant');
1550 $updateStatusMsg = NULL;
1551 //send mail when participant status changed, CRM-4326
1552 if ($this->_id
&& $this->_statusId
&&
1553 $this->_statusId
!= CRM_Utils_Array
::value('status_id', $params) &&
1554 CRM_Utils_Array
::value('is_notify', $params)
1557 $updateStatusMsg = CRM_Event_BAO_Participant
::updateStatusMessage($this->_id
,
1558 $params['status_id'],
1565 if (CRM_Utils_Array
::value('send_receipt', $params)) {
1566 if (array_key_exists($params['from_email_address'], $this->_fromEmails
['from_email_id'])) {
1567 $receiptFrom = $params['from_email_address'];
1570 $this->assign('module', 'Event Registration');
1571 //use of the message template below requires variables in different format
1572 $event = $events = array();
1573 $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
1575 //get all event details.
1576 CRM_Core_DAO
::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
1577 $event = $events[$params['event_id']];
1578 unset($event['start_date']);
1579 unset($event['end_date']);
1581 $role = CRM_Event_PseudoConstant
::participantRole();
1582 $participantRoles = CRM_Utils_Array
::value('role_id', $params);
1583 if (is_array($participantRoles)) {
1584 $selectedRoles = array();
1585 foreach (array_keys($participantRoles) as $roleId) {
1586 $selectedRoles[] = $role[$roleId];
1588 $event['participant_role'] = implode(', ', $selectedRoles);
1591 $event['participant_role'] = CRM_Utils_Array
::value($participantRoles, $role);
1593 $event['is_monetary'] = $this->_isPaidEvent
;
1595 if ($params['receipt_text']) {
1596 $event['confirm_email_text'] = $params['receipt_text'];
1599 $this->assign('isAmountzero', 1);
1600 $this->assign('event', $event);
1602 $this->assign('isShowLocation', $event['is_show_location']);
1603 if (CRM_Utils_Array
::value('is_show_location', $event) == 1) {
1604 $locationParams = array(
1605 'entity_id' => $params['event_id'],
1606 'entity_table' => 'civicrm_event',
1608 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
1609 $this->assign('location', $location);
1612 $status = CRM_Event_PseudoConstant
::participantStatus();
1613 if ($this->_isPaidEvent
) {
1614 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
1615 if (!$this->_mode
) {
1616 if (isset($params['payment_instrument_id'])) {
1617 $this->assign('paidBy',
1618 CRM_Utils_Array
::value($params['payment_instrument_id'],
1625 $this->assign('totalAmount', $contributionParams['total_amount']);
1627 $this->assign('isPrimary', 1);
1628 $this->assign('checkNumber', CRM_Utils_Array
::value('check_number', $params));
1631 if (CRM_Utils_Array
::value('billing_first_name', $params)) {
1632 $name = $params['billing_first_name'];
1635 if (CRM_Utils_Array
::value('billing_middle_name', $params)) {
1636 $name .= " {$params['billing_middle_name']}";
1639 if (CRM_Utils_Array
::value('billing_last_name', $params)) {
1640 $name .= " {$params['billing_last_name']}";
1642 $this->assign('billingName', $name);
1644 // assign the address formatted up for display
1645 $addressParts = array(
1646 "street_address-{$this->_bltID}",
1647 "city-{$this->_bltID}",
1648 "postal_code-{$this->_bltID}",
1649 "state_province-{$this->_bltID}",
1650 "country-{$this->_bltID}",
1652 $addressFields = array();
1653 foreach ($addressParts as $part) {
1654 list($n, $id) = explode('-', $part);
1655 if (isset($this->_params
['billing_' . $part])) {
1656 $addressFields[$n] = $this->_params
['billing_' . $part];
1659 $this->assign('address', CRM_Utils_Address
::format($addressFields));
1661 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
1662 $date = CRM_Utils_Date
::mysqlToIso($date);
1663 $this->assign('credit_card_exp_date', $date);
1664 $this->assign('credit_card_number',
1665 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
1667 $this->assign('credit_card_type', $params['credit_card_type']);
1668 $this->assign('contributeMode', 'direct');
1669 $this->assign('isAmountzero', 0);
1670 $this->assign('is_pay_later', 0);
1671 $this->assign('isPrimary', 1);
1674 $this->assign('register_date', $params['register_date']);
1675 if ($params['receive_date']) {
1676 $this->assign('receive_date', $params['receive_date']);
1679 $participant = array(array('participant_id', '=', $participants[0]->id
, 0, 0));
1680 // check whether its a test drive ref CRM-3075
1681 if (CRM_Utils_Array
::value('is_test', $this->_defaultValues
)) {
1682 $participant[] = array('participant_test', '=', 1, 0, 0);
1685 $template = CRM_Core_Smarty
::singleton();
1686 $customGroup = array();
1687 //format submitted data
1688 foreach ($params['custom'] as $fieldID => $values) {
1689 foreach ($values as $fieldValue) {
1690 $customValue = array('data' => $fieldValue['value']);
1691 $customFields[$fieldID]['id'] = $fieldID;
1692 $formattedValue = CRM_Core_BAO_CustomGroup
::formatCustomValues($customValue, $customFields[$fieldID], TRUE);
1693 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace(' ', '', $formattedValue);
1697 foreach ($this->_contactIds
as $num => $contactID) {
1698 // Retrieve the name and email of the contact - this will be the TO for receipt email
1699 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($contactID);
1701 $this->_contributorDisplayName
= ($this->_contributorDisplayName
== ' ') ?
$this->_contributorEmail
: $this->_contributorDisplayName
;
1703 $waitStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
1704 if ($waitingStatus = CRM_Utils_Array
::value($params['status_id'], $waitStatus)) {
1705 $this->assign('isOnWaitlist', TRUE);
1708 $this->assign('customGroup', $customGroup);
1709 $this->assign('contactID', $contactID);
1710 $this->assign('participantID', $participants[$num]->id
);
1712 $this->_id
= $participants[$num]->id
;
1714 if ($this->_isPaidEvent
) {
1715 // fix amount for each of participants ( for bulk mode )
1716 $eventAmount = array();
1717 if (!empty($additionalParticipantDetails)) {
1718 $params['amount_level'] = preg_replace('/\ 1/', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName
;
1721 $eventAmount[$num] = array(
1722 'label' => preg_replace('/\ 1/', '', $params['amount_level']),
1723 'amount' => $params['fee_amount'],
1725 //as we are using same template for online & offline registration.
1726 //So we have to build amount as array.
1727 $eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
1728 $this->assign('amount', $eventAmount);
1731 $sendTemplateParams = array(
1732 'groupName' => 'msg_tpl_workflow_event',
1733 'valueName' => 'event_offline_receipt',
1734 'contactId' => $contactID,
1735 'isTest' => (bool) CRM_Utils_Array
::value('is_test', $this->_defaultValues
),
1736 'PDFFilename' => ts('confirmation').'.pdf',
1739 // try to send emails only if email id is present
1740 // and the do-not-email option is not checked for that contact
1741 if ($this->_contributorEmail
and !$this->_toDoNotEmail
) {
1742 $sendTemplateParams['from'] = $receiptFrom;
1743 $sendTemplateParams['toName'] = $this->_contributorDisplayName
;
1744 $sendTemplateParams['toEmail'] = $this->_contributorEmail
;
1745 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc', $this->_fromEmails
);
1746 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc', $this->_fromEmails
);
1749 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1751 $sent[] = $contactID;
1752 foreach ($participants as $ids => $values) {
1753 if ($values->contact_id
== $contactID) {
1754 CRM_Activity_BAO_Activity
::addActivity($values, 'Email');
1760 $notSent[] = $contactID;
1765 // set the participant id if it is not set
1767 $this->_id
= $participants[0]->id
;
1770 if (($this->_action
& CRM_Core_Action
::UPDATE
)) {
1771 $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contributorDisplayName
));
1772 if (CRM_Utils_Array
::value('send_receipt', $params) && count($sent)) {
1773 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', array(1 => $this->_contributorEmail
));
1776 if ($updateStatusMsg) {
1777 $statusMsg = "{$statusMsg} {$updateStatusMsg}";
1780 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
1781 if ($this->_single
) {
1782 $statusMsg = ts('Event registration for %1 has been added.', array(1 => $this->_contributorDisplayName
));
1783 if (CRM_Utils_Array
::value('send_receipt', $params) && count($sent)) {
1784 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $this->_contributorEmail
));
1788 $statusMsg = ts('Total Participant(s) added to event: %1.', array(1 => count($this->_contactIds
)));
1789 if (count($notSent) > 0) {
1790 $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)));
1792 elseif (isset($params['send_receipt'])) {
1793 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');
1797 CRM_Core_Session
::setStatus($statusMsg, ts('Saved'), 'success');
1799 $buttonName = $this->controller
->getButtonName();
1800 if ($this->_context
== 'standalone') {
1801 if ($buttonName == $this->getButtonName('upload', 'new')) {
1802 $urlParams = 'reset=1&action=add&context=standalone';
1804 $urlParams .= '&mode=' . $this->_mode
;
1807 $urlParams .= '&eid=' . $this->_eID
;
1809 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/participant/add', $urlParams));
1812 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
1813 "reset=1&cid={$this->_contactId}&selectedChild=participant"
1817 elseif ($buttonName == $this->getButtonName('upload', 'new')) {
1818 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view/participant',
1819 "reset=1&action=add&context={$this->_context}&cid={$this->_contactId}"