Пример #1
0
 /**
  * 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']);
         }
     }
 }
 /**
  * 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);
     }
 }
Пример #3
0
 /**
  * This function is to make a copy of a Event, including
  * all the fields in the event Wizard
  *
  * @param int $id the event id to copy
  *
  * @return void
  * @access public
  */
 static function copy($id)
 {
     $defaults = $eventValues = array();
     //get the require event values.
     $eventParams = array('id' => $id);
     $returnProperties = array('loc_block_id', 'is_show_location', 'default_fee_id', 'default_discount_fee_id');
     CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $eventParams, $eventValues, $returnProperties);
     // since the location is sharable, lets use the same loc_block_id.
     $locBlockId = CRM_Utils_Array::value('loc_block_id', $eventValues);
     $fieldsFix = array('prefix' => array('title' => ts('Copy of') . ' '));
     if (!CRM_Utils_Array::value('is_show_location', $eventValues)) {
         $fieldsFix['prefix']['is_show_location'] = 0;
     }
     $copyEvent =& CRM_Core_DAO::copyGeneric('CRM_Event_DAO_Event', array('id' => $id), array('loc_block_id' => $locBlockId ? $locBlockId : null), $fieldsFix);
     $copyPriceSet =& CRM_Core_DAO::copyGeneric('CRM_Price_DAO_SetEntity', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id));
     $copyUF =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id));
     $copyTellFriend =& CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id));
     require_once "CRM/Core/BAO/OptionGroup.php";
     //copy option Group and values
     $copyEvent->default_fee_id = CRM_Core_BAO_OptionGroup::copyValue('event', $id, $copyEvent->id, CRM_Utils_Array::value('default_fee_id', $eventValues));
     //copy discounted fee levels
     require_once 'CRM/Core/BAO/Discount.php';
     $discount = CRM_Core_BAO_Discount::getOptionGroup($id, 'civicrm_event');
     if (!empty($discount)) {
         foreach ($discount as $discountOptionGroup) {
             $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $discountOptionGroup);
             $length = substr_compare($name, "civicrm_event.amount." . $id, 0);
             $discountSuffix = substr($name, $length * -1);
             $copyEvent->default_discount_fee_id = CRM_Core_BAO_OptionGroup::copyValue('event', $id, $copyEvent->id, CRM_Utils_Array::value('default_discount_fee_id', $eventValues), $discountSuffix);
         }
     }
     //copy custom data
     require_once 'CRM/Core/BAO/CustomGroup.php';
     $extends = array('event');
     $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(null, null, $extends);
     if ($groupTree) {
         foreach ($groupTree as $groupID => $group) {
             $table[$groupTree[$groupID]['table_name']] = array('entity_id');
             foreach ($group['fields'] as $fieldID => $field) {
                 $table[$groupTree[$groupID]['table_name']][] = $groupTree[$groupID]['fields'][$fieldID]['column_name'];
             }
         }
         foreach ($table as $tableName => $tableColumns) {
             $insert = 'INSERT INTO ' . $tableName . ' (' . implode(', ', $tableColumns) . ') ';
             $tableColumns[0] = $copyEvent->id;
             $select = 'SELECT ' . implode(', ', $tableColumns);
             $from = ' FROM ' . $tableName;
             $where = " WHERE {$tableName}.entity_id = {$id}";
             $query = $insert . $select . $from . $where;
             $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
         }
     }
     $copyEvent->save();
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::copy('Event', $copyEvent);
     return $copyEvent;
 }
