/** * takes an associative array and creates a price set object * * @param array $params (reference) an assoc array of name/value pairs * * @return object CRM_Price_DAO_Set object * @access public * @static */ static function create(&$params) { $priceSetBAO = new CRM_Price_BAO_Set(); $priceSetBAO->copyValues($params); if (defined('CIVICRM_EVENT_PRICE_SET_DOMAIN_ID') && CIVICRM_EVENT_PRICE_SET_DOMAIN_ID) { $priceSetBAO->domain_id = CRM_Core_Config::domainID(); } return $priceSetBAO->save(); }
/** * takes an associative array and creates a price set object * * @param array $params (reference) an assoc array of name/value pairs * * @return object CRM_Price_DAO_Set object * @access public * @static */ static function create(&$params) { $priceSetBAO = new CRM_Price_BAO_Set(); $priceSetBAO->copyValues($params); if (self::eventPriceSetDomainID()) { $priceSetBAO->domain_id = CRM_Core_Config::domainID(); } return $priceSetBAO->save(); }
/** * Process the form when submitted * * @return void * @access public */ public function postProcess() { if (CRM_Price_BAO_Set::deleteSet($this->_sid)) { CRM_Core_Session::setStatus(ts('The Price Set \'%1\' has been deleted.', array(1 => $this->_title))); } else { CRM_Core_Session::setStatus(ts('The Price Set \'%1\' has not been deleted! You must delete all price fields in this set prior to deleting the set.', array(1 => $this->_title))); } }
/** * pre processing work done here. * * gets session variables for group or field id * * @param null * * @return void * @access public */ function preProcess() { // get the controller vars $groupId = $this->get('groupId'); $fieldId = $this->get('fieldId'); if ($fieldId) { require_once 'CRM/Price/BAO/Set.php'; $groupTree = CRM_Price_BAO_Set::getSetDetail($groupId); $this->_groupTree[$groupId]['fields'][$fieldId] = $groupTree[$groupId]['fields'][$fieldId]; $this->assign('preview_type', 'field'); } else { // group preview require_once 'CRM/Price/BAO/Set.php'; $this->_groupTree = CRM_Price_BAO_Set::getSetDetail($groupId); $this->assign('preview_type', 'group'); } }
/** * pre processing work done here. * * gets session variables for group or field id * * @param null * * @return void * @access public */ function preProcess() { // get the controller vars $groupId = $this->get('groupId'); $fieldId = $this->get('fieldId'); if ($fieldId) { $groupTree = CRM_Price_BAO_Set::getSetDetail($groupId); $this->_groupTree[$groupId]['fields'][$fieldId] = $groupTree[$groupId]['fields'][$fieldId]; $this->assign('preview_type', 'field'); $url = CRM_Utils_System::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$groupId}"); $breadCrumb = array(array('title' => ts('Price Set Fields'), 'url' => $url)); } else { // group preview $this->_groupTree = CRM_Price_BAO_Set::getSetDetail($groupId); $this->assign('preview_type', 'group'); $this->assign('setTitle', CRM_Price_BAO_Set::getTitle($groupId)); $url = CRM_Utils_System::url('civicrm/admin/price', 'reset=1'); $breadCrumb = array(array('title' => ts('Price Sets'), 'url' => $url)); } CRM_Utils_System::appendBreadCrumb($breadCrumb); }
/** * 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; }
/** * 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]; }
/** * 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(); }
/** * Function to process the form * * @access public */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { require_once "CRM/Event/BAO/Participant.php"; CRM_Event_BAO_Participant::deleteParticipant($this->_participantId); return; } // get the submitted form values. $params = $this->controller->exportValues($this->_name); // set the contact, when contact is selected if (CRM_Utils_Array::value('contact_select_id', $params)) { $this->_contactID = CRM_Utils_Array::value('contact_select_id', $params); } $config =& CRM_Core_Config::singleton(); //check if discount is selected if (CRM_Utils_Array::value('discount_id', $params)) { $discountId = $params['discount_id']; } else { $params['discount_id'] = 'null'; $discountId = null; } if ($this->_isPaidEvent) { //lets carry currency, CRM-4453 $params['fee_currency'] = $config->defaultCurrency; // fix for CRM-3088 if ($discountId && !empty($this->_values['discount'][$discountId])) { $params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label']; $params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value']; $this->assign('amount_level', $params['amount_level']); } else { if (!isset($params['priceSetId'])) { $params['amount_level'] = $this->_values['fee'][$params['amount']]['label']; $params['amount'] = $this->_values['fee'][$params['amount']]['value']; $this->assign('amount_level', $params['amount_level']); } else { if (!$this->_online) { $lineItem = array(); CRM_Price_BAO_Set::processAmount($this->_values['fee']['fields'], $params, $lineItem[0]); $this->set('lineItem', $lineItem); $this->assign('lineItem', $lineItem); $this->_lineItem = $lineItem; } } } $params['fee_level'] = $params['amount_level']; $contributionParams = array(); $contributionParams['total_amount'] = $params['amount']; } //fix for CRM-3086 $params['fee_amount'] = $params['amount']; $this->_params = $params; unset($params['amount']); $params['register_date'] = CRM_Utils_Date::processDate($params['register_date'], $params['register_date_time']); $params['receive_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $params)); $params['contact_id'] = $this->_contactID; if ($this->_participantId) { $params['id'] = $this->_participantId; } $status = null; if ($this->_action & CRM_Core_Action::UPDATE) { $participantBAO =& new CRM_Event_BAO_Participant(); $participantBAO->id = $this->_participantId; $participantBAO->find(); while ($participantBAO->fetch()) { $status = $participantBAO->status_id; $contributionParams['total_amount'] = $participantBAO->fee_amount; } $params['discount_id'] = null; //re-enter the values for UPDATE mode $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level; $params['fee_amount'] = $participantBAO->fee_amount; } require_once 'CRM/Contact/BAO/Contact.php'; // Retrieve the name and email of the current user - this will be the FROM for the receipt email $session =& CRM_Core_Session::singleton(); $userID = $session->get('userID'); list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID); require_once "CRM/Event/BAO/Participant.php"; if ($this->_mode) { if (!$this->_isPaidEvent) { CRM_Core_Error::fatal(ts('Selected Event is not Paid Event ')); } //modify params according to parameter used in create //participant method (addParticipant) $params['participant_status_id'] = $params['status_id']; $params['participant_role_id'] = $params['role_id']; $params['participant_register_date'] = $params['register_date']; $params['participant_source'] = $params['source']; require_once 'CRM/Core/BAO/PaymentProcessor.php'; $this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($this->_params['payment_processor_id'], $this->_mode); require_once "CRM/Contact/BAO/Contact.php"; $now = date('YmdHis'); $fields = array(); // set email for primary location. $fields["email-Primary"] = 1; $params["email-Primary"] = $params["email-{$this->_bltID}"] = $this->_contributorEmail; $params['register_date'] = $now; // now set the values for the billing location. foreach ($this->_fields as $name => $dontCare) { $fields[$name] = 1; } // also add location name to the array $params["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params); $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]); $fields["address_name-{$this->_bltID}"] = 1; $fields["email-{$this->_bltID}"] = 1; $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type'); $nameFields = array('first_name', 'middle_name', 'last_name'); foreach ($nameFields as $name) { $fields[$name] = 1; if (array_key_exists("billing_{$name}", $params)) { $params[$name] = $params["billing_{$name}"]; $params['preserveDBName'] = true; } } $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $this->_contactID, null, null, $ctype); } // build custom data getFields array $customFieldsRole = CRM_Core_BAO_CustomField::getFields('Participant', false, false, CRM_Utils_Array::value('role_id', $params), $this->_roleCustomDataTypeID); $customFieldsEvent = CRM_Core_BAO_CustomField::getFields('Participant', false, false, CRM_Utils_Array::value('event_id', $params), $this->_eventNameCustomDataTypeID); $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsRole, CRM_Core_BAO_CustomField::getFields('Participant', false, false, null, null, true)); $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEvent, $customFields); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_participantId, 'Participant'); if ($this->_mode) { // add all the additioanl payment params we need $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]); $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]); $this->_params['year'] = $this->_params['credit_card_exp_date']['Y']; $this->_params['month'] = $this->_params['credit_card_exp_date']['M']; $this->_params['ip_address'] = CRM_Utils_System::ipAddress(); $this->_params['amount'] = $params['fee_amount']; $this->_params['amount_level'] = $params['amount_level']; $this->_params['currencyID'] = $config->defaultCurrency; $this->_params['payment_action'] = 'Sale'; $this->_params['invoiceID'] = md5(uniqid(rand(), true)); // at this point we've created a contact and stored its address etc // all the payment processors expect the name and address to be in the // so we copy stuff over to first_name etc. $paymentParams = $this->_params; if (CRM_Utils_Array::value('send_receipt', $this->_params)) { $paymentParams['email'] = $this->_contributorEmail; } require_once 'CRM/Core/Payment/Form.php'; CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, true); $payment =& CRM_Core_Payment::singleton($this->_mode, 'Event', $this->_paymentProcessor, $this); $result =& $payment->doDirectPayment($paymentParams); if (is_a($result, 'CRM_Core_Error')) { CRM_Core_Error::displaySessionError($result); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/participant', "reset=1&action=add&cid={$this->_contactID}&context=participant&mode={$this->_mode}")); } if ($result) { $this->_params = array_merge($this->_params, $result); } $this->_params['receive_date'] = $now; if (CRM_Utils_Array::value('send_receipt', $this->_params)) { $this->_params['receipt_date'] = $now; } else { $this->_params['receipt_date'] = null; } $this->set('params', $this->_params); $this->assign('trxn_id', $result['trxn_id']); $this->assign('receive_date', CRM_Utils_Date::processDate($this->_params['receive_date'])); // set source if not set $this->_params['description'] = ts('Submit Credit Card for Event Registration by: %1', array(1 => $userName)); require_once 'CRM/Event/Form/Registration/Confirm.php'; require_once 'CRM/Event/Form/Registration.php'; //add contribution record $this->_params['contribution_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'contribution_type_id'); $this->_params['mode'] = $this->_mode; //add contribution reocord $contribution = CRM_Event_Form_Registration_Confirm::processContribution($this, $this->_params, $result, $contactID, false); // add participant record $participants = array(); $participants[] = CRM_Event_Form_Registration::addParticipant($this->_params, $contactID); //add custom data for participant require_once 'CRM/Core/BAO/CustomValueTable.php'; CRM_Core_BAO_CustomValueTable::postProcess($this->_params, CRM_Core_DAO::$_nullArray, 'civicrm_participant', $participants[0]->id, 'Participant'); //add participant payment require_once 'CRM/Event/BAO/ParticipantPayment.php'; $paymentParticipant = array('participant_id' => $participants[0]->id, 'contribution_id' => $contribution->id); $ids = array(); CRM_Event_BAO_ParticipantPayment::create($paymentParticipant, $ids); $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'title'); $this->_contactIds[] = $this->_contactID; } else { $participants = array(); // fix note if deleted if (!$params['note']) { $params['note'] = 'null'; } if ($this->_single) { $participants[] = CRM_Event_BAO_Participant::create($params); } else { foreach ($this->_contactIds as $contactID) { $commonParams = $params; $commonParams['contact_id'] = $contactID; $participants[] = CRM_Event_BAO_Participant::create($commonParams); } } if (isset($params['event_id'])) { $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'title'); } if ($this->_single) { $this->_contactIds[] = $this->_contactID; } if (CRM_Utils_Array::value('record_contribution', $params)) { if (CRM_Utils_Array::value('id', $params)) { if ($this->_onlinePendingContributionId) { $ids['contribution'] = $this->_onlinePendingContributionId; } else { $ids['contribution'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $params['id'], 'contribution_id', 'participant_id'); } } unset($params['note']); //build contribution params if (!$this->_onlinePendingContributionId) { $contributionParams['source'] = "{$eventTitle}: Offline registration (by {$userName})"; } $contributionParams['currency'] = $config->defaultCurrency; $contributionParams['non_deductible_amount'] = 'null'; $contributionParams['receipt_date'] = CRM_Utils_Array::value('send_receipt', $params) ? CRM_Utils_Array::value('receive_date', $params) : 'null'; $recordContribution = array('contact_id', 'contribution_type_id', 'payment_instrument_id', 'trxn_id', 'contribution_status_id', 'receive_date', 'check_number'); foreach ($recordContribution as $f) { $contributionParams[$f] = CRM_Utils_Array::value($f, $params); if ($f == 'trxn_id') { $this->assign('trxn_id', $contributionParams[$f]); } } //insert contribution type name in receipt. $this->assign('contributionTypeName', CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionType', $contributionParams['contribution_type_id'])); require_once 'CRM/Contribute/BAO/Contribution.php'; $contributions = array(); if ($this->_single) { $contributions[] =& CRM_Contribute_BAO_Contribution::create($contributionParams, $ids); } else { $ids = array(); foreach ($this->_contactIds as $contactID) { $contributionParams['contact_id'] = $contactID; $contributions[] =& CRM_Contribute_BAO_Contribution::create($contributionParams, $ids); } } //insert payment record for this participation if (!$ids['contribution']) { require_once 'CRM/Event/DAO/ParticipantPayment.php'; foreach ($this->_contactIds as $num => $contactID) { $ppDAO =& new CRM_Event_DAO_ParticipantPayment(); $ppDAO->participant_id = $participants[$num]->id; $ppDAO->contribution_id = $contributions[$num]->id; $ppDAO->save(); } } } } // also store lineitem stuff here if ($this->_lineItem) { require_once 'CRM/Price/BAO/LineItem.php'; foreach ($this->_contactIds as $num => $contactID) { foreach ($this->_lineItem as $key => $value) { if (is_array($value) && $value != 'skip') { foreach ($value as $line) { $line['entity_table'] = 'civicrm_participant'; $line['entity_id'] = $participants[$num]->id; CRM_Price_BAO_LineItem::create($line); } } } } } $updateStatusMsg = null; //send mail when participant status changed, CRM-4326 if ($this->_participantId && $this->_statusId && $this->_statusId != CRM_Utils_Array::value('status_id', $params) && CRM_Utils_Array::value('is_notify', $params)) { require_once "CRM/Event/BAO/Participant.php"; $updateStatusMsg = CRM_Event_BAO_Participant::updateStatusMessage($this->_participantId, $params['status_id'], $this->_statusId); } if (CRM_Utils_Array::value('send_receipt', $params)) { $receiptFrom = "{$userName} <{$userEmail}>"; $this->assign('module', 'Event Registration'); //use of the message template below requires variables in different format $event = $events = array(); $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title'); //get all event details. CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties); $event = $events[$params['event_id']]; unset($event['start_date']); unset($event['end_date']); $role = CRM_Event_PseudoConstant::participantRole(); $event['participant_role'] = $role[$params['role_id']]; $event['is_monetary'] = $this->_isPaidEvent; if ($params['receipt_text']) { $event['confirm_email_text'] = $params['receipt_text']; } $this->assign('isAmountzero', 1); $this->assign('event', $event); $this->assign('isShowLocation', $event['is_show_location']); if (CRM_Utils_Array::value('is_show_location', $event) == 1) { $locationParams = array('entity_id' => $params['event_id'], 'entity_table' => 'civicrm_event'); require_once 'CRM/Core/BAO/Location.php'; $location = CRM_Core_BAO_Location::getValues($locationParams, true); $this->assign('location', $location); } $status = CRM_Event_PseudoConstant::participantStatus(); if ($this->_isPaidEvent) { $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); if (!$this->_mode) { $this->assign('paidBy', CRM_Utils_Array::value($params['payment_instrument_id'], $paymentInstrument)); } $this->assign('totalAmount', $contributionParams['total_amount']); $this->assign('isPrimary', 1); $this->assign('checkNumber', CRM_Utils_Array::value('check_number', $params)); } if ($this->_mode) { if (CRM_Utils_Array::value('billing_first_name', $params)) { $name = $params['billing_first_name']; } if (CRM_Utils_Array::value('billing_middle_name', $params)) { $name .= " {$params['billing_middle_name']}"; } if (CRM_Utils_Array::value('billing_last_name', $params)) { $name .= " {$params['billing_last_name']}"; } $this->assign('billingName', $name); // assign the address formatted up for display $addressParts = array("street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "state_province-{$this->_bltID}", "country-{$this->_bltID}"); $addressFields = array(); foreach ($addressParts as $part) { list($n, $id) = explode('-', $part); if (isset($this->_params['billing_' . $part])) { $addressFields[$n] = $this->_params['billing_' . $part]; } } require_once 'CRM/Utils/Address.php'; $this->assign('address', CRM_Utils_Address::format($addressFields)); $date = CRM_Utils_Date::format($params['credit_card_exp_date']); $date = CRM_Utils_Date::mysqlToIso($date); $this->assign('credit_card_exp_date', $date); $this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($params['credit_card_number'])); $this->assign('credit_card_type', $params['credit_card_type']); $this->assign('contributeMode', 'direct'); $this->assign('isAmountzero', 0); $this->assign('is_pay_later', 0); $this->assign('isPrimary', 1); } $this->assign('register_date', $params['register_date']); if ($params['receive_date']) { $this->assign('receive_date', $params['receive_date']); } $participant = array(array('participant_id', '=', $participants[0]->id, 0, 0)); // check whether its a test drive ref CRM-3075 if (CRM_Utils_Array::value('is_test', $this->_defaultValues)) { $participant[] = array('participant_test', '=', 1, 0, 0); } $template =& CRM_Core_Smarty::singleton(); $customGroup = array(); //format submitted data foreach ($params['custom'] as $fieldID => $values) { foreach ($values as $fieldValue) { $customValue = array('data' => $fieldValue['value']); $customFields[$fieldID]['id'] = $fieldID; $formattedValue = CRM_Core_BAO_CustomGroup::formatCustomValues($customValue, $customFields[$fieldID]); $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace(' ', '', $formattedValue); } } foreach ($this->_contactIds as $num => $contactID) { // Retrieve the name and email of the contact - this will be the TO for receipt email list($this->_contributorDisplayName, $this->_contributorEmail, $this->_toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($contactID); $this->_contributorDisplayName = $this->_contributorDisplayName == ' ' ? $this->_contributorEmail : $this->_contributorDisplayName; $this->assign('customGroup', $customGroup); $this->assign('contactID', $contactID); $this->assign('participantID', $participants[$num]->id); if ($this->_isPaidEvent) { // fix amount for each of participants ( for bulk mode ) $eventAmount = array(); $eventAmount[$num] = array('label' => $params['amount_level'], 'amount' => $params['fee_amount']); //as we are using same template for online & offline registration. //So we have to build amount as array. $this->assign('amount', $eventAmount); } $sendTemplateParams = array('groupName' => 'msg_tpl_workflow_event', 'valueName' => 'event_offline_receipt', 'contactId' => $contactID, 'isTest' => (bool) CRM_Utils_Array::value('is_test', $this->_defaultValues)); // try to send emails only if email id is present // and the do-not-email option is not checked for that contact if ($this->_contributorEmail and !$this->_toDoNotEmail) { $sendTemplateParams['from'] = $receiptFrom; $sendTemplateParams['toName'] = $this->_contributorDisplayName; $sendTemplateParams['toEmail'] = $this->_contributorEmail; } require_once 'CRM/Core/BAO/MessageTemplates.php'; list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate($sendTemplateParams); if ($mailSent) { $sent[] = $contactID; } else { $notSent[] = $contactID; } } } if ($this->_action & CRM_Core_Action::UPDATE) { $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contributorDisplayName)); if ($params['send_receipt'] && count($sent)) { $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', array(1 => $this->_contributorEmail)); } if ($updateStatusMsg) { $statusMsg = "{$statusMsg} {$updateStatusMsg}"; } } elseif ($this->_action & CRM_Core_Action::ADD) { if ($this->_single) { $statusMsg = ts('Event registration for %1 has been added.', array(1 => $this->_contributorDisplayName)); if (CRM_Utils_Array::value('send_receipt', $params) && count($sent)) { $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $this->_contributorEmail)); } } else { $statusMsg = ts('Total Participant(s) added to event: %1.', array(1 => count($this->_contactIds))); if (count($notSent) > 0) { $statusMsg .= ' ' . ts('Email has NOT been sent to %1 contact - communication preferences specify DO NOT EMAIL OR valid Email is NOT present. ', array(1 => count($notSent))); } elseif (isset($params['send_receipt'])) { $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants'); } } } require_once "CRM/Core/Session.php"; CRM_Core_Session::setStatus("{$statusMsg}"); $buttonName = $this->controller->getButtonName(); if ($this->_context == 'standalone') { if ($buttonName == $this->getButtonName('upload', 'new')) { $session->replaceUserContext(CRM_Utils_System::url('civicrm/participant/add', 'reset=1&action=add&context=standalone')); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactID}&selectedChild=participant")); } } else { if ($buttonName == $this->getButtonName('upload', 'new')) { $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/participant', "reset=1&action=add&context=participant&cid={$this->_contactID}")); } } }
/** * global validation rules for the form * * @param array $fields (referance) posted values of the form * * @return array if errors then list of errors to be posted back to the form, * true otherwise * @static * @access public */ static function formRule($fields, $files, $form) { // all option fields are of type "money" $errors = array(); /** Check the option values entered * Appropriate values are required for the selected datatype * Incomplete row checking is also required. */ if (($form->_action & CRM_Core_Action::ADD || $form->_action & CRM_Core_Action::UPDATE) && $fields['html_type'] == 'Text' && $fields['price'] == NULL) { $errors['price'] = ts('Price is a required field'); } //avoid the same price field label in Within PriceSet $priceFieldLabel = new CRM_Price_DAO_Field(); $priceFieldLabel->label = $fields['label']; $priceFieldLabel->price_set_id = $form->_sid; $dupeLabel = FALSE; if ($priceFieldLabel->find(TRUE) && $form->_fid != $priceFieldLabel->id) { $dupeLabel = TRUE; } if ($dupeLabel) { $errors['label'] = ts('Name already exists in Database.'); } if (is_numeric(CRM_Utils_Array::value('count', $fields)) && CRM_Utils_Array::value('count', $fields) == 0 && CRM_Utils_Array::value('html_type', $fields) == 'Text') { $errors['count'] = ts('Participant Count must be greater than zero.'); } if ($form->_action & CRM_Core_Action::ADD) { if ($fields['html_type'] != 'Text') { $countemptyrows = 0; $_flagOption = $_rowError = 0; $_showHide = new CRM_Core_ShowHideBlocks('', ''); for ($index = 1; $index <= self::NUM_OPTION; $index++) { $noLabel = $noAmount = $noWeight = 1; if (!empty($fields['option_label'][$index])) { $noLabel = 0; $duplicateIndex = CRM_Utils_Array::key($fields['option_label'][$index], $fields['option_label']); if (!($duplicateIndex === FALSE) && !($duplicateIndex == $index)) { $errors["option_label[{$index}]"] = ts('Duplicate label value'); $_flagOption = 1; } } if ($form->_useForMember) { if (!empty($fields['membership_type_id'][$index])) { $memTypesIDS[] = $fields['membership_type_id'][$index]; } } // allow for 0 value. if (!empty($fields['option_amount'][$index]) || strlen($fields['option_amount'][$index]) > 0) { $noAmount = 0; } if (!empty($fields['option_weight'][$index])) { $noWeight = 0; $duplicateIndex = CRM_Utils_Array::key($fields['option_weight'][$index], $fields['option_weight']); if (!($duplicateIndex === FALSE) && !($duplicateIndex == $index)) { $errors["option_weight[{$index}]"] = ts('Duplicate weight value'); $_flagOption = 1; } } if ($noLabel && !$noAmount) { $errors["option_label[{$index}]"] = ts('Label cannot be empty.'); $_flagOption = 1; } if (!$noLabel && $noAmount) { $errors["option_amount[{$index}]"] = ts('Amount cannot be empty.'); $_flagOption = 1; } if ($noLabel && $noAmount) { $countemptyrows++; $_emptyRow = 1; } elseif (!empty($fields['option_max_value'][$index]) && !empty($fields['option_count'][$index]) && $fields['option_count'][$index] > $fields['option_max_value'][$index]) { $errors["option_max_value[{$index}]"] = ts('Participant count can not be greater than max participants.'); $_flagOption = 1; } $showBlocks = 'optionField_' . $index; if ($_flagOption) { $_showHide->addShow($showBlocks); $_rowError = 1; } if (!empty($_emptyRow)) { $_showHide->addHide($showBlocks); } else { $_showHide->addShow($showBlocks); } if ($index == self::NUM_OPTION) { $hideBlock = 'additionalOption'; $_showHide->addHide($hideBlock); } $_flagOption = $_emptyRow = 0; } if (!empty($memTypesIDS)) { // check for checkboxes allowing user to select multiple memberships from same membership organization if ($fields['html_type'] == 'CheckBox') { $foundDuplicate = FALSE; $orgIds = array(); foreach ($memTypesIDS as $key => $val) { $org = CRM_Member_BAO_MembershipType::getMembershipTypeOrganization($val); if (in_array($org[$val], $orgIds)) { $foundDuplicate = TRUE; break; } $orgIds[$val] = $org[$val]; } if ($foundDuplicate) { $errors['_qf_default'] = ts('You have selected multiple memberships for the same organization or entity. Please review your selections and choose only one membership per entity.'); } } // CRM-10390 - Only one price field in a set can include auto-renew membership options $foundAutorenew = FALSE; foreach ($memTypesIDS as $key => $val) { // see if any price field option values in this price field are for memberships with autorenew $memTypeDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($val); if (CRM_Utils_Array::value('auto_renew', $memTypeDetails)) { $foundAutorenew = TRUE; break; } } if ($foundAutorenew) { // if so, check for other fields in this price set which also have auto-renew membership options $otherFieldAutorenew = CRM_Price_BAO_Set::checkAutoRenewForPriceSet($form->_sid); if ($otherFieldAutorenew) { $errors['_qf_default'] = ts('You can include auto-renew membership choices for only one price field in a price set. Another field in this set already contains one or more auto-renew membership options.'); } } } $_showHide->addToTemplate(); if ($countemptyrows == 11) { $errors['option_label[1]'] = $errors['option_amount[1]'] = ts('Label and value cannot be empty.'); $_flagOption = 1; } } elseif (!empty($fields['max_value']) && !empty($fields['count']) && $fields['count'] > $fields['max_value']) { $errors['max_value'] = ts('Participant count can not be greater than max participants.'); } // do not process if no option rows were submitted if (empty($fields['option_amount']) && empty($fields['option_label'])) { return TRUE; } if (empty($fields['option_name'])) { $fields['option_amount'] = array(); } if (empty($fields['option_label'])) { $fields['option_label'] = array(); } } return empty($errors) ? TRUE : $errors; }
/** * 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(); }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { $config = CRM_Core_Config::singleton(); $session = CRM_Core_Session::singleton(); // current contribution page id $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); if (!$this->_id) { $pastContributionID = $session->get('pastContributionID'); if (!$pastContributionID) { CRM_Core_Error::fatal(ts('We can\'t load the requested web page due to an incomplete link. This can be caused by using your browser\'s Back button or by using an incomplete or invalid link.')); } else { CRM_Core_Error::fatal(ts('This contribution has already been submitted. Click <a href=\'%1\'>here</a> if you want to make another contribution.', array(1 => CRM_Utils_System::url('civicrm/contribute/transact', 'reset=1&id=' . $pastContributionID)))); } } else { $session->set('pastContributionID', $this->_id); } $this->_userID = $session->get('userID'); $this->_mid = null; if ($this->_userID) { $this->_mid = CRM_Utils_Request::retrieve('mid', 'Positive', $this); if ($this->_mid) { require_once 'CRM/Member/DAO/Membership.php'; $membership = new CRM_Member_DAO_Membership(); $membership->id = $this->_mid; if ($membership->find(true)) { $this->_defaultMemTypeId = $membership->membership_type_id; if ($membership->contact_id != $this->_userID) { require_once 'CRM/Contact/BAO/Relationship.php'; $employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($this->_userID); if (array_key_exists($membership->contact_id, $employers)) { $this->_membershipContactID = $membership->contact_id; $this->assign('membershipContactID', $this->_membershipContactID); $this->assign('membershipContactName', $employers[$this->_membershipContactID]['name']); } else { CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership.")); } } } else { CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership.")); } unset($membership); } } // we do not want to display recently viewed items, so turn off $this->assign('displayRecent', false); // Contribution page values are cleared from session, so can't use normal Printer Friendly view. // Use Browser Print instead. $this->assign('browserPrint', true); // action $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'add'); $this->assign('action', $this->_action); // current mode $this->_mode = $this->_action == 1024 ? 'test' : 'live'; $this->_values = $this->get('values'); $this->_fields = $this->get('fields'); $this->_bltID = $this->get('bltID'); $this->_paymentProcessor = $this->get('paymentProcessor'); $this->_priceSetId = $this->get('priceSetId'); $this->_priceSet = $this->get('priceSet'); if (!$this->_values) { // get all the values from the dao object $this->_values = array(); $this->_fields = array(); require_once 'CRM/Contribute/BAO/ContributionPage.php'; CRM_Contribute_BAO_ContributionPage::setValues($this->_id, $this->_values); // check if form is active if (!$this->_values['is_active']) { // form is inactive, die a fatal death CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.')); } // also check for billing informatin // 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); // check for is_monetary status $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values); $isPayLater = CRM_Utils_Array::value('is_pay_later', $this->_values); if ($isMonetary && (!$isPayLater || CRM_Utils_Array::value('payment_processor_id', $this->_values))) { $ppID = CRM_Utils_Array::value('payment_processor_id', $this->_values); if (!$ppID) { CRM_Core_Error::fatal(ts('A payment processor must be selected for this contribution page (contact the site administrator for assistance).')); } require_once 'CRM/Core/BAO/PaymentProcessor.php'; $this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode); // check selected payment processor is active if (empty($this->_paymentProcessor)) { CRM_Core_Error::fatal(ts('A payment processor configured for this page might be disabled (contact the site administrator for assistance).')); } // ensure that processor has a valid config $this->_paymentObject =& CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this); $error = $this->_paymentObject->checkConfig(); if (!empty($error)) { CRM_Core_Error::fatal($error); } $this->_paymentProcessor['processorName'] = $this->_paymentObject->_processorName; $this->set('paymentProcessor', $this->_paymentProcessor); } // get price info // CRM-5095 require_once 'CRM/Price/BAO/Set.php'; CRM_Price_BAO_Set::initSet($this, $this->_id, 'civicrm_contribution_page'); // this avoids getting E_NOTICE errors in php $setNullFields = array('amount_block_is_active', 'honor_block_is_active', 'is_allow_other_amount', 'footer_text'); foreach ($setNullFields as $f) { if (!isset($this->_values[$f])) { $this->_values[$f] = null; } } //check if Membership Block is enabled, if Membership Fields are included in profile //get membership section for this contribution page require_once 'CRM/Member/BAO/Membership.php'; $this->_membershipBlock = CRM_Member_BAO_Membership::getMembershipBlock($this->_id); $this->set('membershipBlock', $this->_membershipBlock); require_once "CRM/Core/BAO/UFField.php"; if ($this->_values['custom_pre_id']) { $preProfileType = CRM_Core_BAO_UFField::getProfileType($this->_values['custom_pre_id']); } if ($this->_values['custom_post_id']) { $postProfileType = CRM_Core_BAO_UFField::getProfileType($this->_values['custom_post_id']); } // also set cancel subscription url if (CRM_Utils_Array::value('is_recur', $this->_paymentProcessor) && CRM_Utils_Array::value('is_recur', $this->_values)) { $this->_values['cancelSubscriptionUrl'] = $this->_paymentObject->cancelSubscriptionURL(); } if ((isset($postProfileType) && $postProfileType == 'Membership' || isset($preProfileType) && $preProfileType == 'Membership') && !$this->_membershipBlock['is_active']) { CRM_Core_Error::fatal(ts('This page includes a Profile with Membership fields - but the Membership Block is NOT enabled. Please notify the site administrator.')); } require_once 'CRM/Pledge/BAO/PledgeBlock.php'; $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::getPledgeBlock($this->_id); if ($pledgeBlock) { $this->_values['pledge_block_id'] = CRM_Utils_Array::value('id', $pledgeBlock); $this->_values['max_reminders'] = CRM_Utils_Array::value('max_reminders', $pledgeBlock); $this->_values['initial_reminder_day'] = CRM_Utils_Array::value('initial_reminder_day', $pledgeBlock); $this->_values['additional_reminder_day'] = CRM_Utils_Array::value('additional_reminder_day', $pledgeBlock); //set pledge id in values $pledgeId = CRM_Utils_Request::retrieve('pledgeId', 'Positive', $this); //authenticate pledge user for pledge payment. if ($pledgeId) { $this->_values['pledge_id'] = $pledgeId; self::authenticatePledgeUser(); } } $this->set('values', $this->_values); $this->set('fields', $this->_fields); } require_once 'CRM/Contribute/BAO/PCP.php'; $pcpId = CRM_Utils_Request::retrieve('pcpId', 'Positive', $this); if ($pcpId) { require_once 'CRM/Core/OptionGroup.php'; $approvedId = CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name'); $prms = array('entity_id' => $this->_values['id'], 'entity_table' => 'civicrm_contribution_page'); require_once 'CRM/Contribute/PseudoConstant.php'; $pcpStatus = CRM_Contribute_PseudoConstant::pcpStatus(); CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_PCPBlock', $prms, $pcpBlock); $prms = array('id' => $pcpId); CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_PCP', $prms, $pcpInfo); //start and end date of the contribution page $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('start_date', $this->_values)); $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $this->_values)); $now = time(); if ($pcpInfo['contribution_page_id'] != $this->_values['id']) { $statusMessage = ts('This contribution page is not related to the Personal Campaign Page you have just visited. However you can still make a contribution here.'); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$this->_values['id']}", false, null, false, true)); } else { if ($pcpInfo['status_id'] != $approvedId) { $statusMessage = ts('The Personal Campaign Page you have just visited is currently %1. However you can still support the campaign by making a contribution here.', array(1 => $pcpStatus[$pcpInfo['status_id']])); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true)); } else { if (!CRM_Utils_Array::value('is_active', $pcpBlock)) { $statusMessage = ts('Personal Campaign Pages are currently not enabled for this contribution page. However you can still support the campaign by making a contribution here.'); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true)); } else { if (!CRM_Utils_Array::value('is_active', $pcpInfo)) { $statusMessage = ts('The Personal Campaign Page you have just visited is current inactive. However you can still make a contribution here.'); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true)); } else { if ($startDate && $startDate > $now || $endDate && $endDate < $now) { $customStartDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $this->_values)); $customEndDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $this->_values)); if ($startDate && $endDate) { $statusMessage = ts('The Personal Campaign Page you have just visited is only active between %1 to %2. However you can still support the campaign by making a contribution here.', array(1 => $customStartDate, 2 => $customEndDate)); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true)); } else { if ($startDate) { $statusMessage = ts('The Personal Campaign Page you have just visited will be active beginning on %1. However you can still support the campaign by making a contribution here.', array(1 => $customStartDate)); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true)); } else { if ($endDate) { $statusMessage = ts('The Personal Campaign Page you have just visited is not longer active (as of %1). However you can still support the campaign by making a contribution here.', array(1 => $customEndDate)); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true)); } } } } } } } } $this->_pcpId = $pcpId; $this->_pcpBlock = $pcpBlock; $this->_pcpInfo = $pcpInfo; } // Link (button) for users to create their own Personal Campaign page if ($linkText = CRM_Contribute_BAO_PCP::getPcpBlockStatus($this->_id)) { $linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign', "action=add&reset=1&pageId={$this->_id}", false, null, true); $this->assign('linkTextUrl', $linkTextUrl); $this->assign('linkText', $linkText); } //set pledge block if block id is set if (CRM_Utils_Array::value('pledge_block_id', $this->_values)) { $this->assign('pledgeBlock', true); } // we do this outside of the above conditional to avoid // saving the country/state list in the session (which could be huge) if ($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM && CRM_Utils_Array::value('is_monetary', $this->_values)) { require_once 'CRM/Core/Payment/Form.php'; require_once 'CRM/Core/Payment.php'; // payment fields are depending on payment type if ($this->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) { CRM_Core_Payment_Form::setDirectDebitFields($this); } else { CRM_Core_Payment_Form::setCreditCardFields($this); } } $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor); // check if this is a paypal auto return and redirect accordingly if (CRM_Core_Payment::paypalRedirect($this->_paymentProcessor)) { $url = CRM_Utils_System::url('civicrm/contribute/transact', "_qf_ThankYou_display=1&qfKey={$this->controller->_key}"); CRM_Utils_System::redirect($url); } // make sure we have a valid payment class, else abort if (CRM_Utils_Array::value('is_monetary', $this->_values) && !$this->_paymentProcessor['class_name'] && !CRM_Utils_Array::value('is_pay_later', $this->_values)) { CRM_Core_Error::fatal(ts('Payment processor is not set for this page')); } // check if one of the (amount , membership) bloks is active or not require_once 'CRM/Member/BAO/Membership.php'; $this->_membershipBlock = $this->get('membershipBlock'); if (!$this->_values['amount_block_is_active'] && !$this->_membershipBlock['is_active'] && !$this->_priceSetId) { CRM_Core_Error::fatal(ts('The requested online contribution page is missing a required Contribution Amount section or Membership section or Price Set. Please check with the site administrator for assistance.')); } if ($this->_values['amount_block_is_active']) { $this->set('amount_block_is_active', $this->_values['amount_block_is_active']); } if (!empty($this->_membershipBlock) && CRM_Utils_Array::value('is_separate_payment', $this->_membershipBlock) && !($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM)) { CRM_Core_Error::fatal(ts('This contribution page is configured to support separate contribution and membership payments. This %1 plugin does not currently support multiple simultaneous payments. Please contact the site administrator and notify them of this error', array(1 => $this->_paymentProcessor['payment_processor_type']))); } $this->_contributeMode = $this->get('contributeMode'); $this->assign('contributeMode', $this->_contributeMode); //assigning is_monetary and is_email_receipt to template $this->assign('is_monetary', $this->_values['is_monetary']); $this->assign('is_email_receipt', $this->_values['is_email_receipt']); $this->assign('bltID', $this->_bltID); //assign cancelSubscription URL to templates $this->assign('cancelSubscriptionUrl', CRM_Utils_Array::value('cancelSubscriptionUrl', $this->_values)); // assigning title to template in case someone wants to use it, also setting CMS page title if ($this->_pcpId) { $this->assign('title', $pcpInfo['title']); CRM_Utils_System::setTitle($pcpInfo['title']); } else { $this->assign('title', $this->_values['title']); CRM_Utils_System::setTitle($this->_values['title']); } $this->_defaults = array(); $this->_amount = $this->get('amount'); //CRM-6907 $config = CRM_Core_Config::singleton(); $config->defaultCurrency = CRM_Utils_Array::value('currency', $this->_values, $config->defaultCurrency); }
/** * Function to build status message while * enabling/ disabling various objects */ static function getStatusMsg(&$config) { $recordID = CRM_Utils_Type::escape($_POST['recordID'], 'Integer'); $recordBAO = CRM_Utils_Type::escape($_POST['recordBAO'], 'String'); $op = CRM_Utils_Type::escape($_POST['op'], 'String'); $show = null; if ($op == 'disable-enable') { $status = ts('Are you sure you want to enable this record?'); } else { switch ($recordBAO) { case 'CRM_Core_BAO_UFGroup': require_once str_replace('_', DIRECTORY_SEPARATOR, $recordBAO) . ".php"; $method = 'getUFJoinRecord'; $result = array($recordBAO, $method); $ufJoin = call_user_func_array($result, array($recordID, true)); if (!empty($ufJoin)) { $status = ts('This profile is currently used for %1.', array(1 => implode(', ', $ufJoin))) . ' <br/><br/>' . ts('If you disable the profile - it will be removed from these forms and/or modules. Do you want to continue?'); } else { $status = ts('Are you sure you want to disable this profile?'); } break; case 'CRM_Price_BAO_Set': require_once str_replace('_', DIRECTORY_SEPARATOR, $recordBAO) . ".php"; $usedBy = CRM_Price_BAO_Set::getUsedBy($recordID); $priceSet = CRM_Price_BAO_Set::getTitle($recordID); if (!CRM_Utils_System::isNull($usedBy)) { $template =& CRM_Core_Smarty::singleton(); $template->assign('usedBy', $usedBy); $comps = array("Event" => "civicrm_event", "Contribution" => "civicrm_contribution_page"); $contexts = array(); foreach ($comps as $name => $table) { if (array_key_exists($table, $usedBy)) { $contexts[] = $name; } } $template->assign('contexts', $contexts); $show = "noButton"; $table = $template->fetch('CRM/Price/Page/table.tpl'); $status = ts('Unable to disable the \'%1\' price set - it is currently in use by one or more active events, contribution pages or contributions.', array(1 => $priceSet)) . "<br/> {$table}"; } else { $status = ts('Are you sure you want to disable \'%1\' Price Set?', array(1 => $priceSet)); } break; case 'CRM_Event_BAO_Event': $status = ts('Are you sure you want to disable this Event?'); break; case 'CRM_Core_BAO_UFField': $status = ts('Are you sure you want to disable this CiviCRM Profile field?'); break; case 'CRM_Contribute_BAO_ManagePremiums': $status = ts('Are you sure you want to disable this premium? This action will remove the premium from any contribution pages that currently offer it. However it will not delete the premium record - so you can re-enable it and add it back to your contribution page(s) at a later time.'); break; case 'CRM_Contact_BAO_RelationshipType': $status = ts('Are you sure you want to disable this relationship type?') . '<br/><br/>' . ts('Users will no longer be able to select this value when adding or editing relationships between contacts.'); break; case 'CRM_Contribute_BAO_ContributionType': $status = ts('Are you sure you want to disable this contribution type?'); break; case 'CRM_Core_BAO_PaymentProcessor': $status = ts('Are you sure you want to disable this payment processor?') . ' <br/><br/>' . ts('Users will no longer be able to select this value when adding or editing transaction pages.'); break; case 'CRM_Core_BAO_PaymentProcessorType': $status = ts('Are you sure you want to disable this payment processor type?'); break; case 'CRM_Core_BAO_LocationType': $status = ts('Are you sure you want to disable this location type?') . ' <br/><br/>' . ts('Users will no longer be able to select this value when adding or editing contact locations.'); break; case 'CRM_Event_BAO_ParticipantStatusType': $status = ts('Are you sure you want to disable this Participant Status?') . '<br/><br/> ' . ts('Users will no longer be able to select this value when adding or editing Participant Status.'); break; case 'CRM_Mailing_BAO_Component': $status = ts('Are you sure you want to disable this component?'); break; case 'CRM_Core_BAO_CustomField': $status = ts('Are you sure you want to disable this custom data field?'); break; case 'CRM_Core_BAO_CustomGroup': $status = ts('Are you sure you want to disable this custom data group? Any profile fields that are linked to custom fields of this group will be disabled.'); break; case 'CRM_Core_BAO_MessageTemplates': $status = ts('Are you sure you want to disable this message tempate?'); break; case 'CRM_ACL_BAO_ACL': $status = ts('Are you sure you want to disable this ACL?'); break; case 'CRM_ACL_BAO_EntityRole': $status = ts('Are you sure you want to disable this ACL Role Assignment?'); break; case 'CRM_Member_BAO_MembershipType': $status = ts('Are you sure you want to disable this membership type?'); break; case 'CRM_Member_BAO_MembershipStatus': $status = ts('Are you sure you want to disable this membership status rule?'); break; case 'CRM_Price_BAO_Field': $status = ts('Are you sure you want to disable this price field?'); break; case 'CRM_Contact_BAO_Group': $status = ts('Are you sure you want to disable this Group?'); break; case 'CRM_Core_BAO_OptionGroup': $status = ts('Are you sure you want to disable this Option?'); break; case 'CRM_Contact_BAO_ContactType': $status = ts('Are you sure you want to disable this Contact Type?'); break; case 'CRM_Core_BAO_OptionValue': require_once str_replace('_', DIRECTORY_SEPARATOR, $recordBAO) . ".php"; $label = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $recordID, 'label'); $status = ts('Are you sure you want to disable this \'%1\' record ?', array(1 => $label)); break; default: $status = ts('Are you sure you want to disable this record?'); break; } } $statusMessage['status'] = $status; $statusMessage['show'] = $show; echo json_encode($statusMessage); exit; }
/** * Run the page. * * This method is called after the page is created. It checks for the * type of action and executes that action. * * @param null * * @return void * @access public */ function run() { require_once 'CRM/Price/BAO/Set.php'; // get the group id $this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive', $this); $fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, false, 0); $action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse'); // default to 'browse' if ($this->_sid) { require_once 'CRM/Price/BAO/Set.php'; CRM_Price_BAO_Set::checkPermission($this->_sid); } if ($action & CRM_Core_Action::DELETE) { require_once 'CRM/Price/BAO/Set.php'; $usedBy =& CRM_Price_BAO_Set::getUsedBy($this->_sid); if (empty($usedBy)) { // prompt to delete $session =& CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid)); $controller =& new CRM_Core_Controller_Simple('CRM_Price_Form_DeleteField', "Delete Price Field", ''); $controller->set('fid', $fid); $controller->setEmbedded(true); $controller->process(); $controller->run(); } else { // add breadcrumb require_once 'CRM/Price/BAO/Field.php'; $url = CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1'); CRM_Utils_System::appendBreadCrumb(ts('Price'), $url); $this->assign('usedPriceSetTitle', CRM_Price_BAO_Field::getTitle($fid)); $this->assign('usedBy', $usedBy); $comps = array("Event" => "civicrm_event", "Contribution" => "civicrm_contribution_page"); $priceSetContexts = array(); foreach ($comps as $name => $table) { if (array_key_exists($table, $usedBy)) { $priceSetContexts[] = $name; } } $this->assign('contexts', $priceSetContexts); } } if ($this->_sid) { $groupTitle = CRM_Price_BAO_Set::getTitle($this->_sid); $this->assign('sid', $this->_sid); $this->assign('groupTitle', $groupTitle); CRM_Utils_System::setTitle(ts('%1 - Price Fields', array(1 => $groupTitle))); } // assign vars to templates $this->assign('action', $action); // what action to take ? if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { $this->edit($action); // no browse for edit/update/view } else { if ($action & CRM_Core_Action::PREVIEW) { $this->preview($fid); } else { require_once 'CRM/Price/BAO/Field.php'; $this->browse(); } } // Call the parents run method parent::run(); }
/** * Function to process price set and line items. * * @access public * @return None */ function processPriceSet($contributionId, $lineItem) { if (!$contributionId || !is_array($lineItem) || CRM_Utils_system::isNull($lineItem)) { return; } require_once 'CRM/Price/BAO/Set.php'; require_once 'CRM/Price/BAO/LineItem.php'; foreach ($lineItem as $priceSetId => $values) { if (!$priceSetId) { continue; } foreach ($values as $line) { $line['entity_table'] = 'civicrm_contribution'; $line['entity_id'] = $contributionId; CRM_Price_BAO_LineItem::create($line); } CRM_Price_BAO_Set::addTo('civicrm_contribution', $contributionId, $priceSetId); } }
/** * 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() { if ($this->_action & CRM_Core_Action::DELETE) { CRM_Member_BAO_Membership::deleteRelatedMemberships($this->_id); CRM_Member_BAO_Membership::deleteMembership($this->_id); return; } $config = CRM_Core_Config::singleton(); // get the submitted form values. $this->_params = $formValues = $this->controller->exportValues($this->_name); $params = $ids = array(); $membershipTypeValues = array(); foreach ($this->_memTypeSelected as $memType) { $membershipTypeValues[$memType]['membership_type_id'] = $memType; } //take the required membership recur values. if ($this->_mode && CRM_Utils_Array::value('auto_renew', $this->_params)) { $params['is_recur'] = $this->_params['is_recur'] = $formValues['is_recur'] = TRUE; $mapping = array('frequency_interval' => 'duration_interval', 'frequency_unit' => 'duration_unit'); $count = 0; foreach ($this->_memTypeSelected as $memType) { $recurMembershipTypeValues = CRM_Utils_Array::value($memType, $this->_recurMembershipTypes, array()); foreach ($mapping as $mapVal => $mapParam) { $membershipTypeValues[$memType][$mapVal] = CRM_Utils_Array::value($mapParam, $recurMembershipTypeValues); if (!$count) { $this->_params[$mapVal] = $formValues[$mapVal] = CRM_Utils_Array::value($mapParam, $recurMembershipTypeValues); } } $count++; } // unset send-receipt option, since receipt will be sent when ipn is received. unset($this->_params['send_receipt'], $formValues['send_receipt']); } // process price set and get total amount and line items. $lineItem = array(); $priceSetId = NULL; if (!($priceSetId = CRM_Utils_Array::value('price_set_id', $formValues))) { CRM_Member_BAO_Membership::createLineItems($this, $formValues['membership_type_id'], $priceSetId); } if ($priceSetId) { CRM_Price_BAO_Set::processAmount($this->_priceSet['fields'], $this->_params, $lineItem[$priceSetId]); $params['total_amount'] = CRM_Utils_Array::value('amount', $this->_params); } $this->storeContactFields($formValues); $params['contact_id'] = $this->_contactID; $fields = array('status_id', 'source', 'is_override', 'campaign_id'); foreach ($fields as $f) { $params[$f] = CRM_Utils_Array::value($f, $formValues); } // fix for CRM-3724 // when is_override false ignore is_admin statuses during membership // status calculation. similarly we did fix for import in CRM-3570. if (!CRM_Utils_Array::value('is_override', $params)) { $params['exclude_is_admin'] = TRUE; } // process date params to mysql date format. $dateTypes = array('join_date' => 'joinDate', 'start_date' => 'startDate', 'end_date' => 'endDate'); foreach ($dateTypes as $dateField => $dateVariable) { ${$dateVariable} = CRM_Utils_Date::processDate($formValues[$dateField]); } $dates = array('join_date', 'start_date', 'end_date', 'reminder_date'); $calcDates = array(); foreach ($this->_memTypeSelected as $memType) { $calcDates[$memType] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($memType, $joinDate, $startDate, $endDate); } foreach ($calcDates as $memType => $calcDate) { foreach ($dates as $d) { //first give priority to form values then calDates. $date = CRM_Utils_Array::value($d, $formValues); if (!$date) { $date = CRM_Utils_Array::value($d, $calcDate); } $membershipTypeValues[$memType][$d] = CRM_Utils_Date::processDate($date); //$params[$d] = CRM_Utils_Date::processDate( $date ); } } if ($this->_id) { $ids['membership'] = $params['id'] = $this->_id; } $session = CRM_Core_Session::singleton(); $ids['userId'] = $session->get('userID'); // membership type custom data foreach ($this->_memTypeSelected as $memType) { $customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $memType); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, NULL, NULL, TRUE)); $membershipTypeValues[$memType]['custom'] = CRM_Core_BAO_CustomField::postProcess($formValues, $customFields, $this->_id, 'Membership'); } foreach ($this->_memTypeSelected as $memType) { $membershipTypes[$memType] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $memType); } $membershipType = implode(', ', $membershipTypes); // Retrieve the name and email of the current user - this will be the FROM for the receipt email list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($ids['userId']); //CRM-10223 - allow contribution to be recorded against different contact if ($this->_contributorContactID != $this->_contactID) { $params['contribution_contact_id'] = $this->_contributorContactID; if (CRM_Utils_Array::value('honor_type_id', $this->_params)) { $params['honor_type_id'] = $this->_params['honor_type_id']; $params['honor_contact_id'] = $params['contact_id']; } } if (CRM_Utils_Array::value('record_contribution', $formValues)) { $recordContribution = array('total_amount', 'honor_type_id', 'contribution_type_id', 'payment_instrument_id', 'trxn_id', 'contribution_status_id', 'check_number', 'campaign_id', 'receive_date'); foreach ($recordContribution as $f) { $params[$f] = CRM_Utils_Array::value($f, $formValues); } if (!$this->_onlinePendingContributionId) { $params['contribution_source'] = ts('%1 Membership: Offline signup (by %2)', array(1 => $membershipType, 2 => $userName)); } if (!CRM_Utils_Array::value('is_override', $params) && CRM_Utils_Array::value('contribution_status_id', $params) == array_search('Pending', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'))) { $allStatus = CRM_Member_PseudoConstant::membershipStatus(); $params['status_id'] = array_search('Pending', $allStatus); $params['skipStatusCal'] = TRUE; $params['is_pay_later'] = 1; $this->assign('is_pay_later', 1); } if (CRM_Utils_Array::value('receive_date', $params)) { $formValues['receive_date'] = $params['receive_date'] = CRM_Utils_Date::processDate($params['receive_date']); } if (CRM_Utils_Array::value('send_receipt', $formValues)) { $params['receipt_date'] = CRM_Utils_Array::value('receive_date', $params); } //insert contribution type name in receipt. $formValues['contributionType_name'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionType', $formValues['contribution_type_id']); } // process line items, until no previous line items. if (!empty($lineItem)) { $params['lineItems'] = $lineItem; $params['processPriceSet'] = TRUE; } //crm_core_error::debug('params', $params ); //crm_core_error::debug('formValue', $formValues ); //exit; $createdMemberships = array(); if ($this->_mode) { if (empty($formValues['total_amount']) && !$priceSetId) { // if total amount not provided minimum for membership type is used $params['total_amount'] = $formValues['total_amount'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $formValues['membership_type_id'][1], 'minimum_fee'); } else { $params['total_amount'] = CRM_Utils_Array::value('total_amount', $formValues, 0); } if ($priceSetId) { $params['contribution_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $priceSetId, 'contribution_type_id'); } else { $params['contribution_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', end($this->_memTypeSelected), 'contribution_type_id'); } $this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($formValues['payment_processor_id'], $this->_mode); //get the payment processor id as per mode. $params['payment_processor_id'] = $this->_params['payment_processor_id'] = $formValues['payment_processor_id'] = $this->_paymentProcessor['id']; $now = date('YmdHis'); $fields = array(); // set email for primary location. $fields["email-Primary"] = 1; $formValues["email-5"] = $formValues["email-Primary"] = $this->_memberEmail; $params['register_date'] = $now; // now set the values for the billing location. foreach ($this->_fields as $name => $dontCare) { $fields[$name] = 1; } // also add location name to the array $formValues["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_middle_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_last_name', $formValues); $formValues["address_name-{$this->_bltID}"] = trim($formValues["address_name-{$this->_bltID}"]); $fields["address_name-{$this->_bltID}"] = 1; $fields["email-{$this->_bltID}"] = 1; $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type'); $nameFields = array('first_name', 'middle_name', 'last_name'); foreach ($nameFields as $name) { $fields[$name] = 1; if (array_key_exists("billing_{$name}", $formValues)) { $formValues[$name] = $formValues["billing_{$name}"]; $formValues['preserveDBName'] = TRUE; } } //here we are setting up the billing contact - if different from the member they are already created // but they will get billing details assigned CRM_Contact_BAO_Contact::createProfileContact($formValues, $fields, $this->_contributorContactID, NULL, NULL, $ctype); // add all the additioanl payment params we need $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]); $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]); $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params); $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params); $this->_params['ip_address'] = CRM_Utils_System::ipAddress(); $this->_params['amount'] = $params['total_amount']; $this->_params['currencyID'] = $config->defaultCurrency; $this->_params['payment_action'] = 'Sale'; $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE)); $this->_params['contribution_type_id'] = $params['contribution_type_id']; // at this point we've created a contact and stored its address etc // all the payment processors expect the name and address to be in the // so we copy stuff over to first_name etc. $paymentParams = $this->_params; $paymentParams['contactID'] = $this->_contributorContactID; //CRM-10377 if payment is by an alternate contact then we need to set that person // as the contact in the payment params if ($this->_contributorContactID != $this->_contactID) { if (CRM_Utils_Array::value('honor_type_id', $this->_params)) { $paymentParams['honor_contact_id'] = $this->_contactID; $paymentParams['honor_type_id'] = $this->_params['honor_type_id']; } } if (CRM_Utils_Array::value('send_receipt', $this->_params)) { $paymentParams['email'] = $this->_contributorEmail; } CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE); // CRM-7137 -for recurring membership, // we do need contribution and recuring records. $result = NULL; if (CRM_Utils_Array::value('is_recur', $paymentParams)) { $allStatus = CRM_Member_PseudoConstant::membershipStatus(); $contributionType = new CRM_Contribute_DAO_ContributionType(); $contributionType->id = $params['contribution_type_id']; if (!$contributionType->find(TRUE)) { CRM_Core_Error::fatal('Could not find a system table'); } $contribution = CRM_Contribute_Form_Contribution_Confirm::processContribution($this, $paymentParams, $result, $this->_contributorContactID, $contributionType, FALSE, TRUE, FALSE); $paymentParams['contributionID'] = $contribution->id; $paymentParams['contributionTypeID'] = $contribution->contribution_type_id; $paymentParams['contributionPageID'] = $contribution->contribution_page_id; $paymentParams['contributionRecurID'] = $contribution->contribution_recur_id; $ids['contribution'] = $contribution->id; $params['contribution_recur_id'] = $paymentParams['contributionRecurID']; $params['status_id'] = array_search('Pending', $allStatus); $params['skipStatusCal'] = TRUE; //as membership is pending set dates to null. $memberDates = array('join_date' => 'joinDate', 'start_date' => 'startDate', 'end_date' => 'endDate'); foreach ($memberDates as $dp => $dv) { ${$dv} = NULL; foreach ($this->_memTypeSelected as $memType) { $membershipTypeValues[$memType][$dv] = NULL; } } } if ($params['total_amount'] > 0.0) { $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this); $result =& $payment->doDirectPayment($paymentParams); } if (is_a($result, 'CRM_Core_Error')) { //make sure to cleanup db for recurring case. if (CRM_Utils_Array::value('contributionID', $paymentParams)) { CRM_Contribute_BAO_Contribution::deleteContribution($paymentParams['contributionID']); } if (CRM_Utils_Array::value('contributionRecurID', $paymentParams)) { CRM_Contribute_BAO_ContributionRecur::deleteRecurContribution($paymentParams['contributionRecurID']); } CRM_Core_Error::displaySessionError($result); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=add&cid={$this->_contactID}&context=&mode={$this->_mode}")); } if ($result) { $this->_params = array_merge($this->_params, $result); //assign amount to template if payment was successful $this->assign('amount', $params['total_amount']); } $params['contribution_status_id'] = CRM_Utils_Array::value('is_recur', $paymentParams) ? 2 : 1; $params['receive_date'] = $now; $params['invoice_id'] = $this->_params['invoiceID']; $params['contribution_source'] = ts('%1 Membership Signup: Credit card or direct debit (by %2)', array(1 => $membershipType, 2 => $userName)); $params['source'] = $formValues['source'] ? $formValues['source'] : $params['contribution_source']; $params['trxn_id'] = CRM_Utils_Array::value('trxn_id', $result); $params['payment_instrument_id'] = 1; $params['is_test'] = $this->_mode == 'live' ? 0 : 1; if (CRM_Utils_Array::value('send_receipt', $this->_params)) { $params['receipt_date'] = $now; } else { $params['receipt_date'] = NULL; } $this->set('params', $this->_params); $this->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $result)); $this->assign('receive_date', CRM_Utils_Date::mysqlToIso($params['receive_date'])); // required for creating membership for related contacts $params['action'] = $this->_action; //create membership record. $count = 0; foreach ($this->_memTypeSelected as $memType) { if ($count && ($relateContribution = CRM_Member_BAO_Membership::getMembershipContributionId($membership->id))) { $membershipTypeValues[$memType]['relate_contribution_id'] = $relateContribution; } $membershipParams = array_merge($membershipTypeValues[$memType], $params); $membership = CRM_Member_BAO_Membership::create($membershipParams, $ids); $this->_membershipIDs[] = $membership->id; $createdMemberships[$memType] = $membership; $count++; } if (!CRM_Utils_Array::value('is_recur', $params) && $params['total_amount'] > 0.0) { $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->trxn_id = CRM_Utils_Array::value('trxn_id', $result); if ($contribution->find(TRUE)) { // next create the transaction record $trxnParams = array('contribution_id' => $contribution->id, 'trxn_date' => $now, 'trxn_type' => 'Debit', 'total_amount' => $params['total_amount'], 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['total_amount']), 'currency' => $config->defaultCurrency, 'payment_processor' => $this->_paymentProcessor['payment_processor_type'], 'trxn_id' => CRM_Utils_Array::value('trxn_id', $result)); $trxn = CRM_Core_BAO_FinancialTrxn::create($trxnParams); } } } else { $params['action'] = $this->_action; if ($this->_onlinePendingContributionId && CRM_Utils_Array::value('record_contribution', $formValues)) { // update membership as well as contribution object, CRM-4395 $params['contribution_id'] = $this->_onlinePendingContributionId; $params['componentId'] = $params['id']; $params['componentName'] = 'contribute'; $result = CRM_Contribute_BAO_Contribution::transitionComponents($params, TRUE); if (!empty($result) && CRM_Utils_Array::value('contribution_id', $params)) { $lineItem = array(); $lineItems = CRM_Price_BAO_LineItem::getLineItems($params['contribution_id'], 'contribution'); $itemId = key($lineItems); $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $lineItems[$itemId]['price_field_id'], 'price_set_id'); $fieldType = NULL; if ($itemId && CRM_Utils_Array::value('price_field_id', $lineItems[$itemId])) { $fieldType = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $lineItems[$itemId]['price_field_id'], 'html_type'); } $lineItems[$itemId]['unit_price'] = $params['total_amount']; $lineItems[$itemId]['line_total'] = $params['total_amount']; $lineItems[$itemId]['id'] = $itemId; $lineItem[$priceSetId] = $lineItems; CRM_Contribute_Form_AdditionalInfo::processPriceSet($params['contribution_id'], $lineItem); } //carry updated membership object. $membership = new CRM_Member_DAO_Membership(); $membership->id = $this->_id; $membership->find(TRUE); $cancelled = TRUE; if ($membership->end_date) { //display end date w/ status message. $endDate = $membership->end_date; $membershipStatues = CRM_Member_PseudoConstant::membershipStatus(); if (!in_array($membership->status_id, array(array_search('Cancelled', $membershipStatues), array_search('Expired', $membershipStatues)))) { $cancelled = FALSE; } } // suppress form values in template. $this->assign('cancelled', $cancelled); // FIX ME: need to recheck this // here we might updated dates, so get from object. foreach ($calcDates[$membership->membership_type_id] as $date => &$val) { if ($membership->{$date}) { $val = $membership->{$date}; } } $createdMemberships[] = $membership; } else { $count = 0; foreach ($this->_memTypeSelected as $memType) { if ($count && CRM_Utils_Array::value('record_contribution', $formValues) && ($relateContribution = CRM_Member_BAO_Membership::getMembershipContributionId($membership->id))) { $membershipTypeValues[$memType]['relate_contribution_id'] = $relateContribution; } $membershipParams = array_merge($params, $membershipTypeValues[$memType]); $membership = CRM_Member_BAO_Membership::create($membershipParams, $ids); $this->_membershipIDs[] = $membership->id; $createdMemberships[$memType] = $membership; $count++; } } } if (!empty($lineItem)) { foreach ($lineItem[$priceSetId] as &$priceFieldOp) { if (CRM_Utils_Array::value('membership_type_id', $priceFieldOp)) { $priceFieldOp['start_date'] = $membershipTypeValues[$priceFieldOp['membership_type_id']]['start_date'] ? CRM_Utils_Date::customFormat($membershipTypeValues[$priceFieldOp['membership_type_id']]['start_date'], '%d%f %b, %Y') : '-'; $priceFieldOp['end_date'] = $membershipTypeValues[$priceFieldOp['membership_type_id']]['end_date'] ? CRM_Utils_Date::customFormat($membershipTypeValues[$priceFieldOp['membership_type_id']]['end_date'], '%d%f %b, %Y') : '-'; } else { $priceFieldOp['start_date'] = $priceFieldOp['end_date'] = 'N/A'; } } } $isQuickConfig = 0; if ($this->_priceSetId && CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId, 'is_quick_config')) { $isQuickConfig = 1; } $this->assign('lineItem', !empty($lineItem) && !$isQuickConfig ? $lineItem : FALSE); $receiptSend = FALSE; if (CRM_Utils_Array::value('send_receipt', $formValues)) { $receiptSend = TRUE; $formValues['contact_id'] = $this->_contactID; // send email receipt $mailSend = self::emailReceipt($this, $formValues, $membership); } if ($this->_action & CRM_Core_Action::UPDATE) { //end date can be modified by hooks, so if end date is set then use it. $endDate = $membership->end_date ? $membership->end_date : $endDate; $statusMsg = ts('Membership for %1 has been updated.', array(1 => $this->_memberDisplayName)); if ($endDate && $endDate !== 'null') { $endDate = CRM_Utils_Date::customFormat($endDate); $statusMsg .= ' ' . ts('The membership End Date is %1.', array(1 => $endDate)); } if ($receiptSend) { $statusMsg .= ' ' . ts('A confirmation and receipt has been sent to %1.', array(1 => $this->_contributorEmail)); } } elseif ($this->_action & CRM_Core_Action::ADD) { // FIX ME: fix status messages $statusMsg = array(); foreach ($membershipTypes as $memType => $membershipType) { $statusMsg[$memType] = ts('%1 membership for %2 has been added.', array(1 => $membershipType, 2 => $this->_memberDisplayName)); $membership = $createdMemberships[$memType]; $memEndDate = $membership->end_date ? $membership->end_date : $endDate; //get the end date from calculated dates. if (!$memEndDate && !CRM_Utils_Array::value('is_recur', $params)) { $memEndDate = CRM_Utils_Array::value('end_date', $calcDates[$memType]); } if ($memEndDate && $memEndDate !== 'null') { $memEndDate = CRM_Utils_Date::customFormat($memEndDate); $statusMsg[$memType] .= ' ' . ts('The new membership End Date is %1.', array(1 => $memEndDate)); } } $statusMsg = implode('<br/>', $statusMsg); if ($receiptSend && $mailSend) { $statusMsg .= '<br/>' . ts('A membership confirmation and receipt has been sent to %1.', array(1 => $this->_contributorEmail)); } } // finally set membership id if already not set if (!$this->_id) { $this->_id = $membership->id; } CRM_Core_Session::setStatus($statusMsg); $buttonName = $this->controller->getButtonName(); if ($this->_context == 'standalone') { if ($buttonName == $this->getButtonName('upload', 'new')) { $session->replaceUserContext(CRM_Utils_System::url('civicrm/member/add', 'reset=1&action=add&context=standalone')); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactID}&selectedChild=member")); } } elseif ($buttonName == $this->getButtonName('upload', 'new')) { $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=add&context=membership&cid={$this->_contactID}")); } }
/** * Function to build status message while * enabling/ disabling various objects */ static function getStatusMsg() { $recordID = CRM_Utils_Type::escape($_POST['recordID'], 'Integer'); $recordBAO = CRM_Utils_Type::escape($_POST['recordBAO'], 'String'); $op = CRM_Utils_Type::escape($_POST['op'], 'String'); $show = NULL; if ($op == 'disable-enable') { $status = ts('Are you sure you want to enable this record?'); } else { switch ($recordBAO) { case 'CRM_Core_BAO_UFGroup': require_once str_replace('_', DIRECTORY_SEPARATOR, $recordBAO) . '.php'; $method = 'getUFJoinRecord'; $result = array($recordBAO, $method); $ufJoin = call_user_func_array($result, array($recordID, TRUE)); if (!empty($ufJoin)) { $status = ts('This profile is currently used for %1.', array(1 => implode(', ', $ufJoin))) . ' <br/><br/>' . ts('If you disable the profile - it will be removed from these forms and/or modules. Do you want to continue?'); } else { $status = ts('Are you sure you want to disable this profile?'); } break; case 'CRM_Price_BAO_Set': require_once str_replace('_', DIRECTORY_SEPARATOR, $recordBAO) . '.php'; $usedBy = CRM_Price_BAO_Set::getUsedBy($recordID); $priceSet = CRM_Price_BAO_Set::getTitle($recordID); if (!CRM_Utils_System::isNull($usedBy)) { $template = CRM_Core_Smarty::singleton(); $template->assign('usedBy', $usedBy); $comps = array('Event' => 'civicrm_event', 'Contribution' => 'civicrm_contribution_page'); $contexts = array(); foreach ($comps as $name => $table) { if (array_key_exists($table, $usedBy)) { $contexts[] = $name; } } $template->assign('contexts', $contexts); $show = 'noButton'; $table = $template->fetch('CRM/Price/Page/table.tpl'); $status = ts('Unable to disable the \'%1\' price set - it is currently in use by one or more active events, contribution pages or contributions.', array(1 => $priceSet)) . "<br/> {$table}"; } else { $status = ts('Are you sure you want to disable \'%1\' Price Set?', array(1 => $priceSet)); } break; case 'CRM_Event_BAO_Event': $status = ts('Are you sure you want to disable this Event?'); break; case 'CRM_Core_BAO_UFField': $status = ts('Are you sure you want to disable this CiviCRM Profile field?'); break; case 'CRM_Contribute_BAO_ManagePremiums': $status = ts('Are you sure you want to disable this premium? This action will remove the premium from any contribution pages that currently offer it. However it will not delete the premium record - so you can re-enable it and add it back to your contribution page(s) at a later time.'); break; case 'CRM_Contact_BAO_RelationshipType': $status = ts('Are you sure you want to disable this relationship type?') . '<br/><br/>' . ts('Users will no longer be able to select this value when adding or editing relationships between contacts.'); break; case 'CRM_Contribute_BAO_ContributionType': $status = ts('Are you sure you want to disable this contribution type?'); break; case 'CRM_Core_BAO_PaymentProcessor': $status = ts('Are you sure you want to disable this payment processor?') . ' <br/><br/>' . ts('Users will no longer be able to select this value when adding or editing transaction pages.'); break; case 'CRM_Core_BAO_PaymentProcessorType': $status = ts('Are you sure you want to disable this payment processor type?'); break; case 'CRM_Core_BAO_LocationType': $status = ts('Are you sure you want to disable this location type?') . ' <br/><br/>' . ts('Users will no longer be able to select this value when adding or editing contact locations.'); break; case 'CRM_Event_BAO_ParticipantStatusType': $status = ts('Are you sure you want to disable this Participant Status?') . '<br/><br/> ' . ts('Users will no longer be able to select this value when adding or editing Participant Status.'); break; case 'CRM_Mailing_BAO_Component': $status = ts('Are you sure you want to disable this component?'); break; case 'CRM_Core_BAO_CustomField': $status = ts('Are you sure you want to disable this custom data field?'); break; case 'CRM_Core_BAO_CustomGroup': $status = ts('Are you sure you want to disable this custom data group? Any profile fields that are linked to custom fields of this group will be disabled.'); break; case 'CRM_Core_BAO_MessageTemplates': $status = ts('Are you sure you want to disable this message tempate?'); break; case 'CRM_ACL_BAO_ACL': $status = ts('Are you sure you want to disable this ACL?'); break; case 'CRM_ACL_BAO_EntityRole': $status = ts('Are you sure you want to disable this ACL Role Assignment?'); break; case 'CRM_Member_BAO_MembershipType': $status = ts('Are you sure you want to disable this membership type?'); break; case 'CRM_Member_BAO_MembershipStatus': $status = ts('Are you sure you want to disable this membership status rule?'); break; case 'CRM_Price_BAO_Field': $status = ts('Are you sure you want to disable this price field?'); break; case 'CRM_Contact_BAO_Group': $status = ts('Are you sure you want to disable this Group?'); break; case 'CRM_Core_BAO_OptionGroup': $status = ts('Are you sure you want to disable this Option?'); break; case 'CRM_Contact_BAO_ContactType': $status = ts('Are you sure you want to disable this Contact Type?'); break; case 'CRM_Core_BAO_OptionValue': require_once str_replace('_', DIRECTORY_SEPARATOR, $recordBAO) . '.php'; $label = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $recordID, 'label'); $status = ts('Are you sure you want to disable the \'%1\' option ?', array(1 => $label)); $status .= '<br /><br />' . ts('WARNING - Disabling an option which has been assigned to existing records will result in that option being cleared when the record is edited.'); break; case 'CRM_Contribute_BAO_ContributionRecur': $recurDetails = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($recordID); $status = ts('Are you sure you want to mark this recurring contribution as cancelled?'); $status .= '<br /><br /><strong>' . ts('WARNING - This action sets the CiviCRM recurring contribution status to Cancelled, but does NOT send a cancellation request to the payment processor. You will need to ensure that this recurring payment (subscription) is cancelled by the payment processor.') . '</strong>'; if ($recurDetails->membership_id) { $status .= '<br /><br /><strong>' . ts('This recurring contribution is linked to an auto-renew membership. If you cancel it, the associated membership will no longer renew automatically. However, the current membership status will not be affected.') . '</strong>'; } break; default: $status = ts('Are you sure you want to disable this record?'); break; } } $statusMessage['status'] = $status; $statusMessage['show'] = $show; echo json_encode($statusMessage); CRM_Utils_System::civiExit(); }
/** * 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); }
/** * Function to process the form * * @access public * * @return None */ public function postProcess() { // get the submitted form values. $params = $this->controller->exportValues($this->_name); //set as Primary participant $params['is_primary'] = 1; if ($this->_values['event']['is_pay_later'] && !array_key_exists('hidden_processor', $params)) { $params['is_pay_later'] = 1; } else { $params['is_pay_later'] = 0; } $this->set('is_pay_later', $params['is_pay_later']); // assign pay later stuff $this->_params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE); $this->assign('is_pay_later', $params['is_pay_later']); if ($params['is_pay_later']) { $this->assign('pay_later_text', $this->_values['event']['pay_later_text']); $this->assign('pay_later_receipt', $this->_values['event']['pay_later_receipt']); } if (!$this->_allowConfirmation) { // check if the participant is already registered if (!$this->_skipDupeRegistrationCheck) { $params['contact_id'] = self::checkRegistration($params, $this, FALSE, TRUE, TRUE); } } if (CRM_Utils_Array::value('image_URL', $params)) { CRM_Contact_BAO_Contact::processImageParams($params); } //carry campaign to partcipants. if (array_key_exists('participant_campaign_id', $params)) { $params['campaign_id'] = $params['participant_campaign_id']; } else { $params['campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']); } //hack to allow group to register w/ waiting $primaryParticipantCount = self::getParticipantCount($this, $params); $totalParticipants = $primaryParticipantCount; if (CRM_Utils_Array::value('additional_participants', $params)) { $totalParticipants += $params['additional_participants']; } if (!$this->_allowConfirmation && CRM_Utils_Array::value('bypass_payment', $params) && is_numeric($this->_availableRegistrations) && $totalParticipants > $this->_availableRegistrations) { $this->_allowWaitlist = TRUE; $this->set('allowWaitlist', TRUE); } //carry participant id if pre-registered. if ($this->_allowConfirmation && $this->_participantId) { $params['participant_id'] = $this->_participantId; } $params['defaultRole'] = 1; if (array_key_exists('participant_role', $params)) { $params['participant_role_id'] = $params['participant_role']; } if (array_key_exists('participant_role_id', $params)) { $params['defaultRole'] = 0; } if (!CRM_Utils_Array::value('participant_role_id', $params) && $this->_values['event']['default_role_id']) { $params['participant_role_id'] = $this->_values['event']['default_role_id']; } $config = CRM_Core_Config::singleton(); $params['currencyID'] = $config->defaultCurrency; if ($this->_values['event']['is_monetary']) { // we first reset the confirm page so it accepts new values $this->controller->resetPage('Confirm'); //added for discount $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event'); if (!empty($this->_values['discount'][$discountId])) { $params['discount_id'] = $discountId; $params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label']; $params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value']; } elseif (empty($params['priceSetId'])) { $params['amount_level'] = $this->_values['fee'][$params['amount']]['label']; $params['amount'] = $this->_values['fee'][$params['amount']]['value']; } else { $lineItem = array(); CRM_Price_BAO_Set::processAmount($this->_values['fee'], $params, $lineItem); $this->set('lineItem', array($lineItem)); $this->set('lineItemParticipantsCount', array($primaryParticipantCount)); } $this->set('amount', $params['amount']); $this->set('amount_level', $params['amount_level']); // generate and set an invoiceID for this transaction $invoiceID = md5(uniqid(rand(), TRUE)); $this->set('invoiceID', $invoiceID); if (is_array($this->_paymentProcessor)) { $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this); } // default mode is direct $this->set('contributeMode', 'direct'); if (isset($params["state_province_id-{$this->_bltID}"]) && $params["state_province_id-{$this->_bltID}"]) { $params["state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($params["state_province_id-{$this->_bltID}"]); } if (isset($params["country_id-{$this->_bltID}"]) && $params["country_id-{$this->_bltID}"]) { $params["country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($params["country_id-{$this->_bltID}"]); } if (isset($params['credit_card_exp_date'])) { $params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($params); $params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($params); } if ($this->_values['event']['is_monetary']) { $params['ip_address'] = CRM_Utils_System::ipAddress(); $params['currencyID'] = $config->defaultCurrency; $params['payment_action'] = 'Sale'; $params['invoiceID'] = $invoiceID; } $this->_params = array(); $this->_params[] = $params; $this->set('params', $this->_params); if ($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) { //get the button name $buttonName = $this->controller->getButtonName(); if (in_array($buttonName, array($this->_expressButtonName, $this->_expressButtonName . '_x', $this->_expressButtonName . '_y')) && !CRM_Utils_Array::value('is_pay_later', $params) && !$this->_allowWaitlist && !$this->_requireApproval) { $this->set('contributeMode', 'express'); // Send Event Name & Id in Params $params['eventName'] = $this->_values['event']['title']; $params['eventId'] = $this->_values['event']['id']; $params['cancelURL'] = CRM_Utils_System::url('civicrm/event/register', "_qf_Register_display=1&qfKey={$this->controller->_key}", TRUE, NULL, FALSE); if (CRM_Utils_Array::value('additional_participants', $params, FALSE)) { $urlArgs = "_qf_Participant_1_display=1&rfp=1&qfKey={$this->controller->_key}"; } else { $urlArgs = "_qf_Confirm_display=1&rfp=1&qfKey={$this->controller->_key}"; } $params['returnURL'] = CRM_Utils_System::url('civicrm/event/register', $urlArgs, TRUE, NULL, FALSE); $params['invoiceID'] = $invoiceID; //default action is Sale $params['payment_action'] = 'Sale'; $token = $payment->setExpressCheckout($params); if (is_a($token, 'CRM_Core_Error')) { CRM_Core_Error::displaySessionError($token); CRM_Utils_System::redirect($params['cancelURL']); } $this->set('token', $token); $paymentURL = $this->_paymentProcessor['url_site'] . "/cgi-bin/webscr?cmd=_express-checkout&token={$token}"; CRM_Utils_System::redirect($paymentURL); } } elseif ($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_NOTIFY) { $this->set('contributeMode', 'notify'); } } else { $session = CRM_Core_Session::singleton(); $params['description'] = ts('Online Event Registration') . ' ' . $this->_values['event']['title']; $this->_params = array(); $this->_params[] = $params; $this->set('params', $this->_params); if (!CRM_Utils_Array::value('additional_participants', $params)) { self::processRegistration($this->_params); } } // If registering > 1 participant, give status message if (CRM_Utils_Array::value('additional_participants', $params, FALSE)) { $statusMsg = ts('Registration information for participant 1 has been saved.'); CRM_Core_Session::setStatus($statusMsg); } }
/** * Run the page. * * This method is called after the page is created. It checks for the * type of action and executes that action. * * @param null * * @return void * @access public */ function run() { // get the field id $this->_fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, FALSE, 0); //get the price set id if (!$this->_sid) { $this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive', $this); } if ($this->_sid) { CRM_Price_BAO_Set::checkPermission($this->_sid); $this->_isSetReserved = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_sid, 'is_reserved'); $this->assign('isReserved', $this->_isSetReserved); } //as url contain $sid so append breadcrumb dynamically. $breadcrumb = array(array('title' => ts('Price Fields'), 'url' => CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&sid=' . $this->_sid))); CRM_Utils_System::appendBreadCrumb($breadcrumb); if ($this->_fid) { $fieldTitle = CRM_Price_BAO_Field::getTitle($this->_fid); $this->assign('fid', $this->_fid); $this->assign('fieldTitle', $fieldTitle); CRM_Utils_System::setTitle(ts('%1 - Price Options', array(1 => $fieldTitle))); $htmlType = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Field', $this->_fid, 'html_type'); $this->assign('addMoreFields', TRUE); //for text price field only single option present if ($htmlType == 'Text') { $this->assign('addMoreFields', FALSE); } } // get the requested action $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); // assign vars to templates $this->assign('action', $action); $oid = CRM_Utils_Request::retrieve('oid', 'Positive', $this, FALSE, 0); // what action to take ? if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::VIEW | CRM_Core_Action::DELETE) && !$this->_isSetReserved) { // no browse for edit/update/view $this->edit($action); } else { $this->browse(); } // Call the parents run method return parent::run(); }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { //get the button name. $button = substr($this->controller->getButtonName(), -4); //take the participant instance. $addParticipantNum = substr($this->_name, 12); if ($button == 'skip') { //hack for free/zero amount event. if ($this->_resetAllowWaitlist) { $this->_allowWaitlist = false; $this->set('allowWaitlist', false); if ($this->_requireApproval) { $status = ts("You have skipped last participant and which result into event having enough spaces, but your registration require approval, Once your registration has been reviewed, you will receive an email with a link to a web page where you can complete the registration process."); } else { $status = ts("You have skipped last participant and which result into event having enough spaces, hence your group become as register participants though you selected on wait list."); } CRM_Core_Session::setStatus($status); } $this->_params[$addParticipantNum] = 'skip'; if (isset($this->_lineItem)) { $this->_lineItem[$addParticipantNum] = 'skip'; } } else { $params = $this->controller->exportValues($this->_name); if ($this->_values['event']['is_monetary']) { //added for discount require_once 'CRM/Core/BAO/Discount.php'; $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event'); if (!empty($this->_values['discount'][$discountId])) { $params['discount_id'] = $discountId; $params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label']; $params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value']; } else { if (empty($params['priceSetId'])) { $params['amount_level'] = $this->_values['fee'][$params['amount']]['label']; $params['amount'] = $this->_values['fee'][$params['amount']]['value']; } else { $lineItem = array(); require_once 'CRM/Price/BAO/Set.php'; CRM_Price_BAO_Set::processAmount($this->_values['fee']['fields'], $params, $lineItem); //build the line item.. if (array_key_exists($addParticipantNum, $this->_lineItem)) { $this->_lineItem[$addParticipantNum] = $lineItem; } else { $this->_lineItem[] = $lineItem; } } } } if (!CRM_Utils_Array::value('participant_role_id', $params) && $this->_values['event']['default_role_id']) { $params['participant_role_id'] = $this->_values['event']['default_role_id']; } if (CRM_Utils_Array::value('is_pay_later', $this->_params[0])) { $params['is_pay_later'] = 1; } //carry additional participant id, contact id if pre-registered. if ($this->_allowConfirmation && $this->_additionalParticipantId) { $params['contact_id'] = $this->_contactID; $params['participant_id'] = $this->_additionalParticipantId; } //build the params array. if (array_key_exists($addParticipantNum, $this->_params)) { $this->_params[$addParticipantNum] = $params; } else { $this->_params[] = $params; } } //finally set the params. $this->set('params', $this->_params); //set the line item. if ($this->_lineItem) { $this->set('lineItem', $this->_lineItem); } $participantNo = count($this->_params); if ($button != 'skip') { require_once "CRM/Core/Session.php"; $statusMsg = ts('Registration information for participant %1 has been saved.', array(1 => $participantNo)); CRM_Core_Session::setStatus("{$statusMsg}"); } //to check whether call processRegistration() if (!$this->_values['event']['is_monetary'] && CRM_Utils_Array::value('additional_participants', $this->_params[0]) && $this->isLastParticipant()) { require_once 'CRM/Event/Form/Registration/Register.php'; CRM_Event_Form_Registration_Register::processRegistration($this->_params, null); } }
/** * process membership records * * @param array $params associated array of submitted values * * @access public * * @return None */ private function processMembership(&$params) { $dateTypes = array('join_date' => 'joinDate', 'membership_start_date' => 'startDate', 'membership_end_date' => 'endDate'); $dates = array('join_date', 'start_date', 'end_date', 'reminder_date'); // get the price set associated with offline memebership $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', 'default_membership_type_amount', 'id', 'name'); $this->_priceSet = $priceSets = current(CRM_Price_BAO_Set::getSetDetail($priceSetId)); if (isset($params['field'])) { $customFields = array(); foreach ($params['field'] as $key => $value) { // if contact is not selected we should skip the row if (!CRM_Utils_Array::value($key, $params['primary_contact_select_id'])) { continue; } $value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_select_id']); // update contact information $this->updateContactInfo($value); $membershipTypeId = $value['membership_type_id'] = $value['membership_type'][1]; foreach ($dateTypes as $dateField => $dateVariable) { ${$dateVariable} = CRM_Utils_Date::processDate($value[$dateField]); } $calcDates = array(); $calcDates[$membershipTypeId] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipTypeId, $joinDate, $startDate, $endDate); foreach ($calcDates as $memType => $calcDate) { foreach ($dates as $d) { //first give priority to form values then calDates. $date = CRM_Utils_Array::value($d, $value); if (!$date) { $date = CRM_Utils_Array::value($d, $calcDate); } $value[$d] = CRM_Utils_Date::processDate($date); } } if (CRM_Utils_Array::value('send_receipt', $value)) { $value['receipt_date'] = date('Y-m-d His'); } if (CRM_Utils_Array::value('membership_source', $value)) { $value['source'] = $value['membership_source']; } unset($value['membership_source']); //Get the membership status if (CRM_Utils_Array::value('membership_status', $value)) { $value['status_id'] = $value['membership_status']; unset($value['membership_status']); } if (empty($customFields)) { // membership type custom data $customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $membershipTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, NULL, NULL, TRUE)); } //check for custom data $value['custom'] = CRM_Core_BAO_CustomField::postProcess($params['field'][$key], $customFields, $key, 'Membership', $membershipTypeId); if (CRM_Utils_Array::value('contribution_type', $value)) { $value['contribution_type_id'] = $value['contribution_type']; } if (CRM_Utils_Array::value('payment_instrument', $value)) { $value['payment_instrument_id'] = $value['payment_instrument']; } // handle soft credit if (CRM_Utils_Array::value('soft_credit_contact_select_id', $params) && CRM_Utils_Array::value($key, $params['soft_credit_contact_select_id'])) { $value['soft_credit_to'] = $params['soft_credit_contact_select_id'][$key]; } if (CRM_Utils_Array::value('receive_date', $value)) { $value['receive_date'] = CRM_Utils_Date::processDate($value['receive_date'], $value['receive_date_time'], TRUE); } $params['actualBatchTotal'] += $value['total_amount']; unset($value['contribution_type']); unset($value['payment_instrument']); $value['batch_id'] = $this->_batchId; $value['skipRecentView'] = TRUE; // make entry in line item for contribution $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => $value['membership_type'][0]); $editedResults = array(); CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults); if (!empty($editedResults)) { unset($this->_priceSet['fields']); $this->_priceSet['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']]; unset($this->_priceSet['fields'][$editedResults['id']]['options']); $fid = $editedResults['id']; $editedFieldParams = array('price_field_id' => $editedResults['id'], 'membership_type_id' => $value['membership_type_id']); $editedResults = array(); CRM_Price_BAO_FieldValue::retrieve($editedFieldParams, $editedResults); $this->_priceSet['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']]; if (CRM_Utils_Array::value('total_amount', $value)) { $this->_priceSet['fields'][$fid]['options'][$editedResults['id']]['amount'] = $value['total_amount']; } $fieldID = key($this->_priceSet['fields']); $value['price_' . $fieldID] = $editedResults['id']; $lineItem = array(); CRM_Price_BAO_Set::processAmount($this->_priceSet['fields'], $value, $lineItem[$priceSetId]); $value['lineItems'] = $lineItem; $value['processPriceSet'] = TRUE; } // end of contribution related section unset($value['membership_type']); unset($value['membership_start_date']); unset($value['membership_end_date']); $value['is_renew'] = false; if (CRM_Utils_Array::value('member_option', $params) && CRM_Utils_Array::value($key, $params['member_option']) == 2) { $this->_params = $params; $value['is_renew'] = true; $membership = CRM_Member_BAO_Membership::renewMembership($value['contact_id'], $value['membership_type_id'], FALSE, $this, NULL, NULL, $value['custom']); // make contribution entry CRM_Member_BAO_Membership::recordMembershipContribution($value, CRM_Core_DAO::$_nullArray, $membership->id); } else { $membership = CRM_Member_BAO_Membership::create($value, CRM_Core_DAO::$_nullArray); } //process premiums if (CRM_Utils_Array::value('product_name', $value)) { if ($value['product_name'][0] > 0) { list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo(); $value['hidden_Premium'] = 1; $value['product_option'] = CRM_Utils_Array::value($value['product_name'][1], $options[$value['product_name'][0]]); $premiumParams = array('product_id' => $value['product_name'][0], 'contribution_id' => $value['contribution_id'], 'product_option' => $value['product_option'], 'quantity' => 1); CRM_Contribute_BAO_Contribution::addPremium($premiumParams); } } // end of premium //send receipt mail. if ($membership->id && CRM_Utils_Array::value('send_receipt', $value)) { // add the domain email id $domainEmail = CRM_Core_BAO_Domain::getNameAndEmail(); $domainEmail = "{$domainEmail['0']} <{$domainEmail['1']}>"; $value['from_email_address'] = $domainEmail; $value['membership_id'] = $membership->id; CRM_Member_Form_Membership::emailReceipt($this, $value, $membership); } } } }
/** * Process the form * * @param null * * @return void * @access public */ public function postProcess() { // get the submitted form values. $params = $this->controller->exportValues('Set'); $nameLength = CRM_Core_DAO::getAttribute('CRM_Price_DAO_Set', 'name'); $params['name'] = CRM_Utils_String::titleToVar($params['title'], CRM_Utils_Array::value('maxlength', $nameLength)); $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false); $compIds = array(); $extends = CRM_Utils_Array::value('extends', $params); if (is_array($extends)) { foreach ($extends as $compId => $selected) { if ($selected) { $compIds[] = $compId; } } } $params['extends'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $compIds); if ($this->_action & CRM_Core_Action::UPDATE) { $params['id'] = $this->_sid; } $set = CRM_Price_BAO_Set::create($params); if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Core_Session::setStatus(ts('The Set \'%1\' has been saved.', array(1 => $set->title))); } else { $url = CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=add&sid=' . $set->id); CRM_Core_Session::setStatus(ts('Your Set \'%1\' has been added. You can add fields to this set now.', array(1 => $set->title))); $session = CRM_Core_Session::singleton(); $session->replaceUserContext($url); } }
/** * This function is to make a copy of a price set, including * all the fields in the page * * @return void * @access public */ function copy() { $id = CRM_Utils_Request::retrieve('sid', 'Positive', $this, true, 0, 'GET'); require_once 'CRM/Price/BAO/Set.php'; CRM_Price_BAO_Set::copy($id); CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1')); }
/** * 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]; }
/** * Process the form when submitted * * @return void * @access public */ public function postProcess() { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); // first delete the join entries associated with this contribution page require_once 'CRM/Core/DAO/UFJoin.php'; $dao = new CRM_Core_DAO_UFJoin(); $params = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id); $dao->copyValues($params); $dao->delete(); require_once 'CRM/Core/OptionGroup.php'; $groupName = "civicrm_contribution_page.amount.{$this->_id}"; CRM_Core_OptionGroup::deleteAssoc($groupName); //next delete the membership block fields require_once 'CRM/Member/DAO/MembershipBlock.php'; $dao = new CRM_Member_DAO_MembershipBlock(); $dao->entity_table = 'civicrm_contribution_page'; $dao->entity_id = $this->_id; $dao->delete(); //next delete the pcp block fields require_once 'CRM/Contribute/DAO/PCPBlock.php'; $dao = new CRM_Contribute_DAO_PCPBlock(); $dao->entity_table = 'civicrm_contribution_page'; $dao->entity_id = $this->_id; $dao->delete(); // need to delete premiums. CRM-4586 require_once 'CRM/Contribute/BAO/Premium.php'; CRM_Contribute_BAO_Premium::deletePremium($this->_id); // price set cleanup, CRM-5527 require_once 'CRM/Price/BAO/Set.php'; CRM_Price_BAO_Set::removeFrom('civicrm_contribution_page', $this->_id); // finally delete the contribution page require_once 'CRM/Contribute/DAO/ContributionPage.php'; $dao = new CRM_Contribute_DAO_ContributionPage(); $dao->id = $this->_id; $dao->delete(); $transaction->commit(); CRM_Core_Session::setStatus(ts('The contribution page \'%1\' has been deleted.', array(1 => $this->_title))); }
/** * 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; }
/** * Process the form * * @return void * @access public */ public function postProcess() { // get the submitted form values. $params = $this->controller->exportValues($this->_name); if (CRM_Utils_Array::value('payment_processor_id', $params) == CRM_Core_DAO::getFieldValue('CRM_Core_DAO_PaymentProcessor', 'AuthNet', 'id', 'payment_processor_type')) { 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']) { require_once 'CRM/Core/BAO/CustomOption.php'; $params['recur_frequency_unit'] = implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, array_keys($params['recur_frequency_unit'])); $params['is_recur_interval'] = CRM_Utils_Array::value('is_recur_interval', $params, false); } require_once 'CRM/Contribute/BAO/ContributionPage.php'; $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) { require_once 'CRM/Price/BAO/Set.php'; require_once 'CRM/Core/OptionGroup.php'; require_once 'CRM/Pledge/BAO/PledgeBlock.php'; if (CRM_Utils_Array::value('amount_block_is_active', $params)) { // handle price set. if ($priceSetID) { // add/update price set. $deletePriceSet = false; CRM_Price_BAO_Set::addTo('civicrm_contribution_page', $contributionPageID, $priceSetID); } else { // 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_Core_OptionGroup::createAssoc("civicrm_contribution_page.amount.{$contributionPageID}", $options, $params['default_amount_id']); if ($params['default_amount_id']) { CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageID, 'default_amount_id', $params['default_amount_id']); } 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. require_once 'CRM/Pledge/BAO/PledgeBlock.php'; CRM_Pledge_BAO_PledgeBlock::create($pledgeBlockParams); } } } // 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); } // delete amount block. if ($deleteAmountBlk) { CRM_Core_OptionGroup::deleteAssoc("civicrm_contribution_page.amount.{$contributionPageID}"); } } }
/** * Returns array of price_sets matching a set of one or more group properties * * @param array $params Array of one or more valid property_name=>value pairs. If $params is set * as null, all price_sets will be returned (default limit is 25) * * @return array Array of matching price_sets * {@getfields price_set_get} * @access public */ function civicrm_api3_price_set_get($params) { $result = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE); // Fetch associated entities foreach ($result as &$item) { $item['entity'] = CRM_Price_BAO_Set::getUsedBy($item['id'], 'entity'); } return civicrm_api3_create_success($result, $params); }