Example #1
0
 /**
  * create trxn entry if an event has discount.
  *
  * @param int $eventID
  *   Event id.
  * @param array $contributionParams
  *   Contribution params.
  *
  * @param string $feeLevel (deprecated)
  * @param int $discountedPriceFieldOptionID
  *   ID of the civicrm_price_field_value field for the discount id.
  */
 public static function createDiscountTrxn($eventID, $contributionParams, $feeLevel, $discountedPriceFieldOptionID)
 {
     $financialTypeID = $contributionParams['contribution']->financial_type_id;
     $total_amount = $contributionParams['total_amount'];
     $checkDiscount = CRM_Core_BAO_Discount::findSet($eventID, 'civicrm_event');
     if (!empty($checkDiscount)) {
         $mainAmount = self::getUnDiscountedAmountForEventPriceSetFieldValue($eventID, $discountedPriceFieldOptionID, $feeLevel);
         $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Discounts Account is' "));
         $transactionParams['from_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($financialTypeID, $relationTypeId);
         if (!empty($transactionParams['trxnParams']['from_financial_account_id'])) {
             $transactionParams['trxnParams']['total_amount'] = $mainAmount - $total_amount;
             $transactionParams['trxnParams']['payment_processor_id'] = NULL;
             $transactionParams['trxnParams']['payment_instrument_id'] = NULL;
             $transactionParams['trxnParams']['check_number'] = NULL;
             $transactionParams['trxnParams']['trxn_id'] = NULL;
             $transactionParams['trxnParams']['net_amount'] = NULL;
             $transactionParams['trxnParams']['fee_amount'] = NULL;
             CRM_Core_BAO_FinancialTrxn::create($transactionParams);
         }
     }
 }
Example #2
0
 /**
  * Process the participant.
  *
  * @param CRM_Core_Form $form
  * @param int $contactID
  *
  * @return \CRM_Event_BAO_Participant
  */
 public static function addParticipant(&$form, $contactID)
 {
     if (empty($form->_params)) {
         return NULL;
     }
     $params = $form->_params;
     $transaction = new CRM_Core_Transaction();
     $groupName = 'participant_role';
     $query = "\nSELECT  v.label as label ,v.value as value\nFROM   civicrm_option_value v,\n       civicrm_option_group g\nWHERE  v.option_group_id = g.id\n  AND  g.name            = %1\n  AND  v.is_active       = 1\n  AND  g.is_active       = 1\n";
     $p = array(1 => array($groupName, 'String'));
     $dao = CRM_Core_DAO::executeQuery($query, $p);
     if ($dao->fetch()) {
         $roleID = $dao->value;
     }
     // handle register date CRM-4320
     $registerDate = NULL;
     if (!empty($form->_allowConfirmation) && $form->_participantId) {
         $registerDate = $params['participant_register_date'];
     } elseif (!empty($params['participant_register_date']) && is_array($params['participant_register_date']) && !empty($params['participant_register_date'])) {
         $registerDate = CRM_Utils_Date::format($params['participant_register_date']);
     }
     $participantFields = CRM_Event_DAO_Participant::fields();
     $participantParams = array('id' => CRM_Utils_Array::value('participant_id', $params), 'contact_id' => $contactID, 'event_id' => $form->_eventId ? $form->_eventId : $params['event_id'], 'status_id' => CRM_Utils_Array::value('participant_status', $params, 1), 'role_id' => CRM_Utils_Array::value('participant_role_id', $params, $roleID), 'register_date' => $registerDate ? $registerDate : date('YmdHis'), 'source' => CRM_Utils_String::ellipsify(isset($params['participant_source']) ? CRM_Utils_Array::value('participant_source', $params) : CRM_Utils_Array::value('description', $params), $participantFields['participant_source']['maxlength']), 'fee_level' => CRM_Utils_Array::value('amount_level', $params), 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0), 'fee_amount' => CRM_Utils_Array::value('fee_amount', $params), 'registered_by_id' => CRM_Utils_Array::value('registered_by_id', $params), 'discount_id' => CRM_Utils_Array::value('discount_id', $params), 'fee_currency' => CRM_Utils_Array::value('currencyID', $params), 'campaign_id' => CRM_Utils_Array::value('campaign_id', $params));
     if ($form->_action & CRM_Core_Action::PREVIEW || CRM_Utils_Array::value('mode', $params) == 'test') {
         $participantParams['is_test'] = 1;
     } else {
         $participantParams['is_test'] = 0;
     }
     if (!empty($form->_params['note'])) {
         $participantParams['note'] = $form->_params['note'];
     } elseif (!empty($form->_params['participant_note'])) {
         $participantParams['note'] = $form->_params['participant_note'];
     }
     // reuse id if one already exists for this one (can happen
     // with back button being hit etc)
     if (!$participantParams['id'] && !empty($params['contributionID'])) {
         $pID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $params['contributionID'], 'participant_id', 'contribution_id');
         $participantParams['id'] = $pID;
     }
     $participantParams['discount_id'] = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event');
     if (!$participantParams['discount_id']) {
         $participantParams['discount_id'] = "null";
     }
     $participant = CRM_Event_BAO_Participant::create($participantParams);
     $transaction->commit();
     return $participant;
 }
 /**
  * create trxn entry if an event has discount.
  *
  * @param int $eventID
  *   Event id.
  * @param array $contributionParams
  *   Contribution params.
  *
  * @param $feeLevel
  *
  */
 public static function createDiscountTrxn($eventID, $contributionParams, $feeLevel)
 {
     // CRM-11124
     $checkDiscount = CRM_Core_BAO_Discount::findSet($eventID, 'civicrm_event');
     if (!empty($checkDiscount)) {
         $feeLevel = current($feeLevel);
         $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventID, NULL);
         $query = "SELECT cpfv.amount FROM `civicrm_price_field_value` cpfv\nLEFT JOIN civicrm_price_field cpf ON cpfv.price_field_id = cpf.id\nWHERE cpf.price_set_id = %1 AND cpfv.label LIKE %2";
         $params = array(1 => array($priceSetId, 'Integer'), 2 => array($feeLevel, 'String'));
         $mainAmount = CRM_Core_DAO::singleValueQuery($query, $params);
         $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Discounts Account is' "));
         $contributionParams['trxnParams']['from_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($contributionParams['contribution']->financial_type_id, $relationTypeId);
         if (!empty($contributionParams['trxnParams']['from_financial_account_id'])) {
             $contributionParams['trxnParams']['total_amount'] = $mainAmount - $contributionParams['total_amount'];
             $contributionParams['trxnParams']['payment_processor_id'] = NULL;
             $contributionParams['trxnParams']['payment_instrument_id'] = NULL;
             $contributionParams['trxnParams']['check_number'] = NULL;
             $contributionParams['trxnParams']['trxn_id'] = NULL;
             $contributionParams['trxnParams']['net_amount'] = NULL;
             $contributionParams['trxnParams']['fee_amount'] = NULL;
             CRM_Core_BAO_FinancialTrxn::create($contributionParams['trxnParams']);
         }
     }
 }
 /**
  * This function sets the default values for the form in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function setDefaultValues(&$form)
 {
     $defaults = array();
     if ($form->_eventId) {
         //get receipt text and financial type
         $returnProperities = array('confirm_email_text', 'financial_type_id', 'campaign_id', 'start_date');
         $details = array();
         CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $form->_eventId, $details, $returnProperities);
         if (!empty($details[$form->_eventId]['financial_type_id'])) {
             $defaults[$form->_pId]['financial_type_id'] = $details[$form->_eventId]['financial_type_id'];
         }
     }
     if ($form->_pId) {
         $ids = array();
         $params = array('id' => $form->_pId);
         CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
         if ($form->_action == CRM_Core_Action::UPDATE) {
             $discounts = array();
             if (!empty($form->_values['discount'])) {
                 foreach ($form->_values['discount'] as $key => $value) {
                     $value = current($value);
                     $discounts[$key] = $value['name'];
                 }
             }
             if ($form->_discountId && !empty($discounts[$defaults[$form->_pId]['discount_id']])) {
                 $form->assign('discount', $discounts[$defaults[$form->_pId]['discount_id']]);
             }
             $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
             $form->assign('fee_level', CRM_Utils_Array::value('fee_level', $defaults[$form->_pId]));
         }
         $defaults[$form->_pId]['send_receipt'] = 0;
     } else {
         $defaults[$form->_pId]['send_receipt'] = strtotime(CRM_Utils_Array::value('start_date', $details[$form->_eventId])) >= time() ? 1 : 0;
         if ($form->_eventId && !empty($details[$form->_eventId]['confirm_email_text'])) {
             //set receipt text
             $defaults[$form->_pId]['receipt_text'] = $details[$form->_eventId]['confirm_email_text'];
         }
         list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults();
     }
     //CRM-11601 we should keep the record contribution
     //true by default while adding participant
     if ($form->_action == CRM_Core_Action::ADD && !$form->_mode && $form->_isPaidEvent) {
         $defaults[$form->_pId]['record_contribution'] = 1;
     }
     //CRM-13420
     if (empty($defaults['payment_instrument_id'])) {
         $defaults[$form->_pId]['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
     }
     if ($form->_mode) {
         $config = CRM_Core_Config::singleton();
         // set default country from config if no country set
         if (empty($defaults[$form->_pId]["billing_country_id-{$form->_bltID}"])) {
             $defaults[$form->_pId]["billing_country_id-{$form->_bltID}"] = $config->defaultContactCountry;
         }
         if (empty($defaults["billing_state_province_id-{$form->_bltID}"])) {
             $defaults[$form->_pId]["billing_state_province_id-{$form->_bltID}"] = $config->defaultContactStateProvince;
         }
         $billingDefaults = $form->getProfileDefaults('Billing', $form->_contactId);
         $defaults[$form->_pId] = array_merge($defaults[$form->_pId], $billingDefaults);
         //             // hack to simplify credit card entry for testing
         //             $defaults[$form->_pId]['credit_card_type']     = 'Visa';
         //             $defaults[$form->_pId]['credit_card_number']   = '4807731747657838';
         //             $defaults[$form->_pId]['cvv2']                 = '000';
         //             $defaults[$form->_pId]['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' );
     }
     // if user has selected discount use that to set default
     if (isset($form->_discountId)) {
         $defaults[$form->_pId]['discount_id'] = $form->_discountId;
         //hack to set defaults for already selected discount value
         if ($form->_action == CRM_Core_Action::UPDATE && !$form->_originalDiscountId) {
             $form->_originalDiscountId = $defaults[$form->_pId]['discount_id'];
             if ($form->_originalDiscountId) {
                 $defaults[$form->_pId]['discount_id'] = $form->_originalDiscountId;
             }
         }
         $discountId = $form->_discountId;
     } else {
         $discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event');
     }
     if ($discountId) {
         $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id');
     } else {
         $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $form->_eventId);
     }
     if ($form->_action == CRM_Core_Action::ADD && $form->_eventId && $discountId) {
         // this case is for add mode, where we show discount automatically
         $defaults[$form->_pId]['discount_id'] = $discountId;
     }
     if ($priceSetId) {
         // get price set default values, CRM-4090
         if (in_array(get_class($form), array('CRM_Event_Form_Participant', 'CRM_Event_Form_Registration_Register', 'CRM_Event_Form_Registration_AdditionalParticipant'))) {
             $priceSetValues = self::setDefaultPriceSet($form->_pId, $form->_eventId);
             if (!empty($priceSetValues)) {
                 $defaults[$form->_pId] = array_merge($defaults[$form->_pId], $priceSetValues);
             }
         }
         if ($form->_action == CRM_Core_Action::ADD && !empty($form->_priceSet['fields'])) {
             foreach ($form->_priceSet['fields'] as $key => $val) {
                 foreach ($val['options'] as $keys => $values) {
                     if ($values['is_default']) {
                         if (get_class($form) != 'CRM_Event_Form_Participant' && !empty($values['is_full'])) {
                             continue;
                         }
                         if ($val['html_type'] == 'CheckBox') {
                             $defaults[$form->_pId]["price_{$key}"][$keys] = 1;
                         } else {
                             $defaults[$form->_pId]["price_{$key}"] = $keys;
                         }
                     }
                 }
             }
         }
         $form->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
         if ($form->_action == CRM_Core_Action::UPDATE) {
             $fee_level = $defaults[$form->_pId]['fee_level'];
             CRM_Event_BAO_Participant::fixEventLevel($fee_level);
             $form->assign('fee_level', $fee_level);
             $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
         }
     }
     //CRM-4453
     if (!empty($defaults[$form->_pId]['participant_fee_currency'])) {
         $form->assign('fee_currency', $defaults[$form->_pId]['participant_fee_currency']);
     }
     // CRM-4395
     if ($contriId = $form->get('onlinePendingContributionId')) {
         $contribution = new CRM_Contribute_DAO_Contribution();
         $contribution->id = $contriId;
         $contribution->find(TRUE);
         foreach (array('financial_type_id', 'payment_instrument_id', 'contribution_status_id', 'receive_date', 'total_amount') as $f) {
             if ($f == 'receive_date') {
                 list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults($contribution->{$f});
             } else {
                 $defaults[$form->_pId][$f] = $contribution->{$f};
             }
         }
     }
     return $defaults[$form->_pId];
 }
Example #5
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the  
  * type of action and executes that action.
  * Finally it calls the parent's run method.
  *
  * @return void
  * @access public
  *
  */
 function run()
 {
     //get the event id.
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, true);
     $config =& CRM_Core_Config::singleton();
     require_once 'CRM/Event/BAO/Event.php';
     // ensure that the user has permission to see this page
     if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW, $this->_id)) {
         CRM_Core_Error::fatal(ts('You do not have permission to view this event'));
     }
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, false);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this, false, 'register');
     $this->assign('context', $context);
     // Sometimes we want to suppress the Event Full msg
     $noFullMsg = CRM_Utils_Request::retrieve('noFullMsg', 'String', $this, false, 'false');
     // set breadcrumb to append to 2nd layer pages
     $breadCrumbPath = CRM_Utils_System::url("civicrm/event/info", "id={$this->_id}&reset=1");
     $additionalBreadCrumb = "<a href=\"{$breadCrumbPath}\">" . ts('Events') . '</a>';
     //retrieve event information
     $params = array('id' => $this->_id);
     CRM_Event_BAO_Event::retrieve($params, $values['event']);
     if (!$values['event']['is_active']) {
         // form is inactive, die a fatal death
         CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.'));
     }
     $this->assign('isShowLocation', CRM_Utils_Array::value('is_show_location', $values['event']));
     // show event fees.
     require_once 'CRM/Price/BAO/Set.php';
     if ($this->_id && CRM_Utils_Array::value('is_monetary', $values['event'])) {
         // get price set options, - CRM-5209
         if ($priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $this->_id)) {
             $setDetails = CRM_Price_BAO_Set::getSetDetail($priceSetId);
             eval("\$priceSetFields = \$setDetails[{$priceSetId}][fields];");
             if (is_array($priceSetFields)) {
                 $fieldCnt = 1;
                 foreach ($priceSetFields as $fid => $fieldValues) {
                     if (!is_array($fieldValues['options']) || empty($fieldValues['options'])) {
                         continue;
                     }
                     foreach ($fieldValues['options'] as $optionId => $optionVal) {
                         $values['feeBlock']['value'][$fieldCnt] = $optionVal['value'];
                         $values['feeBlock']['label'][$fieldCnt] = $optionVal['description'];
                         $fieldCnt++;
                     }
                 }
             }
         } else {
             //retrieve event fee block.
             require_once 'CRM/Core/OptionGroup.php';
             require_once 'CRM/Core/BAO/Discount.php';
             $discountId = CRM_Core_BAO_Discount::findSet($this->_id, 'civicrm_event');
             if ($discountId) {
                 CRM_Core_OptionGroup::getAssoc(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'option_group_id'), $values['feeBlock'], false, 'id');
             } else {
                 CRM_Core_OptionGroup::getAssoc("civicrm_event.amount.{$this->_id}", $values['feeBlock']);
             }
         }
     }
     $params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event');
     require_once 'CRM/Core/BAO/Location.php';
     $values['location'] = CRM_Core_BAO_Location::getValues($params, true);
     //retrieve custom field information
     require_once 'CRM/Core/BAO/CustomGroup.php';
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree("Event", $this, $this->_id, 0, $values['event']['event_type_id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     $this->assign('action', CRM_Core_Action::VIEW);
     //To show the event location on maps directly on event info page
     $locations =& CRM_Event_BAO_Event::getMapInfo($this->_id);
     if (!empty($locations) && CRM_Utils_Array::value('is_map', $values['event'])) {
         $this->assign('locations', $locations);
         $this->assign('mapProvider', $config->mapProvider);
         $this->assign('mapKey', $config->mapAPIKey);
         $sumLat = $sumLng = 0;
         $maxLat = $maxLng = -400;
         $minLat = $minLng = +400;
         foreach ($locations as $location) {
             $sumLat += $location['lat'];
             $sumLng += $location['lng'];
             if ($location['lat'] > $maxLat) {
                 $maxLat = $location['lat'];
             }
             if ($location['lat'] < $minLat) {
                 $minLat = $location['lat'];
             }
             if ($location['lng'] > $maxLng) {
                 $maxLng = $location['lng'];
             }
             if ($location['lng'] < $minLng) {
                 $minLng = $location['lng'];
             }
         }
         $center = array('lat' => (double) $sumLat / count($locations), 'lng' => (double) $sumLng / count($locations));
         $span = array('lat' => (double) ($maxLat - $minLat), 'lng' => (double) ($maxLng - $minLng));
         $this->assign_by_ref('center', $center);
         $this->assign_by_ref('span', $span);
     }
     require_once 'CRM/Event/BAO/Participant.php';
     $eventFullMessage = CRM_Event_BAO_Participant::eventFull($this->_id);
     if ($eventFullMessage and $noFullMsg == 'false') {
         if (CRM_Utils_Array::value('has_waitlist', $values['event'])) {
             $eventFullMessage = null;
             $statusMessage = CRM_Utils_Array::value('waitlist_text', $values['event'], 'Event is currently full, but you can register and be a part of waiting list.');
         } else {
             $statusMessage = $eventFullMessage;
         }
         CRM_Core_Session::setStatus($statusMessage);
     }
     if (CRM_Utils_Array::value('is_online_registration', $values['event'])) {
         if (CRM_Event_BAO_Event::validRegistrationDate($values['event'], $this->_id)) {
             if (!$eventFullMessage) {
                 $registerText = ts('Register Now');
                 if (CRM_Utils_Array::value('registration_link_text', $values['event'])) {
                     $registerText = $values['event']['registration_link_text'];
                 }
                 //Fixed for CRM-4855
                 if (CRM_Event_BAO_Event::showHideRegistrationLink($values)) {
                     $this->assign('allowRegistration', true);
                 }
                 $this->assign('registerText', $registerText);
             }
             // we always generate urls for the front end in joomla
             if ($action == CRM_Core_Action::PREVIEW) {
                 $url = CRM_Utils_System::url('civicrm/event/register', "id={$this->_id}&reset=1&action=preview", true, null, true, true);
             } else {
                 $url = CRM_Utils_System::url('civicrm/event/register', "id={$this->_id}&reset=1", true, null, true, true);
             }
             if (!$eventFullMessage) {
                 $this->assign('registerURL', $url);
             }
         }
         if ($action == CRM_Core_Action::PREVIEW) {
             $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1&action=preview", true, null, true, true);
         } else {
             $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1", true, null, true, true);
         }
         $this->assign('mapURL', $mapURL);
     }
     // we do not want to display recently viewed items, so turn off
     $this->assign('displayRecent', false);
     // set page title = event title
     CRM_Utils_System::setTitle($values['event']['title']);
     $this->assign('event', $values['event']);
     if (isset($values['feeBlock'])) {
         $this->assign('feeBlock', $values['feeBlock']);
     }
     $this->assign('location', $values['location']);
     parent::run();
 }
 /**
  * Process the form submission.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     //get the button name.
     $button = substr($this->controller->getButtonName(), -4);
     //take the participant instance.
     $addParticipantNum = substr($this->_name, 12);
     //user submitted params.
     $params = $this->controller->exportValues($this->_name);
     if (!$this->_allowConfirmation) {
         // check if the participant is already registered
         $params['contact_id'] = CRM_Event_Form_Registration_Register::checkRegistration($params, $this, TRUE, TRUE);
     }
     //carry campaign to partcipants.
     if (array_key_exists('participant_campaign_id', $params)) {
         $params['campaign_id'] = $params['participant_campaign_id'];
     } else {
         $params['campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
     }
     // if waiting is enabled
     if (!$this->_allowConfirmation && is_numeric($this->_availableRegistrations)) {
         $this->_allowWaitlist = FALSE;
         //get the current page count.
         $currentCount = self::getParticipantCount($this, $params);
         if ($button == 'skip') {
             $currentCount = 'skip';
         }
         //get the total count.
         $previousCount = self::getParticipantCount($this, $this->_params, TRUE);
         $totalParticipants = $previousCount;
         if (is_numeric($currentCount)) {
             $totalParticipants += $currentCount;
         }
         if (!empty($this->_values['event']['has_waitlist']) && $totalParticipants > $this->_availableRegistrations) {
             $this->_allowWaitlist = TRUE;
         }
         $this->set('allowWaitlist', $this->_allowWaitlist);
         $this->_lineItemParticipantsCount[$addParticipantNum] = $currentCount;
     }
     if ($button == 'skip') {
         //hack for free/zero amount event.
         if ($this->_resetAllowWaitlist) {
             $this->_allowWaitlist = FALSE;
             $this->set('allowWaitlist', FALSE);
             if ($this->_requireApproval) {
                 $status = ts("You have skipped last participant and which result into event having enough spaces, but your registration require approval, Once your registration has been reviewed, you will receive an email with a link to a web page where you can complete the registration process.");
             } else {
                 $status = ts("You have skipped last participant and which result into event having enough spaces, hence your group become as register participants though you selected on wait list.");
             }
             CRM_Core_Session::setStatus($status);
         }
         $this->_params[$addParticipantNum] = 'skip';
         if (isset($this->_lineItem)) {
             $this->_lineItem[$addParticipantNum] = 'skip';
             $this->_lineItemParticipantsCount[$addParticipantNum] = 'skip';
         }
     } else {
         $config = CRM_Core_Config::singleton();
         $params['currencyID'] = $config->defaultCurrency;
         if ($this->_values['event']['is_monetary']) {
             //added for discount
             $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
             if (!empty($this->_values['discount'][$discountId])) {
                 $params['discount_id'] = $discountId;
                 $params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label'];
                 $params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
             } elseif (empty($params['priceSetId'])) {
                 $params['amount_level'] = $this->_values['fee'][$params['amount']]['label'];
                 $params['amount'] = $this->_values['fee'][$params['amount']]['value'];
             } else {
                 $lineItem = array();
                 CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem);
                 //build line item array..
                 //if requireApproval/waitlist is enabled we hide fees for primary participant
                 // (and not for additional participant which might be is a bug)
                 //lineItem are not correctly build for primary participant
                 //this results in redundancy since now lineItems for additional participant will be build against primary participantNum
                 //therefore lineItems must always be build against current participant No
                 $this->_lineItem[$addParticipantNum] = $lineItem;
             }
         }
         if (array_key_exists('participant_role', $params)) {
             $params['participant_role_id'] = $params['participant_role'];
         }
         if (empty($params['participant_role_id']) && $this->_values['event']['default_role_id']) {
             $params['participant_role_id'] = $this->_values['event']['default_role_id'];
         }
         if (!empty($this->_params[0]['is_pay_later'])) {
             $params['is_pay_later'] = 1;
         }
         //carry additional participant id, contact id if pre-registered.
         if ($this->_allowConfirmation && $this->_additionalParticipantId) {
             $params['contact_id'] = $this->_contactId;
             $params['participant_id'] = $this->_additionalParticipantId;
         }
         //build the params array.
         $this->_params[$addParticipantNum] = $params;
     }
     //finally set the params.
     $this->set('params', $this->_params);
     //set the line item.
     if ($this->_lineItem) {
         $this->set('lineItem', $this->_lineItem);
         $this->set('lineItemParticipantsCount', $this->_lineItemParticipantsCount);
     }
     $participantNo = count($this->_params);
     if ($button != 'skip') {
         $statusMsg = ts('Registration information for participant %1 has been saved.', array(1 => $participantNo));
         CRM_Core_Session::setStatus($statusMsg, ts('Registration Saved'), 'success');
     }
     // Check whether to process the registration now, calling processRegistration()
     if (!$this->_values['event']['is_confirm_enabled'] && !$this->_values['event']['is_monetary'] && CRM_Utils_Array::value('additional_participants', $this->_params[0]) && $this->isLastParticipant()) {
         CRM_Event_Form_Registration_Register::processRegistration($this->_params, NULL);
     }
 }
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     //set as Primary participant
     $params['is_primary'] = 1;
     if ($this->_values['event']['is_pay_later'] && !array_key_exists('hidden_processor', $params)) {
         $params['is_pay_later'] = 1;
     } else {
         $params['is_pay_later'] = 0;
     }
     $this->set('is_pay_later', $params['is_pay_later']);
     // assign pay later stuff
     $this->_params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE);
     $this->assign('is_pay_later', $params['is_pay_later']);
     if ($params['is_pay_later']) {
         $this->assign('pay_later_text', $this->_values['event']['pay_later_text']);
         $this->assign('pay_later_receipt', $this->_values['event']['pay_later_receipt']);
     }
     if (!$this->_allowConfirmation) {
         // check if the participant is already registered
         if (!$this->_skipDupeRegistrationCheck) {
             $params['contact_id'] = self::checkRegistration($params, $this, FALSE, TRUE, TRUE);
         }
     }
     if (CRM_Utils_Array::value('image_URL', $params)) {
         CRM_Contact_BAO_Contact::processImageParams($params);
     }
     //carry campaign to partcipants.
     if (array_key_exists('participant_campaign_id', $params)) {
         $params['campaign_id'] = $params['participant_campaign_id'];
     } else {
         $params['campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
     }
     //hack to allow group to register w/ waiting
     $primaryParticipantCount = self::getParticipantCount($this, $params);
     $totalParticipants = $primaryParticipantCount;
     if (CRM_Utils_Array::value('additional_participants', $params)) {
         $totalParticipants += $params['additional_participants'];
     }
     if (!$this->_allowConfirmation && CRM_Utils_Array::value('bypass_payment', $params) && is_numeric($this->_availableRegistrations) && $totalParticipants > $this->_availableRegistrations) {
         $this->_allowWaitlist = TRUE;
         $this->set('allowWaitlist', TRUE);
     }
     //carry participant id if pre-registered.
     if ($this->_allowConfirmation && $this->_participantId) {
         $params['participant_id'] = $this->_participantId;
     }
     $params['defaultRole'] = 1;
     if (array_key_exists('participant_role', $params)) {
         $params['participant_role_id'] = $params['participant_role'];
     }
     if (array_key_exists('participant_role_id', $params)) {
         $params['defaultRole'] = 0;
     }
     if (!CRM_Utils_Array::value('participant_role_id', $params) && $this->_values['event']['default_role_id']) {
         $params['participant_role_id'] = $this->_values['event']['default_role_id'];
     }
     $config = CRM_Core_Config::singleton();
     $params['currencyID'] = $config->defaultCurrency;
     if ($this->_values['event']['is_monetary']) {
         // we first reset the confirm page so it accepts new values
         $this->controller->resetPage('Confirm');
         //added for discount
         $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
         if (!empty($this->_values['discount'][$discountId])) {
             $params['discount_id'] = $discountId;
             $params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label'];
             $params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
         } elseif (empty($params['priceSetId'])) {
             if (!empty($params['amount'])) {
                 $params['amount_level'] = $this->_values['fee'][$params['amount']]['label'];
                 $params['amount'] = $this->_values['fee'][$params['amount']]['value'];
             } else {
                 $params['amount_level'] = $params['amount'] = '';
             }
         } else {
             $lineItem = array();
             CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem);
             $this->set('lineItem', array($lineItem));
             $this->set('lineItemParticipantsCount', array($primaryParticipantCount));
         }
         $this->set('amount', $params['amount']);
         $this->set('amount_level', $params['amount_level']);
         // generate and set an invoiceID for this transaction
         $invoiceID = md5(uniqid(rand(), TRUE));
         $this->set('invoiceID', $invoiceID);
         if (is_array($this->_paymentProcessor)) {
             $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
         }
         // default mode is direct
         $this->set('contributeMode', 'direct');
         if (isset($params["state_province_id-{$this->_bltID}"]) && $params["state_province_id-{$this->_bltID}"]) {
             $params["state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($params["state_province_id-{$this->_bltID}"]);
         }
         if (isset($params["country_id-{$this->_bltID}"]) && $params["country_id-{$this->_bltID}"]) {
             $params["country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($params["country_id-{$this->_bltID}"]);
         }
         if (isset($params['credit_card_exp_date'])) {
             $params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($params);
             $params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($params);
         }
         if ($this->_values['event']['is_monetary']) {
             $params['ip_address'] = CRM_Utils_System::ipAddress();
             $params['currencyID'] = $config->defaultCurrency;
             $params['payment_action'] = 'Sale';
             $params['invoiceID'] = $invoiceID;
         }
         $this->_params = array();
         $this->_params[] = $params;
         $this->set('params', $this->_params);
         if ($this->_paymentProcessor && $this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) {
             //get the button name
             $buttonName = $this->controller->getButtonName();
             if (in_array($buttonName, array($this->_expressButtonName, $this->_expressButtonName . '_x', $this->_expressButtonName . '_y')) && !CRM_Utils_Array::value('is_pay_later', $params) && !$this->_allowWaitlist && !$this->_requireApproval) {
                 $this->set('contributeMode', 'express');
                 // Send Event Name & Id in Params
                 $params['eventName'] = $this->_values['event']['title'];
                 $params['eventId'] = $this->_values['event']['id'];
                 $params['cancelURL'] = CRM_Utils_System::url('civicrm/event/register', "_qf_Register_display=1&qfKey={$this->controller->_key}", TRUE, NULL, FALSE);
                 if (CRM_Utils_Array::value('additional_participants', $params, FALSE)) {
                     $urlArgs = "_qf_Participant_1_display=1&rfp=1&qfKey={$this->controller->_key}";
                 } else {
                     $urlArgs = "_qf_Confirm_display=1&rfp=1&qfKey={$this->controller->_key}";
                 }
                 $params['returnURL'] = CRM_Utils_System::url('civicrm/event/register', $urlArgs, TRUE, NULL, FALSE);
                 $params['invoiceID'] = $invoiceID;
                 //default action is Sale
                 $params['payment_action'] = 'Sale';
                 $token = $payment->setExpressCheckout($params);
                 if (is_a($token, 'CRM_Core_Error')) {
                     CRM_Core_Error::displaySessionError($token);
                     CRM_Utils_System::redirect($params['cancelURL']);
                 }
                 $this->set('token', $token);
                 $paymentURL = $this->_paymentProcessor['url_site'] . "/cgi-bin/webscr?cmd=_express-checkout&token={$token}";
                 CRM_Utils_System::redirect($paymentURL);
             }
         } elseif ($this->_paymentProcessor && $this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_NOTIFY) {
             $this->set('contributeMode', 'notify');
         }
     } else {
         $session = CRM_Core_Session::singleton();
         $params['description'] = ts('Online Event Registration') . ' ' . $this->_values['event']['title'];
         $this->_params = array();
         $this->_params[] = $params;
         $this->set('params', $this->_params);
         if (!CRM_Utils_Array::value('additional_participants', $params)) {
             self::processRegistration($this->_params);
         }
     }
     // If registering > 1 participant, give status message
     if (CRM_Utils_Array::value('additional_participants', $params, FALSE)) {
         $statusMsg = ts('Registration information for participant 1 has been saved.');
         CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success');
     }
 }
Example #8
0
 /**
  * Run the page.
  *
  * This method is called after the page is created. It checks for the
  * type of action and executes that action.
  * Finally it calls the parent's run method.
  *
  * @return void
  */
 public function run()
 {
     //get the event id.
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $config = CRM_Core_Config::singleton();
     // ensure that the user has permission to see this page
     if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW, $this->_id, 'view event info')) {
         CRM_Utils_System::setUFMessage(ts('You do not have permission to view this event'));
         return CRM_Utils_System::permissionDenied();
     }
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'register');
     $this->assign('context', $context);
     // Sometimes we want to suppress the Event Full msg
     $noFullMsg = CRM_Utils_Request::retrieve('noFullMsg', 'String', $this, FALSE, 'false');
     // set breadcrumb to append to 2nd layer pages
     $breadCrumbPath = CRM_Utils_System::url('civicrm/event/info', "id={$this->_id}&reset=1");
     //retrieve event information
     $params = array('id' => $this->_id);
     CRM_Event_BAO_Event::retrieve($params, $values['event']);
     if (!$values['event']['is_active']) {
         // form is inactive, die a fatal death
         CRM_Utils_System::setUFMessage(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
         return CRM_Utils_System::permissionDenied();
     }
     if (!empty($values['event']['is_template'])) {
         // form is an Event Template
         CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.'));
     }
     // Add Event Type to $values in case folks want to display it
     $values['event']['event_type'] = CRM_Utils_Array::value($values['event']['event_type_id'], CRM_Event_PseudoConstant::eventType());
     $this->assign('isShowLocation', CRM_Utils_Array::value('is_show_location', $values['event']));
     // show event fees.
     if ($this->_id && !empty($values['event']['is_monetary'])) {
         //CRM-6907
         $config = CRM_Core_Config::singleton();
         $config->defaultCurrency = CRM_Utils_Array::value('currency', $values['event'], $config->defaultCurrency);
         //CRM-10434
         $discountId = CRM_Core_BAO_Discount::findSet($this->_id, 'civicrm_event');
         if ($discountId) {
             $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'price_set_id');
         } else {
             $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_id);
         }
         // get price set options, - CRM-5209
         if ($priceSetId) {
             $setDetails = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, TRUE);
             $priceSetFields = $setDetails[$priceSetId]['fields'];
             if (is_array($priceSetFields)) {
                 $fieldCnt = 1;
                 $visibility = CRM_Core_PseudoConstant::visibility('name');
                 // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
                 $adminFieldVisible = FALSE;
                 if (CRM_Core_Permission::check('administer CiviCRM')) {
                     $adminFieldVisible = TRUE;
                 }
                 foreach ($priceSetFields as $fid => $fieldValues) {
                     if (!is_array($fieldValues['options']) || empty($fieldValues['options']) || CRM_Utils_Array::value('visibility_id', $fieldValues) != array_search('public', $visibility) && $adminFieldVisible == FALSE) {
                         continue;
                     }
                     if (count($fieldValues['options']) > 1) {
                         $values['feeBlock']['value'][$fieldCnt] = '';
                         $values['feeBlock']['label'][$fieldCnt] = $fieldValues['label'];
                         $values['feeBlock']['lClass'][$fieldCnt] = 'price_set_option_group-label';
                         $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
                         $fieldCnt++;
                         $labelClass = 'price_set_option-label';
                     } else {
                         $labelClass = 'price_set_field-label';
                     }
                     // show tax rate with amount
                     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
                     $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
                     $displayOpt = CRM_Utils_Array::value('tax_display_settings', $invoiceSettings);
                     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
                     foreach ($fieldValues['options'] as $optionId => $optionVal) {
                         $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
                         if ($invoicing && isset($optionVal['tax_amount'])) {
                             $values['feeBlock']['value'][$fieldCnt] = CRM_Price_BAO_PriceField::getTaxLabel($optionVal, 'amount', $displayOpt, $taxTerm);
                             $values['feeBlock']['tax_amount'][$fieldCnt] = $optionVal['tax_amount'];
                         } else {
                             $values['feeBlock']['value'][$fieldCnt] = $optionVal['amount'];
                         }
                         $values['feeBlock']['label'][$fieldCnt] = $optionVal['label'];
                         $values['feeBlock']['lClass'][$fieldCnt] = $labelClass;
                         $fieldCnt++;
                     }
                 }
             }
             // Tell tpl we have price set fee data and whether it's a quick_config price set
             $this->assign('isPriceSet', 1);
             $this->assign('isQuickConfig', $setDetails[$priceSetId]['is_quick_config']);
         }
     }
     $params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event');
     $values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE);
     // fix phone type labels
     if (!empty($values['location']['phone'])) {
         $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
         foreach ($values['location']['phone'] as &$val) {
             if (!empty($val['phone_type_id'])) {
                 $val['phone_type_display'] = $phoneTypes[$val['phone_type_id']];
             }
         }
     }
     //retrieve custom field information
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this, $this->_id, 0, $values['event']['event_type_id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id);
     $this->assign('action', CRM_Core_Action::VIEW);
     //To show the event location on maps directly on event info page
     $locations = CRM_Event_BAO_Event::getMapInfo($this->_id);
     if (!empty($locations) && !empty($values['event']['is_map'])) {
         $this->assign('locations', $locations);
         $this->assign('mapProvider', $config->mapProvider);
         $this->assign('mapKey', $config->mapAPIKey);
         $sumLat = $sumLng = 0;
         $maxLat = $maxLng = -400;
         $minLat = $minLng = 400;
         foreach ($locations as $location) {
             $sumLat += $location['lat'];
             $sumLng += $location['lng'];
             if ($location['lat'] > $maxLat) {
                 $maxLat = $location['lat'];
             }
             if ($location['lat'] < $minLat) {
                 $minLat = $location['lat'];
             }
             if ($location['lng'] > $maxLng) {
                 $maxLng = $location['lng'];
             }
             if ($location['lng'] < $minLng) {
                 $minLng = $location['lng'];
             }
         }
         $center = array('lat' => (double) $sumLat / count($locations), 'lng' => (double) $sumLng / count($locations));
         $span = array('lat' => (double) ($maxLat - $minLat), 'lng' => (double) ($maxLng - $minLng));
         $this->assign_by_ref('center', $center);
         $this->assign_by_ref('span', $span);
         if ($action == CRM_Core_Action::PREVIEW) {
             $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1&action=preview", TRUE, NULL, TRUE, TRUE);
         } else {
             $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', "eid={$this->_id}&reset=1", TRUE, NULL, TRUE, TRUE);
         }
         $this->assign('skipLocationType', TRUE);
         $this->assign('mapURL', $mapURL);
     }
     if (CRM_Core_Permission::check('view event participants') && CRM_Core_Permission::check('view all contacts')) {
         $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1', 'label');
         $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0', 'label');
         $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
         $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
         $this->assign('findParticipants', $findParticipants);
     }
     $participantListingID = CRM_Utils_Array::value('participant_listing_id', $values['event']);
     if ($participantListingID) {
         $participantListingURL = CRM_Utils_System::url('civicrm/event/participant', "reset=1&id={$this->_id}", TRUE, NULL, TRUE, TRUE);
         $this->assign('participantListingURL', $participantListingURL);
     }
     $hasWaitingList = CRM_Utils_Array::value('has_waitlist', $values['event']);
     $eventFullMessage = CRM_Event_BAO_Participant::eventFull($this->_id, FALSE, $hasWaitingList);
     $allowRegistration = FALSE;
     if (!empty($values['event']['is_online_registration'])) {
         if (CRM_Event_BAO_Event::validRegistrationRequest($values['event'], $this->_id)) {
             // we always generate urls for the front end in joomla
             $action_query = $action === CRM_Core_Action::PREVIEW ? "&action={$action}" : '';
             $url = CRM_Utils_System::url('civicrm/event/register', "id={$this->_id}&reset=1{$action_query}", TRUE, NULL, TRUE, TRUE);
             if (!$eventFullMessage || $hasWaitingList) {
                 $registerText = ts('Register Now');
                 if (!empty($values['event']['registration_link_text'])) {
                     $registerText = $values['event']['registration_link_text'];
                 }
                 // check if we're in shopping cart mode for events
                 $enable_cart = Civi::settings()->get('enable_cart');
                 if ($enable_cart) {
                     $link = CRM_Event_Cart_BAO_EventInCart::get_registration_link($this->_id);
                     $registerText = $link['label'];
                     $url = CRM_Utils_System::url($link['path'], $link['query'] . $action_query, TRUE, NULL, TRUE, TRUE);
                 }
                 //Fixed for CRM-4855
                 $allowRegistration = CRM_Event_BAO_Event::showHideRegistrationLink($values);
                 $this->assign('registerText', $registerText);
                 $this->assign('registerURL', $url);
                 $this->assign('eventCartEnabled', $enable_cart);
             }
         } elseif (CRM_Core_Permission::check('register for events')) {
             $this->assign('registerClosed', TRUE);
         }
     }
     $this->assign('allowRegistration', $allowRegistration);
     $session = CRM_Core_Session::singleton();
     $params = array('contact_id' => $session->get('userID'), 'event_id' => CRM_Utils_Array::value('id', $values['event']), 'role_id' => CRM_Utils_Array::value('default_role_id', $values['event']));
     if ($eventFullMessage && $noFullMsg == 'false' || CRM_Event_BAO_Event::checkRegistration($params)) {
         $statusMessage = $eventFullMessage;
         if (CRM_Event_BAO_Event::checkRegistration($params)) {
             if ($noFullMsg == 'false') {
                 if ($values['event']['allow_same_participant_emails']) {
                     $statusMessage = ts('It looks like you are already registered for this event.  You may proceed if you want to create an additional registration.');
                 } else {
                     $registerUrl = CRM_Utils_System::url('civicrm/event/register', "reset=1&id={$values['event']['id']}&cid=0");
                     $statusMessage = ts("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));
                 }
             }
         } elseif ($hasWaitingList) {
             $statusMessage = CRM_Utils_Array::value('waitlist_text', $values['event']);
             if (!$statusMessage) {
                 $statusMessage = ts('Event is currently full, but you can register and be a part of waiting list.');
             }
         }
         CRM_Core_Session::setStatus($statusMessage);
     }
     // we do not want to display recently viewed items, so turn off
     $this->assign('displayRecent', FALSE);
     // set page title = event title
     CRM_Utils_System::setTitle($values['event']['title']);
     $this->assign('event', $values['event']);
     if (isset($values['feeBlock'])) {
         $this->assign('feeBlock', $values['feeBlock']);
     }
     $this->assign('location', $values['location']);
     if (CRM_Core_Permission::check('access CiviEvent')) {
         $enableCart = Civi::settings()->get('enable_cart');
         $this->assign('manageEventLinks', CRM_Event_Page_ManageEvent::tabs($enableCart));
     }
     return parent::run();
 }
Example #9
0
 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     //set as Primary participant
     $params['is_primary'] = 1;
     if ($this->_values['event']['is_pay_later'] && (!array_key_exists('hidden_processor', $params) || $params['payment_processor_id'] == 0)) {
         $params['is_pay_later'] = 1;
     } else {
         $params['is_pay_later'] = 0;
     }
     $this->set('is_pay_later', $params['is_pay_later']);
     // assign pay later stuff
     $this->_params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE);
     $this->assign('is_pay_later', $params['is_pay_later']);
     if ($params['is_pay_later']) {
         $this->assign('pay_later_text', $this->_values['event']['pay_later_text']);
         $this->assign('pay_later_receipt', $this->_values['event']['pay_later_receipt']);
     }
     if (!$this->_allowConfirmation) {
         // check if the participant is already registered
         if (!$this->_skipDupeRegistrationCheck) {
             $params['contact_id'] = self::checkRegistration($params, $this, FALSE, TRUE, TRUE);
         }
     }
     if (!empty($params['image_URL'])) {
         CRM_Contact_BAO_Contact::processImageParams($params);
     }
     //carry campaign to partcipants.
     if (array_key_exists('participant_campaign_id', $params)) {
         $params['campaign_id'] = $params['participant_campaign_id'];
     } else {
         $params['campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
     }
     //hack to allow group to register w/ waiting
     $primaryParticipantCount = self::getParticipantCount($this, $params);
     $totalParticipants = $primaryParticipantCount;
     if (!empty($params['additional_participants'])) {
         $totalParticipants += $params['additional_participants'];
     }
     if (!$this->_allowConfirmation && !empty($params['bypass_payment']) && is_numeric($this->_availableRegistrations) && $totalParticipants > $this->_availableRegistrations) {
         $this->_allowWaitlist = TRUE;
         $this->set('allowWaitlist', TRUE);
     }
     //carry participant id if pre-registered.
     if ($this->_allowConfirmation && $this->_participantId) {
         $params['participant_id'] = $this->_participantId;
     }
     $params['defaultRole'] = 1;
     if (array_key_exists('participant_role', $params)) {
         $params['participant_role_id'] = $params['participant_role'];
     }
     if (array_key_exists('participant_role_id', $params)) {
         $params['defaultRole'] = 0;
     }
     if (empty($params['participant_role_id']) && $this->_values['event']['default_role_id']) {
         $params['participant_role_id'] = $this->_values['event']['default_role_id'];
     }
     $config = CRM_Core_Config::singleton();
     $params['currencyID'] = $config->defaultCurrency;
     if ($this->_values['event']['is_monetary']) {
         // we first reset the confirm page so it accepts new values
         $this->controller->resetPage('Confirm');
         //added for discount
         $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
         $params['amount_level'] = $this->getAmountLevel($params, $discountId);
         if (!empty($this->_values['discount'][$discountId])) {
             $params['discount_id'] = $discountId;
             $params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
         } elseif (empty($params['priceSetId'])) {
             if (!empty($params['amount'])) {
                 $params['amount'] = $this->_values['fee'][$params['amount']]['value'];
             } else {
                 $params['amount'] = '';
             }
         } else {
             $lineItem = array();
             CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem);
             if ($params['tax_amount']) {
                 $this->set('tax_amount', $params['tax_amount']);
             }
             $submittedLineItems = $this->get('lineItem');
             if (!empty($submittedLineItems) && is_array($submittedLineItems)) {
                 $submittedLineItems[0] = $lineItem;
             } else {
                 $submittedLineItems = array($lineItem);
             }
             $this->set('lineItem', $submittedLineItems);
             $this->set('lineItemParticipantsCount', array($primaryParticipantCount));
         }
         $this->set('amount', $params['amount']);
         $this->set('amount_level', $params['amount_level']);
         // generate and set an invoiceID for this transaction
         $invoiceID = md5(uniqid(rand(), TRUE));
         $this->set('invoiceID', $invoiceID);
         if ($this->_paymentProcessor) {
             $payment = $this->_paymentProcessor['object'];
             $payment->setBaseReturnUrl('civicrm/event/register');
         }
         // ContributeMode is a deprecated concept. It is short-hand for a bunch of
         // assumptions we are working to remove.
         $this->set('contributeMode', 'direct');
         // This code is duplicated multiple places and should be consolidated.
         if (isset($params["state_province_id-{$this->_bltID}"]) && $params["state_province_id-{$this->_bltID}"]) {
             $params["state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($params["state_province_id-{$this->_bltID}"]);
         }
         if (isset($params["country_id-{$this->_bltID}"]) && $params["country_id-{$this->_bltID}"]) {
             $params["country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($params["country_id-{$this->_bltID}"]);
         }
         if (isset($params['credit_card_exp_date'])) {
             $params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($params);
             $params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($params);
         }
         if ($this->_values['event']['is_monetary']) {
             $params['ip_address'] = CRM_Utils_System::ipAddress();
             $params['currencyID'] = $config->defaultCurrency;
             $params['invoiceID'] = $invoiceID;
         }
         $this->_params = $this->get('params');
         // Set the button so we know what
         $params['button'] = $this->controller->getButtonName();
         if (!empty($this->_params) && is_array($this->_params)) {
             $this->_params[0] = $params;
         } else {
             $this->_params = array();
             $this->_params[] = $params;
         }
         $this->set('params', $this->_params);
         if ($this->_paymentProcessor && $this->_paymentProcessor['object']->supports('preApproval') && !$this->_allowWaitlist && !$this->_requireApproval) {
             // The concept of contributeMode is deprecated - but still needs removal from the message templates.
             $this->set('contributeMode', 'express');
             // Send Event Name & Id in Params
             $params['eventName'] = $this->_values['event']['title'];
             $params['eventId'] = $this->_values['event']['id'];
             $params['cancelURL'] = CRM_Utils_System::url('civicrm/event/register', "_qf_Register_display=1&qfKey={$this->controller->_key}", TRUE, NULL, FALSE);
             if (CRM_Utils_Array::value('additional_participants', $params, FALSE)) {
                 $urlArgs = "_qf_Participant_1_display=1&rfp=1&qfKey={$this->controller->_key}";
             } else {
                 $urlArgs = "_qf_Confirm_display=1&rfp=1&qfKey={$this->controller->_key}";
             }
             $params['returnURL'] = CRM_Utils_System::url('civicrm/event/register', $urlArgs, TRUE, NULL, FALSE);
             $params['invoiceID'] = $invoiceID;
             $params['component'] = 'event';
             $this->handlePreApproval($params);
         } elseif ($this->_paymentProcessor && $this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_NOTIFY) {
             // The concept of contributeMode is deprecated - but still needs removal from the message templates.
             $this->set('contributeMode', 'notify');
         }
     } else {
         $params['description'] = ts('Online Event Registration') . ' ' . $this->_values['event']['title'];
         $this->_params = array();
         $this->_params[] = $params;
         $this->set('params', $this->_params);
         if (empty($params['additional_participants']) && !$this->_values['event']['is_confirm_enabled']) {
             $this->processRegistration($this->_params);
         }
     }
     // If registering > 1 participant, give status message
     if (CRM_Utils_Array::value('additional_participants', $params, FALSE)) {
         $statusMsg = ts('Registration information for participant 1 has been saved.');
         CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success');
     }
 }
Example #10
0
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     //get the button name.
     $button = substr($this->controller->getButtonName(), -4);
     //take the participant instance.
     $addParticipantNum = substr($this->_name, 12);
     if ($button == 'skip') {
         //hack for free/zero amount event.
         if ($this->_resetAllowWaitlist) {
             $this->_allowWaitlist = false;
             $this->set('allowWaitlist', false);
             if ($this->_requireApproval) {
                 $status = ts("You have skipped last participant and which result into event having enough spaces, but your registration require approval, Once your registration has been reviewed, you will receive an email with a link to a web page where you can complete the registration process.");
             } else {
                 $status = ts("You have skipped last participant and which result into event having enough spaces, hence your group become as register participants though you selected on wait list.");
             }
             CRM_Core_Session::setStatus($status);
         }
         $this->_params[$addParticipantNum] = 'skip';
         if (isset($this->_lineItem)) {
             $this->_lineItem[$addParticipantNum] = 'skip';
         }
     } else {
         $params = $this->controller->exportValues($this->_name);
         if ($this->_values['event']['is_monetary']) {
             //added for discount
             require_once 'CRM/Core/BAO/Discount.php';
             $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
             if (!empty($this->_values['discount'][$discountId])) {
                 $params['discount_id'] = $discountId;
                 $params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label'];
                 $params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
             } else {
                 if (empty($params['priceSetId'])) {
                     $params['amount_level'] = $this->_values['fee'][$params['amount']]['label'];
                     $params['amount'] = $this->_values['fee'][$params['amount']]['value'];
                 } else {
                     $lineItem = array();
                     require_once 'CRM/Price/BAO/Set.php';
                     CRM_Price_BAO_Set::processAmount($this->_values['fee']['fields'], $params, $lineItem);
                     //build the line item..
                     if (array_key_exists($addParticipantNum, $this->_lineItem)) {
                         $this->_lineItem[$addParticipantNum] = $lineItem;
                     } else {
                         $this->_lineItem[] = $lineItem;
                     }
                 }
             }
         }
         if (!CRM_Utils_Array::value('participant_role_id', $params) && $this->_values['event']['default_role_id']) {
             $params['participant_role_id'] = $this->_values['event']['default_role_id'];
         }
         if (CRM_Utils_Array::value('is_pay_later', $this->_params[0])) {
             $params['is_pay_later'] = 1;
         }
         //carry additional participant id, contact id if pre-registered.
         if ($this->_allowConfirmation && $this->_additionalParticipantId) {
             $params['contact_id'] = $this->_contactID;
             $params['participant_id'] = $this->_additionalParticipantId;
         }
         //build the params array.
         if (array_key_exists($addParticipantNum, $this->_params)) {
             $this->_params[$addParticipantNum] = $params;
         } else {
             $this->_params[] = $params;
         }
     }
     //finally set the params.
     $this->set('params', $this->_params);
     //set the line item.
     if ($this->_lineItem) {
         $this->set('lineItem', $this->_lineItem);
     }
     $participantNo = count($this->_params);
     if ($button != 'skip') {
         require_once "CRM/Core/Session.php";
         $statusMsg = ts('Registration information for participant %1 has been saved.', array(1 => $participantNo));
         CRM_Core_Session::setStatus("{$statusMsg}");
     }
     //to check whether call processRegistration()
     if (!$this->_values['event']['is_monetary'] && CRM_Utils_Array::value('additional_participants', $this->_params[0]) && $this->isLastParticipant()) {
         require_once 'CRM/Event/Form/Registration/Register.php';
         CRM_Event_Form_Registration_Register::processRegistration($this->_params, null);
     }
 }