Пример #4
0
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     //format params
     $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']);
     $params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], $params['end_date_time'], true);
     $params['has_waitlist'] = CRM_Utils_Array::value('has_waitlist', $params, false);
     $params['is_map'] = CRM_Utils_Array::value('is_map', $params, false);
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false);
     $params['is_public'] = CRM_Utils_Array::value('is_public', $params, false);
     $params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, false);
     $params['id'] = $this->_id;
     //new event, so lets set the created_id
     if ($this->_action & CRM_Core_Action::ADD) {
         $session =& CRM_Core_Session::singleton();
         $params['created_id'] = $session->get('userID');
         $params['created_date'] = date('YmdHis');
     }
     $customFields = CRM_Core_BAO_CustomField::getFields('Event', false, false, CRM_Utils_Array::value('event_type_id', $params));
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Event');
     require_once 'CRM/Event/BAO/Event.php';
     // copy all not explicitely set $params keys from the template (if it should be sourced)
     if (CRM_Utils_Array::value('template_id', $params)) {
         $defaults = array();
         $templateParams = array('id' => $params['template_id']);
         CRM_Event_BAO_Event::retrieve($templateParams, $defaults);
         unset($defaults['id']);
         unset($defaults['default_fee_id']);
         unset($defaults['default_discount_fee_id']);
         foreach ($defaults as $key => $value) {
             if (!isset($params[$key])) {
                 $params[$key] = $value;
             }
         }
     }
     $event = CRM_Event_BAO_Event::create($params);
     // now that we have the event’s id, do some more template-based stuff
     if (CRM_Utils_Array::value('template_id', $params)) {
         // copy event fees
         $ogParams = array('name' => "civicrm_event.amount.{$event->id}");
         $defaults = array();
         require_once 'CRM/Core/BAO/OptionGroup.php';
         if (is_null(CRM_Core_BAO_OptionGroup::retrieve($ogParams, $defaults))) {
             // Copy the Main Event Fees
             CRM_Core_BAO_OptionGroup::copyValue('event', $params['template_id'], $event->id);
             // Copy the Discount option Group and Values
             require_once 'CRM/Core/BAO/Discount.php';
             $optionGroupIds = CRM_Core_BAO_Discount::getOptionGroup($params['template_id'], "civicrm_event");
             foreach ($optionGroupIds as $id) {
                 $discountSuffix = '.discount.' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $id, 'label');
                 CRM_Core_BAO_OptionGroup::copyValue('event', $params['template_id'], $event->id, false, $discountSuffix);
             }
         }
         // copy price sets if any
         require_once 'CRM/Price/BAO/Set.php';
         $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $params['template_id']);
         if ($priceSetId) {
             CRM_Price_BAO_Set::addTo('civicrm_event', $event->id, $priceSetId);
         }
         // link profiles if none linked
         $ufParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id);
         require_once 'CRM/Core/BAO/UFJoin.php';
         if (!CRM_Core_BAO_UFJoin::findUFGroupId($ufParams)) {
             CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $params['template_id'], 'entity_table' => 'civicrm_event'), array('entity_id' => $event->id));
         }
         // if no Tell-a-Friend defined, check whether there’s one for template and copy if so
         $tafParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id);
         require_once 'CRM/Friend/BAO/Friend.php';
         if (!CRM_Friend_BAO_Friend::getValues($tafParams)) {
             $tafParams['entity_id'] = $params['template_id'];
             if (CRM_Friend_BAO_Friend::getValues($tafParams)) {
                 $tafParams['entity_id'] = $event->id;
                 CRM_Friend_BAO_Friend::addTellAFriend($tafParams);
             }
         }
     }
     $this->set('id', $event->id);
     if ($this->_action & CRM_Core_Action::ADD) {
         $urlParam = "action=update&reset=1&subPage=Location&id={$event->id}";
         // special case for 'Save and Done' consistency.
         if ($this->controller->getButtonName('submit') == "_qf_EventInfo_upload_done") {
             $urlParam = "action=update&reset=1&id={$event->id}";
             CRM_Core_Session::setStatus(ts("'%1' information has been saved.", array(1 => $this->getTitle())));
         }
         CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), $urlParam));
     }
     parent::endPostProcess();
 }
Пример #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();
 }
