Exemple #1
0
 /** 
  * Function to set variables up before form is built 
  *                                                           
  * @return void 
  * @access public 
  */
 function preProcess()
 {
     parent::preProcess();
     //CRM-4320.
     //here we can't use parent $this->_allowWaitlist as user might
     //walk back and we maight set this value in this postProcess.
     //(we set when spaces < group count and want to allow become part of waiting )
     require_once 'CRM/Event/BAO/Participant.php';
     $eventFull = CRM_Event_BAO_Participant::eventFull($this->_eventId);
     $this->_allowWaitlist = false;
     if ($eventFull && !$this->_allowConfirmation && CRM_Utils_Array::value('has_waitlist', $this->_values['event'])) {
         $this->_allowWaitlist = true;
         $this->_waitlistMsg = CRM_Utils_Array::value('waitlist_text', $this->_values['event'], ts('This event is currently full. However you can register now and get added to a waiting list. You will be notified if spaces become available.'));
     }
     $this->set('allowWaitlist', $this->_allowWaitlist);
     //To check if the user is already registered for the event(CRM-2426)
     self::checkRegistration(null, $this);
     $this->_availableRegistrations = CRM_Event_BAO_Participant::eventFull($this->_values['event']['id'], true);
     if ($this->_availableRegistrations) {
         $this->assign('availableRegistrations', $this->_availableRegistrations);
     }
     // get the participant values from EventFees.php, CRM-4320
     if ($this->_allowConfirmation) {
         require_once 'CRM/Event/Form/EventFees.php';
         CRM_Event_Form_EventFees::preProcess($this);
     }
 }
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     parent::preProcess();
     $participantNo = substr($this->_name, 12);
     //lets process in-queue participants.
     if ($this->_participantId && $this->_additionalParticipantIds) {
         $this->_additionalParticipantId = CRM_Utils_Array::value($participantNo, $this->_additionalParticipantIds);
     }
     $participantCnt = $participantNo + 1;
     $this->assign('formId', $participantNo);
     $this->_params = array();
     $this->_params = $this->get('params');
     $participantTot = $this->_params[0]['additional_participants'] + 1;
     $skipCount = count(array_keys($this->_params, "skip"));
     if ($skipCount) {
         $this->assign('skipCount', $skipCount);
     }
     CRM_Utils_System::setTitle(ts('Register Participant %1 of %2', array(1 => $participantCnt, 2 => $participantTot)));
     //CRM-4320, hack to check last participant.
     $this->_lastParticipant = FALSE;
     if ($participantTot == $participantCnt) {
         $this->_lastParticipant = TRUE;
     }
     $this->assign('lastParticipant', $this->_lastParticipant);
 }
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     parent::preProcess();
     //CRM-4320.
     //here we can't use parent $this->_allowWaitlist as user might
     //walk back and we maight set this value in this postProcess.
     //(we set when spaces < group count and want to allow become part of waiting )
     $eventFull = CRM_Event_BAO_Participant::eventFull($this->_eventId, FALSE, CRM_Utils_Array::value('has_waitlist', $this->_values['event']));
     // Get payment processors if appropriate for this event
     // We hide the payment fields if the event is full or requires approval,
     // and the current user has not yet been approved CRM-12279
     $this->_noFees = ($eventFull || $this->_requireApproval) && !$this->_allowConfirmation;
     CRM_Contribute_Form_Contribution_Main::preProcessPaymentOptions($this, $this->_noFees);
     if ($this->_snippet) {
         return;
     }
     $this->_allowWaitlist = FALSE;
     if ($eventFull && !$this->_allowConfirmation && CRM_Utils_Array::value('has_waitlist', $this->_values['event'])) {
         $this->_allowWaitlist = TRUE;
         $this->_waitlistMsg = CRM_Utils_Array::value('waitlist_text', $this->_values['event']);
         if (!$this->_waitlistMsg) {
             $this->_waitlistMsg = ts('This event is currently full. However you can register now and get added to a waiting list. You will be notified if spaces become available.');
         }
     }
     $this->set('allowWaitlist', $this->_allowWaitlist);
     //To check if the user is already registered for the event(CRM-2426)
     if (!$this->_skipDupeRegistrationCheck) {
         self::checkRegistration(NULL, $this);
     }
     $this->assign('availableRegistrations', $this->_availableRegistrations);
     // get the participant values from EventFees.php, CRM-4320
     if ($this->_allowConfirmation) {
         CRM_Event_Form_EventFees::preProcess($this);
     }
 }
Exemple #4
0
 /** 
  * Function to set variables up before form is built 
  *                                                           
  * @return void 
  * @access public 
  */
 function preProcess()
 {
     parent::preProcess();
     $this->_params = $this->get('params');
     $this->_lineItem = $this->get('lineItem');
     $this->_totalAmount = $this->get('totalAmount');
     $this->_receiveDate = $this->get('receiveDate');
     $this->_trxnId = $this->get('trxnId');
     $finalAmount = $this->get('finalAmount');
     $this->assign('finalAmount', $finalAmount);
     $participantInfo = $this->get('participantInfo');
     $this->assign('participantInfo', $participantInfo);
     $customGroup = $this->get('customProfile');
     $this->assign('customProfile', $customGroup);
     CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->_values['event']));
 }
 /**
  * Build the form object.
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function buildQuickForm(&$form)
 {
     if ($form->_eventId) {
         $form->_isPaidEvent = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $form->_eventId, 'is_monetary');
         if ($form->_isPaidEvent) {
             $form->addElement('hidden', 'hidden_feeblock', 1);
         }
         // make sure this is for backoffice registration.
         if ($form->getName() == 'Participant') {
             $eventfullMsg = CRM_Event_BAO_Participant::eventFullMessage($form->_eventId, $form->_pId);
             $form->addElement('hidden', 'hidden_eventFullMsg', $eventfullMsg, array('id' => 'hidden_eventFullMsg'));
         }
     }
     if ($form->_pId) {
         if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $form->_pId, 'contribution_id', 'participant_id')) {
             $form->_online = TRUE;
         }
     }
     if ($form->_isPaidEvent) {
         $params = array('id' => $form->_eventId);
         CRM_Event_BAO_Event::retrieve($params, $event);
         //retrieve custom information
         $form->_values = array();
         CRM_Event_Form_Registration::initEventFee($form, $event['id']);
         CRM_Event_Form_Registration_Register::buildAmount($form, TRUE, $form->_discountId);
         $lineItem = array();
         $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
         $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
         $totalTaxAmount = 0;
         if (!CRM_Utils_System::isNull(CRM_Utils_Array::value('line_items', $form->_values))) {
             $lineItem[] = $form->_values['line_items'];
             foreach ($form->_values['line_items'] as $key => $value) {
                 $totalTaxAmount = $value['tax_amount'] + $totalTaxAmount;
             }
         }
         if ($invoicing) {
             $form->assign('totalTaxAmount', $totalTaxAmount);
         }
         $form->assign('lineItem', empty($lineItem) ? FALSE : $lineItem);
         $discounts = array();
         if (!empty($form->_values['discount'])) {
             foreach ($form->_values['discount'] as $key => $value) {
                 $value = current($value);
                 $discounts[$key] = $value['name'];
             }
             $element = $form->add('select', 'discount_id', ts('Discount Set'), array(0 => ts('- select -')) + $discounts, FALSE, array('class' => "crm-select2"));
             if ($form->_online) {
                 $element->freeze();
             }
         }
         if ($form->_mode) {
             CRM_Core_Payment_Form::buildPaymentForm($form, $form->_paymentProcessor, FALSE);
         } elseif (!$form->_mode) {
             $form->addElement('checkbox', 'record_contribution', ts('Record Payment?'), NULL, array('onclick' => "return showHideByValue('record_contribution','','payment_information','table-row','radio',false);"));
             $form->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType());
             $form->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDate'));
             $form->add('select', 'payment_instrument_id', ts('Paid By'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
             // don't show transaction id in batch update mode
             $path = CRM_Utils_System::currentPath();
             $form->assign('showTransactionId', FALSE);
             if ($path != 'civicrm/contact/search/basic') {
                 $form->add('text', 'trxn_id', ts('Transaction ID'));
                 $form->addRule('trxn_id', ts('Transaction ID already exists in Database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $form->_eventId, 'trxn_id'));
                 $form->assign('showTransactionId', TRUE);
             }
             $status = CRM_Contribute_PseudoConstant::contributionStatus();
             // CRM-14417 suppressing contribution statuses that are NOT relevant to new participant registrations
             $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
             foreach (array('Cancelled', 'Failed', 'In Progress', 'Overdue', 'Refunded', 'Pending refund') as $suppress) {
                 unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
             }
             $form->add('select', 'contribution_status_id', ts('Payment Status'), $status);
             $form->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number'));
             $form->add('text', 'total_amount', ts('Amount'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'total_amount'));
         }
     } else {
         $form->add('text', 'amount', ts('Event Fee(s)'));
     }
     $form->assign('onlinePendingContributionId', $form->get('onlinePendingContributionId'));
     $form->assign('paid', $form->_isPaidEvent);
     $form->addElement('checkbox', 'send_receipt', ts('Send Confirmation?'), NULL, array('onclick' => "showHideByValue('send_receipt','','notice','table-row','radio',false); showHideByValue('send_receipt','','from-email','table-row','radio',false);"));
     $form->add('select', 'from_email_address', ts('Receipt From'), $form->_fromEmails['from_email_id']);
     $form->add('textarea', 'receipt_text', ts('Confirmation Message'));
     // Retrieve the name and email of the contact - form will be the TO for receipt email ( only if context is not standalone)
     if ($form->_context != 'standalone') {
         if ($form->_contactId) {
             list($form->_contributorDisplayName, $form->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($form->_contactId);
             $form->assign('email', $form->_contributorEmail);
         } else {
             //show email block for batch update for event
             $form->assign('batchEmail', TRUE);
         }
     }
     $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
     $form->assign('outBound_option', $mailingInfo['outBound_option']);
     $form->assign('hasPayment', $form->_paymentId);
 }
 /**
  * Set default values for the form. For edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return void
  */
 public function setDefaultValues()
 {
     $defaults = $unsetSubmittedOptions = array();
     $discountId = NULL;
     //fix for CRM-3088, default value for discount set.
     if (!empty($this->_values['discount'])) {
         $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
         if ($discountId && !empty($this->_values['event']['default_discount_fee_id'])) {
             $discountKey = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_OptionValue", $this->_values['event']['default_discount_fee_id'], 'weight', 'id');
             $defaults['amount'] = key(array_slice($this->_values['discount'][$discountId], $discountKey - 1, $discountKey, TRUE));
         }
     }
     if ($this->_priceSetId) {
         foreach ($this->_feeBlock as $key => $val) {
             if (empty($val['options'])) {
                 continue;
             }
             $optionsFull = CRM_Utils_Array::value('option_full_ids', $val, array());
             foreach ($val['options'] as $keys => $values) {
                 if ($values['is_default'] && !in_array($keys, $optionsFull)) {
                     if ($val['html_type'] == 'CheckBox') {
                         $defaults["price_{$key}"][$keys] = 1;
                     } else {
                         $defaults["price_{$key}"] = $keys;
                     }
                 }
             }
             if (!empty($optionsFull)) {
                 $unsetSubmittedOptions[$val['id']] = $optionsFull;
             }
         }
     }
     //CRM-4320, setdefault additional participant values.
     if ($this->_allowConfirmation && $this->_additionalParticipantId) {
         //hack to get set default from eventFees.php
         $this->_discountId = $discountId;
         $this->_pId = $this->_additionalParticipantId;
         $this->_contactId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_additionalParticipantId, 'contact_id');
         $participantDefaults = CRM_Event_Form_EventFees::setDefaultValues($this);
         $participantDefaults = array_merge($this->_defaults, $participantDefaults);
         // use primary email address if billing email address is empty
         if (empty($this->_defaults["email-{$this->_bltID}"]) && !empty($this->_defaults["email-Primary"])) {
             $participantDefaults["email-{$this->_bltID}"] = $this->_defaults["email-Primary"];
         }
         $defaults = array_merge($defaults, $participantDefaults);
     }
     $defaults = array_merge($this->_defaults, $defaults);
     //reset values for all options those are full.
     CRM_Event_Form_Registration::resetElementValue($unsetSubmittedOptions, $this);
     //load default campaign from page.
     if (array_key_exists('participant_campaign_id', $this->_fields)) {
         $defaults['participant_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
     }
     return $defaults;
 }
