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();
455 if (!empty($roleIds)) {
457 SELECT civicrm_custom_group.name as name,
458 civicrm_custom_group.id as id,
459 extends_entity_column_value as value
460 FROM civicrm_custom_group
461 WHERE ( extends_entity_column_value REGEXP '[[:<:]]" . implode('[[:>:]]|[[:<:]]', array_keys($roleIds)) . "[[:>:]]'
462 OR extends_entity_column_value IS NULL )
463 AND extends_entity_column_id = '{$this->_roleCustomDataTypeID}'
464 AND extends = 'Participant'
467 $dao = CRM_Core_DAO
::executeQuery($query);
468 while ($dao->fetch()) {
470 $getRole = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $dao->value
);
471 foreach ($getRole as $r) {
475 if (isset($this->_participantRoleIds
[$r])) {
476 $this->_participantRoleIds
[$r] .= ',' . $dao->name
;
479 $this->_participantRoleIds
[$r] = $dao->name
;
484 if (isset($this->_participantRoleIds
[0])) {
485 $this->_participantRoleIds
[0] .= ',' . $dao->name
;
488 $this->_participantRoleIds
[0] = $dao->name
;
494 foreach ($roleIds as $k => $v) {
495 if (!isset($this->_participantRoleIds
[$k])) {
496 $this->_participantRoleIds
[$k] = '';
499 $this->assign('participantRoleIds', $this->_participantRoleIds
);
503 * This function sets the default values for the form in edit/view mode
504 * the default values are retrieved from the database
510 public function setDefaultValues() {
511 if ($this->_showFeeBlock
) {
512 return CRM_Event_Form_EventFees
::setDefaultValues($this);
515 if ($this->_cdType
) {
516 return CRM_Custom_Form_CustomData
::setDefaultValues($this);
521 if ($this->_action
& CRM_Core_Action
::DELETE
) {
527 $params = array('id' => $this->_id
);
529 CRM_Event_BAO_Participant
::getValues($params, $defaults, $ids);
530 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
531 if ($defaults[$this->_id
]['role_id']) {
532 foreach (explode($sep, $defaults[$this->_id
]['role_id']) as $k => $v) {
533 $defaults[$this->_id
]["role_id[{$v}]"] = 1;
535 unset($defaults[$this->_id
]['role_id']);
537 $this->_contactId
= $defaults[$this->_id
]['contact_id'];
538 $this->_statusId
= $defaults[$this->_id
]['participant_status_id'];
540 //set defaults for note
541 $noteDetails = CRM_Core_BAO_Note
::getNote($this->_id
, 'civicrm_participant');
542 $defaults[$this->_id
]['note'] = array_pop($noteDetails);
544 // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859)
545 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
546 $this->assign('additionalParticipants', CRM_Event_BAO_Participant
::getAdditionalParticipants($this->_id
));
549 // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
550 if (!empty($defaults[$this->_id
]['participant_registered_by_id'])) {
551 $registered_by_contact_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
552 $defaults[$this->_id
]['participant_registered_by_id'],
555 $this->assign('participant_registered_by_id', $defaults[$this->_id
]['participant_registered_by_id']);
556 $this->assign('registered_by_contact_id', $registered_by_contact_id);
557 $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact
::displayName($registered_by_contact_id));
561 if ($this->_action
& (CRM_Core_Action
::VIEW | CRM_Core_Action
::BROWSE
)) {
562 $inactiveNeeded = TRUE;
567 $inactiveNeeded = FALSE;
570 //setting default register date
571 if ($this->_action
== CRM_Core_Action
::ADD
) {
572 $statuses = array_flip($this->_participantStatuses
);
573 $defaults[$this->_id
]['status_id'] = CRM_Utils_Array
::value(ts('Registered'), $statuses);
574 if (!empty($defaults[$this->_id
]['event_id'])) {
575 $contributionTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
576 $defaults[$this->_id
]['event_id'],
579 if ($contributionTypeId) {
580 $defaults[$this->_id
]['financial_type_id'] = $contributionTypeId;
585 $fields["email-{$this->_bltID}"] = 1;
586 $fields['email-Primary'] = 1;
588 if ($this->_contactId
) {
589 CRM_Core_BAO_UFGroup
::setProfileDefaults($this->_contactId
, $fields, $defaults);
592 if (empty($defaults["email-{$this->_bltID}"]) &&
593 !empty($defaults['email-Primary'])
595 $defaults[$this->_id
]["email-{$this->_bltID}"] = $defaults['email-Primary'];
599 $submittedRole = $this->getElementValue('role_id');
600 if (!empty($submittedRole[0])) {
601 $roleID = $submittedRole[0];
603 $submittedEvent = $this->getElementValue('event_id');
604 if ($submittedEvent[0]) {
605 $eventID = $submittedEvent[0];
609 $defaults[$this->_id
]['record_contribution'] = 0;
611 if ($defaults[$this->_id
]['participant_is_pay_later']) {
612 $this->assign('participant_is_pay_later', TRUE);
615 $this->assign('participant_status_id', $defaults[$this->_id
]['participant_status_id']);
616 $roleID = $defaults[$this->_id
]['participant_role_id'];
617 $eventID = $defaults[$this->_id
]['event_id'];
619 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
621 $this->_discountId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'discount_id');
622 if ($this->_discountId
) {
623 $this->set('discountId', $this->_discountId
);
627 list($defaults[$this->_id
]['register_date'],
628 $defaults[$this->_id
]['register_date_time']
629 ) = CRM_Utils_Date
::setDateDefaults(
630 CRM_Utils_Array
::value('register_date', $defaults[$this->_id
]), 'activityDateTime'
633 //assign event and role id, this is needed for Custom data building
634 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
635 if (!empty($defaults[$this->_id
]['participant_role_id'])) {
636 $roleIDs = explode($sep, $defaults[$this->_id
]['participant_role_id']);
638 if (isset($roleIDs)) {
639 $this->assign('roleID', $roleIDs);
641 if (isset($_POST['event_id'])) {
642 $eventID = $_POST['event_id'];
644 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
648 if (isset($eventID)) {
649 $this->assign('eventID', $eventID);
650 $this->set('eventId', $eventID);
653 if (isset($this->_eventTypeId
)) {
654 $this->assign('eventTypeID', $this->_eventTypeId
);
657 $this->assign('event_is_test', CRM_Utils_Array
::value('event_is_test', $defaults[$this->_id
]));
658 return $defaults[$this->_id
];
662 * Function to build the form
667 public function buildQuickForm() {
668 CRM_Core_Resources
::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
669 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
670 $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses);
671 $this->assign('partiallyPaidStatusId', $partiallyPaidStatusId);
673 if ($this->_showFeeBlock
) {
674 return CRM_Event_Form_EventFees
::buildQuickForm($this);
677 if ($this->_cdType
) {
678 return CRM_Custom_Form_CustomData
::buildQuickForm($this);
681 //need to assign custom data type to the template
682 $this->assign('customDataType', 'Participant');
684 $this->applyFilter('__ALL__', 'trim');
686 if ($this->_action
& CRM_Core_Action
::DELETE
) {
687 if ($this->_single
) {
688 $additionalParticipant = count(CRM_Event_BAO_Event
::buildCustomProfile($this->_id
,
694 if ($additionalParticipant) {
695 $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'),
696 2 => ts('Delete only this participant record.'),
698 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
699 $this->setDefaults(array('delete_participant' => 1));
700 $this->assign('additionalParticipant', $additionalParticipant);
703 $this->addButtons(array(
706 'name' => ts('Delete'),
707 'spacing' => ' ',
712 'name' => ts('Cancel'),
720 if ($this->_single
) {
721 $urlPath = 'civicrm/contact/view/participant';
722 $urlParams = "reset=1&cid={$this->_contactId}&context=participant";
723 if ($this->_context
== 'standalone') {
724 $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE), TRUE);
725 $urlParams = 'reset=1&context=standalone';
726 $urlPath = 'civicrm/participant/add';
730 $urlParams .= "&action=update&id={$this->_id}";
733 $urlParams .= "&action=add";
737 $urlParams .= "&mode={$this->_mode}";
740 $url = CRM_Utils_System
::url($urlPath, $urlParams,
745 $currentPath = CRM_Utils_System
::currentPath();
747 $url = CRM_Utils_System
::url($currentPath, '_qf_Participant_display=true',
752 $this->assign('refreshURL', $url);
754 $eventFieldParams = array(
756 'select' => array('minimumInputLength' => 0),
758 'extra' => array('campaign_id', 'default_role_id', 'event_type_id'),
763 // exclude events which are not monetary when credit card registration is used
764 $eventFieldParams['api']['params']['is_monetary'] = 1;
765 $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors
, TRUE);
768 $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE);
770 //frozen the field fix for CRM-4171
771 if ($this->_action
& CRM_Core_Action
::UPDATE
&& $this->_id
) {
772 if (CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
773 $this->_id
, 'contribution_id', 'participant_id'
779 //CRM-7362 --add campaigns.
782 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'campaign_id');
785 $eventId = CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
787 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
790 CRM_Campaign_BAO_Campaign
::addCampaign($this, $campaignId);
792 $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
795 $this->assign('entityID', $this->_id
);
798 $roleids = CRM_Event_PseudoConstant
::participantRole();
800 foreach ($roleids as $rolekey => $rolevalue) {
801 $roleTypes[] = $this->createElement('checkbox', $rolekey, NULL, $rolevalue);
804 $this->addGroup($roleTypes, 'role_id', ts('Participant Role'));
805 $this->addRule('role_id', ts('Role is required'), 'required');
808 $checkCancelledJs = array('onchange' => "return sendNotification( );");
810 if ($this->_onlinePendingContributionId
) {
811 $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant
::participantStatus());
812 $cancelledContributionStatusId = array_search('Cancelled',
813 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
815 $checkCancelledJs = array(
817 "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});",
820 $participantStatusId = array_search('Pending from pay later',
821 CRM_Event_PseudoConstant
::participantStatus()
823 $contributionStatusId = array_search('Completed',
824 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
826 $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
829 // get the participant status names to build special status array which is used to show notification
830 // checkbox below participant status select
831 $participantStatusName = CRM_Event_PseudoConstant
::participantStatus();
832 $notificationStatuses = array(
834 'Pending from waitlist',
835 'Pending from approval',
839 // get the required status and then implode only ids
840 $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
841 $this->assign('notificationStatusIds', $notificationStatusIds);
843 $this->_participantStatuses
= CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label');
844 $this->addSelect('status_id', $checkCancelledJs, TRUE);
846 $enableCart = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::EVENT_PREFERENCES_NAME
,
849 $pendingInCartStatusId = array_search('Pending in cart', $participantStatusName);
850 $this->assign('pendingInCartStatusId', $pendingInCartStatusId);
851 $this->assign('enableCart', $enableCart);
853 $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
855 $this->add('text', 'source', ts('Event Source'));
856 $noteAttributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Note');
857 $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
861 'name' => ts('Save'),
866 $path = CRM_Utils_System
::currentPath();
867 $excludeForPaths = array(
868 'civicrm/contact/search',
869 'civicrm/group/search'
871 if (!in_array($path, $excludeForPaths)) {
874 'name' => ts('Save and New'),
882 'name' => ts('Cancel'),
885 $this->addButtons($buttons);
886 if ($this->_action
== CRM_Core_Action
::VIEW
) {
892 * Add local and global form rules
898 function addRules() {
899 $this->addFormRule(array('CRM_Event_Form_Participant', 'formRule'), $this);
903 * global validation rules for the form
905 * @param array $fields posted values of the form
907 * @return array list of errors to be posted back to the form
911 static function formRule($values, $files, $self) {
912 // If $values['_qf_Participant_next'] is Delete or
913 // $values['event_id'] is empty, then return
914 // instead of proceeding further.
916 if ((CRM_Utils_Array
::value('_qf_Participant_next', $values) == 'Delete') ||
917 (!$values['event_id'])
924 if (!empty($values['payment_processor_id'])) {
925 // make sure that credit card number and cvv are valid
926 CRM_Core_Payment_Form
::validateCreditCard($values, $errorMsg);
929 if (!empty($values['record_contribution'])) {
930 if (empty($values['financial_type_id'])) {
931 $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
933 if (empty($values['payment_instrument_id'])) {
934 $errorMsg['payment_instrument_id'] = ts('Paid By is a required field.');
938 // validate contribution status for 'Failed'.
939 if ($self->_onlinePendingContributionId
&& !empty($values['record_contribution']) &&
940 (CRM_Utils_Array
::value('contribution_status_id', $values) ==
941 array_search('Failed', CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name'))
944 $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.');
947 // do the amount validations.
948 //skip for update mode since amount is freeze, CRM-6052
949 if ((!$self->_id
&& empty($values['total_amount']) &&
950 empty($self->_values
['line_items'])
952 ($self->_id
&& !$self->_paymentId
&& isset($self->_values
['line_items']) && is_array($self->_values
['line_items']))
954 if ($priceSetId = CRM_Utils_Array
::value('priceSetId', $values)) {
955 CRM_Price_BAO_PriceField
::priceSetValidation($priceSetId, $values, $errorMsg, TRUE);
958 return CRM_Utils_Array
::crmIsEmptyArray($errorMsg) ?
TRUE : $errorMsg;
962 * Function to process the form
966 public function postProcess() {
967 // get the submitted form values.
968 $params = $this->controller
->exportValues($this->_name
);
970 if ($this->_action
& CRM_Core_Action
::DELETE
) {
971 if (CRM_Utils_Array
::value('delete_participant', $params) == 2) {
972 $additionalId = (CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
));
973 $participantLinks = (CRM_Event_BAO_Participant
::getAdditionalParticipantUrl($additionalId));
975 if (CRM_Utils_Array
::value('delete_participant', $params) == 1) {
976 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
977 foreach ($additionalIds as $value) {
978 CRM_Event_BAO_Participant
::deleteParticipant($value);
981 CRM_Event_BAO_Participant
::deleteParticipant($this->_id
);
982 CRM_Core_Session
::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success');
983 if (!empty($participantLinks)) {
984 $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;
985 CRM_Core_Session
::setStatus($status, ts('Group Payment Deleted'));
990 $participantStatus = CRM_Event_PseudoConstant
::participantStatus();
991 // set the contact, when contact is selected
992 if (!empty($params['contact_id'])) {
993 $this->_contactId
= $params['contact_id'];
995 if ($this->_priceSetId
&& $isQuickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
996 $this->_quickConfig
= $isQuickConfig;
1000 $params['id'] = $this->_id
;
1003 $config = CRM_Core_Config
::singleton();
1004 if ($this->_isPaidEvent
) {
1006 $contributionParams = array();
1007 $lineItem = array();
1008 $additionalParticipantDetails = array();
1009 if (($this->_id
&& $this->_action
& CRM_Core_Action
::UPDATE
) && $this->_paymentId
) {
1010 $participantBAO = new CRM_Event_BAO_Participant();
1011 $participantBAO->id
= $this->_id
;
1012 $participantBAO->find(TRUE);
1013 $contributionParams['total_amount'] = $participantBAO->fee_amount
;
1015 $params['discount_id'] = NULL;
1016 //re-enter the values for UPDATE mode
1017 $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level
;
1018 $params['fee_amount'] = $participantBAO->fee_amount
;
1019 if (isset($params['priceSetId'])) {
1020 $lineItem[0] = CRM_Price_BAO_LineItem
::getLineItems($this->_id
);
1022 //also add additional participant's fee level/priceset
1023 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
1024 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
1025 $hasLineItems = CRM_Utils_Array
::value('priceSetId', $params, FALSE);
1026 $additionalParticipantDetails = CRM_Event_BAO_Participant
::getFeeDetails($additionalIds,
1033 //check if discount is selected
1034 if (!empty($params['discount_id'])) {
1035 $discountId = $params['discount_id'];
1038 $discountId = $params['discount_id'] = 'null';
1041 //lets carry currency, CRM-4453
1042 $params['fee_currency'] = $config->defaultCurrency
;
1043 CRM_Price_BAO_PriceSet
::processAmount($this->_values
['fee'],
1044 $params, $lineItem[0]
1046 //CRM-11529 for quick config backoffice transactions
1047 //when financial_type_id is passed in form, update the
1048 //lineitems with the financial type selected in form
1049 $submittedFinancialType = CRM_Utils_Array
::value('financial_type_id', $params);
1050 $isPaymentRecorded = CRM_Utils_Array
::value('record_contribution', $params);
1051 if ($isPaymentRecorded && $this->_quickConfig
&& $submittedFinancialType) {
1052 foreach ($lineItem[0] as &$values) {
1053 $values['financial_type_id'] = $submittedFinancialType;
1057 $params['fee_level'] = $params['amount_level'];
1058 $contributionParams['total_amount'] = $params['amount'];
1059 if ($this->_quickConfig
&& !empty($params['total_amount']) &&
1060 ($params['status_id'] != array_search('Partially paid', $participantStatus) &&
1061 $params['status_id'] != array_search('Pending refund', $participantStatus))) {
1062 $params['fee_amount'] = $params['total_amount'];
1065 $params['fee_amount'] = $params['amount'];
1069 if (isset($params['priceSetId'])) {
1070 if (!empty($lineItem[0])) {
1071 $this->set('lineItem', $lineItem);
1073 $this->_lineItem
= $lineItem;
1074 $lineItem = array_merge($lineItem, $additionalParticipantDetails);
1076 $participantCount = array();
1077 foreach ($lineItem as $k) {
1078 foreach ($k as $v) {
1079 if (CRM_Utils_Array
::value('participant_count', $v) > 0) {
1080 $participantCount[] = $v['participant_count'];
1085 if (isset($participantCount)) {
1086 $this->assign('pricesetFieldsCount', $participantCount);
1088 $this->assign('lineItem', empty($lineItem[0]) ||
$this->_quickConfig?
FALSE : $lineItem);
1091 $this->assign('amount_level', $params['amount_level']);
1095 $this->_params
= $params;
1097 if (isset($params['amount'])) {
1098 $amountOwed = $params['amount'];
1099 unset($params['amount']);
1101 $params['register_date'] = CRM_Utils_Date
::processDate($params['register_date'], $params['register_date_time']);
1102 $params['receive_date'] = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('receive_date', $params));
1103 $params['contact_id'] = $this->_contactId
;
1105 // overwrite actual payment amount if entered
1106 if (!empty($params['total_amount'])) {
1107 $contributionParams['total_amount'] = CRM_Utils_Array
::value('total_amount', $params);
1111 // Retrieve the name and email of the current user - this will be the FROM for the receipt email
1112 $session = CRM_Core_Session
::singleton();
1113 $userID = $session->get('userID');
1116 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($userID);
1118 if ($this->_contactId
) {
1119 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($this->_contactId
);
1123 if (!$this->_isPaidEvent
) {
1124 CRM_Core_Error
::fatal(ts('Selected Event is not Paid Event '));
1126 //modify params according to parameter used in create
1127 //participant method (addParticipant)
1128 $this->_params
['participant_status_id'] = $params['status_id'];
1129 $this->_params
['participant_role_id'] = $params['role_id'];
1130 $this->_params
['participant_register_date'] = $params['register_date'];
1133 CRM_Core_DAO
::getFieldValue(
1134 'CRM_Event_DAO_Event',
1135 $params['event_id'],
1139 // set source if not set
1140 if (empty($params['source'])) {
1141 $this->_params
['participant_source'] = ts('Offline Registration for Event: %2 by: %1', array(1 => $userName, 2 => $eventTitle));
1144 $this->_params
['participant_source'] = $params['source'];
1146 $this->_params
['description'] = $this->_params
['participant_source'];
1148 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($this->_params
['payment_processor_id'],
1151 $now = date('YmdHis');
1154 // set email for primary location.
1155 $fields['email-Primary'] = 1;
1156 $params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail
;
1158 $params['register_date'] = $now;
1160 // now set the values for the billing location.
1161 foreach ($this->_fields
as $name => $dontCare) {
1165 // also add location name to the array
1166 $params["address_name-{$this->_bltID}"] =
1167 CRM_Utils_Array
::value('billing_first_name', $params) . ' ' .
1168 CRM_Utils_Array
::value('billing_middle_name', $params) . ' ' .
1169 CRM_Utils_Array
::value('billing_last_name', $params);
1171 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
1172 $fields["address_name-{$this->_bltID}"] = 1;
1173 $fields["email-{$this->_bltID}"] = 1;
1174 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'contact_type');
1176 $nameFields = array('first_name', 'middle_name', 'last_name');
1178 foreach ($nameFields as $name) {
1180 if (array_key_exists("billing_$name", $params)) {
1181 $params[$name] = $params["billing_{$name}"];
1182 $params['preserveDBName'] = TRUE;
1185 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params, $fields, $this->_contactId
, NULL, NULL, $ctype);
1188 $roleAllIds = CRM_Utils_Array
::value('role_id', $params);
1190 foreach ($roleAllIds as $rkey => $rvalue) {
1191 $customFieldsRole = CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, $rkey, $this->_roleCustomDataTypeID
);
1192 $customFieldsEvent = CRM_Core_BAO_CustomField
::getFields('Participant',
1195 CRM_Utils_Array
::value('event_id', $params),
1196 $this->_eventNameCustomDataTypeID
1198 $customFieldsEventType = CRM_Core_BAO_CustomField
::getFields('Participant',
1201 $this->_eventTypeId
,
1202 $this->_eventTypeCustomDataTypeID
1204 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsRole,
1205 CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE)
1207 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEvent, $customFields);
1208 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEventType, $customFields);
1209 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
1217 //do cleanup line items if participant edit the Event Fee.
1218 if (($this->_lineItem ||
!isset($params['proceSetId'])) && !$this->_paymentId
&& $this->_id
) {
1219 CRM_Price_BAO_LineItem
::deleteLineItems($this->_id
, 'civicrm_participant');
1223 // add all the additioanl payment params we need
1224 $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}"]);
1225 $this->_params
["country-{$this->_bltID}"] = $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
1227 $this->_params
['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($this->_params
);
1228 $this->_params
['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($this->_params
);
1229 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
1230 $this->_params
['amount'] = $params['fee_amount'];
1231 $this->_params
['amount_level'] = $params['amount_level'];
1232 $this->_params
['currencyID'] = $config->defaultCurrency
;
1233 $this->_params
['payment_action'] = 'Sale';
1234 $this->_params
['invoiceID'] = md5(uniqid(rand(), TRUE));
1236 // at this point we've created a contact and stored its address etc
1237 // all the payment processors expect the name and address to be in the
1238 // so we copy stuff over to first_name etc.
1239 $paymentParams = $this->_params
;
1240 if (!empty($this->_params
['send_receipt'])) {
1241 $paymentParams['email'] = $this->_contributorEmail
;
1243 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $this->_params
, $paymentParams, TRUE);
1245 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
1247 $result = &$payment->doDirectPayment($paymentParams);
1249 if (is_a($result, 'CRM_Core_Error')) {
1250 CRM_Core_Error
::displaySessionError($result);
1251 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/view/participant',
1252 "reset=1&action=add&cid={$this->_contactId}&context=participant&mode={$this->_mode}"
1257 $this->_params
= array_merge($this->_params
, $result);
1260 $this->_params
['receive_date'] = $now;
1262 if (!empty($this->_params
['send_receipt'])) {
1263 $this->_params
['receipt_date'] = $now;
1266 $this->_params
['receipt_date'] = NULL;
1269 $this->set('params', $this->_params
);
1270 $this->assign('trxn_id', $result['trxn_id']);
1271 $this->assign('receive_date',
1272 CRM_Utils_Date
::processDate($this->_params
['receive_date'])
1275 //add contribution record
1276 $this->_params
['financial_type_id'] =
1277 CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
1278 $this->_params
['mode'] = $this->_mode
;
1280 //add contribution reocord
1281 $contributions[] = $contribution = CRM_Event_Form_Registration_Confirm
::processContribution($this, $this->_params
, $result, $contactID, FALSE);
1283 // add participant record
1284 $participants = array();
1285 if (!empty($this->_params
['participant_role_id']) && is_array($this->_params
['participant_role_id'])) {
1286 $this->_params
['participant_role_id'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1287 array_keys($this->_params
['participant_role_id'])
1290 $participants[] = CRM_Event_Form_Registration
::addParticipant($this->_params
, $contactID);
1292 //add custom data for participant
1293 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
1294 CRM_Core_DAO
::$_nullArray,
1295 'civicrm_participant',
1296 $participants[0]->id
,
1299 //add participant payment
1300 $paymentParticipant = array(
1301 'participant_id' => $participants[0]->id
,
1302 'contribution_id' => $contribution->id
,
1306 CRM_Event_BAO_ParticipantPayment
::create($paymentParticipant, $ids);
1307 $this->_contactIds
[] = $this->_contactId
;
1310 $participants = array();
1311 if ($this->_single
) {
1312 if ($params['role_id']) {
1313 foreach ($params['role_id'] as $k => $v) {
1316 $seperator = CRM_Core_DAO
::VALUE_SEPARATOR
;
1317 $params['role_id'] = implode($seperator, $rolesIDS);
1320 $params['role_id'] = 'NULL';
1322 $participants[] = CRM_Event_BAO_Participant
::create($params);
1325 foreach ($this->_contactIds
as $contactID) {
1326 $commonParams = $params;
1327 $commonParams['contact_id'] = $contactID;
1328 if ($commonParams['role_id']) {
1329 $rolesIDS = array();
1330 foreach ($commonParams['role_id'] as $k => $v) {
1333 $seperator = CRM_Core_DAO
::VALUE_SEPARATOR
;
1334 $commonParams['role_id'] = implode($seperator, $rolesIDS);
1335 $commonParams['participant_role_id'] = implode($seperator, $rolesIDS);
1338 $commonParams['role_id'] = 'NULL';
1340 $participants[] = CRM_Event_BAO_Participant
::create($commonParams);
1344 if (isset($params['event_id'])) {
1345 $eventTitle = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
1346 $params['event_id'],
1351 if ($this->_single
) {
1352 $this->_contactIds
[] = $this->_contactId
;
1355 $contributions = array();
1356 if (!empty($params['record_contribution'])) {
1357 if (!empty($params['id'])) {
1358 if ($this->_onlinePendingContributionId
) {
1359 $ids['contribution'] = $this->_onlinePendingContributionId
;
1362 $ids['contribution'] = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1369 unset($params['note']);
1371 //build contribution params
1372 if (!$this->_onlinePendingContributionId
) {
1373 $contributionParams['source'] = "{$eventTitle}: Offline registration (by {$userName})";
1376 $contributionParams['currency'] = $config->defaultCurrency
;
1377 $contributionParams['non_deductible_amount'] = 'null';
1378 $contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array
::value('receive_date', $params) : 'null';
1380 $recordContribution = array( 'contact_id', 'financial_type_id',
1381 'payment_instrument_id', 'trxn_id',
1382 'contribution_status_id', 'receive_date',
1383 'check_number', 'campaign_id',
1386 foreach ($recordContribution as $f) {
1387 $contributionParams[$f] = CRM_Utils_Array
::value($f, $params);
1388 if ($f == 'trxn_id') {
1389 $this->assign('trxn_id', $contributionParams[$f]);
1393 //insert financial type name in receipt.
1394 $this->assign('contributionTypeName', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id']));
1395 $contributionParams['skipLineItem'] = 1;
1397 $contributionParams['contribution_mode'] = 'participant';
1398 $contributionParams['participant_id'] = $this->_id
;
1400 // Set is_pay_later flag for back-office offline Pending status contributions
1401 if ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup
::getValue('contribution_status', 'Pending', 'name')) {
1402 $contributionParams['is_pay_later'] = 1;
1405 if ($params['status_id'] == array_search('Partially paid', $participantStatus)) {
1406 // CRM-13964 partial_payment_total
1407 if ($amountOwed > $params['total_amount']) {
1409 $contributionParams['partial_payment_total'] = $amountOwed;
1410 // the actual amount paid
1411 $contributionParams['partial_amount_pay'] = $params['total_amount'];
1414 elseif ($params['status_id'] == array_search('Pending refund', $participantStatus)) {
1415 $totalPaid = $params['total_amount'];
1416 $updatedAmt = $amountOwed;
1418 if ($this->_single
) {
1422 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1426 foreach ($this->_contactIds
as $contactID) {
1427 $contributionParams['contact_id'] = $contactID;
1428 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1432 //insert payment record for this participation
1433 if (empty($ids['contribution'])) {
1434 foreach ($this->_contactIds
as $num => $contactID) {
1435 $ppDAO = new CRM_Event_DAO_ParticipantPayment();
1436 $ppDAO->participant_id
= $participants[$num]->id
;
1437 $ppDAO->contribution_id
= $contributions[$num]->id
;
1441 // next create the transaction record
1442 $transaction = new CRM_Core_Transaction();
1445 if ($this->_quickConfig
) {
1446 if (!empty($this->_params
['amount_priceset_level_radio'])) {
1447 $feeLevel = $this->_params
['amount_priceset_level_radio'];
1450 $feeLevel[] = $this->_params
['fee_level'] ;
1452 CRM_Event_BAO_Participant
::createDiscountTrxn($this->_eventId
, $contributionParams, $feeLevel);
1454 $transaction->commit();
1458 // also store lineitem stuff here
1459 if ((($this->_lineItem
& $this->_action
& CRM_Core_Action
::ADD
) ||
1460 ($this->_lineItem
&& CRM_Core_Action
::UPDATE
&& !$this->_paymentId
))
1462 foreach ($this->_contactIds
as $num => $contactID) {
1463 foreach ($this->_lineItem
as $key => $value) {
1464 if (is_array($value) && $value != 'skip') {
1465 foreach ($value as $lineKey => $line) {
1466 //10117 update the line items for participants if contribution amount is recorded
1467 if ($this->_quickConfig
&& !empty($params['total_amount']) &&
1468 ($params['status_id'] != array_search('Partially paid', $participantStatus) &&
1469 $params['status_id'] != array_search('Pending refund', $participantStatus))
1471 $line['unit_price'] = $line['line_total'] = $params['total_amount'];
1473 $lineItem[$this->_priceSetId
][$lineKey] = $line;
1475 CRM_Price_BAO_LineItem
::processPriceSet($participants[$num]->id
, $lineItem, CRM_Utils_Array
::value($num, $contributions, NULL), 'civicrm_participant');
1481 // record adjusted trxn entry for refund case
1482 if ($this->_isPaidEvent
&& $params['status_id'] == array_search('Pending refund', $participantStatus) &&
1483 !empty($totalPaid) && !empty($updatedAmt)) {
1484 $contributionDetail = $contributions[0];
1485 $contributionId = $contributionDetail->id
;
1486 CRM_Event_BAO_Participant
::recordAdjustedAmt($updatedAmt, $totalPaid, $contributionId);
1488 $updateStatusMsg = NULL;
1489 //send mail when participant status changed, CRM-4326
1490 if ($this->_id
&& $this->_statusId
&&
1491 $this->_statusId
!= CRM_Utils_Array
::value('status_id', $params) && !empty($params['is_notify'])) {
1493 $updateStatusMsg = CRM_Event_BAO_Participant
::updateStatusMessage($this->_id
,
1494 $params['status_id'],
1501 if (!empty($params['send_receipt'])) {
1502 if (array_key_exists($params['from_email_address'], $this->_fromEmails
['from_email_id'])) {
1503 $receiptFrom = $params['from_email_address'];
1506 $this->assign('module', 'Event Registration');
1507 //use of the message template below requires variables in different format
1508 $event = $events = array();
1509 $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
1511 //get all event details.
1512 CRM_Core_DAO
::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
1513 $event = $events[$params['event_id']];
1514 unset($event['start_date']);
1515 unset($event['end_date']);
1517 $role = CRM_Event_PseudoConstant
::participantRole();
1518 $participantRoles = CRM_Utils_Array
::value('role_id', $params);
1519 if (is_array($participantRoles)) {
1520 $selectedRoles = array();
1521 foreach (array_keys($participantRoles) as $roleId) {
1522 $selectedRoles[] = $role[$roleId];
1524 $event['participant_role'] = implode(', ', $selectedRoles);
1527 $event['participant_role'] = CRM_Utils_Array
::value($participantRoles, $role);
1529 $event['is_monetary'] = $this->_isPaidEvent
;
1531 if ($params['receipt_text']) {
1532 $event['confirm_email_text'] = $params['receipt_text'];
1535 $this->assign('isAmountzero', 1);
1536 $this->assign('event', $event);
1538 $this->assign('isShowLocation', $event['is_show_location']);
1539 if (CRM_Utils_Array
::value('is_show_location', $event) == 1) {
1540 $locationParams = array(
1541 'entity_id' => $params['event_id'],
1542 'entity_table' => 'civicrm_event',
1544 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
1545 $this->assign('location', $location);
1548 $status = CRM_Event_PseudoConstant
::participantStatus();
1549 if ($this->_isPaidEvent
) {
1550 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
1551 if (!$this->_mode
) {
1552 if (isset($params['payment_instrument_id'])) {
1553 $this->assign('paidBy',
1554 CRM_Utils_Array
::value($params['payment_instrument_id'],
1561 $this->assign('totalAmount', $contributionParams['total_amount']);
1562 if (isset($contributionParams['partial_payment_total'])) {
1564 $balanceAmount = $contributionParams['partial_payment_total'] - $contributionParams['partial_amount_pay'];
1565 $this->assign('balanceAmount', $balanceAmount );
1567 $this->assign('isPrimary', 1);
1568 $this->assign('checkNumber', CRM_Utils_Array
::value('check_number', $params));
1571 if (!empty($params['billing_first_name'])) {
1572 $name = $params['billing_first_name'];
1575 if (!empty($params['billing_middle_name'])) {
1576 $name .= " {$params['billing_middle_name']}";
1579 if (!empty($params['billing_last_name'])) {
1580 $name .= " {$params['billing_last_name']}";
1582 $this->assign('billingName', $name);
1584 // assign the address formatted up for display
1585 $addressParts = array(
1586 "street_address-{$this->_bltID}",
1587 "city-{$this->_bltID}",
1588 "postal_code-{$this->_bltID}",
1589 "state_province-{$this->_bltID}",
1590 "country-{$this->_bltID}",
1592 $addressFields = array();
1593 foreach ($addressParts as $part) {
1594 list($n, $id) = explode('-', $part);
1595 if (isset($this->_params
['billing_' . $part])) {
1596 $addressFields[$n] = $this->_params
['billing_' . $part];
1599 $this->assign('address', CRM_Utils_Address
::format($addressFields));
1601 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
1602 $date = CRM_Utils_Date
::mysqlToIso($date);
1603 $this->assign('credit_card_exp_date', $date);
1604 $this->assign('credit_card_number',
1605 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
1607 $this->assign('credit_card_type', $params['credit_card_type']);
1608 $this->assign('contributeMode', 'direct');
1609 $this->assign('isAmountzero', 0);
1610 $this->assign('is_pay_later', 0);
1611 $this->assign('isPrimary', 1);
1614 $this->assign('register_date', $params['register_date']);
1615 if ($params['receive_date']) {
1616 $this->assign('receive_date', $params['receive_date']);
1619 $participant = array(array('participant_id', '=', $participants[0]->id
, 0, 0));
1620 // check whether its a test drive ref CRM-3075
1621 if (!empty($this->_defaultValues
['is_test'])) {
1622 $participant[] = array('participant_test', '=', 1, 0, 0);
1625 $template = CRM_Core_Smarty
::singleton();
1626 $customGroup = array();
1627 //format submitted data
1628 foreach ($params['custom'] as $fieldID => $values) {
1629 foreach ($values as $fieldValue) {
1630 $customValue = array('data' => $fieldValue['value']);
1631 $customFields[$fieldID]['id'] = $fieldID;
1632 $formattedValue = CRM_Core_BAO_CustomGroup
::formatCustomValues($customValue, $customFields[$fieldID], TRUE);
1633 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace(' ', '', $formattedValue);
1637 foreach ($this->_contactIds
as $num => $contactID) {
1638 // Retrieve the name and email of the contact - this will be the TO for receipt email
1639 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($contactID);
1641 $this->_contributorDisplayName
= ($this->_contributorDisplayName
== ' ') ?
$this->_contributorEmail
: $this->_contributorDisplayName
;
1643 $waitStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
1644 if ($waitingStatus = CRM_Utils_Array
::value($params['status_id'], $waitStatus)) {
1645 $this->assign('isOnWaitlist', TRUE);
1648 $this->assign('customGroup', $customGroup);
1649 $this->assign('contactID', $contactID);
1650 $this->assign('participantID', $participants[$num]->id
);
1652 $this->_id
= $participants[$num]->id
;
1654 if ($this->_isPaidEvent
) {
1655 // fix amount for each of participants ( for bulk mode )
1656 $eventAmount = array();
1657 if (!empty($additionalParticipantDetails)) {
1658 $params['amount_level'] = preg_replace('/\ 1/', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName
;
1661 $eventAmount[$num] = array(
1662 'label' => preg_replace('/\ 1/', '', $params['amount_level']),
1663 'amount' => $params['fee_amount'],
1665 //as we are using same template for online & offline registration.
1666 //So we have to build amount as array.
1667 $eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
1668 $this->assign('amount', $eventAmount);
1671 $sendTemplateParams = array(
1672 'groupName' => 'msg_tpl_workflow_event',
1673 'valueName' => 'event_offline_receipt',
1674 'contactId' => $contactID,
1675 'isTest' => (bool) CRM_Utils_Array
::value('is_test', $this->_defaultValues
),
1676 'PDFFilename' => ts('confirmation').'.pdf',
1679 // try to send emails only if email id is present
1680 // and the do-not-email option is not checked for that contact
1681 if ($this->_contributorEmail
and !$this->_toDoNotEmail
) {
1682 $sendTemplateParams['from'] = $receiptFrom;
1683 $sendTemplateParams['toName'] = $this->_contributorDisplayName
;
1684 $sendTemplateParams['toEmail'] = $this->_contributorEmail
;
1685 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc', $this->_fromEmails
);
1686 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc', $this->_fromEmails
);
1689 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1691 $sent[] = $contactID;
1692 foreach ($participants as $ids => $values) {
1693 if ($values->contact_id
== $contactID) {
1694 CRM_Activity_BAO_Activity
::addActivity($values, 'Email');
1700 $notSent[] = $contactID;
1705 // set the participant id if it is not set
1707 $this->_id
= $participants[0]->id
;
1710 if (($this->_action
& CRM_Core_Action
::UPDATE
)) {
1711 $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contributorDisplayName
));
1712 if (!empty($params['send_receipt']) && count($sent)) {
1713 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', array(1 => $this->_contributorEmail
));
1716 if ($updateStatusMsg) {
1717 $statusMsg = "{$statusMsg} {$updateStatusMsg}";
1720 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
1721 if ($this->_single
) {
1722 $statusMsg = ts('Event registration for %1 has been added.', array(1 => $this->_contributorDisplayName
));
1723 if (!empty($params['send_receipt']) && count($sent)) {
1724 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $this->_contributorEmail
));
1728 $statusMsg = ts('Total Participant(s) added to event: %1.', array(1 => count($this->_contactIds
)));
1729 if (count($notSent) > 0) {
1730 $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)));
1732 elseif (isset($params['send_receipt'])) {
1733 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');
1737 CRM_Core_Session
::setStatus($statusMsg, ts('Saved'), 'success');
1739 $buttonName = $this->controller
->getButtonName();
1740 if ($this->_context
== 'standalone') {
1741 if ($buttonName == $this->getButtonName('upload', 'new')) {
1742 $urlParams = 'reset=1&action=add&context=standalone';
1744 $urlParams .= '&mode=' . $this->_mode
;
1747 $urlParams .= '&eid=' . $this->_eID
;
1749 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/participant/add', $urlParams));
1752 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
1753 "reset=1&cid={$this->_contactId}&selectedChild=participant"
1757 elseif ($buttonName == $this->getButtonName('upload', 'new')) {
1758 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view/participant',
1759 "reset=1&action=add&context={$this->_context}&cid={$this->_contactId}"