Пример #6
0
 /**
  * Process the form.
  */
 public function postProcess()
 {
     $eventTitle = '';
     $params = $this->exportValues();
     $this->set('discountSection', 0);
     if (!empty($_POST['_qf_Fee_submit'])) {
         $this->buildAmountLabel();
         $this->set('discountSection', 2);
         return;
     }
     if (!empty($params['payment_processor'])) {
         $params['payment_processor'] = str_replace(',', CRM_Core_DAO::VALUE_SEPARATOR, $params['payment_processor']);
     } else {
         $params['payment_processor'] = 'null';
     }
     $params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0);
     $params['is_billing_required'] = CRM_Utils_Array::value('is_billing_required', $params, 0);
     if ($this->_id) {
         // delete all the prior label values or discounts in the custom options table
         // and delete a price set if one exists
         //@todo note that this removes the reference from existing participants -
         // even where there is not change - redress?
         // note that a more tentative form of this is invoked by passing price_set_id as an array
         // to event.create see CRM-14069
         // @todo get all of this logic out of form layer (currently partially in BAO/api layer)
         if (CRM_Price_BAO_PriceSet::removeFrom('civicrm_event', $this->_id)) {
             CRM_Core_BAO_Discount::del($this->_id, 'civicrm_event');
         }
     }
     if ($params['is_monetary']) {
         if (!empty($params['price_set_id'])) {
             //@todo this is now being done in the event BAO if passed price_set_id as an array
             // per notes on that fn - looking at the api converting to an array
             // so calling via the api may cause this to be done in the api
             CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $params['price_set_id']);
             if (!empty($params['price_field_id'])) {
                 $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $params['price_field_id'], 'price_set_id');
                 CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0);
             }
         } else {
             // if there are label / values, create custom options for them
             $labels = CRM_Utils_Array::value('label', $params);
             $values = CRM_Utils_Array::value('value', $params);
             $default = CRM_Utils_Array::value('default', $params);
             $options = array();
             if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
                 for ($i = 1; $i < self::NUM_OPTION; $i++) {
                     if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) {
                         $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                     }
                 }
                 if (!empty($options)) {
                     $params['default_fee_id'] = NULL;
                     if (empty($params['price_set_id'])) {
                         if (empty($params['price_field_id'])) {
                             $setParams['title'] = $eventTitle = $this->_isTemplate ? $this->_defaultValues['template_title'] : $this->_defaultValues['title'];
                             $eventTitle = strtolower(CRM_Utils_String::munge($eventTitle, '_', 245));
                             if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle, 'id', 'name')) {
                                 $setParams['name'] = $eventTitle;
                             } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $this->_id, 'id', 'name')) {
                                 $setParams['name'] = $eventTitle . '_' . $this->_id;
                             } else {
                                 $timeSec = explode('.', microtime(TRUE));
                                 $setParams['name'] = $eventTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
                             }
                             $setParams['is_quick_config'] = 1;
                             $setParams['financial_type_id'] = $params['financial_type_id'];
                             $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
                             $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                             $fieldParams['name'] = strtolower(CRM_Utils_String::munge($params['fee_label'], '_', 245));
                             $fieldParams['price_set_id'] = $priceSet->id;
                         } else {
                             foreach ($params['price_field_value'] as $arrayID => $fieldValueID) {
                                 if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) {
                                     CRM_Price_BAO_PriceFieldValue::setIsActive($fieldValueID, '0');
                                     unset($params['price_field_value'][$arrayID]);
                                 }
                             }
                             $fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params);
                             $fieldParams['option_id'] = $params['price_field_value'];
                             $priceSet = new CRM_Price_BAO_PriceSet();
                             $priceSet->id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('price_field_id', $params), 'price_set_id');
                             if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) {
                                 CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $priceSet->id, 'financial_type_id', $params['financial_type_id']);
                             }
                         }
                         $fieldParams['label'] = $params['fee_label'];
                         $fieldParams['html_type'] = 'Radio';
                         CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $priceSet->id);
                         $fieldParams['option_label'] = $params['label'];
                         $fieldParams['option_amount'] = $params['value'];
                         $fieldParams['financial_type_id'] = $params['financial_type_id'];
                         foreach ($options as $value) {
                             $fieldParams['option_weight'][$value['weight']] = $value['weight'];
                         }
                         $fieldParams['default_option'] = $params['default'];
                         $priceField = CRM_Price_BAO_PriceField::create($fieldParams);
                     }
                 }
             }
             $discountPriceSets = !empty($this->_defaultValues['discount_price_set']) ? $this->_defaultValues['discount_price_set'] : array();
             $discountFieldIDs = !empty($this->_defaultValues['discount_option_id']) ? $this->_defaultValues['discount_option_id'] : array();
             if (CRM_Utils_Array::value('is_discount', $params) == 1) {
                 // if there are discounted set of label / values,
                 // create custom options for them
                 $labels = CRM_Utils_Array::value('discounted_label', $params);
                 $values = CRM_Utils_Array::value('discounted_value', $params);
                 $default = CRM_Utils_Array::value('discounted_default', $params);
                 if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
                     for ($j = 1; $j <= self::NUM_DISCOUNT; $j++) {
                         $discountOptions = array();
                         for ($i = 1; $i < self::NUM_OPTION; $i++) {
                             if (!empty($labels[$i]) && !CRM_Utils_System::isNull(CRM_Utils_Array::value($j, $values[$i]))) {
                                 $discountOptions[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i][$j])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                             }
                         }
                         if (!empty($discountOptions)) {
                             $fieldParams = array();
                             $params['default_discount_fee_id'] = NULL;
                             $keyCheck = $j - 1;
                             $setParams = array();
                             if (empty($discountPriceSets[$keyCheck])) {
                                 if (!$eventTitle) {
                                     $eventTitle = strtolower(CRM_Utils_String::munge($this->_defaultValues['title'], '_', 200));
                                 }
                                 $setParams['title'] = $params['discount_name'][$j];
                                 if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $params['discount_name'][$j], 'id', 'name')) {
                                     $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j];
                                 } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id, 'id', 'name')) {
                                     $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id;
                                 } else {
                                     $timeSec = explode('.', microtime(TRUE));
                                     $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . date('is', $timeSec[0]) . $timeSec[1];
                                 }
                                 $setParams['is_quick_config'] = 1;
                                 $setParams['financial_type_id'] = $params['financial_type_id'];
                                 $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
                                 $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                                 $priceSetID = $priceSet->id;
                             } else {
                                 $priceSetID = $discountPriceSets[$j - 1];
                                 $setParams = array('title' => $params['discount_name'][$j], 'id' => $priceSetID);
                                 if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) {
                                     $setParams['financial_type_id'] = $params['financial_type_id'];
                                 }
                                 CRM_Price_BAO_PriceSet::create($setParams);
                                 unset($discountPriceSets[$j - 1]);
                                 $fieldParams['id'] = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceField', $priceSetID, 'id', 'price_set_id');
                             }
                             $fieldParams['name'] = $fieldParams['label'] = $params['fee_label'];
                             $fieldParams['is_required'] = 1;
                             $fieldParams['price_set_id'] = $priceSetID;
                             $fieldParams['html_type'] = 'Radio';
                             $fieldParams['financial_type_id'] = $params['financial_type_id'];
                             foreach ($discountOptions as $value) {
                                 $fieldParams['option_label'][$value['weight']] = $value['label'];
                                 $fieldParams['option_amount'][$value['weight']] = $value['value'];
                                 $fieldParams['option_weight'][$value['weight']] = $value['weight'];
                                 if (!empty($value['is_default'])) {
                                     $fieldParams['default_option'] = $value['weight'];
                                 }
                                 if (!empty($discountFieldIDs[$j]) && !empty($discountFieldIDs[$j][$value['weight']])) {
                                     $fieldParams['option_id'][$value['weight']] = $discountFieldIDs[$j][$value['weight']];
                                     unset($discountFieldIDs[$j][$value['weight']]);
                                 }
                             }
                             //create discount priceset
                             $priceField = CRM_Price_BAO_PriceField::create($fieldParams);
                             if (!empty($discountFieldIDs[$j])) {
                                 foreach ($discountFieldIDs[$j] as $fID) {
                                     CRM_Price_BAO_PriceFieldValue::setIsActive($fID, '0');
                                 }
                             }
                             $discountParams = array('entity_table' => 'civicrm_event', 'entity_id' => $this->_id, 'price_set_id' => $priceSetID, 'start_date' => CRM_Utils_Date::processDate($params['discount_start_date'][$j]), 'end_date' => CRM_Utils_Date::processDate($params['discount_end_date'][$j]));
                             CRM_Core_BAO_Discount::add($discountParams);
                         }
                     }
                 }
             }
             if (!empty($discountPriceSets)) {
                 foreach ($discountPriceSets as $setId) {
                     CRM_Price_BAO_PriceSet::setIsQuickConfig($setId, 0);
                 }
             }
         }
     } else {
         if (!empty($params['price_field_id'])) {
             $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $params['price_field_id'], 'price_set_id');
             CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0);
         }
         $params['financial_type_id'] = '';
         $params['is_pay_later'] = 0;
         $params['is_billing_required'] = 0;
     }
     //update 'is_billing_required'
     if (empty($params['is_pay_later'])) {
         $params['is_billing_required'] = FALSE;
     }
     //update events table
     $params['id'] = $this->_id;
     // skip update of financial type in price set
     $params['skipFinancialType'] = TRUE;
     CRM_Event_BAO_Event::add($params);
     // Update tab "disabled" css class
     $this->ajaxResponse['tabValid'] = !empty($params['is_monetary']);
     parent::endPostProcess();
 }
 /**
  * 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];
 }
Пример #8
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');
     }
 }
Пример #9
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;
     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');
     }
 }
Пример #10
0
 /**
  * Change is_quick_config priceSet to complex.
  *
  */
 public static function setIsQuickConfig()
 {
     $id = $context = NULL;
     if (!empty($_REQUEST['id'])) {
         $id = CRM_Utils_Type::escape($_REQUEST['id'], 'Integer');
     }
     if (!empty($_REQUEST['context'])) {
         $context = CRM_Utils_Type::escape($_REQUEST['context'], 'String');
     }
     // return false if $id is null and
     // $context is not civicrm_event or civicrm_contribution_page
     if (!$id || !in_array($context, array('civicrm_event', 'civicrm_contribution_page'))) {
         return FALSE;
     }
     $priceSetId = CRM_Price_BAO_PriceSet::getFor($context, $id, NULL);
     if ($priceSetId) {
         $result = CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetId, 0);
         if ($context == 'civicrm_event') {
             $sql = "UPDATE\n          civicrm_price_set cps\n          INNER JOIN civicrm_discount cd ON cd.price_set_id = cps.id\n          SET cps.is_quick_config = 0\n          WHERE cd.entity_id = (%1) AND cd.entity_table = 'civicrm_event' ";
             $params = array(1 => array($id, 'Integer'));
             CRM_Core_DAO::executeQuery($sql, $params);
             CRM_Core_BAO_Discount::del($id, $context);
         }
     }
     if (!$result) {
         $priceSetId = NULL;
     }
     CRM_Utils_JSON::output($priceSetId);
 }