Exemple #7
0
 /** 
  * Function to process the form 
  * 
  * @access public 
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         require_once "CRM/Event/BAO/Participant.php";
         CRM_Event_BAO_Participant::deleteParticipant($this->_participantId);
         return;
     }
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     // set the contact, when contact is selected
     if (CRM_Utils_Array::value('contact_select_id', $params)) {
         $this->_contactID = CRM_Utils_Array::value('contact_select_id', $params);
     }
     $config =& CRM_Core_Config::singleton();
     //check if discount is selected
     if (CRM_Utils_Array::value('discount_id', $params)) {
         $discountId = $params['discount_id'];
     } else {
         $params['discount_id'] = 'null';
         $discountId = null;
     }
     if ($this->_isPaidEvent) {
         //lets carry currency, CRM-4453
         $params['fee_currency'] = $config->defaultCurrency;
         // fix for CRM-3088
         if ($discountId && !empty($this->_values['discount'][$discountId])) {
             $params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label'];
             $params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
             $this->assign('amount_level', $params['amount_level']);
         } else {
             if (!isset($params['priceSetId'])) {
                 $params['amount_level'] = $this->_values['fee'][$params['amount']]['label'];
                 $params['amount'] = $this->_values['fee'][$params['amount']]['value'];
                 $this->assign('amount_level', $params['amount_level']);
             } else {
                 if (!$this->_online) {
                     $lineItem = array();
                     CRM_Price_BAO_Set::processAmount($this->_values['fee']['fields'], $params, $lineItem[0]);
                     $this->set('lineItem', $lineItem);
                     $this->assign('lineItem', $lineItem);
                     $this->_lineItem = $lineItem;
                 }
             }
         }
         $params['fee_level'] = $params['amount_level'];
         $contributionParams = array();
         $contributionParams['total_amount'] = $params['amount'];
     }
     //fix for CRM-3086
     $params['fee_amount'] = $params['amount'];
     $this->_params = $params;
     unset($params['amount']);
     $params['register_date'] = CRM_Utils_Date::processDate($params['register_date'], $params['register_date_time']);
     $params['receive_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $params));
     $params['contact_id'] = $this->_contactID;
     if ($this->_participantId) {
         $params['id'] = $this->_participantId;
     }
     $status = null;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $participantBAO =& new CRM_Event_BAO_Participant();
         $participantBAO->id = $this->_participantId;
         $participantBAO->find();
         while ($participantBAO->fetch()) {
             $status = $participantBAO->status_id;
             $contributionParams['total_amount'] = $participantBAO->fee_amount;
         }
         $params['discount_id'] = null;
         //re-enter the values for UPDATE mode
         $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level;
         $params['fee_amount'] = $participantBAO->fee_amount;
     }
     require_once 'CRM/Contact/BAO/Contact.php';
     // Retrieve the name and email of the current user - this will be the FROM for the receipt email
     $session =& CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
     require_once "CRM/Event/BAO/Participant.php";
     if ($this->_mode) {
         if (!$this->_isPaidEvent) {
             CRM_Core_Error::fatal(ts('Selected Event is not Paid Event '));
         }
         //modify params according to parameter used in create
         //participant method (addParticipant)
         $params['participant_status_id'] = $params['status_id'];
         $params['participant_role_id'] = $params['role_id'];
         $params['participant_register_date'] = $params['register_date'];
         $params['participant_source'] = $params['source'];
         require_once 'CRM/Core/BAO/PaymentProcessor.php';
         $this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($this->_params['payment_processor_id'], $this->_mode);
         require_once "CRM/Contact/BAO/Contact.php";
         $now = date('YmdHis');
         $fields = array();
         // set email for primary location.
         $fields["email-Primary"] = 1;
         $params["email-Primary"] = $params["email-{$this->_bltID}"] = $this->_contributorEmail;
         $params['register_date'] = $now;
         // now set the values for the billing location.
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
         // also add location name to the array
         $params["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params);
         $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
         $fields["address_name-{$this->_bltID}"] = 1;
         $fields["email-{$this->_bltID}"] = 1;
         $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type');
         $nameFields = array('first_name', 'middle_name', 'last_name');
         foreach ($nameFields as $name) {
             $fields[$name] = 1;
             if (array_key_exists("billing_{$name}", $params)) {
                 $params[$name] = $params["billing_{$name}"];
                 $params['preserveDBName'] = true;
             }
         }
         $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $this->_contactID, null, null, $ctype);
     }
     // build custom data getFields array
     $customFieldsRole = CRM_Core_BAO_CustomField::getFields('Participant', false, false, CRM_Utils_Array::value('role_id', $params), $this->_roleCustomDataTypeID);
     $customFieldsEvent = CRM_Core_BAO_CustomField::getFields('Participant', false, false, CRM_Utils_Array::value('event_id', $params), $this->_eventNameCustomDataTypeID);
     $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsRole, CRM_Core_BAO_CustomField::getFields('Participant', false, false, null, null, true));
     $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEvent, $customFields);
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_participantId, 'Participant');
     if ($this->_mode) {
         // add all the additioanl payment params we need
         $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
         $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
         $this->_params['year'] = $this->_params['credit_card_exp_date']['Y'];
         $this->_params['month'] = $this->_params['credit_card_exp_date']['M'];
         $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
         $this->_params['amount'] = $params['fee_amount'];
         $this->_params['amount_level'] = $params['amount_level'];
         $this->_params['currencyID'] = $config->defaultCurrency;
         $this->_params['payment_action'] = 'Sale';
         $this->_params['invoiceID'] = md5(uniqid(rand(), true));
         // at this point we've created a contact and stored its address etc
         // all the payment processors expect the name and address to be in the
         // so we copy stuff over to first_name etc.
         $paymentParams = $this->_params;
         if (CRM_Utils_Array::value('send_receipt', $this->_params)) {
             $paymentParams['email'] = $this->_contributorEmail;
         }
         require_once 'CRM/Core/Payment/Form.php';
         CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, true);
         $payment =& CRM_Core_Payment::singleton($this->_mode, 'Event', $this->_paymentProcessor, $this);
         $result =& $payment->doDirectPayment($paymentParams);
         if (is_a($result, 'CRM_Core_Error')) {
             CRM_Core_Error::displaySessionError($result);
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/participant', "reset=1&action=add&cid={$this->_contactID}&context=participant&mode={$this->_mode}"));
         }
         if ($result) {
             $this->_params = array_merge($this->_params, $result);
         }
         $this->_params['receive_date'] = $now;
         if (CRM_Utils_Array::value('send_receipt', $this->_params)) {
             $this->_params['receipt_date'] = $now;
         } else {
             $this->_params['receipt_date'] = null;
         }
         $this->set('params', $this->_params);
         $this->assign('trxn_id', $result['trxn_id']);
         $this->assign('receive_date', CRM_Utils_Date::processDate($this->_params['receive_date']));
         // set source if not set
         $this->_params['description'] = ts('Submit Credit Card for Event Registration by: %1', array(1 => $userName));
         require_once 'CRM/Event/Form/Registration/Confirm.php';
         require_once 'CRM/Event/Form/Registration.php';
         //add contribution record
         $this->_params['contribution_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'contribution_type_id');
         $this->_params['mode'] = $this->_mode;
         //add contribution reocord
         $contribution = CRM_Event_Form_Registration_Confirm::processContribution($this, $this->_params, $result, $contactID, false);
         // add participant record
         $participants = array();
         $participants[] = CRM_Event_Form_Registration::addParticipant($this->_params, $contactID);
         //add custom data for participant
         require_once 'CRM/Core/BAO/CustomValueTable.php';
         CRM_Core_BAO_CustomValueTable::postProcess($this->_params, CRM_Core_DAO::$_nullArray, 'civicrm_participant', $participants[0]->id, 'Participant');
         //add participant payment
         require_once 'CRM/Event/BAO/ParticipantPayment.php';
         $paymentParticipant = array('participant_id' => $participants[0]->id, 'contribution_id' => $contribution->id);
         $ids = array();
         CRM_Event_BAO_ParticipantPayment::create($paymentParticipant, $ids);
         $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'title');
         $this->_contactIds[] = $this->_contactID;
     } else {
         $participants = array();
         // fix note if deleted
         if (!$params['note']) {
             $params['note'] = 'null';
         }
         if ($this->_single) {
             $participants[] = CRM_Event_BAO_Participant::create($params);
         } else {
             foreach ($this->_contactIds as $contactID) {
                 $commonParams = $params;
                 $commonParams['contact_id'] = $contactID;
                 $participants[] = CRM_Event_BAO_Participant::create($commonParams);
             }
         }
         if (isset($params['event_id'])) {
             $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'title');
         }
         if ($this->_single) {
             $this->_contactIds[] = $this->_contactID;
         }
         if (CRM_Utils_Array::value('record_contribution', $params)) {
             if (CRM_Utils_Array::value('id', $params)) {
                 if ($this->_onlinePendingContributionId) {
                     $ids['contribution'] = $this->_onlinePendingContributionId;
                 } else {
                     $ids['contribution'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $params['id'], 'contribution_id', 'participant_id');
                 }
             }
             unset($params['note']);
             //build contribution params
             if (!$this->_onlinePendingContributionId) {
                 $contributionParams['source'] = "{$eventTitle}: Offline registration (by {$userName})";
             }
             $contributionParams['currency'] = $config->defaultCurrency;
             $contributionParams['non_deductible_amount'] = 'null';
             $contributionParams['receipt_date'] = CRM_Utils_Array::value('send_receipt', $params) ? CRM_Utils_Array::value('receive_date', $params) : 'null';
             $recordContribution = array('contact_id', 'contribution_type_id', 'payment_instrument_id', 'trxn_id', 'contribution_status_id', 'receive_date', 'check_number');
             foreach ($recordContribution as $f) {
                 $contributionParams[$f] = CRM_Utils_Array::value($f, $params);
                 if ($f == 'trxn_id') {
                     $this->assign('trxn_id', $contributionParams[$f]);
                 }
             }
             //insert contribution type name in receipt.
             $this->assign('contributionTypeName', CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionType', $contributionParams['contribution_type_id']));
             require_once 'CRM/Contribute/BAO/Contribution.php';
             $contributions = array();
             if ($this->_single) {
                 $contributions[] =& CRM_Contribute_BAO_Contribution::create($contributionParams, $ids);
             } else {
                 $ids = array();
                 foreach ($this->_contactIds as $contactID) {
                     $contributionParams['contact_id'] = $contactID;
                     $contributions[] =& CRM_Contribute_BAO_Contribution::create($contributionParams, $ids);
                 }
             }
             //insert payment record for this participation
             if (!$ids['contribution']) {
                 require_once 'CRM/Event/DAO/ParticipantPayment.php';
                 foreach ($this->_contactIds as $num => $contactID) {
                     $ppDAO =& new CRM_Event_DAO_ParticipantPayment();
                     $ppDAO->participant_id = $participants[$num]->id;
                     $ppDAO->contribution_id = $contributions[$num]->id;
                     $ppDAO->save();
                 }
             }
         }
     }
     // also store lineitem stuff here
     if ($this->_lineItem) {
         require_once 'CRM/Price/BAO/LineItem.php';
         foreach ($this->_contactIds as $num => $contactID) {
             foreach ($this->_lineItem as $key => $value) {
                 if (is_array($value) && $value != 'skip') {
                     foreach ($value as $line) {
                         $line['entity_table'] = 'civicrm_participant';
                         $line['entity_id'] = $participants[$num]->id;
                         CRM_Price_BAO_LineItem::create($line);
                     }
                 }
             }
         }
     }
     $updateStatusMsg = null;
     //send mail when participant status changed, CRM-4326
     if ($this->_participantId && $this->_statusId && $this->_statusId != CRM_Utils_Array::value('status_id', $params) && CRM_Utils_Array::value('is_notify', $params)) {
         require_once "CRM/Event/BAO/Participant.php";
         $updateStatusMsg = CRM_Event_BAO_Participant::updateStatusMessage($this->_participantId, $params['status_id'], $this->_statusId);
     }
     if (CRM_Utils_Array::value('send_receipt', $params)) {
         $receiptFrom = "{$userName} <{$userEmail}>";
         $this->assign('module', 'Event Registration');
         //use of the message template below requires variables in different format
         $event = $events = array();
         $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
         //get all event details.
         CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
         $event = $events[$params['event_id']];
         unset($event['start_date']);
         unset($event['end_date']);
         $role = CRM_Event_PseudoConstant::participantRole();
         $event['participant_role'] = $role[$params['role_id']];
         $event['is_monetary'] = $this->_isPaidEvent;
         if ($params['receipt_text']) {
             $event['confirm_email_text'] = $params['receipt_text'];
         }
         $this->assign('isAmountzero', 1);
         $this->assign('event', $event);
         $this->assign('isShowLocation', $event['is_show_location']);
         if (CRM_Utils_Array::value('is_show_location', $event) == 1) {
             $locationParams = array('entity_id' => $params['event_id'], 'entity_table' => 'civicrm_event');
             require_once 'CRM/Core/BAO/Location.php';
             $location = CRM_Core_BAO_Location::getValues($locationParams, true);
             $this->assign('location', $location);
         }
         $status = CRM_Event_PseudoConstant::participantStatus();
         if ($this->_isPaidEvent) {
             $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
             if (!$this->_mode) {
                 $this->assign('paidBy', CRM_Utils_Array::value($params['payment_instrument_id'], $paymentInstrument));
             }
             $this->assign('totalAmount', $contributionParams['total_amount']);
             $this->assign('isPrimary', 1);
             $this->assign('checkNumber', CRM_Utils_Array::value('check_number', $params));
         }
         if ($this->_mode) {
             if (CRM_Utils_Array::value('billing_first_name', $params)) {
                 $name = $params['billing_first_name'];
             }
             if (CRM_Utils_Array::value('billing_middle_name', $params)) {
                 $name .= " {$params['billing_middle_name']}";
             }
             if (CRM_Utils_Array::value('billing_last_name', $params)) {
                 $name .= " {$params['billing_last_name']}";
             }
             $this->assign('billingName', $name);
             // assign the address formatted up for display
             $addressParts = array("street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "state_province-{$this->_bltID}", "country-{$this->_bltID}");
             $addressFields = array();
             foreach ($addressParts as $part) {
                 list($n, $id) = explode('-', $part);
                 if (isset($this->_params['billing_' . $part])) {
                     $addressFields[$n] = $this->_params['billing_' . $part];
                 }
             }
             require_once 'CRM/Utils/Address.php';
             $this->assign('address', CRM_Utils_Address::format($addressFields));
             $date = CRM_Utils_Date::format($params['credit_card_exp_date']);
             $date = CRM_Utils_Date::mysqlToIso($date);
             $this->assign('credit_card_exp_date', $date);
             $this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($params['credit_card_number']));
             $this->assign('credit_card_type', $params['credit_card_type']);
             $this->assign('contributeMode', 'direct');
             $this->assign('isAmountzero', 0);
             $this->assign('is_pay_later', 0);
             $this->assign('isPrimary', 1);
         }
         $this->assign('register_date', $params['register_date']);
         if ($params['receive_date']) {
             $this->assign('receive_date', $params['receive_date']);
         }
         $participant = array(array('participant_id', '=', $participants[0]->id, 0, 0));
         // check whether its a test drive ref CRM-3075
         if (CRM_Utils_Array::value('is_test', $this->_defaultValues)) {
             $participant[] = array('participant_test', '=', 1, 0, 0);
         }
         $template =& CRM_Core_Smarty::singleton();
         $customGroup = array();
         //format submitted data
         foreach ($params['custom'] as $fieldID => $values) {
             foreach ($values as $fieldValue) {
                 $customValue = array('data' => $fieldValue['value']);
                 $customFields[$fieldID]['id'] = $fieldID;
                 $formattedValue = CRM_Core_BAO_CustomGroup::formatCustomValues($customValue, $customFields[$fieldID]);
                 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace('&nbsp;', '', $formattedValue);
             }
         }
         foreach ($this->_contactIds as $num => $contactID) {
             // Retrieve the name and email of the contact - this will be the TO for receipt email
             list($this->_contributorDisplayName, $this->_contributorEmail, $this->_toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($contactID);
             $this->_contributorDisplayName = $this->_contributorDisplayName == ' ' ? $this->_contributorEmail : $this->_contributorDisplayName;
             $this->assign('customGroup', $customGroup);
             $this->assign('contactID', $contactID);
             $this->assign('participantID', $participants[$num]->id);
             if ($this->_isPaidEvent) {
                 // fix amount for each of participants ( for bulk mode )
                 $eventAmount = array();
                 $eventAmount[$num] = array('label' => $params['amount_level'], 'amount' => $params['fee_amount']);
                 //as we are using same template for online & offline registration.
                 //So we have to build amount as array.
                 $this->assign('amount', $eventAmount);
             }
             $sendTemplateParams = array('groupName' => 'msg_tpl_workflow_event', 'valueName' => 'event_offline_receipt', 'contactId' => $contactID, 'isTest' => (bool) CRM_Utils_Array::value('is_test', $this->_defaultValues));
             // try to send emails only if email id is present
             // and the do-not-email option is not checked for that contact
             if ($this->_contributorEmail and !$this->_toDoNotEmail) {
                 $sendTemplateParams['from'] = $receiptFrom;
                 $sendTemplateParams['toName'] = $this->_contributorDisplayName;
                 $sendTemplateParams['toEmail'] = $this->_contributorEmail;
             }
             require_once 'CRM/Core/BAO/MessageTemplates.php';
             list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate($sendTemplateParams);
             if ($mailSent) {
                 $sent[] = $contactID;
             } else {
                 $notSent[] = $contactID;
             }
         }
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contributorDisplayName));
         if ($params['send_receipt'] && count($sent)) {
             $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', array(1 => $this->_contributorEmail));
         }
         if ($updateStatusMsg) {
             $statusMsg = "{$statusMsg} {$updateStatusMsg}";
         }
     } elseif ($this->_action & CRM_Core_Action::ADD) {
         if ($this->_single) {
             $statusMsg = ts('Event registration for %1 has been added.', array(1 => $this->_contributorDisplayName));
             if (CRM_Utils_Array::value('send_receipt', $params) && count($sent)) {
                 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $this->_contributorEmail));
             }
         } else {
             $statusMsg = ts('Total Participant(s) added to event: %1.', array(1 => count($this->_contactIds)));
             if (count($notSent) > 0) {
                 $statusMsg .= ' ' . ts('Email has NOT been sent to %1 contact - communication preferences specify DO NOT EMAIL OR valid Email is NOT present. ', array(1 => count($notSent)));
             } elseif (isset($params['send_receipt'])) {
                 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');
             }
         }
     }
     require_once "CRM/Core/Session.php";
     CRM_Core_Session::setStatus("{$statusMsg}");
     $buttonName = $this->controller->getButtonName();
     if ($this->_context == 'standalone') {
         if ($buttonName == $this->getButtonName('upload', 'new')) {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/participant/add', 'reset=1&action=add&context=standalone'));
         } else {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactID}&selectedChild=participant"));
         }
     } else {
         if ($buttonName == $this->getButtonName('upload', 'new')) {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/participant', "reset=1&action=add&context=participant&cid={$this->_contactID}"));
         }
     }
 }
Exemple #8
0
 /**
  * Set variables up before form is built.
  */
 public function preProcess()
 {
     parent::preProcess();
     // lineItem isn't set until Register postProcess
     $this->_lineItem = $this->get('lineItem');
     $this->_params = $this->get('params');
     $this->_params[0]['tax_amount'] = $this->get('tax_amount');
     $this->_params[0]['is_pay_later'] = $this->get('is_pay_later');
     $this->assign('is_pay_later', $this->_params[0]['is_pay_later']);
     if ($this->_params[0]['is_pay_later']) {
         $this->assign('pay_later_receipt', $this->_values['event']['pay_later_receipt']);
     }
     CRM_Utils_Hook::eventDiscount($this, $this->_params);
     if (!empty($this->_params[0]['discount']) && !empty($this->_params[0]['discount']['applied'])) {
         $this->set('hookDiscount', $this->_params[0]['discount']);
         $this->assign('hookDiscount', $this->_params[0]['discount']);
     }
     // The concept of contributeMode is deprecated.
     if ($this->_contributeMode == 'express') {
         $params = array();
         // rfp == redirect from paypal
         // rfp is probably not required - the getPreApprovalDetails should deal with any payment-processor specific 'stuff'
         $rfp = CRM_Utils_Request::retrieve('rfp', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET');
         //we lost rfp in case of additional participant. So set it explicitly.
         if ($rfp || CRM_Utils_Array::value('additional_participants', $this->_params[0], FALSE)) {
             if (!empty($this->_paymentProcessor) && $this->_paymentProcessor['object']->supports('preApproval')) {
                 $preApprovalParams = $this->_paymentProcessor['object']->getPreApprovalDetails($this->get('pre_approval_parameters'));
                 $params = array_merge($this->_params, $preApprovalParams);
             }
             CRM_Core_Payment_Form::mapParams($this->_bltID, $params, $params, FALSE);
             // set a few other parameters that are not really specific to this method because we don't know what
             // will break if we change this.
             $params['amount'] = $this->_params[0]['amount'];
             if (!empty($this->_params[0]['discount'])) {
                 $params['discount'] = $this->_params[0]['discount'];
                 $params['discountAmount'] = $this->_params[0]['discountAmount'];
                 $params['discountMessage'] = $this->_params[0]['discountMessage'];
             }
             $params['amount_level'] = $this->_params[0]['amount_level'];
             $params['currencyID'] = $this->_params[0]['currencyID'];
             // also merge all the other values from the profile fields
             $values = $this->controller->exportValues('Register');
             $skipFields = array('amount', "street_address-{$this->_bltID}", "city-{$this->_bltID}", "state_province_id-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}");
             foreach ($values as $name => $value) {
                 // skip amount field
                 if (!in_array($name, $skipFields)) {
                     $params[$name] = $value;
                 }
                 if (substr($name, 0, 6) == 'price_') {
                     $params[$name] = $this->_params[0][$name];
                 }
             }
             $this->set('getExpressCheckoutDetails', $params);
         }
         $this->_params[0] = array_merge($this->_params[0], $params);
         $this->_params[0]['is_primary'] = 1;
     } else {
         //process only primary participant params.
         $registerParams = $this->_params[0];
         if (isset($registerParams["billing_state_province_id-{$this->_bltID}"]) && $registerParams["billing_state_province_id-{$this->_bltID}"]) {
             $registerParams["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($registerParams["billing_state_province_id-{$this->_bltID}"]);
         }
         if (isset($registerParams["billing_country_id-{$this->_bltID}"]) && $registerParams["billing_country_id-{$this->_bltID}"]) {
             $registerParams["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($registerParams["billing_country_id-{$this->_bltID}"]);
         }
         if (isset($registerParams['credit_card_exp_date'])) {
             $registerParams['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($registerParams);
             $registerParams['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($registerParams);
         }
         if ($this->_values['event']['is_monetary']) {
             $registerParams['ip_address'] = CRM_Utils_System::ipAddress();
             $registerParams['currencyID'] = $this->_params[0]['currencyID'];
         }
         //assign back primary participant params.
         $this->_params[0] = $registerParams;
     }
     if ($this->_values['event']['is_monetary']) {
         $this->_params[0]['invoiceID'] = $this->get('invoiceID');
     }
     $this->assign('defaultRole', FALSE);
     if (CRM_Utils_Array::value('defaultRole', $this->_params[0]) == 1) {
         $this->assign('defaultRole', TRUE);
     }
     if (empty($this->_params[0]['participant_role_id']) && $this->_values['event']['default_role_id']) {
         $this->_params[0]['participant_role_id'] = $this->_values['event']['default_role_id'];
     }
     if (isset($this->_values['event']['confirm_title'])) {
         CRM_Utils_System::setTitle($this->_values['event']['confirm_title']);
     }
     if ($this->_pcpId) {
         $params = CRM_Contribute_Form_Contribution_Confirm::processPcp($this, $this->_params[0]);
         $this->_params[0] = $params;
     }
     $this->set('params', $this->_params);
 }
 public function buildQuickForm()
 {
     $statuses = CRM_Event_PseudoConstant::participantStatus();
     $this->assign('partiallyPaid', array_search('Partially paid', $statuses));
     $this->assign('pendingRefund', array_search('Pending refund', $statuses));
     $this->assign('participantStatus', $this->_participantStatus);
     $config = CRM_Core_Config::singleton();
     $this->assign('currencySymbol', $config->defaultCurrencySymbol);
     // line items block
     $lineItem = $event = array();
     $params = array('id' => $this->_eventId);
     CRM_Event_BAO_Event::retrieve($params, $event);
     //retrieve custom information
     $this->_values = array();
     CRM_Event_Form_Registration::initEventFee($this, $event['id']);
     CRM_Event_Form_Registration_Register::buildAmount($this, TRUE);
     if (!CRM_Utils_System::isNull(CRM_Utils_Array::value('line_items', $this->_values))) {
         $lineItem[] = $this->_values['line_items'];
     }
     $this->assign('lineItem', empty($lineItem) ? FALSE : $lineItem);
     $event = CRM_Event_BAO_Event::getEvents(0, $this->_eventId);
     $this->assign('eventName', $event[$this->_eventId]);
     $statusOptions = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label');
     $this->add('select', 'status_id', ts('Participant Status'), array('' => ts('- select -')) + $statusOptions, TRUE);
     $this->addElement('checkbox', 'send_receipt', ts('Send Confirmation?'), NULL, array('onclick' => "showHideByValue('send_receipt','','notice','table-row','radio',false); showHideByValue('send_receipt','','from-email','table-row','radio',false);"));
     $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails['from_email_id']);
     $this->add('textarea', 'receipt_text', ts('Confirmation Message'));
     $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note');
     $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
     $buttons[] = array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE);
     if (CRM_Event_BAO_Participant::isPrimaryParticipant($this->_participantId)) {
         $buttons[] = array('type' => 'upload', 'name' => ts('Save and Record Payment'), 'subName' => 'new');
     }
     $buttons[] = array('type' => 'cancel', 'name' => ts('Cancel'));
     $this->addButtons($buttons);
     $this->addFormRule(array('CRM_Event_Form_ParticipantFeeSelection', 'formRule'), $this);
 }
Exemple #10
0
 /**
  * Set default values for the form.
  */
 public function setDefaultValues()
 {
     $this->_defaults = array();
     if (!$this->_allowConfirmation && $this->_requireApproval) {
         $this->_defaults['bypass_payment'] = 1;
     }
     $contactID = $this->getContactID();
     CRM_Core_Payment_Form::setDefaultValues($this, $contactID);
     CRM_Event_BAO_Participant::formatFieldsAndSetProfileDefaults($contactID, $this);
     // Set default payment processor as default payment_processor radio button value
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $pid => $value) {
             if (!empty($value['is_default'])) {
                 $this->_defaults['payment_processor_id'] = $pid;
             }
         }
     }
     //if event is monetary and pay later is enabled and payment
     //processor is not available then freeze the pay later checkbox with
     //default check
     if (!empty($this->_values['event']['is_pay_later']) && !is_array($this->_paymentProcessor)) {
         $this->_defaults['is_pay_later'] = 1;
     }
     //set custom field defaults
     if (!empty($this->_fields)) {
         //load default campaign from page.
         if (array_key_exists('participant_campaign_id', $this->_fields)) {
             $this->_defaults['participant_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
         }
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 // fix for CRM-1743
                 if (!isset($this->_defaults[$name])) {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
                 }
             }
         }
     }
     //fix for CRM-3088, default value for discount set.
     $discountId = NULL;
     if (!empty($this->_values['discount'])) {
         $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
         if ($discountId) {
             if (isset($this->_values['event']['default_discount_fee_id'])) {
                 $discountKey = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_values['event']['default_discount_fee_id'], 'weight', 'id');
                 $this->_defaults['amount'] = key(array_slice($this->_values['discount'][$discountId], $discountKey - 1, $discountKey, TRUE));
             }
         }
     }
     // add this event's default participant role to defaults array
     // (for cases where participant_role field is included in form via profile)
     if ($this->_values['event']['default_role_id']) {
         $this->_defaults['participant_role'] = $this->_defaults['participant_role_id'] = $this->_values['event']['default_role_id'];
     }
     if ($this->_priceSetId && !empty($this->_feeBlock)) {
         foreach ($this->_feeBlock as $key => $val) {
             if (empty($val['options'])) {
                 continue;
             }
             $optionFullIds = CRM_Utils_Array::value('option_full_ids', $val, array());
             foreach ($val['options'] as $keys => $values) {
                 if ($values['is_default'] && empty($values['is_full'])) {
                     if ($val['html_type'] == 'CheckBox') {
                         $this->_defaults["price_{$key}"][$keys] = 1;
                     } else {
                         $this->_defaults["price_{$key}"] = $keys;
                     }
                 }
             }
             $unsetSubmittedOptions[$val['id']] = $optionFullIds;
         }
         //reset values for all options those are full.
         CRM_Event_Form_Registration::resetElementValue($unsetSubmittedOptions, $this);
     }
     //set default participant fields, CRM-4320.
     $hasAdditionalParticipants = FALSE;
     if ($this->_allowConfirmation) {
         $this->_contactId = $contactID;
         $this->_discountId = $discountId;
         $forcePayLater = CRM_Utils_Array::value('is_pay_later', $this->_defaults, FALSE);
         $this->_defaults = array_merge($this->_defaults, CRM_Event_Form_EventFees::setDefaultValues($this));
         $this->_defaults['is_pay_later'] = $forcePayLater;
         if ($this->_additionalParticipantIds) {
             $hasAdditionalParticipants = TRUE;
             $this->_defaults['additional_participants'] = count($this->_additionalParticipantIds);
         }
     }
     $this->assign('hasAdditionalParticipants', $hasAdditionalParticipants);
     //         //hack to simplify credit card entry for testing
     //         $this->_defaults['credit_card_type']     = 'Visa';
     //         $this->_defaults['credit_card_number']   = '4807731747657838';
     //         $this->_defaults['cvv2']                 = '000';
     //         $this->_defaults['credit_card_exp_date'] = array( 'Y' => '2010', 'M' => '05' );
     // to process Custom data that are appended to URL
     $getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams($this, "'Contact', 'Individual', 'Contribution', 'Participant'");
     if (!empty($getDefaults)) {
         $this->_defaults = array_merge($this->_defaults, $getDefaults);
     }
     return $this->_defaults;
 }
