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;
 }
예제 #2
0
 /**
  * function to change is_quick_config priceSet to complex
  *
  * @static
  * @access public
  */
 static function setIsQuickConfig()
 {
     if (!($id = CRM_Utils_Array::value('id', $_GET))) {
         return false;
     }
     $priceSetId = CRM_Price_BAO_Set::getFor($_GET['context'], $id, NULL);
     if ($priceSetId) {
         $result = CRM_Price_BAO_Set::setIsQuickConfig($priceSetId, 0);
     }
     if (!$result) {
         $priceSetId = null;
     }
     echo json_encode($priceSetId);
     CRM_Utils_System::civiExit();
 }
 /**
  * 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();
 }
예제 #4
0
 /**
  * This function sets the default values for price set.
  * 
  * @access public
  * @return None
  */
 static function setDefaultPriceSet($participantID, $eventID = null)
 {
     $defaults = array();
     if (!$eventID && $participantID) {
         $eventID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $participantID, 'event_id');
     }
     if (!$participantID || !$eventID) {
         return $defaults;
     }
     // get price set ID.
     require_once 'CRM/Price/BAO/Set.php';
     $priceSetID = CRM_Price_BAO_Set::getFor('civicrm_event', $eventID);
     if (!$priceSetID) {
         return $defaults;
     }
     // use line items for setdefault price set fields, CRM-4090
     require_once 'CRM/Price/BAO/LineItem.php';
     $lineItems[$participantID] = CRM_Price_BAO_LineItem::getLineItems($participantID);
     if (is_array($lineItems[$participantID]) && !CRM_Utils_System::isNull($lineItems[$participantID])) {
         $priceFields = $htmlTypes = $optionValues = array();
         foreach ($lineItems[$participantID] as $lineId => $items) {
             $priceFieldId = CRM_Utils_Array::value('price_field_id', $items);
             $optionGroupId = CRM_Utils_Array::value('option_group_id', $items);
             if ($priceFieldId && $optionGroupId) {
                 $priceFields[$priceFieldId] = $optionGroupId;
             }
         }
         if (empty($priceFields)) {
             return $defaults;
         }
         // get all price set field html types.
         $sql = "\nSELECT  id, html_type \n  FROM  civicrm_price_field \n WHERE  id IN (" . implode(',', array_keys($priceFields)) . ')';
         $fieldDAO = CRM_Core_DAO::executeQuery($sql);
         while ($fieldDAO->fetch()) {
             $htmlTypes[$fieldDAO->id] = $fieldDAO->html_type;
         }
         $sql = "\nSELECT  id, label, name, option_group_id  \n  FROM  civicrm_option_value \n WHERE  option_group_id IN (" . implode(',', $priceFields) . ')';
         $valueDAO = CRM_Core_DAO::executeQuery($sql);
         while ($valueDAO->fetch()) {
             $optionValues[$valueDAO->option_group_id][$valueDAO->id] = array('name' => $valueDAO->name, 'label' => $valueDAO->label);
         }
         foreach ($lineItems[$participantID] as $lineId => $items) {
             $fieldId = $items['price_field_id'];
             $htmlType = CRM_Utils_Array::value($fieldId, $htmlTypes);
             if (!$htmlType) {
                 continue;
             }
             if ($htmlType == "Text") {
                 $defaults["price_{$fieldId}"] = $items['qty'];
             } else {
                 $optionGroupId = CRM_Utils_Array::value($fieldId, $priceFields);
                 $fieldOptValues = CRM_Utils_Array::value($optionGroupId, $optionValues);
                 if (!is_array($fieldOptValues)) {
                     continue;
                 }
                 foreach ($fieldOptValues as $optionId => $values) {
                     if ($values['label'] == $items['label'] && $values['name'] == $items['unit_price']) {
                         if ($htmlType == "CheckBox") {
                             $defaults["price_{$fieldId}"][$optionId] = true;
                         } else {
                             $defaults["price_{$fieldId}"] = $optionId;
                             break;
                         }
                     }
                 }
             }
         }
     }
     return $defaults;
 }
 /**
  * Process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     $deletePriceSet = 0;
     if ($params['membership_type']) {
         // we do this in case the user has hit the forward/back button
         $dao = new CRM_Member_DAO_MembershipBlock();
         $dao->entity_table = 'civicrm_contribution_page';
         $dao->entity_id = $this->_id;
         $dao->find(TRUE);
         $membershipID = $dao->id;
         if ($membershipID) {
             $params['id'] = $membershipID;
         }
         $membershipTypes = array();
         if (is_array($params['membership_type'])) {
             foreach ($params['membership_type'] as $k => $v) {
                 if ($v) {
                     $membershipTypes[$k] = CRM_Utils_Array::value("auto_renew_{$k}", $params);
                 }
             }
         }
         // check for price set.
         $priceSetID = CRM_Utils_Array::value('member_price_set_id', $params);
         if (CRM_Utils_Array::value('member_is_active', $params) && is_array($membershipTypes) && !$priceSetID) {
             $usedPriceSetId = CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $this->_id, 2);
             if (!CRM_Utils_Array::value('mem_price_field_id', $params) && !$usedPriceSetId) {
                 $pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245));
                 $setParams['title'] = $this->_values['title'];
                 if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $pageTitle, 'id', 'name')) {
                     $setParams['name'] = $pageTitle;
                 } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $pageTitle . '_' . $this->_id, 'id', 'name')) {
                     $setParams['name'] = $pageTitle . '_' . $this->_id;
                 } else {
                     $timeSec = explode(".", microtime(true));
                     $setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
                 }
                 $setParams['is_quick_config'] = 1;
                 $setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember');
                 $setParams['contribution_type_id'] = CRM_Utils_Array::value('contribution_type_id', $this->_values);
                 $priceSet = CRM_Price_BAO_Set::create($setParams);
                 $priceSetID = $priceSet->id;
                 $fieldParams['price_set_id'] = $priceSet->id;
             } elseif ($usedPriceSetId) {
                 $setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember');
                 $setParams['contribution_type_id'] = CRM_Utils_Array::value('contribution_type_id', $this->_values);
                 $setParams['id'] = $usedPriceSetId;
                 $priceSet = CRM_Price_BAO_Set::create($setParams);
                 $priceSetID = $priceSet->id;
                 $fieldParams['price_set_id'] = $priceSet->id;
             } else {
                 $fieldParams['id'] = CRM_Utils_Array::value('mem_price_field_id', $params);
                 $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', CRM_Utils_Array::value('mem_price_field_id', $params), 'price_set_id');
             }
             $editedFieldParams = array('price_set_id' => $priceSetID, 'name' => 'membership_amount');
             $editedResults = array();
             CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults);
             if (!CRM_Utils_Array::value('id', $editedResults)) {
                 $fieldParams['name'] = strtolower(CRM_Utils_String::munge('Membership Amount', '_', 245));
                 $fieldParams['label'] = CRM_Utils_Array::value('new_title', $params) ? $params['new_title'] : 'Membership Amount';
                 if (!CRM_Utils_Array::value('mem_price_field_id', $params)) {
                     CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_Field', 0, 1, array('price_set_id' => $priceSetID));
                 }
                 $fieldParams['weight'] = 1;
             } else {
                 $fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults);
             }
             $fieldParams['is_active'] = 1;
             $fieldParams['html_type'] = 'Radio';
             $fieldParams['is_required'] = CRM_Utils_Array::value('is_required', $params) ? 1 : 0;
             $fieldParams['is_display_amounts'] = CRM_Utils_Array::value('display_min_fee', $params) ? 1 : 0;
             $rowCount = 1;
             $options = array();
             if (CRM_Utils_Array::value('id', $fieldParams)) {
                 CRM_Core_PseudoConstant::populate($options, 'CRM_Price_DAO_FieldValue', TRUE, 'membership_type_id', NULL, " price_field_id = {$fieldParams['id']} ");
             }
             foreach ($membershipTypes as $memType => $memAutoRenew) {
                 if ($priceFieldID = CRM_Utils_Array::key($memType, $options)) {
                     $fieldParams['option_id'][$rowCount] = $priceFieldID;
                     unset($options[$priceFieldID]);
                 }
                 $membetype = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($memType);
                 $fieldParams['option_label'][$rowCount] = CRM_Utils_Array::value('name', $membetype);
                 $fieldParams['option_amount'][$rowCount] = CRM_Utils_Array::value('minimum_fee', $membetype, 0);
                 $fieldParams['option_weight'][$rowCount] = CRM_Utils_Array::value('weight', $membetype);
                 $fieldParams['option_description'][$rowCount] = CRM_Utils_Array::value('description', $membetype);
                 $fieldParams['default_option'] = CRM_Utils_Array::value('membership_type_default', $params);
                 $fieldParams['membership_type_id'][$rowCount] = $memType;
                 // [$rowCount] = $membetype[''];
                 $rowCount++;
             }
             foreach ($options as $priceFieldID => $memType) {
                 CRM_Price_BAO_FieldValue::setIsActive($priceFieldID, '0');
             }
             $priceField = CRM_Price_BAO_Field::create($fieldParams);
         } elseif (!$priceSetID) {
             $deletePriceSet = 1;
         }
         $params['is_required'] = CRM_Utils_Array::value('is_required', $params, FALSE);
         $params['is_active'] = CRM_Utils_Array::value('member_is_active', $params, FALSE);
         if ($priceSetID) {
             $params['membership_types'] = 'null';
             $params['membership_type_default'] = CRM_Utils_Array::value('membership_type_default', $params, 'null');
             $params['membership_types'] = serialize($membershipTypes);
             $params['display_min_fee'] = CRM_Utils_Array::value('display_min_fee', $params, FALSE);
             $params['is_separate_payment'] = CRM_Utils_Array::value('is_separate_payment', $params, FALSE);
         }
         $params['entity_table'] = 'civicrm_contribution_page';
         $params['entity_id'] = $this->_id;
         $dao = new CRM_Member_DAO_MembershipBlock();
         $dao->copyValues($params);
         $dao->save();
         if ($priceSetID && $params['is_active']) {
             CRM_Price_BAO_Set::addTo('civicrm_contribution_page', $this->_id, $priceSetID);
         }
         if ($deletePriceSet || !CRM_Utils_Array::value('member_is_active', $params, FALSE)) {
             if ($this->_memPriceSetId) {
                 $pFIDs = array();
                 $conditionParams = array('price_set_id' => $this->_memPriceSetId, 'html_type' => 'radio', 'name' => 'contribution_amount');
                 CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_Field', $conditionParams, $pFIDs);
                 if (!CRM_Utils_Array::value('id', $pFIDs)) {
                     CRM_Price_BAO_Set::removeFrom('civicrm_contribution_page', $this->_id);
                     CRM_Price_BAO_Set::setIsQuickConfig($this->_memPriceSetId, '0');
                 } else {
                     CRM_Price_BAO_Field::setIsActive($params['mem_price_field_id'], '0');
                 }
             }
         }
     }
     parent::endPostProcess();
 }
예제 #6
0
 /**
  * This is sometimes called in a loop (during event search)
  * hence we cache the values to prevent repeated calls to the db
  */
 static function usesPriceSet($id)
 {
     require_once 'CRM/Price/BAO/Set.php';
     static $usesPriceSet = array();
     if (!array_key_exists($id, $usesPriceSet)) {
         $usesPriceSet[$id] = CRM_Price_BAO_Set::getFor('civicrm_event', $id);
     }
     return $usesPriceSet[$id];
 }