Пример #11
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);
     }
 }
Пример #12
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];
 }
Пример #13
0
 /**
  * Process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $params = array();
     $params = $this->exportValues();
     $this->set('discountSection', 0);
     if (CRM_Utils_Array::value('_qf_Fee_submit', $_POST)) {
         $this->buildAmountLabel();
         $this->set('discountSection', 1);
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/manage', '#isDiscount'));
         return;
     }
     $params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0);
     if ($this->_id) {
         require_once 'CRM/Price/BAO/Set.php';
         // delete all the prior label values or discounts in the custom options table
         // and delete a price set if one exists
         if (!CRM_Price_BAO_Set::removeFrom('civicrm_event', $this->_id)) {
             require_once 'CRM/Core/OptionGroup.php';
             CRM_Core_OptionGroup::deleteAssoc("civicrm_event.amount.{$this->_id}");
             CRM_Core_OptionGroup::deleteAssoc("civicrm_event.amount.{$this->_id}.discount.%", "LIKE");
         }
     }
     if ($params['is_monetary']) {
         if ($params['price_set_id']) {
             CRM_Price_BAO_Set::addTo('civicrm_event', $this->_id, $params['price_set_id']);
         } else {
             // if there are label / values, create custom options for them
             $labels = CRM_Utils_Array::value('label', $params);
             $values = CRM_Utils_Array::value('value', $params);
             $default = CRM_Utils_Array::value('default', $params);
             $options = array();
             if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
                 for ($i = 1; $i < self::NUM_OPTION; $i++) {
                     if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) {
                         $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                     }
                 }
                 if (!empty($options)) {
                     $params['default_fee_id'] = null;
                     CRM_Core_OptionGroup::createAssoc("civicrm_event.amount.{$this->_id}", $options, $params['default_fee_id']);
                 }
             }
             if (CRM_Utils_Array::value('is_discount', $params) == 1) {
                 // if there are discounted set of label / values,
                 // create custom options for them
                 $labels = CRM_Utils_Array::value('discounted_label', $params);
                 $values = CRM_Utils_Array::value('discounted_value', $params);
                 $default = CRM_Utils_Array::value('discounted_default', $params);
                 if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
                     for ($j = 1; $j <= self::NUM_DISCOUNT; $j++) {
                         $discountOptions = array();
                         for ($i = 1; $i < self::NUM_OPTION; $i++) {
                             if (!empty($labels[$i]) && CRM_Utils_Array::value($j, $values[$i])) {
                                 $discountOptions[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i][$j])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                             }
                         }
                         if (!empty($discountOptions)) {
                             $params['default_discount_fee_id'] = null;
                             $discountOptionsGroupId = CRM_Core_OptionGroup::createAssoc("civicrm_event.amount.{$this->_id}.discount.{$params['discount_name'][$j]}", $discountOptions, $params['default_discount_fee_id'], $params['discount_name'][$j]);
                             $discountParams = array('entity_table' => 'civicrm_event', 'entity_id' => $this->_id, 'option_group_id' => $discountOptionsGroupId, 'start_date' => CRM_Utils_Date::format($params["discount_start_date"][$j]), 'end_date' => CRM_Utils_Date::format($params["discount_end_date"][$j]));
                             require_once 'CRM/Core/BAO/Discount.php';
                             CRM_Core_BAO_Discount::add($discountParams);
                         }
                     }
                 }
             }
         }
     } else {
         $params['contribution_type_id'] = '';
     }
     //update events table
     require_once 'CRM/Event/BAO/Event.php';
     $params['id'] = $this->_id;
     CRM_Event_BAO_Event::add($params);
     parent::endPostProcess();
 }
Пример #14
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}");
     }
 }
Пример #15
0
 /**
  * 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];
 }
Пример #16
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();
 }
Пример #17
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);
         }
     }
 }
Пример #18
0
 /**
  * Copy priceSet when event/contibution page is copied
  *
  * @param string $baoName
  *   BAO name.
  * @param int $id
  *   Old event/contribution page id.
  * @param int $newId
  *   Newly created event/contribution page id.
  */
 public static function copyPriceSet($baoName, $id, $newId)
 {
     $priceSetId = CRM_Price_BAO_PriceSet::getFor($baoName, $id);
     if ($priceSetId) {
         $isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config');
         if ($isQuickConfig) {
             $copyPriceSet = CRM_Price_BAO_PriceSet::copy($priceSetId);
             CRM_Price_BAO_PriceSet::addTo($baoName, $newId, $copyPriceSet->id);
         } else {
             $copyPriceSet =& CRM_Core_DAO::copyGeneric('CRM_Price_DAO_PriceSetEntity', array('entity_id' => $id, 'entity_table' => $baoName), array('entity_id' => $newId));
         }
         // copy event discount
         if ($baoName == 'civicrm_event') {
             $discount = CRM_Core_BAO_Discount::getOptionGroup($id, 'civicrm_event');
             foreach ($discount as $discountId => $setId) {
                 $copyPriceSet =& CRM_Price_BAO_PriceSet::copy($setId);
                 CRM_Core_DAO::copyGeneric('CRM_Core_DAO_Discount', array('id' => $discountId), array('entity_id' => $newId, 'price_set_id' => $copyPriceSet->id));
             }
         }
     }
 }