Exemple #11
0
 /**
  * Set default values for the form. For edit/view mode
  * the default values are retrieved from the database
  * Adding discussion from CRM-11915 as code comments
  * When multiple payment processors are configured for a event and user does any selection changes for them on online event registeration page :
  * The 'Register' page gets loaded through ajax and following happens :
  * the setDefaults function is called with the variable _ppType set with selected payment processor type,
  * so in the 'if' condition checked whether the selected payment processor's billing mode is of 'billing form mode'. If its not, don't setDefaults for billing form and return instead.
  * - For payment processors of billing mode 'Notify' - return from setDefaults before the code for billing profile population execution .
  * (done this is because for payment processors with 'Notify' mode billing profile form doesn't get rendered on UI)
  *
  * @return void
  */
 public function setDefaultValues()
 {
     if ($this->_paymentProcessorID && $this->_snippet && !($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM)) {
         // see function comment block for explanation of this. Note that CRM-15555 will require this to look at the billing form fields not the
         // billing_mode which
         return;
     }
     $this->_defaults = array();
     $contactID = $this->getContactID();
     $billingDefaults = $this->getProfileDefaults('Billing', $contactID);
     $this->_defaults = array_merge($this->_defaults, $billingDefaults);
     $config = CRM_Core_Config::singleton();
     // set default country from config if no country set
     // note the effect of this is to set the billing country to default to the site default
     // country if the person has an address but no country (for anonymous country is set above)
     // this could have implications if the billing profile is filled but hidden.
     // this behaviour has been in place for a while but the use of js to hide things has increased
     if (empty($this->_defaults["billing_country_id-{$this->_bltID}"])) {
         $this->_defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
     }
     // set default state/province from config if no state/province set
     if (empty($this->_defaults["billing_state_province_id-{$this->_bltID}"])) {
         $this->_defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
     }
     if ($this->_snippet) {
         return $this->_defaults;
     }
     if ($contactID) {
         $fields = array();
         if (!empty($this->_fields)) {
             $removeCustomFieldTypes = array('Participant');
             foreach ($this->_fields as $name => $dontCare) {
                 if (substr($name, 0, 7) == 'custom_') {
                     $id = substr($name, 7);
                     if (!$this->_allowConfirmation && !CRM_Core_BAO_CustomGroup::checkCustomField($id, $removeCustomFieldTypes)) {
                         continue;
                     }
                     // ignore component fields
                 } elseif (substr($name, 0, 12) == 'participant_') {
                     continue;
                 }
                 $fields[$name] = 1;
             }
         }
     }
     if (!empty($fields)) {
         CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults);
     }
     // Set default payment processor as default payment_processor radio button value
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $pid => $value) {
             if (!empty($value['is_default'])) {
                 $this->_defaults['payment_processor_id'] = $pid;
             }
         }
     }
     //if event is monetary and pay later is enabled and payment
     //processor is not available then freeze the pay later checkbox with
     //default check
     if (!empty($this->_values['event']['is_pay_later']) && !is_array($this->_paymentProcessor)) {
         $this->_defaults['is_pay_later'] = 1;
     }
     //set custom field defaults
     if (!empty($this->_fields)) {
         //load default campaign from page.
         if (array_key_exists('participant_campaign_id', $this->_fields)) {
             $this->_defaults['participant_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
         }
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 // fix for CRM-1743
                 if (!isset($this->_defaults[$name])) {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
                 }
             }
         }
     }
     //fix for CRM-3088, default value for discount set.
     $discountId = NULL;
     if (!empty($this->_values['discount'])) {
         $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
         if ($discountId) {
             if (isset($this->_values['event']['default_discount_fee_id'])) {
                 $discountKey = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_values['event']['default_discount_fee_id'], 'weight', 'id');
                 $this->_defaults['amount'] = key(array_slice($this->_values['discount'][$discountId], $discountKey - 1, $discountKey, TRUE));
             }
         }
     }
     // add this event's default participant role to defaults array
     // (for cases where participant_role field is included in form via profile)
     if ($this->_values['event']['default_role_id']) {
         $this->_defaults['participant_role'] = $this->_defaults['participant_role_id'] = $this->_values['event']['default_role_id'];
     }
     if ($this->_priceSetId && !empty($this->_feeBlock)) {
         foreach ($this->_feeBlock as $key => $val) {
             if (empty($val['options'])) {
                 continue;
             }
             $optionFullIds = CRM_Utils_Array::value('option_full_ids', $val, array());
             foreach ($val['options'] as $keys => $values) {
                 if ($values['is_default'] && empty($values['is_full'])) {
                     if ($val['html_type'] == 'CheckBox') {
                         $this->_defaults["price_{$key}"][$keys] = 1;
                     } else {
                         $this->_defaults["price_{$key}"] = $keys;
                     }
                 }
             }
             $unsetSubmittedOptions[$val['id']] = $optionFullIds;
         }
         //reset values for all options those are full.
         CRM_Event_Form_Registration::resetElementValue($unsetSubmittedOptions, $this);
     }
     //set default participant fields, CRM-4320.
     $hasAdditionalParticipants = FALSE;
     if ($this->_allowConfirmation) {
         $this->_contactId = $contactID;
         $this->_discountId = $discountId;
         $forcePayLater = CRM_Utils_Array::value('is_pay_later', $this->_defaults, FALSE);
         $this->_defaults = array_merge($this->_defaults, CRM_Event_Form_EventFees::setDefaultValues($this));
         $this->_defaults['is_pay_later'] = $forcePayLater;
         if ($this->_additionalParticipantIds) {
             $hasAdditionalParticipants = TRUE;
             $this->_defaults['additional_participants'] = count($this->_additionalParticipantIds);
         }
     }
     $this->assign('hasAdditionalParticipants', $hasAdditionalParticipants);
     //         //hack to simplify credit card entry for testing
     //         $this->_defaults['credit_card_type']     = 'Visa';
     //         $this->_defaults['credit_card_number']   = '4807731747657838';
     //         $this->_defaults['cvv2']                 = '000';
     //         $this->_defaults['credit_card_exp_date'] = array( 'Y' => '2010', 'M' => '05' );
     // to process Custom data that are appended to URL
     $getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams($this, "'Contact', 'Individual', 'Contribution', 'Participant'");
     if (!empty($getDefaults)) {
         $this->_defaults = array_merge($this->_defaults, $getDefaults);
     }
     return $this->_defaults;
 }
 /**
  * Method to check if the user is already registered for the event
  * and if result found redirect to the event info page
  *
  * @param array $fields  the input form values(anonymous user)
  * @param array $self    event data
  *
  * @return void
  * @access public
  */
 function checkRegistration($fields, &$self, $isAdditional = FALSE, $returnContactId = FALSE, $useDedupeRules = FALSE)
 {
     // CRM-3907, skip check for preview registrations
     // CRM-4320 participant need to walk wizard
     if (!$returnContactId && ($self->_mode == 'test' || $self->_allowConfirmation)) {
         return FALSE;
     }
     $contactID = NULL;
     $session = CRM_Core_Session::singleton();
     if (!$isAdditional) {
         $contactID = parent::getContactID();
     }
     if (!$contactID && is_array($fields) && !empty($fields)) {
         //CRM-6996
         //as we are allowing w/ same email address,
         //lets check w/ other contact params.
         if ($self->_values['event']['allow_same_participant_emails'] || $useDedupeRules) {
             $params = $fields;
             $level = $isAdditional ? 'Fuzzy' : 'Strict';
             $dedupeParams = CRM_Dedupe_Finder::formatParams($params, 'Individual');
             // disable permission based on cache since event registration is public page/feature.
             $dedupeParams['check_permission'] = FALSE;
             $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual', $level);
             $contactID = CRM_Utils_Array::value(0, $ids);
         } else {
             foreach ($fields as $fieldname => $fieldvalue) {
                 if (substr($fieldname, 0, 6) == 'email-') {
                     $emailString = trim($fieldvalue);
                     if (!empty($emailString)) {
                         $match = CRM_Contact_BAO_Contact::matchContactOnEmail($emailString, 'Individual');
                         if (!empty($match)) {
                             $contactID = $match->contact_id;
                         }
                     }
                 }
             }
         }
     }
     if ($returnContactId) {
         // CRM-7377
         // return contactID if contact already exists
         return $contactID;
     }
     if ($contactID) {
         $participant = new CRM_Event_BAO_Participant();
         $participant->contact_id = $contactID;
         $participant->event_id = $self->_values['event']['id'];
         $participant->role_id = $self->_values['event']['default_role_id'];
         $participant->is_test = 0;
         $participant->find();
         $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1');
         while ($participant->fetch()) {
             if (array_key_exists($participant->status_id, $statusTypes)) {
                 if (!$isAdditional && !$self->_values['event']['allow_same_participant_emails']) {
                     $registerUrl = CRM_Utils_System::url('civicrm/event/register', "reset=1&id={$self->_values['event']['id']}&cid=0");
                     if ($self->_pcpId) {
                         $registerUrl .= '&pcpId=' . $self->_pcpId;
                     }
                     $status = ts("Oops. It looks like you are already registered for this event. If you want to change your registration, or you feel that you've gotten this message in error, please contact the site administrator.") . ' ' . ts('You can also <a href="%1">register another participant</a>.', array(1 => $registerUrl));
                     $session->setStatus($status);
                     $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$self->_values['event']['id']}&noFullMsg=true");
                     if ($self->_action & CRM_Core_Action::PREVIEW) {
                         $url .= '&action=preview';
                     }
                     if ($self->_pcpId) {
                         $url .= '&pcpId=' . $self->_pcpId;
                     }
                     CRM_Utils_System::redirect($url);
                 }
                 if ($isAdditional) {
                     $status = ts("Oops. It looks like this participant is already registered for this event. If you want to change your registration, or you feel that you've gotten this message in error, please contact the site administrator.");
                     $session->setStatus($status);
                     return $participant->id;
                 }
             }
         }
     }
 }
