3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2013
38 * This class generates form components for processing 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->_totalParticipantCount
= $this->get('totalParticipantcount');
223 $this->_participantIDS
= $this->get('participantIDs');
225 //check if participant allow to walk registration wizard.
226 $this->_allowConfirmation
= $this->get('allowConfirmation');
228 // check for Approval
229 $this->_requireApproval
= $this->get('requireApproval');
231 // check for waitlisting.
232 $this->_allowWaitlist
= $this->get('allowWaitlist');
234 $this->_forcePayement
= $this->get('forcePayement');
236 //get the additional participant ids.
237 $this->_additionalParticipantIds
= $this->get('additionalParticipantIds');
239 $config = CRM_Core_Config
::singleton();
241 if (!$this->_values
) {
242 // create redirect URL to send folks back to event info page is registration not available
243 $infoUrl = CRM_Utils_System
::url(
244 'civicrm/event/info',
245 "reset=1&id={$this->_eventId}",
246 FALSE, NULL, FALSE, TRUE
249 // this is the first time we are hitting this, so check for permissions here
250 if (!CRM_Core_Permission
::event(CRM_Core_Permission
::EDIT
, $this->_eventId
)) {
251 CRM_Core_Error
::statusBounce(ts('You do not have permission to register for this event'), $infoUrl);
254 // get all the values from the dao object
255 $this->_values
= array();
256 $this->_fields
= array();
257 $this->_forcePayement
= FALSE;
259 //retrieve event information
260 $params = array('id' => $this->_eventId
);
261 CRM_Event_BAO_Event
::retrieve($params, $this->_values
['event']);
263 $this->checkValidEvent($infoUrl);
265 // get the participant values, CRM-4320
266 $this->_allowConfirmation
= FALSE;
267 if ($this->_participantId
) {
268 $this->processFirstParticipant($this->_participantId
);
271 //check for additional participants.
272 if ($this->_allowConfirmation
&& $this->_values
['event']['is_multiple_registrations']) {
273 $additionalParticipantIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_participantId
);
275 foreach ($additionalParticipantIds as $additionalParticipantId) {
276 $this->_additionalParticipantIds
[$cnt] = $additionalParticipantId;
279 $this->set('additionalParticipantIds', $this->_additionalParticipantIds
);
282 $eventFull = CRM_Event_BAO_Participant
::eventFull(
285 CRM_Utils_Array
::value('has_waitlist', $this->_values
['event'])
288 $this->_allowWaitlist
= FALSE;
289 $this->_isEventFull
= FALSE;
290 if ($eventFull && !$this->_allowConfirmation
) {
291 $this->_isEventFull
= TRUE;
292 //lets redirecting to info only when to waiting list.
293 $this->_allowWaitlist
= CRM_Utils_Array
::value('has_waitlist', $this->_values
['event']);
294 if (!$this->_allowWaitlist
) {
295 CRM_Utils_System
::redirect($infoUrl);
298 $this->set('isEventFull', $this->_isEventFull
);
299 $this->set('allowWaitlist', $this->_allowWaitlist
);
301 //check for require requires approval.
302 $this->_requireApproval
= FALSE;
303 if (CRM_Utils_Array
::value('requires_approval', $this->_values
['event']) && !$this->_allowConfirmation
) {
304 $this->_requireApproval
= TRUE;
306 $this->set('requireApproval', $this->_requireApproval
);
308 // also get the accounting code
309 /* if (CRM_Utils_Array::value('financial_type_id', $this->_values['event'])) { */
310 /* $this->_values['event']['accountingCode'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', */
311 /* $this->_values['event']['financial_type_id'], */
312 /* 'accounting_code' */
315 if (isset($this->_values
['event']['default_role_id'])) {
316 $participant_role = CRM_Core_OptionGroup
::values('participant_role');
317 $this->_values
['event']['participant_role'] = $participant_role["{$this->_values['event']['default_role_id']}"];
320 // check for is_monetary status
321 $isMonetary = CRM_Utils_Array
::value('is_monetary', $this->_values
['event']);
323 //retrieve custom information
324 $eventID = $this->_eventId
;
326 $isPayLater = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventID, 'is_pay_later');
327 //check for variour combination for paylater, payment
328 //process with paid event.
330 (!$isPayLater || CRM_Utils_Array
::value('payment_processor', $this->_values
['event']))
332 $ppID = CRM_Utils_Array
::value('payment_processor',
333 $this->_values
['event']
336 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);
339 $ppIds = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $ppID);
340 $this->_paymentProcessors
= CRM_Financial_BAO_PaymentProcessor
::getPayments($ppIds,
344 $this->set('paymentProcessors', $this->_paymentProcessors
);
346 //set default payment processor
347 if (!empty($this->_paymentProcessors
) && empty($this->_paymentProcessor
)) {
348 foreach ($this->_paymentProcessors
as $ppId => $values) {
349 if ($values['is_default'] == 1 ||
(count($this->_paymentProcessors
) == 1)) {
350 $defaultProcessorId = $ppId;
356 if (isset($defaultProcessorId)) {
357 $this->_paymentProcessor
= CRM_Financial_BAO_PaymentProcessor
::getPayment($defaultProcessorId, $this->_mode
);
358 $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor
);
361 // make sure we have a valid payment class, else abort
362 if ($this->_values
['event']['is_monetary']) {
364 if (!CRM_Utils_System
::isNull($this->_paymentProcessors
)) {
365 foreach ($this->_paymentProcessors
as $eachPaymentProcessor) {
367 // check selected payment processor is active
368 if (!$eachPaymentProcessor) {
369 CRM_Core_Error
::fatal(ts('The site administrator must set a Payment Processor for this event in order to use online registration.'));
372 // ensure that processor has a valid config
373 $payment = CRM_Core_Payment
::singleton($this->_mode
, $eachPaymentProcessor, $this);
374 $error = $payment->checkConfig();
375 if (!empty($error)) {
376 CRM_Core_Error
::fatal($error);
384 self
::initEventFee($this, $eventID);
386 // get the profile ids
387 $ufJoinParams = array(
388 'entity_table' => 'civicrm_event',
389 // CRM-4377:Â CiviEvent for the main participant, CiviEvent_Additional for additional participants
390 'module' => 'CiviEvent',
391 'entity_id' => $this->_eventId
,
393 list($this->_values
['custom_pre_id'],
394 $this->_values
['custom_post_id']
395 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
397 // set profiles for additional participants
398 if ($this->_values
['event']['is_multiple_registrations']) {
399 $ufJoinParams = array(
400 'entity_table' => 'civicrm_event',
401 // CRM-4377:Â CiviEvent for the main participant, CiviEvent_Additional for additional participants
402 'module' => 'CiviEvent_Additional',
403 'entity_id' => $this->_eventId
,
405 list($this->_values
['additional_custom_pre_id'],
406 $this->_values
['additional_custom_post_id'], $preActive, $postActive
407 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
409 // CRM-4377:Â we need to maintain backward compatibility, hence if there is profile for main contact
410 // set same profile for additional contacts.
411 if ($this->_values
['custom_pre_id'] && !$this->_values
['additional_custom_pre_id']) {
412 $this->_values
['additional_custom_pre_id'] = $this->_values
['custom_pre_id'];
415 if ($this->_values
['custom_post_id'] && !$this->_values
['additional_custom_post_id']) {
416 $this->_values
['additional_custom_post_id'] = $this->_values
['custom_post_id'];
419 // now check for no profile condition, in that case is_active = 0
420 if (isset($preActive) && !$preActive) {
421 unset($this->_values
['additional_custom_pre_id']);
424 if (isset($postActive) && !$postActive) {
425 unset($this->_values
['additional_custom_post_id']);
429 $params = array('id' => $this->_eventId
);
431 // get the billing location type
432 $locationTypes = CRM_Core_PseudoConstant
::locationType();
434 // CRM-8108 remove ts from Billing as the location type can not be translated in CiviCRM!
435 //$this->_bltID = array_search( ts('Billing'), $locationTypes );
436 $this->_bltID
= array_search('Billing', $locationTypes);
438 if (!$this->_bltID
) {
439 CRM_Core_Error
::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
441 $this->set('bltID', $this->_bltID
);
443 if ($this->_values
['event']['is_monetary'] &&
444 ($this->_paymentProcessor
['billing_mode'] & CRM_Core_Payment
::BILLING_MODE_FORM
)
446 CRM_Core_Payment_Form
::setCreditCardFields($this);
449 $params = array('entity_id' => $this->_eventId
, 'entity_table' => 'civicrm_event');
450 $this->_values
['location'] = CRM_Core_BAO_Location
::getValues($params, TRUE);
452 $this->set('values', $this->_values
);
453 $this->set('fields', $this->_fields
);
455 $this->_availableRegistrations
=
456 CRM_Event_BAO_Participant
::eventFull(
457 $this->_values
['event']['id'],
459 CRM_Utils_Array
::value('has_waitlist', $this->_values
['event'])
461 $this->set('availableRegistrations', $this->_availableRegistrations
);
464 $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor
);
466 // check if this is a paypal auto return and redirect accordingly
467 if (CRM_Core_Payment
::paypalRedirect($this->_paymentProcessor
)) {
468 $url = CRM_Utils_System
::url('civicrm/event/register',
469 "_qf_ThankYou_display=1&qfKey={$this->controller->_key}"
471 CRM_Utils_System
::redirect($url);
474 $this->_contributeMode
= $this->get('contributeMode');
475 $this->assign('contributeMode', $this->_contributeMode
);
477 // setting CMS page title
478 CRM_Utils_System
::setTitle($this->_values
['event']['title']);
479 $this->assign('title', $this->_values
['event']['title']);
481 $this->assign('paidEvent', $this->_values
['event']['is_monetary']);
483 // we do not want to display recently viewed items on Registration pages
484 $this->assign('displayRecent', FALSE);
485 // Registration page values are cleared from session, so can't use normal Printer Friendly view.
486 // Use Browser Print instead.
487 $this->assign('browserPrint', TRUE);
489 $isShowLocation = CRM_Utils_Array
::value('is_show_location', $this->_values
['event']);
490 $this->assign('isShowLocation', $isShowLocation);
493 $pcpId = CRM_Utils_Request
::retrieve('pcpId', 'Positive', $this);
495 $pcp = CRM_PCP_BAO_PCP
::handlePcp($pcpId, 'event', $this->_values
['event']);
496 $this->_pcpId
= $pcp['pcpId'];
497 $this->_pcpBlock
= $pcp['pcpBlock'];
498 $this->_pcpInfo
= $pcp['pcpInfo'];
501 if (isset($this->_pcpInfo
) && CRM_Utils_Array
::value('intro_text', $this->_pcpInfo
)) {
502 $this->_values
['event']['intro_text'] = $this->_pcpInfo
['intro_text'];
505 // assign all event properties so wizard templates can display event info.
506 $this->assign('event', $this->_values
['event']);
507 $this->assign('location', $this->_values
['location']);
508 $this->assign('bltID', $this->_bltID
);
509 $isShowLocation = CRM_Utils_Array
::value('is_show_location', $this->_values
['event']);
510 $this->assign('isShowLocation', $isShowLocation);
511 if ($pcpId && $pcpSupporter = CRM_PCP_BAO_PCP
::displayName($pcpId)) {
512 $this->assign('pcpSupporterText', ts('This event registration is being made thanks to effort of <strong>%1</strong>, who supports our campaign. You can support it as well - once you complete the registration, you will be able to create your own Personal Campaign Page!', array(1 => $pcpSupporter)));
516 $config = CRM_Core_Config
::singleton();
517 $config->defaultCurrency
= CRM_Utils_Array
::value('currency',
518 $this->_values
['event'],
519 $config->defaultCurrency
522 //lets allow user to override campaign.
523 $campID = CRM_Utils_Request
::retrieve('campID', 'Positive', $this);
524 if ($campID && CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) {
525 $this->_values
['event']['campaign_id'] = $campID;
530 * assign the minimal set of variables to the template
535 function assignToTemplate() {
536 //process only primary participant params
537 $this->_params
= $this->get('params');
538 if (isset($this->_params
[0])) {
539 $params = $this->_params
[0];
542 if (CRM_Utils_Array
::value('billing_first_name', $params)) {
543 $name = $params['billing_first_name'];
546 if (CRM_Utils_Array
::value('billing_middle_name', $params)) {
547 $name .= " {$params['billing_middle_name']}";
550 if (CRM_Utils_Array
::value('billing_last_name', $params)) {
551 $name .= " {$params['billing_last_name']}";
553 $this->assign('billingName', $name);
554 $this->set('name', $name);
557 'amount', 'currencyID', 'credit_card_type',
558 'trxn_id', 'amount_level', 'receive_date',
561 foreach ($vars as $v) {
562 if (CRM_Utils_Array
::value($v, $params)) {
563 if ($v == 'receive_date') {
564 $this->assign($v, CRM_Utils_Date
::mysqlToIso($params[$v]));
567 $this->assign($v, $params[$v]);
570 elseif (CRM_Utils_Array
::value('amount', $params) == 0) {
571 $this->assign($v, CRM_Utils_Array
::value($v, $params));
575 // assign the address formatted up for display
576 $addressParts = array(
577 "street_address-{$this->_bltID}",
578 "city-{$this->_bltID}",
579 "postal_code-{$this->_bltID}",
580 "state_province-{$this->_bltID}",
581 "country-{$this->_bltID}",
583 $addressFields = array();
584 foreach ($addressParts as $part) {
585 list($n, $id) = explode('-', $part);
586 if (isset($params['billing_' . $part])) {
587 $addressFields[$n] = CRM_Utils_Array
::value('billing_' . $part, $params);
591 $this->assign('address', CRM_Utils_Address
::format($addressFields));
593 if ($this->_contributeMode
== 'direct' &&
594 !CRM_Utils_Array
::value('is_pay_later', $params)
596 $date = CRM_Utils_Date
::format(CRM_Utils_Array
::value('credit_card_exp_date', $params));
597 $date = CRM_Utils_Date
::mysqlToIso($date);
598 $this->assign('credit_card_exp_date', $date);
599 $this->assign('credit_card_number',
600 CRM_Utils_System
::mungeCreditCard(CRM_Utils_Array
::value('credit_card_number', $params))
604 // get the email that the confirmation would have been sent to
605 $session = CRM_Core_Session
::singleton();
607 // assign is_email_confirm to templates
608 if (isset($this->_values
['event']['is_email_confirm'])) {
609 $this->assign('is_email_confirm', $this->_values
['event']['is_email_confirm']);
612 // assign pay later stuff
613 $params['is_pay_later'] = CRM_Utils_Array
::value('is_pay_later', $params, FALSE);
614 $this->assign('is_pay_later', $params['is_pay_later']);
615 if ($params['is_pay_later']) {
616 $this->assign('pay_later_text', $this->_values
['event']['pay_later_text']);
617 $this->assign('pay_later_receipt', $this->_values
['event']['pay_later_receipt']);
620 // also assign all participantIDs to the template
621 // useful in generating confirmation numbers if needed
622 $this->assign('participantIDs',
623 $this->_participantIDS
628 * Function to add the custom fields
633 function buildCustom($id, $name, $viewOnly = FALSE) {
634 $stateCountryMap = $fields = array();
637 $button = substr($this->controller
->getButtonName(), -4);
638 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
639 $session = CRM_Core_Session
::singleton();
640 $contactID = $session->get('userID');
642 // we don't allow conflicting fields to be
643 // configured via profile
644 $fieldsToIgnore = array(
645 'participant_fee_amount' => 1,
646 'participant_fee_level' => 1,
652 foreach ($id as $profileID) {
653 $field = CRM_Core_BAO_UFGroup
::getFields($profileID, FALSE, CRM_Core_Action
::ADD
,
654 NULL, NULL, FALSE, NULL,
655 FALSE, NULL, CRM_Core_Permission
::CREATE
,
658 $fields = array_merge($fields, $field);
662 if (CRM_Core_BAO_UFGroup
::filterUFGroups($id, $contactID)) {
663 $fields = CRM_Core_BAO_UFGroup
::getFields($id, FALSE, CRM_Core_Action
::ADD
,
664 NULL, NULL, FALSE, NULL,
665 FALSE, NULL, CRM_Core_Permission
::CREATE
,
672 $fields = CRM_Core_BAO_UFGroup
::getFields($id, FALSE, CRM_Core_Action
::ADD
,
673 NULL, NULL, FALSE, NULL,
674 FALSE, NULL, CRM_Core_Permission
::CREATE
,
679 if (array_intersect_key($fields, $fieldsToIgnore)) {
680 $fields = array_diff_key($fields, $fieldsToIgnore);
681 CRM_Core_Session
::setStatus(ts('Some of the profile fields cannot be configured for this page.'));
684 $fields = array_diff_assoc($fields, $this->_fields
);
685 if (!CRM_Utils_Array
::value('additional_participants', $this->_params
[0]) &&
688 CRM_Core_BAO_Address
::checkContactSharedAddressFields($fields, $contactID);
690 $this->assign($name, $fields);
691 $profileAddressFields = array();
692 if (is_array($fields)) {
693 foreach ($fields as $key => $field) {
695 isset($field['data_type']) &&
696 $field['data_type'] == 'File' ||
($viewOnly && $field['name'] == 'image_URL')
698 // ignore file upload fields
701 //make the field optional if primary participant
702 //have been skip the additional participant.
703 if ($button == 'skip') {
704 $field['is_required'] = FALSE;
706 elseif ($field['add_captcha']) {
707 // only add captcha for first page
711 list($prefixName, $index) = CRM_Utils_System
::explode('-', $key, 2);
712 if ($prefixName == 'state_province' ||
$prefixName == 'country' ||
$prefixName == 'county') {
713 if (!array_key_exists($index, $stateCountryMap)) {
714 $stateCountryMap[$index] = array();
716 $stateCountryMap[$index][$prefixName] = $key;
718 CRM_Core_BAO_UFField
::assignAddressField($key, $profileAddressFields);
719 CRM_Core_BAO_UFGroup
::buildProfile($this, $field, CRM_Profile_Form
::MODE_CREATE
, $contactID, TRUE);
721 $this->_fields
[$key] = $field;
724 if (!empty($profileAddressFields)) {
725 $this->set('profileAddressFields', $profileAddressFields);
727 CRM_Core_BAO_Address
::addStateCountryMap($stateCountryMap);
729 if ($addCaptcha && !$viewOnly) {
730 $captcha = CRM_Utils_ReCAPTCHA
::singleton();
731 $captcha->add($this);
732 $this->assign('isCaptcha', TRUE);
737 static function initEventFee(&$form, $eventID) {
740 // retrive all active price set fields.
741 $discountId = CRM_Core_BAO_Discount
::findSet($eventID, 'civicrm_event');
743 $priceSetId = CRM_Core_DAO
::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id');
744 $price = CRM_Price_BAO_Set
::initSet($form, $eventID, 'civicrm_event', TRUE, $priceSetId);
747 $price = CRM_Price_BAO_Set
::initSet($form, $eventID, 'civicrm_event', TRUE);
750 $eventFee = CRM_Utils_Array
::value('fee', $form->_values
);
751 if (!is_array($eventFee) ||
empty($eventFee)) {
752 $form->_values
['fee'] = array();
755 //fix for non-upgraded price sets.CRM-4256.
756 if (isset($form->_isPaidEvent
)) {
757 $isPaidEvent = $form->_isPaidEvent
;
760 $isPaidEvent = CRM_Utils_Array
::value('is_monetary', $form->_values
['event']);
762 if ($isPaidEvent && empty($form->_values
['fee'])) {
763 if (CRM_Utils_System
::getClassName($form) != 'CRM_Event_Form_Participant') {
764 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
))));
770 * Function to handle process after the confirmation of payment by User
775 function confirmPostProcess($contactID = NULL, $contribution = NULL, $payment = NULL) {
776 // add/update contact information
778 unset($this->_params
['note']);
780 //to avoid conflict overwrite $this->_params
781 $this->_params
= $this->get('value');
783 //get the amount of primary participant
784 if (CRM_Utils_Array
::value('is_primary', $this->_params
)) {
785 $this->_params
['fee_amount'] = $this->get('primaryParticipantAmount');
788 // add participant record
789 $participant = $this->addParticipant($this->_params
, $contactID);
790 $this->_participantIDS
[] = $participant->id
;
792 //setting register_by_id field and primaryContactId
793 if (CRM_Utils_Array
::value('is_primary', $this->_params
)) {
794 $this->set('registerByID', $participant->id
);
795 $this->set('primaryContactId', $contactID);
798 $this->processFirstParticipant($participant->id
);
801 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
802 CRM_Core_DAO
::$_nullArray,
803 'civicrm_participant',
808 $createPayment = (CRM_Utils_Array
::value('amount', $this->_params
, 0) != 0) ?
TRUE : FALSE;
810 // force to create zero amount payment, CRM-5095
811 // we know the amout is zero since createPayment is false
812 if (!$createPayment &&
813 (isset($contribution) && $contribution->id
) &&
814 $this->_priceSetId
&&
817 $createPayment = TRUE;
820 if ($createPayment && $this->_values
['event']['is_monetary'] &&
821 CRM_Utils_Array
::value('contributionID', $this->_params
)
823 $paymentParams = array(
824 'participant_id' => $participant->id
,
825 'contribution_id' => $contribution->id
,
828 $paymentPartcipant = CRM_Event_BAO_ParticipantPayment
::create($paymentParams, $ids);
831 //set only primary participant's params for transfer checkout.
832 if (($this->_contributeMode
== 'checkout' ||
$this->_contributeMode
== 'notify')
833 && CRM_Utils_Array
::value('is_primary', $this->_params
)
835 $this->_params
['participantID'] = $participant->id
;
836 $this->set('primaryParticipant', $this->_params
);
839 $this->assign('action', $this->_action
);
842 if (CRM_Utils_Array
::value('cms_create_account', $this->_params
)) {
843 $this->_params
['contactID'] = $contactID;
845 if (array_key_exists('email-5', $this->_params
)) {
848 foreach ($this->_params
as $name => $dontCare) {
849 if (substr($name, 0, 5) == 'email') {
856 // we should use primary email for
857 // 1. free event registration.
858 // 2. pay later participant.
859 // 3. waiting list participant.
860 // 4. require approval participant.
861 if (CRM_Utils_Array
::value('is_pay_later', $this->_params
) ||
862 $this->_allowWaitlist ||
$this->_requireApproval ||
863 !CRM_Utils_Array
::value('is_monetary', $this->_values
['event'])
865 $mail = 'email-Primary';
868 if (!CRM_Core_BAO_CMSUser
::create($this->_params
, $mail)) {
869 CRM_Core_Error
::statusBounce(ts('Your profile is not saved and Account is not created.'));
875 * Process the participant
880 public function addParticipant($params, $contactID) {
882 $transaction = new CRM_Core_Transaction();
884 $groupName = 'participant_role';
886 SELECT v.label as label ,v.value as value
887 FROM civicrm_option_value v,
888 civicrm_option_group g
889 WHERE v.option_group_id = g.id
894 $p = array(1 => array($groupName, 'String'));
896 $dao = CRM_Core_DAO
::executeQuery($query, $p);
898 $roleID = $dao->value
;
901 // handle register date CRM-4320
902 $registerDate = NULL;
903 if ($this->_allowConfirmation
&& $this->_participantId
) {
904 $registerDate = $params['participant_register_date'];
906 elseif (CRM_Utils_Array
::value('participant_register_date', $params) &&
907 is_array($params['participant_register_date']) &&
908 !empty($params['participant_register_date'])
910 $registerDate = CRM_Utils_Date
::format($params['participant_register_date']);
913 $participantParams = array('id' => CRM_Utils_Array
::value('participant_id', $params),
914 'contact_id' => $contactID,
915 'event_id' => $this->_eventId ?
$this->_eventId
: $params['event_id'],
916 'status_id' => CRM_Utils_Array
::value('participant_status',
919 'role_id' => CRM_Utils_Array
::value('participant_role_id',
922 'register_date' => ($registerDate) ?
$registerDate : date('YmdHis'),
923 'source' => isset($params['participant_source']) ?
924 CRM_Utils_Array
::value('participant_source', $params) : CRM_Utils_Array
::value('description', $params),
925 'fee_level' => CRM_Utils_Array
::value('amount_level', $params),
926 'is_pay_later' => CRM_Utils_Array
::value('is_pay_later', $params, 0),
927 'fee_amount' => CRM_Utils_Array
::value('fee_amount', $params),
928 'registered_by_id' => CRM_Utils_Array
::value('registered_by_id', $params),
929 'discount_id' => CRM_Utils_Array
::value('discount_id', $params),
930 'fee_currency' => CRM_Utils_Array
::value('currencyID', $params),
931 'campaign_id' => CRM_Utils_Array
::value('campaign_id', $params),
934 if ($this->_action
& CRM_Core_Action
::PREVIEW || CRM_Utils_Array
::value('mode', $params) == 'test') {
935 $participantParams['is_test'] = 1;
938 $participantParams['is_test'] = 0;
941 if (CRM_Utils_Array
::value('note', $this->_params
)) {
942 $participantParams['note'] = $this->_params
['note'];
944 elseif (CRM_Utils_Array
::value('participant_note', $this->_params
)) {
945 $participantParams['note'] = $this->_params
['participant_note'];
948 // reuse id if one already exists for this one (can happen
949 // with back button being hit etc)
950 if (!$participantParams['id'] &&
951 CRM_Utils_Array
::value('contributionID', $params)
953 $pID = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
954 $params['contributionID'],
958 $participantParams['id'] = $pID;
960 $participantParams['discount_id'] = CRM_Core_BAO_Discount
::findSet($this->_eventId
, 'civicrm_event');
962 if (!$participantParams['discount_id']) {
963 $participantParams['discount_id'] = "null";
966 $participant = CRM_Event_BAO_Participant
::create($participantParams);
968 $transaction->commit();
973 /* Calculate the total participant count as per params.
975 * @param array $params user params.
977 * @return $totalCount total participant count.
980 public static function getParticipantCount(&$form, $params, $skipCurrent = FALSE) {
982 if (!is_array($params) ||
empty($params)) {
986 $priceSetId = $form->get('priceSetId');
987 $addParticipantNum = substr($form->_name
, 12);
988 $priceSetFields = $priceSetDetails = array();
989 $hasPriceFieldsCount = FALSE;
991 $priceSetDetails = $form->get('priceSet');
992 if (isset($priceSetDetails['optionsCountTotal'])
993 && $priceSetDetails['optionsCountTotal']
995 $hasPriceFieldsCount = TRUE;
996 $priceSetFields = $priceSetDetails['optionsCountDetails']['fields'];
1000 $singleFormParams = FALSE;
1001 foreach ($params as $key => $val) {
1002 if (!is_numeric($key)) {
1003 $singleFormParams = TRUE;
1008 //first format the params.
1009 if ($singleFormParams) {
1010 $params = self
::formatPriceSetParams($form, $params);
1011 $params = array($params);
1014 foreach ($params as $key => $values) {
1015 if (!is_numeric($key) ||
1016 $values == 'skip' ||
1017 ($skipCurrent && ($addParticipantNum == $key))
1024 $cacheCount = CRM_Utils_Array
::value($key, $form->_lineItemParticipantsCount
);
1025 if ($cacheCount && is_numeric($cacheCount)) {
1026 $count = $cacheCount;
1030 if (!$usedCache && $hasPriceFieldsCount) {
1032 foreach ($values as $valKey => $value) {
1033 if (strpos($valKey, 'price_') === FALSE) {
1036 $priceFieldId = substr($valKey, 6);
1037 if (!$priceFieldId ||
1038 !is_array($value) ||
1039 !array_key_exists($priceFieldId, $priceSetFields)
1043 foreach ($value as $optId => $optVal) {
1044 $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal;
1045 if ($currentCount) {
1046 $count +
= $currentCount;
1054 $totalCount +
= $count;
1063 /* Format user submitted price set params.
1064 * Convert price set each param as an array.
1066 * @param $params an array of user submitted params.
1069 * @return array $formatted, formatted price set params.
1072 public static function formatPriceSetParams(&$form, $params) {
1073 if (!is_array($params) ||
empty($params)) {
1077 $priceSetId = $form->get('priceSetId');
1081 $priceSetDetails = $form->get('priceSet');
1083 foreach ($params as $key => & $value) {
1085 if (strpos($key, 'price_') !== FALSE) {
1086 $fieldId = substr($key, 6);
1087 if (!array_key_exists($fieldId, $priceSetDetails['fields']) ||
1093 $field = $priceSetDetails['fields'][$fieldId];
1094 if ($field['html_type'] == 'Text') {
1095 $fieldOption = current($field['options']);
1096 $value = array($fieldOption['id'] => $value);
1099 $value = array($value => TRUE);
1107 /* Calculate total count for each price set options.
1108 * those are currently selected by user.
1110 * @param $form form object.
1113 * @return array $optionsCount, array of each option w/ count total.
1116 function getPriceSetOptionCount(&$form) {
1117 $params = $form->get('params');
1118 $priceSet = $form->get('priceSet');
1119 $priceSetId = $form->get('priceSetId');
1121 $optionsCount = array();
1123 !is_array($priceSet) ||
1125 !is_array($params) ||
1128 return $optionsCount;
1131 $priceSetFields = $priceMaxFieldDetails = array();
1132 if (CRM_Utils_Array
::value('optionsCountTotal', $priceSet)) {
1133 $priceSetFields = $priceSet['optionsCountDetails']['fields'];
1136 if (CRM_Utils_Array
::value('optionsMaxValueTotal', $priceSet)) {
1137 $priceMaxFieldDetails = $priceSet['optionsMaxValueDetails']['fields'];
1140 $addParticipantNum = substr($form->_name
, 12);
1141 foreach ($params as $pCnt => $values) {
1142 if ($values == 'skip' ||
1143 $pCnt == $addParticipantNum
1148 foreach ($values as $valKey => $value) {
1149 if (strpos($valKey, 'price_') === FALSE) {
1153 $priceFieldId = substr($valKey, 6);
1154 if (!$priceFieldId ||
1155 !is_array($value) ||
1156 !(array_key_exists($priceFieldId, $priceSetFields) ||
array_key_exists($priceFieldId, $priceMaxFieldDetails))
1161 foreach ($value as $optId => $optVal) {
1162 if (CRM_Utils_Array
::value('html_type', $priceSet['fields'][$priceFieldId]) == 'Text') {
1163 $currentCount = $optVal;
1169 if (isset($priceSetFields[$priceFieldId]) && isset($priceSetFields[$priceFieldId]['options'][$optId])) {
1170 $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal;
1173 $optionsCount[$optId] = $currentCount + CRM_Utils_Array
::value($optId, $optionsCount, 0);
1178 return $optionsCount;
1181 function checkTemplateFileExists($suffix = '') {
1182 if ($this->_eventId
) {
1183 $templateName = $this->_name
;
1184 if (substr($templateName, 0, 12) == 'Participant_') {
1185 $templateName = 'AdditionalParticipant';
1188 $templateFile = "CRM/Event/Form/Registration/{$this->_eventId}/{$templateName}.{$suffix}tpl";
1189 $template = CRM_Core_Form
::getTemplate();
1190 if ($template->template_exists($templateFile)) {
1191 return $templateFile;
1197 function getTemplateFileName() {
1198 $fileName = $this->checkTemplateFileExists();
1199 return $fileName ?
$fileName : parent
::getTemplateFileName();
1202 function overrideExtraTemplateFileName() {
1203 $fileName = $this->checkTemplateFileExists('extra.');
1204 return $fileName ?
$fileName : parent
::overrideExtraTemplateFileName();
1207 function getContactID() {
1208 $tempID = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
1210 // force to ignore the authenticated user
1211 if ($tempID === '0') {
1215 // check if the user is logged in and has a contact ID
1216 $session = CRM_Core_Session
::singleton();
1217 $userID = $session->get('userID');
1219 if ($tempID == $userID) {
1223 //check if this is a checksum authentication
1224 $userChecksum = CRM_Utils_Request
::retrieve('cs', 'String', $this);
1225 if ($userChecksum) {
1226 //check for anonymous user.
1227 $validUser = CRM_Contact_BAO_Contact_Utils
::validChecksum($tempID, $userChecksum);
1232 // check if user has permission, CRM-12062
1233 else if (CRM_Contact_BAO_Contact_Permission
::allow($tempID)) {
1240 /* Validate price set submitted params for price option limit,
1241 * as well as user should select at least one price field option.
1244 static function validatePriceSet(&$form, $params) {
1246 $hasOptMaxValue = FALSE;
1247 if (!is_array($params) ||
empty($params)) {
1251 $currentParticipantNum = substr($form->_name
, 12);
1252 if (!$currentParticipantNum) {
1253 $currentParticipantNum = 0;
1256 $priceSetId = $form->get('priceSetId');
1257 $priceSetDetails = $form->get('priceSet');
1260 !is_array($priceSetDetails) ||
1261 empty($priceSetDetails)
1266 $optionsCountDetails = $optionsMaxValueDetails = array();
1268 isset($priceSetDetails['optionsMaxValueTotal'])
1269 && $priceSetDetails['optionsMaxValueTotal']
1271 $hasOptMaxValue = TRUE;
1272 $optionsMaxValueDetails = $priceSetDetails['optionsMaxValueDetails']['fields'];
1275 isset($priceSetDetails['optionsCountTotal'])
1276 && $priceSetDetails['optionsCountTotal']
1278 $hasOptCount = TRUE;
1279 $optionsCountDetails = $priceSetDetails['optionsCountDetails']['fields'];
1281 $feeBlock = $form->_feeBlock
;
1283 if (empty($feeBlock)) {
1284 $feeBlock = $priceSetDetails['fields'];
1287 $optionMaxValues = $fieldSelected = array();
1288 foreach ($params as $pNum => $values) {
1289 if (!is_array($values) ||
$values == 'skip') {
1293 foreach ($values as $valKey => $value) {
1294 if (strpos($valKey, 'price_') === FALSE) {
1297 $priceFieldId = substr($valKey, 6);
1298 $noneOptionValueSelected = FALSE;
1299 if (!$feeBlock[$priceFieldId]['is_required'] && $value == 0) {
1300 $noneOptionValueSelected = TRUE;
1305 (!$noneOptionValueSelected && !is_array($value))
1310 $fieldSelected[$pNum] = TRUE;
1312 if (!$hasOptMaxValue ||
!is_array($value)) {
1316 foreach ($value as $optId => $optVal) {
1317 if (CRM_Utils_Array
::value('html_type', $feeBlock[$priceFieldId]) == 'Text') {
1318 $currentMaxValue = $optVal;
1321 $currentMaxValue = 1;
1324 if (isset($optionsCountDetails[$priceFieldId]) && isset($optionsCountDetails[$priceFieldId]['options'][$optId])) {
1325 $currentMaxValue = $optionsCountDetails[$priceFieldId]['options'][$optId] * $optVal;
1327 if (empty($optionMaxValues)) {
1328 $optionMaxValues[$priceFieldId][$optId] = $currentMaxValue;
1331 $optionMaxValues[$priceFieldId][$optId] =
1332 $currentMaxValue + CRM_Utils_Array
::value($optId, CRM_Utils_Array
::value($priceFieldId, $optionMaxValues), 0);
1339 //validate for option max value.
1340 foreach ($optionMaxValues as $fieldId => $values) {
1341 $options = CRM_Utils_Array
::value('options', $feeBlock[$fieldId], array());
1342 foreach ($values as $optId => $total) {
1343 $optMax = $optionsMaxValueDetails[$fieldId]['options'][$optId];
1344 $opDbCount = CRM_Utils_Array
::value('db_total_count', $options[$optId], 0);
1345 $total +
= $opDbCount;
1346 if ($optMax && $total > $optMax) {
1347 if ($opDbCount && ($opDbCount >= $optMax)) {
1348 $errors[$currentParticipantNum]["price_{$fieldId}"] =
1349 ts('Sorry, this option is currently sold out.');
1351 elseif (($optMax - $opDbCount) == 1) {
1352 $errors[$currentParticipantNum]["price_{$fieldId}"] =
1353 ts('Sorry, currently only a single seat is available for this option.', array(1 => ($optMax - $opDbCount)));
1356 $errors[$currentParticipantNum]["price_{$fieldId}"] =
1357 ts('Sorry, currently only %1 seats are available for this option.', array(1 => ($optMax - $opDbCount)));
1363 //validate for price field selection.
1364 foreach ($params as $pNum => $values) {
1365 if (!is_array($values) ||
$values == 'skip') {
1368 if (!CRM_Utils_Array
::value($pNum, $fieldSelected)) {
1369 $errors[$pNum]['_qf_default'] = ts('Select at least one option from Event Fee(s).');
1376 // set the first participant ID if not set, CRM-10032
1377 function processFirstParticipant($participantID) {
1378 $this->_participantId
= $participantID;
1379 $this->set('participantId', $this->_participantId
);
1381 $ids = $participantValues = array();
1382 $participantParams = array('id' => $this->_participantId
);
1383 CRM_Event_BAO_Participant
::getValues($participantParams, $participantValues, $ids);
1384 $this->_values
['participant'] = $participantValues[$this->_participantId
];
1385 $this->set('values', $this->_values
);
1387 // also set the allow confirmation stuff
1388 if (array_key_exists(
1389 $this->_values
['participant']['status_id'],
1390 CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Pending'")
1392 $this->_allowConfirmation
= TRUE;
1393 $this->set('allowConfirmation', TRUE);
1397 function checkValidEvent($redirect = NULL) {
1398 // is the event active (enabled)?
1399 if (!$this->_values
['event']['is_active']) {
1400 // form is inactive, die a fatal death
1401 CRM_Core_Error
::statusBounce(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
1404 // is online registration is enabled?
1405 if (!$this->_values
['event']['is_online_registration']) {
1406 CRM_Core_Error
::statusBounce(ts('Online registration is not currently available for this event (contact the site administrator for assistance).'), $redirect);
1409 // is this an event template ?
1410 if (CRM_Utils_Array
::value('is_template', $this->_values
['event'])) {
1411 CRM_Core_Error
::statusBounce(ts('Event templates are not meant to be registered.'), $redirect);
1414 $now = date('YmdHis');
1415 $startDate = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('registration_start_date',
1416 $this->_values
['event']
1423 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);
1426 $endDate = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('registration_end_date',
1427 $this->_values
['event']
1433 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);