예제 #7
0
 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     $id = $this->get('id');
     $values = $ids = array();
     $params = array('id' => $id);
     require_once 'CRM/Contribute/BAO/Contribution.php';
     CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids);
     $softParams = array('contribution_id' => $values['contribution_id']);
     if ($softContribution = CRM_Contribute_BAO_Contribution::getSoftContribution($softParams, true)) {
         $values = array_merge($values, $softContribution);
     }
     CRM_Contribute_BAO_Contribution::resolveDefaults($values);
     if (CRM_Utils_Array::value('honor_contact_id', $values)) {
         $sql = "SELECT display_name FROM civicrm_contact WHERE id = %1";
         $params = array(1 => array($values['honor_contact_id'], 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($sql, $params);
         if ($dao->fetch()) {
             $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$values['honor_contact_id']}");
             $values["honor_display"] = "<A href = {$url}>" . $dao->display_name . "</A>";
         }
         $honor = CRM_Core_PseudoConstant::honor();
         $values['honor_type'] = $honor[$values['honor_type_id']];
     }
     if (CRM_Utils_Array::value('contribution_recur_id', $values)) {
         $sql = "SELECT  installments, frequency_interval, frequency_unit FROM civicrm_contribution_recur WHERE id = %1";
         $params = array(1 => array($values['contribution_recur_id'], 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($sql, $params);
         if ($dao->fetch()) {
             $values["recur_installments"] = $dao->installments;
             $values["recur_frequency_unit"] = $dao->frequency_unit;
             $values["recur_frequency_interval"] = $dao->frequency_interval;
         }
     }
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $id, 0, $values['contribution_type_id']);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     $premiumId = null;
     if ($id) {
         require_once 'CRM/Contribute/DAO/ContributionProduct.php';
         $dao =& new CRM_Contribute_DAO_ContributionProduct();
         $dao->contribution_id = $id;
         if ($dao->find(true)) {
             $premiumId = $dao->id;
             $productID = $dao->product_id;
         }
     }
     if ($premiumId) {
         require_once 'CRM/Contribute/DAO/Product.php';
         $productDAO =& new CRM_Contribute_DAO_Product();
         $productDAO->id = $productID;
         $productDAO->find(true);
         $this->assign('premium', $productDAO->name);
         $this->assign('option', $dao->product_option);
         $this->assign('fulfilled', $dao->fulfilled_date);
     }
     // Get Note
     $noteValue = CRM_Core_BAO_Note::getNote($values['id'], 'civicrm_contribution');
     $values['note'] = array_values($noteValue);
     // show billing address location details, if exists
     if (CRM_Utils_Array::value('address_id', $values)) {
         $addressParams = array('id' => CRM_Utils_Array::value('address_id', $values));
         $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, false, 'id');
         $addressDetails = array_values($addressDetails);
         $values['billing_address'] = $addressDetails[0]['display'];
     }
     //get soft credit record if exists.
     if ($softContribution = CRM_Contribute_BAO_Contribution::getSoftContribution($softParams)) {
         $softContribution['softCreditToName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $softContribution['soft_credit_to'], 'display_name');
         //hack to avoid dispalyName conflict
         //for viewing softcredit record.
         $softContribution['displayName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name');
         $values = array_merge($values, $softContribution);
     }
     require_once 'CRM/Price/BAO/Set.php';
     $lineItems = array();
     if ($id && CRM_Price_BAO_Set::getFor('civicrm_contribution', $id)) {
         require_once 'CRM/Price/BAO/LineItem.php';
         $lineItems[] = CRM_Price_BAO_LineItem::getLineItems($id, 'contribution');
     }
     $this->assign('lineItem', empty($lineItems) ? false : $lineItems);
     $values['totalAmount'] = $values['total_amount'];
     // assign values to the template
     $this->assign($values);
     // add viewed contribution to recent items list
     require_once 'CRM/Utils/Recent.php';
     require_once 'CRM/Utils/Money.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     $url = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}");
     $title = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name') . ' - (' . CRM_Utils_Money::format($values['total_amount']) . ' ' . ' - ' . $values['contribution_type'] . ')';
     CRM_Utils_Recent::add($title, $url, $values['id'], 'Contribution', $values['contact_id'], null);
 }
예제 #8
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();
 }
 /**
  * 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(CRM_Utils_Array::value('end_date', $params), CRM_Utils_Array::value('end_date_time', $params), 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['is_share'] = CRM_Utils_Array::value('is_share', $params, FALSE);
     $params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, FALSE);
     $params['id'] = $this->_id;
     $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');
     //merge params with defaults from templates
     if (CRM_Utils_Array::value('template_id', $params)) {
         $params = array_merge(CRM_Event_BAO_Event::getTemplateDefaultValues($params['template_id']), $params);
     }
     $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 price sets if any
         $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $params['template_id']);
         if ($priceSetId) {
             $isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $priceSetId, 'is_quick_config');
             if ($isQuickConfig) {
                 $copyPriceSet =& CRM_Price_BAO_Set::copy($priceSetId);
                 $priceSetId = $copyPriceSet->id;
             }
             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);
         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);
         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;
                 if (isset($tafParams['id'])) {
                     unset($tafParams['id']);
                 }
                 CRM_Friend_BAO_Friend::addTellAFriend($tafParams);
             }
         }
         //copy pcp settings
         CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock', array('entity_id' => $params['template_id'], 'entity_table' => 'civicrm_event'), array('entity_id' => $event->id), array('replace' => array('target_entity_id' => $event->id)));
         //copy event schedule remainder
         CRM_Core_DAO::copyGeneric('CRM_Core_DAO_ActionSchedule', array('entity_value' => $params['template_id']), array('entity_value' => $event->id));
     }
     $this->set('id', $event->id);
     if ($this->_action & CRM_Core_Action::ADD) {
         $url = 'civicrm/event/manage/location';
         $urlParams = "action=update&reset=1&id={$event->id}";
         // special case for 'Save and Done' consistency.
         if ($this->controller->getButtonName('submit') == '_qf_EventInfo_upload_done') {
             $url = 'civicrm/event/manage';
             $urlParams = 'reset=1';
             CRM_Core_Session::setStatus(ts("'%1' information has been saved.", array(1 => $this->getTitle())));
         }
         CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams));
     }
     parent::endPostProcess();
 }
예제 #10
0
 /** 
  * Function to set variables up before form is built 
  *                                                           
  * @return void 
  * @access public 
  */
 public function preProcess()
 {
     //check permission for action.
     if (!CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
     }
     $this->_cdType = CRM_Utils_Array::value('type', $_GET);
     $this->assign('cdType', false);
     if ($this->_cdType) {
         $this->assign('cdType', true);
         return CRM_Custom_Form_CustomData::preProcess($this);
     }
     $this->_formType = CRM_Utils_Array::value('formType', $_GET);
     // get price set id.
     $this->_priceSetId = CRM_Utils_Array::value('priceSetId', $_GET);
     $this->set('priceSetId', $this->_priceSetId);
     $this->assign('priceSetId', $this->_priceSetId);
     //get the pledge payment id
     $this->_ppID = CRM_Utils_Request::retrieve('ppid', 'Positive', $this);
     //get the contact id
     $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     //get the action.
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'add');
     $this->assign('action', $this->_action);
     //get the contribution id if update
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $this->_context);
     //set the contribution mode.
     $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
     $this->assign('contributionMode', $this->_mode);
     $this->_paymentProcessor = array('billing_mode' => 1);
     $this->assign('showCheckNumber', false);
     //ensure that processor has a valid config
     //only valid processors get display to user
     if ($this->_mode) {
         $validProcessors = array();
         $processors = CRM_Core_PseudoConstant::paymentProcessor(false, false, "billing_mode IN ( 1, 3 )");
         foreach ($processors as $ppID => $label) {
             require_once 'CRM/Core/BAO/PaymentProcessor.php';
             require_once 'CRM/Core/Payment.php';
             $paymentProcessor =& CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode);
             if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) {
                 continue;
             } else {
                 if ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') {
                     continue;
                 } else {
                     $paymentObject =& CRM_Core_Payment::singleton($this->_mode, 'Contribute', $paymentProcessor, $this);
                     $error = $paymentObject->checkConfig();
                     if (empty($error)) {
                         $validProcessors[$ppID] = $label;
                     }
                     $paymentObject = null;
                 }
             }
         }
         if (empty($validProcessors)) {
             CRM_Core_Error::fatal(ts('You will need to configure the %1 settings for your Payment Processor before you can submit credit card transactions.', array(1 => $this->_mode)));
         } else {
             $this->_processors = $validProcessors;
         }
     }
     // this required to show billing block
     $this->assign_by_ref('paymentProcessor', $paymentProcessor);
     $this->assign('hidePayPalExpress', true);
     if ($this->_contactID) {
         require_once 'CRM/Contact/BAO/Contact/Location.php';
         list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
         $this->assign('displayName', $this->userDisplayName);
     }
     // also check for billing information
     // get the billing location type
     $locationTypes =& CRM_Core_PseudoConstant::locationType();
     $this->_bltID = array_search('Billing', $locationTypes);
     if (!$this->_bltID) {
         CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
     }
     $this->set('bltID', $this->_bltID);
     $this->assign('bltID', $this->_bltID);
     $this->_fields = array();
     require_once 'CRM/Core/Payment.php';
     require_once 'CRM/Core/Payment/Form.php';
     // payment fields are depending on payment type
     if ($this->_processors['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) {
         CRM_Core_Payment_Form::setDirectDebitFields($this);
     } else {
         CRM_Core_Payment_Form::setCreditCardFields($this);
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $config =& CRM_Core_Config::singleton();
     if (in_array("CiviPledge", $config->enableComponents) && !$this->_formType) {
         //get the payment values associated with given pledge payment id OR check for payments due.
         $this->_pledgeValues = array();
         if ($this->_ppID) {
             $payParams = array('id' => $this->_ppID);
             require_once "CRM/Pledge/BAO/Payment.php";
             CRM_Pledge_BAO_Payment::retrieve($payParams, $this->_pledgeValues['pledgePayment']);
             $this->_pledgeID = CRM_Utils_Array::value('pledge_id', $this->_pledgeValues['pledgePayment']);
             $paymentStatusID = CRM_Utils_Array::value('status_id', $this->_pledgeValues['pledgePayment']);
             $this->_id = CRM_Utils_Array::value('contribution_id', $this->_pledgeValues['pledgePayment']);
             //get all status
             $allStatus = CRM_Contribute_PseudoConstant::contributionStatus();
             if (!($paymentStatusID == array_search('Pending', $allStatus) || $paymentStatusID == array_search('Overdue', $allStatus))) {
                 CRM_Core_Error::fatal(ts("Pledge payment status should be 'Pending' or  'Overdue'."));
             }
             //get the pledge values associated with given pledge payment.
             require_once 'CRM/Pledge/BAO/Pledge.php';
             $ids = array();
             $pledgeParams = array('id' => $this->_pledgeID);
             CRM_Pledge_BAO_Pledge::getValues($pledgeParams, $this->_pledgeValues, $ids);
             $this->assign('ppID', $this->_ppID);
         } else {
             // Not making a pledge payment, so check if pledge payment(s) are due for this contact so we can alert the user. CRM-5206
             if (isset($this->_contactID)) {
                 require_once "CRM/Pledge/BAO/Pledge.php";
                 $contactPledges = array();
                 $contactPledges = CRM_Pledge_BAO_Pledge::getContactPledges($this->_contactID);
                 if (!empty($contactPledges)) {
                     $payments = null;
                     $paymentsDue = null;
                     $multipleDue = false;
                     require_once "CRM/Pledge/BAO/Payment.php";
                     foreach ($contactPledges as $key => $pledgeId) {
                         $payments = CRM_Pledge_BAO_Payment::getOldestPledgePayment($pledgeId);
                         if ($payments) {
                             if ($paymentsDue) {
                                 $multipleDue = true;
                                 break;
                             } else {
                                 $paymentsDue = $payments;
                             }
                         }
                     }
                     if ($multipleDue) {
                         // Show link to pledge tab since more than one pledge has a payment due
                         $pledgeTab = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->_contactID}&selectedChild=pledge");
                         CRM_Core_Session::setStatus(ts('This contact has pending or overdue pledge payments. <a href="%1">Click here to view their Pledges tab</a> and verify whether this contribution should be applied as a pledge payment.', array(1 => $pledgeTab)));
                     } else {
                         if ($paymentsDue) {
                             // Show user link to oldest Pending or Overdue pledge payment
                             require_once 'CRM/Utils/Date.php';
                             require_once 'CRM/Utils/Money.php';
                             $ppAmountDue = CRM_Utils_Money::format($payments['amount']);
                             $ppSchedDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Payment', $payments['id'], 'scheduled_date'));
                             if ($this->_mode) {
                                 $ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge&mode=live");
                             } else {
                                 $ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge");
                             }
                             CRM_Core_Session::setStatus(ts('This contact has a pending or overdue pledge payment of %2 which is scheduled for %3. <a href="%1">Click here to apply this contribution as a pledge payment<a/>.', array(1 => $ppUrl, 2 => $ppAmountDue, 3 => $ppSchedDate)));
                         }
                     }
                 }
             }
         }
     }
     $this->_values = array();
     // current contribution id
     if ($this->_id) {
         $this->_online = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_FinancialTrxn', $this->_id, 'id', 'contribution_id');
         if ($this->_online) {
             $this->assign('isOnline', true);
         }
         //to get Premium id
         $sql = "\nSELECT *\nFROM   civicrm_contribution_product\nWHERE  contribution_id = {$this->_id}\n";
         $dao = CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
         if ($dao->fetch()) {
             $this->_premiumID = $dao->id;
             $this->_productDAO = $dao;
         }
         $dao->free();
         $ids = array();
         $params = array('id' => $this->_id);
         require_once "CRM/Contribute/BAO/Contribution.php";
         CRM_Contribute_BAO_Contribution::getValues($params, $this->_values, $ids);
         //unset the honor type id:when delete the honor_contact_id
         //and edit the contribution, honoree infomation pane open
         //since honor_type_id is present
         if (!CRM_Utils_Array::value('honor_contact_id', $this->_values)) {
             unset($this->_values['honor_type_id']);
         }
         //to get note id
         require_once 'CRM/Core/BAO/Note.php';
         $daoNote =& new CRM_Core_BAO_Note();
         $daoNote->entity_table = 'civicrm_contribution';
         $daoNote->entity_id = $this->_id;
         if ($daoNote->find(true)) {
             $this->_noteID = $daoNote->id;
             $this->_values['note'] = $daoNote->note;
         }
         $this->_contributionType = $this->_values['contribution_type_id'];
         $csParams = array('contribution_id' => $this->_id);
         $softCredit = CRM_Contribute_BAO_Contribution::getSoftContribution($csParams, true);
         if (CRM_Utils_Array::value('soft_credit_to', $softCredit)) {
             $softCredit['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $softCredit['soft_credit_to'], 'sort_name');
         }
         $this->_values['soft_credit_to'] = $softCredit['sort_name'];
         $this->_values['softID'] = $softCredit['soft_credit_id'];
         $this->_values['soft_contact_id'] = $softCredit['soft_credit_to'];
         $this->_values['pcp_made_through_id'] = $softCredit['pcp_id'];
         $this->_values['pcp_display_in_roll'] = $softCredit['pcp_display_in_roll'];
         $this->_values['pcp_roll_nickname'] = $softCredit['pcp_roll_nickname'];
         $this->_values['pcp_personal_note'] = $softCredit['pcp_personal_note'];
         //display check number field only if its having value or its offline mode.
         if (CRM_Utils_Array::value('payment_instrument_id', $this->_values) == CRM_Core_OptionGroup::getValue('payment_instrument', 'Check', 'name') || CRM_Utils_Array::value('check_number', $this->_values)) {
             $this->assign('showCheckNumber', true);
         }
     }
     // when custom data is included in this page
     if (CRM_Utils_Array::value("hidden_custom", $_POST)) {
         $this->set('type', 'Contribution');
         $this->set('subType', $this->_contributionType);
         $this->set('entityId', $this->_id);
         CRM_Custom_Form_Customdata::preProcess($this);
         CRM_Custom_Form_Customdata::buildQuickForm($this);
         CRM_Custom_Form_Customdata::setDefaultValues($this);
     }
     require_once 'CRM/Price/BAO/Set.php';
     $this->_lineItems = array();
     if ($this->_id && ($priceSetId = CRM_Price_BAO_Set::getFor('civicrm_contribution', $this->_id))) {
         $this->_priceSetId = $priceSetId;
         require_once 'CRM/Price/BAO/LineItem.php';
         $this->_lineItems[] = CRM_Price_BAO_LineItem::getLineItems($this->_id, 'contribution');
     }
     $this->assign('lineItem', empty($this->_lineItems) ? false : $this->_lineItems);
 }
예제 #11
0
 /**
  * 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;
 }
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return void
  */
 function setDefaultValues()
 {
     //some child classes calling setdefaults directly w/o preprocess.
     $this->_values = $this->get('values');
     if (!is_array($this->_values)) {
         $this->_values = array();
         if (isset($this->_id) && $this->_id) {
             $params = array('id' => $this->_id);
             CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values);
         }
         $this->set('values', $this->_values);
     }
     $defaults = $this->_values;
     $config = CRM_Core_Config::singleton();
     if (isset($this->_id)) {
         //set defaults for pledgeBlock values.
         $pledgeBlockParams = array('entity_id' => $this->_id, 'entity_table' => ts('civicrm_contribution_page'));
         $pledgeBlockDefaults = array();
         CRM_Pledge_BAO_PledgeBlock::retrieve($pledgeBlockParams, $pledgeBlockDefaults);
         if ($this->_pledgeBlockID = CRM_Utils_Array::value('id', $pledgeBlockDefaults)) {
             $defaults['is_pledge_active'] = TRUE;
         }
         $pledgeBlock = array('is_pledge_interval', 'max_reminders', 'initial_reminder_day', 'additional_reminder_day');
         foreach ($pledgeBlock as $key) {
             $defaults[$key] = CRM_Utils_Array::value($key, $pledgeBlockDefaults);
         }
         if (CRM_Utils_Array::value('pledge_frequency_unit', $pledgeBlockDefaults)) {
             $defaults['pledge_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO::VALUE_SEPARATOR, $pledgeBlockDefaults['pledge_frequency_unit']), '1');
         }
         // fix the display of the monetary value, CRM-4038
         if (isset($defaults['goal_amount'])) {
             $defaults['goal_amount'] = CRM_Utils_Money::format($defaults['goal_amount'], NULL, '%a');
         }
         // get price set of type contributions
         //this is the value for stored in db if price set extends contribution
         $usedFor = 2;
         $this->_priceSetID = CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $this->_id, $usedFor, 1);
         if ($this->_priceSetID) {
             $defaults['price_set_id'] = $this->_priceSetID;
         }
         if (CRM_Utils_Array::value('end_date', $defaults)) {
             list($defaults['end_date'], $defaults['end_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['end_date']);
         }
         if (CRM_Utils_Array::value('start_date', $defaults)) {
             list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['start_date']);
         }
     } else {
         $defaults['is_active'] = 1;
         // set current date as start date
         list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults();
     }
     if (!isset($defaults['for_organization'])) {
         $defaults['for_organization'] = ts('I am contributing on behalf of an organization.');
     }
     if (CRM_Utils_Array::value('recur_frequency_unit', $defaults)) {
         $defaults['recur_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['recur_frequency_unit']), '1');
     } else {
         $defaults['recur_frequency_unit'] = array_fill_keys(CRM_Core_OptionGroup::values('recur_frequency_units'), '1');
     }
     if (CRM_Utils_Array::value('is_for_organization', $defaults)) {
         $defaults['is_organization'] = 1;
     } else {
         $defaults['is_for_organization'] = 1;
     }
     // confirm page starts out enabled
     if (!isset($defaults['is_confirm_enabled'])) {
         $defaults['is_confirm_enabled'] = 1;
     }
     return $defaults;
 }
예제 #13
0
 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);
 }
 /**
  * Delete the indirect records associated with this contribution first
  *
  * @return $results no of deleted Contribution on success, false otherwise
  * @access public
  * @static
  */
 static function deleteContribution($id)
 {
     CRM_Utils_Hook::pre('delete', 'Contribution', $id, CRM_Core_DAO::$_nullArray);
     $transaction = new CRM_Core_Transaction();
     $results = NULL;
     //delete activity record
     $params = array('source_record_id' => $id, 'activity_type_id' => 6);
     CRM_Activity_BAO_Activity::deleteActivity($params);
     //delete billing address if exists for this contribution.
     self::deleteAddress($id);
     //update pledge and pledge payment, CRM-3961
     CRM_Pledge_BAO_PledgePayment::resetPledgePayment($id);
     // remove entry from civicrm_price_set_entity, CRM-5095
     if (CRM_Price_BAO_Set::getFor('civicrm_contribution', $id)) {
         CRM_Price_BAO_Set::removeFrom('civicrm_contribution', $id);
     }
     // cleanup line items.
     $participantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $id, 'participant_id', 'contribution_id');
     // delete any related entity_financial_trxn and financial_trxn records.
     CRM_Core_BAO_FinancialTrxn::deleteFinancialTrxn($id, 'civicrm_contribution');
     if ($participantId) {
         CRM_Price_BAO_LineItem::deleteLineItems($participantId, 'civicrm_participant');
     } else {
         CRM_Price_BAO_LineItem::deleteLineItems($id, 'civicrm_contribution');
     }
     //delete note.
     $note = CRM_Core_BAO_Note::getNote($id, 'civicrm_contribution');
     $noteId = key($note);
     if ($noteId) {
         CRM_Core_BAO_Note::del($noteId, FALSE);
     }
     $dao = new CRM_Contribute_DAO_Contribution();
     $dao->id = $id;
     $results = $dao->delete();
     $transaction->commit();
     CRM_Utils_Hook::post('delete', 'Contribution', $dao->id, $dao);
     // delete the recently created Contribution
     $contributionRecent = array('id' => $id, 'type' => 'Contribution');
     CRM_Utils_Recent::del($contributionRecent);
     return $results;
 }