Exemple #13
0
 /** 
  * Function to set variables up before form is built 
  *                                                           
  * @return void 
  * @access public 
  */
 function preProcess()
 {
     parent::preProcess();
     // lineItem isn't set until Register postProcess
     $this->_lineItem = $this->get('lineItem');
     $this->_params = $this->get('params');
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::eventDiscount($this, $this->_params);
     if (CRM_Utils_Array::value('discount', $this->_params[0]) && CRM_Utils_Array::value('applied', $this->_params[0]['discount'])) {
         $this->set('hookDiscount', $this->_params[0]['discount']);
         $this->assign('hookDiscount', $this->_params[0]['discount']);
     }
     $config =& CRM_Core_Config::singleton();
     if ($this->_contributeMode == 'express') {
         $params = array();
         // rfp == redirect from paypal
         $rfp = CRM_Utils_Request::retrieve('rfp', 'Boolean', CRM_Core_DAO::$_nullObject, false, null, 'GET');
         //we lost rfp in case of additional participant. So set it explicitly.
         if ($rfp || CRM_Utils_Array::value('additional_participants', $this->_params[0], false)) {
             require_once 'CRM/Core/Payment.php';
             $payment =& CRM_Core_Payment::singleton($this->_mode, 'Event', $this->_paymentProcessor, $this);
             $expressParams = $payment->getExpressCheckoutDetails($this->get('token'));
             $params['payer'] = $expressParams['payer'];
             $params['payer_id'] = $expressParams['payer_id'];
             $params['payer_status'] = $expressParams['payer_status'];
             require_once 'CRM/Core/Payment/Form.php';
             CRM_Core_Payment_Form::mapParams($this->_bltID, $expressParams, $params, false);
             // fix state and country id if present
             if (isset($params["billing_state_province_id-{$this->_bltID}"])) {
                 $params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($params["billing_state_province_id-{$this->_bltID}"]);
             }
             if (isset($params['billing_country_id'])) {
                 $params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($params["billing_country_id-{$this->_bltID}"]);
             }
             // set a few other parameters for PayPal
             $params['token'] = $this->get('token');
             $params['amount'] = $this->_params[0]['amount'];
             if (CRM_Utils_Array::value('discount', $this->_params[0])) {
                 $params['discount'] = $this->_params[0]['discount'];
                 $params['discountAmount'] = $this->_params[0]['discountAmount'];
                 $params['discountMessage'] = $this->_params[0]['discountMessage'];
             }
             $params['amount_level'] = $this->_params[0]['amount_level'];
             $params['currencyID'] = $this->_params[0]['currencyID'];
             $params['payment_action'] = 'Sale';
             // also merge all the other values from the profile fields
             $values = $this->controller->exportValues('Register');
             $skipFields = array('amount', "street_address-{$this->_bltID}", "city-{$this->_bltID}", "state_province_id-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}");
             foreach ($values as $name => $value) {
                 // skip amount field
                 if (!in_array($name, $skipFields)) {
                     $params[$name] = $value;
                 }
             }
             $this->set('getExpressCheckoutDetails', $params);
         } else {
             $params = $this->get('getExpressCheckoutDetails');
         }
         $this->_params[0] = $params;
         $this->_params[0]['is_primary'] = 1;
     } else {
         //process only primary participant params.
         $registerParams = $this->_params[0];
         if (isset($registerParams["billing_state_province_id-{$this->_bltID}"]) && $registerParams["billing_state_province_id-{$this->_bltID}"]) {
             $registerParams["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($registerParams["billing_state_province_id-{$this->_bltID}"]);
         }
         if (isset($registerParams["billing_country_id-{$this->_bltID}"]) && $registerParams["billing_country_id-{$this->_bltID}"]) {
             $registerParams["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($registerParams["billing_country_id-{$this->_bltID}"]);
         }
         if (isset($registerParams['credit_card_exp_date'])) {
             $registerParams['year'] = $registerParams['credit_card_exp_date']['Y'];
             $registerParams['month'] = $registerParams['credit_card_exp_date']['M'];
         }
         if ($this->_values['event']['is_monetary']) {
             $registerParams['ip_address'] = CRM_Utils_System::ipAddress();
             $registerParams['currencyID'] = $this->_params[0]['currencyID'];
             $registerParams['payment_action'] = 'Sale';
         }
         //assign back primary participant params.
         $this->_params[0] = $registerParams;
     }
     if ($this->_values['event']['is_monetary']) {
         $this->_params[0]['invoiceID'] = $this->get('invoiceID');
     }
     $this->assign('defaultRole', false);
     if (CRM_Utils_Array::value('defaultRole', $this->_params[0]) == 1) {
         $this->assign('defaultRole', true);
     }
     if (!CRM_Utils_Array::value('participant_role_id', $this->_params[0]) && $this->_values['event']['default_role_id']) {
         $this->_params[0]['participant_role_id'] = $this->_values['event']['default_role_id'];
     }
     if (isset($this->_values['event']['confirm_title'])) {
         CRM_Utils_System::setTitle($this->_values['event']['confirm_title']);
     }
     $this->set('params', $this->_params);
 }
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     $now = date('YmdHis');
     $config = CRM_Core_Config::singleton();
     $session = CRM_Core_Session::singleton();
     $this->_params = $this->get('params');
     if (CRM_Utils_Array::value('contact_id', $this->_params[0])) {
         $contactID = $this->_params[0]['contact_id'];
     } else {
         $contactID = parent::getContactID();
     }
     // if a discount has been applied, lets now deduct it from the amount
     // and fix the fee level
     if (CRM_Utils_Array::value('discount', $this->_params[0]) && CRM_Utils_Array::value('applied', $this->_params[0]['discount'])) {
         foreach ($this->_params as $k => $v) {
             if (CRM_Utils_Array::value('amount', $this->_params[$k]) > 0 && CRM_Utils_Array::value('discountAmount', $this->_params[$k])) {
                 $this->_params[$k]['amount'] -= $this->_params[$k]['discountAmount'];
                 $this->_params[$k]['amount_level'] .= CRM_Utils_Array::value('discountMessage', $this->_params[$k]);
             }
         }
         $this->set('params', $this->_params);
     }
     // CRM-4320, lets build array of cancelled additional participant ids
     // those are drop or skip by primary at the time of confirmation.
     // get all in and then unset those we want to process.
     $cancelledIds = $this->_additionalParticipantIds;
     $params = $this->_params;
     $this->set('finalAmount', $this->_amount);
     $participantCount = array();
     //unset the skip participant from params.
     //build the $participantCount array.
     //maintain record for all participants.
     foreach ($params as $participantNum => $record) {
         if ($record == 'skip') {
             unset($params[$participantNum]);
             $participantCount[$participantNum] = 'skip';
         } elseif ($participantNum) {
             $participantCount[$participantNum] = 'participant';
         }
         //lets get additional participant id to cancel.
         if ($this->_allowConfirmation && is_array($cancelledIds)) {
             $additonalId = CRM_Utils_Array::value('participant_id', $record);
             if ($additonalId && ($key = array_search($additonalId, $cancelledIds))) {
                 unset($cancelledIds[$key]);
             }
         }
     }
     $payment = $registerByID = $primaryCurrencyID = $contribution = NULL;
     $paymentObjError = ts('The system did not record payment details for this payment and so could not process the transaction. Please report this error to the site administrator.');
     $this->participantIDS = array();
     foreach ($params as $key => $value) {
         $this->fixLocationFields($value, $fields);
         //unset the billing parameters if it is pay later mode
         //to avoid creation of billing location
         if ($this->_allowWaitlist || $this->_requireApproval || CRM_Utils_Array::value('is_pay_later', $value) || !CRM_Utils_Array::value('is_primary', $value)) {
             $billingFields = array("email-{$this->_bltID}", "billing_first_name", "billing_middle_name", "billing_last_name", "billing_street_address-{$this->_bltID}", "billing_city-{$this->_bltID}", "billing_state_province-{$this->_bltID}", "billing_state_province_id-{$this->_bltID}", "billing_postal_code-{$this->_bltID}", "billing_country-{$this->_bltID}", "billing_country_id-{$this->_bltID}", "address_name-{$this->_bltID}");
             foreach ($billingFields as $field) {
                 unset($value[$field]);
             }
             if (CRM_Utils_Array::value('is_pay_later', $value)) {
                 $this->_values['params']['is_pay_later'] = TRUE;
             }
         }
         //Unset ContactID for additional participants and set RegisterBy Id.
         if (!CRM_Utils_Array::value('is_primary', $value)) {
             $contactID = CRM_Utils_Array::value('contact_id', $value);
             $registerByID = $this->get('registerByID');
             if ($registerByID) {
                 $value['registered_by_id'] = $registerByID;
             }
         } else {
             $value['amount'] = $this->_totalAmount;
         }
         $contactID =& $this->updateContactFields($contactID, $value, $fields);
         // lets store the contactID in the session
         // we dont store in userID in case the user is doing multiple
         // transactions etc
         // for things like tell a friend
         if (!parent::getContactID() && CRM_Utils_Array::value('is_primary', $value)) {
             $session->set('transaction.userID', $contactID);
         }
         $value['description'] = ts('Online Event Registration') . ': ' . $this->_values['event']['title'];
         $value['accountingCode'] = CRM_Utils_Array::value('accountingCode', $this->_values['event']);
         // required only if paid event
         if ($this->_values['event']['is_monetary']) {
             if (is_array($this->_paymentProcessor)) {
                 $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
             }
             $pending = FALSE;
             $result = NULL;
             if ($this->_allowWaitlist || $this->_requireApproval) {
                 //get the participant statuses.
                 $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'");
                 if ($this->_allowWaitlist) {
                     $value['participant_status_id'] = $value['participant_status'] = array_search('On waitlist', $waitingStatuses);
                 } else {
                     $value['participant_status_id'] = $value['participant_status'] = array_search('Awaiting approval', $waitingStatuses);
                 }
                 //there might be case user seleted pay later and
                 //now becomes part of run time waiting list.
                 $value['is_pay_later'] = FALSE;
             } elseif (CRM_Utils_Array::value('is_pay_later', $value) || $value['amount'] == 0 || $this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify') {
                 if ($value['amount'] != 0) {
                     $pending = TRUE;
                     //get the participant statuses.
                     $pendingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'");
                     $status = CRM_Utils_Array::value('is_pay_later', $value) ? 'Pending from pay later' : 'Pending from incomplete transaction';
                     $value['participant_status_id'] = $value['participant_status'] = array_search($status, $pendingStatuses);
                 }
             } elseif ($this->_contributeMode == 'express' && CRM_Utils_Array::value('is_primary', $value)) {
                 if (is_object($payment)) {
                     $result =& $payment->doExpressCheckout($value);
                 } else {
                     CRM_Core_Error::fatal($paymentObjError);
                 }
             } elseif (CRM_Utils_Array::value('is_primary', $value)) {
                 CRM_Core_Payment_Form::mapParams($this->_bltID, $value, $value, TRUE);
                 if (is_object($payment)) {
                     $result =& $payment->doDirectPayment($value);
                 } else {
                     CRM_Core_Error::fatal($paymentObjError);
                 }
             }
             if (is_a($result, 'CRM_Core_Error')) {
                 CRM_Core_Error::displaySessionError($result);
                 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "id={$this->_eventId}"));
             }
             if ($result) {
                 $value = array_merge($value, $result);
             }
             $value['receive_date'] = $now;
             if ($this->_allowConfirmation) {
                 $value['participant_register_date'] = $this->_values['participant']['register_date'];
             }
             $createContrib = $value['amount'] != 0 ? TRUE : FALSE;
             // force to create zero amount contribution, CRM-5095
             if (!$createContrib && $value['amount'] == 0 && $this->_priceSetId && $this->_lineItem) {
                 $createContrib = TRUE;
             }
             if ($createContrib && CRM_Utils_Array::value('is_primary', $value) && !$this->_allowWaitlist && !$this->_requireApproval) {
                 // if paid event add a contribution record
                 //if primary participant contributing additional amount
                 //append (multiple participants) to its fee level. CRM-4196.
                 $isAdditionalAmount = FALSE;
                 if (count($params) > 1) {
                     $isAdditionalAmount = TRUE;
                 }
                 //passing contribution id is already registered.
                 $contribution =& self::processContribution($this, $value, $result, $contactID, $pending, $isAdditionalAmount);
                 $value['contributionID'] = $contribution->id;
                 $value['contributionTypeID'] = $contribution->contribution_type_id;
                 $value['receive_date'] = $contribution->receive_date;
                 $value['trxn_id'] = $contribution->trxn_id;
                 $value['contributionID'] = $contribution->id;
                 $value['contributionTypeID'] = $contribution->contribution_type_id;
             }
             $value['contactID'] = $contactID;
             $value['eventID'] = $this->_eventId;
             $value['item_name'] = $value['description'];
         }
         //CRM-4453.
         if (CRM_Utils_Array::value('is_primary', $value)) {
             $primaryCurrencyID = CRM_Utils_Array::value('currencyID', $value);
         }
         if (!CRM_Utils_Array::value('currencyID', $value)) {
             $value['currencyID'] = $primaryCurrencyID;
         }
         if (!$pending && CRM_Utils_Array::value('is_primary', $value) && !$this->_allowWaitlist && !$this->_requireApproval) {
             // transactionID & receive date required while building email template
             $this->assign('trxn_id', $value['trxn_id']);
             $this->assign('receive_date', CRM_Utils_Date::mysqlToIso($value['receive_date']));
             $this->set('receiveDate', CRM_Utils_Date::mysqlToIso($value['receive_date']));
             $this->set('trxnId', CRM_Utils_Array::value('trxn_id', $value));
         }
         $value['fee_amount'] = $value['amount'];
         $this->set('value', $value);
         // handle register date CRM-4320
         if ($this->_allowConfirmation) {
             $registerDate = CRM_Utils_Array::value('participant_register_date', $params);
         } elseif (CRM_Utils_Array::value('participant_register_date', $params) && is_array($params['participant_register_date']) && !empty($params['participant_register_date'])) {
             $registerDate = CRM_Utils_Date::format($params['participant_register_date']);
         } else {
             $registerDate = date('YmdHis');
         }
         $this->assign('register_date', $registerDate);
         $this->confirmPostProcess($contactID, $contribution, $payment);
     }
     //handle if no additional participant.
     if (!$registerByID) {
         $registerByID = $this->get('registerByID');
     }
     $this->set('participantIDs', $this->_participantIDS);
     // create line items, CRM-5313
     if ($this->_priceSetId && !empty($this->_lineItem)) {
         // take all processed participant ids.
         $allParticipantIds = $this->_participantIDS;
         // when participant re-walk wizard.
         if ($this->_allowConfirmation && !empty($this->_additionalParticipantIds)) {
             $allParticipantIds = array_merge(array($registerByID), $this->_additionalParticipantIds);
         }
         $entityTable = 'civicrm_participant';
         foreach ($this->_lineItem as $key => $value) {
             if ($value != 'skip' && ($entityId = CRM_Utils_Array::value($key, $allParticipantIds))) {
                 // do cleanup line  items if participant re-walking wizard.
                 if ($this->_allowConfirmation) {
                     CRM_Price_BAO_LineItem::deleteLineItems($entityId, $entityTable);
                 }
                 // create line.
                 foreach ($value as $line) {
                     $line['entity_id'] = $entityId;
                     $line['entity_table'] = $entityTable;
                     CRM_Price_BAO_LineItem::create($line);
                 }
             }
         }
     }
     //update status and send mail to cancelled additonal participants, CRM-4320
     if ($this->_allowConfirmation && is_array($cancelledIds) && !empty($cancelledIds)) {
         $cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"));
         CRM_Event_BAO_Participant::transitionParticipants($cancelledIds, $cancelledId);
     }
     $isTest = FALSE;
     if ($this->_action & CRM_Core_Action::PREVIEW) {
         $isTest = TRUE;
     }
     // for Transfer checkout.
     if (($this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify') && !CRM_Utils_Array::value('is_pay_later', $params[0]) && !$this->_allowWaitlist && !$this->_requireApproval && $this->_totalAmount > 0) {
         $primaryParticipant = $this->get('primaryParticipant');
         if (!CRM_Utils_Array::value('participantID', $primaryParticipant)) {
             $primaryParticipant['participantID'] = $registerByID;
         }
         //build an array of custom profile and assigning it to template
         $customProfile = CRM_Event_BAO_Event::buildCustomProfile($registerByID, $this->_values, NULL, $isTest);
         if (count($customProfile)) {
             $this->assign('customProfile', $customProfile);
             $this->set('customProfile', $customProfile);
         }
         // do a transfer only if a monetary payment greater than 0
         if ($this->_values['event']['is_monetary'] && $primaryParticipant) {
             if ($payment && is_object($payment)) {
                 $payment->doTransferCheckout($primaryParticipant, 'event');
             } else {
                 CRM_Core_Error::fatal($paymentObjError);
             }
         }
     } else {
         //otherwise send mail Confirmation/Receipt
         $primaryContactId = $this->get('primaryContactId');
         //build an array of cId/pId of participants
         $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID, NULL, $primaryContactId, $isTest, TRUE);
         //lets send  mails to all with meaningful text, CRM-4320.
         $this->assign('isOnWaitlist', $this->_allowWaitlist);
         $this->assign('isRequireApproval', $this->_requireApproval);
         //need to copy, since we are unsetting on the way.
         $copyParticipantCount = $participantCount;
         //lets carry all paticipant params w/ values.
         foreach ($additionalIDs as $participantID => $contactId) {
             $participantNum = NULL;
             if ($participantID == $registerByID) {
                 $participantNum = 0;
             } else {
                 if ($participantNum = array_search('participant', $copyParticipantCount)) {
                     unset($copyParticipantCount[$participantNum]);
                 }
             }
             if ($participantNum === NULL) {
                 break;
             }
             //carry the participant submitted values.
             $this->_values['params'][$participantID] = $params[$participantNum];
         }
         foreach ($additionalIDs as $participantID => $contactId) {
             $participantNum = 0;
             if ($participantID == $registerByID) {
                 //set as Primary Participant
                 $this->assign('isPrimary', 1);
                 //build an array of custom profile and assigning it to template.
                 $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participantID, $this->_values, NULL, $isTest);
                 if (count($customProfile)) {
                     $this->assign('customProfile', $customProfile);
                     $this->set('customProfile', $customProfile);
                 }
                 $this->_values['params']['additionalParticipant'] = FALSE;
             } else {
                 //take the Additional participant number.
                 if ($participantNum = array_search('participant', $participantCount)) {
                     unset($participantCount[$participantNum]);
                 }
                 $this->assign('isPrimary', 0);
                 $this->assign('customProfile', NULL);
                 //Additional Participant should get only it's payment information
                 if ($this->_amount) {
                     $amount = array();
                     $params = $this->get('params');
                     $amount[$participantNum]['label'] = $params[$participantNum]['amount_level'];
                     $amount[$participantNum]['amount'] = $params[$participantNum]['amount'];
                     $this->assign('amount', $amount);
                 }
                 if ($this->_lineItem) {
                     $lineItems = $this->_lineItem;
                     $lineItem = array();
                     $lineItem[] = CRM_Utils_Array::value($participantNum, $lineItems);
                     $this->assign('lineItem', $lineItem);
                 }
                 $this->_values['params']['additionalParticipant'] = TRUE;
             }
             //pass these variables since these are run time calculated.
             $this->_values['params']['isOnWaitlist'] = $this->_allowWaitlist;
             $this->_values['params']['isRequireApproval'] = $this->_requireApproval;
             //send mail to primary as well as additional participants.
             $this->assign('contactID', $contactId);
             $this->assign('participantID', $participantID);
             CRM_Event_BAO_Event::sendMail($contactId, $this->_values, $participantID, $isTest);
         }
     }
 }
