Esempio n. 1
0
 /**
  * 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}");
         }
     }
 }
Esempio n. 2
0
 /**
  * Process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $params = array();
     $params = $this->exportValues();
     $this->set('discountSection', 0);
     if (CRM_Utils_Array::value('_qf_Fee_submit', $_POST)) {
         $this->buildAmountLabel();
         $this->set('discountSection', 1);
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/manage', '#isDiscount'));
         return;
     }
     $params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0);
     if ($this->_id) {
         require_once 'CRM/Price/BAO/Set.php';
         // delete all the prior label values or discounts in the custom options table
         // and delete a price set if one exists
         if (!CRM_Price_BAO_Set::removeFrom('civicrm_event', $this->_id)) {
             require_once 'CRM/Core/OptionGroup.php';
             CRM_Core_OptionGroup::deleteAssoc("civicrm_event.amount.{$this->_id}");
             CRM_Core_OptionGroup::deleteAssoc("civicrm_event.amount.{$this->_id}.discount.%", "LIKE");
         }
     }
     if ($params['is_monetary']) {
         if ($params['price_set_id']) {
             CRM_Price_BAO_Set::addTo('civicrm_event', $this->_id, $params['price_set_id']);
         } else {
             // if there are label / values, create custom options for them
             $labels = CRM_Utils_Array::value('label', $params);
             $values = CRM_Utils_Array::value('value', $params);
             $default = CRM_Utils_Array::value('default', $params);
             $options = array();
             if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
                 for ($i = 1; $i < self::NUM_OPTION; $i++) {
                     if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) {
                         $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                     }
                 }
                 if (!empty($options)) {
                     $params['default_fee_id'] = null;
                     CRM_Core_OptionGroup::createAssoc("civicrm_event.amount.{$this->_id}", $options, $params['default_fee_id']);
                 }
             }
             if (CRM_Utils_Array::value('is_discount', $params) == 1) {
                 // if there are discounted set of label / values,
                 // create custom options for them
                 $labels = CRM_Utils_Array::value('discounted_label', $params);
                 $values = CRM_Utils_Array::value('discounted_value', $params);
                 $default = CRM_Utils_Array::value('discounted_default', $params);
                 if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
                     for ($j = 1; $j <= self::NUM_DISCOUNT; $j++) {
                         $discountOptions = array();
                         for ($i = 1; $i < self::NUM_OPTION; $i++) {
                             if (!empty($labels[$i]) && CRM_Utils_Array::value($j, $values[$i])) {
                                 $discountOptions[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i][$j])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
                             }
                         }
                         if (!empty($discountOptions)) {
                             $params['default_discount_fee_id'] = null;
                             $discountOptionsGroupId = CRM_Core_OptionGroup::createAssoc("civicrm_event.amount.{$this->_id}.discount.{$params['discount_name'][$j]}", $discountOptions, $params['default_discount_fee_id'], $params['discount_name'][$j]);
                             $discountParams = array('entity_table' => 'civicrm_event', 'entity_id' => $this->_id, 'option_group_id' => $discountOptionsGroupId, 'start_date' => CRM_Utils_Date::format($params["discount_start_date"][$j]), 'end_date' => CRM_Utils_Date::format($params["discount_end_date"][$j]));
                             require_once 'CRM/Core/BAO/Discount.php';
                             CRM_Core_BAO_Discount::add($discountParams);
                         }
                     }
                 }
             }
         }
     } else {
         $params['contribution_type_id'] = '';
     }
     //update events table
     require_once 'CRM/Event/BAO/Event.php';
     $params['id'] = $this->_id;
     CRM_Event_BAO_Event::add($params);
     parent::endPostProcess();
 }
Esempio n. 3
0
 public function postProcess()
 {
     $values = $this->exportValues();
     //cache contact fields retaining localized titles
     //though we changed localization, so reseting cache.
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     //CRM-8559, cache navigation do not respect locale if it is changed, so reseting cache.
     CRM_Core_BAO_Cache::deleteGroup('navigation');
     // we do this only to initialize monetary decimal point and thousand separator
     $config = CRM_Core_Config::singleton();
     // save enabled currencies and defaul currency in option group 'currencies_enabled'
     // CRM-1496
     if (empty($values['currencyLimit'])) {
         $values['currencyLimit'] = array($values['defaultCurrency']);
     } elseif (!in_array($values['defaultCurrency'], $values['currencyLimit'])) {
         $values['currencyLimit'][] = $values['defaultCurrency'];
     }
     // sort so that when we display drop down, weights have right value
     sort($values['currencyLimit']);
     // get labels for all the currencies
     $options = array();
     $currencySymbols = self::getCurrencySymbols();
     for ($i = 0; $i < count($values['currencyLimit']); $i++) {
         $options[] = array('label' => $currencySymbols[$values['currencyLimit'][$i]], 'value' => $values['currencyLimit'][$i], 'weight' => $i + 1, 'is_active' => 1, 'is_default' => $values['currencyLimit'][$i] == $values['defaultCurrency']);
     }
     $dontCare = NULL;
     CRM_Core_OptionGroup::createAssoc('currencies_enabled', $options, $dontCare);
     // unset currencyLimit so we dont store there
     unset($values['currencyLimit']);
     // make the site multi-lang if requested
     if (!empty($values['makeMultilingual'])) {
         CRM_Core_I18n_Schema::makeMultilingual($values['lcMessages']);
         $values['languageLimit'][$values['lcMessages']] = 1;
         // make the site single-lang if requested
     } elseif (!empty($values['makeSinglelingual'])) {
         CRM_Core_I18n_Schema::makeSinglelingual($values['lcMessages']);
         $values['languageLimit'] = '';
     }
     // add a new db locale if the requested language is not yet supported by the db
     if (!CRM_Utils_Array::value('makeSinglelingual', $values) and CRM_Utils_Array::value('addLanguage', $values)) {
         $domain = new CRM_Core_DAO_Domain();
         $domain->find(TRUE);
         if (!substr_count($domain->locales, $values['addLanguage'])) {
             CRM_Core_I18n_Schema::addLocale($values['addLanguage'], $values['lcMessages']);
         }
         $values['languageLimit'][$values['addLanguage']] = 1;
     }
     // if we manipulated the language list, return to the localization admin screen
     $return = (bool) (CRM_Utils_Array::value('makeMultilingual', $values) or CRM_Utils_Array::value('addLanguage', $values));
     $filteredValues = $values;
     unset($filteredValues['makeMultilingual']);
     unset($filteredValues['makeSinglelingual']);
     unset($filteredValues['addLanguage']);
     unset($filteredValues['languageLimit']);
     Civi::settings()->set('languageLimit', CRM_Utils_Array::value('languageLimit', $values));
     // save all the settings
     parent::commonProcess($filteredValues);
     if ($return) {
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/setting/localization', 'reset=1'));
     }
 }
Esempio n. 4
0
 /**
  * takes an associative array and creates a price field object
  *
  * This function is invoked from within the web form layer and also from the api layer
  *
  * @param array $params (reference) an assoc array of name/value pairs
  *
  * @return object CRM_Price_DAO_Field object
  * @access public
  * @static
  */
 static function create(&$params, $ids)
 {
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $priceField =& self::add($params, $ids);
     if (is_a($priceField, 'CRM_Core_Error')) {
         $transaction->rollback();
         return $priceField;
     }
     $options = array();
     require_once 'CRM/Price/Form/Field.php';
     $maxIndex = CRM_Price_Form_Field::NUM_OPTION;
     if ($priceField->html_type == 'Text') {
         $maxIndex = 1;
     }
     $defaultArray = array();
     if ($params['html_type'] == 'CheckBox' && isset($params['default_checkbox_option'])) {
         $tempArray = array_keys($params['default_checkbox_option']);
         foreach ($tempArray as $v) {
             if ($params['option_value'][$v]) {
                 $defaultArray[$v] = 1;
             }
         }
     } else {
         if (CRM_Utils_Array::value('default_option', $params) && isset($params['option_value'][$params['default_option']])) {
             $defaultArray[$params['default_option']] = 1;
         }
     }
     for ($index = 1; $index <= $maxIndex; $index++) {
         if ($maxIndex == 1) {
             $description = $params['label'];
         } else {
             $description = $params['label'] . " - " . trim($params['option_label'][$index]);
         }
         if (CRM_Utils_Array::value($index, $params['option_label']) && !CRM_Utils_System::isNull($params['option_value'][$index])) {
             $options[] = array('label' => trim($params['option_label'][$index]), 'name' => CRM_Utils_Rule::cleanMoney(trim($params['option_name'][$index])), 'value' => CRM_Utils_Rule::cleanMoney(trim($params['option_value'][$index])), 'description' => $description, 'weight' => $params['option_weight'][$index], 'is_active' => 1, 'is_default' => CRM_Utils_Array::value($index, $defaultArray));
         }
     }
     if (!empty($options)) {
         $params['default_amount_id'] = null;
         $groupName = "civicrm_price_field.amount.{$priceField->id}";
         require_once 'CRM/Core/OptionGroup.php';
         CRM_Core_OptionGroup::createAssoc($groupName, $options, $params['default_amount_id']);
     }
     $transaction->commit();
     return $priceField;
 }