예제 #15
0
 /**
  * This is sometimes called in a loop (during event search)
  * hence we cache the values to prevent repeated calls to the db
  */
 static function usesPriceSet($id)
 {
     static $usesPriceSet = array();
     if (!array_key_exists($id, $usesPriceSet)) {
         $usesPriceSet[$id] = CRM_Price_BAO_Set::getFor('civicrm_event', $id);
     }
     return $usesPriceSet[$id];
 }
예제 #16
0
 /**
  * Function for validation
  *
  * @param array $params (ref.) an assoc array of name/value pairs
  *
  * @return mixed true or array of errors
  * @access public
  * @static
  */
 public function formRule(&$params, &$files, $contributionPageId = null)
 {
     $errors = array();
     if (CRM_Utils_Array::value('is_active', $params)) {
         // don't allow price set w/ membership signup, CRM-5095
         require_once 'CRM/Price/BAO/Set.php';
         if ($contributionPageId && CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $contributionPageId)) {
             $errors['is_active'] = ts('You cannot enable both Membership Signup and Price Set on the same online contribution page.');
             return $errors;
         }
         if (!isset($params['membership_type']) || !is_array($params['membership_type'])) {
             $errors['membership_type'] = ts('Please select at least one Membership Type to include in the Membership section of this page.');
         } else {
             $membershipType = array_values($params['membership_type']);
             if (array_sum($membershipType) == 0) {
                 $errors['membership_type'] = ts('Please select at least one Membership Type to include in the Membership section of this page.');
             }
         }
         //for CRM-1302
         //if Membership status is not present, then display an error message
         require_once 'CRM/Member/BAO/MembershipStatus.php';
         $dao =& new CRM_Member_BAO_MembershipStatus();
         if (!$dao->find()) {
             $errors['_qf_default'] = ts('Add status rules, before configuring membership');
         }
         //give error if default is selected for an unchecked membership type
         if (isset($params['membership_type_default']) && !$params['membership_type'][$params['membership_type_default']]) {
             $errors['membership_type_default'] = ts('Can\'t set default option for an unchecked membership type.');
         }
         if ($contributionPageId) {
             require_once "CRM/Contribute/DAO/ContributionPage.php";
             $amountBlock = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'amount_block_is_active');
             if (!$amountBlock && CRM_Utils_Array::value('is_separate_payment', $params)) {
                 $errors['is_separate_payment'] = ts('Please enable the contribution amount section to use this option.');
             }
         }
     }
     return empty($errors) ? true : $errors;
 }
    /**
     * This function sets the default values for price set.
     *
     * @access public
     *
     * @return None
     */
    static function setDefaultPriceSet($participantID, $eventID = NULL)
    {
        $defaults = array();
        if (!$eventID && $participantID) {
            $eventID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $participantID, 'event_id');
        }
        if (!$participantID || !$eventID) {
            return $defaults;
        }
        // get price set ID.
        $priceSetID = CRM_Price_BAO_Set::getFor('civicrm_event', $eventID);
        if (!$priceSetID) {
            return $defaults;
        }
        // use line items for setdefault price set fields, CRM-4090
        $lineItems[$participantID] = CRM_Price_BAO_LineItem::getLineItems($participantID);
        if (is_array($lineItems[$participantID]) && !CRM_Utils_System::isNull($lineItems[$participantID])) {
            $priceFields = $htmlTypes = $optionValues = array();
            foreach ($lineItems[$participantID] as $lineId => $items) {
                $priceFieldId = CRM_Utils_Array::value('price_field_id', $items);
                $priceOptionId = CRM_Utils_Array::value('price_field_value_id', $items);
                if ($priceFieldId && $priceOptionId) {
                    $priceFields[$priceFieldId][] = $priceOptionId;
                }
            }
            if (empty($priceFields)) {
                return $defaults;
            }
            // get all price set field html types.
            $sql = '
SELECT  id, html_type
  FROM  civicrm_price_field
 WHERE  id IN (' . implode(',', array_keys($priceFields)) . ')';
            $fieldDAO = CRM_Core_DAO::executeQuery($sql);
            while ($fieldDAO->fetch()) {
                $htmlTypes[$fieldDAO->id] = $fieldDAO->html_type;
            }
            foreach ($lineItems[$participantID] as $lineId => $items) {
                $fieldId = $items['price_field_id'];
                $htmlType = CRM_Utils_Array::value($fieldId, $htmlTypes);
                if (!$htmlType) {
                    continue;
                }
                if ($htmlType == 'Text') {
                    $defaults["price_{$fieldId}"] = $items['qty'];
                } else {
                    $fieldOptValues = CRM_Utils_Array::value($fieldId, $priceFields);
                    if (!is_array($fieldOptValues)) {
                        continue;
                    }
                    foreach ($fieldOptValues as $optionId) {
                        if ($htmlType == 'CheckBox') {
                            $defaults["price_{$fieldId}"][$optionId] = TRUE;
                        } else {
                            $defaults["price_{$fieldId}"] = $optionId;
                            break;
                        }
                    }
                }
            }
        }
        return $defaults;
    }
