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->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
234 $this->_id
, 'id', 'participant_id'
236 // CRM-12615 - Get payment information from the primary registration
237 if ((!$this->_paymentId
) && ($this->_action
== CRM_Core_Action
::UPDATE
)) {
238 $registered_by_id = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
239 $this->_id
, 'registered_by_id', 'id'
241 if ($registered_by_id) {
242 $this->_paymentId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
243 $registered_by_id, 'id', 'participant_id'
245 $this->assign('registeredByParticipantId', $registered_by_id);
250 // get the option value for custom data type
251 $this->_roleCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantRole', 'name');
252 $this->_eventNameCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantEventName', 'name');
253 $this->_eventTypeCustomDataTypeID
= CRM_Core_OptionGroup
::getValue('custom_data_type', 'ParticipantEventType', 'name');
254 $this->assign('roleCustomDataTypeID', $this->_roleCustomDataTypeID
);
255 $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID
);
256 $this->assign('eventTypeCustomDataTypeID', $this->_eventTypeCustomDataTypeID
);
259 $this->assign('participantMode', $this->_mode
);
261 $this->_paymentProcessor
= array('billing_mode' => 1);
263 $validProcessors = array();
264 $processors = CRM_Core_PseudoConstant
::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )");
266 foreach ($processors as $ppID => $label) {
267 $paymentProcessor = CRM_Financial_BAO_PaymentProcessor
::getPayment($ppID, $this->_mode
);
268 if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) {
271 elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode
== 'live') {
275 $paymentObject = CRM_Core_Payment
::singleton($this->_mode
, $paymentProcessor, $this);
276 $error = $paymentObject->checkConfig();
278 $validProcessors[$ppID] = $label;
280 $paymentObject = NULL;
283 if (empty($validProcessors)) {
284 CRM_Core_Error
::fatal(ts('Could not find valid payment processor for this page'));
287 $this->_processors
= $validProcessors;
289 // also check for billing information
290 // get the billing location type
291 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
292 // CRM-8108 remove ts around Billing location type
293 //$this->_bltID = array_search( ts('Billing'), $locationTypes );
294 $this->_bltID
= array_search('Billing', $locationTypes);
295 if (!$this->_bltID
) {
296 CRM_Core_Error
::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
298 $this->set('bltID', $this->_bltID
);
299 $this->assign('bltID', $this->_bltID
);
301 $this->_fields
= array();
303 CRM_Core_Payment_Form
::setCreditCardFields($this);
305 // this required to show billing block
306 $this->assign_by_ref('paymentProcessor', $paymentProcessor);
307 $this->assign('hidePayPalExpress', TRUE);
310 if ($this->_showFeeBlock
) {
311 $this->assign('showFeeBlock', TRUE);
312 $isMonetary = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_showFeeBlock
, 'is_monetary');
314 $this->assign('feeBlockPaid', TRUE);
316 return CRM_Event_Form_EventFees
::preProcess($this);
319 //custom data related code
320 $this->_cdType
= CRM_Utils_Array
::value('type', $_GET);
321 $this->assign('cdType', FALSE);
322 if ($this->_cdType
) {
323 $this->assign('cdType', TRUE);
324 return CRM_Custom_Form_CustomData
::preProcess($this, NULL, NULL, NULL, NULL, NULL, TRUE);
327 //check the mode when this form is called either single or as
329 if ($this->_id ||
$this->_contactId ||
$this->_context
== 'standalone') {
330 $this->_single
= TRUE;
331 $this->assign('urlPath', 'civicrm/contact/view/participant');
332 if (!$this->_id
&& !$this->_contactId
) {
333 $breadCrumbs = array(array('title' => ts('CiviEvent Dashboard'),
334 'url' => CRM_Utils_System
::url('civicrm/event', 'reset=1'),
337 CRM_Utils_System
::appendBreadCrumb($breadCrumbs);
341 //set the appropriate action
342 $context = $this->get('context');
343 $urlString = 'civicrm/contact/search';
344 $this->_action
= CRM_Core_Action
::BASIC
;
347 $urlString = 'civicrm/contact/search/advanced';
348 $this->_action
= CRM_Core_Action
::ADVANCED
;
352 $urlString = 'civicrm/contact/search/builder';
353 $this->_action
= CRM_Core_Action
::PROFILE
;
357 $urlString = 'civicrm/contact/search/basic';
358 $this->_action
= CRM_Core_Action
::BASIC
;
362 $urlString = 'civicrm/contact/search/custom';
363 $this->_action
= CRM_Core_Action
::COPY
;
366 parent
::preProcess();
368 $this->_single
= FALSE;
369 $this->_contactId
= NULL;
371 //set ajax path, this used for custom data building
372 $this->assign('urlPath', $urlString);
373 $this->assign('urlPathVar', "_qf_Participant_display=true&qfKey={$this->controller->_key}");
376 $this->assign('single', $this->_single
);
379 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'add');
381 $this->assign('action', $this->_action
);
383 // check for edit permission
384 if (!CRM_Core_Permission
::checkActionPermission('CiviEvent', $this->_action
)) {
385 CRM_Core_Error
::fatal(ts('You do not have permission to access this page'));
388 if ($this->_action
& CRM_Core_Action
::DELETE
) {
389 // check delete permission for contribution
390 if ($this->_id
&& $this->_paymentId
&& !CRM_Core_Permission
::checkActionPermission('CiviContribute', $this->_action
)) {
391 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."));
397 // assign participant id to the template
398 $this->assign('participantId', $this->_id
);
399 $this->_roleId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'role_id');
402 // when fee amount is included in form
403 if (CRM_Utils_Array
::value('hidden_feeblock', $_POST)
404 || CRM_Utils_Array
::value('send_receipt', $_POST)
406 CRM_Event_Form_EventFees
::preProcess($this);
407 CRM_Event_Form_EventFees
::buildQuickForm($this);
408 CRM_Event_Form_EventFees
::setDefaultValues($this);
411 // when custom data is included in this page
412 if (CRM_Utils_Array
::value('hidden_custom', $_POST)) {
413 //custom data of type participant role
414 if (CRM_Utils_Array
::value('role_id', $_POST)) {
415 foreach ($_POST['role_id'] as $k => $val) {
417 CRM_Custom_Form_CustomData
::preProcess($this, $this->_roleCustomDataTypeID
, $k, 1, 'Participant', $this->_id
);
418 CRM_Custom_Form_CustomData
::buildQuickForm($this);
419 CRM_Custom_Form_CustomData
::setDefaultValues($this);
423 //custom data of type participant event
424 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventNameCustomDataTypeID
, $_POST['event_id'], 1, 'Participant', $this->_id
);
425 CRM_Custom_Form_CustomData
::buildQuickForm($this);
426 CRM_Custom_Form_CustomData
::setDefaultValues($this);
428 // custom data of type participant event type
430 if ($eventId = CRM_Utils_Array
::value('event_id', $_POST)) {
431 $eventTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'event_type_id', 'id');
433 CRM_Custom_Form_CustomData
::preProcess($this, $this->_eventTypeCustomDataTypeID
, $eventTypeId,
434 1, 'Participant', $this->_id
436 CRM_Custom_Form_CustomData
::buildQuickForm($this);
437 CRM_Custom_Form_CustomData
::setDefaultValues($this);
439 //custom data of type participant, ( we 'null' to reset subType and subName)
440 CRM_Custom_Form_CustomData
::preProcess($this, 'null', 'null', 1, 'Participant', $this->_id
);
441 CRM_Custom_Form_CustomData
::buildQuickForm($this);
442 CRM_Custom_Form_CustomData
::setDefaultValues($this);
445 // CRM-4395, get the online pending contribution id.
446 $this->_onlinePendingContributionId
= NULL;
447 if (!$this->_mode
&& $this->_id
&& ($this->_action
& CRM_Core_Action
::UPDATE
)) {
448 $this->_onlinePendingContributionId
= CRM_Contribute_BAO_Contribution
::checkOnlinePendingContribution($this->_id
,
452 $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId
);
453 $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 (CRM_Utils_Array
::value('participant_registered_by_id', $defaults[$this->_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 (CRM_Utils_Array
::value('event_id', $defaults[$this->_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 (CRM_Utils_Array
::value(0, $submittedRole)) {
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 (CRM_Utils_Array
::value('participant_role_id', $defaults[$this->_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 if ($this->_showFeeBlock
) {
669 return CRM_Event_Form_EventFees
::buildQuickForm($this);
672 if ($this->_cdType
) {
673 return CRM_Custom_Form_CustomData
::buildQuickForm($this);
676 //need to assign custom data type to the template
677 $this->assign('customDataType', 'Participant');
679 $this->applyFilter('__ALL__', 'trim');
681 if ($this->_action
& CRM_Core_Action
::DELETE
) {
682 if ($this->_single
) {
683 $additionalParticipant = count(CRM_Event_BAO_Event
::buildCustomProfile($this->_id
,
689 if ($additionalParticipant) {
690 $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'),
691 2 => ts('Delete only this participant record.'),
693 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
694 $this->setDefaults(array('delete_participant' => 1));
695 $this->assign('additionalParticipant', $additionalParticipant);
698 $this->addButtons(array(
701 'name' => ts('Delete'),
702 'spacing' => ' ',
707 'name' => ts('Cancel'),
715 if ($this->_single
) {
716 $urlPath = 'civicrm/contact/view/participant';
717 $urlParams = "reset=1&cid={$this->_contactId}&context=participant";
718 if ($this->_context
== 'standalone') {
719 CRM_Contact_Form_NewContact
::buildQuickForm($this);
720 $urlParams = 'reset=1&context=standalone';
721 $urlPath = 'civicrm/participant/add';
725 $urlParams .= "&action=update&id={$this->_id}";
728 $urlParams .= "&action=add";
732 $urlParams .= "&mode={$this->_mode}";
735 $url = CRM_Utils_System
::url($urlPath, $urlParams,
740 $currentPath = CRM_Utils_System
::currentPath();
742 $url = CRM_Utils_System
::url($currentPath, '_qf_Participant_display=true',
747 $this->assign('refreshURL', $url);
749 $this->add('hidden', 'past_event');
753 $eventEndDate = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_eID
,'end_date');
755 $this->assign('past', 0);
756 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
757 $events = CRM_Event_BAO_Event
::getEvents(1, FALSE, FALSE);
759 elseif ($this->getElementValue('past_event') ||
(isset($eventEndDate) && (CRM_Utils_Date
::currentDBDate() > CRM_Utils_Date
::processDate($eventEndDate)))) {
760 $pastval = $this->getElementValue('past_event');
761 $events = CRM_Event_BAO_Event
::getEvents($pastval);
762 $this->assign('past', $pastval);
765 $events = CRM_Event_BAO_Event
::getEvents();
769 //unset the event which are not monetary when credit card
770 //event registration is used
771 foreach ($events as $key => $val) {
772 $isPaid = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $key, 'is_monetary');
774 unset($events[$key]);
777 $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors
, TRUE);
780 // build array(event -> eventType) mapper
782 SELECT civicrm_event.id as id, civicrm_event.event_type_id as event_type_id
784 WHERE civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0";
785 $dao = CRM_Core_DAO
::executeQuery($query);
786 $eventAndTypeMapping = array();
787 while ($dao->fetch()) {
788 $eventAndTypeMapping[$dao->id
] = $dao->event_type_id
;
790 $eventAndTypeMapping = json_encode($eventAndTypeMapping);
791 // building of mapping ends --
793 //inherit the campaign from event.
794 $eventCampaigns = array();
795 $allEventIds = array_keys($events);
796 if (!empty($allEventIds)) {
797 CRM_Core_PseudoConstant
::populate($eventCampaigns,
798 'CRM_Event_DAO_Event',
802 $eventCampaigns = json_encode($eventCampaigns);
804 $element = $this->add('select', 'event_id', ts('Event'),
806 '' => ts('- select -')) +
$events,
808 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')
812 // note that embedding JS within PHP files is quite awful, IMO
813 // but we do the same for the onChange element and this form is complex
814 // and i did not want to break it late in the 3.2 cycle
815 $preloadJSSnippet = NULL;
816 if (CRM_Utils_Array
::value('reset', $_GET) && $this->_eID
) {
817 $preloadJSSnippet = "
819 cj('#event_id').val( '{$this->_eID}' );
820 buildFeeBlock( {$this->_eID} );
821 CRM.buildCustomData( 'Participant', {$this->_eID}, {$this->_eventNameCustomDataTypeID} );
822 buildEventTypeCustomData( {$this->_eID}, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' );
823 loadCampaign( {$this->_eID}, {$eventCampaigns} );
828 $this->assign('preloadJSSnippet', $preloadJSSnippet);
831 //frozen the field fix for CRM-4171
832 if ($this->_action
& CRM_Core_Action
::UPDATE
&& $this->_id
) {
833 if (CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
834 $this->_id
, 'contribution_id', 'participant_id'
840 //CRM-7362 --add campaigns.
843 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_id
, 'campaign_id');
846 $eventId = CRM_Utils_Request
::retrieve('eid', 'Positive', $this);
848 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
851 CRM_Campaign_BAO_Campaign
::addCampaign($this, $campaignId);
853 $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
856 $this->assign('entityID', $this->_id
);
859 $roleids = CRM_Event_PseudoConstant
::participantRole();
861 foreach ($roleids as $rolekey => $rolevalue) {
862 $roleTypes[] = $this->createElement('checkbox', $rolekey, NULL, $rolevalue,
863 array('onclick' => "showCustomData( 'Participant', {$rolekey}, {$this->_roleCustomDataTypeID} );")
867 $this->addGroup($roleTypes, 'role_id', ts('Participant Role'));
868 $this->addRule('role_id', ts('Role is required'), 'required');
871 $checkCancelledJs = array('onchange' => "return sendNotification( );");
873 if ($this->_onlinePendingContributionId
) {
874 $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant
::participantStatus());
875 $cancelledContributionStatusId = array_search('Cancelled',
876 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
878 $checkCancelledJs = array(
880 "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});",
883 $participantStatusId = array_search('Pending from pay later',
884 CRM_Event_PseudoConstant
::participantStatus()
886 $contributionStatusId = array_search('Completed',
887 CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name')
889 $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
892 // get the participant status names to build special status array which is used to show notification
893 // checkbox below participant status select
894 $participantStatusName = CRM_Event_PseudoConstant
::participantStatus();
895 $notificationStatuses = array(
897 'Pending from waitlist',
898 'Pending from approval',
902 // get the required status and then implode only ids
903 $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
904 $this->assign('notificationStatusIds', $notificationStatusIds);
906 $this->_participantStatuses
= CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label');
907 $this->add('select', 'status_id', ts('Participant Status'),
909 '' => ts('- select -')) +
$this->_participantStatuses
,
914 $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
916 $this->add('text', 'source', ts('Event Source'));
917 $noteAttributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Note');
918 $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
922 'name' => ts('Save'),
927 $path = CRM_Utils_System
::currentPath();
928 $excludeForPaths = array(
929 'civicrm/contact/search',
930 'civicrm/group/search'
932 if (!in_array($path, $excludeForPaths)) {
935 'name' => ts('Save and New'),
943 'name' => ts('Cancel'),
946 $this->addButtons($buttons);
947 if ($this->_action
== CRM_Core_Action
::VIEW
) {
953 * Add local and global form rules
959 function addRules() {
960 $this->addFormRule(array('CRM_Event_Form_Participant', 'formRule'), $this);
964 * global validation rules for the form
966 * @param array $fields posted values of the form
968 * @return array list of errors to be posted back to the form
972 static function formRule($values, $files, $self) {
973 // If $values['_qf_Participant_next'] is Delete or
974 // $values['event_id'] is empty, then return
975 // instead of proceeding further.
977 if ((CRM_Utils_Array
::value('_qf_Participant_next', $values) == 'Delete') ||
978 (!$values['event_id'])
984 //check if contact is selected in standalone mode
985 if (isset($values['contact_select_id'][1]) && !$values['contact_select_id'][1]) {
986 $errorMsg['contact[1]'] = ts('Please select a contact or create new contact');
989 if (CRM_Utils_Array
::value('payment_processor_id', $values)) {
990 // make sure that credit card number and cvv are valid
991 CRM_Core_Payment_Form
::validateCreditCard($values, $errorMsg);
994 if (CRM_Utils_Array
::value('record_contribution', $values)) {
995 if (!CRM_Utils_Array
::value('financial_type_id', $values)) {
996 $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
998 if (!CRM_Utils_Array
::value('payment_instrument_id', $values)) {
999 $errorMsg['payment_instrument_id'] = ts('Paid By is a required field.');
1003 // validate contribution status for 'Failed'.
1004 if ($self->_onlinePendingContributionId
&&
1005 CRM_Utils_Array
::value('record_contribution', $values) &&
1006 (CRM_Utils_Array
::value('contribution_status_id', $values) ==
1007 array_search('Failed', CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name'))
1010 $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.');
1013 // do the amount validations.
1014 //skip for update mode since amount is freeze, CRM-6052
1016 !CRM_Utils_Array
::value('total_amount', $values) &&
1017 empty($self->_values
['line_items'])
1019 ($self->_id
&& !$self->_paymentId
&& isset($self->_values
['line_items']) && is_array($self->_values
['line_items']))
1021 if ($priceSetId = CRM_Utils_Array
::value('priceSetId', $values)) {
1022 CRM_Price_BAO_PriceField
::priceSetValidation($priceSetId, $values, $errorMsg, TRUE);
1025 return CRM_Utils_Array
::crmIsEmptyArray($errorMsg) ?
TRUE : $errorMsg;
1029 * Function to process the form
1033 public function postProcess() {
1034 // get the submitted form values.
1035 $params = $this->controller
->exportValues($this->_name
);
1037 if ($this->_action
& CRM_Core_Action
::DELETE
) {
1038 if (CRM_Utils_Array
::value('delete_participant', $params) == 2) {
1039 $additionalId = (CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
));
1040 $participantLinks = (CRM_Event_BAO_Participant
::getAdditionalParticipantUrl($additionalId));
1042 if (CRM_Utils_Array
::value('delete_participant', $params) == 1) {
1043 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
1044 foreach ($additionalIds as $value) {
1045 CRM_Event_BAO_Participant
::deleteParticipant($value);
1048 CRM_Event_BAO_Participant
::deleteParticipant($this->_id
);
1049 CRM_Core_Session
::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success');
1050 if (!empty($participantLinks)) {
1051 $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;
1052 CRM_Core_Session
::setStatus($status, ts('Group Payment Deleted'));
1057 // set the contact, when contact is selected
1058 if (CRM_Utils_Array
::value('contact_select_id', $params)) {
1059 $this->_contactId
= $params['contact_select_id'][1];
1061 if ($this->_priceSetId
&& $isQuickConfig = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId
, 'is_quick_config')) {
1062 $this->_quickConfig
= $isQuickConfig;
1066 $params['id'] = $this->_id
;
1069 $config = CRM_Core_Config
::singleton();
1070 if ($this->_isPaidEvent
) {
1072 $contributionParams = array();
1073 $lineItem = array();
1074 $additionalParticipantDetails = array();
1075 if (($this->_id
&& $this->_action
& CRM_Core_Action
::UPDATE
) && $this->_paymentId
) {
1076 $participantBAO = new CRM_Event_BAO_Participant();
1077 $participantBAO->id
= $this->_id
;
1078 $participantBAO->find(TRUE);
1079 $contributionParams['total_amount'] = $participantBAO->fee_amount
;
1081 $params['discount_id'] = NULL;
1082 //re-enter the values for UPDATE mode
1083 $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level
;
1084 $params['fee_amount'] = $participantBAO->fee_amount
;
1085 if (isset($params['priceSetId'])) {
1086 $lineItem[0] = CRM_Price_BAO_LineItem
::getLineItems($this->_id
);
1088 //also add additional participant's fee level/priceset
1089 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_id
)) {
1090 $additionalIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_id
);
1091 $hasLineItems = CRM_Utils_Array
::value('priceSetId', $params, FALSE);
1092 $additionalParticipantDetails = CRM_Event_BAO_Participant
::getFeeDetails($additionalIds,
1099 //check if discount is selected
1100 if (CRM_Utils_Array
::value('discount_id', $params)) {
1101 $discountId = $params['discount_id'];
1104 $discountId = $params['discount_id'] = 'null';
1107 //lets carry currency, CRM-4453
1108 $params['fee_currency'] = $config->defaultCurrency
;
1109 CRM_Price_BAO_PriceSet
::processAmount($this->_values
['fee'],
1110 $params, $lineItem[0]
1112 //CRM-11529 for quick config backoffice transactions
1113 //when financial_type_id is passed in form, update the
1114 //lineitems with the financial type selected in form
1115 $submittedFinancialType = CRM_Utils_Array
::value('financial_type_id', $params);
1116 $isPaymentRecorded = CRM_Utils_Array
::value('record_contribution', $params);
1117 if ($isPaymentRecorded && $this->_quickConfig
&& $submittedFinancialType) {
1118 foreach ($lineItem[0] as &$values) {
1119 $values['financial_type_id'] = $submittedFinancialType;
1123 $params['fee_level'] = $params['amount_level'];
1124 $contributionParams['total_amount'] = $params['amount'];
1125 if ($this->_quickConfig
&& CRM_Utils_Array
::value('total_amount', $params)) {
1126 $params['fee_amount'] = $params['total_amount'];
1129 $params['fee_amount'] = $params['amount'];
1133 if (isset($params['priceSetId'])) {
1134 if (!empty($lineItem[0])) {
1135 $this->set('lineItem', $lineItem);
1137 $this->_lineItem
= $lineItem;
1138 $lineItem = array_merge($lineItem, $additionalParticipantDetails);
1140 $participantCount = array();
1141 foreach ($lineItem as $k) {
1142 foreach ($k as $v) {
1143 if (CRM_Utils_Array
::value('participant_count', $v) > 0) {
1144 $participantCount[] = $v['participant_count'];
1149 if (isset($participantCount)) {
1150 $this->assign('pricesetFieldsCount', $participantCount);
1152 $this->assign('lineItem', empty($lineItem[0]) ||
$this->_quickConfig?
FALSE : $lineItem);
1155 $this->assign('amount_level', $params['amount_level']);
1159 $this->_params
= $params;
1160 unset($params['amount']);
1161 $params['register_date'] = CRM_Utils_Date
::processDate($params['register_date'], $params['register_date_time']);
1162 $params['receive_date'] = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('receive_date', $params));
1163 $params['contact_id'] = $this->_contactId
;
1165 // overwrite actual payment amount if entered
1166 if (CRM_Utils_Array
::value('total_amount', $params)) {
1167 $contributionParams['total_amount'] = CRM_Utils_Array
::value('total_amount', $params);
1171 // Retrieve the name and email of the current user - this will be the FROM for the receipt email
1172 $session = CRM_Core_Session
::singleton();
1173 $userID = $session->get('userID');
1176 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($userID);
1178 if ($this->_contactId
) {
1179 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($this->_contactId
);
1183 if (!$this->_isPaidEvent
) {
1184 CRM_Core_Error
::fatal(ts('Selected Event is not Paid Event '));
1186 //modify params according to parameter used in create
1187 //participant method (addParticipant)
1188 $this->_params
['participant_status_id'] = $params['status_id'];
1189 $this->_params
['participant_role_id'] = $params['role_id'];
1190 $this->_params
['participant_register_date'] = $params['register_date'];
1193 CRM_Core_DAO
::getFieldValue(
1194 'CRM_Event_DAO_Event',
1195 $params['event_id'],
1199 // set source if not set
1200 if (empty($params['source'])) {
1201 $this->_params
['participant_source'] = ts('Offline Registration for Event: %2 by: %1', array(1 => $userName, 2 => $eventTitle));
1204 $this->_params
['participant_source'] = $params['source'];
1206 $this->_params
['description'] = $this->_params
['participant_source'];
1208 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($this->_params
['payment_processor_id'],
1211 $now = date('YmdHis');
1214 // set email for primary location.
1215 $fields['email-Primary'] = 1;
1216 $params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail
;
1218 $params['register_date'] = $now;
1220 // now set the values for the billing location.
1221 foreach ($this->_fields
as $name => $dontCare) {
1225 // also add location name to the array
1226 $params["address_name-{$this->_bltID}"] =
1227 CRM_Utils_Array
::value('billing_first_name', $params) . ' ' .
1228 CRM_Utils_Array
::value('billing_middle_name', $params) . ' ' .
1229 CRM_Utils_Array
::value('billing_last_name', $params);
1231 $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
1232 $fields["address_name-{$this->_bltID}"] = 1;
1233 $fields["email-{$this->_bltID}"] = 1;
1234 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'contact_type');
1236 $nameFields = array('first_name', 'middle_name', 'last_name');
1238 foreach ($nameFields as $name) {
1240 if (array_key_exists("billing_$name", $params)) {
1241 $params[$name] = $params["billing_{$name}"];
1242 $params['preserveDBName'] = TRUE;
1245 $contactID = CRM_Contact_BAO_Contact
::createProfileContact($params, $fields, $this->_contactId
, NULL, NULL, $ctype);
1248 $roleAllIds = CRM_Utils_Array
::value('role_id', $params);
1250 foreach ($roleAllIds as $rkey => $rvalue) {
1251 $customFieldsRole = CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, $rkey, $this->_roleCustomDataTypeID
);
1252 $customFieldsEvent = CRM_Core_BAO_CustomField
::getFields('Participant',
1255 CRM_Utils_Array
::value('event_id', $params),
1256 $this->_eventNameCustomDataTypeID
1258 $customFieldsEventType = CRM_Core_BAO_CustomField
::getFields('Participant',
1261 $this->_eventTypeId
,
1262 $this->_eventTypeCustomDataTypeID
1264 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsRole,
1265 CRM_Core_BAO_CustomField
::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE)
1267 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEvent, $customFields);
1268 $customFields = CRM_Utils_Array
::crmArrayMerge($customFieldsEventType, $customFields);
1269 $params['custom'] = CRM_Core_BAO_CustomField
::postProcess($params,
1277 //do cleanup line items if participant edit the Event Fee.
1278 if (($this->_lineItem ||
!isset($params['proceSetId'])) && !$this->_paymentId
&& $this->_id
) {
1279 CRM_Price_BAO_LineItem
::deleteLineItems($this->_id
, 'civicrm_participant');
1283 // add all the additioanl payment params we need
1284 $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}"]);
1285 $this->_params
["country-{$this->_bltID}"] = $this->_params
["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($this->_params
["billing_country_id-{$this->_bltID}"]);
1287 $this->_params
['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($this->_params
);
1288 $this->_params
['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($this->_params
);
1289 $this->_params
['ip_address'] = CRM_Utils_System
::ipAddress();
1290 $this->_params
['amount'] = $params['fee_amount'];
1291 $this->_params
['amount_level'] = $params['amount_level'];
1292 $this->_params
['currencyID'] = $config->defaultCurrency
;
1293 $this->_params
['payment_action'] = 'Sale';
1294 $this->_params
['invoiceID'] = md5(uniqid(rand(), TRUE));
1296 // at this point we've created a contact and stored its address etc
1297 // all the payment processors expect the name and address to be in the
1298 // so we copy stuff over to first_name etc.
1299 $paymentParams = $this->_params
;
1300 if (CRM_Utils_Array
::value('send_receipt', $this->_params
)) {
1301 $paymentParams['email'] = $this->_contributorEmail
;
1303 CRM_Core_Payment_Form
::mapParams($this->_bltID
, $this->_params
, $paymentParams, TRUE);
1305 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
1307 $result = &$payment->doDirectPayment($paymentParams);
1309 if (is_a($result, 'CRM_Core_Error')) {
1310 CRM_Core_Error
::displaySessionError($result);
1311 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/contact/view/participant',
1312 "reset=1&action=add&cid={$this->_contactId}&context=participant&mode={$this->_mode}"
1317 $this->_params
= array_merge($this->_params
, $result);
1320 $this->_params
['receive_date'] = $now;
1322 if (CRM_Utils_Array
::value('send_receipt', $this->_params
)) {
1323 $this->_params
['receipt_date'] = $now;
1326 $this->_params
['receipt_date'] = NULL;
1329 $this->set('params', $this->_params
);
1330 $this->assign('trxn_id', $result['trxn_id']);
1331 $this->assign('receive_date',
1332 CRM_Utils_Date
::processDate($this->_params
['receive_date'])
1335 //add contribution record
1336 $this->_params
['financial_type_id'] =
1337 CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
1338 $this->_params
['mode'] = $this->_mode
;
1340 //add contribution reocord
1341 $contributions[] = $contribution = CRM_Event_Form_Registration_Confirm
::processContribution($this, $this->_params
, $result, $contactID, FALSE);
1343 // add participant record
1344 $participants = array();
1345 if (CRM_Utils_Array
::value('participant_role_id', $this->_params
) && is_array($this->_params
['participant_role_id'])) {
1346 $this->_params
['participant_role_id'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1347 array_keys($this->_params
['participant_role_id'])
1350 $participants[] = CRM_Event_Form_Registration
::addParticipant($this->_params
, $contactID);
1352 //add custom data for participant
1353 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
1354 CRM_Core_DAO
::$_nullArray,
1355 'civicrm_participant',
1356 $participants[0]->id
,
1359 //add participant payment
1360 $paymentParticipant = array(
1361 'participant_id' => $participants[0]->id
,
1362 'contribution_id' => $contribution->id
,
1366 CRM_Event_BAO_ParticipantPayment
::create($paymentParticipant, $ids);
1367 $this->_contactIds
[] = $this->_contactId
;
1370 $participants = array();
1371 if ($this->_single
) {
1372 if ($params['role_id']) {
1373 foreach ($params['role_id'] as $k => $v) {
1376 $seperator = CRM_Core_DAO
::VALUE_SEPARATOR
;
1377 $params['role_id'] = implode($seperator, $rolesIDS);
1380 $params['role_id'] = 'NULL';
1382 $participants[] = CRM_Event_BAO_Participant
::create($params);
1385 foreach ($this->_contactIds
as $contactID) {
1386 $commonParams = $params;
1387 $commonParams['contact_id'] = $contactID;
1388 if ($commonParams['role_id']) {
1389 $rolesIDS = array();
1390 foreach ($commonParams['role_id'] as $k => $v) {
1393 $seperator = CRM_Core_DAO
::VALUE_SEPARATOR
;
1394 $commonParams['role_id'] = implode($seperator, $rolesIDS);
1395 $commonParams['participant_role_id'] = implode($seperator, $rolesIDS);
1398 $commonParams['role_id'] = 'NULL';
1400 $participants[] = CRM_Event_BAO_Participant
::create($commonParams);
1404 if (isset($params['event_id'])) {
1405 $eventTitle = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
1406 $params['event_id'],
1411 if ($this->_single
) {
1412 $this->_contactIds
[] = $this->_contactId
;
1415 $contributions = array();
1416 if (CRM_Utils_Array
::value('record_contribution', $params)) {
1417 if (CRM_Utils_Array
::value('id', $params)) {
1418 if ($this->_onlinePendingContributionId
) {
1419 $ids['contribution'] = $this->_onlinePendingContributionId
;
1422 $ids['contribution'] = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
1429 unset($params['note']);
1431 //build contribution params
1432 if (!$this->_onlinePendingContributionId
) {
1433 $contributionParams['source'] = "{$eventTitle}: Offline registration (by {$userName})";
1436 $contributionParams['currency'] = $config->defaultCurrency
;
1437 $contributionParams['non_deductible_amount'] = 'null';
1438 $contributionParams['receipt_date'] = CRM_Utils_Array
::value('send_receipt', $params) ? CRM_Utils_Array
::value('receive_date', $params) : 'null';
1440 $recordContribution = array( 'contact_id', 'financial_type_id',
1441 'payment_instrument_id', 'trxn_id',
1442 'contribution_status_id', 'receive_date',
1443 'check_number', 'campaign_id',
1446 foreach ($recordContribution as $f) {
1447 $contributionParams[$f] = CRM_Utils_Array
::value($f, $params);
1448 if ($f == 'trxn_id') {
1449 $this->assign('trxn_id', $contributionParams[$f]);
1453 //insert financial type name in receipt.
1454 $this->assign('contributionTypeName', CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id']));
1455 $contributionParams['skipLineItem'] = 1;
1457 $contributionParams['contribution_mode'] = 'participant';
1458 $contributionParams['participant_id'] = $this->_id
;
1460 // Set is_pay_later flag for back-office offline Pending status contributions
1461 if ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup
::getValue('contribution_status', 'Pending', 'name')) {
1462 $contributionParams['is_pay_later'] = 1;
1464 if ($this->_single
) {
1468 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1472 foreach ($this->_contactIds
as $contactID) {
1473 $contributionParams['contact_id'] = $contactID;
1474 $contributions[] = CRM_Contribute_BAO_Contribution
::create($contributionParams, $ids);
1478 //insert payment record for this participation
1479 if (empty($ids['contribution'])) {
1480 foreach ($this->_contactIds
as $num => $contactID) {
1481 $ppDAO = new CRM_Event_DAO_ParticipantPayment();
1482 $ppDAO->participant_id
= $participants[$num]->id
;
1483 $ppDAO->contribution_id
= $contributions[$num]->id
;
1487 // next create the transaction record
1488 $transaction = new CRM_Core_Transaction();
1491 if ($this->_quickConfig
) {
1492 if (CRM_Utils_Array
::value('amount_priceset_level_radio', $this->_params
)) {
1493 $feeLevel = $this->_params
['amount_priceset_level_radio'];
1496 $feeLevel[] = $this->_params
['fee_level'] ;
1498 CRM_Event_BAO_Participant
::createDiscountTrxn($this->_eventId
, $contributionParams, $feeLevel);
1500 $transaction->commit();
1504 // also store lineitem stuff here
1505 if ((($this->_lineItem
& $this->_action
& CRM_Core_Action
::ADD
) ||
1506 ($this->_lineItem
&& CRM_Core_Action
::UPDATE
&& !$this->_paymentId
))
1508 foreach ($this->_contactIds
as $num => $contactID) {
1509 foreach ($this->_lineItem
as $key => $value) {
1510 if (is_array($value) && $value != 'skip') {
1511 foreach ($value as $lineKey => $line) {
1512 //10117 update the line items for participants if contribution amount is recorded
1513 if ($this->_quickConfig
&& CRM_Utils_Array
::value('total_amount', $params )) {
1514 $line['unit_price'] = $line['line_total'] = $params['total_amount'];
1516 $lineItem[$this->_priceSetId
][$lineKey] = $line;
1518 CRM_Price_BAO_LineItem
::processPriceSet($participants[$num]->id
, $lineItem, CRM_Utils_Array
::value($num, $contributions, NULL), 'civicrm_participant');
1524 $updateStatusMsg = NULL;
1525 //send mail when participant status changed, CRM-4326
1526 if ($this->_id
&& $this->_statusId
&&
1527 $this->_statusId
!= CRM_Utils_Array
::value('status_id', $params) &&
1528 CRM_Utils_Array
::value('is_notify', $params)
1531 $updateStatusMsg = CRM_Event_BAO_Participant
::updateStatusMessage($this->_id
,
1532 $params['status_id'],
1539 if (CRM_Utils_Array
::value('send_receipt', $params)) {
1540 if (array_key_exists($params['from_email_address'], $this->_fromEmails
['from_email_id'])) {
1541 $receiptFrom = $params['from_email_address'];
1544 $this->assign('module', 'Event Registration');
1545 //use of the message template below requires variables in different format
1546 $event = $events = array();
1547 $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
1549 //get all event details.
1550 CRM_Core_DAO
::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
1551 $event = $events[$params['event_id']];
1552 unset($event['start_date']);
1553 unset($event['end_date']);
1555 $role = CRM_Event_PseudoConstant
::participantRole();
1556 $participantRoles = CRM_Utils_Array
::value('role_id', $params);
1557 if (is_array($participantRoles)) {
1558 $selectedRoles = array();
1559 foreach (array_keys($participantRoles) as $roleId) {
1560 $selectedRoles[] = $role[$roleId];
1562 $event['participant_role'] = implode(', ', $selectedRoles);
1565 $event['participant_role'] = CRM_Utils_Array
::value($participantRoles, $role);
1567 $event['is_monetary'] = $this->_isPaidEvent
;
1569 if ($params['receipt_text']) {
1570 $event['confirm_email_text'] = $params['receipt_text'];
1573 $this->assign('isAmountzero', 1);
1574 $this->assign('event', $event);
1576 $this->assign('isShowLocation', $event['is_show_location']);
1577 if (CRM_Utils_Array
::value('is_show_location', $event) == 1) {
1578 $locationParams = array(
1579 'entity_id' => $params['event_id'],
1580 'entity_table' => 'civicrm_event',
1582 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
1583 $this->assign('location', $location);
1586 $status = CRM_Event_PseudoConstant
::participantStatus();
1587 if ($this->_isPaidEvent
) {
1588 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
1589 if (!$this->_mode
) {
1590 if (isset($params['payment_instrument_id'])) {
1591 $this->assign('paidBy',
1592 CRM_Utils_Array
::value($params['payment_instrument_id'],
1599 $this->assign('totalAmount', $contributionParams['total_amount']);
1601 $this->assign('isPrimary', 1);
1602 $this->assign('checkNumber', CRM_Utils_Array
::value('check_number', $params));
1605 if (CRM_Utils_Array
::value('billing_first_name', $params)) {
1606 $name = $params['billing_first_name'];
1609 if (CRM_Utils_Array
::value('billing_middle_name', $params)) {
1610 $name .= " {$params['billing_middle_name']}";
1613 if (CRM_Utils_Array
::value('billing_last_name', $params)) {
1614 $name .= " {$params['billing_last_name']}";
1616 $this->assign('billingName', $name);
1618 // assign the address formatted up for display
1619 $addressParts = array(
1620 "street_address-{$this->_bltID}",
1621 "city-{$this->_bltID}",
1622 "postal_code-{$this->_bltID}",
1623 "state_province-{$this->_bltID}",
1624 "country-{$this->_bltID}",
1626 $addressFields = array();
1627 foreach ($addressParts as $part) {
1628 list($n, $id) = explode('-', $part);
1629 if (isset($this->_params
['billing_' . $part])) {
1630 $addressFields[$n] = $this->_params
['billing_' . $part];
1633 $this->assign('address', CRM_Utils_Address
::format($addressFields));
1635 $date = CRM_Utils_Date
::format($params['credit_card_exp_date']);
1636 $date = CRM_Utils_Date
::mysqlToIso($date);
1637 $this->assign('credit_card_exp_date', $date);
1638 $this->assign('credit_card_number',
1639 CRM_Utils_System
::mungeCreditCard($params['credit_card_number'])
1641 $this->assign('credit_card_type', $params['credit_card_type']);
1642 $this->assign('contributeMode', 'direct');
1643 $this->assign('isAmountzero', 0);
1644 $this->assign('is_pay_later', 0);
1645 $this->assign('isPrimary', 1);
1648 $this->assign('register_date', $params['register_date']);
1649 if ($params['receive_date']) {
1650 $this->assign('receive_date', $params['receive_date']);
1653 $participant = array(array('participant_id', '=', $participants[0]->id
, 0, 0));
1654 // check whether its a test drive ref CRM-3075
1655 if (CRM_Utils_Array
::value('is_test', $this->_defaultValues
)) {
1656 $participant[] = array('participant_test', '=', 1, 0, 0);
1659 $template = CRM_Core_Smarty
::singleton();
1660 $customGroup = array();
1661 //format submitted data
1662 foreach ($params['custom'] as $fieldID => $values) {
1663 foreach ($values as $fieldValue) {
1664 $customValue = array('data' => $fieldValue['value']);
1665 $customFields[$fieldID]['id'] = $fieldID;
1666 $formattedValue = CRM_Core_BAO_CustomGroup
::formatCustomValues($customValue, $customFields[$fieldID], TRUE);
1667 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace(' ', '', $formattedValue);
1671 foreach ($this->_contactIds
as $num => $contactID) {
1672 // Retrieve the name and email of the contact - this will be the TO for receipt email
1673 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($contactID);
1675 $this->_contributorDisplayName
= ($this->_contributorDisplayName
== ' ') ?
$this->_contributorEmail
: $this->_contributorDisplayName
;
1677 $waitStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
1678 if ($waitingStatus = CRM_Utils_Array
::value($params['status_id'], $waitStatus)) {
1679 $this->assign('isOnWaitlist', TRUE);
1682 $this->assign('customGroup', $customGroup);
1683 $this->assign('contactID', $contactID);
1684 $this->assign('participantID', $participants[$num]->id
);
1686 $this->_id
= $participants[$num]->id
;
1688 if ($this->_isPaidEvent
) {
1689 // fix amount for each of participants ( for bulk mode )
1690 $eventAmount = array();
1691 if (!empty($additionalParticipantDetails)) {
1692 $params['amount_level'] = preg_replace('/\ 1/', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName
;
1695 $eventAmount[$num] = array(
1696 'label' => preg_replace('/\ 1/', '', $params['amount_level']),
1697 'amount' => $params['fee_amount'],
1699 //as we are using same template for online & offline registration.
1700 //So we have to build amount as array.
1701 $eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
1702 $this->assign('amount', $eventAmount);
1705 $sendTemplateParams = array(
1706 'groupName' => 'msg_tpl_workflow_event',
1707 'valueName' => 'event_offline_receipt',
1708 'contactId' => $contactID,
1709 'isTest' => (bool) CRM_Utils_Array
::value('is_test', $this->_defaultValues
),
1710 'PDFFilename' => ts('confirmation').'.pdf',
1713 // try to send emails only if email id is present
1714 // and the do-not-email option is not checked for that contact
1715 if ($this->_contributorEmail
and !$this->_toDoNotEmail
) {
1716 $sendTemplateParams['from'] = $receiptFrom;
1717 $sendTemplateParams['toName'] = $this->_contributorDisplayName
;
1718 $sendTemplateParams['toEmail'] = $this->_contributorEmail
;
1719 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc', $this->_fromEmails
);
1720 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc', $this->_fromEmails
);
1723 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1725 $sent[] = $contactID;
1726 foreach ($participants as $ids => $values) {
1727 if ($values->contact_id
== $contactID) {
1728 CRM_Activity_BAO_Activity
::addActivity($values, 'Email');
1734 $notSent[] = $contactID;
1739 // set the participant id if it is not set
1741 $this->_id
= $participants[0]->id
;
1744 if (($this->_action
& CRM_Core_Action
::UPDATE
)) {
1745 $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contributorDisplayName
));
1746 if (CRM_Utils_Array
::value('send_receipt', $params) && count($sent)) {
1747 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', array(1 => $this->_contributorEmail
));
1750 if ($updateStatusMsg) {
1751 $statusMsg = "{$statusMsg} {$updateStatusMsg}";
1754 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
1755 if ($this->_single
) {
1756 $statusMsg = ts('Event registration for %1 has been added.', array(1 => $this->_contributorDisplayName
));
1757 if (CRM_Utils_Array
::value('send_receipt', $params) && count($sent)) {
1758 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $this->_contributorEmail
));
1762 $statusMsg = ts('Total Participant(s) added to event: %1.', array(1 => count($this->_contactIds
)));
1763 if (count($notSent) > 0) {
1764 $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)));
1766 elseif (isset($params['send_receipt'])) {
1767 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');
1771 CRM_Core_Session
::setStatus($statusMsg, ts('Saved'), 'success');
1773 $buttonName = $this->controller
->getButtonName();
1774 if ($this->_context
== 'standalone') {
1775 if ($buttonName == $this->getButtonName('upload', 'new')) {
1776 $urlParams = 'reset=1&action=add&context=standalone';
1778 $urlParams .= '&mode=' . $this->_mode
;
1781 $urlParams .= '&eid=' . $this->_eID
;
1783 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/participant/add', $urlParams));
1786 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view',
1787 "reset=1&cid={$this->_contactId}&selectedChild=participant"
1791 elseif ($buttonName == $this->getButtonName('upload', 'new')) {
1792 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/contact/view/participant',
1793 "reset=1&action=add&context={$this->_context}&cid={$this->_contactId}"