Example #11
0
 /**
  * This function sets the default values for the form in edit/view mode
  * the default values are retrieved from the database
  * 
  * @access public
  * @return None
  */
 static function setDefaultValues(&$form)
 {
     $defaults = array();
     if ($form->_eventId) {
         //get receipt text and contribution type
         $returnProperities = array('confirm_email_text', 'contribution_type_id');
         $details = array();
         CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $form->_eventId, $details, $returnProperities);
         $defaults[$form->_pId]['contribution_type_id'] = $details[$form->_eventId]['contribution_type_id'];
     }
     if ($form->_pId) {
         $ids = array();
         $params = array('id' => $form->_pId);
         require_once "CRM/Event/BAO/Participant.php";
         CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
         if ($form->_action == CRM_Core_Action::UPDATE) {
             $discounts = array();
             if (!empty($form->_values['discount'])) {
                 foreach ($form->_values['discount'] as $key => $value) {
                     $discounts[$key] = $value['name'];
                 }
             }
             if ($form->_discountId) {
                 $form->assign('discount', $discounts[$defaults[$form->_pId]['discount_id']]);
             }
             $form->assign('fee_amount', $defaults[$form->_pId]['fee_amount']);
             $form->assign('fee_level', $defaults[$form->_pId]['fee_level']);
         }
         $defaults[$form->_pId]['send_receipt'] = 0;
     } else {
         $defaults[$form->_pId]['send_receipt'] = 1;
         if ($form->_eventId) {
             //set receipt text
             $defaults[$form->_pId]['receipt_text'] = $details[$form->_eventId]['confirm_email_text'];
         }
         list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults();
     }
     if ($form->_mode) {
         $fields = array();
         foreach ($form->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
         $names = array("first_name", "middle_name", "last_name", "street_address-{$form->_bltID}", "city-{$form->_bltID}", "postal_code-{$form->_bltID}", "country_id-{$form->_bltID}", "state_province_id-{$form->_bltID}");
         foreach ($names as $name) {
             $fields[$name] = 1;
         }
         $fields["state_province-{$form->_bltID}"] = 1;
         $fields["country-{$form->_bltID}"] = 1;
         $fields["email-{$form->_bltID}"] = 1;
         $fields["email-Primary"] = 1;
         require_once "CRM/Core/BAO/UFGroup.php";
         if ($form->_contactID) {
             CRM_Core_BAO_UFGroup::setProfileDefaults($form->_contactID, $fields, $form->_defaults);
         }
         // use primary email address if billing email address is empty
         if (empty($form->_defaults["email-{$form->_bltID}"]) && !empty($form->_defaults["email-Primary"])) {
             $defaults[$form->_pId]["email-{$form->_bltID}"] = $form->_defaults["email-Primary"];
         }
         foreach ($names as $name) {
             if (!empty($form->_defaults[$name])) {
                 $defaults[$form->_pId]["billing_" . $name] = $form->_defaults[$name];
             }
         }
     }
     require_once 'CRM/Price/BAO/Set.php';
     if ($priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $form->_eventId)) {
         // get price set default values, CRM-4090
         if (in_array(get_class($form), array('CRM_Event_Form_Registration_Register', 'CRM_Event_Form_Registration_AdditionalParticipant'))) {
             $priceSetValues = self::setDefaultPriceSet($form->_pId, $form->_eventId);
             if (!empty($priceSetValues)) {
                 $defaults[$form->_pId] = array_merge($defaults[$form->_pId], $priceSetValues);
             }
         }
         if ($form->_action == CRM_Core_Action::ADD) {
             foreach ($form->_priceSet['fields'] as $key => $val) {
                 foreach ($val['options'] as $keys => $values) {
                     if ($values['is_default']) {
                         if ($val['html_type'] == 'CheckBox') {
                             $defaults[$form->_pId]["price_{$key}"][$keys] = 1;
                         } else {
                             $defaults[$form->_pId]["price_{$key}"] = $keys;
                         }
                     }
                 }
             }
         }
         $form->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
         if ($form->_action == CRM_Core_Action::UPDATE) {
             $fee_level = $defaults[$form->_pId]['fee_level'];
             CRM_Event_BAO_Participant::fixEventLevel($fee_level);
             $form->assign("fee_level", $fee_level);
             $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
         }
     } else {
         $optionGroupId = null;
         // if user has selected discount use that to set default
         if (isset($form->_discountId)) {
             $defaults[$form->_pId]['discount_id'] = $form->_discountId;
             //hack to set defaults for already selected discount value
             if ($form->_action == CRM_Core_Action::UPDATE && !$form->_originalDiscountId) {
                 $form->_originalDiscountId = $defaults[$form->_pId]['discount_id'];
                 if ($form->_originalDiscountId) {
                     $optionGroupId = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_Discount", $form->_originalDiscountId, 'option_group_id');
                     $defaults[$form->_pId]['discount_id'] = $form->_originalDiscountId;
                 }
             }
         }
         if ($form->_action == CRM_Core_Action::ADD) {
             // this case is for add mode, where we show discount automatically
             if (!isset($form->_discountId)) {
                 require_once 'CRM/Core/BAO/Discount.php';
                 $discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event');
             } else {
                 $discountId = $form->_discountId;
             }
             if ($form->_eventId && $discountId) {
                 $defaultDiscountId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $form->_eventId, 'default_discount_fee_id');
                 if ($defaultDiscountId) {
                     $discountKey = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_OptionValue", $defaultDiscountId, 'weight');
                 }
                 $defaults[$form->_pId]['discount_id'] = $discountId;
                 $defaults[$form->_pId]['amount'] = key(array_slice($form->_values['discount'][$discountId], $discountKey - 1, $discountKey, true));
                 $optionGroupId = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_Discount", $discountId, 'option_group_id');
             } else {
                 if ($form->_eventId) {
                     $defaults[$form->_pId]['amount'] = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $form->_eventId, 'default_fee_id');
                 }
             }
         }
         if (CRM_Utils_Array::value('event_id', $defaults[$form->_pId]) && ($form->_action == CRM_Core_Action::UPDATE || $form->_allowConfirmation)) {
             if (!empty($form->_feeBlock)) {
                 $feeLevel = CRM_Utils_Array::value('fee_level', $defaults[$form->_pId]);
                 $feeAmount = CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]);
                 foreach ($form->_feeBlock as $amountId => $amountInfo) {
                     if ($amountInfo['label'] == $feeLevel && $amountInfo['value'] == $feeAmount) {
                         $defaults[$form->_pId]['amount'] = $amountInfo['amount_id'];
                     }
                     // if amount is not set do fuzzy matching
                     if (!isset($defaults[$form->_pId]['amount'])) {
                         // if only level use that
                         if ($amountInfo['label'] == $feeLevel) {
                             $defaults[$form->_pId]['amount'] = $amountInfo['amount_id'];
                         } else {
                             if (strpos($feeLevel, $amountInfo['label']) !== false) {
                                 $defaults[$form->_pId]['amount'] = $amountInfo['amount_id'];
                             } else {
                                 if ($amountInfo['value'] == $feeAmount) {
                                     // if amount matches use that
                                     $defaults[$form->_pId]['amount'] = $amountInfo['amount_id'];
                                 }
                             }
                         }
                     }
                 }
             }
             if (!isset($defaults[$form->_pId]['amount'])) {
                 // keeping the old code too
                 if (!$optionGroupId) {
                     $optionGroupId = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_OptionGroup", 'civicrm_event.amount.' . $defaults[$form->_pId]['event_id'], 'id', 'name');
                 }
                 $optionParams = array('option_group_id' => $optionGroupId, 'label' => CRM_Utils_Array::value('fee_level', $defaults[$form->_pId]));
                 CRM_Core_BAO_CustomOption::retrieve($optionParams, $params);
                 $defaults[$form->_pId]['amount'] = $params['id'];
             }
         }
         $form->assign("amountId", $defaults[$form->_pId]['amount']);
     }
     //CRM-4453
     $form->assign('fee_currency', $defaults[$form->_pId]['participant_fee_currency']);
     // CRM-4395
     if ($contriId = $form->get('onlinePendingContributionId')) {
         require_once 'CRM/Contribute/DAO/Contribution.php';
         $contribution =& new CRM_Contribute_DAO_Contribution();
         $contribution->id = $contriId;
         $contribution->find(true);
         foreach (array('contribution_type_id', 'payment_instrument_id', 'contribution_status_id', 'receive_date') as $f) {
             $defaults[$form->_pId][$f] = $contribution->{$f};
         }
     }
     return $defaults[$form->_pId];
 }
