3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2016
34 * This class generates form components for processing Event.
36 class CRM_Event_Form_Registration
extends CRM_Core_Form
{
39 * How many locationBlocks should we display?
44 const LOCATION_BLOCKS
= 1;
47 * The id of the event we are proceessing.
54 * The array of ids of all the participant we are proceessing.
58 protected $_participantIDS = NULL;
61 * The id of the participant we are proceessing.
65 protected $_participantId;
68 * Is participant able to walk registration wizard.
72 public $_allowConfirmation;
75 * Is participant requires approval.
79 public $_requireApproval;
82 * Is event configured for waitlist.
86 public $_allowWaitlist;
89 * Store additional participant ids.
90 * when there are pre-registered.
94 public $_additionalParticipantIds;
97 * The mode that we are in.
105 * The values for the contribution db object.
112 * The paymentProcessor attributes for this page.
116 public $_paymentProcessor;
119 * The params submitted by the form and computed by the app.
126 * The fields involved in this contribution page.
133 * The billing location id for this contribiution page.
140 * Price Set ID, if the new price set method is used
144 public $_priceSetId = NULL;
147 * Array of fields for the price set.
157 /* Is event already full.
162 public $_isEventFull;
165 public $_lineItemParticipantsCount;
166 public $_availableRegistrations;
168 public $_forcePayement;
170 public $_isBillingAddressRequiredForPayLater;
173 * Set variables up before form is built.
175 public function preProcess() {
176 $this->_eventId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
177 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE);
180 $this->_participantId
= CRM_Utils_Request
::retrieve('participantId', 'Positive', $this);
183 $this->_mode
= ($this->_action
== 1024) ?
'test' : 'live';
185 $this->_values
= $this->get('values');
186 $this->_fields
= $this->get('fields');
187 $this->_bltID
= $this->get('bltID');
188 $this->_paymentProcessor
= $this->get('paymentProcessor');
189 $this->_priceSetId
= $this->get('priceSetId');
190 $this->_priceSet
= $this->get('priceSet');
191 $this->_lineItem
= $this->get('lineItem');
192 $this->_isEventFull
= $this->get('isEventFull');
193 $this->_lineItemParticipantsCount
= $this->get('lineItemParticipants');
194 if (!is_array($this->_lineItem
)) {
195 $this->_lineItem
= array();
197 if (!is_array($this->_lineItemParticipantsCount
)) {
198 $this->_lineItemParticipantsCount
= array();
200 $this->_availableRegistrations
= $this->get('availableRegistrations');
201 $this->_participantIDS
= $this->get('participantIDs');
203 //check if participant allow to walk registration wizard.
204 $this->_allowConfirmation
= $this->get('allowConfirmation');
206 // check for Approval
207 $this->_requireApproval
= $this->get('requireApproval');
209 // check for waitlisting.
210 $this->_allowWaitlist
= $this->get('allowWaitlist');
212 $this->_forcePayement
= $this->get('forcePayement');
214 //get the additional participant ids.
215 $this->_additionalParticipantIds
= $this->get('additionalParticipantIds');
216 $config = CRM_Core_Config
::singleton();
218 if (!$this->_values
) {
219 // create redirect URL to send folks back to event info page is registration not available
220 $infoUrl = CRM_Utils_System
::url('civicrm/event/info', "reset=1&id={$this->_eventId}",
221 FALSE, NULL, FALSE, TRUE
224 // this is the first time we are hitting this, so check for permissions here
225 if (!CRM_Core_Permission
::event(CRM_Core_Permission
::EDIT
, $this->_eventId
, 'register for events')) {
226 CRM_Core_Error
::statusBounce(ts('You do not have permission to register for this event'), $infoUrl);
229 // get all the values from the dao object
230 $this->_values
= $this->_fields
= array();
231 $this->_forcePayement
= FALSE;
233 //retrieve event information
234 $params = array('id' => $this->_eventId
);
235 CRM_Event_BAO_Event
::retrieve($params, $this->_values
['event']);
236 // check for is_monetary status
237 $isMonetary = CRM_Utils_Array
::value('is_monetary', $this->_values
['event']);
238 // check for ability to add contributions of type
240 && CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus()
241 && !CRM_Core_Permission
::check('add contributions of type ' . CRM_Contribute_PseudoConstant
::financialType($this->_values
['event']['financial_type_id']))
243 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
246 $this->checkValidEvent($infoUrl);
247 // get the participant values, CRM-4320
248 $this->_allowConfirmation
= FALSE;
249 if ($this->_participantId
) {
250 $this->processFirstParticipant($this->_participantId
);
252 //check for additional participants.
253 if ($this->_allowConfirmation
&& $this->_values
['event']['is_multiple_registrations']) {
254 $additionalParticipantIds = CRM_Event_BAO_Participant
::getAdditionalParticipantIds($this->_participantId
);
256 foreach ($additionalParticipantIds as $additionalParticipantId) {
257 $this->_additionalParticipantIds
[$cnt] = $additionalParticipantId;
260 $this->set('additionalParticipantIds', $this->_additionalParticipantIds
);
263 $eventFull = CRM_Event_BAO_Participant
::eventFull($this->_eventId
, FALSE,
264 CRM_Utils_Array
::value('has_waitlist', $this->_values
['event'])
267 $this->_allowWaitlist
= $this->_isEventFull
= FALSE;
268 if ($eventFull && !$this->_allowConfirmation
) {
269 $this->_isEventFull
= TRUE;
270 //lets redirecting to info only when to waiting list.
271 $this->_allowWaitlist
= CRM_Utils_Array
::value('has_waitlist', $this->_values
['event']);
272 if (!$this->_allowWaitlist
) {
273 CRM_Utils_System
::redirect($infoUrl);
276 $this->set('isEventFull', $this->_isEventFull
);
277 $this->set('allowWaitlist', $this->_allowWaitlist
);
279 //check for require requires approval.
280 $this->_requireApproval
= FALSE;
281 if (!empty($this->_values
['event']['requires_approval']) && !$this->_allowConfirmation
) {
282 $this->_requireApproval
= TRUE;
284 $this->set('requireApproval', $this->_requireApproval
);
286 if (isset($this->_values
['event']['default_role_id'])) {
287 $participant_role = CRM_Core_OptionGroup
::values('participant_role');
288 $this->_values
['event']['participant_role'] = $participant_role["{$this->_values['event']['default_role_id']}"];
290 $isPayLater = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_eventId
, 'is_pay_later');
291 //check for various combinations for paylater, payment
292 //process with paid event.
293 if ($isMonetary && (!$isPayLater ||
!empty($this->_values
['event']['payment_processor']))) {
294 $this->_paymentProcessorIDs
= explode(CRM_Core_DAO
::VALUE_SEPARATOR
, CRM_Utils_Array
::value('payment_processor',
295 $this->_values
['event']
297 $this->assignPaymentProcessor($isPayLater);
301 self
::initEventFee($this, $this->_eventId
);
303 // get the profile ids
304 $ufJoinParams = array(
305 'entity_table' => 'civicrm_event',
306 // CRM-4377:Â CiviEvent for the main participant, CiviEvent_Additional for additional participants
307 'module' => 'CiviEvent',
308 'entity_id' => $this->_eventId
,
310 list($this->_values
['custom_pre_id'],
311 $this->_values
['custom_post_id']
312 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
314 // set profiles for additional participants
315 if ($this->_values
['event']['is_multiple_registrations']) {
316 // CRM-4377:Â CiviEvent for the main participant, CiviEvent_Additional for additional participants
317 $ufJoinParams['module'] = 'CiviEvent_Additional';
319 list($this->_values
['additional_custom_pre_id'],
320 $this->_values
['additional_custom_post_id'], $preActive, $postActive
321 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
323 // CRM-4377:Â we need to maintain backward compatibility, hence if there is profile for main contact
324 // set same profile for additional contacts.
325 if ($this->_values
['custom_pre_id'] && !$this->_values
['additional_custom_pre_id']) {
326 $this->_values
['additional_custom_pre_id'] = $this->_values
['custom_pre_id'];
329 if ($this->_values
['custom_post_id'] && !$this->_values
['additional_custom_post_id']) {
330 $this->_values
['additional_custom_post_id'] = $this->_values
['custom_post_id'];
332 // now check for no profile condition, in that case is_active = 0
333 if (isset($preActive) && !$preActive) {
334 unset($this->_values
['additional_custom_pre_id']);
336 if (isset($postActive) && !$postActive) {
337 unset($this->_values
['additional_custom_post_id']);
341 $this->assignBillingType();
343 if ($this->_values
['event']['is_monetary']) {
344 CRM_Core_Payment_Form
::setPaymentFieldsByProcessor($this, $this->_paymentProcessor
);
346 $params = array('entity_id' => $this->_eventId
, 'entity_table' => 'civicrm_event');
347 $this->_values
['location'] = CRM_Core_BAO_Location
::getValues($params, TRUE);
349 $this->set('values', $this->_values
);
350 $this->set('fields', $this->_fields
);
352 $this->_availableRegistrations
353 = CRM_Event_BAO_Participant
::eventFull(
354 $this->_values
['event']['id'], TRUE,
355 CRM_Utils_Array
::value('has_waitlist', $this->_values
['event'])
357 $this->set('availableRegistrations', $this->_availableRegistrations
);
359 $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor
);
361 // check if this is a paypal auto return and redirect accordingly
362 if (CRM_Core_Payment
::paypalRedirect($this->_paymentProcessor
)) {
363 $url = CRM_Utils_System
::url('civicrm/event/register',
364 "_qf_ThankYou_display=1&qfKey={$this->controller->_key}"
366 CRM_Utils_System
::redirect($url);
368 // The concept of contributeMode is deprecated.
369 $this->_contributeMode
= $this->get('contributeMode');
370 $this->assign('contributeMode', $this->_contributeMode
);
372 // setting CMS page title
373 CRM_Utils_System
::setTitle($this->_values
['event']['title']);
374 $this->assign('title', $this->_values
['event']['title']);
376 $this->assign('paidEvent', $this->_values
['event']['is_monetary']);
378 // we do not want to display recently viewed items on Registration pages
379 $this->assign('displayRecent', FALSE);
380 // Registration page values are cleared from session, so can't use normal Printer Friendly view.
381 // Use Browser Print instead.
382 $this->assign('browserPrint', TRUE);
384 $isShowLocation = CRM_Utils_Array
::value('is_show_location', $this->_values
['event']);
385 $this->assign('isShowLocation', $isShowLocation);
387 $pcpId = CRM_Utils_Request
::retrieve('pcpId', 'Positive', $this);
389 $pcp = CRM_PCP_BAO_PCP
::handlePcp($pcpId, 'event', $this->_values
['event']);
390 $this->_pcpId
= $pcp['pcpId'];
391 $this->_values
['event']['intro_text'] = CRM_Utils_Array
::value('intro_text', $pcp['pcpInfo']);
394 // assign all event properties so wizard templates can display event info.
395 $this->assign('event', $this->_values
['event']);
396 $this->assign('location', $this->_values
['location']);
397 $this->assign('bltID', $this->_bltID
);
398 $isShowLocation = CRM_Utils_Array
::value('is_show_location', $this->_values
['event']);
399 $this->assign('isShowLocation', $isShowLocation);
401 $config->defaultCurrency
= CRM_Utils_Array
::value('currency', $this->_values
['event'],
402 $config->defaultCurrency
405 //lets allow user to override campaign.
406 $campID = CRM_Utils_Request
::retrieve('campID', 'Positive', $this);
407 if ($campID && CRM_Core_DAO
::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) {
408 $this->_values
['event']['campaign_id'] = $campID;
411 // Set the same value for is_billing_required as contribution page so code can be shared.
412 $this->_values
['is_billing_required'] = CRM_Utils_Array
::value('is_billing_required', $this->_values
['event']);
413 // check if billing block is required for pay later
414 // note that I have started removing the use of isBillingAddressRequiredForPayLater in favour of letting
415 // the CRM_Core_Payment_Manual class handle it - but there are ~300 references to it in the code base so only
416 // removing in very limited cases.
417 if (CRM_Utils_Array
::value('is_pay_later', $this->_values
['event'])) {
418 $this->_isBillingAddressRequiredForPayLater
= CRM_Utils_Array
::value('is_billing_required', $this->_values
['event']);
419 $this->assign('isBillingAddressRequiredForPayLater', $this->_isBillingAddressRequiredForPayLater
);
424 * Assign the minimal set of variables to the template.
426 public function assignToTemplate() {
427 //process only primary participant params
428 $this->_params
= $this->get('params');
429 if (isset($this->_params
[0])) {
430 $params = $this->_params
[0];
433 if (!empty($params['billing_first_name'])) {
434 $name = $params['billing_first_name'];
437 if (!empty($params['billing_middle_name'])) {
438 $name .= " {$params['billing_middle_name']}";
441 if (!empty($params['billing_last_name'])) {
442 $name .= " {$params['billing_last_name']}";
444 $this->assign('billingName', $name);
445 $this->set('name', $name);
456 foreach ($vars as $v) {
457 if (!empty($params[$v])) {
458 if ($v == 'receive_date') {
459 $this->assign($v, CRM_Utils_Date
::mysqlToIso($params[$v]));
462 $this->assign($v, $params[$v]);
465 elseif (CRM_Utils_Array
::value('amount', $params) == 0) {
466 $this->assign($v, CRM_Utils_Array
::value($v, $params));
470 // assign the address formatted up for display
471 $addressParts = array(
472 "street_address-{$this->_bltID}",
473 "city-{$this->_bltID}",
474 "postal_code-{$this->_bltID}",
475 "state_province-{$this->_bltID}",
476 "country-{$this->_bltID}",
478 $addressFields = array();
479 foreach ($addressParts as $part) {
480 list($n, $id) = explode('-', $part);
481 if (isset($params['billing_' . $part])) {
482 $addressFields[$n] = CRM_Utils_Array
::value('billing_' . $part, $params);
486 $this->assign('address', CRM_Utils_Address
::format($addressFields));
488 // The concept of contributeMode is deprecated.
489 if ($this->_contributeMode
== 'direct' && empty($params['is_pay_later'])) {
490 $date = CRM_Utils_Date
::format(CRM_Utils_Array
::value('credit_card_exp_date', $params));
491 $date = CRM_Utils_Date
::mysqlToIso($date);
492 $this->assign('credit_card_exp_date', $date);
493 $this->assign('credit_card_number',
494 CRM_Utils_System
::mungeCreditCard(CRM_Utils_Array
::value('credit_card_number', $params))
498 // get the email that the confirmation would have been sent to
499 $session = CRM_Core_Session
::singleton();
501 // assign is_email_confirm to templates
502 if (isset($this->_values
['event']['is_email_confirm'])) {
503 $this->assign('is_email_confirm', $this->_values
['event']['is_email_confirm']);
506 // assign pay later stuff
507 $params['is_pay_later'] = CRM_Utils_Array
::value('is_pay_later', $params, FALSE);
508 $this->assign('is_pay_later', $params['is_pay_later']);
509 if ($params['is_pay_later']) {
510 $this->assign('pay_later_text', $this->_values
['event']['pay_later_text']);
511 $this->assign('pay_later_receipt', $this->_values
['event']['pay_later_receipt']);
514 // also assign all participantIDs to the template
515 // useful in generating confirmation numbers if needed
516 $this->assign('participantIDs',
517 $this->_participantIDS
522 * Add the custom fields.
525 * @param string $name
526 * @param bool $viewOnly
528 public function buildCustom($id, $name, $viewOnly = FALSE) {
530 $button = substr($this->controller
->getButtonName(), -4);
531 $cid = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
532 $session = CRM_Core_Session
::singleton();
533 $contactID = $session->get('userID');
535 // we don't allow conflicting fields to be
536 // configured via profile
537 $fieldsToIgnore = array(
538 'participant_fee_amount' => 1,
539 'participant_fee_level' => 1,
545 foreach ($id as $profileID) {
546 $field = CRM_Core_BAO_UFGroup
::getFields($profileID, FALSE, CRM_Core_Action
::ADD
,
547 NULL, NULL, FALSE, NULL,
548 FALSE, NULL, CRM_Core_Permission
::CREATE
,
551 $fields = array_merge($fields, $field);
555 if (CRM_Core_BAO_UFGroup
::filterUFGroups($id, $contactID)) {
556 $fields = CRM_Core_BAO_UFGroup
::getFields($id, FALSE, CRM_Core_Action
::ADD
,
557 NULL, NULL, FALSE, NULL,
558 FALSE, NULL, CRM_Core_Permission
::CREATE
,
565 $fields = CRM_Core_BAO_UFGroup
::getFields($id, FALSE, CRM_Core_Action
::ADD
,
566 NULL, NULL, FALSE, NULL,
567 FALSE, NULL, CRM_Core_Permission
::CREATE
,
572 if (array_intersect_key($fields, $fieldsToIgnore)) {
573 $fields = array_diff_key($fields, $fieldsToIgnore);
574 CRM_Core_Session
::setStatus(ts('Some of the profile fields cannot be configured for this page.'));
578 if (!empty($this->_fields
)) {
579 $fields = @array_diff_assoc
($fields, $this->_fields
);
582 if (empty($this->_params
[0]['additional_participants']) &&
585 CRM_Core_BAO_Address
::checkContactSharedAddressFields($fields, $contactID);
587 $this->assign($name, $fields);
588 if (is_array($fields)) {
589 foreach ($fields as $key => $field) {
591 isset($field['data_type']) &&
592 $field['data_type'] == 'File' ||
($viewOnly && $field['name'] == 'image_URL')
594 // ignore file upload fields
597 //make the field optional if primary participant
598 //have been skip the additional participant.
599 if ($button == 'skip') {
600 $field['is_required'] = FALSE;
602 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
603 elseif ($field['add_captcha'] && !$contactID) {
604 // only add captcha for first page
607 list($prefixName, $index) = CRM_Utils_System
::explode('-', $key, 2);
608 CRM_Core_BAO_UFGroup
::buildProfile($this, $field, CRM_Profile_Form
::MODE_CREATE
, $contactID, TRUE);
610 $this->_fields
[$key] = $field;
614 if ($addCaptcha && !$viewOnly) {
615 $captcha = CRM_Utils_ReCAPTCHA
::singleton();
616 $captcha->add($this);
617 $this->assign('isCaptcha', TRUE);
623 * Initiate event fee.
625 * @param CRM_Core_Form $form
626 * @param int $eventID
630 public static function initEventFee(&$form, $eventID) {
633 // retrive all active price set fields.
634 $discountId = CRM_Core_BAO_Discount
::findSet($eventID, 'civicrm_event');
635 if (property_exists($form, '_discountId') && $form->_discountId
) {
636 $discountId = $form->_discountId
;
639 //CRM-16456 get all price field including expired one.
640 $getAllPriceField = TRUE;
641 $className = CRM_Utils_System
::getClassName($form);
642 if ($className == 'CRM_Event_Form_ParticipantFeeSelection' && $form->_action
== CRM_Core_Action
::UPDATE
) {
643 $getAllPriceField = FALSE;
647 $priceSetId = CRM_Core_DAO
::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id');
648 $price = CRM_Price_BAO_PriceSet
::initSet($form, $eventID, 'civicrm_event', $getAllPriceField, $priceSetId);
651 $price = CRM_Price_BAO_PriceSet
::initSet($form, $eventID, 'civicrm_event', $getAllPriceField);
654 if (property_exists($form, '_context') && ($form->_context
== 'standalone'
655 ||
$form->_context
== 'participant')
657 $discountedEvent = CRM_Core_BAO_Discount
::getOptionGroup($eventID, 'civicrm_event');
658 if (is_array($discountedEvent)) {
659 foreach ($discountedEvent as $key => $priceSetId) {
660 $priceSet = CRM_Price_BAO_PriceSet
::getSetDetail($priceSetId);
661 $priceSet = CRM_Utils_Array
::value($priceSetId, $priceSet);
662 $form->_values
['discount'][$key] = CRM_Utils_Array
::value('fields', $priceSet);
663 $fieldID = key($form->_values
['discount'][$key]);
664 $form->_values
['discount'][$key][$fieldID]['name'] = CRM_Core_DAO
::getFieldValue(
665 'CRM_Price_DAO_PriceSet',
672 $eventFee = CRM_Utils_Array
::value('fee', $form->_values
);
673 if (!is_array($eventFee) ||
empty($eventFee)) {
674 $form->_values
['fee'] = array();
677 //fix for non-upgraded price sets.CRM-4256.
678 if (isset($form->_isPaidEvent
)) {
679 $isPaidEvent = $form->_isPaidEvent
;
682 $isPaidEvent = CRM_Utils_Array
::value('is_monetary', $form->_values
['event']);
684 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus()
685 && !empty($form->_values
['fee'])
687 foreach ($form->_values
['fee'] as $k => $fees) {
688 foreach ($fees['options'] as $options) {
689 if (!CRM_Core_Permission
::check('add contributions of type ' . CRM_Contribute_PseudoConstant
::financialType($options['financial_type_id']))) {
690 unset($form->_values
['fee'][$k]);
695 if ($isPaidEvent && empty($form->_values
['fee'])) {
696 if (CRM_Utils_System
::getClassName($form) != 'CRM_Event_Form_Participant') {
697 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
))));
703 * Handle process after the confirmation of payment by User.
705 * @param int $contactID
706 * @param null $contribution
707 * @param null $payment
709 public function confirmPostProcess($contactID = NULL, $contribution = NULL, $payment = NULL) {
710 // add/update contact information
712 unset($this->_params
['note']);
714 //to avoid conflict overwrite $this->_params
715 $this->_params
= $this->get('value');
717 //get the amount of primary participant
718 if (!empty($this->_params
['is_primary'])) {
719 $this->_params
['fee_amount'] = $this->get('primaryParticipantAmount');
722 // add participant record
723 $participant = CRM_Event_Form_Registration
::addParticipant($this, $contactID);
724 $this->_participantIDS
[] = $participant->id
;
726 //setting register_by_id field and primaryContactId
727 if (!empty($this->_params
['is_primary'])) {
728 $this->set('registerByID', $participant->id
);
729 $this->set('primaryContactId', $contactID);
732 $this->processFirstParticipant($participant->id
);
735 CRM_Core_BAO_CustomValueTable
::postProcess($this->_params
,
736 'civicrm_participant',
741 $createPayment = (CRM_Utils_Array
::value('amount', $this->_params
, 0) != 0) ?
TRUE : FALSE;
743 // force to create zero amount payment, CRM-5095
744 // we know the amout is zero since createPayment is false
745 if (!$createPayment &&
746 (isset($contribution) && $contribution->id
) &&
747 $this->_priceSetId
&&
750 $createPayment = TRUE;
753 if ($createPayment && $this->_values
['event']['is_monetary'] && !empty($this->_params
['contributionID'])) {
754 $paymentParams = array(
755 'participant_id' => $participant->id
,
756 'contribution_id' => $contribution->id
,
759 $paymentPartcipant = CRM_Event_BAO_ParticipantPayment
::create($paymentParams, $ids);
762 //set only primary participant's params for transfer checkout.
763 // The concept of contributeMode is deprecated.
764 if (($this->_contributeMode
== 'checkout' ||
$this->_contributeMode
== 'notify') && !empty($this->_params
['is_primary'])) {
765 $this->_params
['participantID'] = $participant->id
;
766 $this->set('primaryParticipant', $this->_params
);
769 $this->assign('action', $this->_action
);
772 if (!empty($this->_params
['cms_create_account'])) {
773 $this->_params
['contactID'] = $contactID;
775 if (array_key_exists('email-5', $this->_params
)) {
779 foreach ($this->_params
as $name => $dontCare) {
780 if (substr($name, 0, 5) == 'email') {
787 // we should use primary email for
788 // 1. free event registration.
789 // 2. pay later participant.
790 // 3. waiting list participant.
791 // 4. require approval participant.
792 if (!empty($this->_params
['is_pay_later']) ||
793 $this->_allowWaitlist ||
$this->_requireApproval ||
empty($this->_values
['event']['is_monetary'])
795 $mail = 'email-Primary';
798 if (!CRM_Core_BAO_CMSUser
::create($this->_params
, $mail)) {
799 CRM_Core_Error
::statusBounce(ts('Your profile is not saved and Account is not created.'));
805 * Process the participant.
807 * @param CRM_Core_Form $form
808 * @param int $contactID
810 * @return \CRM_Event_BAO_Participant
812 public static function addParticipant(&$form, $contactID) {
813 if (empty($form->_params
)) {
816 $params = $form->_params
;
817 $transaction = new CRM_Core_Transaction();
819 $groupName = 'participant_role';
821 SELECT v.label as label ,v.value as value
822 FROM civicrm_option_value v,
823 civicrm_option_group g
824 WHERE v.option_group_id = g.id
829 $p = array(1 => array($groupName, 'String'));
831 $dao = CRM_Core_DAO
::executeQuery($query, $p);
833 $roleID = $dao->value
;
836 // handle register date CRM-4320
837 $registerDate = NULL;
838 if (!empty($form->_allowConfirmation
) && $form->_participantId
) {
839 $registerDate = $params['participant_register_date'];
841 elseif (!empty($params['participant_register_date']) &&
842 is_array($params['participant_register_date']) &&
843 !empty($params['participant_register_date'])
845 $registerDate = CRM_Utils_Date
::format($params['participant_register_date']);
848 $participantFields = CRM_Event_DAO_Participant
::fields();
849 $participantParams = array(
850 'id' => CRM_Utils_Array
::value('participant_id', $params),
851 'contact_id' => $contactID,
852 'event_id' => $form->_eventId ?
$form->_eventId
: $params['event_id'],
853 'status_id' => CRM_Utils_Array
::value('participant_status',
856 'role_id' => CRM_Utils_Array
::value('participant_role_id',
859 'register_date' => ($registerDate) ?
$registerDate : date('YmdHis'),
860 'source' => CRM_Utils_String
::ellipsify(
861 isset($params['participant_source']) ? CRM_Utils_Array
::value('participant_source', $params) : CRM_Utils_Array
::value('description', $params),
862 $participantFields['participant_source']['maxlength']
864 'fee_level' => CRM_Utils_Array
::value('amount_level', $params),
865 'is_pay_later' => CRM_Utils_Array
::value('is_pay_later', $params, 0),
866 'fee_amount' => CRM_Utils_Array
::value('fee_amount', $params),
867 'registered_by_id' => CRM_Utils_Array
::value('registered_by_id', $params),
868 'discount_id' => CRM_Utils_Array
::value('discount_id', $params),
869 'fee_currency' => CRM_Utils_Array
::value('currencyID', $params),
870 'campaign_id' => CRM_Utils_Array
::value('campaign_id', $params),
873 if ($form->_action
& CRM_Core_Action
::PREVIEW || CRM_Utils_Array
::value('mode', $params) == 'test') {
874 $participantParams['is_test'] = 1;
877 $participantParams['is_test'] = 0;
880 if (!empty($form->_params
['note'])) {
881 $participantParams['note'] = $form->_params
['note'];
883 elseif (!empty($form->_params
['participant_note'])) {
884 $participantParams['note'] = $form->_params
['participant_note'];
887 // reuse id if one already exists for this one (can happen
888 // with back button being hit etc)
889 if (!$participantParams['id'] && !empty($params['contributionID'])) {
890 $pID = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment',
891 $params['contributionID'],
895 $participantParams['id'] = $pID;
897 $participantParams['discount_id'] = CRM_Core_BAO_Discount
::findSet($form->_eventId
, 'civicrm_event');
899 if (!$participantParams['discount_id']) {
900 $participantParams['discount_id'] = "null";
903 $participant = CRM_Event_BAO_Participant
::create($participantParams);
905 $transaction->commit();
911 * Calculate the total participant count as per params.
913 * @param CRM_Core_Form $form
914 * @param array $params
916 * @param bool $skipCurrent
920 public static function getParticipantCount(&$form, $params, $skipCurrent = FALSE) {
922 if (!is_array($params) ||
empty($params)) {
926 $priceSetId = $form->get('priceSetId');
927 $addParticipantNum = substr($form->_name
, 12);
928 $priceSetFields = $priceSetDetails = array();
929 $hasPriceFieldsCount = FALSE;
931 $priceSetDetails = $form->get('priceSet');
932 if (isset($priceSetDetails['optionsCountTotal'])
933 && $priceSetDetails['optionsCountTotal']
935 $hasPriceFieldsCount = TRUE;
936 $priceSetFields = $priceSetDetails['optionsCountDetails']['fields'];
940 $singleFormParams = FALSE;
941 foreach ($params as $key => $val) {
942 if (!is_numeric($key)) {
943 $singleFormParams = TRUE;
948 //first format the params.
949 if ($singleFormParams) {
950 $params = self
::formatPriceSetParams($form, $params);
951 $params = array($params);
954 foreach ($params as $key => $values) {
955 if (!is_numeric($key) ||
957 ($skipCurrent && ($addParticipantNum == $key))
964 $cacheCount = CRM_Utils_Array
::value($key, $form->_lineItemParticipantsCount
);
965 if ($cacheCount && is_numeric($cacheCount)) {
966 $count = $cacheCount;
970 if (!$usedCache && $hasPriceFieldsCount) {
972 foreach ($values as $valKey => $value) {
973 if (strpos($valKey, 'price_') === FALSE) {
976 $priceFieldId = substr($valKey, 6);
977 if (!$priceFieldId ||
979 !array_key_exists($priceFieldId, $priceSetFields)
983 foreach ($value as $optId => $optVal) {
984 $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal;
986 $count +
= $currentCount;
994 $totalCount +
= $count;
1004 * Format user submitted price set params.
1006 * Convert price set each param as an array.
1008 * @param CRM_Core_Form $form
1009 * @param array $params
1010 * An array of user submitted params.
1013 * Formatted price set params.
1015 public static function formatPriceSetParams(&$form, $params) {
1016 if (!is_array($params) ||
empty($params)) {
1020 $priceSetId = $form->get('priceSetId');
1024 $priceSetDetails = $form->get('priceSet');
1026 foreach ($params as $key => & $value) {
1028 if (strpos($key, 'price_') !== FALSE) {
1029 $fieldId = substr($key, 6);
1030 if (!array_key_exists($fieldId, $priceSetDetails['fields']) ||
1036 $field = $priceSetDetails['fields'][$fieldId];
1037 if ($field['html_type'] == 'Text') {
1038 $fieldOption = current($field['options']);
1039 $value = array($fieldOption['id'] => $value);
1042 $value = array($value => TRUE);
1051 * Calculate total count for each price set options.
1053 * - currently selected by user.
1055 * @param CRM_Core_Form $form
1059 * array of each option w/ count total.
1061 public static function getPriceSetOptionCount(&$form) {
1062 $params = $form->get('params');
1063 $priceSet = $form->get('priceSet');
1064 $priceSetId = $form->get('priceSetId');
1066 $optionsCount = array();
1068 !is_array($priceSet) ||
1070 !is_array($params) ||
1073 return $optionsCount;
1076 $priceSetFields = $priceMaxFieldDetails = array();
1077 if (!empty($priceSet['optionsCountTotal'])) {
1078 $priceSetFields = $priceSet['optionsCountDetails']['fields'];
1081 if (!empty($priceSet['optionsMaxValueTotal'])) {
1082 $priceMaxFieldDetails = $priceSet['optionsMaxValueDetails']['fields'];
1085 $addParticipantNum = substr($form->_name
, 12);
1086 foreach ($params as $pCnt => $values) {
1087 if ($values == 'skip' ||
1088 $pCnt === $addParticipantNum
1093 foreach ($values as $valKey => $value) {
1094 if (strpos($valKey, 'price_') === FALSE) {
1098 $priceFieldId = substr($valKey, 6);
1099 if (!$priceFieldId ||
1100 !is_array($value) ||
1101 !(array_key_exists($priceFieldId, $priceSetFields) ||
array_key_exists($priceFieldId, $priceMaxFieldDetails))
1106 foreach ($value as $optId => $optVal) {
1107 if (CRM_Utils_Array
::value('html_type', $priceSet['fields'][$priceFieldId]) == 'Text') {
1108 $currentCount = $optVal;
1114 if (isset($priceSetFields[$priceFieldId]) && isset($priceSetFields[$priceFieldId]['options'][$optId])) {
1115 $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal;
1118 $optionsCount[$optId] = $currentCount + CRM_Utils_Array
::value($optId, $optionsCount, 0);
1123 return $optionsCount;
1127 * Check if template file exists.
1129 * @param string $suffix
1131 * @return null|string
1133 public function checkTemplateFileExists($suffix = '') {
1134 if ($this->_eventId
) {
1135 $templateName = $this->_name
;
1136 if (substr($templateName, 0, 12) == 'Participant_') {
1137 $templateName = 'AdditionalParticipant';
1140 $templateFile = "CRM/Event/Form/Registration/{$this->_eventId}/{$templateName}.{$suffix}tpl";
1141 $template = CRM_Core_Form
::getTemplate();
1142 if ($template->template_exists($templateFile)) {
1143 return $templateFile;
1150 * Get template file name.
1152 * @return null|string
1154 public function getTemplateFileName() {
1155 $fileName = $this->checkTemplateFileExists();
1156 return $fileName ?
$fileName : parent
::getTemplateFileName();
1160 * Override extra template name.
1162 * @return null|string
1164 public function overrideExtraTemplateFileName() {
1165 $fileName = $this->checkTemplateFileExists('extra.');
1166 return $fileName ?
$fileName : parent
::overrideExtraTemplateFileName();
1170 * Reset values for all options those are full.
1172 * @param array $optionFullIds
1173 * @param CRM_Core_Form $form
1175 public static function resetElementValue($optionFullIds = array(), &$form) {
1176 if (!is_array($optionFullIds) ||
1177 empty($optionFullIds) ||
1178 !$form->isSubmitted()
1183 foreach ($optionFullIds as $fldId => $optIds) {
1184 $name = "price_$fldId";
1185 if (!$form->elementExists($name)) {
1189 $element = $form->getElement($name);
1190 $eleType = $element->getType();
1192 $resetSubmitted = FALSE;
1195 if ($element->getValue() && $element->isFrozen()) {
1196 $label = "{$element->getLabel()}<tt>(x)</tt>";
1197 $element->setLabel($label);
1198 $element->setPersistantFreeze();
1199 $resetSubmitted = TRUE;
1204 if (is_array($element->_elements
)) {
1205 foreach ($element->_elements
as $child) {
1206 $childType = $child->getType();
1207 $methodName = 'getName';
1209 $methodName = 'getValue';
1211 if (in_array($child->{$methodName}(), $optIds) && $child->isFrozen()) {
1212 $resetSubmitted = TRUE;
1213 $child->setPersistantFreeze();
1220 $value = $element->getValue();
1221 if (in_array($value[0], $optIds)) {
1222 foreach ($element->_options
as $option) {
1223 if ($option['attr']['value'] === "crm_disabled_opt-{$value[0]}") {
1224 $placeholder = html_entity_decode($option['text'], ENT_QUOTES
, "UTF-8");
1225 $element->updateAttributes(array('placeholder' => $placeholder));
1229 $resetSubmitted = TRUE;
1234 //finally unset values from submitted.
1235 if ($resetSubmitted) {
1236 self
::resetSubmittedValue($name, $optIds, $form);
1242 * Reset submitted value.
1244 * @param string $elementName
1245 * @param array $optionIds
1246 * @param CRM_Core_form $form
1248 public static function resetSubmittedValue($elementName, $optionIds = array(), &$form) {
1249 if (empty($elementName) ||
1250 !$form->elementExists($elementName) ||
1251 !$form->getSubmitValue($elementName)
1260 $values = $form->{"_$val"};
1261 if (!is_array($values) ||
empty($values)) {
1264 $eleVal = CRM_Utils_Array
::value($elementName, $values);
1265 if (empty($eleVal)) {
1268 if (is_array($eleVal)) {
1270 foreach ($eleVal as $keyId => $ignore) {
1271 if (in_array($keyId, $optionIds)) {
1273 unset($values[$elementName][$keyId]);
1276 if ($found && empty($values[$elementName][$keyId])) {
1277 $values[$elementName][$keyId] = NULL;
1281 if (!empty($keyId)) {
1282 $values[$elementName][$keyId] = NULL;
1289 * Validate price set submitted params for price option limit.
1291 * User should select at least one price field option.
1293 * @param CRM_Core_Form $form
1294 * @param array $params
1298 public static function validatePriceSet(&$form, $params) {
1300 $hasOptMaxValue = FALSE;
1301 if (!is_array($params) ||
empty($params)) {
1305 $currentParticipantNum = substr($form->_name
, 12);
1306 if (!$currentParticipantNum) {
1307 $currentParticipantNum = 0;
1310 $priceSetId = $form->get('priceSetId');
1311 $priceSetDetails = $form->get('priceSet');
1314 !is_array($priceSetDetails) ||
1315 empty($priceSetDetails)
1320 $optionsCountDetails = $optionsMaxValueDetails = array();
1322 isset($priceSetDetails['optionsMaxValueTotal'])
1323 && $priceSetDetails['optionsMaxValueTotal']
1325 $hasOptMaxValue = TRUE;
1326 $optionsMaxValueDetails = $priceSetDetails['optionsMaxValueDetails']['fields'];
1329 isset($priceSetDetails['optionsCountTotal'])
1330 && $priceSetDetails['optionsCountTotal']
1332 $hasOptCount = TRUE;
1333 $optionsCountDetails = $priceSetDetails['optionsCountDetails']['fields'];
1335 $feeBlock = $form->_feeBlock
;
1337 if (empty($feeBlock)) {
1338 $feeBlock = $priceSetDetails['fields'];
1341 $optionMaxValues = $fieldSelected = array();
1342 foreach ($params as $pNum => $values) {
1343 if (!is_array($values) ||
$values == 'skip') {
1347 foreach ($values as $valKey => $value) {
1348 if (strpos($valKey, 'price_') === FALSE) {
1351 $priceFieldId = substr($valKey, 6);
1352 $noneOptionValueSelected = FALSE;
1353 if (!$feeBlock[$priceFieldId]['is_required'] && $value == 0) {
1354 $noneOptionValueSelected = TRUE;
1359 (!$noneOptionValueSelected && !is_array($value))
1364 $fieldSelected[$pNum] = TRUE;
1366 if (!$hasOptMaxValue ||
!is_array($value)) {
1370 foreach ($value as $optId => $optVal) {
1371 if (CRM_Utils_Array
::value('html_type', $feeBlock[$priceFieldId]) == 'Text') {
1372 $currentMaxValue = $optVal;
1375 $currentMaxValue = 1;
1378 if (isset($optionsCountDetails[$priceFieldId]) && isset($optionsCountDetails[$priceFieldId]['options'][$optId])) {
1379 $currentMaxValue = $optionsCountDetails[$priceFieldId]['options'][$optId] * $optVal;
1381 if (empty($optionMaxValues)) {
1382 $optionMaxValues[$priceFieldId][$optId] = $currentMaxValue;
1385 $optionMaxValues[$priceFieldId][$optId]
1386 = $currentMaxValue + CRM_Utils_Array
::value($optId, CRM_Utils_Array
::value($priceFieldId, $optionMaxValues), 0);
1388 $soldOutPnum[$optId] = $pNum;
1392 //validate for price field selection.
1393 if (empty($fieldSelected[$pNum])) {
1394 $errors[$pNum]['_qf_default'] = ts('Select at least one option from Event Fee(s).');
1398 //validate for option max value.
1399 foreach ($optionMaxValues as $fieldId => $values) {
1400 $options = CRM_Utils_Array
::value('options', $feeBlock[$fieldId], array());
1401 foreach ($values as $optId => $total) {
1402 $optMax = $optionsMaxValueDetails[$fieldId]['options'][$optId];
1403 $opDbCount = CRM_Utils_Array
::value('db_total_count', $options[$optId], 0);
1404 $total +
= $opDbCount;
1405 if ($optMax && ($total > $optMax)) {
1406 if ($opDbCount && ($opDbCount >= $optMax)) {
1407 $errors[$soldOutPnum[$optId]]["price_{$fieldId}"]
1408 = ts('Sorry, this option is currently sold out.');
1410 elseif (($optMax - $opDbCount) == 1) {
1411 $errors[$soldOutPnum[$optId]]["price_{$fieldId}"]
1412 = ts('Sorry, currently only a single space is available for this option.', array(1 => ($optMax - $opDbCount)));
1415 $errors[$soldOutPnum[$optId]]["price_{$fieldId}"]
1416 = ts('Sorry, currently only %1 spaces are available for this option.', array(1 => ($optMax - $opDbCount)));
1425 * Set the first participant ID if not set.
1429 * @param int $participantID
1431 public function processFirstParticipant($participantID) {
1432 $this->_participantId
= $participantID;
1433 $this->set('participantId', $this->_participantId
);
1435 $ids = $participantValues = array();
1436 $participantParams = array('id' => $this->_participantId
);
1437 CRM_Event_BAO_Participant
::getValues($participantParams, $participantValues, $ids);
1438 $this->_values
['participant'] = $participantValues[$this->_participantId
];
1439 $this->set('values', $this->_values
);
1441 // also set the allow confirmation stuff
1442 if (array_key_exists(
1443 $this->_values
['participant']['status_id'],
1444 CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Pending'")
1446 $this->_allowConfirmation
= TRUE;
1447 $this->set('allowConfirmation', TRUE);
1452 * Check if event is valid.
1454 * @todo - combine this with CRM_Event_BAO_Event::validRegistrationRequest
1455 * (probably extract relevant values here & call that with them & handle bounces & redirects here -as
1456 * those belong in the form layer)
1458 * @param string $redirect
1460 public function checkValidEvent($redirect = NULL) {
1461 // is the event active (enabled)?
1462 if (!$this->_values
['event']['is_active']) {
1463 // form is inactive, die a fatal death
1464 CRM_Core_Error
::statusBounce(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
1467 // is online registration is enabled?
1468 if (!$this->_values
['event']['is_online_registration']) {
1469 CRM_Core_Error
::statusBounce(ts('Online registration is not currently available for this event (contact the site administrator for assistance).'), $redirect);
1472 // is this an event template ?
1473 if (!empty($this->_values
['event']['is_template'])) {
1474 CRM_Core_Error
::statusBounce(ts('Event templates are not meant to be registered.'), $redirect);
1477 $now = date('YmdHis');
1478 $startDate = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('registration_start_date',
1479 $this->_values
['event']
1486 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);
1489 $regEndDate = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('registration_end_date',
1490 $this->_values
['event']
1492 $eventEndDate = CRM_Utils_Date
::processDate(CRM_Utils_Array
::value('event_end_date', $this->_values
['event']));
1493 if (($regEndDate && ($regEndDate < $now)) ||
(empty($regEndDate) && !empty($eventEndDate) && ($eventEndDate < $now))) {
1494 $endDate = CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('registration_end_date', $this->_values
['event']));
1495 if (empty($regEndDate)) {
1496 $endDate = CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('event_end_date', $this->_values
['event']));
1498 CRM_Core_Error
::statusBounce(ts('Registration for this event ended on %1', array(1 => $endDate)), $redirect);
1503 * Get the amount level for the event payment.
1505 * The amount level is the string stored on the contribution record that describes the purchase.
1507 * @param array $params
1508 * @param int|null $discountID
1512 protected function getAmountLevel($params, $discountID) {
1513 // @todo move handling of discount ID to the BAO function - preferably by converting it to a price_set with
1515 if (!empty($this->_values
['discount'][$discountID])) {
1516 return $this->_values
['discount'][$discountID][$params['amount']]['label'];
1518 if (empty($params['priceSetId'])) {
1519 // CRM-17509 An example of this is where the person is being waitlisted & there is no payment.
1520 // ideally we would have calculated amount first & only call this is there is an
1521 // amount but the flow needs more changes for that.
1524 return CRM_Price_BAO_PriceSet
::getAmountLevelText($params);
1528 * Process Registration of free event.
1530 * @param array $params
1532 * @param int $contactID
1534 public function processRegistration($params, $contactID = NULL) {
1535 $session = CRM_Core_Session
::singleton();
1536 $this->_participantInfo
= array();
1538 // CRM-4320, lets build array of cancelled additional participant ids
1539 // those are drop or skip by primary at the time of confirmation.
1540 // get all in and then unset those are confirmed.
1541 $cancelledIds = $this->_additionalParticipantIds
;
1543 $participantCount = array();
1544 foreach ($params as $participantNum => $record) {
1545 if ($record == 'skip') {
1546 $participantCount[$participantNum] = 'skip';
1548 elseif ($participantNum) {
1549 $participantCount[$participantNum] = 'participant';
1553 $registerByID = NULL;
1554 foreach ($params as $key => $value) {
1555 if ($value != 'skip') {
1558 // setting register by Id and unset contactId.
1559 if (empty($value['is_primary'])) {
1561 $registerByID = $this->get('registerByID');
1562 if ($registerByID) {
1563 $value['registered_by_id'] = $registerByID;
1565 // get an email if one exists for the participant
1566 $participantEmail = '';
1567 foreach (array_keys($value) as $valueName) {
1568 if (substr($valueName, 0, 6) == 'email-') {
1569 $participantEmail = $value[$valueName];
1572 if ($participantEmail) {
1573 $this->_participantInfo
[] = $participantEmail;
1576 $this->_participantInfo
[] = $value['first_name'] . ' ' . $value['last_name'];
1579 elseif (!empty($value['contact_id'])) {
1580 $contactID = $value['contact_id'];
1583 $contactID = $this->getContactID();
1586 CRM_Event_Form_Registration_Confirm
::fixLocationFields($value, $fields, $this);
1587 //for free event or additional participant, dont create billing email address.
1588 if (empty($value['is_primary']) ||
!$this->_values
['event']['is_monetary']) {
1589 unset($value["email-{$this->_bltID}"]);
1592 $contactID = CRM_Event_Form_Registration_Confirm
::updateContactFields($contactID, $value, $fields, $this);
1594 // lets store the contactID in the session
1595 // we dont store in userID in case the user is doing multiple
1597 // for things like tell a friend
1598 if (!$this->getContactID() && !empty($value['is_primary'])) {
1599 $session->set('transaction.userID', $contactID);
1602 //lets get the status if require approval or waiting.
1604 $waitingStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
1605 if ($this->_allowWaitlist
&& !$this->_allowConfirmation
) {
1606 $value['participant_status_id'] = $value['participant_status'] = array_search('On waitlist', $waitingStatuses);
1608 elseif ($this->_requireApproval
&& !$this->_allowConfirmation
) {
1609 $value['participant_status_id'] = $value['participant_status'] = array_search('Awaiting approval', $waitingStatuses);
1612 $this->set('value', $value);
1613 $this->confirmPostProcess($contactID, NULL, NULL);
1615 //lets get additional participant id to cancel.
1616 if ($this->_allowConfirmation
&& is_array($cancelledIds)) {
1617 $additonalId = CRM_Utils_Array
::value('participant_id', $value);
1618 if ($additonalId && $key = array_search($additonalId, $cancelledIds)) {
1619 unset($cancelledIds[$key]);
1625 // update status and send mail to cancelled additional participants, CRM-4320
1626 if ($this->_allowConfirmation
&& is_array($cancelledIds) && !empty($cancelledIds)) {
1627 $cancelledId = array_search('Cancelled',
1628 CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Negative'")
1630 CRM_Event_BAO_Participant
::transitionParticipants($cancelledIds, $cancelledId);
1633 //set information about additional participants if exists
1634 if (count($this->_participantInfo
)) {
1635 $this->set('participantInfo', $this->_participantInfo
);
1638 //send mail Confirmation/Receipt
1639 if ($this->_contributeMode
!= 'checkout' ||
1640 $this->_contributeMode
!= 'notify'
1643 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
1647 //handle if no additional participant.
1648 if (!$registerByID) {
1649 $registerByID = $this->get('registerByID');
1651 $primaryContactId = $this->get('primaryContactId');
1653 //build an array of custom profile and assigning it to template.
1654 $additionalIDs = CRM_Event_BAO_Event
::buildCustomProfile($registerByID, NULL,
1655 $primaryContactId, $isTest, TRUE
1658 //lets carry all participant params w/ values.
1659 foreach ($additionalIDs as $participantID => $contactId) {
1660 $participantNum = NULL;
1661 if ($participantID == $registerByID) {
1662 $participantNum = 0;
1665 if ($participantNum = array_search('participant', $participantCount)) {
1666 unset($participantCount[$participantNum]);
1670 if ($participantNum === NULL) {
1674 //carry the participant submitted values.
1675 $this->_values
['params'][$participantID] = $params[$participantNum];
1678 //lets send mails to all with meanigful text, CRM-4320.
1679 $this->assign('isOnWaitlist', $this->_allowWaitlist
);
1680 $this->assign('isRequireApproval', $this->_requireApproval
);
1682 foreach ($additionalIDs as $participantID => $contactId) {
1683 if ($participantID == $registerByID) {
1684 //set as Primary Participant
1685 $this->assign('isPrimary', 1);
1687 $customProfile = CRM_Event_BAO_Event
::buildCustomProfile($participantID, $this->_values
, NULL, $isTest);
1689 if (count($customProfile)) {
1690 $this->assign('customProfile', $customProfile);
1691 $this->set('customProfile', $customProfile);
1695 $this->assign('isPrimary', 0);
1696 $this->assign('customProfile', NULL);
1699 //send Confirmation mail to Primary & additional Participants if exists
1700 CRM_Event_BAO_Event
::sendMail($contactId, $this->_values
, $participantID, $isTest);