Exemple #15
0
 /** 
  * Function to build the form 
  * 
  * @return None 
  * @access public 
  */
 static function buildQuickForm(&$form)
 {
     if ($form->_eventId) {
         $form->_isPaidEvent = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $form->_eventId, 'is_monetary');
         if ($form->_isPaidEvent) {
             $form->addElement('hidden', 'hidden_feeblock', 1);
         }
         // make sure this is for backoffice registration.
         if ($form->getName() == 'Participant') {
             require_once "CRM/Event/BAO/Participant.php";
             $eventfullMsg = CRM_Event_BAO_Participant::eventFullMessage($form->_eventId, $form->_pId);
             $form->addElement('hidden', 'hidden_eventFullMsg', $eventfullMsg, array('id' => 'hidden_eventFullMsg'));
         }
     }
     if ($form->_pId) {
         if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $form->_pId, 'contribution_id', 'participant_id')) {
             $form->_online = true;
         }
     }
     if ($form->_isPaidEvent) {
         require_once "CRM/Event/BAO/Event.php";
         $params = array('id' => $form->_eventId);
         CRM_Event_BAO_Event::retrieve($params, $event);
         //retrieve custom information
         $form->_values = array();
         require_once "CRM/Event/Form/Registration/Register.php";
         CRM_Event_Form_Registration::initPriceSet($form, $event['id']);
         CRM_Event_Form_Registration_Register::buildAmount($form, true, $form->_discountId);
         $lineItem = array();
         if (!CRM_Utils_System::isNull(CRM_Utils_Array::value('line_items', $form->_values))) {
             $lineItem[] = $form->_values['line_items'];
         }
         $form->assign('lineItem', empty($lineItem) ? false : $lineItem);
         $discounts = array();
         if (!empty($form->_values['discount'])) {
             foreach ($form->_values['discount'] as $key => $value) {
                 $discounts[$key] = $value['name'];
             }
             $element = $form->add('select', 'discount_id', ts('Discount Set'), array(0 => ts('- select -')) + $discounts, false, array('onchange' => "buildFeeBlock( {$form->_eventId}, this.value );"));
             if ($form->_online) {
                 $element->freeze();
             }
         }
         if ($form->_mode) {
             require_once 'CRM/Core/Payment/Form.php';
             CRM_Core_Payment_Form::buildCreditCard($form, true);
         } else {
             if (!$form->_mode) {
                 $form->addElement('checkbox', 'record_contribution', ts('Record Payment?'), null, array('onclick' => "return showHideByValue('record_contribution','','payment_information','table-row','radio',false);"));
                 require_once 'CRM/Contribute/PseudoConstant.php';
                 $form->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType());
                 $form->addDate('receive_date', ts('Received'), false, array('formatType' => 'activityDate'));
                 $form->add('select', 'payment_instrument_id', ts('Paid By'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), false, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
                 // don't show transaction id in batch update mode
                 $path = CRM_Utils_System::currentPath();
                 $form->assign('showTransactionId', false);
                 if ($path != 'civicrm/contact/search/basic') {
                     $form->add('text', 'trxn_id', ts('Transaction ID'));
                     $form->addRule('trxn_id', ts('Transaction ID already exists in Database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $form->_eventId, 'trxn_id'));
                     $form->assign('showTransactionId', true);
                 }
                 $allowStatuses = array();
                 $statuses = CRM_Contribute_PseudoConstant::contributionStatus();
                 if ($form->get('onlinePendingContributionId')) {
                     $statusNames = CRM_Contribute_PseudoConstant::contributionStatus(null, 'name');
                     foreach ($statusNames as $val => $name) {
                         if (in_array($name, array('In Progress', 'Overdue'))) {
                             continue;
                         }
                         $allowStatuses[$val] = $statuses[$val];
                     }
                 } else {
                     $allowStatuses = $statuses;
                 }
                 $form->add('select', 'contribution_status_id', ts('Payment Status'), $allowStatuses);
                 $form->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number'));
             }
         }
     } else {
         $form->add('text', 'amount', ts('Event Fee(s)'));
     }
     $form->assign('onlinePendingContributionId', $form->get('onlinePendingContributionId'));
     $form->assign("paid", $form->_isPaidEvent);
     $form->addElement('checkbox', 'send_receipt', ts('Send Confirmation?'), null, array('onclick' => "return showHideByValue('send_receipt','','notice','table-row','radio',false);"));
     $form->add('textarea', 'receipt_text', ts('Confirmation Message'));
     // Retrieve the name and email of the contact - form will be the TO for receipt email ( only if context is not standalone)
     if ($form->_context != 'standalone') {
         if ($form->_contactID) {
             list($form->_contributorDisplayName, $form->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($form->_contactID);
             $form->assign('email', $form->_contributorEmail);
         } else {
             //show email block for batch update for event
             $form->assign('batchEmail', true);
         }
     }
     require_once "CRM/Core/BAO/Preferences.php";
     $mailingInfo =& CRM_Core_BAO_Preferences::mailingPreferences();
     $form->assign('outBound_option', $mailingInfo['outBound_option']);
 }
 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     if ($this->_action & CRM_Core_Action::DELETE) {
         if (CRM_Utils_Array::value('delete_participant', $params) == 2) {
             $additionalId = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_id);
             $participantLinks = CRM_Event_BAO_Participant::getAdditionalParticipantUrl($additionalId);
         }
         if (CRM_Utils_Array::value('delete_participant', $params) == 1) {
             $additionalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_id);
             foreach ($additionalIds as $value) {
                 CRM_Event_BAO_Participant::deleteParticipant($value);
             }
         }
         CRM_Event_BAO_Participant::deleteParticipant($this->_id);
         CRM_Core_Session::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success');
         if (!empty($participantLinks)) {
             $status = ts('The following participants no longer have an event fee recorded. You can edit their registration and record a replacement contribution by clicking the links below:') . '<br/>' . $participantLinks;
             CRM_Core_Session::setStatus($status, ts('Group Payment Deleted'));
         }
         return;
     }
     // When adding a single contact, the formRule prevents you from adding duplicates
     // (See above in formRule()). When adding more than one contact, the duplicates are
     // removed automatically and the user receives one notification.
     if ($this->_action & CRM_Core_Action::ADD) {
         $event_id = $this->_eventId;
         if (empty($event_id) && !empty($params['event_id'])) {
             $event_id = $params['event_id'];
         }
         if (!$this->_single && !empty($event_id)) {
             $duplicateContacts = 0;
             while (list($k, $dupeCheckContactId) = each($this->_contactIds)) {
                 // Eliminate contacts that have already been assigned to this event.
                 $dupeCheck = new CRM_Event_BAO_Participant();
                 $dupeCheck->contact_id = $dupeCheckContactId;
                 $dupeCheck->event_id = $event_id;
                 $dupeCheck->find(TRUE);
                 if (!empty($dupeCheck->id)) {
                     $duplicateContacts++;
                     unset($this->_contactIds[$k]);
                 }
             }
             if ($duplicateContacts > 0) {
                 $msg = ts("%1 contacts have already been assigned to this event. They were not added a second time.", array(1 => $duplicateContacts));
                 CRM_Core_Session::setStatus($msg);
             }
             if (count($this->_contactIds) == 0) {
                 CRM_Core_Session::setStatus(ts("No participants were added."));
                 return;
             }
             // We have to re-key $this->_contactIds so each contact has the same
             // key as their corresponding record in the $participants array that
             // will be created below.
             $this->_contactIds = array_values($this->_contactIds);
         }
     }
     $participantStatus = CRM_Event_PseudoConstant::participantStatus();
     // set the contact, when contact is selected
     if (!empty($params['contact_id'])) {
         $this->_contactId = $params['contact_id'];
     }
     if ($this->_priceSetId && ($isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config'))) {
         $this->_quickConfig = $isQuickConfig;
     }
     if ($this->_id) {
         $params['id'] = $this->_id;
     }
     $config = CRM_Core_Config::singleton();
     if ($this->_isPaidEvent) {
         $contributionParams = array();
         $lineItem = array();
         $additionalParticipantDetails = array();
         if (CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled')) {
             $eventStartDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eventId, 'start_date');
             if ($eventStartDate) {
                 $contributionParams['revenue_recognition_date'] = date('Ymd', strtotime($eventStartDate));
             }
         }
         if ($this->_id && $this->_action & CRM_Core_Action::UPDATE && $this->_paymentId) {
             $participantBAO = new CRM_Event_BAO_Participant();
             $participantBAO->id = $this->_id;
             $participantBAO->find(TRUE);
             $contributionParams['total_amount'] = $participantBAO->fee_amount;
             $params['discount_id'] = NULL;
             //re-enter the values for UPDATE mode
             $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level;
             $params['fee_amount'] = $participantBAO->fee_amount;
             if (isset($params['priceSetId'])) {
                 $lineItem[0] = CRM_Price_BAO_LineItem::getLineItems($this->_id);
             }
             //also add additional participant's fee level/priceset
             if (CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) {
                 $additionalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_id);
                 $hasLineItems = CRM_Utils_Array::value('priceSetId', $params, FALSE);
                 $additionalParticipantDetails = CRM_Event_BAO_Participant::getFeeDetails($additionalIds, $hasLineItems);
             }
         } else {
             //check if discount is selected
             if (!empty($params['discount_id'])) {
                 $discountId = $params['discount_id'];
             } else {
                 $discountId = $params['discount_id'] = 'null';
             }
             //lets carry currency, CRM-4453
             $params['fee_currency'] = $config->defaultCurrency;
             CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem[0]);
             //CRM-11529 for quick config backoffice transactions
             //when financial_type_id is passed in form, update the
             //lineitems with the financial type selected in form
             $submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $params);
             $isPaymentRecorded = CRM_Utils_Array::value('record_contribution', $params);
             if ($isPaymentRecorded && $this->_quickConfig && $submittedFinancialType) {
                 foreach ($lineItem[0] as &$values) {
                     $values['financial_type_id'] = $submittedFinancialType;
                 }
             }
             $params['fee_level'] = $params['amount_level'];
             $contributionParams['total_amount'] = $params['amount'];
             if ($this->_quickConfig && !empty($params['total_amount']) && $params['status_id'] != array_search('Partially paid', $participantStatus)) {
                 $params['fee_amount'] = $params['total_amount'];
             } else {
                 //fix for CRM-3086
                 $params['fee_amount'] = $params['amount'];
             }
         }
         if (isset($params['priceSetId'])) {
             if (!empty($lineItem[0])) {
                 $this->set('lineItem', $lineItem);
                 $this->_lineItem = $lineItem;
                 $lineItem = array_merge($lineItem, $additionalParticipantDetails);
                 $participantCount = array();
                 foreach ($lineItem as $k) {
                     foreach ($k as $v) {
                         if (CRM_Utils_Array::value('participant_count', $v) > 0) {
                             $participantCount[] = $v['participant_count'];
                         }
                     }
                 }
             }
             if (isset($participantCount)) {
                 $this->assign('pricesetFieldsCount', $participantCount);
             }
             $this->assign('lineItem', empty($lineItem[0]) || $this->_quickConfig ? FALSE : $lineItem);
         } else {
             $this->assign('amount_level', $params['amount_level']);
         }
     }
     $this->_params = $params;
     $amountOwed = NULL;
     if (isset($params['amount'])) {
         $amountOwed = $params['amount'];
         unset($params['amount']);
     }
     $params['register_date'] = CRM_Utils_Date::processDate($params['register_date'], $params['register_date_time']);
     $params['receive_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $params), CRM_Utils_Array::value('receive_date_time', $params));
     $params['contact_id'] = $this->_contactId;
     // overwrite actual payment amount if entered
     if (!empty($params['total_amount'])) {
         $contributionParams['total_amount'] = CRM_Utils_Array::value('total_amount', $params);
     }
     // Retrieve the name and email of the current user - this will be the FROM for the receipt email
     $userName = CRM_Core_Session::singleton()->getLoggedInContactDisplayName();
     if ($this->_contactId) {
         list($this->_contributorDisplayName, $this->_contributorEmail, $this->_toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($this->_contactId);
     }
     //modify params according to parameter used in create
     //participant method (addParticipant)
     $this->_params['participant_status_id'] = $params['status_id'];
     $this->_params['participant_role_id'] = is_array($params['role_id']) ? $params['role_id'] : explode(',', $params['role_id']);
     $this->_params['participant_register_date'] = $params['register_date'];
     $roleIdWithSeparator = implode(CRM_Core_DAO::VALUE_SEPARATOR, $this->_params['participant_role_id']);
     if ($this->_mode) {
         if (!$this->_isPaidEvent) {
             CRM_Core_Error::fatal(ts('Selected Event is not Paid Event '));
         }
         $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'title');
         // set source if not set
         if (empty($params['source'])) {
             $this->_params['participant_source'] = ts('Offline Registration for Event: %2 by: %1', array(1 => $userName, 2 => $eventTitle));
         } else {
             $this->_params['participant_source'] = $params['source'];
         }
         $this->_params['description'] = $this->_params['participant_source'];
         $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($this->_params['payment_processor_id'], $this->_mode);
         $now = date('YmdHis');
         $fields = array();
         // set email for primary location.
         $fields['email-Primary'] = 1;
         $params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail;
         $params['register_date'] = $now;
         // now set the values for the billing location.
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
         // also add location name to the array
         $params["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params);
         $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
         $fields["address_name-{$this->_bltID}"] = 1;
         $fields["email-{$this->_bltID}"] = 1;
         $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'contact_type');
         $nameFields = array('first_name', 'middle_name', 'last_name');
         foreach ($nameFields as $name) {
             $fields[$name] = 1;
             if (array_key_exists("billing_{$name}", $params)) {
                 $params[$name] = $params["billing_{$name}"];
                 $params['preserveDBName'] = TRUE;
             }
         }
         $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $this->_contactId, NULL, NULL, $ctype);
     }
     if (!empty($this->_params['participant_role_id'])) {
         $customFieldsRole = array();
         foreach ($this->_params['participant_role_id'] as $roleKey) {
             $customFieldsRole = CRM_Utils_Array::crmArrayMerge(CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, $roleKey, $this->_roleCustomDataTypeID), $customFieldsRole);
         }
         $customFieldsEvent = CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, CRM_Utils_Array::value('event_id', $params), $this->_eventNameCustomDataTypeID);
         $customFieldsEventType = CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, $this->_eventTypeId, $this->_eventTypeCustomDataTypeID);
         $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsRole, CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE));
         $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEvent, $customFields);
         $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEventType, $customFields);
         $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->_id, 'Participant');
     }
     //do cleanup line  items if participant edit the Event Fee.
     if (($this->_lineItem || !isset($params['proceSetId'])) && !$this->_paymentId && $this->_id) {
         CRM_Price_BAO_LineItem::deleteLineItems($this->_id, 'civicrm_participant');
     }
     if ($this->_mode) {
         // add all the additional payment params we need
         $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
         $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
         $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
         $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
         $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
         $this->_params['amount'] = $params['fee_amount'];
         $this->_params['amount_level'] = $params['amount_level'];
         $this->_params['currencyID'] = $config->defaultCurrency;
         $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
         // at this point we've created a contact and stored its address etc
         // all the payment processors expect the name and address to be in the
         // so we copy stuff over to first_name etc.
         $paymentParams = $this->_params;
         if (!empty($this->_params['send_receipt'])) {
             $paymentParams['email'] = $this->_contributorEmail;
         }
         // The only reason for merging in the 'contact_id' rather than ensuring it is set
         // is that this patch is being done around the time of the stable release
         // so more conservative approach is called for.
         // In fact the use of $params and $this->_params & $this->_contactId vs $contactID
         // needs rationalising.
         $mapParams = array_merge(array('contact_id' => $contactID), $this->_params);
         CRM_Core_Payment_Form::mapParams($this->_bltID, $mapParams, $paymentParams, TRUE);
         $payment = $this->_paymentProcessor['object'];
         // CRM-15622: fix for incorrect contribution.fee_amount
         $paymentParams['fee_amount'] = NULL;
         $result = $payment->doPayment($paymentParams);
         if (is_a($result, 'CRM_Core_Error')) {
             CRM_Core_Error::displaySessionError($result);
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/participant', "reset=1&action=add&cid={$this->_contactId}&context=participant&mode={$this->_mode}"));
         }
         if ($result) {
             $this->_params = array_merge($this->_params, $result);
         }
         $this->_params['receive_date'] = $now;
         if (!empty($this->_params['send_receipt'])) {
             $this->_params['receipt_date'] = $now;
         } else {
             $this->_params['receipt_date'] = NULL;
         }
         $this->set('params', $this->_params);
         $this->assign('trxn_id', $result['trxn_id']);
         $this->assign('receive_date', CRM_Utils_Date::processDate($this->_params['receive_date']));
         //add contribution record
         $this->_params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
         $this->_params['mode'] = $this->_mode;
         //add contribution record
         $contributions[] = $contribution = CRM_Event_Form_Registration_Confirm::processContribution($this, $this->_params, $result, $contactID, FALSE);
         // add participant record
         $participants = array();
         if (!empty($this->_params['role_id']) && is_array($this->_params['role_id'])) {
             $this->_params['role_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $this->_params['role_id']);
         }
         //CRM-15372 patch to fix fee amount replacing amount
         $this->_params['fee_amount'] = $this->_params['amount'];
         $participants[] = CRM_Event_Form_Registration::addParticipant($this, $contactID);
         //add custom data for participant
         CRM_Core_BAO_CustomValueTable::postProcess($this->_params, 'civicrm_participant', $participants[0]->id, 'Participant');
         //add participant payment
         $paymentParticipant = array('participant_id' => $participants[0]->id, 'contribution_id' => $contribution->id);
         $ids = array();
         CRM_Event_BAO_ParticipantPayment::create($paymentParticipant, $ids);
         $this->_contactIds[] = $this->_contactId;
     } else {
         $participants = array();
         if ($this->_single) {
             if ($params['role_id']) {
                 $params['role_id'] = $roleIdWithSeparator;
             } else {
                 $params['role_id'] = 'NULL';
             }
             $participants[] = CRM_Event_BAO_Participant::create($params);
         } else {
             foreach ($this->_contactIds as $contactID) {
                 $commonParams = $params;
                 $commonParams['contact_id'] = $contactID;
                 if ($commonParams['role_id']) {
                     $commonParams['role_id'] = $commonParams['role_id'] = str_replace(',', CRM_Core_DAO::VALUE_SEPARATOR, $params['role_id']);
                 } else {
                     $commonParams['role_id'] = 'NULL';
                 }
                 $participants[] = CRM_Event_BAO_Participant::create($commonParams);
             }
         }
         if (isset($params['event_id'])) {
             $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'title');
         }
         if ($this->_single) {
             $this->_contactIds[] = $this->_contactId;
         }
         $contributions = array();
         if (!empty($params['record_contribution'])) {
             if (!empty($params['id'])) {
                 if ($this->_onlinePendingContributionId) {
                     $ids['contribution'] = $this->_onlinePendingContributionId;
                 } else {
                     $ids['contribution'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $params['id'], 'contribution_id', 'participant_id');
                 }
             }
             unset($params['note']);
             //build contribution params
             if (!$this->_onlinePendingContributionId) {
                 if (empty($params['source'])) {
                     $contributionParams['source'] = ts('%1 : Offline registration (by %2)', array(1 => $eventTitle, 2 => $userName));
                 } else {
                     $contributionParams['source'] = $params['source'];
                 }
             }
             $contributionParams['currency'] = $config->defaultCurrency;
             $contributionParams['non_deductible_amount'] = 'null';
             $contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array::value('receive_date', $params) : 'null';
             $recordContribution = array('contact_id', 'financial_type_id', 'payment_instrument_id', 'trxn_id', 'contribution_status_id', 'receive_date', 'check_number', 'campaign_id');
             foreach ($recordContribution as $f) {
                 $contributionParams[$f] = CRM_Utils_Array::value($f, $params);
                 if ($f == 'trxn_id') {
                     $this->assign('trxn_id', $contributionParams[$f]);
                 }
             }
             //insert financial type name in receipt.
             $this->assign('financialTypeName', CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id']));
             // legacy support
             $this->assign('contributionTypeName', CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id']));
             $contributionParams['skipLineItem'] = 1;
             if ($this->_id) {
                 $contributionParams['contribution_mode'] = 'participant';
                 $contributionParams['participant_id'] = $this->_id;
             }
             // Set is_pay_later flag for back-office offline Pending status contributions
             if ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup::getValue('contribution_status', 'Pending', 'name')) {
                 $contributionParams['is_pay_later'] = 1;
             } elseif ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name')) {
                 $contributionParams['is_pay_later'] = 0;
             }
             if ($params['status_id'] == array_search('Partially paid', $participantStatus)) {
                 if (!$amountOwed && $this->_action & CRM_Core_Action::UPDATE) {
                     $amountOwed = $params['fee_amount'];
                 }
                 // if multiple participants are link, consider contribution total amount as the amount Owed
                 if ($this->_id && CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) {
                     $amountOwed = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $ids['contribution'], 'total_amount');
                 }
                 // CRM-13964 partial_payment_total
                 if ($amountOwed > $params['total_amount']) {
                     // the owed amount
                     $contributionParams['partial_payment_total'] = $amountOwed;
                     // the actual amount paid
                     $contributionParams['partial_amount_pay'] = $params['total_amount'];
                 }
             }
             if (CRM_Utils_Array::value('tax_amount', $this->_params)) {
                 $contributionParams['tax_amount'] = $this->_params['tax_amount'];
             }
             if ($this->_single) {
                 if (empty($ids)) {
                     $ids = array();
                 }
                 $contributions[] = CRM_Contribute_BAO_Contribution::create($contributionParams, $ids);
             } else {
                 $ids = array();
                 foreach ($this->_contactIds as $contactID) {
                     $contributionParams['contact_id'] = $contactID;
                     $contributions[] = CRM_Contribute_BAO_Contribution::create($contributionParams, $ids);
                 }
             }
             //insert payment record for this participation
             if (empty($ids['contribution'])) {
                 foreach ($this->_contactIds as $num => $contactID) {
                     $ppDAO = new CRM_Event_DAO_ParticipantPayment();
                     $ppDAO->participant_id = $participants[$num]->id;
                     $ppDAO->contribution_id = $contributions[$num]->id;
                     $ppDAO->save();
                 }
             }
             // next create the transaction record
             $transaction = new CRM_Core_Transaction();
             // CRM-11124
             if ($this->_params['discount_id']) {
                 CRM_Event_BAO_Participant::createDiscountTrxn($this->_eventId, $contributionParams, NULL, CRM_Price_BAO_PriceSet::parseFirstPriceSetValueIDFromParams($this->_params));
             }
             $transaction->commit();
         }
     }
     // also store lineitem stuff here
     if ($this->_lineItem & $this->_action & CRM_Core_Action::ADD || $this->_lineItem && CRM_Core_Action::UPDATE && !$this->_paymentId) {
         foreach ($this->_contactIds as $num => $contactID) {
             foreach ($this->_lineItem as $key => $value) {
                 if (is_array($value) && $value != 'skip') {
                     foreach ($value as $lineKey => $line) {
                         //10117 update the line items for participants if contribution amount is recorded
                         if ($this->_quickConfig && !empty($params['total_amount']) && $params['status_id'] != array_search('Partially paid', $participantStatus)) {
                             $line['unit_price'] = $line['line_total'] = $params['total_amount'];
                             if (!empty($params['tax_amount'])) {
                                 $line['unit_price'] = $line['unit_price'] - $params['tax_amount'];
                                 $line['line_total'] = $line['line_total'] - $params['tax_amount'];
                             }
                         }
                         $lineItem[$this->_priceSetId][$lineKey] = $line;
                     }
                     CRM_Price_BAO_LineItem::processPriceSet($participants[$num]->id, $lineItem, CRM_Utils_Array::value($num, $contributions, NULL), 'civicrm_participant');
                     CRM_Contribute_BAO_Contribution::addPayments($value, $contributions);
                 }
             }
         }
     }
     $updateStatusMsg = NULL;
     //send mail when participant status changed, CRM-4326
     if ($this->_id && $this->_statusId && $this->_statusId != CRM_Utils_Array::value('status_id', $params) && !empty($params['is_notify'])) {
         $updateStatusMsg = CRM_Event_BAO_Participant::updateStatusMessage($this->_id, $params['status_id'], $this->_statusId);
     }
     $sent = array();
     $notSent = array();
     if (!empty($params['send_receipt'])) {
         if (array_key_exists($params['from_email_address'], $this->_fromEmails['from_email_id'])) {
             $receiptFrom = $params['from_email_address'];
         }
         $this->assign('module', 'Event Registration');
         //use of the message template below requires variables in different format
         $event = $events = array();
         $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
         //get all event details.
         CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
         $event = $events[$params['event_id']];
         unset($event['start_date']);
         unset($event['end_date']);
         $role = CRM_Event_PseudoConstant::participantRole();
         $participantRoles = CRM_Utils_Array::value('role_id', $params);
         if (is_array($participantRoles)) {
             $selectedRoles = array();
             foreach ($participantRoles as $roleId) {
                 $selectedRoles[] = $role[$roleId];
             }
             $event['participant_role'] = implode(', ', $selectedRoles);
         } else {
             $event['participant_role'] = CRM_Utils_Array::value($participantRoles, $role);
         }
         $event['is_monetary'] = $this->_isPaidEvent;
         if ($params['receipt_text']) {
             $event['confirm_email_text'] = $params['receipt_text'];
         }
         $this->assign('isAmountzero', 1);
         $this->assign('event', $event);
         $this->assign('isShowLocation', $event['is_show_location']);
         if (CRM_Utils_Array::value('is_show_location', $event) == 1) {
             $locationParams = array('entity_id' => $params['event_id'], 'entity_table' => 'civicrm_event');
             $location = CRM_Core_BAO_Location::getValues($locationParams, TRUE);
             $this->assign('location', $location);
         }
         $status = CRM_Event_PseudoConstant::participantStatus();
         if ($this->_isPaidEvent) {
             $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
             if (!$this->_mode) {
                 if (isset($params['payment_instrument_id'])) {
                     $this->assign('paidBy', CRM_Utils_Array::value($params['payment_instrument_id'], $paymentInstrument));
                 }
             }
             $this->assign('totalAmount', $contributionParams['total_amount']);
             if (isset($contributionParams['partial_payment_total'])) {
                 // balance amount
                 $balanceAmount = $contributionParams['partial_payment_total'] - $contributionParams['partial_amount_pay'];
                 $this->assign('balanceAmount', $balanceAmount);
             }
             $this->assign('isPrimary', 1);
             $this->assign('checkNumber', CRM_Utils_Array::value('check_number', $params));
         }
         if ($this->_mode) {
             if (!empty($params['billing_first_name'])) {
                 $name = $params['billing_first_name'];
             }
             if (!empty($params['billing_middle_name'])) {
                 $name .= " {$params['billing_middle_name']}";
             }
             if (!empty($params['billing_last_name'])) {
                 $name .= " {$params['billing_last_name']}";
             }
             $this->assign('billingName', $name);
             // assign the address formatted up for display
             $addressParts = array("street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "state_province-{$this->_bltID}", "country-{$this->_bltID}");
             $addressFields = array();
             foreach ($addressParts as $part) {
                 list($n, $id) = explode('-', $part);
                 if (isset($this->_params['billing_' . $part])) {
                     $addressFields[$n] = $this->_params['billing_' . $part];
                 }
             }
             $this->assign('address', CRM_Utils_Address::format($addressFields));
             $date = CRM_Utils_Date::format($params['credit_card_exp_date']);
             $date = CRM_Utils_Date::mysqlToIso($date);
             $this->assign('credit_card_exp_date', $date);
             $this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($params['credit_card_number']));
             $this->assign('credit_card_type', $params['credit_card_type']);
             // The concept of contributeMode is deprecated.
             $this->assign('contributeMode', 'direct');
             $this->assign('isAmountzero', 0);
             $this->assign('is_pay_later', 0);
             $this->assign('isPrimary', 1);
         }
         $this->assign('register_date', $params['register_date']);
         if ($params['receive_date']) {
             $this->assign('receive_date', $params['receive_date']);
         }
         $participant = array(array('participant_id', '=', $participants[0]->id, 0, 0));
         // check whether its a test drive ref CRM-3075
         if (!empty($this->_defaultValues['is_test'])) {
             $participant[] = array('participant_test', '=', 1, 0, 0);
         }
         $template = CRM_Core_Smarty::singleton();
         $customGroup = array();
         //format submitted data
         foreach ($params['custom'] as $fieldID => $values) {
             foreach ($values as $fieldValue) {
                 $customFields[$fieldID]['id'] = $fieldID;
                 $formattedValue = CRM_Core_BAO_CustomField::displayValue($fieldValue['value'], $fieldID, $participants[0]->id);
                 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace('&nbsp;', '', $formattedValue);
             }
         }
         foreach ($this->_contactIds as $num => $contactID) {
             // Retrieve the name and email of the contact - this will be the TO for receipt email
             list($this->_contributorDisplayName, $this->_contributorEmail, $this->_toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($contactID);
             $this->_contributorDisplayName = $this->_contributorDisplayName == ' ' ? $this->_contributorEmail : $this->_contributorDisplayName;
             $waitStatus = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'");
             if ($waitingStatus = CRM_Utils_Array::value($params['status_id'], $waitStatus)) {
                 $this->assign('isOnWaitlist', TRUE);
             }
             $this->assign('customGroup', $customGroup);
             $this->assign('contactID', $contactID);
             $this->assign('participantID', $participants[$num]->id);
             $this->_id = $participants[$num]->id;
             if ($this->_isPaidEvent) {
                 // fix amount for each of participants ( for bulk mode )
                 $eventAmount = array();
                 $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
                 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
                 $totalTaxAmount = 0;
                 //add dataArray in the receipts in ADD and UPDATE condition
                 $dataArray = array();
                 if ($this->_action & CRM_Core_Action::ADD) {
                     $line = $lineItem[0];
                 } elseif ($this->_action & CRM_Core_Action::UPDATE) {
                     $line = $this->_values['line_items'];
                 }
                 if ($invoicing) {
                     foreach ($line as $key => $value) {
                         if (isset($value['tax_amount'])) {
                             $totalTaxAmount += $value['tax_amount'];
                             if (isset($dataArray[(string) $value['tax_rate']])) {
                                 $dataArray[(string) $value['tax_rate']] = $dataArray[(string) $value['tax_rate']] + CRM_Utils_Array::value('tax_amount', $value);
                             } else {
                                 $dataArray[(string) $value['tax_rate']] = CRM_Utils_Array::value('tax_amount', $value);
                             }
                         }
                     }
                     $this->assign('totalTaxAmount', $totalTaxAmount);
                     $this->assign('taxTerm', CRM_Utils_Array::value('tax_term', $invoiceSettings));
                     $this->assign('dataArray', $dataArray);
                 }
                 if (!empty($additionalParticipantDetails)) {
                     $params['amount_level'] = preg_replace('//', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName;
                 }
                 $eventAmount[$num] = array('label' => preg_replace('//', '', $params['amount_level']), 'amount' => $params['fee_amount']);
                 //as we are using same template for online & offline registration.
                 //So we have to build amount as array.
                 $eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
                 $this->assign('amount', $eventAmount);
             }
             $sendTemplateParams = array('groupName' => 'msg_tpl_workflow_event', 'valueName' => 'event_offline_receipt', 'contactId' => $contactID, 'isTest' => !empty($this->_defaultValues['is_test']), 'PDFFilename' => ts('confirmation') . '.pdf');
             // try to send emails only if email id is present
             // and the do-not-email option is not checked for that contact
             if ($this->_contributorEmail and !$this->_toDoNotEmail) {
                 $sendTemplateParams['from'] = $receiptFrom;
                 $sendTemplateParams['toName'] = $this->_contributorDisplayName;
                 $sendTemplateParams['toEmail'] = $this->_contributorEmail;
                 $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc', $this->_fromEmails);
                 $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc', $this->_fromEmails);
             }
             //send email with pdf invoice
             $template = CRM_Core_Smarty::singleton();
             $taxAmt = $template->get_template_vars('dataArray');
             $contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id');
             $prefixValue = Civi::settings()->get('contribution_invoice_settings');
             $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue);
             if (count($taxAmt) > 0 && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
                 $sendTemplateParams['isEmailPdf'] = TRUE;
                 $sendTemplateParams['contributionId'] = $contributionId;
             }
             list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
             if ($mailSent) {
                 $sent[] = $contactID;
                 foreach ($participants as $ids => $values) {
                     if ($values->contact_id == $contactID) {
                         $values->details = CRM_Utils_Array::value('receipt_text', $params);
                         CRM_Activity_BAO_Activity::addActivity($values, 'Email');
                         break;
                     }
                 }
             } else {
                 $notSent[] = $contactID;
             }
         }
     }
     // set the participant id if it is not set
     if (!$this->_id) {
         $this->_id = $participants[0]->id;
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contributorDisplayName));
         if (!empty($params['send_receipt']) && count($sent)) {
             $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', array(1 => $this->_contributorEmail));
         }
         if ($updateStatusMsg) {
             $statusMsg = "{$statusMsg} {$updateStatusMsg}";
         }
     } elseif ($this->_action & CRM_Core_Action::ADD) {
         if ($this->_single) {
             $statusMsg = ts('Event registration for %1 has been added.', array(1 => $this->_contributorDisplayName));
             if (!empty($params['send_receipt']) && count($sent)) {
                 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $this->_contributorEmail));
             }
         } else {
             $statusMsg = ts('Total Participant(s) added to event: %1.', array(1 => count($this->_contactIds)));
             if (count($notSent) > 0) {
                 $statusMsg .= ' ' . ts('Email has NOT been sent to %1 contact(s) - communication preferences specify DO NOT EMAIL OR valid Email is NOT present. ', array(1 => count($notSent)));
             } elseif (isset($params['send_receipt'])) {
                 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');
             }
         }
     }
     CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success');
     $session = CRM_Core_Session::singleton();
     $buttonName = $this->controller->getButtonName();
     if ($this->_context == 'standalone') {
         if ($buttonName == $this->getButtonName('upload', 'new')) {
             $urlParams = 'reset=1&action=add&context=standalone';
             if ($this->_mode) {
                 $urlParams .= '&mode=' . $this->_mode;
             }
             if ($this->_eID) {
                 $urlParams .= '&eid=' . $this->_eID;
             }
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/participant/add', $urlParams));
         } else {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactId}&selectedChild=participant"));
         }
     } elseif ($buttonName == $this->getButtonName('upload', 'new')) {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/participant', "reset=1&action=add&context={$this->_context}&cid={$this->_contactId}"));
     }
 }