Пример #19
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;
 }
Пример #20
0
 /**
  * Process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $params = array();
     $eventTitle = '';
     $params = $this->exportValues();
     $this->set('discountSection', 0);
     if (CRM_Utils_Array::value('_qf_Fee_submit', $_POST)) {
         $this->buildAmountLabel();
         $this->set('discountSection', 2);
         return;
     }
     if (array_key_exists('payment_processor', $params) && !CRM_Utils_System::isNull($params['payment_processor'])) {
         $params['payment_processor'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['payment_processor']));
     } else {
         $params['payment_processor'] = 'null';
     }
     $params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0);
     if ($this->_id) {
         // delete all the prior label values or discounts in the custom options table
         // and delete a price set if one exists
         if (CRM_Price_BAO_Set::removeFrom('civicrm_event', $this->_id)) {
             CRM_Core_BAO_Discount::del($this->_id, 'civicrm_event');
         }
     }
     if ($params['is_monetary']) {
         if (CRM_Utils_Array::value('price_set_id', $params)) {
             CRM_Price_BAO_Set::addTo('civicrm_event', $this->_id, $params['price_set_id']);
             if (CRM_Utils_Array::value('price_field_id', $params)) {
                 $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $params['price_field_id'], 'price_set_id');
                 CRM_Price_BAO_Set::setIsQuickConfig($priceSetID, 0);
             }
         } else {
             // if there are label / values, create custom options for them
             $labels = CRM_Utils_Array::value('label', $params);
             $values = CRM_Utils_Array::value('value', $params);
             $default = CRM_Utils_Array::value('default', $params);
             $options = array();
             if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
                 for ($i = 1; $i < self::NUM_OPTION; $i++) {
                     if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) {
                         $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                     }
                 }
                 if (!empty($options)) {
                     $params['default_fee_id'] = NULL;
                     if (!CRM_Utils_Array::value('price_set_id', $params)) {
                         if (!CRM_Utils_Array::value('price_field_id', $params)) {
                             $eventTitle = $this->_isTemplate ? $this->_defaultValues['template_title'] : $this->_defaultValues['title'];
                             if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $eventTitle, 'id', 'title')) {
                                 $setParams['name'] = $setParams['title'] = $eventTitle;
                             } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $eventTitle . '_' . $this->_id, 'id', 'title')) {
                                 $setParams['name'] = $setParams['title'] = $eventTitle . '_' . $this->_id;
                             } else {
                                 $timeSec = explode(".", microtime(true));
                                 $setParams['name'] = $setParams['title'] = $eventTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
                             }
                             $setParams['is_quick_config'] = 1;
                             $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
                             $priceSet = CRM_Price_BAO_Set::create($setParams);
                             $fieldParams['name'] = $fieldParams['label'] = $params['fee_label'];
                             $fieldParams['price_set_id'] = $priceSet->id;
                         } else {
                             foreach ($params['price_field_value'] as $arrayID => $fieldValueID) {
                                 if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) {
                                     CRM_Price_BAO_FieldValue::setIsActive($fieldValueID, '0');
                                     unset($params['price_field_value'][$arrayID]);
                                 }
                             }
                             $fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params);
                             $fieldParams['option_id'] = $params['price_field_value'];
                             $priceSet->id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', CRM_Utils_Array::value('price_field_id', $params), 'price_set_id');
                         }
                         $fieldParams['html_type'] = 'Radio';
                         CRM_Price_BAO_Set::addTo('civicrm_event', $this->_id, $priceSet->id);
                         $fieldParams['option_label'] = $params['label'];
                         $fieldParams['option_amount'] = $params['value'];
                         foreach ($options as $value) {
                             $fieldParams['option_weight'][$value['weight']] = $value['weight'];
                         }
                         $fieldParams['default_option'] = $params['default'];
                         $priceField = CRM_Price_BAO_Field::create($fieldParams);
                     }
                 }
             }
             $discountPriceSets = CRM_Utils_Array::value('discount_price_set', $this->_defaultValues) ? $this->_defaultValues['discount_price_set'] : array();
             $discountFieldIDs = CRM_Utils_Array::value('discount_option_id', $this->_defaultValues) ? $this->_defaultValues['discount_option_id'] : array();
             if (CRM_Utils_Array::value('is_discount', $params) == 1) {
                 // if there are discounted set of label / values,
                 // create custom options for them
                 $labels = CRM_Utils_Array::value('discounted_label', $params);
                 $values = CRM_Utils_Array::value('discounted_value', $params);
                 $default = CRM_Utils_Array::value('discounted_default', $params);
                 if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
                     for ($j = 1; $j <= self::NUM_DISCOUNT; $j++) {
                         $discountOptions = array();
                         for ($i = 1; $i < self::NUM_OPTION; $i++) {
                             if (!empty($labels[$i]) && !empty($values[$i][$j])) {
                                 $discountOptions[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i][$j])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                             }
                         }
                         if (!empty($discountOptions)) {
                             $fieldParams = array();
                             $params['default_discount_fee_id'] = NULL;
                             $keyCheck = $j - 1;
                             if (!CRM_Utils_Array::value($keyCheck, $discountPriceSets)) {
                                 if (!$eventTitle) {
                                     $eventTitle = strtolower(CRM_Utils_String::munge($this->_defaultValues['title'], '_', 200));
                                 }
                                 $setParams['title'] = $params['discount_name'][$j];
                                 if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $eventTitle . '_' . $params['discount_name'][$j], 'id', 'name')) {
                                     $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j];
                                 } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id, 'id', 'name')) {
                                     $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id;
                                 } else {
                                     $timeSec = explode(".", microtime(true));
                                     $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . date('is', $timeSec[0]) . $timeSec[1];
                                 }
                                 $setParams['is_quick_config'] = 1;
                                 $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
                                 $priceSet = CRM_Price_BAO_Set::create($setParams);
                                 $priceSetID = $priceSet->id;
                             } else {
                                 $priceSetID = $discountPriceSets[$j - 1];
                                 unset($discountPriceSets[$j - 1]);
                                 $fieldParams['id'] = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Field', $priceSetID, 'id', 'price_set_id');
                             }
                             $fieldParams['name'] = $fieldParams['label'] = $params['fee_label'];
                             $fieldParams['is_required'] = 1;
                             $fieldParams['price_set_id'] = $priceSetID;
                             $fieldParams['html_type'] = 'Radio';
                             foreach ($discountOptions as $value) {
                                 $fieldParams['option_label'][$value['weight']] = $value['label'];
                                 $fieldParams['option_amount'][$value['weight']] = $value['value'];
                                 $fieldParams['option_weight'][$value['weight']] = $value['weight'];
                                 if (CRM_Utils_Array::value('is_default', $value)) {
                                     $fieldParams['default_option'] = $value['weight'];
                                 }
                                 if (CRM_Utils_Array::value($j, $discountFieldIDs) && CRM_Utils_Array::value($value['weight'] - 1, $discountFieldIDs[$j])) {
                                     $fieldParams['option_id'][$value['weight']] = $discountFieldIDs[$j][$value['weight'] - 1];
                                     unset($discountFieldIDs[$j][$value['weight'] - 1]);
                                 }
                             }
                             //create discount priceset
                             $priceField = CRM_Price_BAO_Field::create($fieldParams);
                             if (!empty($discountFieldIDs)) {
                                 foreach ($discountFieldIDs as $fID) {
                                     CRM_Price_BAO_FieldValue::setIsActive($fID, '0');
                                 }
                             }
                             $discountParams = array('entity_table' => 'civicrm_event', 'entity_id' => $this->_id, 'option_group_id' => $priceSetID, 'start_date' => CRM_Utils_Date::processDate($params["discount_start_date"][$j]), 'end_date' => CRM_Utils_Date::processDate($params["discount_end_date"][$j]));
                             CRM_Core_BAO_Discount::add($discountParams);
                         }
                     }
                 }
             }
             if (!empty($discountPriceSets)) {
                 foreach ($discountPriceSets as $setId) {
                     CRM_Price_BAO_Set::setIsQuickConfig($setId, 0);
                 }
             }
         }
     } else {
         if (CRM_Utils_Array::value('price_field_id', $params)) {
             $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $params['price_field_id'], 'price_set_id');
             CRM_Price_BAO_Set::setIsQuickConfig($priceSetID, 0);
         }
         $params['contribution_type_id'] = '';
     }
     //update events table
     $params['id'] = $this->_id;
     CRM_Event_BAO_Event::add($params);
     parent::endPostProcess();
 }