예제 #18
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();
 }
예제 #19
0
파일: Fee.php 프로젝트: ksecor/civicrm
 /**
  * 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)) {
         require_once 'CRM/Price/BAO/Set.php';
         $price_set_id = CRM_Price_BAO_Set::getFor('civicrm_event', $eventId);
         if ($price_set_id) {
             $defaults['price_set_id'] = $price_set_id;
         } else {
             require_once 'CRM/Core/OptionGroup.php';
             CRM_Core_OptionGroup::getAssoc("civicrm_event.amount.{$eventId}", $defaults);
         }
     }
     //check if discounted
     require_once 'CRM/Core/BAO/Discount.php';
     $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) {
             $name = $defaults["discount_name[{$i}]"] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $optionGroupId, 'label');
             $defaults["discount_start_date[{$i}]"] = CRM_Utils_Date::unformat(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId, 'start_date', 'option_group_id'));
             $defaults["discount_end_date[{$i}]"] = CRM_Utils_Date::unformat(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId, 'end_date', 'option_group_id'));
             CRM_Core_OptionGroup::getAssoc("civicrm_event.amount.{$eventId}.discount.{$name}", $defaultDiscounts[]);
             $i++;
         }
         //avoid moving up value of lable when some labels don't
         //have a value ,fixed for CRM-3088
         foreach ($defaultDiscounts as $key => $val) {
             $totalLables[$key]['label'] = $val['label'];
             $totalLables[$key]['value'] = $val['value'];
             $totalLables[$key]['amount_id'] = $val['amount_id'];
             foreach ($val['weight'] as $v) {
                 //take array of weight for setdefault
                 $discountWeight[$key][] = $v;
             }
             foreach ($val['value'] as $v) {
                 //take array of available value for particular
                 //discount set
                 $discountValue[$key][] = $v;
             }
             //combining the weight with amount array for set default
             $discountDefualt[] = array_combine($discountWeight[$key], $discountValue[$key]);
             foreach ($discountDefualt[$key] as $k => $v) {
                 $defaults["discounted_value"][$k][$key + 1] = $v;
             }
             $maxSize[$key] = sizeof($val['label']);
         }
         $maxKey = CRM_Utils_Array::key(max($maxSize), $maxSize);
         $defaults["discounted_label"] = $totalLables[$maxKey]['label'];
         $this->set('discountSection', 1);
         $this->buildQuickForm();
     } else {
         if (!empty($defaults['label'])) {
             //if Regular Fees are present in DB and event fee page is in update mode
             $defaults["discounted_label"] = $defaults['label'];
         } else {
             if (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 = array_merge($defaults, $parentDefaults);
     $defaults['id'] = $eventId;
     if (CRM_Utils_Array::value('value', $defaults)) {
         foreach ($defaults['value'] as $i => $v) {
             if ($defaults['amount_id'][$i] == $defaults['default_fee_id']) {
                 $defaults['default'] = $i;
                 break;
             }
         }
     }
     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['default'])) {
         $defaults['default'] = 1;
     }
     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');
     }
     require_once 'CRM/Core/ShowHideBlocks.php';
     $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);
     return $defaults;
 }
예제 #20
0
 /**
  * Process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     if (array_key_exists('payment_processor', $params)) {
         if (array_key_exists(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_PaymentProcessor', 'AuthNet', 'id', 'payment_processor_type'), CRM_Utils_Array::value('payment_processor', $params))) {
             CRM_Core_Session::setStatus(ts(' Please note that the Authorize.net payment processor only allows recurring contributions and auto-renew memberships with payment intervals from 7-365 days or 1-12 months (i.e. not greater than 1 year).'));
         }
     }
     // check for price set.
     $priceSetID = CRM_Utils_Array::value('price_set_id', $params);
     // get required fields.
     $fields = array('id' => $this->_id, 'is_recur' => FALSE, 'min_amount' => "null", 'max_amount' => "null", 'is_monetary' => FALSE, 'is_pay_later' => FALSE, 'is_recur_interval' => FALSE, 'recur_frequency_unit' => "null", 'default_amount_id' => "null", 'is_allow_other_amount' => FALSE, 'amount_block_is_active' => FALSE);
     $resetFields = array();
     if ($priceSetID) {
         $resetFields = array('min_amount', 'max_amount', 'is_allow_other_amount');
     }
     if (!CRM_Utils_Array::value('is_recur', $params)) {
         $resetFields = array_merge($resetFields, array('is_recur_interval', 'recur_frequency_unit'));
     }
     foreach ($fields as $field => $defaultVal) {
         $val = CRM_Utils_Array::value($field, $params, $defaultVal);
         if (in_array($field, $resetFields)) {
             $val = $defaultVal;
         }
         if (in_array($field, array('min_amount', 'max_amount'))) {
             $val = CRM_Utils_Rule::cleanMoney($val);
         }
         $params[$field] = $val;
     }
     if ($params['is_recur']) {
         $params['recur_frequency_unit'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['recur_frequency_unit']));
         $params['is_recur_interval'] = CRM_Utils_Array::value('is_recur_interval', $params, FALSE);
     }
     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';
     }
     $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params);
     $contributionPageID = $contributionPage->id;
     // prepare for data cleanup.
     $deleteAmountBlk = $deletePledgeBlk = $deletePriceSet = FALSE;
     if ($this->_priceSetID) {
         $deletePriceSet = TRUE;
     }
     if ($this->_pledgeBlockID) {
         $deletePledgeBlk = TRUE;
     }
     if (!empty($this->_amountBlock)) {
         $deleteAmountBlk = TRUE;
     }
     if ($contributionPageID) {
         if (CRM_Utils_Array::value('amount_block_is_active', $params)) {
             // handle price set.
             if ($priceSetID) {
                 // add/update price set.
                 $deletePriceSet = FALSE;
                 if (CRM_Utils_Array::value('price_field_id', $params) || CRM_Utils_Array::value('price_field_other', $params)) {
                     $deleteAmountBlk = TRUE;
                 }
                 CRM_Price_BAO_Set::addTo('civicrm_contribution_page', $contributionPageID, $priceSetID);
             } else {
                 $deletePriceSet = FALSE;
                 // process contribution amount block
                 $deleteAmountBlk = FALSE;
                 $labels = CRM_Utils_Array::value('label', $params);
                 $values = CRM_Utils_Array::value('value', $params);
                 $default = CRM_Utils_Array::value('default', $params);
                 $options = array();
                 for ($i = 1; $i < self::NUM_OPTION; $i++) {
                     if (isset($values[$i]) && strlen(trim($values[$i])) > 0) {
                         $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                     }
                 }
                 /* || CRM_Utils_Array::value( 'price_field_value', $params )|| CRM_Utils_Array::value( 'price_field_other', $params )*/
                 if (!empty($options) || CRM_Utils_Array::value('is_allow_other_amount', $params)) {
                     $fieldParams['is_quick_config'] = 1;
                     $noContriAmount = NULL;
                     $usedPriceSetId = CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $this->_id, 3);
                     if (!(CRM_Utils_Array::value('price_field_id', $params) || CRM_Utils_Array::value('price_field_other', $params)) && !$usedPriceSetId) {
                         $pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245));
                         $setParams['title'] = $this->_values['title'];
                         if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $pageTitle, 'id', 'name')) {
                             $setParams['name'] = $pageTitle;
                         } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $pageTitle . '_' . $this->_id, 'id', 'name')) {
                             $setParams['name'] = $pageTitle . '_' . $this->_id;
                         } else {
                             $timeSec = explode(".", microtime(true));
                             $setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
                         }
                         $setParams['is_quick_config'] = 1;
                         $setParams['extends'] = CRM_Core_Component::getComponentID('CiviContribute');
                         $priceSet = CRM_Price_BAO_Set::create($setParams);
                         $priceSetId = $priceSet->id;
                     } elseif ($usedPriceSetId && !CRM_Utils_Array::value('price_field_id', $params)) {
                         $priceSetId = $usedPriceSetId;
                     } else {
                         if ($priceFieldId = CRM_Utils_Array::value('price_field_id', $params)) {
                             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]);
                                 }
                             }
                             if (implode('', $params['price_field_value'])) {
                                 $fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params);
                                 $fieldParams['option_id'] = $params['price_field_value'];
                             } else {
                                 $noContriAmount = 0;
                                 CRM_Price_BAO_Field::setIsActive($priceFieldId, '0');
                             }
                         } else {
                             $priceFieldId = CRM_Utils_Array::value('price_field_other', $params);
                         }
                         $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $priceFieldId, 'price_set_id');
                     }
                     CRM_Price_BAO_Set::addTo('civicrm_contribution_page', $this->_id, $priceSetId);
                     if (!empty($options)) {
                         $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => 'contribution_amount');
                         $editedResults = array();
                         $noContriAmount = 1;
                         CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults);
                         if (!CRM_Utils_Array::value('id', $editedResults)) {
                             $fieldParams['name'] = strtolower(CRM_Utils_String::munge("Contribution Amount", '_', 245));
                             $fieldParams['label'] = "Contribution Amount";
                         } else {
                             $fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults);
                         }
                         $fieldParams['price_set_id'] = $priceSetId;
                         $fieldParams['is_active'] = 1;
                         $fieldParams['weight'] = 2;
                         if (CRM_Utils_Array::value('is_allow_other_amount', $params)) {
                             $fieldParams['is_required'] = 0;
                         } else {
                             $fieldParams['is_required'] = 1;
                         }
                         $fieldParams['html_type'] = 'Radio';
                         $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);
                     }
                     if (CRM_Utils_Array::value('is_allow_other_amount', $params) && !CRM_Utils_Array::value('price_field_other', $params)) {
                         $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => 'other_amount');
                         $editedResults = array();
                         CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults);
                         if (!($priceFieldID = CRM_Utils_Array::value('id', $editedResults))) {
                             $fieldParams = array('name' => 'other_amount', 'label' => 'Other Amount', 'price_set_id' => $priceSetId, 'html_type' => 'Text', 'is_display_amounts' => 0, 'weight' => 3);
                             $fieldParams['option_weight'][1] = 1;
                             $fieldParams['option_amount'][1] = 1;
                             if (!$noContriAmount) {
                                 $fieldParams['is_required'] = 1;
                                 $fieldParams['option_label'][1] = 'Contribution Amount';
                             } else {
                                 $fieldParams['is_required'] = 0;
                                 $fieldParams['option_label'][1] = 'Other Amount';
                             }
                             $priceField = CRM_Price_BAO_Field::create($fieldParams);
                         } else {
                             if (!CRM_Utils_Array::value('is_active', $editedResults)) {
                                 CRM_Price_BAO_Field::setIsActive($priceFieldID, '1');
                             }
                         }
                     } elseif (!CRM_Utils_Array::value('is_allow_other_amount', $params) && CRM_Utils_Array::value('price_field_other', $params)) {
                         CRM_Price_BAO_Field::setIsActive($params['price_field_other'], '0');
                     } elseif ($priceFieldID = CRM_Utils_Array::value('price_field_other', $params)) {
                         $priceFieldValueID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_FieldValue', $priceFieldID, 'id', 'price_field_id');
                         if (!$noContriAmount) {
                             CRM_Core_DAO::setFieldValue('CRM_Price_DAO_Field', $priceFieldID, 'is_required', 1);
                             CRM_Core_DAO::setFieldValue('CRM_Price_DAO_FieldValue', $priceFieldValueID, 'label', 'Contribution Amount');
                         } else {
                             CRM_Core_DAO::setFieldValue('CRM_Price_DAO_Field', $priceFieldID, 'is_required', 0);
                             CRM_Core_DAO::setFieldValue('CRM_Price_DAO_FieldValue', $priceFieldValueID, 'label', 'Other Amount');
                         }
                     }
                 }
                 if (CRM_Utils_Array::value('is_pledge_active', $params)) {
                     $deletePledgeBlk = FALSE;
                     $pledgeBlockParams = array('entity_id' => $contributionPageID, 'entity_table' => ts('civicrm_contribution_page'));
                     if ($this->_pledgeBlockID) {
                         $pledgeBlockParams['id'] = $this->_pledgeBlockID;
                     }
                     $pledgeBlock = array('pledge_frequency_unit', 'max_reminders', 'initial_reminder_day', 'additional_reminder_day');
                     foreach ($pledgeBlock as $key) {
                         $pledgeBlockParams[$key] = CRM_Utils_Array::value($key, $params);
                     }
                     $pledgeBlockParams['is_pledge_interval'] = CRM_Utils_Array::value('is_pledge_interval', $params, FALSE);
                     // create pledge block.
                     CRM_Pledge_BAO_PledgeBlock::create($pledgeBlockParams);
                 }
             }
         } else {
             if (CRM_Utils_Array::value('price_field_id', $params) || CRM_Utils_Array::value('price_field_other', $params)) {
                 $usedPriceSetId = CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $this->_id, 3);
                 if ($usedPriceSetId) {
                     if (CRM_Utils_Array::value('price_field_id', $params)) {
                         CRM_Price_BAO_Field::setIsActive($params['price_field_id'], '0');
                     }
                     if (CRM_Utils_Array::value('price_field_other', $params)) {
                         CRM_Price_BAO_Field::setIsActive($params['price_field_other'], '0');
                     }
                 } else {
                     $deleteAmountBlk = TRUE;
                     $deletePriceSet = TRUE;
                 }
             }
         }
         // delete pledge block.
         if ($deletePledgeBlk) {
             CRM_Pledge_BAO_PledgeBlock::deletePledgeBlock($this->_pledgeBlockID);
         }
         // delete previous price set.
         if ($deletePriceSet) {
             CRM_Price_BAO_Set::removeFrom('civicrm_contribution_page', $contributionPageID);
         }
         if ($deleteAmountBlk) {
             $priceField = CRM_Utils_Array::value('price_field_id', $params) ? $params['price_field_id'] : CRM_Utils_Array::value('price_field_other', $params);
             if ($priceField) {
                 $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $priceField, 'price_set_id');
                 CRM_Price_BAO_Set::setIsQuickConfig($priceSetID, 0);
             }
         }
     }
     parent::endPostProcess();
 }
