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
::get('CRM_Core_DAO_Address', 'location_type_id');
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 if (is_array($fields)) {
692 foreach ($fields as $key => $field) {
694 isset($field['data_type']) &&
695 $field['data_type'] == 'File' ||
($viewOnly && $field['name'] == 'image_URL')
697 // ignore file upload fields
700 //make the field optional if primary participant
701 //have been skip the additional participant.
702 if ($button == 'skip') {
703 $field['is_required'] = FALSE;
705 elseif ($field['add_captcha']) {
706 // only add captcha for first page
710 list($prefixName, $index) = CRM_Utils_System
::explode('-', $key, 2);
711 if ($prefixName == 'state_province' ||
$prefixName == 'country' ||
$prefixName == 'county') {
712 if (!array_key_exists($index, $stateCountryMap)) {
713 $stateCountryMap[$index] = array();
715 $stateCountryMap[$index][$prefixName] = $key;
717 CRM_Core_BAO_UFGroup
::buildProfile($this, $field, CRM_Profile_Form
::MODE_CREATE
, $contactID, TRUE);
719 $this->_fields
[$key] = $field;
723 CRM_Core_BAO_Address
::addStateCountryMap($stateCountryMap);
725 if ($addCaptcha && !$viewOnly) {
726 $captcha = CRM_Utils_ReCAPTCHA
::singleton();
727 $captcha->add($this);
728 $this->assign('isCaptcha', TRUE);
733 static function initEventFee(&$form, $eventID) {
736 // retrive all active price set fields.
737 $discountId = CRM_Core_BAO_Discount
::findSet($eventID, 'civicrm_event');
739 $priceSetId = CRM_Core_DAO
::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id');
740 $price = CRM_Price_BAO_Set
::initSet($form, $eventID, 'civicrm_event', TRUE, $priceSetId);
743 $price = CRM_Price_BAO_Set
::initSet($form, $eventID, 'civicrm_event', TRUE);
746 $eventFee = CRM_Utils_Array
::value('fee', $form->_values
);
747 if (!is_array($eventFee) ||
empty($eventFee)) {
748 $form->_values
['fee'] = array();
751 //fix for non-upgraded price sets.CRM-4256.
752 if (isset($form->_isPaidEvent
)) {
753 $isPaidEvent = $form->_isPaidEvent
;
756 $isPaidEvent = CRM_Utils_Array
::value('is_monetary', $form->_values
['event']);
758 if ($isPaidEvent && empty($form->_values
['fee'])) {
759 if (CRM_Utils_System
::getClassName($form) != 'CRM_Event_Form_Participant') {
760 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
))));
766 * Function to handle process after the confirmation of payment by User
771 function confirmPostProcess($contactID = NULL, $contribution = NULL, $payment = NULL) {
772 // add/update contact information
774 unset($this->_params
['note']);
776 //to avoid conflict overwrite $this->_params
777 $this->_params
= $this->get('value');
779 //get the amount of primary participant
780 if (CRM_Utils_Array
::value('is_primary', $this->_params
)) {
781 $this->_params
['fee_amount'] = $this->get('primaryParticipantAmount');
784 // add participant record
785 $participant = $this->addParticipant($this->_params
, $contactID);
786 $this->_participantIDS
[] = $participant->id
;
788 //setting register_by_id field and primaryContactId
789 if (CRM_Utils_Array
::value('is_primary', $this->_params
)) {
790 $this->set('registerByID', $participant->id
);
791 $this->set('primaryContactId', $contactID);
794 $this->processFirstParticipant($participant->id
);
797 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
798 CRM_Core_DAO
::$_nullArray,
799 'civicrm_participant',
804 $createPayment = (CRM_Utils_Array
::value('amount', $this->_params
, 0) != 0) ?
TRUE : FALSE;
806 // force to create zero amount payment, CRM-5095
807 // we know the amout is zero since createPayment is false
808 if (!$createPayment &&
809 (isset($contribution) && $contribution->id
) &&
810 $this->_priceSetId
&&
813 $createPayment = TRUE;
816 if ($createPayment && $this->_values
['event']['is_monetary'] &&
817 CRM_Utils_Array
::value('contributionID', $this->_params
)
819 $paymentParams = array(
820 'participant_id' => $participant->id
,
821 'contribution_id' => $contribution->id
,
824 $paymentPartcipant = CRM_Event_BAO_ParticipantPayment
::create($paymentParams, $ids);
827 //set only primary participant's params for transfer checkout.
828 if (($this->_contributeMode
== 'checkout' ||
$this->_contributeMode
== 'notify')
829 && CRM_Utils_Array
::value('is_primary', $this->_params
)
831 $this->_params
['participantID'] = $participant->id
;
832 $this->set('primaryParticipant', $this->_params
);
835 $this->assign('action', $this->_action
);
838 if (CRM_Utils_Array
::value('cms_create_account', $this->_params
)) {
839 $this->_params
['contactID'] = $contactID;
841 if (array_key_exists('email-5', $this->_params
)) {
844 foreach ($this->_params
as $name => $dontCare) {
845 if (substr($name, 0, 5) == 'email') {
852 // we should use primary email for
853 // 1. free event registration.
854 // 2. pay later participant.
855 // 3. waiting list participant.
856 // 4. require approval participant.
857 if (CRM_Utils_Array
::value('is_pay_later', $this->_params
) ||
858 $this->_allowWaitlist ||
$this->_requireApproval ||
859 !CRM_Utils_Array
::value('is_monetary', $this->_values
['event'])
861 $mail = 'email-Primary';
864 if (!CRM_Core_BAO_CMSUser
::create($this->_params
, $mail)) {
865 CRM_Core_Error
::statusBounce(ts('Your profile is not saved and Account is not created.'));
871 * Process the participant
876 public function addParticipant($params, $contactID) {
878 $transaction = new CRM_Core_Transaction();
880 $groupName = 'participant_role';
882 SELECT v.label as label ,v.value as value
883 FROM civicrm_option_value v,
884 civicrm_option_group g
885 WHERE v.option_group_id = g.id
890 $p = array(1 => array($groupName, 'String'));
892 $dao = CRM_Core_DAO
::executeQuery($query, $p);
894 $roleID = $dao->value
;
897 // handle register date CRM-4320
898 $registerDate = NULL;
899 if ($this->_allowConfirmation
&& $this->_participantId
) {
900 $registerDate = $params['participant_register_date'];
902 elseif (CRM_Utils_Array
::value('participant_register_date', $params) &&
903 is_array($params['participant_register_date']) &&
904 !empty($params['participant_register_date'])
906 $registerDate = CRM_Utils_Date
::format($params['participant_register_date']);
909 $participantParams = array('id' => CRM_Utils_Array
::value('participant_id', $params),
910 'contact_id' => $contactID,
911 'event_id' => $this->_eventId ?
$this->_eventId
: $params['event_id'],
912 'status_id' => CRM_Utils_Array
::value('participant_status',
915 'role_id' => CRM_Utils_Array
::value('participant_role_id',
918 'register_date' => ($registerDate) ?
$registerDate : date('YmdHis'),
919 'source' => isset($params['participant_source']) ?
920 CRM_Utils_Array
::value('participant_source', $params) : CRM_Utils_Array
::value('description', $params),
921 'fee_level' => CRM_Utils_Array
::value('amount_level', $params),
922 'is_pay_later' => CRM_Utils_Array
::value('is_pay_later', $params, 0),
923 'fee_amount' => CRM_Utils_Array
::value('fee_amount', $params),
924 'registered_by_id' => CRM_Utils_Array
::value('registered_by_id', $params),
925 'discount_id' => CRM_Utils_Array
::value('discount_id', $params),
926 'fee_currency' => CRM_Utils_Array
::value('currencyID', $params),
927 'campaign_id' => CRM_Utils_Array
::value('campaign_id', $params),
930 if ($this->_action
& CRM_Core_Action
::PREVIEW || CRM_Utils_Array
::value('mode', $params) == 'test') {
931 $participantParams['is_test'] = 1;
934 $participantParams['is_test'] = 0;
937 if (CRM_Utils_Array
::value('note', $this->_params
)) {
938 $participantParams['note'] = $this->_params
['note'];
940 elseif (CRM_Utils_Array
::value('participant_note', $this->_params
)) {
941 $participantParams['note'] = $this->_params
['participant_note'];
944 // reuse id if one already exists for this one (can happen
945 // with back button being hit etc)
946 if (!$participantParams['id'] &&
947 CRM_Utils_Array
::value('contributionID', $params)
949 $pID = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
950 $params['contributionID'],
954 $participantParams['id'] = $pID;
956 $participantParams['discount_id'] = CRM_Core_BAO_Discount
::findSet($this->_eventId
, 'civicrm_event');
958 if (!$participantParams['discount_id']) {
959 $participantParams['discount_id'] = "null";
962 $participant = CRM_Event_BAO_Participant
::create($participantParams);
964 $transaction->commit();
969 /* Calculate the total participant count as per params.
971 * @param array $params user params.
973 * @return $totalCount total participant count.
976 public static function getParticipantCount(&$form, $params, $skipCurrent = FALSE) {
978 if (!is_array($params) ||
empty($params)) {
982 $priceSetId = $form->get('priceSetId');
983 $addParticipantNum = substr($form->_name
, 12);
984 $priceSetFields = $priceSetDetails = array();
985 $hasPriceFieldsCount = FALSE;
987 $priceSetDetails = $form->get('priceSet');
988 if (isset($priceSetDetails['optionsCountTotal'])
989 && $priceSetDetails['optionsCountTotal']
991 $hasPriceFieldsCount = TRUE;
992 $priceSetFields = $priceSetDetails['optionsCountDetails']['fields'];
996 $singleFormParams = FALSE;
997 foreach ($params as $key => $val) {
998 if (!is_numeric($key)) {
999 $singleFormParams = TRUE;
1004 //first format the params.
1005 if ($singleFormParams) {
1006 $params = self
::formatPriceSetParams($form, $params);
1007 $params = array($params);
1010 foreach ($params as $key => $values) {
1011 if (!is_numeric($key) ||
1012 $values == 'skip' ||
1013 ($skipCurrent && ($addParticipantNum == $key))
1020 $cacheCount = CRM_Utils_Array
::value($key, $form->_lineItemParticipantsCount
);
1021 if ($cacheCount && is_numeric($cacheCount)) {
1022 $count = $cacheCount;
1026 if (!$usedCache && $hasPriceFieldsCount) {
1028 foreach ($values as $valKey => $value) {
1029 if (strpos($valKey, 'price_') === FALSE) {
1032 $priceFieldId = substr($valKey, 6);
1033 if (!$priceFieldId ||
1034 !is_array($value) ||
1035 !array_key_exists($priceFieldId, $priceSetFields)
1039 foreach ($value as $optId => $optVal) {
1040 $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal;
1041 if ($currentCount) {
1042 $count +
= $currentCount;
1050 $totalCount +
= $count;
1059 /* Format user submitted price set params.
1060 * Convert price set each param as an array.
1062 * @param $params an array of user submitted params.
1065 * @return array $formatted, formatted price set params.
1068 public static function formatPriceSetParams(&$form, $params) {
1069 if (!is_array($params) ||
empty($params)) {
1073 $priceSetId = $form->get('priceSetId');
1077 $priceSetDetails = $form->get('priceSet');
1079 foreach ($params as $key => & $value) {
1081 if (strpos($key, 'price_') !== FALSE) {
1082 $fieldId = substr($key, 6);
1083 if (!array_key_exists($fieldId, $priceSetDetails['fields']) ||
1089 $field = $priceSetDetails['fields'][$fieldId];
1090 if ($field['html_type'] == 'Text') {
1091 $fieldOption = current($field['options']);
1092 $value = array($fieldOption['id'] => $value);
1095 $value = array($value => TRUE);
1103 /* Calculate total count for each price set options.
1104 * those are currently selected by user.
1106 * @param $form form object.
1109 * @return array $optionsCount, array of each option w/ count total.
1112 function getPriceSetOptionCount(&$form) {
1113 $params = $form->get('params');
1114 $priceSet = $form->get('priceSet');
1115 $priceSetId = $form->get('priceSetId');
1117 $optionsCount = array();
1119 !is_array($priceSet) ||
1121 !is_array($params) ||
1124 return $optionsCount;
1127 $priceSetFields = $priceMaxFieldDetails = array();
1128 if (CRM_Utils_Array
::value('optionsCountTotal', $priceSet)) {
1129 $priceSetFields = $priceSet['optionsCountDetails']['fields'];
1132 if (CRM_Utils_Array
::value('optionsMaxValueTotal', $priceSet)) {
1133 $priceMaxFieldDetails = $priceSet['optionsMaxValueDetails']['fields'];
1136 $addParticipantNum = substr($form->_name
, 12);
1137 foreach ($params as $pCnt => $values) {
1138 if ($values == 'skip' ||
1139 $pCnt == $addParticipantNum
1144 foreach ($values as $valKey => $value) {
1145 if (strpos($valKey, 'price_') === FALSE) {
1149 $priceFieldId = substr($valKey, 6);
1150 if (!$priceFieldId ||
1151 !is_array($value) ||
1152 !(array_key_exists($priceFieldId, $priceSetFields) ||
array_key_exists($priceFieldId, $priceMaxFieldDetails))
1157 foreach ($value as $optId => $optVal) {
1158 if (CRM_Utils_Array
::value('html_type', $priceSet['fields'][$priceFieldId]) == 'Text') {
1159 $currentCount = $optVal;
1165 if (isset($priceSetFields[$priceFieldId]) && isset($priceSetFields[$priceFieldId]['options'][$optId])) {
1166 $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal;
1169 $optionsCount[$optId] = $currentCount + CRM_Utils_Array
::value($optId, $optionsCount, 0);
1174 return $optionsCount;
1177 function checkTemplateFileExists($suffix = '') {
1178 if ($this->_eventId
) {
1179 $templateName = $this->_name
;
1180 if (substr($templateName, 0, 12) == 'Participant_') {
1181 $templateName = 'AdditionalParticipant';
1184 $templateFile = "CRM/Event/Form/Registration/{$this->_eventId}/{$templateName}.{$suffix}tpl";
1185 $template = CRM_Core_Form
::getTemplate();
1186 if ($template->template_exists($templateFile)) {
1187 return $templateFile;
1193 function getTemplateFileName() {
1194 $fileName = $this->checkTemplateFileExists();
1195 return $fileName ?
$fileName : parent
::getTemplateFileName();
1198 function overrideExtraTemplateFileName() {
1199 $fileName = $this->checkTemplateFileExists('extra.');
1200 return $fileName ?
$fileName : parent
::overrideExtraTemplateFileName();
1203 function getContactID() {
1204 $tempID = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
1206 // force to ignore the authenticated user
1207 if ($tempID === '0') {
1211 // check if the user is logged in and has a contact ID
1212 $session = CRM_Core_Session
::singleton();
1213 $userID = $session->get('userID');
1215 if ($tempID == $userID) {
1219 //check if this is a checksum authentication
1220 $userChecksum = CRM_Utils_Request
::retrieve('cs', 'String', $this);
1221 if ($userChecksum) {
1222 //check for anonymous user.
1223 $validUser = CRM_Contact_BAO_Contact_Utils
::validChecksum($tempID, $userChecksum);
1228 // check if user has permission, CRM-12062
1229 else if ($tempID && CRM_Contact_BAO_Contact_Permission
::allow($tempID)) {
1236 /* Validate price set submitted params for price option limit,
1237 * as well as user should select at least one price field option.
1240 static function validatePriceSet(&$form, $params) {
1242 $hasOptMaxValue = FALSE;
1243 if (!is_array($params) ||
empty($params)) {
1247 $currentParticipantNum = substr($form->_name
, 12);
1248 if (!$currentParticipantNum) {
1249 $currentParticipantNum = 0;
1252 $priceSetId = $form->get('priceSetId');
1253 $priceSetDetails = $form->get('priceSet');
1256 !is_array($priceSetDetails) ||
1257 empty($priceSetDetails)
1262 $optionsCountDetails = $optionsMaxValueDetails = array();
1264 isset($priceSetDetails['optionsMaxValueTotal'])
1265 && $priceSetDetails['optionsMaxValueTotal']
1267 $hasOptMaxValue = TRUE;
1268 $optionsMaxValueDetails = $priceSetDetails['optionsMaxValueDetails']['fields'];
1271 isset($priceSetDetails['optionsCountTotal'])
1272 && $priceSetDetails['optionsCountTotal']
1274 $hasOptCount = TRUE;
1275 $optionsCountDetails = $priceSetDetails['optionsCountDetails']['fields'];
1277 $feeBlock = $form->_feeBlock
;
1279 if (empty($feeBlock)) {
1280 $feeBlock = $priceSetDetails['fields'];
1283 $optionMaxValues = $fieldSelected = array();
1284 foreach ($params as $pNum => $values) {
1285 if (!is_array($values) ||
$values == 'skip') {
1289 foreach ($values as $valKey => $value) {
1290 if (strpos($valKey, 'price_') === FALSE) {
1293 $priceFieldId = substr($valKey, 6);
1294 $noneOptionValueSelected = FALSE;
1295 if (!$feeBlock[$priceFieldId]['is_required'] && $value == 0) {
1296 $noneOptionValueSelected = TRUE;
1301 (!$noneOptionValueSelected && !is_array($value))
1306 $fieldSelected[$pNum] = TRUE;
1308 if (!$hasOptMaxValue ||
!is_array($value)) {
1312 foreach ($value as $optId => $optVal) {
1313 if (CRM_Utils_Array
::value('html_type', $feeBlock[$priceFieldId]) == 'Text') {
1314 $currentMaxValue = $optVal;
1317 $currentMaxValue = 1;
1320 if (isset($optionsCountDetails[$priceFieldId]) && isset($optionsCountDetails[$priceFieldId]['options'][$optId])) {
1321 $currentMaxValue = $optionsCountDetails[$priceFieldId]['options'][$optId] * $optVal;
1323 if (empty($optionMaxValues)) {
1324 $optionMaxValues[$priceFieldId][$optId] = $currentMaxValue;
1327 $optionMaxValues[$priceFieldId][$optId] =
1328 $currentMaxValue + CRM_Utils_Array
::value($optId, CRM_Utils_Array
::value($priceFieldId, $optionMaxValues), 0);
1335 //validate for option max value.
1336 foreach ($optionMaxValues as $fieldId => $values) {
1337 $options = CRM_Utils_Array
::value('options', $feeBlock[$fieldId], array());
1338 foreach ($values as $optId => $total) {
1339 $optMax = $optionsMaxValueDetails[$fieldId]['options'][$optId];
1340 $opDbCount = CRM_Utils_Array
::value('db_total_count', $options[$optId], 0);
1341 $total +
= $opDbCount;
1342 if ($optMax && $total > $optMax) {
1343 if ($opDbCount && ($opDbCount >= $optMax)) {
1344 $errors[$currentParticipantNum]["price_{$fieldId}"] =
1345 ts('Sorry, this option is currently sold out.');
1347 elseif (($optMax - $opDbCount) == 1) {
1348 $errors[$currentParticipantNum]["price_{$fieldId}"] =
1349 ts('Sorry, currently only a single seat is available for this option.', array(1 => ($optMax - $opDbCount)));
1352 $errors[$currentParticipantNum]["price_{$fieldId}"] =
1353 ts('Sorry, currently only %1 seats are available for this option.', array(1 => ($optMax - $opDbCount)));
1359 //validate for price field selection.
1360 foreach ($params as $pNum => $values) {
1361 if (!is_array($values) ||
$values == 'skip') {
1364 if (!CRM_Utils_Array
::value($pNum, $fieldSelected)) {
1365 $errors[$pNum]['_qf_default'] = ts('Select at least one option from Event Fee(s).');
1372 // set the first participant ID if not set, CRM-10032
1373 function processFirstParticipant($participantID) {
1374 $this->_participantId
= $participantID;
1375 $this->set('participantId', $this->_participantId
);
1377 $ids = $participantValues = array();
1378 $participantParams = array('id' => $this->_participantId
);
1379 CRM_Event_BAO_Participant
::getValues($participantParams, $participantValues, $ids);
1380 $this->_values
['participant'] = $participantValues[$this->_participantId
];
1381 $this->set('values', $this->_values
);
1383 // also set the allow confirmation stuff
1384 if (array_key_exists(
1385 $this->_values
['participant']['status_id'],
1386 CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Pending'")
1388 $this->_allowConfirmation
= TRUE;
1389 $this->set('allowConfirmation', TRUE);
1393 function checkValidEvent($redirect = NULL) {
1394 // is the event active (enabled)?
1395 if (!$this->_values
['event']['is_active']) {
1396 // form is inactive, die a fatal death
1397 CRM_Core_Error
::statusBounce(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
1400 // is online registration is enabled?
1401 if (!$this->_values
['event']['is_online_registration']) {
1402 CRM_Core_Error
::statusBounce(ts('Online registration is not currently available for this event (contact the site administrator for assistance).'), $redirect);
1405 // is this an event template ?
1406 if (CRM_Utils_Array
::value('is_template', $this->_values
['event'])) {
1407 CRM_Core_Error
::statusBounce(ts('Event templates are not meant to be registered.'), $redirect);
1410 $now = date('YmdHis');
1411 $startDate = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('registration_start_date',
1412 $this->_values
['event']
1419 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);
1422 $endDate = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('registration_end_date',
1423 $this->_values
['event']
1429 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);