示例#1
0
 /**
  * pre processing work done here.
  * 
  * gets session variables for group or field id
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 function preProcess()
 {
     // get the controller vars
     $groupId = $this->get('groupId');
     $fieldId = $this->get('fieldId');
     if ($fieldId) {
         require_once 'CRM/Price/BAO/Set.php';
         $groupTree = CRM_Price_BAO_Set::getSetDetail($groupId);
         $this->_groupTree[$groupId]['fields'][$fieldId] = $groupTree[$groupId]['fields'][$fieldId];
         $this->assign('preview_type', 'field');
     } else {
         // group preview
         require_once 'CRM/Price/BAO/Set.php';
         $this->_groupTree = CRM_Price_BAO_Set::getSetDetail($groupId);
         $this->assign('preview_type', 'group');
     }
 }
 function build_price_options($event)
 {
     $price_fields_for_event = array();
     $base_field_name = "event_{$event->id}_amount";
     $price_set_id = CRM_Price_BAO_Set::getFor('civicrm_event', $event->id);
     if ($price_set_id) {
         $price_sets = CRM_Price_BAO_Set::getSetDetail($price_set_id, TRUE, TRUE);
         $price_set = $price_sets[$price_set_id];
         $index = -1;
         foreach ($price_set['fields'] as $field) {
             $index++;
             $field_name = "event_{$event->id}_price_{$field['id']}";
             CRM_Price_BAO_Field::addQuickFormElement($this, $field_name, $field['id'], FALSE);
             $price_fields_for_event[] = $field_name;
         }
     }
     return $price_fields_for_event;
 }
 /**
  * pre processing work done here.
  *
  * gets session variables for group or field id
  *
  * @param null
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     // get the controller vars
     $groupId = $this->get('groupId');
     $fieldId = $this->get('fieldId');
     if ($fieldId) {
         $groupTree = CRM_Price_BAO_Set::getSetDetail($groupId);
         $this->_groupTree[$groupId]['fields'][$fieldId] = $groupTree[$groupId]['fields'][$fieldId];
         $this->assign('preview_type', 'field');
         $url = CRM_Utils_System::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$groupId}");
         $breadCrumb = array(array('title' => ts('Price Set Fields'), 'url' => $url));
     } else {
         // group preview
         $this->_groupTree = CRM_Price_BAO_Set::getSetDetail($groupId);
         $this->assign('preview_type', 'group');
         $this->assign('setTitle', CRM_Price_BAO_Set::getTitle($groupId));
         $url = CRM_Utils_System::url('civicrm/admin/price', 'reset=1');
         $breadCrumb = array(array('title' => ts('Price Sets'), 'url' => $url));
     }
     CRM_Utils_System::appendBreadCrumb($breadCrumb);
 }
 /**
  * process membership records
  *
  * @param array $params associated array of submitted values
  *
  * @access public
  *
  * @return None
  */
 private function processMembership(&$params)
 {
     $dateTypes = array('join_date' => 'joinDate', 'membership_start_date' => 'startDate', 'membership_end_date' => 'endDate');
     $dates = array('join_date', 'start_date', 'end_date', 'reminder_date');
     // get the price set associated with offline memebership
     $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', 'default_membership_type_amount', 'id', 'name');
     $this->_priceSet = $priceSets = current(CRM_Price_BAO_Set::getSetDetail($priceSetId));
     if (isset($params['field'])) {
         $customFields = array();
         foreach ($params['field'] as $key => $value) {
             // if contact is not selected we should skip the row
             if (!CRM_Utils_Array::value($key, $params['primary_contact_select_id'])) {
                 continue;
             }
             $value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_select_id']);
             // update contact information
             $this->updateContactInfo($value);
             $membershipTypeId = $value['membership_type_id'] = $value['membership_type'][1];
             foreach ($dateTypes as $dateField => $dateVariable) {
                 ${$dateVariable} = CRM_Utils_Date::processDate($value[$dateField]);
             }
             $calcDates = array();
             $calcDates[$membershipTypeId] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipTypeId, $joinDate, $startDate, $endDate);
             foreach ($calcDates as $memType => $calcDate) {
                 foreach ($dates as $d) {
                     //first give priority to form values then calDates.
                     $date = CRM_Utils_Array::value($d, $value);
                     if (!$date) {
                         $date = CRM_Utils_Array::value($d, $calcDate);
                     }
                     $value[$d] = CRM_Utils_Date::processDate($date);
                 }
             }
             if (CRM_Utils_Array::value('send_receipt', $value)) {
                 $value['receipt_date'] = date('Y-m-d His');
             }
             if (CRM_Utils_Array::value('membership_source', $value)) {
                 $value['source'] = $value['membership_source'];
             }
             unset($value['membership_source']);
             //Get the membership status
             if (CRM_Utils_Array::value('membership_status', $value)) {
                 $value['status_id'] = $value['membership_status'];
                 unset($value['membership_status']);
             }
             if (empty($customFields)) {
                 // membership type custom data
                 $customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $membershipTypeId);
                 $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, NULL, NULL, TRUE));
             }
             //check for custom data
             $value['custom'] = CRM_Core_BAO_CustomField::postProcess($params['field'][$key], $customFields, $key, 'Membership', $membershipTypeId);
             if (CRM_Utils_Array::value('contribution_type', $value)) {
                 $value['contribution_type_id'] = $value['contribution_type'];
             }
             if (CRM_Utils_Array::value('payment_instrument', $value)) {
                 $value['payment_instrument_id'] = $value['payment_instrument'];
             }
             // handle soft credit
             if (CRM_Utils_Array::value('soft_credit_contact_select_id', $params) && CRM_Utils_Array::value($key, $params['soft_credit_contact_select_id'])) {
                 $value['soft_credit_to'] = $params['soft_credit_contact_select_id'][$key];
             }
             if (CRM_Utils_Array::value('receive_date', $value)) {
                 $value['receive_date'] = CRM_Utils_Date::processDate($value['receive_date'], $value['receive_date_time'], TRUE);
             }
             $params['actualBatchTotal'] += $value['total_amount'];
             unset($value['contribution_type']);
             unset($value['payment_instrument']);
             $value['batch_id'] = $this->_batchId;
             $value['skipRecentView'] = TRUE;
             // make entry in line item for contribution
             $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => $value['membership_type'][0]);
             $editedResults = array();
             CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults);
             if (!empty($editedResults)) {
                 unset($this->_priceSet['fields']);
                 $this->_priceSet['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']];
                 unset($this->_priceSet['fields'][$editedResults['id']]['options']);
                 $fid = $editedResults['id'];
                 $editedFieldParams = array('price_field_id' => $editedResults['id'], 'membership_type_id' => $value['membership_type_id']);
                 $editedResults = array();
                 CRM_Price_BAO_FieldValue::retrieve($editedFieldParams, $editedResults);
                 $this->_priceSet['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']];
                 if (CRM_Utils_Array::value('total_amount', $value)) {
                     $this->_priceSet['fields'][$fid]['options'][$editedResults['id']]['amount'] = $value['total_amount'];
                 }
                 $fieldID = key($this->_priceSet['fields']);
                 $value['price_' . $fieldID] = $editedResults['id'];
                 $lineItem = array();
                 CRM_Price_BAO_Set::processAmount($this->_priceSet['fields'], $value, $lineItem[$priceSetId]);
                 $value['lineItems'] = $lineItem;
                 $value['processPriceSet'] = TRUE;
             }
             // end of contribution related section
             unset($value['membership_type']);
             unset($value['membership_start_date']);
             unset($value['membership_end_date']);
             $value['is_renew'] = false;
             if (CRM_Utils_Array::value('member_option', $params) && CRM_Utils_Array::value($key, $params['member_option']) == 2) {
                 $this->_params = $params;
                 $value['is_renew'] = true;
                 $membership = CRM_Member_BAO_Membership::renewMembership($value['contact_id'], $value['membership_type_id'], FALSE, $this, NULL, NULL, $value['custom']);
                 // make contribution entry
                 CRM_Member_BAO_Membership::recordMembershipContribution($value, CRM_Core_DAO::$_nullArray, $membership->id);
             } else {
                 $membership = CRM_Member_BAO_Membership::create($value, CRM_Core_DAO::$_nullArray);
             }
             //process premiums
             if (CRM_Utils_Array::value('product_name', $value)) {
                 if ($value['product_name'][0] > 0) {
                     list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
                     $value['hidden_Premium'] = 1;
                     $value['product_option'] = CRM_Utils_Array::value($value['product_name'][1], $options[$value['product_name'][0]]);
                     $premiumParams = array('product_id' => $value['product_name'][0], 'contribution_id' => $value['contribution_id'], 'product_option' => $value['product_option'], 'quantity' => 1);
                     CRM_Contribute_BAO_Contribution::addPremium($premiumParams);
                 }
             }
             // end of premium
             //send receipt mail.
             if ($membership->id && CRM_Utils_Array::value('send_receipt', $value)) {
                 // add the domain email id
                 $domainEmail = CRM_Core_BAO_Domain::getNameAndEmail();
                 $domainEmail = "{$domainEmail['0']} <{$domainEmail['1']}>";
                 $value['from_email_address'] = $domainEmail;
                 $value['membership_id'] = $membership->id;
                 CRM_Member_Form_Membership::emailReceipt($this, $value, $membership);
             }
         }
     }
 }