예제 #21
0
 function sendMail(&$input, &$ids, &$objects, &$values, $recur = false, $returnMessageText = false)
 {
     $contribution =& $objects['contribution'];
     $membership =& $objects['membership'];
     $participant =& $objects['participant'];
     $event =& $objects['event'];
     if (empty($values)) {
         $values = array();
         $contribID = $ids['contribution'];
         if ($input['component'] == 'contribute') {
             require_once 'CRM/Contribute/BAO/ContributionPage.php';
             if (isset($contribution->contribution_page_id)) {
                 CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values);
             } else {
                 // Handle re-print receipt for offline contributions (call from PDF.php - no contribution_page_id)
                 $values['is_email_receipt'] = 1;
                 $values['title'] = 'Contribution';
             }
             // set lineItem for contribution
             require_once 'CRM/Price/BAO/Set.php';
             if ($contribID && ($pId = CRM_Price_BAO_Set::getFor('civicrm_contribution', $contribID))) {
                 require_once 'CRM/Price/BAO/LineItem.php';
                 $values['lineItem'][0] = CRM_Price_BAO_LineItem::getLineItems($contribID, 'contribution');
                 $values['priceSetID'] = $pId;
             }
             require_once 'CRM/Contribute/BAO/Contribution.php';
             $relatedContact = CRM_Contribute_BAO_Contribution::getOnbehalfIds($contribID, $contribution->contact_id);
             // if this is onbehalf of contribution then set related contact
             if ($relatedContactId = $relatedContact['individual_id']) {
                 $values['related_contact'] = $ids['related_contact'] = $relatedContactId;
             }
         } else {
             // event
             $eventParams = array('id' => $objects['event']->id);
             $values['event'] = array();
             require_once 'CRM/Event/BAO/Event.php';
             CRM_Event_BAO_Event::retrieve($eventParams, $values['event']);
             //get location details
             $locationParams = array('entity_id' => $objects['event']->id, 'entity_table' => 'civicrm_event');
             require_once 'CRM/Core/BAO/Location.php';
             require_once 'CRM/Event/Form/ManageEvent/Location.php';
             $values['location'] = CRM_Core_BAO_Location::getValues($locationParams);
             require_once 'CRM/Core/BAO/UFJoin.php';
             $ufJoinParams = array('entity_table' => 'civicrm_event', 'entity_id' => $ids['event'], 'weight' => 1);
             $values['custom_pre_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams);
             $ufJoinParams['weight'] = 2;
             $values['custom_post_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams);
             // set lineItem for event contribution
             if ($contribID) {
                 require_once 'CRM/Event/BAO/Participant.php';
                 $participantIds = CRM_Event_BAO_Participant::getParticipantIds($contribID);
                 require_once 'CRM/Price/BAO/LineItem.php';
                 if (!empty($participantIds)) {
                     foreach ($participantIds as $pIDs) {
                         $lineItem = CRM_Price_BAO_LineItem::getLineItems($pIDs);
                         if (!CRM_Utils_System::isNull($lineItem)) {
                             $values['lineItem'][] = $lineItem;
                         }
                     }
                 }
             }
         }
         // set receipt from e-mail and name in value
         if (!$returnMessageText) {
             require_once 'CRM/Contact/BAO/Contact/Location.php';
             $session = CRM_Core_Session::singleton();
             $userID = $session->get('userID');
             list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
             $values['receipt_from_email'] = $userEmail;
             $values['receipt_from_name'] = $userName;
         }
         // set display address of contributor
         if ($contribution->address_id) {
             require_once 'CRM/Core/BAO/Address.php';
             $addressParams = array('id' => $contribution->address_id);
             $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, false, 'id');
             $addressDetails = array_values($addressDetails);
             $values['address'] = $addressDetails[0]['display'];
         }
     }
     $template =& CRM_Core_Smarty::singleton();
     // CRM_Core_Error::debug('tpl',$template);
     //assign honor infomation to receiptmessage
     if ($honarID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contribution->id, 'honor_contact_id')) {
         $honorDefault = array();
         $honorIds = array();
         $honorIds['contribution'] = $contribution->id;
         $idParams = array('id' => $honarID, 'contact_id' => $honarID);
         require_once "CRM/Contact/BAO/Contact.php";
         CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $honorIds);
         require_once "CRM/Core/PseudoConstant.php";
         $honorType = CRM_Core_PseudoConstant::honor();
         $prefix = CRM_Core_PseudoConstant::individualPrefix();
         $template->assign('honor_block_is_active', 1);
         $template->assign('honor_prefix', $prefix[$honorDefault["prefix_id"]]);
         $template->assign('honor_first_name', CRM_Utils_Array::value("first_name", $honorDefault));
         $template->assign('honor_last_name', CRM_Utils_Array::value("last_name", $honorDefault));
         $template->assign('honor_email', CRM_Utils_Array::value("email", $honorDefault["email"][1]));
         $template->assign('honor_type', $honorType[$contribution->honor_type_id]);
     }
     require_once 'CRM/Contribute/DAO/ContributionProduct.php';
     $dao = new CRM_Contribute_DAO_ContributionProduct();
     $dao->contribution_id = $contribution->id;
     if ($dao->find(true)) {
         $premiumId = $dao->product_id;
         $template->assign('option', $dao->product_option);
         require_once 'CRM/Contribute/DAO/Product.php';
         $productDAO = new CRM_Contribute_DAO_Product();
         $productDAO->id = $premiumId;
         $productDAO->find(true);
         $template->assign('selectPremium', true);
         $template->assign('product_name', $productDAO->name);
         $template->assign('price', $productDAO->price);
         $template->assign('sku', $productDAO->sku);
     }
     // add the new contribution values
     if ($input['component'] == 'contribute') {
         $template->assign('title', $values['title']);
         $template->assign('amount', $input['amount']);
         //PCP Info
         require_once 'CRM/Contribute/DAO/ContributionSoft.php';
         $softDAO = new CRM_Contribute_DAO_ContributionSoft();
         $softDAO->contribution_id = $contribution->id;
         if ($softDAO->find(true)) {
             $template->assign('pcpBlock', true);
             $template->assign('pcp_display_in_roll', $softDAO->pcp_display_in_roll);
             $template->assign('pcp_roll_nickname', $softDAO->pcp_roll_nickname);
             $template->assign('pcp_personal_note', $softDAO->pcp_personal_note);
             //assign the pcp page title for email subject
             require_once 'CRM/Contribute/DAO/PCP.php';
             $pcpDAO = new CRM_Contribute_DAO_PCP();
             $pcpDAO->id = $softDAO->pcp_id;
             if ($pcpDAO->find(true)) {
                 $template->assign('title', $pcpDAO->title);
             }
         }
     } else {
         $template->assign('title', $values['event']['title']);
         $template->assign('totalAmount', $input['amount']);
     }
     if ($contribution->contribution_type_id) {
         $values['contribution_type_id'] = $contribution->contribution_type_id;
     }
     $template->assign('trxn_id', $contribution->trxn_id);
     $template->assign('receive_date', CRM_Utils_Date::mysqlToIso($contribution->receive_date));
     $template->assign('contributeMode', 'notify');
     $template->assign('action', $contribution->is_test ? 1024 : 1);
     $template->assign('receipt_text', CRM_Utils_Array::value('receipt_text', $values));
     $template->assign('is_monetary', 1);
     $template->assign('is_recur', $recur);
     $template->assign('currency', $contribution->currency);
     if ($recur) {
         require_once 'CRM/Core/Payment.php';
         $paymentObject =& CRM_Core_Payment::singleton($contribution->is_test ? 'test' : 'live', $objects['paymentProcessor']);
         if (!empty($membership) && $membership->id) {
             $url = $paymentObject->cancelSubscriptionURL($membership->id, 'membership');
         } else {
             $url = $paymentObject->cancelSubscriptionURL();
         }
         $template->assign('cancelSubscriptionUrl', $url);
         if ($objects['paymentProcessor']['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) {
             //direct mode showing billing block, so use directIPN for temporary
             $template->assign('contributeMode', 'directIPN');
         }
     }
     require_once 'CRM/Utils/Address.php';
     $template->assign('address', CRM_Utils_Address::format($input));
     if ($input['component'] == 'event') {
         require_once 'CRM/Core/OptionGroup.php';
         $participant_role = CRM_Core_OptionGroup::values('participant_role');
         $values['event']['participant_role'] = $participant_role[$participant->role_id];
         $template->assign('event', $values['event']);
         $template->assign('location', $values['location']);
         $template->assign('customPre', $values['custom_pre_id']);
         $template->assign('customPost', $values['custom_post_id']);
         $isTest = false;
         if ($participant->is_test) {
             $isTest = true;
         }
         $values['params'] = array();
         require_once "CRM/Event/BAO/Event.php";
         //to get email of primary participant.
         $primaryEmail = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $participant->contact_id, 'email', 'contact_id');
         $primaryAmount[] = array('label' => $participant->fee_level . ' - ' . $primaryEmail, 'amount' => $participant->fee_amount);
         //build an array of cId/pId of participants
         $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($participant->id, null, $ids['contact'], $isTest, true);
         unset($additionalIDs[$participant->id]);
         //send receipt to additional participant if exists
         if (count($additionalIDs)) {
             $template->assign('isPrimary', 0);
             $template->assign('customProfile', null);
             //set additionalParticipant true
             $values['params']['additionalParticipant'] = true;
             foreach ($additionalIDs as $pId => $cId) {
                 $amount = array();
                 //to change the status pending to completed
                 $additional = new CRM_Event_DAO_Participant();
                 $additional->id = $pId;
                 $additional->contact_id = $cId;
                 $additional->find(true);
                 $additional->register_date = $participant->register_date;
                 $additional->status_id = 1;
                 $additionalParticipantInfo = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $additional->contact_id, 'email', 'contact_id');
                 //if additional participant dont have email
                 //use display name.
                 if (!$additionalParticipantInfo) {
                     require_once "CRM/Contact/BAO/Contact.php";
                     $additionalParticipantInfo = CRM_Contact_BAO_Contact::displayName($additional->contact_id);
                 }
                 $amount[0] = array('label' => $additional->fee_level, 'amount' => $additional->fee_amount);
                 $primaryAmount[] = array('label' => $additional->fee_level . ' - ' . $additionalParticipantInfo, 'amount' => $additional->fee_amount);
                 $additional->save();
                 $additional->free();
                 $template->assign('amount', $amount);
                 CRM_Event_BAO_Event::sendMail($cId, $values, $pId, $isTest, $returnMessageText);
             }
         }
         //build an array of custom profile and assigning it to template
         $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participant->id, $values, null, $isTest);
         if (count($customProfile)) {
             $template->assign('customProfile', $customProfile);
         }
         // for primary contact
         $values['params']['additionalParticipant'] = false;
         $template->assign('isPrimary', 1);
         $template->assign('amount', $primaryAmount);
         $template->assign('register_date', CRM_Utils_Date::isoToMysql($participant->register_date));
         if ($contribution->payment_instrument_id) {
             require_once 'CRM/Contribute/PseudoConstant.php';
             $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
             $template->assign('paidBy', $paymentInstrument[$contribution->payment_instrument_id]);
         }
         // carry paylater, since we did not created billing,
         // so need to pull email from primary location, CRM-4395
         $values['params']['is_pay_later'] = $participant->is_pay_later;
         return CRM_Event_BAO_Event::sendMail($ids['contact'], $values, $participant->id, $isTest, $returnMessageText);
     } else {
         if ($membership) {
             $values['membership_id'] = $membership->id;
             // need to set the membership values here
             $template->assign('membership_assign', 1);
             require_once 'CRM/Member/PseudoConstant.php';
             $template->assign('membership_name', CRM_Member_PseudoConstant::membershipType($membership->membership_type_id));
             $template->assign('mem_start_date', $membership->start_date);
             $template->assign('mem_end_date', $membership->end_date);
             // if separate payment there are two contributions recorded and the
             // admin will need to send a receipt for each of them separately.
             // we dont link the two in the db (but can potentially infer it if needed)
             $template->assign('is_separate_payment', 0);
         }
         $values['contribution_id'] = $contribution->id;
         if (CRM_Utils_Array::value('related_contact', $ids)) {
             $values['related_contact'] = $ids['related_contact'];
             if (isset($ids['onbehalf_dupe_alert'])) {
                 $values['onbehalf_dupe_alert'] = $ids['onbehalf_dupe_alert'];
             }
             require_once 'CRM/Core/BAO/Address.php';
             $entityBlock = array('contact_id' => $ids['contact'], 'location_type_id' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_LocationType', 'Home', 'id', 'name'));
             $address = CRM_Core_BAO_Address::getValues($entityBlock);
             $template->assign('onBehalfAddress', $address[$entityBlock['location_type_id']]['display']);
         }
         $isTest = false;
         if ($contribution->is_test) {
             $isTest = true;
         }
         // CRM_Core_Error::debug('val',$values);
         require_once 'CRM/Contribute/BAO/ContributionPage.php';
         return CRM_Contribute_BAO_ContributionPage::sendMail($ids['contact'], $values, $isTest, $returnMessageText);
     }
 }