Example #12
0
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     //set as Primary participant
     $params['is_primary'] = 1;
     //hack to allow group to register w/ waiting
     if (!$this->_allowConfirmation && CRM_Utils_Array::value('bypass_payment', $params) && is_numeric($this->_availableRegistrations) && CRM_Utils_Array::value('additional_participants', $params) >= $this->_availableRegistrations) {
         $this->_allowWaitlist = true;
         $this->set('allowWaitlist', true);
     }
     //carry participant id if pre-registered.
     if ($this->_allowConfirmation && $this->_participantId) {
         $params['participant_id'] = $this->_participantId;
     }
     $params['defaultRole'] = 1;
     if (array_key_exists('participant_role_id', $params)) {
         $params['defaultRole'] = 0;
     }
     if (!CRM_Utils_Array::value('participant_role_id', $params) && $this->_values['event']['default_role_id']) {
         $params['participant_role_id'] = $this->_values['event']['default_role_id'];
     }
     if ($this->_values['event']['is_monetary']) {
         $config =& CRM_Core_Config::singleton();
         // we first reset the confirm page so it accepts new values
         $this->controller->resetPage('Confirm');
         // get the submitted form values.
         $params['currencyID'] = $config->defaultCurrency;
         //added for discount
         require_once 'CRM/Core/BAO/Discount.php';
         $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
         if (!empty($this->_values['discount'][$discountId])) {
             $params['discount_id'] = $discountId;
             $params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label'];
             $params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
         } else {
             if (empty($params['priceSetId'])) {
                 $params['amount_level'] = $this->_values['fee'][$params['amount']]['label'];
                 $params['amount'] = $this->_values['fee'][$params['amount']]['value'];
             } else {
                 $lineItem = array();
                 require_once "CRM/Price/BAO/Set.php";
                 CRM_Price_BAO_Set::processAmount($this->_values['fee']['fields'], $params, $lineItem);
                 $priceSet = array();
                 $priceSet[] = $lineItem;
                 $this->set('lineItem', $priceSet);
             }
         }
         $this->set('amount', $params['amount']);
         $this->set('amount_level', $params['amount_level']);
         // generate and set an invoiceID for this transaction
         $invoiceID = md5(uniqid(rand(), true));
         $this->set('invoiceID', $invoiceID);
         if (is_array($this->_paymentProcessor)) {
             $payment =& CRM_Core_Payment::singleton($this->_mode, 'Event', $this->_paymentProcessor, $this);
         }
         // default mode is direct
         $this->set('contributeMode', 'direct');
         if (isset($params["state_province_id-{$this->_bltID}"]) && $params["state_province_id-{$this->_bltID}"]) {
             $params["state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($params["state_province_id-{$this->_bltID}"]);
         }
         if (isset($params["country_id-{$this->_bltID}"]) && $params["country_id-{$this->_bltID}"]) {
             $params["country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($params["country_id-{$this->_bltID}"]);
         }
         if (isset($params['credit_card_exp_date'])) {
             $params['year'] = $params['credit_card_exp_date']['Y'];
             $params['month'] = $params['credit_card_exp_date']['M'];
         }
         if ($this->_values['event']['is_monetary']) {
             $params['ip_address'] = CRM_Utils_System::ipAddress();
             $params['currencyID'] = $config->defaultCurrency;
             $params['payment_action'] = 'Sale';
             $params['invoiceID'] = $invoiceID;
         }
         $this->_params = array();
         $this->_params[] = $params;
         $this->set('params', $this->_params);
         if ($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) {
             //get the button name
             $buttonName = $this->controller->getButtonName();
             if (in_array($buttonName, array($this->_expressButtonName, $this->_expressButtonName . '_x', $this->_expressButtonName . '_y')) && !isset($params['is_pay_later']) && !$this->_allowWaitlist && !$this->_requireApproval) {
                 $this->set('contributeMode', 'express');
                 // Send Event Name & Id in Params
                 $params['eventName'] = $this->_values['event']['title'];
                 $params['eventId'] = $this->_values['event']['id'];
                 $params['cancelURL'] = CRM_Utils_System::url('civicrm/event/register', '_qf_Register_display=1', true, null, false);
                 if (CRM_Utils_Array::value('additional_participants', $params, false)) {
                     $urlArgs = "_qf_Participant_1_display=1&rfp=1&qfKey={$this->controller->_key}";
                 } else {
                     $urlArgs = '_qf_Confirm_display=1&rfp=1';
                 }
                 $params['returnURL'] = CRM_Utils_System::url('civicrm/event/register', $urlArgs, true, null, false);
                 $params['invoiceID'] = $invoiceID;
                 //default action is Sale
                 $params['payment_action'] = 'Sale';
                 $token = $payment->setExpressCheckout($params);
                 if (is_a($token, 'CRM_Core_Error')) {
                     CRM_Core_Error::displaySessionError($token);
                     CRM_Utils_System::redirect($params['cancelURL']);
                 }
                 $this->set('token', $token);
                 $paymentURL = $this->_paymentProcessor['url_site'] . "/cgi-bin/webscr?cmd=_express-checkout&token={$token}";
                 CRM_Utils_System::redirect($paymentURL);
             }
         } else {
             if ($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_NOTIFY) {
                 $this->set('contributeMode', 'notify');
             }
         }
     } else {
         $session =& CRM_Core_Session::singleton();
         $contactID = $session->get('userID');
         $params['description'] = ts('Online Event Registration') . ' ' . $this->_values['event']['title'];
         $this->_params = array();
         $this->_params[] = $params;
         $this->set('params', $this->_params);
         if (!CRM_Utils_Array::value('additional_participants', $params)) {
             self::processRegistration($this->_params, $contactID);
         }
     }
     // If registering > 1 participant, give status message
     if (CRM_Utils_Array::value('additional_participants', $params, false)) {
         require_once "CRM/Core/Session.php";
         $statusMsg = ts('Registration information for participant 1 has been saved.');
         CRM_Core_Session::setStatus("{$statusMsg}");
     }
 }
 /**
  * This function sets the default values for the form in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return None
  */
 static function setDefaultValues(&$form)
 {
     $defaults = array();
     if ($form->_eventId) {
         //get receipt text and contribution type
         $returnProperities = array('confirm_email_text', 'contribution_type_id', 'campaign_id');
         $details = array();
         CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $form->_eventId, $details, $returnProperities);
         if (CRM_Utils_Array::value('contribution_type_id', $details[$form->_eventId])) {
             $defaults[$form->_pId]['contribution_type_id'] = $details[$form->_eventId]['contribution_type_id'];
         }
     }
     if ($form->_pId) {
         $ids = array();
         $params = array('id' => $form->_pId);
         CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
         if ($form->_action == CRM_Core_Action::UPDATE) {
             $discounts = array();
             if (!empty($form->_values['discount'])) {
                 foreach ($form->_values['discount'] as $key => $value) {
                     $discounts[$key] = $value['name'];
                 }
             }
             if ($form->_discountId) {
                 $form->assign('discount', $discounts[$defaults[$form->_pId]['discount_id']]);
             }
             $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
             $form->assign('fee_level', CRM_Utils_Array::value('fee_level', $defaults[$form->_pId]));
         }
         $defaults[$form->_pId]['send_receipt'] = 0;
     } else {
         $defaults[$form->_pId]['send_receipt'] = 1;
         if ($form->_eventId && CRM_Utils_Array::value('confirm_email_text', $details[$form->_eventId])) {
             //set receipt text
             $defaults[$form->_pId]['receipt_text'] = $details[$form->_eventId]['confirm_email_text'];
         }
         list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults();
     }
     if ($form->_mode) {
         $fields = array();
         foreach ($form->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
         $names = array('first_name', 'middle_name', 'last_name', "street_address-{$form->_bltID}", "city-{$form->_bltID}", "postal_code-{$form->_bltID}", "country_id-{$form->_bltID}", "state_province_id-{$form->_bltID}");
         foreach ($names as $name) {
             $fields[$name] = 1;
         }
         $fields["state_province-{$form->_bltID}"] = 1;
         $fields["country-{$form->_bltID}"] = 1;
         $fields["email-{$form->_bltID}"] = 1;
         $fields['email-Primary'] = 1;
         if ($form->_contactId) {
             CRM_Core_BAO_UFGroup::setProfileDefaults($form->_contactId, $fields, $form->_defaults);
         }
         // use primary email address if billing email address is empty
         if (empty($form->_defaults["email-{$form->_bltID}"]) && !empty($form->_defaults['email-Primary'])) {
             $defaults[$form->_pId]["email-{$form->_bltID}"] = $form->_defaults['email-Primary'];
         }
         foreach ($names as $name) {
             if (!empty($form->_defaults[$name])) {
                 $defaults[$form->_pId]['billing_' . $name] = $form->_defaults[$name];
             }
         }
         $config = CRM_Core_Config::singleton();
         // set default country from config if no country set
         if (!CRM_Utils_Array::value("billing_country_id-{$form->_bltID}", $defaults[$form->_pId])) {
             $defaults[$form->_pId]["billing_country_id-{$form->_bltID}"] = $config->defaultContactCountry;
         }
         //             // hack to simplify credit card entry for testing
         //             $defaults[$form->_pId]['credit_card_type']     = 'Visa';
         //             $defaults[$form->_pId]['credit_card_number']   = '4807731747657838';
         //             $defaults[$form->_pId]['cvv2']                 = '000';
         //             $defaults[$form->_pId]['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' );
     }
     if ($priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $form->_eventId)) {
         // get price set default values, CRM-4090
         if (in_array(get_class($form), array('CRM_Event_Form_Participant', 'CRM_Event_Form_Registration_Register', 'CRM_Event_Form_Registration_AdditionalParticipant'))) {
             $priceSetValues = self::setDefaultPriceSet($form->_pId, $form->_eventId);
             if (!empty($priceSetValues)) {
                 $defaults[$form->_pId] = array_merge($defaults[$form->_pId], $priceSetValues);
             }
         }
         if ($form->_action == CRM_Core_Action::ADD && CRM_Utils_Array::value('fields', $form->_priceSet)) {
             foreach ($form->_priceSet['fields'] as $key => $val) {
                 foreach ($val['options'] as $keys => $values) {
                     if ($values['is_default']) {
                         if (get_class($form) != 'CRM_Event_Form_Participant' && CRM_Utils_Array::value('is_full', $values)) {
                             continue;
                         }
                         if ($val['html_type'] == 'CheckBox') {
                             $defaults[$form->_pId]["price_{$key}"][$keys] = 1;
                         } else {
                             $defaults[$form->_pId]["price_{$key}"] = $keys;
                         }
                     }
                 }
             }
         }
         $form->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
         if ($form->_action == CRM_Core_Action::UPDATE) {
             $fee_level = $defaults[$form->_pId]['fee_level'];
             CRM_Event_BAO_Participant::fixEventLevel($fee_level);
             $form->assign('fee_level', $fee_level);
             $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
         }
     } else {
         $optionGroupId = NULL;
         // if user has selected discount use that to set default
         if (isset($form->_discountId)) {
             $defaults[$form->_pId]['discount_id'] = $form->_discountId;
             //hack to set defaults for already selected discount value
             if ($form->_action == CRM_Core_Action::UPDATE && !$form->_originalDiscountId) {
                 $form->_originalDiscountId = $defaults[$form->_pId]['discount_id'];
                 if ($form->_originalDiscountId) {
                     $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $form->_originalDiscountId, 'option_group_id');
                     $defaults[$form->_pId]['discount_id'] = $form->_originalDiscountId;
                 }
             }
         }
         if ($form->_action == CRM_Core_Action::ADD) {
             // this case is for add mode, where we show discount automatically
             if (!isset($form->_discountId)) {
                 $discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event');
             } else {
                 $discountId = $form->_discountId;
             }
             if ($form->_eventId && $discountId) {
                 $defaultDiscountId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $form->_eventId, 'default_discount_fee_id');
                 if ($defaultDiscountId) {
                     $discountKey = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $defaultDiscountId, 'weight');
                 }
                 $defaults[$form->_pId]['discount_id'] = $discountId;
                 $defaults[$form->_pId]['amount'] = key(array_slice($form->_values['discount'][$discountId], $discountKey - 1, $discountKey, TRUE));
                 $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'option_group_id');
             } else {
                 if ($form->_eventId) {
                     $defaults[$form->_pId]['amount'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $form->_eventId, 'default_fee_id');
                 }
             }
         }
         if (CRM_Utils_Array::value('event_id', $defaults[$form->_pId]) && ($form->_action == CRM_Core_Action::UPDATE || $form->_allowConfirmation)) {
             if (!empty($form->_feeBlock)) {
                 $feeLevel = CRM_Utils_Array::value('fee_level', $defaults[$form->_pId]);
                 $feeAmount = CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]);
                 foreach ($form->_feeBlock as $amountId => $amountInfo) {
                     if ($amountInfo['label'] == $feeLevel && $amountInfo['value'] == $feeAmount) {
                         $defaults[$form->_pId]['amount'] = $amountInfo['amount_id'];
                     }
                     // if amount is not set do fuzzy matching
                     if (!isset($defaults[$form->_pId]['amount'])) {
                         // if only level use that
                         if ($amountInfo['label'] == $feeLevel) {
                             $defaults[$form->_pId]['amount'] = $amountInfo['amount_id'];
                         } elseif (strpos($feeLevel, $amountInfo['label']) !== FALSE) {
                             $defaults[$form->_pId]['amount'] = $amountInfo['amount_id'];
                         } elseif ($amountInfo['value'] == $feeAmount) {
                             // if amount matches use that
                             $defaults[$form->_pId]['amount'] = $amountInfo['amount_id'];
                         }
                     }
                 }
             }
         }
         $form->assign('amountId', CRM_Utils_Array::value('amount', $defaults[$form->_pId]));
     }
     //CRM-4453
     if (CRM_Utils_Array::value('participant_fee_currency', $defaults[$form->_pId])) {
         $form->assign('fee_currency', $defaults[$form->_pId]['participant_fee_currency']);
     }
     // CRM-4395
     if ($contriId = $form->get('onlinePendingContributionId')) {
         $contribution = new CRM_Contribute_DAO_Contribution();
         $contribution->id = $contriId;
         $contribution->find(TRUE);
         foreach (array('contribution_type_id', 'payment_instrument_id', 'contribution_status_id', 'receive_date', 'total_amount') as $f) {
             if ($f == 'receive_date') {
                 list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults($contribution->{$f});
             } else {
                 $defaults[$form->_pId][$f] = $contribution->{$f};
             }
         }
     }
     return $defaults[$form->_pId];
 }