Exemple #17
0
 /**
  * Handle process after the confirmation of payment by User.
  *
  * @param int $contactID
  * @param null $contribution
  * @param null $payment
  */
 public function confirmPostProcess($contactID = NULL, $contribution = NULL, $payment = NULL)
 {
     // add/update contact information
     $fields = array();
     unset($this->_params['note']);
     //to avoid conflict overwrite $this->_params
     $this->_params = $this->get('value');
     //get the amount of primary participant
     if (!empty($this->_params['is_primary'])) {
         $this->_params['fee_amount'] = $this->get('primaryParticipantAmount');
     }
     // add participant record
     $participant = CRM_Event_Form_Registration::addParticipant($this, $contactID);
     $this->_participantIDS[] = $participant->id;
     //setting register_by_id field and primaryContactId
     if (!empty($this->_params['is_primary'])) {
         $this->set('registerByID', $participant->id);
         $this->set('primaryContactId', $contactID);
         // CRM-10032
         $this->processFirstParticipant($participant->id);
     }
     CRM_Core_BAO_CustomValueTable::postProcess($this->_params, 'civicrm_participant', $participant->id, 'Participant');
     $createPayment = CRM_Utils_Array::value('amount', $this->_params, 0) != 0 ? TRUE : FALSE;
     // force to create zero amount payment, CRM-5095
     // we know the amout is zero since createPayment is false
     if (!$createPayment && (isset($contribution) && $contribution->id) && $this->_priceSetId && $this->_lineItem) {
         $createPayment = TRUE;
     }
     if ($createPayment && $this->_values['event']['is_monetary'] && !empty($this->_params['contributionID'])) {
         $paymentParams = array('participant_id' => $participant->id, 'contribution_id' => $contribution->id);
         $ids = array();
         $paymentPartcipant = CRM_Event_BAO_ParticipantPayment::create($paymentParams, $ids);
     }
     //set only primary participant's params for transfer checkout.
     // The concept of contributeMode is deprecated.
     if (($this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify') && !empty($this->_params['is_primary'])) {
         $this->_params['participantID'] = $participant->id;
         $this->set('primaryParticipant', $this->_params);
     }
     $this->assign('action', $this->_action);
     // create CMS user
     if (!empty($this->_params['cms_create_account'])) {
         $this->_params['contactID'] = $contactID;
         if (array_key_exists('email-5', $this->_params)) {
             $mail = 'email-5';
         } else {
             foreach ($this->_params as $name => $dontCare) {
                 if (substr($name, 0, 5) == 'email') {
                     $mail = $name;
                     break;
                 }
             }
         }
         // we should use primary email for
         // 1. free event registration.
         // 2. pay later participant.
         // 3. waiting list participant.
         // 4. require approval participant.
         if (!empty($this->_params['is_pay_later']) || $this->_allowWaitlist || $this->_requireApproval || empty($this->_values['event']['is_monetary'])) {
             $mail = 'email-Primary';
         }
         if (!CRM_Core_BAO_CMSUser::create($this->_params, $mail)) {
             CRM_Core_Error::statusBounce(ts('Your profile is not saved and Account is not created.'));
         }
     }
 }
Exemple #18
0
 /**
  * Set variables up before form is built.
  *
  * @return void
  */
 public function preProcess()
 {
     parent::preProcess();
     // lineItem isn't set until Register postProcess
     $this->_lineItem = $this->get('lineItem');
     $this->_params = $this->get('params');
     $this->_params[0]['tax_amount'] = $this->get('tax_amount');
     $this->_params[0]['is_pay_later'] = $this->get('is_pay_later');
     $this->assign('is_pay_later', $this->_params[0]['is_pay_later']);
     if ($this->_params[0]['is_pay_later']) {
         $this->assign('pay_later_receipt', $this->_values['event']['pay_later_receipt']);
     }
     CRM_Utils_Hook::eventDiscount($this, $this->_params);
     if (!empty($this->_params[0]['discount']) && !empty($this->_params[0]['discount']['applied'])) {
         $this->set('hookDiscount', $this->_params[0]['discount']);
         $this->assign('hookDiscount', $this->_params[0]['discount']);
     }
     if ($this->_contributeMode == 'express') {
         $params = array();
         // rfp == redirect from paypal
         $rfp = CRM_Utils_Request::retrieve('rfp', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET');
         //we lost rfp in case of additional participant. So set it explicitly.
         if ($rfp || CRM_Utils_Array::value('additional_participants', $this->_params[0], FALSE)) {
             $payment = $this->_paymentProcessor['object'];
             $paymentObjError = ts('The system did not record payment details for this payment and so could not process the transaction. Please report this error to the site administrator.');
             if (is_object($payment)) {
                 $expressParams = $payment->getExpressCheckoutDetails($this->get('token'));
             } else {
                 CRM_Core_Error::fatal($paymentObjError);
             }
             $params['payer'] = CRM_Utils_Array::value('payer', $expressParams);
             $params['payer_id'] = $expressParams['payer_id'];
             $params['payer_status'] = $expressParams['payer_status'];
             CRM_Core_Payment_Form::mapParams($this->_bltID, $expressParams, $params, FALSE);
             // fix state and country id if present
             if (isset($params["billing_state_province_id-{$this->_bltID}"])) {
                 $params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($params["billing_state_province_id-{$this->_bltID}"]);
             }
             if (isset($params['billing_country_id'])) {
                 $params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($params["billing_country_id-{$this->_bltID}"]);
             }
             // set a few other parameters for PayPal
             $params['token'] = $this->get('token');
             $params['amount'] = $this->_params[0]['amount'];
             if (!empty($this->_params[0]['discount'])) {
                 $params['discount'] = $this->_params[0]['discount'];
                 $params['discountAmount'] = $this->_params[0]['discountAmount'];
                 $params['discountMessage'] = $this->_params[0]['discountMessage'];
             }
             if (!empty($this->_params[0]['amount_priceset_level_radio'])) {
                 $params['amount_priceset_level_radio'] = $this->_params[0]['amount_priceset_level_radio'];
             }
             $params['amount_level'] = $this->_params[0]['amount_level'];
             $params['currencyID'] = $this->_params[0]['currencyID'];
             // also merge all the other values from the profile fields
             $values = $this->controller->exportValues('Register');
             $skipFields = array('amount', "street_address-{$this->_bltID}", "city-{$this->_bltID}", "state_province_id-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}");
             foreach ($values as $name => $value) {
                 // skip amount field
                 if (!in_array($name, $skipFields)) {
                     $params[$name] = $value;
                 }
                 if (substr($name, 0, 6) == 'price_') {
                     $params[$name] = $this->_params[0][$name];
                 }
             }
             $this->set('getExpressCheckoutDetails', $params);
         } else {
             $params = $this->get('getExpressCheckoutDetails');
         }
         $this->_params[0] = $params;
         $this->_params[0]['is_primary'] = 1;
     } else {
         //process only primary participant params.
         $registerParams = $this->_params[0];
         if (isset($registerParams["billing_state_province_id-{$this->_bltID}"]) && $registerParams["billing_state_province_id-{$this->_bltID}"]) {
             $registerParams["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($registerParams["billing_state_province_id-{$this->_bltID}"]);
         }
         if (isset($registerParams["billing_country_id-{$this->_bltID}"]) && $registerParams["billing_country_id-{$this->_bltID}"]) {
             $registerParams["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($registerParams["billing_country_id-{$this->_bltID}"]);
         }
         if (isset($registerParams['credit_card_exp_date'])) {
             $registerParams['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($registerParams);
             $registerParams['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($registerParams);
         }
         if ($this->_values['event']['is_monetary']) {
             $registerParams['ip_address'] = CRM_Utils_System::ipAddress();
             $registerParams['currencyID'] = $this->_params[0]['currencyID'];
         }
         //assign back primary participant params.
         $this->_params[0] = $registerParams;
     }
     if ($this->_values['event']['is_monetary']) {
         $this->_params[0]['invoiceID'] = $this->get('invoiceID');
     }
     $this->assign('defaultRole', FALSE);
     if (CRM_Utils_Array::value('defaultRole', $this->_params[0]) == 1) {
         $this->assign('defaultRole', TRUE);
     }
     if (empty($this->_params[0]['participant_role_id']) && $this->_values['event']['default_role_id']) {
         $this->_params[0]['participant_role_id'] = $this->_values['event']['default_role_id'];
     }
     if (isset($this->_values['event']['confirm_title'])) {
         CRM_Utils_System::setTitle($this->_values['event']['confirm_title']);
     }
     if ($this->_pcpId) {
         $params = CRM_Contribute_Form_Contribution_Confirm::processPcp($this, $this->_params[0]);
         $this->_params[0] = $params;
     }
     $this->set('params', $this->_params);
 }