예제 #22
0
 /**                                                           
  * Delete the indirect records associated with this contribution first
  * 
  * @return $results no of deleted Contribution on success, false otherwise
  * @access public 
  * @static 
  */
 static function deleteContribution($id)
 {
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::pre('delete', 'Contribution', $id, CRM_Core_DAO::$_nullArray);
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $results = null;
     //delete activity record
     require_once "CRM/Activity/BAO/Activity.php";
     $params = array('source_record_id' => $id, 'activity_type_id' => 6);
     // activity type id for contribution
     CRM_Activity_BAO_Activity::deleteActivity($params);
     //delete billing address if exists for this contribution.
     self::deleteAddress($id);
     //update pledge and pledge payment, CRM-3961
     require_once 'CRM/Pledge/BAO/Payment.php';
     CRM_Pledge_BAO_Payment::resetPledgePayment($id);
     // remove entry from civicrm_price_set_entity, CRM-5095
     require_once 'CRM/Price/BAO/Set.php';
     if (CRM_Price_BAO_Set::getFor('civicrm_contribution', $id)) {
         CRM_Price_BAO_Set::removeFrom('civicrm_contribution', $id);
     }
     // cleanup line items.
     require_once 'CRM/Price/BAO/Field.php';
     require_once 'CRM/Event/BAO/ParticipantPayment.php';
     $participantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $id, 'participant_id', 'contribution_id');
     // delete any related entity_financial_trxn and financial_trxn records.
     require_once 'CRM/Core/BAO/FinancialTrxn.php';
     CRM_Core_BAO_FinancialTrxn::deleteFinancialTrxn($id, 'civicrm_contribution');
     if ($participantId) {
         require_once 'CRM/Price/BAO/LineItem.php';
         CRM_Price_BAO_LineItem::deleteLineItems($participantId, 'civicrm_participant');
     } else {
         require_once 'CRM/Price/BAO/LineItem.php';
         CRM_Price_BAO_LineItem::deleteLineItems($id, 'civicrm_contribution');
     }
     $dao = new CRM_Contribute_DAO_Contribution();
     $dao->id = $id;
     $results = $dao->delete();
     $transaction->commit();
     CRM_Utils_Hook::post('delete', 'Contribution', $dao->id, $dao);
     // delete the recently created Contribution
     require_once 'CRM/Utils/Recent.php';
     $contributionRecent = array('id' => $id, 'type' => 'Contribution');
     CRM_Utils_Recent::del($contributionRecent);
     return $results;
 }
