3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
38 * This class generates form components for processing Event
41 class CRM_Event_Form_Registration
extends CRM_Core_Form
{
44 * how many locationBlocks should we display?
49 CONST LOCATION_BLOCKS
= 1;
52 * the id of the event we are proceessing
60 * the array of ids of all the participant we are proceessing
65 protected $_participantIDS = NULL;
68 * the id of the participant we are proceessing
73 protected $_participantId;
76 * is participant able to walk registration wizard.
81 public $_allowConfirmation;
84 * is participant requires approval
89 public $_requireApproval;
92 * is event configured for waitlist.
97 public $_allowWaitlist;
100 * store additional participant ids
101 * when there are pre-registered.
106 public $_additionalParticipantIds;
109 * the mode that we are in
117 * the values for the contribution db object
125 * the paymentProcessor attributes for this page
130 public $_paymentProcessor;
133 * The params submitted by the form and computed by the app
141 * The fields involved in this contribution page
149 * The billing location id for this contribiution page
157 * Price Set ID, if the new price set method is used
162 public $_priceSetId = NULL;
165 * Array of fields for the price set
176 /* Is event already full.
182 public $_isEventFull;
185 public $_lineItemParticipantsCount;
186 public $_availableRegistrations;
188 public $_forcePayement;
191 * Function to set variables up before form is built
196 function preProcess() {
197 $this->_eventId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
198 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE);
201 $this->_participantId
= CRM_Utils_Request
::retrieve('participantId', 'Positive', $this);
204 $this->_mode
= ($this->_action
== 1024) ?
'test' : 'live';
206 $this->_values
= $this->get('values');
207 $this->_fields
= $this->get('fields');
208 $this->_bltID
= $this->get('bltID');
209 $this->_paymentProcessor
= $this->get('paymentProcessor');
210 $this->_priceSetId
= $this->get('priceSetId');
211 $this->_priceSet
= $this->get('priceSet');
212 $this->_lineItem
= $this->get('lineItem');
213 $this->_isEventFull
= $this->get('isEventFull');
214 $this->_lineItemParticipantsCount
= $this->get('lineItemParticipants');
215 if (!is_array($this->_lineItem
)) {
216 $this->_lineItem
= array();
218 if (!is_array($this->_lineItemParticipantsCount
)) {
219 $this->_lineItemParticipantsCount
= array();
221 $this->_availableRegistrations
= $this->get('availableRegistrations');
222 $this->_participantIDS
= $this->get('participantIDs');
224 //check if participant allow to walk registration wizard.
225 $this->_allowConfirmation
= $this->get('allowConfirmation');
227 // check for Approval
228 $this->_requireApproval
= $this->get('requireApproval');
230 // check for waitlisting.
231 $this->_allowWaitlist
= $this->get('allowWaitlist');
233 $this->_forcePayement
= $this->get('forcePayement');
235 //get the additional participant ids.
236 $this->_additionalParticipantIds
= $this->get('additionalParticipantIds');
237 $config = CRM_Core_Config
::singleton();
239 if (!$this->_values
) {
240 // create redirect URL to send folks back to event info page is registration not available
241 $infoUrl = CRM_Utils_System
::url('civicrm/event/info', "reset=1&id={$this->_eventId}",
242 FALSE, NULL, FALSE, TRUE
245 // this is the first time we are hitting this, so check for permissions here
246 if (!CRM_Core_Permission
::event(CRM_Core_Permission
::EDIT
, $this->_eventId
, 'register for events')) {
247 CRM_Core_Error
::statusBounce(ts('You do not have permission to register for this event'), $infoUrl);
250 // get all the values from the dao object
251 $this->_values
= $this->_fields
= array();
252 $this->_forcePayement
= FALSE;
254 //retrieve event information
255 $params = array('id' => $this->_eventId
);
256 CRM_Event_BAO_Event
::retrieve($params, $this->_values
['event']);
258 $this->checkValidEvent($infoUrl);
259 // get the participant values, CRM-4320
260 $this->_allowConfirmation
= FALSE;
261 if ($this->_participantId
) {
262 $this->processFirstParticipant($this->_participantId
);
264 //check for additional participants.
265 if ($this->_allowConfirmation
&& $this->_values
['event']['is_multiple_registrations']) {
266 $additionalParticipantIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_participantId
);
268 foreach ($additionalParticipantIds as $additionalParticipantId) {
269 $this->_additionalParticipantIds
[$cnt] = $additionalParticipantId;
272 $this->set('additionalParticipantIds', $this->_additionalParticipantIds
);
275 $eventFull = CRM_Event_BAO_Participant
::eventFull($this->_eventId
, FALSE,
276 CRM_Utils_Array
::value('has_waitlist', $this->_values
['event'])
279 $this->_allowWaitlist
= $this->_isEventFull
= FALSE;
280 if ($eventFull && !$this->_allowConfirmation
) {
281 $this->_isEventFull
= TRUE;
282 //lets redirecting to info only when to waiting list.
283 $this->_allowWaitlist
= CRM_Utils_Array
::value('has_waitlist', $this->_values
['event']);
284 if (!$this->_allowWaitlist
) {
285 CRM_Utils_System
::redirect($infoUrl);
288 $this->set('isEventFull', $this->_isEventFull
);
289 $this->set('allowWaitlist', $this->_allowWaitlist
);
291 //check for require requires approval.
292 $this->_requireApproval
= FALSE;
293 if (!empty($this->_values
['event']['requires_approval']) && !$this->_allowConfirmation
) {
294 $this->_requireApproval
= TRUE;
296 $this->set('requireApproval', $this->_requireApproval
);
298 if (isset($this->_values
['event']['default_role_id'])) {
299 $participant_role = CRM_Core_OptionGroup
::values('participant_role');
300 $this->_values
['event']['participant_role'] = $participant_role["{$this->_values['event']['default_role_id']}"];
302 // check for is_monetary status
303 $isMonetary = CRM_Utils_Array
::value('is_monetary', $this->_values
['event']);
304 $isPayLater = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_eventId
, 'is_pay_later');
305 //check for variour combination for paylater, payment
306 //process with paid event.
307 if ($isMonetary && (!$isPayLater ||
!empty($this->_values
['event']['payment_processor']))) {
308 $ppID = CRM_Utils_Array
::value('payment_processor',
309 $this->_values
['event']
312 CRM_Core_Error
::statusBounce(ts('A payment processor must be selected for this event registration page, or the event must be configured to give users the option to pay later (contact the site administrator for assistance).'), $infoUrl);
314 $ppIds = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $ppID);
315 $this->_paymentProcessors
= CRM_Financial_BAO_PaymentProcessor
::getPayments($ppIds,
318 $this->set('paymentProcessors', $this->_paymentProcessors
);
320 //set default payment processor
321 if (!empty($this->_paymentProcessors
) && empty($this->_paymentProcessor
)) {
322 foreach ($this->_paymentProcessors
as $ppId => $values) {
323 if ($values['is_default'] == 1 ||
(count($this->_paymentProcessors
) == 1)) {
324 $defaultProcessorId = $ppId;
330 if (isset($defaultProcessorId)) {
331 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($defaultProcessorId, $this->_mode
);
333 // make sure we have a valid payment class, else abort
334 if ($this->_values
['event']['is_monetary']) {
335 if (!CRM_Utils_System
::isNull($this->_paymentProcessors
)) {
336 foreach ($this->_paymentProcessors
as $eachPaymentProcessor) {
337 // check selected payment processor is active
338 if (!$eachPaymentProcessor) {
339 CRM_Core_Error
::fatal(ts('The site administrator must set a Payment Processor for this event in order to use online registration.'));
341 // ensure that processor has a valid config
342 $payment = CRM_Core_Payment
::singleton($this->_mode
, $eachPaymentProcessor, $this);
343 $error = $payment->checkConfig();
344 if (!empty($error)) {
345 CRM_Core_Error
::fatal($error);
352 self
::initEventFee($this, $this->_eventId
);
354 // get the profile ids
355 $ufJoinParams = array(
356 'entity_table' => 'civicrm_event',
357 // CRM-4377:Â CiviEvent for the main participant, CiviEvent_Additional for additional participants
358 'module' => 'CiviEvent',
359 'entity_id' => $this->_eventId
,
361 list($this->_values
['custom_pre_id'],
362 $this->_values
['custom_post_id']
363 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
365 // set profiles for additional participants
366 if ($this->_values
['event']['is_multiple_registrations']) {
367 // CRM-4377:Â CiviEvent for the main participant, CiviEvent_Additional for additional participants
368 $ufJoinParams['module'] = 'CiviEvent_Additional';
370 list($this->_values
['additional_custom_pre_id'],
371 $this->_values
['additional_custom_post_id'], $preActive, $postActive
372 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
374 // CRM-4377:Â we need to maintain backward compatibility, hence if there is profile for main contact
375 // set same profile for additional contacts.
376 if ($this->_values
['custom_pre_id'] && !$this->_values
['additional_custom_pre_id']) {
377 $this->_values
['additional_custom_pre_id'] = $this->_values
['custom_pre_id'];
380 if ($this->_values
['custom_post_id'] && !$this->_values
['additional_custom_post_id']) {
381 $this->_values
['additional_custom_post_id'] = $this->_values
['custom_post_id'];
383 // now check for no profile condition, in that case is_active = 0
384 if (isset($preActive) && !$preActive) {
385 unset($this->_values
['additional_custom_pre_id']);
387 if (isset($postActive) && !$postActive) {
388 unset($this->_values
['additional_custom_post_id']);
391 // get the billing location type
392 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
393 // CRM-8108 remove ts from Billing as the location type can not be translated in CiviCRM!
394 //$this->_bltID = array_search( ts('Billing'), $locationTypes );
395 $this->_bltID
= array_search('Billing', $locationTypes);
396 if (!$this->_bltID
) {
397 CRM_Core_Error
::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
399 $this->set('bltID', $this->_bltID
);
401 if ($this->_values
['event']['is_monetary'] &&
402 ($this->_paymentProcessor
['billing_mode'] & CRM_Core_Payment
::BILLING_MODE_FORM
)
404 CRM_Core_Payment_Form
::setCreditCardFields($this);
406 $params = array('entity_id' => $this->_eventId
, 'entity_table' => 'civicrm_event');
407 $this->_values
['location'] = CRM_Core_BAO_Location
::getValues($params, TRUE);
409 $this->set('values', $this->_values
);
410 $this->set('fields', $this->_fields
);
412 $this->_availableRegistrations
=
413 CRM_Event_BAO_Participant
::eventFull(
414 $this->_values
['event']['id'], TRUE,
415 CRM_Utils_Array
::value('has_waitlist', $this->_values
['event'])
417 $this->set('availableRegistrations', $this->_availableRegistrations
);
419 $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor
);
421 // check if this is a paypal auto return and redirect accordingly
422 if (CRM_Core_Payment
::paypalRedirect($this->_paymentProcessor
)) {
423 $url = CRM_Utils_System
::url('civicrm/event/register',
424 "_qf_ThankYou_display=1&qfKey={$this->controller->_key}"
426 CRM_Utils_System
::redirect($url);
428 $this->_contributeMode
= $this->get('contributeMode');
429 $this->assign('contributeMode', $this->_contributeMode
);
431 // setting CMS page title
432 CRM_Utils_System
::setTitle($this->_values
['event']['title']);
433 $this->assign('title', $this->_values
['event']['title']);
435 $this->assign('paidEvent', $this->_values
['event']['is_monetary']);
437 // we do not want to display recently viewed items on Registration pages
438 $this->assign('displayRecent', FALSE);
439 // Registration page values are cleared from session, so can't use normal Printer Friendly view.
440 // Use Browser Print instead.
441 $this->assign('browserPrint', TRUE);
443 $isShowLocation = CRM_Utils_Array
::value('is_show_location', $this->_values
['event']);
444 $this->assign('isShowLocation', $isShowLocation);
446 $pcpId = CRM_Utils_Request
::retrieve('pcpId', 'Positive', $this);
448 $pcp = CRM_PCP_BAO_PCP
::handlePcp($pcpId, 'event', $this->_values
['event']);
449 $this->_pcpId
= $pcp['pcpId'];
450 $this->_values
['event']['intro_text'] = CRM_Utils_Array
::value('intro_text', $pcp['pcpInfo']);
453 // assign all event properties so wizard templates can display event info.
454 $this->assign('event', $this->_values
['event']);
455 $this->assign('location', $this->_values
['location']);
456 $this->assign('bltID', $this->_bltID
);
457 $isShowLocation = CRM_Utils_Array
::value('is_show_location', $this->_values
['event']);
458 $this->assign('isShowLocation', $isShowLocation);
460 $config->defaultCurrency
= CRM_Utils_Array
::value('currency', $this->_values
['event'],
461 $config->defaultCurrency
464 //lets allow user to override campaign.
465 $campID = CRM_Utils_Request
::retrieve('campID', 'Positive', $this);
466 if ($campID && CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) {
467 $this->_values
['event']['campaign_id'] = $campID;
472 * assign the minimal set of variables to the template
477 function assignToTemplate() {
478 //process only primary participant params
479 $this->_params
= $this->get('params');
480 if (isset($this->_params
[0])) {
481 $params = $this->_params
[0];
484 if (!empty($params['billing_first_name'])) {
485 $name = $params['billing_first_name'];
488 if (!empty($params['billing_middle_name'])) {
489 $name .= " {$params['billing_middle_name']}";
492 if (!empty($params['billing_last_name'])) {
493 $name .= " {$params['billing_last_name']}";
495 $this->assign('billingName', $name);
496 $this->set('name', $name);
499 'amount', 'currencyID', 'credit_card_type',
500 'trxn_id', 'amount_level', 'receive_date',
503 foreach ($vars as $v) {
504 if (!empty($params[$v])) {
505 if ($v == 'receive_date') {
506 $this->assign($v, CRM_Utils_Date
::mysqlToIso($params[$v]));
509 $this->assign($v, $params[$v]);
512 elseif (CRM_Utils_Array
::value('amount', $params) == 0) {
513 $this->assign($v, CRM_Utils_Array
::value($v, $params));
517 // assign the address formatted up for display
518 $addressParts = array(
519 "street_address-{$this->_bltID}",
520 "city-{$this->_bltID}",
521 "postal_code-{$this->_bltID}",
522 "state_province-{$this->_bltID}",
523 "country-{$this->_bltID}",
525 $addressFields = array();
526 foreach ($addressParts as $part) {
527 list($n, $id) = explode('-', $part);
528 if (isset($params['billing_' . $part])) {
529 $addressFields[$n] = CRM_Utils_Array
::value('billing_' . $part, $params);
533 $this->assign('address', CRM_Utils_Address
::format($addressFields));
535 if ($this->_contributeMode
== 'direct' && empty($params['is_pay_later'])) {
536 $date = CRM_Utils_Date
::format(CRM_Utils_Array
::value('credit_card_exp_date', $params));
537 $date = CRM_Utils_Date
::mysqlToIso($date);
538 $this->assign('credit_card_exp_date', $date);
539 $this->assign('credit_card_number',
540 CRM_Utils_System
::mungeCreditCard(CRM_Utils_Array
::value('credit_card_number', $params))
544 // get the email that the confirmation would have been sent to
545 $session = CRM_Core_Session
::singleton();
547 // assign is_email_confirm to templates
548 if (isset($this->_values
['event']['is_email_confirm'])) {
549 $this->assign('is_email_confirm', $this->_values
['event']['is_email_confirm']);
552 // assign pay later stuff
553 $params['is_pay_later'] = CRM_Utils_Array
::value('is_pay_later', $params, FALSE);
554 $this->assign('is_pay_later', $params['is_pay_later']);
555 if ($params['is_pay_later']) {
556 $this->assign('pay_later_text', $this->_values
['event']['pay_later_text']);
557 $this->assign('pay_later_receipt', $this->_values
['event']['pay_later_receipt']);
560 // also assign all participantIDs to the template
561 // useful in generating confirmation numbers if needed
562 $this->assign('participantIDs',
563 $this->_participantIDS
568 * Function to add the custom fields
572 * @param bool $viewOnly
577 function buildCustom($id, $name, $viewOnly = FALSE) {
578 $stateCountryMap = $fields = array();
581 $button = substr($this->controller
->getButtonName(), -4);
582 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
583 $session = CRM_Core_Session
::singleton();
584 $contactID = $session->get('userID');
586 // we don't allow conflicting fields to be
587 // configured via profile
588 $fieldsToIgnore = array(
589 'participant_fee_amount' => 1,
590 'participant_fee_level' => 1,
596 foreach ($id as $profileID) {
597 $field = CRM_Core_BAO_UFGroup
::getFields($profileID, FALSE, CRM_Core_Action
::ADD
,
598 NULL, NULL, FALSE, NULL,
599 FALSE, NULL, CRM_Core_Permission
::CREATE
,
602 $fields = array_merge($fields, $field);
606 if (CRM_Core_BAO_UFGroup
::filterUFGroups($id, $contactID)) {
607 $fields = CRM_Core_BAO_UFGroup
::getFields($id, FALSE, CRM_Core_Action
::ADD
,
608 NULL, NULL, FALSE, NULL,
609 FALSE, NULL, CRM_Core_Permission
::CREATE
,
616 $fields = CRM_Core_BAO_UFGroup
::getFields($id, FALSE, CRM_Core_Action
::ADD
,
617 NULL, NULL, FALSE, NULL,
618 FALSE, NULL, CRM_Core_Permission
::CREATE
,
623 if (array_intersect_key($fields, $fieldsToIgnore)) {
624 $fields = array_diff_key($fields, $fieldsToIgnore);
625 CRM_Core_Session
::setStatus(ts('Some of the profile fields cannot be configured for this page.'));
629 if (!empty($this->_fields
)) {
630 $fields = @array_diff_assoc
($fields, $this->_fields
);
633 if (empty($this->_params
[0]['additional_participants']) &&
636 CRM_Core_BAO_Address
::checkContactSharedAddressFields($fields, $contactID);
638 $this->assign($name, $fields);
639 if (is_array($fields)) {
640 foreach ($fields as $key => $field) {
642 isset($field['data_type']) &&
643 $field['data_type'] == 'File' ||
($viewOnly && $field['name'] == 'image_URL')
645 // ignore file upload fields
648 //make the field optional if primary participant
649 //have been skip the additional participant.
650 if ($button == 'skip') {
651 $field['is_required'] = FALSE;
653 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
654 elseif ($field['add_captcha'] && !$contactID) {
655 // only add captcha for first page
658 list($prefixName, $index) = CRM_Utils_System
::explode('-', $key, 2);
659 if ($prefixName == 'state_province' ||
$prefixName == 'country' ||
$prefixName == 'county') {
660 if (!array_key_exists($index, $stateCountryMap)) {
661 $stateCountryMap[$index] = array();
663 $stateCountryMap[$index][$prefixName] = $key;
665 CRM_Core_BAO_UFGroup
::buildProfile($this, $field, CRM_Profile_Form
::MODE_CREATE
, $contactID, TRUE);
667 $this->_fields
[$key] = $field;
671 CRM_Core_BAO_Address
::addStateCountryMap($stateCountryMap);
673 if ($addCaptcha && !$viewOnly) {
674 $captcha = CRM_Utils_ReCAPTCHA
::singleton();
675 $captcha->add($this);
676 $this->assign('isCaptcha', TRUE);
681 static function initEventFee(&$form, $eventID) {
684 // retrive all active price set fields.
685 $discountId = CRM_Core_BAO_Discount
::findSet($eventID, 'civicrm_event');
686 if (property_exists($form, '_discountId') && $form->_discountId
) {
687 $discountId = $form->_discountId
;
690 $priceSetId = CRM_Core_DAO
::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id');
691 $price = CRM_Price_BAO_PriceSet
::initSet($form, $eventID, 'civicrm_event', TRUE, $priceSetId);
694 $price = CRM_Price_BAO_PriceSet
::initSet($form, $eventID, 'civicrm_event', TRUE);
697 if (property_exists($form, '_context') && ($form->_context
== 'standalone'
698 ||
$form->_context
== 'participant')) {
699 $discountedEvent = CRM_Core_BAO_Discount
::getOptionGroup($eventID, 'civicrm_event');
700 if (is_array( $discountedEvent)) {
701 foreach ($discountedEvent as $key => $priceSetId) {
702 $priceSet = CRM_Price_BAO_PriceSet
::getSetDetail($priceSetId);
703 $priceSet = CRM_Utils_Array
::value($priceSetId, $priceSet);
704 $form->_values
['discount'][$key] = CRM_Utils_Array
::value('fields', $priceSet);
705 $fieldID = key($form->_values
['discount'][$key]);
706 $form->_values
['discount'][$key][$fieldID]['name'] = CRM_Core_DAO
::getFieldValue(
707 'CRM_Price_DAO_PriceSet',
714 $eventFee = CRM_Utils_Array
::value('fee', $form->_values
);
715 if (!is_array($eventFee) ||
empty($eventFee)) {
716 $form->_values
['fee'] = array();
719 //fix for non-upgraded price sets.CRM-4256.
720 if (isset($form->_isPaidEvent
)) {
721 $isPaidEvent = $form->_isPaidEvent
;
724 $isPaidEvent = CRM_Utils_Array
::value('is_monetary', $form->_values
['event']);
726 if ($isPaidEvent && empty($form->_values
['fee'])) {
727 if (CRM_Utils_System
::getClassName($form) != 'CRM_Event_Form_Participant') {
728 CRM_Core_Error
::fatal(ts('No Fee Level(s) or Price Set is configured for this event.<br />Click <a href=\'%1\'>CiviEvent >> Manage Event >> Configure >> Event Fees</a> to configure the Fee Level(s) or Price Set for this event.', array(1 => CRM_Utils_System
::url('civicrm/event/manage/fee', 'reset=1&action=update&id=' . $form->_eventId
))));
734 * Function to handle process after the confirmation of payment by User
736 * @param null $contactID
737 * @param null $contribution
738 * @param null $payment
743 function confirmPostProcess($contactID = NULL, $contribution = NULL, $payment = NULL) {
744 // add/update contact information
746 unset($this->_params
['note']);
748 //to avoid conflict overwrite $this->_params
749 $this->_params
= $this->get('value');
751 //get the amount of primary participant
752 if (!empty($this->_params
['is_primary'])) {
753 $this->_params
['fee_amount'] = $this->get('primaryParticipantAmount');
756 // add participant record
757 $participant = $this->addParticipant($this->_params
, $contactID);
758 $this->_participantIDS
[] = $participant->id
;
760 //setting register_by_id field and primaryContactId
761 if (!empty($this->_params
['is_primary'])) {
762 $this->set('registerByID', $participant->id
);
763 $this->set('primaryContactId', $contactID);
766 $this->processFirstParticipant($participant->id
);
769 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
770 CRM_Core_DAO
::$_nullArray,
771 'civicrm_participant',
776 $createPayment = (CRM_Utils_Array
::value('amount', $this->_params
, 0) != 0) ?
TRUE : FALSE;
778 // force to create zero amount payment, CRM-5095
779 // we know the amout is zero since createPayment is false
780 if (!$createPayment &&
781 (isset($contribution) && $contribution->id
) &&
782 $this->_priceSetId
&&
785 $createPayment = TRUE;
788 if ($createPayment && $this->_values
['event']['is_monetary'] && !empty($this->_params
['contributionID'])) {
789 $paymentParams = array(
790 'participant_id' => $participant->id
,
791 'contribution_id' => $contribution->id
,
794 $paymentPartcipant = CRM_Event_BAO_ParticipantPayment
::create($paymentParams, $ids);
797 //set only primary participant's params for transfer checkout.
798 if (($this->_contributeMode
== 'checkout' ||
$this->_contributeMode
== 'notify') && !empty($this->_params
['is_primary'])) {
799 $this->_params
['participantID'] = $participant->id
;
800 $this->set('primaryParticipant', $this->_params
);
803 $this->assign('action', $this->_action
);
806 if (!empty($this->_params
['cms_create_account'])) {
807 $this->_params
['contactID'] = $contactID;
809 if (array_key_exists('email-5', $this->_params
)) {
812 foreach ($this->_params
as $name => $dontCare) {
813 if (substr($name, 0, 5) == 'email') {
820 // we should use primary email for
821 // 1. free event registration.
822 // 2. pay later participant.
823 // 3. waiting list participant.
824 // 4. require approval participant.
825 if (!empty($this->_params
['is_pay_later']) ||
826 $this->_allowWaitlist ||
$this->_requireApproval ||
empty($this->_values
['event']['is_monetary'])) {
827 $mail = 'email-Primary';
830 if (!CRM_Core_BAO_CMSUser
::create($this->_params
, $mail)) {
831 CRM_Core_Error
::statusBounce(ts('Your profile is not saved and Account is not created.'));
837 * Process the participant
845 public function addParticipant($params, $contactID) {
847 $transaction = new CRM_Core_Transaction();
849 $groupName = 'participant_role';
851 SELECT v.label as label ,v.value as value
852 FROM civicrm_option_value v,
853 civicrm_option_group g
854 WHERE v.option_group_id = g.id
859 $p = array(1 => array($groupName, 'String'));
861 $dao = CRM_Core_DAO
::executeQuery($query, $p);
863 $roleID = $dao->value
;
866 // handle register date CRM-4320
867 $registerDate = NULL;
868 if ($this->_allowConfirmation
&& $this->_participantId
) {
869 $registerDate = $params['participant_register_date'];
871 elseif (!empty($params['participant_register_date']) &&
872 is_array($params['participant_register_date']) &&
873 !empty($params['participant_register_date'])
875 $registerDate = CRM_Utils_Date
::format($params['participant_register_date']);
878 $participantParams = array('id' => CRM_Utils_Array
::value('participant_id', $params),
879 'contact_id' => $contactID,
880 'event_id' => $this->_eventId ?
$this->_eventId
: $params['event_id'],
881 'status_id' => CRM_Utils_Array
::value('participant_status',
884 'role_id' => CRM_Utils_Array
::value('participant_role_id',
887 'register_date' => ($registerDate) ?
$registerDate : date('YmdHis'),
888 'source' => isset($params['participant_source']) ?
889 CRM_Utils_Array
::value('participant_source', $params) : CRM_Utils_Array
::value('description', $params),
890 'fee_level' => CRM_Utils_Array
::value('amount_level', $params),
891 'is_pay_later' => CRM_Utils_Array
::value('is_pay_later', $params, 0),
892 'fee_amount' => CRM_Utils_Array
::value('fee_amount', $params),
893 'registered_by_id' => CRM_Utils_Array
::value('registered_by_id', $params),
894 'discount_id' => CRM_Utils_Array
::value('discount_id', $params),
895 'fee_currency' => CRM_Utils_Array
::value('currencyID', $params),
896 'campaign_id' => CRM_Utils_Array
::value('campaign_id', $params),
899 if ($this->_action
& CRM_Core_Action
::PREVIEW || CRM_Utils_Array
::value('mode', $params) == 'test') {
900 $participantParams['is_test'] = 1;
903 $participantParams['is_test'] = 0;
906 if (!empty($this->_params
['note'])) {
907 $participantParams['note'] = $this->_params
['note'];
909 elseif (!empty($this->_params
['participant_note'])) {
910 $participantParams['note'] = $this->_params
['participant_note'];
913 // reuse id if one already exists for this one (can happen
914 // with back button being hit etc)
915 if (!$participantParams['id'] && !empty($params['contributionID'])) {
916 $pID = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
917 $params['contributionID'],
921 $participantParams['id'] = $pID;
923 $participantParams['discount_id'] = CRM_Core_BAO_Discount
::findSet($this->_eventId
, 'civicrm_event');
925 if (!$participantParams['discount_id']) {
926 $participantParams['discount_id'] = "null";
929 $participant = CRM_Event_BAO_Participant
::create($participantParams);
931 $transaction->commit();
936 /* Calculate the total participant count as per params.
938 * @param array $params user params.
940 * @return $totalCount total participant count.
943 public static function getParticipantCount(&$form, $params, $skipCurrent = FALSE) {
945 if (!is_array($params) ||
empty($params)) {
949 $priceSetId = $form->get('priceSetId');
950 $addParticipantNum = substr($form->_name
, 12);
951 $priceSetFields = $priceSetDetails = array();
952 $hasPriceFieldsCount = FALSE;
954 $priceSetDetails = $form->get('priceSet');
955 if (isset($priceSetDetails['optionsCountTotal'])
956 && $priceSetDetails['optionsCountTotal']
958 $hasPriceFieldsCount = TRUE;
959 $priceSetFields = $priceSetDetails['optionsCountDetails']['fields'];
963 $singleFormParams = FALSE;
964 foreach ($params as $key => $val) {
965 if (!is_numeric($key)) {
966 $singleFormParams = TRUE;
971 //first format the params.
972 if ($singleFormParams) {
973 $params = self
::formatPriceSetParams($form, $params);
974 $params = array($params);
977 foreach ($params as $key => $values) {
978 if (!is_numeric($key) ||
980 ($skipCurrent && ($addParticipantNum == $key))
987 $cacheCount = CRM_Utils_Array
::value($key, $form->_lineItemParticipantsCount
);
988 if ($cacheCount && is_numeric($cacheCount)) {
989 $count = $cacheCount;
993 if (!$usedCache && $hasPriceFieldsCount) {
995 foreach ($values as $valKey => $value) {
996 if (strpos($valKey, 'price_') === FALSE) {
999 $priceFieldId = substr($valKey, 6);
1000 if (!$priceFieldId ||
1001 !is_array($value) ||
1002 !array_key_exists($priceFieldId, $priceSetFields)
1006 foreach ($value as $optId => $optVal) {
1007 $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal;
1008 if ($currentCount) {
1009 $count +
= $currentCount;
1017 $totalCount +
= $count;
1026 /* Format user submitted price set params.
1027 * Convert price set each param as an array.
1029 * @param $params an array of user submitted params.
1032 * @return array $formatted, formatted price set params.
1035 public static function formatPriceSetParams(&$form, $params) {
1036 if (!is_array($params) ||
empty($params)) {
1040 $priceSetId = $form->get('priceSetId');
1044 $priceSetDetails = $form->get('priceSet');
1046 foreach ($params as $key => & $value) {
1048 if (strpos($key, 'price_') !== FALSE) {
1049 $fieldId = substr($key, 6);
1050 if (!array_key_exists($fieldId, $priceSetDetails['fields']) ||
1056 $field = $priceSetDetails['fields'][$fieldId];
1057 if ($field['html_type'] == 'Text') {
1058 $fieldOption = current($field['options']);
1059 $value = array($fieldOption['id'] => $value);
1062 $value = array($value => TRUE);
1070 /* Calculate total count for each price set options.
1071 * those are currently selected by user.
1073 * @param $form form object.
1076 * @return array $optionsCount, array of each option w/ count total.
1079 public static function getPriceSetOptionCount(&$form) {
1080 $params = $form->get('params');
1081 $priceSet = $form->get('priceSet');
1082 $priceSetId = $form->get('priceSetId');
1084 $optionsCount = array();
1086 !is_array($priceSet) ||
1088 !is_array($params) ||
1091 return $optionsCount;
1094 $priceSetFields = $priceMaxFieldDetails = array();
1095 if (!empty($priceSet['optionsCountTotal'])) {
1096 $priceSetFields = $priceSet['optionsCountDetails']['fields'];
1099 if (!empty($priceSet['optionsMaxValueTotal'])) {
1100 $priceMaxFieldDetails = $priceSet['optionsMaxValueDetails']['fields'];
1103 $addParticipantNum = substr($form->_name
, 12);
1104 foreach ($params as $pCnt => $values) {
1105 if ($values == 'skip' ||
1106 $pCnt == $addParticipantNum
1111 foreach ($values as $valKey => $value) {
1112 if (strpos($valKey, 'price_') === FALSE) {
1116 $priceFieldId = substr($valKey, 6);
1117 if (!$priceFieldId ||
1118 !is_array($value) ||
1119 !(array_key_exists($priceFieldId, $priceSetFields) ||
array_key_exists($priceFieldId, $priceMaxFieldDetails))
1124 foreach ($value as $optId => $optVal) {
1125 if (CRM_Utils_Array
::value('html_type', $priceSet['fields'][$priceFieldId]) == 'Text') {
1126 $currentCount = $optVal;
1132 if (isset($priceSetFields[$priceFieldId]) && isset($priceSetFields[$priceFieldId]['options'][$optId])) {
1133 $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal;
1136 $optionsCount[$optId] = $currentCount + CRM_Utils_Array
::value($optId, $optionsCount, 0);
1141 return $optionsCount;
1144 function checkTemplateFileExists($suffix = '') {
1145 if ($this->_eventId
) {
1146 $templateName = $this->_name
;
1147 if (substr($templateName, 0, 12) == 'Participant_') {
1148 $templateName = 'AdditionalParticipant';
1151 $templateFile = "CRM/Event/Form/Registration/{$this->_eventId}/{$templateName}.{$suffix}tpl";
1152 $template = CRM_Core_Form
::getTemplate();
1153 if ($template->template_exists($templateFile)) {
1154 return $templateFile;
1160 function getTemplateFileName() {
1161 $fileName = $this->checkTemplateFileExists();
1162 return $fileName ?
$fileName : parent
::getTemplateFileName();
1165 function overrideExtraTemplateFileName() {
1166 $fileName = $this->checkTemplateFileExists('extra.');
1167 return $fileName ?
$fileName : parent
::overrideExtraTemplateFileName();
1171 * Validate price set submitted params for price option limit,
1172 * as well as user should select at least one price field option.
1173 * @param unknown_type $form
1174 * @param unknown_type $params
1175 * @return multitype:|Ambigous <multitype:, string, string>
1177 static function validatePriceSet(&$form, $params) {
1179 $hasOptMaxValue = FALSE;
1180 if (!is_array($params) ||
empty($params)) {
1184 $currentParticipantNum = substr($form->_name
, 12);
1185 if (!$currentParticipantNum) {
1186 $currentParticipantNum = 0;
1189 $priceSetId = $form->get('priceSetId');
1190 $priceSetDetails = $form->get('priceSet');
1193 !is_array($priceSetDetails) ||
1194 empty($priceSetDetails)
1199 $optionsCountDetails = $optionsMaxValueDetails = array();
1201 isset($priceSetDetails['optionsMaxValueTotal'])
1202 && $priceSetDetails['optionsMaxValueTotal']
1204 $hasOptMaxValue = TRUE;
1205 $optionsMaxValueDetails = $priceSetDetails['optionsMaxValueDetails']['fields'];
1208 isset($priceSetDetails['optionsCountTotal'])
1209 && $priceSetDetails['optionsCountTotal']
1211 $hasOptCount = TRUE;
1212 $optionsCountDetails = $priceSetDetails['optionsCountDetails']['fields'];
1214 $feeBlock = $form->_feeBlock
;
1216 if (empty($feeBlock)) {
1217 $feeBlock = $priceSetDetails['fields'];
1220 $optionMaxValues = $fieldSelected = array();
1221 foreach ($params as $pNum => $values) {
1222 if (!is_array($values) ||
$values == 'skip') {
1226 foreach ($values as $valKey => $value) {
1227 if (strpos($valKey, 'price_') === FALSE) {
1230 $priceFieldId = substr($valKey, 6);
1231 $noneOptionValueSelected = FALSE;
1232 if (!$feeBlock[$priceFieldId]['is_required'] && $value == 0) {
1233 $noneOptionValueSelected = TRUE;
1238 (!$noneOptionValueSelected && !is_array($value))
1243 $fieldSelected[$pNum] = TRUE;
1245 if (!$hasOptMaxValue ||
!is_array($value)) {
1249 foreach ($value as $optId => $optVal) {
1250 if (CRM_Utils_Array
::value('html_type', $feeBlock[$priceFieldId]) == 'Text') {
1251 $currentMaxValue = $optVal;
1254 $currentMaxValue = 1;
1257 if (isset($optionsCountDetails[$priceFieldId]) && isset($optionsCountDetails[$priceFieldId]['options'][$optId])) {
1258 $currentMaxValue = $optionsCountDetails[$priceFieldId]['options'][$optId] * $optVal;
1260 if (empty($optionMaxValues)) {
1261 $optionMaxValues[$priceFieldId][$optId] = $currentMaxValue;
1264 $optionMaxValues[$priceFieldId][$optId] =
1265 $currentMaxValue + CRM_Utils_Array
::value($optId, CRM_Utils_Array
::value($priceFieldId, $optionMaxValues), 0);
1272 //validate for option max value.
1273 foreach ($optionMaxValues as $fieldId => $values) {
1274 $options = CRM_Utils_Array
::value('options', $feeBlock[$fieldId], array());
1275 foreach ($values as $optId => $total) {
1276 $optMax = $optionsMaxValueDetails[$fieldId]['options'][$optId];
1277 $opDbCount = CRM_Utils_Array
::value('db_total_count', $options[$optId], 0);
1278 $total +
= $opDbCount;
1279 if ($optMax && $total > $optMax) {
1280 if ($opDbCount && ($opDbCount >= $optMax)) {
1281 $errors[$currentParticipantNum]["price_{$fieldId}"] =
1282 ts('Sorry, this option is currently sold out.');
1284 elseif (($optMax - $opDbCount) == 1) {
1285 $errors[$currentParticipantNum]["price_{$fieldId}"] =
1286 ts('Sorry, currently only a single seat is available for this option.', array(1 => ($optMax - $opDbCount)));
1289 $errors[$currentParticipantNum]["price_{$fieldId}"] =
1290 ts('Sorry, currently only %1 seats are available for this option.', array(1 => ($optMax - $opDbCount)));
1296 //validate for price field selection.
1297 foreach ($params as $pNum => $values) {
1298 if (!is_array($values) ||
$values == 'skip') {
1301 if (empty($fieldSelected[$pNum])) {
1302 $errors[$pNum]['_qf_default'] = ts('Select at least one option from Event Fee(s).');
1309 // set the first participant ID if not set, CRM-10032
1310 function processFirstParticipant($participantID) {
1311 $this->_participantId
= $participantID;
1312 $this->set('participantId', $this->_participantId
);
1314 $ids = $participantValues = array();
1315 $participantParams = array('id' => $this->_participantId
);
1316 CRM_Event_BAO_Participant
::getValues($participantParams, $participantValues, $ids);
1317 $this->_values
['participant'] = $participantValues[$this->_participantId
];
1318 $this->set('values', $this->_values
);
1320 // also set the allow confirmation stuff
1321 if (array_key_exists(
1322 $this->_values
['participant']['status_id'],
1323 CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Pending'")
1325 $this->_allowConfirmation
= TRUE;
1326 $this->set('allowConfirmation', TRUE);
1331 * @todo - combine this with CRM_Event_BAO_Event::validRegistrationRequest
1332 * (probably extract relevant values here & call that with them & handle bounces & redirects here -as
1333 * those belong in the form layer)
1335 * @param string $redirect
1337 function checkValidEvent($redirect = NULL) {
1338 // is the event active (enabled)?
1339 if (!$this->_values
['event']['is_active']) {
1340 // form is inactive, die a fatal death
1341 CRM_Core_Error
::statusBounce(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
1344 // is online registration is enabled?
1345 if (!$this->_values
['event']['is_online_registration']) {
1346 CRM_Core_Error
::statusBounce(ts('Online registration is not currently available for this event (contact the site administrator for assistance).'), $redirect);
1349 // is this an event template ?
1350 if (!empty($this->_values
['event']['is_template'])) {
1351 CRM_Core_Error
::statusBounce(ts('Event templates are not meant to be registered.'), $redirect);
1354 $now = date('YmdHis');
1355 $startDate = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('registration_start_date',
1356 $this->_values
['event']
1363 CRM_Core_Error
::statusBounce(ts('Registration for this event begins on %1', array(1 => CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('registration_start_date', $this->_values
['event'])))), $redirect);
1366 $endDate = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('registration_end_date',
1367 $this->_values
['event']
1373 CRM_Core_Error
::statusBounce(ts('Registration for this event ended on %1', array(1 => CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('registration_end_date', $this->_values
['event'])))), $redirect);