示例#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();
 }
 /**
  * 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();
     // ensure that the user has permission to see this page
     if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW, $this->_id)) {
         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");
     $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.'));
     }
     if (!empty($values['event']['is_template'])) {
         // form is an Event Template
         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.
     if ($this->_id && CRM_Utils_Array::value('is_monetary', $values['event'])) {
         //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, 'option_group_id');
         } else {
             $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $this->_id);
         }
         // get price set options, - CRM-5209
         if ($priceSetId) {
             $setDetails = CRM_Price_BAO_Set::getSetDetail($priceSetId, TRUE, TRUE);
             $priceSetFields = $setDetails[$priceSetId]['fields'];
             if (is_array($priceSetFields)) {
                 $fieldCnt = 1;
                 $visibility = CRM_Core_PseudoConstant::visibility('name');
                 foreach ($priceSetFields as $fid => $fieldValues) {
                     if (!is_array($fieldValues['options']) || empty($fieldValues['options']) || CRM_Utils_Array::value('visibility_id', $fieldValues) != array_search('public', $visibility)) {
                         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';
                     }
                     foreach ($fieldValues['options'] as $optionId => $optionVal) {
                         $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
                         $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);
     //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);
     $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);
         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');
         $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0');
         $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 (CRM_Utils_Array::value('is_online_registration', $values['event'])) {
         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 (CRM_Utils_Array::value('registration_link_text', $values['event'])) {
                     $registerText = $values['event']['registration_link_text'];
                 }
                 // check if we're in shopping cart mode for events
                 $enable_cart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, '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']);
     return parent::run();
 }
 function setColumns()
 {
     $this->_columns = array(ts('Contact Id') => 'contact_id', ts('Participant Id') => 'participant_id', ts('Name') => 'display_name');
     if (!$this->_eventID) {
         return;
     }
     // for the selected event, find the price set and all the columns associated with it.
     // create a column for each field and option group within it
     $dao = $this->priceSetDAO($this->_formValues['event_id']);
     if ($dao->fetch() && !$dao->price_set_id) {
         CRM_Core_Error::fatal(ts('There are no events with Price Sets'));
     }
     // get all the fields and all the option values associated with it
     $priceSet = CRM_Price_BAO_Set::getSetDetail($dao->price_set_id);
     if (is_array($priceSet[$dao->price_set_id])) {
         foreach ($priceSet[$dao->price_set_id]['fields'] as $key => $value) {
             if (is_array($value['options'])) {
                 foreach ($value['options'] as $oKey => $oValue) {
                     $columnHeader = CRM_Utils_Array::value('label', $value);
                     if (CRM_Utils_Array::value('html_type', $value) != 'Text') {
                         $columnHeader .= ' - ' . $oValue['label'];
                     }
                     $this->_columns[$columnHeader] = "price_field_{$oValue['id']}";
                 }
             }
         }
     }
 }
示例#8
0
 function setColumns()
 {
     $this->_columns = array(ts('Contact Id') => 'contact_id', ts('Participant Id') => 'participant_id', ts('Name') => 'display_name');
     if (!$this->_eventID) {
         return;
     }
     // for the selected event, find the price set and all the columns associated with it.
     // create a column for each field and option group within it
     $dao = $this->priceSetDAO($this->_formValues['event_id']);
     if ($dao->fetch() && !$dao->price_set_id) {
         CRM_Core_Error::fatal(ts('There are no events with Price Sets'));
     }
     // get all the fields and all the option values associated with it
     require_once 'CRM/Price/BAO/Set.php';
     $priceSet = CRM_Price_BAO_Set::getSetDetail($dao->price_set_id);
     if (is_array($priceSet[$dao->price_set_id])) {
         foreach ($priceSet[$dao->price_set_id]['fields'] as $key => $value) {
             if (is_array($value['options'])) {
                 foreach ($value['options'] as $oKey => $oValue) {
                     $this->_columns[$oValue['description']] = "price_field_{$oValue['id']}";
                 }
             }
         }
     }
 }
 /**
  * This function sets the default values for the form. For edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return None
  */
 function setDefaultValues()
 {
     $parentDefaults = parent::setDefaultValues();
     $eventId = $this->_id;
     $params = array();
     $defaults = array();
     if (isset($eventId)) {
         $params = array('id' => $eventId);
     }
     CRM_Event_BAO_Event::retrieve($params, $defaults);
     if (isset($eventId)) {
         $price_set_id = CRM_Price_BAO_Set::getFor('civicrm_event', $eventId, NULL, 1);
         if ($price_set_id) {
             $defaults['price_set_id'] = $price_set_id;
         } else {
             $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $eventId, NULL);
             if ($priceSetId) {
                 if ($isQuick = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $priceSetId, 'is_quick_config')) {
                     $this->assign('isQuick', $isQuick);
                     $priceField = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $priceSetId, 'id', 'price_set_id');
                     $options = array();
                     $priceFieldOptions = CRM_Price_BAO_FieldValue::getValues($priceField, $options, 'weight', true);
                     $defaults['price_field_id'] = $priceField;
                     $countRow = 0;
                     foreach ($options as $optionId => $optionValue) {
                         $countRow++;
                         $defaults['value'][$countRow] = $optionValue['amount'];
                         $defaults['label'][$countRow] = $optionValue['label'];
                         $defaults['name'][$countRow] = $optionValue['name'];
                         $defaults['weight'][$countRow] = $optionValue['weight'];
                         $defaults["price_field_value"][$countRow] = $optionValue['id'];
                         if ($optionValue['is_default']) {
                             $defaults['default'] = $countRow;
                         }
                     }
                 }
             }
         }
     }
     //check if discounted
     $discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($this->_id, "civicrm_event");
     if (!empty($discountedEvent)) {
         $defaults['is_discount'] = $i = 1;
         $totalLables = $maxSize = $defaultDiscounts = array();
         foreach ($discountedEvent as $optionGroupId) {
             $defaults["discount_price_set"][] = $optionGroupId;
             $name = $defaults["discount_name[{$i}]"] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $optionGroupId, 'title');
             list($defaults["discount_start_date[{$i}]"]) = CRM_Utils_Date::setDateDefaults(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId, 'start_date', 'option_group_id'));
             list($defaults["discount_end_date[{$i}]"]) = CRM_Utils_Date::setDateDefaults(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId, 'end_date', 'option_group_id'));
             $defaultDiscounts[] = CRM_Price_BAO_Set::getSetDetail($optionGroupId);
             $i++;
         }
         //avoid moving up value of lable when some labels don't
         //have a value ,fixed for CRM-3088
         $rowCount = 1;
         foreach ($defaultDiscounts as $val) {
             $discountFields = current($val);
             $discountFields = current($discountFields['fields']);
             foreach ($discountFields['options'] as $discountFieldsval) {
                 $defaults["discounted_label"][$discountFieldsval['weight']] = $discountFieldsval['label'];
                 $defaults["discounted_value"][$discountFieldsval['weight']][$rowCount] = $discountFieldsval['amount'];
                 $defaults['discount_option_id'][$rowCount][] = $discountFieldsval['id'];
                 if (CRM_Utils_Array::value('is_default', $discountFieldsval)) {
                     $defaults['discounted_default'] = $discountFieldsval['weight'];
                 }
             }
             $rowCount++;
         }
         $this->set('discountSection', 1);
         $this->buildQuickForm();
     } elseif (!empty($defaults['label'])) {
         //if Regular Fees are present in DB and event fee page is in update mode
         $defaults["discounted_label"] = $defaults['label'];
     } elseif (CRM_Utils_Array::value('label', $this->_submitValues)) {
         //if event is newly created, use submitted values for
         //discount labels
         if (is_array($this->_submitValues['label'])) {
             $k = 1;
             foreach ($this->_submitValues['label'] as $value) {
                 if ($value) {
                     $defaults["discounted_label"][$k] = $value;
                     $k++;
                 }
             }
         }
     }
     $defaults['id'] = $eventId;
     if (!empty($totalLables)) {
         $maxKey = count($totalLables) - 1;
         if (isset($maxKey) && CRM_Utils_Array::value('value', $totalLables[$maxKey])) {
             foreach ($totalLables[$maxKey]['value'] as $i => $v) {
                 if ($totalLables[$maxKey]['amount_id'][$i] == CRM_Utils_Array::value('default_discount_fee_id', $defaults)) {
                     $defaults['discounted_default'] = $i;
                     break;
                 }
             }
         }
     }
     if (!isset($defaults['discounted_default'])) {
         $defaults['discounted_default'] = 1;
     }
     if (!isset($defaults['is_monetary'])) {
         $defaults['is_monetary'] = 1;
     }
     if (!isset($defaults['fee_label'])) {
         $defaults['fee_label'] = ts('Event Fee(s)');
     }
     if (!isset($defaults['pay_later_text']) || empty($defaults['pay_later_text'])) {
         $defaults['pay_later_text'] = ts('I will send payment by check');
     }
     $this->_showHide = new CRM_Core_ShowHideBlocks();
     if (!$defaults['is_monetary']) {
         $this->_showHide->addHide('event-fees');
     }
     if (isset($defaults['price_set_id'])) {
         $this->_showHide->addHide('map-field');
     }
     $this->_showHide->addToTemplate();
     $this->assign('inDate', $this->_inDate);
     if (CRM_Utils_Array::value('payment_processor', $defaults)) {
         $defaults['payment_processor'] = array_fill_keys(explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['payment_processor']), '1');
     }
     return $defaults;
 }
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     $session = CRM_Core_Session::singleton();
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Contribute_BAO_Contribution::deleteContribution($this->_id);
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactID}&selectedChild=contribute"));
         return;
     }
     // get the submitted form values.
     $submittedValues = $this->controller->exportValues($this->_name);
     if (CRM_Utils_Array::value('price_set_id', $submittedValues) && $this->_action & CRM_Core_Action::UPDATE) {
         $line = CRM_Price_BAO_LineItem::getLineItems($this->_id, 'contribution');
         $lineID = key($line);
         $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', CRM_Utils_Array::value('price_field_id', $line[$lineID]), 'price_set_id');
         $quickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $priceSetId, 'is_quick_config');
         if ($quickConfig) {
             CRM_Price_BAO_LineItem::deleteLineItems($this->_id, 'civicrm_contribution');
         }
     }
     // process price set and get total amount and line items.
     $lineItem = array();
     $priceSetId = $pId = NULL;
     $priceSetId = CRM_Utils_Array::value('price_set_id', $submittedValues);
     if (empty($priceSetId) && !$this->_id) {
         $this->_priceSetId = $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', 'default_contribution_amount', 'id', 'name');
         $this->_priceSet = current(CRM_Price_BAO_Set::getSetDetail($priceSetId));
         $fieldID = key($this->_priceSet['fields']);
         $fieldValueId = key($this->_priceSet['fields'][$fieldID]['options']);
         $this->_priceSet['fields'][$fieldID]['options'][$fieldValueId]['amount'] = $submittedValues['total_amount'];
         $submittedValues['price_' . $fieldID] = 1;
     }
     if ($priceSetId) {
         CRM_Price_BAO_Set::processAmount($this->_priceSet['fields'], $submittedValues, $lineItem[$priceSetId]);
         $submittedValues['total_amount'] = CRM_Utils_Array::value('amount', $submittedValues);
     }
     if (!$priceSetId && CRM_Utils_Array::value('total_amount', $submittedValues) && $this->_id) {
         // 10117 update th line items for participants
         $pId = $this->_compId && $this->_context == 'participant' ? $this->_compId : CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'participant_id', 'contribution_id');
         //CRM-10964
         if ($pId) {
             $entityTable = 'participant';
             $entityID = $pId;
             $participantParams = array('fee_amount' => $submittedValues['total_amount'], 'id' => $entityID);
             CRM_Event_BAO_Participant::add($participantParams);
             if (empty($this->_lineItems)) {
                 $this->_lineItems = CRM_Price_BAO_LineItem::getLineItems($entityID, 'participant', 1);
             }
         } else {
             $entityTable = 'contribution';
             $entityID = $this->_id;
         }
         $lineItems = CRM_Price_BAO_LineItem::getLineItems($entityID, $entityTable);
         $itemId = key($lineItems);
         $fieldType = NULL;
         if ($itemId && CRM_Utils_Array::value('price_field_id', $lineItems[$itemId])) {
             $fieldType = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $lineItems[$itemId]['price_field_id'], 'html_type');
         }
         $lineItems[$itemId]['unit_price'] = $lineItems[$itemId]['line_total'] = CRM_Utils_Rule::cleanMoney(CRM_Utils_Array::value('total_amount', $submittedValues));
         $lineItems[$itemId]['id'] = $itemId;
         // 10117 update th line items for participants
         $this->_priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $lineItems[$itemId]['price_field_id'], 'price_set_id');
         $lineItem[$this->_priceSetId] = $lineItems;
     }
     $isQuickConfig = 0;
     if ($this->_priceSetId && CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId, 'is_quick_config')) {
         $isQuickConfig = 1;
     }
     if (!CRM_Utils_Array::value('total_amount', $submittedValues)) {
         $submittedValues['total_amount'] = CRM_Utils_Array::value('total_amount', $this->_values);
     }
     $this->assign('lineItem', !empty($lineItem) && !$isQuickConfig ? $lineItem : FALSE);
     if (CRM_Utils_Array::value('soft_credit_to', $submittedValues)) {
         $submittedValues['soft_credit_to'] = $submittedValues['soft_contact_id'];
     }
     // set the contact, when contact is selected
     if (CRM_Utils_Array::value('contact_select_id', $submittedValues)) {
         $this->_contactID = $submittedValues['contact_select_id'][1];
     }
     $config = CRM_Core_Config::singleton();
     //Credit Card Contribution.
     if ($this->_mode) {
         $unsetParams = array('trxn_id', 'payment_instrument_id', 'contribution_status_id', 'cancel_date', 'cancel_reason');
         foreach ($unsetParams as $key) {
             if (isset($submittedValues[$key])) {
                 unset($submittedValues[$key]);
             }
         }
         //Get the rquire fields value only.
         $params = $this->_params = $submittedValues;
         $this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($this->_params['payment_processor_id'], $this->_mode);
         //get the payment processor id as per mode.
         $params['payment_processor_id'] = $this->_params['payment_processor_id'] = $submittedValues['payment_processor_id'] = $this->_paymentProcessor['id'];
         $now = date('YmdHis');
         $fields = array();
         // we need to retrieve email address
         if ($this->_context == 'standalone' && CRM_Utils_Array::value('is_email_receipt', $submittedValues)) {
             list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
             $this->assign('displayName', $this->userDisplayName);
         }
         //set email for primary location.
         $fields['email-Primary'] = 1;
         $params['email-Primary'] = $this->userEmail;
         // now set the values for the billing location.
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
         // also add location name to the array
         $params["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params);
         $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
         $fields["address_name-{$this->_bltID}"] = 1;
         $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type');
         $nameFields = array('first_name', 'middle_name', 'last_name');
         foreach ($nameFields as $name) {
             $fields[$name] = 1;
             if (array_key_exists("billing_{$name}", $params)) {
                 $params[$name] = $params["billing_{$name}"];
                 $params['preserveDBName'] = TRUE;
             }
         }
         if (CRM_Utils_Array::value('source', $params)) {
             unset($params['source']);
         }
         $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $this->_contactID, NULL, NULL, $ctype);
         // add all the additioanl payment params we need
         $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
         $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
         if ($this->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_CREDIT_CARD) {
             $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
             $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
         }
         $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
         $this->_params['amount'] = $this->_params['total_amount'];
         $this->_params['amount_level'] = 0;
         $this->_params['currencyID'] = CRM_Utils_Array::value('currency', $this->_params, $config->defaultCurrency);
         $this->_params['payment_action'] = 'Sale';
         if (CRM_Utils_Array::value('receive_date', $this->_params)) {
             $this->_params['receive_date'] = CRM_Utils_Date::processDate($this->_params['receive_date'], $this->_params['receive_date_time']);
         }
         if (CRM_Utils_Array::value('soft_credit_to', $params)) {
             $this->_params['soft_credit_to'] = $params['soft_credit_to'];
             $this->_params['pcp_made_through_id'] = $params['pcp_made_through_id'];
         }
         $this->_params['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $params);
         $this->_params['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $params);
         $this->_params['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $params);
         //Add common data to formatted params
         CRM_Contribute_Form_AdditionalInfo::postProcessCommon($params, $this->_params);
         if (empty($this->_params['invoice_id'])) {
             $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
         } else {
             $this->_params['invoiceID'] = $this->_params['invoice_id'];
         }
         // at this point we've created a contact and stored its address etc
         // all the payment processors expect the name and address to be in the
         // so we copy stuff over to first_name etc.
         $paymentParams = $this->_params;
         $paymentParams['contactID'] = $this->_contactID;
         CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);
         $contributionType = new CRM_Contribute_DAO_ContributionType();
         $contributionType->id = $params['contribution_type_id'];
         if (!$contributionType->find(TRUE)) {
             CRM_Core_Error::fatal('Could not find a system table');
         }
         // add some contribution type details to the params list
         // if folks need to use it
         $paymentParams['contributionType_name'] = $this->_params['contributionType_name'] = $contributionType->name;
         $paymentParams['contributionType_accounting_code'] = $this->_params['contributionType_accounting_code'] = $contributionType->accounting_code;
         $paymentParams['contributionPageID'] = NULL;
         if (CRM_Utils_Array::value('is_email_receipt', $this->_params)) {
             $paymentParams['email'] = $this->userEmail;
             $paymentParams['is_email_receipt'] = 1;
         } else {
             $paymentParams['is_email_receipt'] = 0;
             $this->_params['is_email_receipt'] = 0;
         }
         if (CRM_Utils_Array::value('receive_date', $this->_params)) {
             $paymentParams['receive_date'] = $this->_params['receive_date'];
         }
         if (CRM_Utils_Array::value('receive_date', $this->_params)) {
             $paymentParams['receive_date'] = $this->_params['receive_date'];
         }
         $result = NULL;
         // For recurring contribution, create Contribution Record first.
         // Contribution ID, Recurring ID and Contact ID needed
         // When we get a callback from the payment processor, CRM-7115
         if (CRM_Utils_Array::value('is_recur', $paymentParams)) {
             $contribution = CRM_Contribute_Form_Contribution_Confirm::processContribution($this, $this->_params, $result, $this->_contactID, $contributionType, FALSE, TRUE, FALSE);
             $paymentParams['contributionID'] = $contribution->id;
             $paymentParams['contributionTypeID'] = $contribution->contribution_type_id;
             $paymentParams['contributionPageID'] = $contribution->contribution_page_id;
             $paymentParams['contributionRecurID'] = $contribution->contribution_recur_id;
         }
         if ($paymentParams['amount'] > 0.0) {
             // force a reget of the payment processor in case the form changed it, CRM-7179
             $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this, TRUE);
             $result = $payment->doDirectPayment($paymentParams);
         }
         if (is_a($result, 'CRM_Core_Error')) {
             //make sure to cleanup db for recurring case.
             if (CRM_Utils_Array::value('contributionID', $paymentParams)) {
                 CRM_Core_Error::debug_log_message(CRM_Core_Error::getMessages($result) . "contact id={$this->_contactID} (deleting contribution {$paymentParams['contributionID']}");
                 CRM_Contribute_BAO_Contribution::deleteContribution($paymentParams['contributionID']);
             }
             if (CRM_Utils_Array::value('contributionRecurID', $paymentParams)) {
                 CRM_Core_Error::debug_log_message(CRM_Core_Error::getMessages($result) . "contact id={$this->_contactID} (deleting recurring contribution {$paymentParams['contributionRecurID']}");
                 CRM_Contribute_BAO_ContributionRecur::deleteRecurContribution($paymentParams['contributionRecurID']);
             }
             //set the contribution mode.
             $urlParams = "action=add&cid={$this->_contactID}";
             if ($this->_mode) {
                 $urlParams .= "&mode={$this->_mode}";
             }
             if (!empty($this->_ppID)) {
                 $urlParams .= "&context=pledge&ppid={$this->_ppID}";
             }
             CRM_Core_Error::displaySessionError($result);
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams));
         }
         if ($result) {
             $this->_params = array_merge($this->_params, $result);
         }
         $this->_params['receive_date'] = $now;
         if (CRM_Utils_Array::value('is_email_receipt', $this->_params)) {
             $this->_params['receipt_date'] = $now;
         } else {
             $this->_params['receipt_date'] = CRM_Utils_Date::processDate($this->_params['receipt_date'], $params['receipt_date_time'], TRUE);
         }
         $this->set('params', $this->_params);
         $this->assign('trxn_id', $result['trxn_id']);
         $this->assign('receive_date', $this->_params['receive_date']);
         // result has all the stuff we need
         // lets archive it to a financial transaction
         if ($contributionType->is_deductible) {
             $this->assign('is_deductible', TRUE);
             $this->set('is_deductible', TRUE);
         }
         // set source if not set
         if (empty($this->_params['source'])) {
             $userID = $session->get('userID');
             $userSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $userID, 'sort_name');
             $this->_params['source'] = ts('Submit Credit Card Payment by: %1', array(1 => $userSortName));
         }
         // build custom data getFields array
         $customFieldsContributionType = CRM_Core_BAO_CustomField::getFields('Contribution', FALSE, FALSE, CRM_Utils_Array::value('contribution_type_id', $params));
         $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsContributionType, CRM_Core_BAO_CustomField::getFields('Contribution', FALSE, FALSE, NULL, NULL, TRUE));
         $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Contribution');
         if (!CRM_Utils_Array::value('is_recur', $paymentParams)) {
             $contribution = CRM_Contribute_Form_Contribution_Confirm::processContribution($this, $this->_params, $result, $this->_contactID, $contributionType, FALSE, FALSE, FALSE);
         }
         if ($this->_context != 'participant' && !$pId) {
             $entityID = $contribution->id;
             $entityTable = 'contribution';
         }
         // process line items, until no previous line items.
         if (empty($this->_lineItems) && $entityID && !empty($lineItem)) {
             CRM_Contribute_Form_AdditionalInfo::processPriceSet($entityID, $lineItem, 'civicrm_' . $entityTable);
         }
         //send receipt mail.
         if ($contribution->id && CRM_Utils_Array::value('is_email_receipt', $this->_params)) {
             $this->_params['trxn_id'] = CRM_Utils_Array::value('trxn_id', $result);
             $this->_params['contact_id'] = $this->_contactID;
             $this->_params['contribution_id'] = $contribution->id;
             $sendReceipt = CRM_Contribute_Form_AdditionalInfo::emailReceipt($this, $this->_params, TRUE);
         }
         //process the note
         if ($contribution->id && isset($params['note'])) {
             CRM_Contribute_Form_AdditionalInfo::processNote($params, $contactID, $contribution->id, NULL);
         }
         //process premium
         if ($contribution->id && isset($params['product_name'][0])) {
             CRM_Contribute_Form_AdditionalInfo::processPremium($params, $contribution->id, NULL, $this->_options);
         }
         //update pledge payment status.
         if ($this->_ppID && $contribution->id) {
             //store contribution id in payment record.
             CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $this->_ppID, 'contribution_id', $contribution->id);
             CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($this->_pledgeID, array($this->_ppID), $contribution->contribution_status_id, NULL, $contribution->total_amount);
         }
         if ($contribution->id) {
             $statusMsg = ts('The contribution record has been processed.');
             if (CRM_Utils_Array::value('is_email_receipt', $this->_params) && $sendReceipt) {
                 $statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
             }
             CRM_Core_Session::setStatus($statusMsg);
         }
         //submit credit card contribution ends.
     } else {
         //Offline Contribution.
         $unsetParams = array('payment_processor_id', "email-{$this->_bltID}", 'hidden_buildCreditCard', 'hidden_buildDirectDebit', 'billing_first_name', 'billing_middle_name', 'billing_last_name', 'street_address-5', "city-{$this->_bltID}", "state_province_id-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", 'credit_card_number', 'cvv2', 'credit_card_exp_date', 'credit_card_type');
         foreach ($unsetParams as $key) {
             if (isset($submittedValues[$key])) {
                 unset($submittedValues[$key]);
             }
         }
         // get the required field value only.
         $formValues = $submittedValues;
         $params = $ids = array();
         $params['contact_id'] = $this->_contactID;
         // get current currency from DB or use default currency
         $currentCurrency = CRM_Utils_Array::value('currency', $this->_values, $config->defaultCurrency);
         // use submitted currency if present else use current currency
         $params['currency'] = CRM_Utils_Array::value('currency', $submittedValues, $currentCurrency);
         $fields = array('contribution_type_id', 'contribution_status_id', 'payment_instrument_id', 'cancel_reason', 'source', 'check_number', 'soft_credit_to', 'pcp_made_through_id', 'pcp_display_in_roll', 'pcp_roll_nickname', 'pcp_personal_note');
         foreach ($fields as $f) {
             $params[$f] = CRM_Utils_Array::value($f, $formValues);
         }
         if ($softID = CRM_Utils_Array::value('softID', $this->_values)) {
             $params['softID'] = $softID;
         }
         //if priceset is used, no need to cleanup money
         //CRM-5740
         if ($priceSetId) {
             $params['skipCleanMoney'] = 1;
         }
         $dates = array('receive_date', 'receipt_date', 'cancel_date');
         foreach ($dates as $d) {
             $params[$d] = CRM_Utils_Date::processDate($formValues[$d], $formValues[$d . '_time'], TRUE);
         }
         if (CRM_Utils_Array::value('is_email_receipt', $formValues)) {
             $params['receipt_date'] = date("Y-m-d");
         }
         if ($params['contribution_status_id'] == CRM_Core_OptionGroup::getValue('contribution_status', 'Cancelled', 'name')) {
             if (CRM_Utils_System::isNull(CRM_Utils_Array::value('cancel_date', $params))) {
                 $params['cancel_date'] = date("Y-m-d");
             }
         } else {
             $params['cancel_date'] = $params['cancel_reason'] = 'null';
         }
         // Set is_pay_later flag for back-office offline Pending status contributions CRM-8996
         if ($params['contribution_status_id'] == CRM_Core_OptionGroup::getValue('contribution_status', 'Pending', 'name')) {
             $params['is_pay_later'] = 1;
         }
         $ids['contribution'] = $params['id'] = $this->_id;
         //Add Additional common information  to formatted params
         CRM_Contribute_Form_AdditionalInfo::postProcessCommon($formValues, $params);
         //create contribution.
         $contribution = CRM_Contribute_BAO_Contribution::create($params, $ids);
         // 10117 update th line items for participants
         if ($this->_context != 'participant' && !$pId) {
             $entityID = $contribution->id;
             $entityTable = 'contribution';
         }
         // process line items, until no previous line items.
         if (empty($this->_lineItems) && $entityID && !empty($lineItem)) {
             CRM_Contribute_Form_AdditionalInfo::processPriceSet($entityID, $lineItem, 'civicrm_' . $entityTable);
         }
         // process associated membership / participant, CRM-4395
         $relatedComponentStatusMsg = NULL;
         if ($contribution->id && $this->_action & CRM_Core_Action::UPDATE) {
             $relatedComponentStatusMsg = $this->updateRelatedComponent($contribution->id, $contribution->contribution_status_id, CRM_Utils_Array::value('contribution_status_id', $this->_values));
         }
         //process  note
         if ($contribution->id && isset($formValues['note'])) {
             CRM_Contribute_Form_AdditionalInfo::processNote($formValues, $this->_contactID, $contribution->id, $this->_noteID);
         }
         //process premium
         if ($contribution->id && isset($formValues['product_name'][0])) {
             CRM_Contribute_Form_AdditionalInfo::processPremium($formValues, $contribution->id, $this->_premiumID, $this->_options);
         }
         //send receipt mail.
         if ($contribution->id && CRM_Utils_Array::value('is_email_receipt', $formValues)) {
             $formValues['contact_id'] = $this->_contactID;
             $formValues['contribution_id'] = $contribution->id;
             // to get 'from email id' for send receipt
             $this->fromEmailId = $formValues['from_email_address'];
             $sendReceipt = CRM_Contribute_Form_AdditionalInfo::emailReceipt($this, $formValues);
         }
         $pledgePaymentId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $contribution->id, 'id', 'contribution_id');
         //update pledge payment status.
         if ($this->_ppID && $contribution->id && $this->_action & CRM_Core_Action::ADD || $pledgePaymentId && $this->_action & CRM_Core_Action::UPDATE) {
             if ($this->_ppID) {
                 //store contribution id in payment record.
                 CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $this->_ppID, 'contribution_id', $contribution->id);
             } else {
                 $this->_ppID = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $contribution->id, 'id', 'contribution_id');
                 $this->_pledgeID = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $contribution->id, 'pledge_id', 'contribution_id');
             }
             $adjustTotalAmount = FALSE;
             if (CRM_Utils_Array::value('option_type', $formValues) == 2) {
                 $adjustTotalAmount = TRUE;
             }
             CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($this->_pledgeID, array($this->_ppID), $contribution->contribution_status_id, NULL, $contribution->total_amount, $adjustTotalAmount);
         }
         $statusMsg = ts('The contribution record has been saved.');
         if (CRM_Utils_Array::value('is_email_receipt', $formValues) && $sendReceipt) {
             $statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
         }
         if ($relatedComponentStatusMsg) {
             $statusMsg .= ' ' . $relatedComponentStatusMsg;
         }
         CRM_Core_Session::setStatus($statusMsg, FALSE);
         //Offline Contribution ends.
     }
     $buttonName = $this->controller->getButtonName();
     if ($this->_context == 'standalone') {
         if ($buttonName == $this->getButtonName('upload', 'new')) {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/contribute/add', 'reset=1&action=add&context=standalone'));
         } else {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactID}&selectedChild=contribute"));
         }
     } elseif ($this->_context == 'contribution' && $this->_mode && $buttonName == $this->getButtonName('upload', 'new')) {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/contribution', "reset=1&action=add&context={$this->_context}&cid={$this->_contactID}&mode={$this->_mode}"));
     } elseif ($buttonName == $this->getButtonName('upload', 'new')) {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/contribution', "reset=1&action=add&context={$this->_context}&cid={$this->_contactID}"));
     }
 }
 /**
  * (Queue Task Callback)
  *
  * Find any participant records and create corresponding line-item
  * records.
  *
  * @param $startId int, the first/lowest participant ID to convert
  * @param $endId int, the last/highest participant ID to convert
  */
 static function task_4_2_alpha1_convertParticipants(CRM_Queue_TaskContext $ctx, $startId, $endId)
 {
     $upgrade = new CRM_Upgrade_Form();
     //create lineitems for participant in edge cases using default price set for contribution.
     $query = "\nSELECT    cp.id as participant_id, cp.fee_amount, cp.fee_level,ce.is_monetary,\n          cpse.price_set_id, cpf.id as price_field_id, cpfv.id as price_field_value_id\nFROM      civicrm_participant cp\nLEFT JOIN civicrm_line_item cli ON cli.entity_id=cp.id and cli.entity_table = 'civicrm_participant'\nLEFT JOIN civicrm_event ce ON ce.id=cp.event_id\nLEFT JOIN civicrm_price_set_entity cpse ON cp.event_id = cpse.entity_id and cpse.entity_table = 'civicrm_event'\nLEFT JOIN civicrm_price_field cpf ON cpf.price_set_id = cpse.price_set_id\nLEFT JOIN civicrm_price_field_value cpfv ON cpfv.price_field_id = cpf.id AND cpfv.label = cp.fee_level\nWHERE     (cp.id BETWEEN %1 AND %2)\nAND       cli.entity_id IS NULL AND cp.fee_amount IS NOT NULL";
     $sqlParams = array(1 => array($startId, 'Integer'), 2 => array($endId, 'Integer'));
     $dao = CRM_Core_DAO::executeQuery($query, $sqlParams);
     if ($dao->N) {
         $defaultPriceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', 'default_contribution_amount', 'id', 'name');
         $priceSets = current(CRM_Price_BAO_Set::getSetDetail($defaultPriceSetId));
         $fieldID = key($priceSets['fields']);
     }
     while ($dao->fetch()) {
         $lineParams = array('entity_table' => 'civicrm_participant', 'entity_id' => $dao->participant_id, 'label' => $dao->fee_level ? $dao->fee_level : ts('Default'), 'qty' => 1, 'unit_price' => $dao->fee_amount, 'line_total' => $dao->fee_amount, 'participant_count' => 1);
         if ($dao->is_monetary && $dao->price_field_id) {
             $lineParams += array('price_field_id' => $dao->price_field_id, 'price_field_value_id' => $dao->price_field_value_id);
             $priceSetId = $dao->price_set_id;
         } else {
             $lineParams['price_field_id'] = $fieldID;
             $priceSetId = $defaultPriceSetId;
         }
         CRM_Price_BAO_LineItem::create($lineParams);
     }
     return TRUE;
 }
 function process_event_line_item(&$event_in_cart, $class = NULL)
 {
     $cost = 0;
     $price_set_id = CRM_Price_BAO_Set::getFor("civicrm_event", $event_in_cart->event_id);
     $amount_level = NULL;
     if ($price_set_id) {
         $event_price_values = array();
         foreach ($this->_price_values as $key => $value) {
             if (preg_match("/event_{$event_in_cart->event_id}_(price.*)/", $key, $matches)) {
                 $event_price_values[$matches[1]] = $value;
             }
         }
         $price_sets = CRM_Price_BAO_Set::getSetDetail($price_set_id, TRUE);
         $price_set = $price_sets[$price_set_id];
         $price_set_amount = array();
         CRM_Price_BAO_Set::processAmount($price_set['fields'], $event_price_values, $price_set_amount);
         $price_set_index = end(array_keys($event_price_values['amount_priceset_level_radio']));
         $cost = $event_price_values['amount'];
         $amount_level = $event_price_values['amount_level'];
     }
     // iterate over each participant in event
     foreach ($event_in_cart->participants as &$participant) {
         $participant->cost = $cost;
         $participant->fee_level = $amount_level;
     }
     $this->add_line_item($event_in_cart, $class);
 }
 /**
  * Function to record line items for default membership
  *
  * @param $qf object
  *
  * @param $membershipType array with membership type and organization
  *
  * @param$ priceSetId priceset id
  * @access public
  * @static
  */
 static function createLineItems(&$qf, $membershipType, &$priceSetId)
 {
     $qf->_priceSetId = $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', 'default_membership_type_amount', 'id', 'name');
     if ($priceSetId) {
         $qf->_priceSet = $priceSets = current(CRM_Price_BAO_Set::getSetDetail($priceSetId));
     }
     $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => $membershipType[0]);
     $editedResults = array();
     CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults);
     if (!empty($editedResults)) {
         unset($qf->_priceSet['fields']);
         $qf->_priceSet['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']];
         unset($qf->_priceSet['fields'][$editedResults['id']]['options']);
         $fid = $editedResults['id'];
         $editedFieldParams = array('price_field_id' => $editedResults['id'], 'membership_type_id' => $membershipType[1]);
         $editedResults = array();
         CRM_Price_BAO_FieldValue::retrieve($editedFieldParams, $editedResults);
         $qf->_priceSet['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']];
         if (CRM_Utils_Array::value('total_amount', $qf->_params)) {
             $qf->_priceSet['fields'][$fid]['options'][$editedResults['id']]['amount'] = $qf->_params['total_amount'];
         }
     }
     $fieldID = key($qf->_priceSet['fields']);
     $qf->_params['price_' . $fieldID] = $editedResults['id'];
 }