예제 #23
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  * @return void
  */
 function setDefaultValues()
 {
     $defaults = array();
     $config = CRM_Core_Config::singleton();
     if (isset($this->_id)) {
         $params = array('id' => $this->_id);
         CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $defaults);
         //set defaults for pledgeBlock values.
         require_once 'CRM/Pledge/BAO/PledgeBlock.php';
         $pledgeBlockParams = array('entity_id' => $this->_id, 'entity_table' => ts('civicrm_contribution_page'));
         $pledgeBlockDefaults = array();
         CRM_Pledge_BAO_pledgeBlock::retrieve($pledgeBlockParams, $pledgeBlockDefaults);
         if ($this->_pledgeBlockID = CRM_Utils_Array::value('id', $pledgeBlockDefaults)) {
             $defaults['is_pledge_active'] = true;
         }
         $pledgeBlock = array('is_pledge_interval', 'max_reminders', 'initial_reminder_day', 'additional_reminder_day');
         foreach ($pledgeBlock as $key) {
             $defaults[$key] = CRM_Utils_Array::value($key, $pledgeBlockDefaults);
         }
         require_once 'CRM/Core/BAO/CustomOption.php';
         if (CRM_Utils_Array::value('pledge_frequency_unit', $pledgeBlockDefaults)) {
             $defaults['pledge_frequency_unit'] = array_fill_keys(explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $pledgeBlockDefaults['pledge_frequency_unit']), '1');
         }
         // fix the display of the monetary value, CRM-4038
         require_once 'CRM/Utils/Money.php';
         if (isset($defaults['goal_amount'])) {
             $defaults['goal_amount'] = CRM_Utils_Money::format($defaults['goal_amount'], null, '%a');
         }
         // get price set id.
         require_once 'CRM/Price/BAO/Set.php';
         $this->_priceSetID = CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $this->_id);
         if ($this->_priceSetID) {
             $defaults['price_set_id'] = $this->_priceSetID;
         }
         if (CRM_Utils_Array::value('end_date', $defaults)) {
             list($defaults['end_date'], $defaults['end_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['end_date']);
         }
         if (CRM_Utils_Array::value('start_date', $defaults)) {
             list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['start_date']);
         }
     } else {
         $defaults['is_active'] = 1;
         // set current date as start date
         list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults();
     }
     if (!isset($defaults['for_organization'])) {
         $defaults['for_organization'] = ts('I am contributing on behalf of an organization.');
     }
     if (CRM_Utils_Array::value('recur_frequency_unit', $defaults)) {
         require_once 'CRM/Core/BAO/CustomOption.php';
         $defaults['recur_frequency_unit'] = array_fill_keys(explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $defaults['recur_frequency_unit']), '1');
     } else {
         require_once 'CRM/Core/OptionGroup.php';
         $defaults['recur_frequency_unit'] = array_fill_keys(CRM_Core_OptionGroup::values('recur_frequency_units'), '1');
     }
     if (!isset($defaults['is_recur_interval'])) {
         $defaults['is_recur_interval'] = 1;
     }
     if (CRM_Utils_Array::value('is_for_organization', $defaults)) {
         $defaults['is_organization'] = 1;
     } else {
         $defaults['is_for_organization'] = 1;
     }
     return $defaults;
 }