3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
234 $this->_id
, 'id', 'participant_id'
238 // get the option value for custom data type
239 $this->_roleCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantRole', 'name');
240 $this->_eventNameCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantEventName', 'name');
241 $this->_eventTypeCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantEventType', 'name');
242 $this->assign('roleCustomDataTypeID', $this->_roleCustomDataTypeID
);
243 $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID
);
244 $this->assign('eventTypeCustomDataTypeID', $this->_eventTypeCustomDataTypeID
);
247 $this->assign('participantMode', $this->_mode
);
249 $this->_paymentProcessor
= array('billing_mode' => 1);
251 $validProcessors = array();
252 $processors = CRM_Core_PseudoConstant
::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )");
254 foreach ($processors as $ppID => $label) {
255 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getPayment($ppID, $this->_mode
);
256 if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) {
259 elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode
== 'live') {
263 $paymentObject = CRM_Core_Payment
::singleton($this->_mode
, $paymentProcessor, $this);
264 $error = $paymentObject->checkConfig();
266 $validProcessors[$ppID] = $label;
268 $paymentObject = NULL;
271 if (empty($validProcessors)) {
272 CRM_Core_Error
::fatal(ts('Could not find valid payment processor for this page'));
275 $this->_processors
= $validProcessors;
277 // also check for billing information
278 // get the billing location type
279 $locationTypes = CRM_Core_PseudoConstant
::locationType();
280 // CRM-8108 remove ts around Billing location type
281 //$this->_bltID = array_search( ts('Billing'), $locationTypes );
282 $this->_bltID
= array_search('Billing', $locationTypes);
283 if (!$this->_bltID
) {
284 CRM_Core_Error
::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
286 $this->set('bltID', $this->_bltID
);
287 $this->assign('bltID', $this->_bltID
);
289 $this->_fields
= array();
291 CRM_Core_Payment_Form
::setCreditCardFields($this);
293 // this required to show billing block
294 $this->assign_by_ref('paymentProcessor', $paymentProcessor);
295 $this->assign('hidePayPalExpress', TRUE);
298 if ($this->_showFeeBlock
) {
299 $this->assign('showFeeBlock', TRUE);
300 $isMonetary = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_showFeeBlock
, 'is_monetary');
302 $this->assign('feeBlockPaid', TRUE);
304 return CRM_Event_Form_EventFees
::preProcess($this);
307 //custom data related code
308 $this->_cdType
= CRM_Utils_Array
::value('type', $_GET);
309 $this->assign('cdType', FALSE);
310 if ($this->_cdType
) {
311 $this->assign('cdType', TRUE);
312 return CRM_Custom_Form_CustomData
::preProcess($this);
315 //check the mode when this form is called either single or as
317 if ($this->_id ||
$this->_contactId ||
$this->_context
== 'standalone') {
318 $this->_single
= TRUE;
319 $this->assign('urlPath', 'civicrm/contact/view/participant');
320 if (!$this->_id
&& !$this->_contactId
) {
321 $breadCrumbs = array(array('title' => ts('CiviEvent Dashboard'),
322 'url' => CRM_Utils_System
::url('civicrm/event', 'reset=1'),
325 CRM_Utils_System
::appendBreadCrumb($breadCrumbs);
329 //set the appropriate action
330 $context = $this->get('context');
331 $urlString = 'civicrm/contact/search';
332 $this->_action
= CRM_Core_Action
::BASIC
;
335 $urlString = 'civicrm/contact/search/advanced';
336 $this->_action
= CRM_Core_Action
::ADVANCED
;
340 $urlString = 'civicrm/contact/search/builder';
341 $this->_action
= CRM_Core_Action
::PROFILE
;
345 $urlString = 'civicrm/contact/search/basic';
346 $this->_action
= CRM_Core_Action
::BASIC
;
350 $urlString = 'civicrm/contact/search/custom';
351 $this->_action
= CRM_Core_Action
::COPY
;
354 parent
::preProcess();
356 $this->_single
= FALSE;
357 $this->_contactId
= NULL;
359 //set ajax path, this used for custom data building
360 $this->assign('urlPath', $urlString);
361 $this->assign('urlPathVar', "_qf_Participant_display=true&qfKey={$this->controller->_key}");
364 $this->assign('single', $this->_single
);
367 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
369 $this->assign('action', $this->_action
);
371 // check for edit permission
372 if (!CRM_Core_Permission
::checkActionPermission('CiviEvent', $this->_action
)) {
373 CRM_Core_Error
::fatal(ts('You do not have permission to access this page'));
376 if ($this->_action
& CRM_Core_Action
::DELETE
) {
377 // check delete permission for contribution
378 if ($this->_id
&& $this->_paymentId
&& !CRM_Core_Permission
::checkActionPermission('CiviContribute', $this->_action
)) {
379 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."));
385 // assign participant id to the template
386 $this->assign('participantId', $this->_id
);
387 $this->_roleId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'role_id');
390 // when fee amount is included in form
391 if (CRM_Utils_Array
::value('hidden_feeblock', $_POST)
392 || CRM_Utils_Array
::value('send_receipt', $_POST)
394 CRM_Event_Form_EventFees
::preProcess($this);
395 CRM_Event_Form_EventFees
::buildQuickForm($this);
396 CRM_Event_Form_EventFees
::setDefaultValues($this);
399 // when custom data is included in this page
400 if (CRM_Utils_Array
::value('hidden_custom', $_POST)) {
401 //custom data of type participant role
402 if (CRM_Utils_Array
::value('role_id', $_POST)) {
403 foreach ($_POST['role_id'] as $k => $val) {
405 CRM_Custom_Form_CustomData
::preProcess($this, $this->_roleCustomDataTypeID
, $k, 1, 'Participant', $this->_id
);
406 CRM_Custom_Form_CustomData
::buildQuickForm($this);
407 CRM_Custom_Form_CustomData
::setDefaultValues($this);
411 //custom data of type participant event
412 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventNameCustomDataTypeID
, $_POST['event_id'], 1, 'Participant', $this->_id
);
413 CRM_Custom_Form_CustomData
::buildQuickForm($this);
414 CRM_Custom_Form_CustomData
::setDefaultValues($this);
416 // custom data of type participant event type
418 if ($eventId = CRM_Utils_Array
::value('event_id', $_POST)) {
419 $eventTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'event_type_id', 'id');
421 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventTypeCustomDataTypeID
, $eventTypeId,
422 1, 'Participant', $this->_id
424 CRM_Custom_Form_CustomData
::buildQuickForm($this);
425 CRM_Custom_Form_CustomData
::setDefaultValues($this);
427 //custom data of type participant, ( we 'null' to reset subType and subName)
428 CRM_Custom_Form_CustomData
::preProcess($this, 'null', 'null', 1, 'Participant', $this->_id
);
429 CRM_Custom_Form_CustomData
::buildQuickForm($this);
430 CRM_Custom_Form_CustomData
::setDefaultValues($this);
433 // CRM-4395, get the online pending contribution id.
434 $this->_onlinePendingContributionId
= NULL;
435 if (!$this->_mode
&& $this->_id
&& ($this->_action
& CRM_Core_Action
::UPDATE
)) {
436 $this->_onlinePendingContributionId
= CRM_Contribute_BAO_Contribution
::checkOnlinePendingContribution($this->_id
,
440 $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId
);
441 $roleIds = CRM_Event_PseudoConstant
::participantRole();
443 if (!empty($roleIds)) {
445 SELECT civicrm_custom_group.name as name,
446 civicrm_custom_group.id as id,
447 extends_entity_column_value as value
448 FROM civicrm_custom_group
449 WHERE ( extends_entity_column_value REGEXP '[[:<:]]" . implode('[[:>:]]|[[:<:]]', array_keys($roleIds)) . "[[:>:]]'
450 OR extends_entity_column_value IS NULL )
451 AND extends_entity_column_id = '{$this->_roleCustomDataTypeID}'
452 AND extends = 'Participant'
455 $dao = CRM_Core_DAO
::executeQuery($query);
456 while ($dao->fetch()) {
458 $getRole = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $dao->value
);
459 foreach ($getRole as $r) {
463 if (isset($this->_participantRoleIds
[$r])) {
464 $this->_participantRoleIds
[$r] .= ',' . $dao->name
;
467 $this->_participantRoleIds
[$r] = $dao->name
;
472 if (isset($this->_participantRoleIds
[0])) {
473 $this->_participantRoleIds
[0] .= ',' . $dao->name
;
476 $this->_participantRoleIds
[0] = $dao->name
;
482 foreach ($roleIds as $k => $v) {
483 if (!isset($this->_participantRoleIds
[$k])) {
484 $this->_participantRoleIds
[$k] = '';
487 $this->assign('participantRoleIds', $this->_participantRoleIds
);
491 * This function sets the default values for the form in edit/view mode
492 * the default values are retrieved from the database
498 public function setDefaultValues() {
499 if ($this->_showFeeBlock
) {
500 return CRM_Event_Form_EventFees
::setDefaultValues($this);
503 if ($this->_cdType
) {
504 return CRM_Custom_Form_CustomData
::setDefaultValues($this);
509 if ($this->_action
& CRM_Core_Action
::DELETE
) {
515 $params = array('id' => $this->_id
);
517 CRM_Event_BAO_Participant
::getValues($params, $defaults, $ids);
518 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
519 if ($defaults[$this->_id
]['role_id']) {
520 foreach (explode($sep, $defaults[$this->_id
]['role_id']) as $k => $v) {
521 $defaults[$this->_id
]["role_id[{$v}]"] = 1;
523 unset($defaults[$this->_id
]['role_id']);
525 $this->_contactId
= $defaults[$this->_id
]['contact_id'];
526 $this->_statusId
= $defaults[$this->_id
]['participant_status_id'];
528 //set defaults for note
529 $noteDetails = CRM_Core_BAO_Note
::getNote($this->_id
, 'civicrm_participant');
530 $defaults[$this->_id
]['note'] = array_pop($noteDetails);
532 // Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859)
533 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
534 $this->assign('additionalParticipants', CRM_Event_BAO_Participant
::getAdditionalParticipants($this->_id
));
537 // Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
538 if (CRM_Utils_Array
::value('participant_registered_by_id', $defaults[$this->_id
])) {
539 $registered_by_contact_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
540 $defaults[$this->_id
]['participant_registered_by_id'],
543 $this->assign('participant_registered_by_id', $defaults[$this->_id
]['participant_registered_by_id']);
544 $this->assign('registered_by_contact_id', $registered_by_contact_id);
545 $this->assign('registered_by_display_name', CRM_Contact_BAO_Contact
::displayName($registered_by_contact_id));
549 if ($this->_action
& (CRM_Core_Action
::VIEW | CRM_Core_Action
::BROWSE
)) {
550 $inactiveNeeded = TRUE;
555 $inactiveNeeded = FALSE;
558 //setting default register date
559 if ($this->_action
== CRM_Core_Action
::ADD
) {
560 $statuses = array_flip($this->_participantStatuses
);
561 $defaults[$this->_id
]['status_id'] = CRM_Utils_Array
::value(ts('Registered'), $statuses);
562 if (CRM_Utils_Array
::value('event_id', $defaults[$this->_id
])) {
563 $contributionTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
564 $defaults[$this->_id
]['event_id'],
565 'financial_type_id' );
566 if ($contributionTypeId) {
567 $defaults[$this->_id
]['financial_type_id'] = $contributionTypeId;
572 $fields["email-{$this->_bltID}"] = 1;
573 $fields['email-Primary'] = 1;
575 if ($this->_contactId
) {
576 CRM_Core_BAO_UFGroup
::setProfileDefaults($this->_contactId
, $fields, $defaults);
579 if (empty($defaults["email-{$this->_bltID}"]) &&
580 !empty($defaults['email-Primary'])
582 $defaults[$this->_id
]["email-{$this->_bltID}"] = $defaults['email-Primary'];
586 $submittedRole = $this->getElementValue('role_id');
587 if (CRM_Utils_Array
::value(0, $submittedRole)) {
588 $roleID = $submittedRole[0];
590 $submittedEvent = $this->getElementValue('event_id');
591 if ($submittedEvent[0]) {
592 $eventID = $submittedEvent[0];
596 $defaults[$this->_id
]['record_contribution'] = 0;
598 if ($defaults[$this->_id
]['participant_is_pay_later']) {
599 $this->assign('participant_is_pay_later', TRUE);
602 $this->assign('participant_status_id', $defaults[$this->_id
]['participant_status_id']);
603 $roleID = $defaults[$this->_id
]['participant_role_id'];
604 $eventID = $defaults[$this->_id
]['event_id'];
606 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
608 $this->_discountId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'discount_id');
609 if ($this->_discountId
) {
610 $this->set('discountId', $this->_discountId
);
614 list($defaults[$this->_id
]['register_date'],
615 $defaults[$this->_id
]['register_date_time']
616 ) = CRM_Utils_Date
::setDateDefaults(
617 CRM_Utils_Array
::value('register_date', $defaults[$this->_id
]), 'activityDateTime'
620 //assign event and role id, this is needed for Custom data building
621 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
622 if (CRM_Utils_Array
::value('participant_role_id', $defaults[$this->_id
])) {
623 $roleIDs = explode($sep, $defaults[$this->_id
]['participant_role_id']);
625 if (isset($roleIDs)) {
626 $this->assign('roleID', $roleIDs);
628 if (isset($_POST['event_id'])) {
629 $eventID = $_POST['event_id'];
631 $this->_eventTypeId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id');
635 if (isset($eventID)) {
636 $this->assign('eventID', $eventID);
637 $this->set('eventId', $eventID);
640 if (isset($this->_eventTypeId
)) {
641 $this->assign('eventTypeID', $this->_eventTypeId
);
644 $this->assign('event_is_test', CRM_Utils_Array
::value('event_is_test', $defaults[$this->_id
]));
645 return $defaults[$this->_id
];
649 * Function to build the form
654 public function buildQuickForm() {
655 if ($this->_showFeeBlock
) {
656 return CRM_Event_Form_EventFees
::buildQuickForm($this);
659 if ($this->_cdType
) {
660 return CRM_Custom_Form_CustomData
::buildQuickForm($this);
663 //need to assign custom data type to the template
664 $this->assign('customDataType', 'Participant');
666 $this->applyFilter('__ALL__', 'trim');
668 if ($this->_action
& CRM_Core_Action
::DELETE
) {
669 if ($this->_single
) {
670 $additionalParticipant = count(CRM_Event_BAO_Event
::buildCustomProfile($this->_id
,
676 if ($additionalParticipant) {
677 $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'),
678 2 => ts('Delete only this participant record.'),
680 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
681 $this->setDefaults(array('delete_participant' => 1));
682 $this->assign('additionalParticipant', $additionalParticipant);
685 $this->addButtons(array(
688 'name' => ts('Delete'),
689 'spacing' => ' ',
694 'name' => ts('Cancel'),
702 if ($this->_single
) {
703 $urlPath = 'civicrm/contact/view/participant';
704 $urlParams = "reset=1&cid={$this->_contactId}&context=participant";
705 if ($this->_context
== 'standalone') {
706 CRM_Contact_Form_NewContact
::buildQuickForm($this);
707 $urlParams = 'reset=1&context=standalone';
708 $urlPath = 'civicrm/participant/add';
712 $urlParams .= "&action=update&id={$this->_id}";
715 $urlParams .= "&action=add";
719 $urlParams .= "&mode={$this->_mode}";
722 $url = CRM_Utils_System
::url($urlPath, $urlParams,
727 $currentPath = CRM_Utils_System
::currentPath();
729 $url = CRM_Utils_System
::url($currentPath, '_qf_Participant_display=true',
734 $this->assign('refreshURL', $url);
736 $this->add('hidden', 'past_event');
740 $eventEndDate = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_eID
,'end_date');
742 $this->assign('past', FALSE);
743 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
744 $events = CRM_Event_BAO_Event
::getEvents(TRUE, FALSE, FALSE);
746 elseif ($this->getElementValue('past_event') ||
(isset($eventEndDate) && (CRM_Utils_Date
::currentDBDate() > CRM_Utils_Date
::processDate($eventEndDate)))) {
747 $events = CRM_Event_BAO_Event
::getEvents(TRUE);
748 $this->assign('past', TRUE);
751 $events = CRM_Event_BAO_Event
::getEvents();
755 //unset the event which are not monetary when credit card
756 //event registration is used
757 foreach ($events as $key => $val) {
758 $isPaid = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $key, 'is_monetary');
760 unset($events[$key]);
763 $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors
, TRUE);
766 // build array(event -> eventType) mapper
768 SELECT civicrm_event.id as id, civicrm_event.event_type_id as event_type_id
770 WHERE civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0";
771 $dao = CRM_Core_DAO
::executeQuery($query);
772 $eventAndTypeMapping = array();
773 while ($dao->fetch()) {
774 $eventAndTypeMapping[$dao->id
] = $dao->event_type_id
;
776 $eventAndTypeMapping = json_encode($eventAndTypeMapping);
777 // building of mapping ends --
779 //inherit the campaign from event.
780 $eventCampaigns = array();
781 $allEventIds = array_keys($events);
782 if (!empty($allEventIds)) {
783 CRM_Core_PseudoConstant
::populate($eventCampaigns,
784 'CRM_Event_DAO_Event',
788 $eventCampaigns = json_encode($eventCampaigns);
790 $element = $this->add('select', 'event_id', ts('Event'),
792 '' => ts('- select -')) +
$events,
794 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')
798 // note that embedding JS within PHP files is quite awful, IMO
799 // but we do the same for the onChange element and this form is complex
800 // and i did not want to break it late in the 3.2 cycle
801 $preloadJSSnippet = NULL;
802 if (CRM_Utils_Array
::value('reset', $_GET) && $this->_eID
) {
803 $preloadJSSnippet = "
805 cj('#event_id').val( '{$this->_eID}' );
806 buildFeeBlock( {$this->_eID} );
807 CRM.buildCustomData( 'Participant', {$this->_eID}, {$this->_eventNameCustomDataTypeID} );
808 buildEventTypeCustomData( {$this->_eID}, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' );
809 loadCampaign( {$this->_eID}, {$eventCampaigns} );
814 $this->assign('preloadJSSnippet', $preloadJSSnippet);
817 //frozen the field fix for CRM-4171
818 if ($this->_action
& CRM_Core_Action
::UPDATE
&& $this->_id
) {
819 if (CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
820 $this->_id
, 'contribution_id', 'participant_id'
826 //CRM-7362 --add campaigns.
829 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'campaign_id');
832 $eventId = CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
834 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
837 CRM_Campaign_BAO_Campaign
::addCampaign($this, $campaignId);
839 $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
842 $this->assign('entityID', $this->_id
);
845 $roleids = CRM_Event_PseudoConstant
::participantRole();
847 foreach ($roleids as $rolekey => $rolevalue) {
848 $roleTypes[] = $this->createElement('checkbox', $rolekey, NULL, $rolevalue,
849 array('onclick' => "showCustomData( 'Participant', {$rolekey}, {$this->_roleCustomDataTypeID} );")
853 $this->addGroup($roleTypes, 'role_id', ts('Participant Role'));
854 $this->addRule('role_id', ts('Role is required'), 'required');
857 $checkCancelledJs = array('onchange' => "return sendNotification( );");
859 if ($this->_onlinePendingContributionId
) {
860 $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant
::participantStatus());
861 $cancelledContributionStatusId = array_search('Cancelled',
862 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
864 $checkCancelledJs = array(
866 "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});",
869 $participantStatusId = array_search('Pending from pay later',
870 CRM_Event_PseudoConstant
::participantStatus()
872 $contributionStatusId = array_search('Completed',
873 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
875 $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
878 $this->_participantStatuses
= CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label');
879 $this->add('select', 'status_id', ts('Participant Status'),
881 '' => ts('- select -')) +
$this->_participantStatuses
,
886 $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
888 $this->add('text', 'source', ts('Event Source'));
889 $noteAttributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Note');
890 $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
894 'name' => ts('Save'),
899 $path = CRM_Utils_System
::currentPath();
900 if (strpos($path, 'civicrm/contact/search') !== 0) {
903 'name' => ts('Save and New'),
910 'name' => ts('Cancel'),
913 $this->addButtons($buttons);
914 if ($this->_action
== CRM_Core_Action
::VIEW
) {
920 * Add local and global form rules
926 function addRules() {
927 $this->addFormRule(array('CRM_Event_Form_Participant', 'formRule'), $this);
931 * global validation rules for the form
933 * @param array $fields posted values of the form
935 * @return array list of errors to be posted back to the form
939 static function formRule($values, $files, $self) {
940 // If $values['_qf_Participant_next'] is Delete or
941 // $values['event_id'] is empty, then return
942 // instead of proceeding further.
944 if ((CRM_Utils_Array
::value('_qf_Participant_next', $values) == 'Delete') ||
945 (!$values['event_id'])
951 //check if contact is selected in standalone mode
952 if (isset($values['contact_select_id'][1]) && !$values['contact_select_id'][1]) {
953 $errorMsg['contact[1]'] = ts('Please select a contact or create new contact');
956 if (CRM_Utils_Array
::value('payment_processor_id', $values)) {
957 // make sure that credit card number and cvv are valid
958 CRM_Core_Payment_Form
::validateCreditCard($values, $errorMsg);
961 if (CRM_Utils_Array
::value('record_contribution', $values) && !CRM_Utils_Array
::value('financial_type_id', $values)) {
962 $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
965 // validate contribution status for 'Failed'.
966 if ($self->_onlinePendingContributionId
&&
967 CRM_Utils_Array
::value('record_contribution', $values) &&
968 (CRM_Utils_Array
::value('contribution_status_id', $values) ==
969 array_search('Failed', CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name'))
972 $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.');
975 // do the amount validations.
976 //skip for update mode since amount is freeze, CRM-6052
978 !CRM_Utils_Array
::value('total_amount', $values) &&
979 empty($self->_values
['line_items'])
981 ($self->_id
&& !$self->_paymentId
&& isset($self->_values
['line_items']) && is_array($self->_values
['line_items']))
983 if ($priceSetId = CRM_Utils_Array
::value('priceSetId', $values)) {
984 CRM_Price_BAO_Field
::priceSetValidation($priceSetId, $values, $errorMsg, TRUE);
987 return CRM_Utils_Array
::crmIsEmptyArray($errorMsg) ?
TRUE : $errorMsg;
991 * Function to process the form
995 public function postProcess() {
996 // get the submitted form values.
997 $params = $this->controller
->exportValues($this->_name
);
999 if ($this->_action
& CRM_Core_Action
::DELETE
) {
1000 if (CRM_Utils_Array
::value('delete_participant', $params) == 2) {
1001 $additionalId = (CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
));
1002 $participantLinks = (CRM_Event_BAO_Participant
::getAdditionalParticipantUrl($additionalId));
1004 if (CRM_Utils_Array
::value('delete_participant', $params) == 1) {
1005 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
1006 foreach ($additionalIds as $value) {
1007 CRM_Event_BAO_Participant
::deleteParticipant($value);
1010 CRM_Event_BAO_Participant
::deleteParticipant($this->_id
);
1011 CRM_Core_Session
::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success');
1012 if (!empty($participantLinks)) {
1013 $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;
1014 CRM_Core_Session
::setStatus($status, ts('Group Payment Deleted'));
1019 // set the contact, when contact is selected
1020 if (CRM_Utils_Array
::value('contact_select_id', $params)) {
1021 $this->_contactId
= $params['contact_select_id'][1];
1023 if ($this->_priceSetId
&& $isQuickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId
, 'is_quick_config')) {
1024 $this->_quickConfig
= $isQuickConfig;
1028 $params['id'] = $this->_id
;
1031 $config = CRM_Core_Config
::singleton();
1032 if ($this->_isPaidEvent
) {
1034 $contributionParams = array();
1035 $lineItem = array();
1036 $additionalParticipantDetails = array();
1037 if (($this->_id
&& $this->_action
& CRM_Core_Action
::UPDATE
) && $this->_paymentId
) {
1038 $participantBAO = new CRM_Event_BAO_Participant();
1039 $participantBAO->id
= $this->_id
;
1040 $participantBAO->find(TRUE);
1041 $contributionParams['total_amount'] = $participantBAO->fee_amount
;
1043 $params['discount_id'] = NULL;
1044 //re-enter the values for UPDATE mode
1045 $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level
;
1046 $params['fee_amount'] = $participantBAO->fee_amount
;
1047 if (isset($params['priceSetId'])) {
1048 $lineItem[0] = CRM_Price_BAO_LineItem
::getLineItems($this->_id
);
1050 //also add additional participant's fee level/priceset
1051 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
1052 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
1053 $hasLineItems = CRM_Utils_Array
::value('priceSetId', $params, FALSE);
1054 $additionalParticipantDetails = CRM_Event_BAO_Participant
::getFeeDetails($additionalIds,
1061 //check if discount is selected
1062 if (CRM_Utils_Array
::value('discount_id', $params)) {
1063 $discountId = $params['discount_id'];
1066 $discountId = $params['discount_id'] = 'null';
1069 //lets carry currency, CRM-4453
1070 $params['fee_currency'] = $config->defaultCurrency
;
1073 !empty($this->_values
['discount'][$discountId])
1075 $params['amount_level'] = $this->_values
['discount'][$discountId][$params['amount']]['label'];
1076 $params['amount'] = $this->_values
['discount'][$discountId][$params['amount']]['value'];
1078 elseif (!isset($params['priceSetId']) && CRM_Utils_Array
::value('amount', $params)) {
1079 $params['amount_level'] = $this->_values
['fee'][$params['amount']]['label'];
1080 $params['amount'] = $this->_values
['fee'][$params['amount']]['value'];
1083 CRM_Price_BAO_Set
::processAmount($this->_values
['fee'],
1084 $params, $lineItem[0]
1087 //CRM-11529 for quick config backoffice transactions
1088 //when financial_type_id is passed in form, update the
1089 //lineitems with the financial type selected in form
1090 $submittedFinancialType = CRM_Utils_Array
::value('financial_type_id', $params);
1091 $isPaymentRecorded = CRM_Utils_Array
::value('record_contribution', $params);
1092 if ($isPaymentRecorded && $this->_quickConfig
&& $submittedFinancialType) {
1093 foreach ($lineItem[0] as &$values) {
1094 $values['financial_type_id'] = $submittedFinancialType;
1098 $params['fee_level'] = $params['amount_level'];
1099 $contributionParams['total_amount'] = $params['amount'];
1100 if ($this->_quickConfig
&& CRM_Utils_Array
::value('total_amount', $params)) {
1101 $params['fee_amount'] = $params['total_amount'];
1104 $params['fee_amount'] = $params['amount'];
1108 if (isset($params['priceSetId'])) {
1109 if (!empty($lineItem[0])) {
1110 $this->set('lineItem', $lineItem);
1112 $this->_lineItem
= $lineItem;
1113 $lineItem = array_merge($lineItem, $additionalParticipantDetails);
1115 $participantCount = array();
1116 foreach ($lineItem as $k) {
1117 foreach ($k as $v) {
1118 if (CRM_Utils_Array
::value('participant_count', $v) > 0) {
1119 $participantCount[] = $v['participant_count'];
1124 if (isset($participantCount)) {
1125 $this->assign('pricesetFieldsCount', $participantCount);
1127 $this->assign('lineItem', empty($lineItem[0]) ||
$this->_quickConfig?
FALSE : $lineItem);
1130 $this->assign('amount_level', $params['amount_level']);
1134 $this->_params
= $params;
1135 unset($params['amount']);
1136 $params['register_date'] = CRM_Utils_Date
::processDate($params['register_date'], $params['register_date_time']);
1137 $params['receive_date'] = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('receive_date', $params));
1138 $params['contact_id'] = $this->_contactId
;
1140 // overwrite actual payment amount if entered
1141 if (CRM_Utils_Array
::value('total_amount', $params)) {
1142 $contributionParams['total_amount'] = CRM_Utils_Array
::value('total_amount', $params);
1146 // Retrieve the name and email of the current user - this will be the FROM for the receipt email
1147 $session = CRM_Core_Session
::singleton();
1148 $userID = $session->get('userID');
1151 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($userID);
1153 if ($this->_contactId
) {
1154 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($this->_contactId
);
1158 if (!$this->_isPaidEvent
) {
1159 CRM_Core_Error
::fatal(ts('Selected Event is not Paid Event '));
1161 //modify params according to parameter used in create
1162 //participant method (addParticipant)
1163 $this->_params
['participant_status_id'] = $params['status_id'];
1164 $this->_params
['participant_role_id'] = $params['role_id'];
1165 $this->_params
['participant_register_date'] = $params['register_date'];
1168 CRM_Core_DAO
::getFieldValue(
1169 'CRM_Event_DAO_Event',
1170 $params['event_id'],
1174 // set source if not set
1175 if (empty($params['source'])) {
1176 $this->_params
['participant_source'] = ts('Offline Registration for Event: %2 by: %1', array(1 => $userName, 2 => $eventTitle));
1179 $this->_params
['participant_source'] = $params['source'];
1181 $this->_params
['description'] = $this->_params
['participant_source'];
1183 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($this->_params
['payment_processor_id'],
1186 $now = date('YmdHis');
1189 // set email for primary location.
1190 $fields['email-Primary'] = 1;
1191 $params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail
;
1193 $params['register_date'] = $now;
1195 // now set the values for the billing location.
1196 foreach ($this->_fields
as $name => $dontCare) {
1200 // also add location name to the array
1201 $params["address_name-{$this->_bltID}"] =
1202 CRM_Utils_Array
::value('billing_first_name', $params) . ' ' .
1203 CRM_Utils_Array
::value('billing_middle_name', $params) . ' ' .
1204 CRM_Utils_Array
::value('billing_last_name', $params);
1206 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
1207 $fields["address_name-{$this->_bltID}"] = 1;
1208 $fields["email-{$this->_bltID}"] = 1;
1209 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'contact_type');
1211 $nameFields = array('first_name', 'middle_name', 'last_name');
1213 foreach ($nameFields as $name) {
1215 if (array_key_exists("billing_$name", $params)) {
1216 $params[$name] = $params["billing_{$name}"];
1217 $params['preserveDBName'] = TRUE;
1220 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params, $fields, $this->_contactId
, NULL, NULL, $ctype);
1223 $roleAllIds = CRM_Utils_Array
::value('role_id', $params);
1225 foreach ($roleAllIds as $rkey => $rvalue) {
1226 $customFieldsRole = CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, $rkey, $this->_roleCustomDataTypeID
);
1227 $customFieldsEvent = CRM_Core_BAO_CustomField
::getFields('Participant',
1230 CRM_Utils_Array
::value('event_id', $params),
1231 $this->_eventNameCustomDataTypeID
1233 $customFieldsEventType = CRM_Core_BAO_CustomField
::getFields('Participant',
1236 $this->_eventTypeId
,
1237 $this->_eventTypeCustomDataTypeID
1239 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsRole,
1240 CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE)
1242 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEvent, $customFields);
1243 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEventType, $customFields);
1244 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
1252 //do cleanup line items if participant edit the Event Fee.
1253 if (($this->_lineItem ||
!isset($params['proceSetId'])) && !$this->_paymentId
&& $this->_id
) {
1254 CRM_Price_BAO_LineItem
::deleteLineItems($this->_id
, 'civicrm_participant');
1258 // add all the additioanl payment params we need
1259 $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}"]);
1260 $this->_params
["country-{$this->_bltID}"] = $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
1262 $this->_params
['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($this->_params
);
1263 $this->_params
['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($this->_params
);
1264 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
1265 $this->_params
['amount'] = $params['fee_amount'];
1266 $this->_params
['amount_level'] = $params['amount_level'];
1267 $this->_params
['currencyID'] = $config->defaultCurrency
;
1268 $this->_params
['payment_action'] = 'Sale';
1269 $this->_params
['invoiceID'] = md5(uniqid(rand(), TRUE));
1271 // at this point we've created a contact and stored its address etc
1272 // all the payment processors expect the name and address to be in the
1273 // so we copy stuff over to first_name etc.
1274 $paymentParams = $this->_params
;
1275 if (CRM_Utils_Array
::value('send_receipt', $this->_params
)) {
1276 $paymentParams['email'] = $this->_contributorEmail
;
1278 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $this->_params
, $paymentParams, TRUE);
1280 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
1282 $result = &$payment->doDirectPayment($paymentParams);
1284 if (is_a($result, 'CRM_Core_Error')) {
1285 CRM_Core_Error
::displaySessionError($result);
1286 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/view/participant',
1287 "reset=1&action=add&cid={$this->_contactId}&context=participant&mode={$this->_mode}"
1292 $this->_params
= array_merge($this->_params
, $result);
1295 $this->_params
['receive_date'] = $now;
1297 if (CRM_Utils_Array
::value('send_receipt', $this->_params
)) {
1298 $this->_params
['receipt_date'] = $now;
1301 $this->_params
['receipt_date'] = NULL;
1304 $this->set('params', $this->_params
);
1305 $this->assign('trxn_id', $result['trxn_id']);
1306 $this->assign('receive_date',
1307 CRM_Utils_Date
::processDate($this->_params
['receive_date'])
1310 //add contribution record
1311 $this->_params
['financial_type_id'] =
1312 CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
1313 $this->_params
['mode'] = $this->_mode
;
1315 //add contribution reocord
1316 $contributions[] = $contribution = CRM_Event_Form_Registration_Confirm
::processContribution($this, $this->_params
, $result, $contactID, FALSE);
1318 // add participant record
1319 $participants = array();
1320 if (CRM_Utils_Array
::value('participant_role_id', $this->_params
) && is_array($this->_params
['participant_role_id'])) {
1321 $this->_params
['participant_role_id'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1322 array_keys($this->_params
['participant_role_id'])
1325 $participants[] = CRM_Event_Form_Registration
::addParticipant($this->_params
, $contactID);
1327 //add custom data for participant
1328 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
1329 CRM_Core_DAO
::$_nullArray,
1330 'civicrm_participant',
1331 $participants[0]->id
,
1334 //add participant payment
1335 $paymentParticipant = array(
1336 'participant_id' => $participants[0]->id
,
1337 'contribution_id' => $contribution->id
,
1341 CRM_Event_BAO_ParticipantPayment
::create($paymentParticipant, $ids);
1342 $this->_contactIds
[] = $this->_contactId
;
1345 $participants = array();
1346 if ($this->_single
) {
1347 if ($params['role_id']) {
1348 foreach ($params['role_id'] as $k => $v) {
1351 $seperator = CRM_Core_DAO
::VALUE_SEPARATOR
;
1352 $params['role_id'] = implode($seperator, $rolesIDS);
1355 $params['role_id'] = 'NULL';
1357 $participants[] = CRM_Event_BAO_Participant
::create($params);
1360 foreach ($this->_contactIds
as $contactID) {
1361 $commonParams = $params;
1362 $commonParams['contact_id'] = $contactID;
1363 if ($commonParams['role_id']) {
1364 $rolesIDS = array();
1365 foreach ($commonParams['role_id'] as $k => $v) {
1368 $seperator = CRM_Core_DAO
::VALUE_SEPARATOR
;
1369 $commonParams['role_id'] = implode($seperator, $rolesIDS);
1370 $commonParams['participant_role_id'] = implode($seperator, $rolesIDS);
1373 $commonParams['role_id'] = 'NULL';
1375 $participants[] = CRM_Event_BAO_Participant
::create($commonParams);
1379 if (isset($params['event_id'])) {
1380 $eventTitle = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
1381 $params['event_id'],
1386 if ($this->_single
) {
1387 $this->_contactIds
[] = $this->_contactId
;
1390 $contributions = array();
1391 if (CRM_Utils_Array
::value('record_contribution', $params)) {
1392 if (CRM_Utils_Array
::value('id', $params)) {
1393 if ($this->_onlinePendingContributionId
) {
1394 $ids['contribution'] = $this->_onlinePendingContributionId
;
1397 $ids['contribution'] = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1404 unset($params['note']);
1406 //build contribution params
1407 if (!$this->_onlinePendingContributionId
) {
1408 $contributionParams['source'] = "{$eventTitle}: Offline registration (by {$userName})";
1411 $contributionParams['currency'] = $config->defaultCurrency
;
1412 $contributionParams['non_deductible_amount'] = 'null';
1413 $contributionParams['receipt_date'] = CRM_Utils_Array
::value('send_receipt', $params) ? CRM_Utils_Array
::value('receive_date', $params) : 'null';
1415 $recordContribution = array( 'contact_id', 'financial_type_id',
1416 'payment_instrument_id', 'trxn_id',
1417 'contribution_status_id', 'receive_date',
1418 'check_number', 'campaign_id',
1421 foreach ($recordContribution as $f) {
1422 $contributionParams[$f] = CRM_Utils_Array
::value($f, $params);
1423 if ($f == 'trxn_id') {
1424 $this->assign('trxn_id', $contributionParams[$f]);
1428 //insert financial type name in receipt.
1429 $this->assign('contributionTypeName', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id']));
1430 $contributionParams['skipLineItem'] = 1;
1432 $contributionParams['contribution_mode'] = 'participant';
1433 $contributionParams['participant_id'] = $this->_id
;
1435 // Set is_pay_later flag for back-office offline Pending status contributions
1436 if ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup
::getValue('contribution_status', 'Pending', 'name')) {
1437 $contributionParams['is_pay_later'] = 1;
1439 if ($this->_single
) {
1440 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1444 foreach ($this->_contactIds
as $contactID) {
1445 $contributionParams['contact_id'] = $contactID;
1446 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1450 //insert payment record for this participation
1451 if (!$ids['contribution']) {
1452 foreach ($this->_contactIds
as $num => $contactID) {
1453 $ppDAO = new CRM_Event_DAO_ParticipantPayment();
1454 $ppDAO->participant_id
= $participants[$num]->id
;
1455 $ppDAO->contribution_id
= $contributions[$num]->id
;
1459 // next create the transaction record
1460 $transaction = new CRM_Core_Transaction();
1463 if ($this->_quickConfig
) {
1464 if (CRM_Utils_Array
::value('amount_priceset_level_radio', $this->_params
)) {
1465 $feeLevel = $this->_params
['amount_priceset_level_radio'];
1468 $feeLevel[] = $this->_params
['fee_level'] ;
1470 CRM_Event_BAO_Participant
::createDiscountTrxn($this->_eventId
, $contributionParams, $feeLevel);
1472 $transaction->commit();
1476 // also store lineitem stuff here
1477 if ((($this->_lineItem
& $this->_action
& CRM_Core_Action
::ADD
) ||
1478 ($this->_lineItem
&& CRM_Core_Action
::UPDATE
&& !$this->_paymentId
))
1480 foreach ($this->_contactIds
as $num => $contactID) {
1481 foreach ($this->_lineItem
as $key => $value) {
1482 if (is_array($value) && $value != 'skip') {
1483 foreach ($value as $lineKey => $line) {
1484 //10117 update the line items for participants if contribution amount is recorded
1485 if ($this->_quickConfig
&& CRM_Utils_Array
::value('total_amount', $params )) {
1486 $line['unit_price'] = $line['line_total'] = $params['total_amount'];
1488 $lineItem[$this->_priceSetId
][$lineKey] = $line;
1490 CRM_Price_BAO_LineItem
::processPriceSet($participants[$num]->id
, $lineItem, CRM_Utils_Array
::value($num, $contributions, NULL), 'civicrm_participant');
1496 $updateStatusMsg = NULL;
1497 //send mail when participant status changed, CRM-4326
1498 if ($this->_id
&& $this->_statusId
&&
1499 $this->_statusId
!= CRM_Utils_Array
::value('status_id', $params) &&
1500 CRM_Utils_Array
::value('is_notify', $params)
1503 $updateStatusMsg = CRM_Event_BAO_Participant
::updateStatusMessage($this->_id
,
1504 $params['status_id'],
1511 if (CRM_Utils_Array
::value('send_receipt', $params)) {
1512 if (array_key_exists($params['from_email_address'], $this->_fromEmails
['from_email_id'])) {
1513 $receiptFrom = $params['from_email_address'];
1516 $this->assign('module', 'Event Registration');
1517 //use of the message template below requires variables in different format
1518 $event = $events = array();
1519 $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
1521 //get all event details.
1522 CRM_Core_DAO
::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
1523 $event = $events[$params['event_id']];
1524 unset($event['start_date']);
1525 unset($event['end_date']);
1527 $role = CRM_Event_PseudoConstant
::participantRole();
1528 $participantRoles = CRM_Utils_Array
::value('role_id', $params);
1529 if (is_array($participantRoles)) {
1530 $selectedRoles = array();
1531 foreach (array_keys($participantRoles) as $roleId) {
1532 $selectedRoles[] = $role[$roleId];
1534 $event['participant_role'] = implode(', ', $selectedRoles);
1537 $event['participant_role'] = CRM_Utils_Array
::value($participantRoles, $role);
1539 $event['is_monetary'] = $this->_isPaidEvent
;
1541 if ($params['receipt_text']) {
1542 $event['confirm_email_text'] = $params['receipt_text'];
1545 $this->assign('isAmountzero', 1);
1546 $this->assign('event', $event);
1548 $this->assign('isShowLocation', $event['is_show_location']);
1549 if (CRM_Utils_Array
::value('is_show_location', $event) == 1) {
1550 $locationParams = array(
1551 'entity_id' => $params['event_id'],
1552 'entity_table' => 'civicrm_event',
1554 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
1555 $this->assign('location', $location);
1558 $status = CRM_Event_PseudoConstant
::participantStatus();
1559 if ($this->_isPaidEvent
) {
1560 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
1561 if (!$this->_mode
) {
1562 if (isset($params['payment_instrument_id'])) {
1563 $this->assign('paidBy',
1564 CRM_Utils_Array
::value($params['payment_instrument_id'],
1571 $this->assign('totalAmount', $contributionParams['total_amount']);
1573 $this->assign('isPrimary', 1);
1574 $this->assign('checkNumber', CRM_Utils_Array
::value('check_number', $params));
1577 if (CRM_Utils_Array
::value('billing_first_name', $params)) {
1578 $name = $params['billing_first_name'];
1581 if (CRM_Utils_Array
::value('billing_middle_name', $params)) {
1582 $name .= " {$params['billing_middle_name']}";
1585 if (CRM_Utils_Array
::value('billing_last_name', $params)) {
1586 $name .= " {$params['billing_last_name']}";
1588 $this->assign('billingName', $name);
1590 // assign the address formatted up for display
1591 $addressParts = array(
1592 "street_address-{$this->_bltID}",
1593 "city-{$this->_bltID}",
1594 "postal_code-{$this->_bltID}",
1595 "state_province-{$this->_bltID}",
1596 "country-{$this->_bltID}",
1598 $addressFields = array();
1599 foreach ($addressParts as $part) {
1600 list($n, $id) = explode('-', $part);
1601 if (isset($this->_params
['billing_' . $part])) {
1602 $addressFields[$n] = $this->_params
['billing_' . $part];
1605 $this->assign('address', CRM_Utils_Address
::format($addressFields));
1607 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
1608 $date = CRM_Utils_Date
::mysqlToIso($date);
1609 $this->assign('credit_card_exp_date', $date);
1610 $this->assign('credit_card_number',
1611 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
1613 $this->assign('credit_card_type', $params['credit_card_type']);
1614 $this->assign('contributeMode', 'direct');
1615 $this->assign('isAmountzero', 0);
1616 $this->assign('is_pay_later', 0);
1617 $this->assign('isPrimary', 1);
1620 $this->assign('register_date', $params['register_date']);
1621 if ($params['receive_date']) {
1622 $this->assign('receive_date', $params['receive_date']);
1625 $participant = array(array('participant_id', '=', $participants[0]->id
, 0, 0));
1626 // check whether its a test drive ref CRM-3075
1627 if (CRM_Utils_Array
::value('is_test', $this->_defaultValues
)) {
1628 $participant[] = array('participant_test', '=', 1, 0, 0);
1631 $template = CRM_Core_Smarty
::singleton();
1632 $customGroup = array();
1633 //format submitted data
1634 foreach ($params['custom'] as $fieldID => $values) {
1635 foreach ($values as $fieldValue) {
1636 $customValue = array('data' => $fieldValue['value']);
1637 $customFields[$fieldID]['id'] = $fieldID;
1638 $formattedValue = CRM_Core_BAO_CustomGroup
::formatCustomValues($customValue, $customFields[$fieldID], TRUE);
1639 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace(' ', '', $formattedValue);
1643 foreach ($this->_contactIds
as $num => $contactID) {
1644 // Retrieve the name and email of the contact - this will be the TO for receipt email
1645 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($contactID);
1647 $this->_contributorDisplayName
= ($this->_contributorDisplayName
== ' ') ?
$this->_contributorEmail
: $this->_contributorDisplayName
;
1649 $waitStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
1650 if ($waitingStatus = CRM_Utils_Array
::value($params['status_id'], $waitStatus)) {
1651 $this->assign('isOnWaitlist', TRUE);
1654 $this->assign('customGroup', $customGroup);
1655 $this->assign('contactID', $contactID);
1656 $this->assign('participantID', $participants[$num]->id
);
1658 $this->_id
= $participants[$num]->id
;
1660 if ($this->_isPaidEvent
) {
1661 // fix amount for each of participants ( for bulk mode )
1662 $eventAmount = array();
1663 if (!empty($additionalParticipantDetails)) {
1664 $params['amount_level'] = preg_replace('/\ 1/', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName
;
1667 $eventAmount[$num] = array(
1668 'label' => preg_replace('/\ 1/', '', $params['amount_level']),
1669 'amount' => $params['fee_amount'],
1671 //as we are using same template for online & offline registration.
1672 //So we have to build amount as array.
1673 $eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
1674 $this->assign('amount', $eventAmount);
1677 $sendTemplateParams = array(
1678 'groupName' => 'msg_tpl_workflow_event',
1679 'valueName' => 'event_offline_receipt',
1680 'contactId' => $contactID,
1681 'isTest' => (bool) CRM_Utils_Array
::value('is_test', $this->_defaultValues
),
1684 // try to send emails only if email id is present
1685 // and the do-not-email option is not checked for that contact
1686 if ($this->_contributorEmail
and !$this->_toDoNotEmail
) {
1687 $sendTemplateParams['from'] = $receiptFrom;
1688 $sendTemplateParams['toName'] = $this->_contributorDisplayName
;
1689 $sendTemplateParams['toEmail'] = $this->_contributorEmail
;
1690 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc', $this->_fromEmails
);
1691 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc', $this->_fromEmails
);
1694 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates
::sendTemplate($sendTemplateParams);
1696 $sent[] = $contactID;
1697 foreach ($participants as $ids => $values) {
1698 if ($values->contact_id
== $contactID) {
1699 CRM_Activity_BAO_Activity
::addActivity($values, 'Email');
1705 $notSent[] = $contactID;
1710 // set the participant id if it is not set
1712 $this->_id
= $participants[0]->id
;
1715 if (($this->_action
& CRM_Core_Action
::UPDATE
)) {
1716 $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contributorDisplayName
));
1717 if (CRM_Utils_Array
::value('send_receipt', $params) && count($sent)) {
1718 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', array(1 => $this->_contributorEmail
));
1721 if ($updateStatusMsg) {
1722 $statusMsg = "{$statusMsg} {$updateStatusMsg}";
1725 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
1726 if ($this->_single
) {
1727 $statusMsg = ts('Event registration for %1 has been added.', array(1 => $this->_contributorDisplayName
));
1728 if (CRM_Utils_Array
::value('send_receipt', $params) && count($sent)) {
1729 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $this->_contributorEmail
));
1733 $statusMsg = ts('Total Participant(s) added to event: %1.', array(1 => count($this->_contactIds
)));
1734 if (count($notSent) > 0) {
1735 $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)));
1737 elseif (isset($params['send_receipt'])) {
1738 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');
1742 CRM_Core_Session
::setStatus($statusMsg, ts('Saved'), 'success');
1744 $buttonName = $this->controller
->getButtonName();
1745 if ($this->_context
== 'standalone') {
1746 if ($buttonName == $this->getButtonName('upload', 'new')) {
1747 $urlParams = 'reset=1&action=add&context=standalone';
1749 $urlParams .= '&mode=' . $this->_mode
;
1752 $urlParams .= '&eid=' . $this->_eID
;
1754 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/participant/add', $urlParams));
1757 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
1758 "reset=1&cid={$this->_contactId}&selectedChild=participant"
1762 elseif ($buttonName == $this->getButtonName('upload', 'new')) {
1763 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view/participant',
1764 "reset=1&action=add&context={$this->_context}&cid={$this->_contactId}"