3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * form to process actions on the group aspect of Custom Data
39 class CRM_Contribute_Form_ContributionPage_Amount
extends CRM_Contribute_Form_ContributionPage
{
42 * Contribution amount block.
47 protected $_amountBlock = array();
50 * Constants for number of options for data types of multiple option.
52 CONST NUM_OPTION
= 11;
55 * Build the form object
60 public function buildQuickForm() {
62 // do u want to allow a free form text field for amount
63 $this->addElement('checkbox', 'is_allow_other_amount', ts('Allow other amounts'), NULL, array('onclick' => "minMax(this);showHideAmountBlock( this, 'is_allow_other_amount' );"));
64 $this->add('text', 'min_amount', ts('Minimum Amount'), array('size' => 8, 'maxlength' => 8));
65 $this->addRule('min_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money
::format('9.99', ' '))), 'money');
67 $this->add('text', 'max_amount', ts('Maximum Amount'), array('size' => 8, 'maxlength' => 8));
68 $this->addRule('max_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money
::format('99.99', ' '))), 'money');
71 $this->add('text', 'amount_label', ts('Contribution Amounts Label'));
73 $default = array($this->createElement('radio', NULL, NULL, NULL, 0));
74 $this->add('hidden', "price_field_id", '', array('id' => "price_field_id"));
75 $this->add('hidden', "price_field_other", '', array('id' => "price_field_option"));
76 for ($i = 1; $i <= self
::NUM_OPTION
; $i++
) {
78 $this->add('text', "label[$i]", ts('Label'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_OptionValue', 'label'));
80 $this->add('hidden', "price_field_value[$i]", '', array('id' => "price_field_value[$i]"));
83 $this->add('text', "value[$i]", ts('Value'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_OptionValue', 'value'));
84 $this->addRule("value[$i]", ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money
::format('99.99', ' '))), 'money');
87 $default[] = $this->createElement('radio', NULL, NULL, NULL, $i);
90 $this->addGroup($default, 'default');
92 $this->addElement('checkbox', 'amount_block_is_active', ts('Contribution Amounts section enabled'), NULL, array('onclick' => "showHideAmountBlock( this, 'amount_block_is_active' );"));
94 $this->addElement('checkbox', 'is_monetary', ts('Execute real-time monetary transactions'));
96 $paymentProcessor = CRM_Core_PseudoConstant
::paymentProcessor();
97 $recurringPaymentProcessor = array();
99 if (!empty($paymentProcessor)) {
100 $paymentProcessorIds = implode(',', array_keys($paymentProcessor));
103 FROM civicrm_payment_processor
104 WHERE id IN ({$paymentProcessorIds})
106 $dao = CRM_Core_DAO
::executeQuery($query);
107 while ($dao->fetch()) {
108 $recurringPaymentProcessor[] = $dao->id
;
111 $this->assign('recurringPaymentProcessor', $recurringPaymentProcessor);
112 if (count($paymentProcessor)) {
113 $this->assign('paymentProcessor', $paymentProcessor);
116 $this->addCheckBox('payment_processor', ts('Payment Processor'),
117 array_flip($paymentProcessor),
118 NULL, NULL, NULL, NULL,
119 array(' ', ' ', ' ', '<br/>')
123 //check if selected payment processor supports recurring payment
124 if (!empty($recurringPaymentProcessor)) {
125 $this->addElement('checkbox', 'is_recur', ts('Recurring Contributions'), NULL,
126 array('onclick' => "showHideByValue('is_recur',true,'recurFields','table-row','radio',false);")
128 $this->addCheckBox('recur_frequency_unit', ts('Supported recurring units'),
129 CRM_Core_OptionGroup
::values('recur_frequency_units', FALSE, FALSE, FALSE, NULL, 'name'),
130 NULL, NULL, NULL, NULL,
131 array(' ', ' ', ' ', '<br/>')
133 $this->addElement('checkbox', 'is_recur_interval', ts('Support recurring intervals'));
134 $this->addElement('checkbox', 'is_recur_installments', ts('Offer installments'));
137 // add pay later options
138 $this->addElement('checkbox', 'is_pay_later', ts('Pay later option'), NULL);
139 $this->addElement('textarea', 'pay_later_text', ts('Pay later label'),
140 CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_ContributionPage', 'pay_later_text'),
143 $this->addWysiwyg('pay_later_receipt', ts('Pay Later Instructions'), CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_ContributionPage', 'pay_later_receipt'));
144 $this->addElement('checkbox', 'is_billing_required', ts('Billing address required'));
146 //add partial payment options
148 // add price set fields
149 $price = CRM_Price_BAO_PriceSet
::getAssoc(FALSE, 'CiviContribute');
150 if (CRM_Utils_System
::isNull($price)) {
151 $this->assign('price', FALSE);
154 $this->assign('price', TRUE);
156 $this->add('select', 'price_set_id', ts('Price Set'),
158 '' => ts('- none -')) +
$price,
159 NULL, array('onchange' => "showHideAmountBlock( this.value, 'price_set_id' );")
162 $config = CRM_Core_Config
::singleton();
163 if (in_array('CiviPledge', $config->enableComponents
)) {
164 $this->assign('civiPledge', TRUE);
165 $this->addElement('checkbox', 'is_pledge_active', ts('Pledges'),
166 NULL, array('onclick' => "showHideAmountBlock( this, 'is_pledge_active' ); return showHideByValue('is_pledge_active',true,'pledgeFields','table-row','radio',false);")
168 $this->addCheckBox('pledge_frequency_unit', ts('Supported pledge frequencies'),
169 CRM_Core_OptionGroup
::values('recur_frequency_units', FALSE, FALSE, FALSE, NULL, 'name'),
170 NULL, NULL, NULL, NULL,
171 array(' ', ' ', ' ', '<br/>')
173 $this->addElement('checkbox', 'is_pledge_interval', ts('Allow frequency intervals'));
174 $this->addElement('text', 'initial_reminder_day', ts('Send payment reminder'), array('size' => 3));
175 $this->addElement('text', 'max_reminders', ts('Send up to'), array('size' => 3));
176 $this->addElement('text', 'additional_reminder_day', ts('Send additional reminders'), array('size' => 3));
179 //add currency element.
180 $this->addCurrency('currency', ts('Currency'));
182 $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Amount', 'formRule'), $this);
184 parent
::buildQuickForm();
188 * Set default values for the form. Note that in edit/view mode
189 * the default values are retrieved from the database
195 function setDefaultValues() {
196 $defaults = parent
::setDefaultValues();
197 $title = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id
, 'title');
198 CRM_Utils_System
::setTitle(ts('Contribution Amounts') . " ($title)");
200 if (empty($defaults['pay_later_text'])) {
201 $defaults['pay_later_text'] = ts('I will send payment by check');
204 if (!empty($defaults['amount_block_is_active'])) {
206 if ($priceSetId = CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $this->_id
, NULL)) {
207 if ($isQuick = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config')) {
208 $this->assign('isQuick', $isQuick);
209 //$priceField = CRM_Core_DAO::getFieldValue( 'CRM_Price_DAO_PriceField', $priceSetId, 'id', 'price_set_id' );
210 $options = $pFIDs = array();
211 $priceFieldParams = array('price_set_id' => $priceSetId);
212 $priceFields = CRM_Core_DAO
::commonRetrieveAll('CRM_Price_DAO_PriceField', 'price_set_id', $priceSetId, $pFIDs, $return = array('html_type', 'name', 'is_active', 'label'));
213 foreach ($priceFields as $priceField) {
214 if ($priceField['id'] && $priceField['html_type'] == 'Radio' && $priceField['name'] == 'contribution_amount') {
215 $defaults['price_field_id'] = $priceField['id'];
216 $priceFieldOptions = CRM_Price_BAO_PriceFieldValue
::getValues($priceField['id'], $options, 'id', 1);
217 if (empty($priceFieldOptions)) {
221 $defaults['amount_label'] = $priceField['label'];
222 foreach ($options as $optionId => $optionValue) {
224 $defaults['value'][$countRow] = $optionValue['amount'];
225 $defaults['label'][$countRow] = CRM_Utils_Array
::value('label', $optionValue);
226 $defaults['name'][$countRow] = CRM_Utils_Array
::value('name', $optionValue);
227 $defaults['weight'][$countRow] = $optionValue['weight'];
229 $defaults["price_field_value"][$countRow] = $optionValue['id'];
230 if ($optionValue['is_default']) {
231 $defaults['default'] = $countRow;
235 elseif ($priceField['id'] && $priceField['html_type'] == 'Text' && $priceField['name'] = 'other_amount' && $priceField['is_active']) {
236 $defaults['price_field_other'] = $priceField['id'];
237 if (!isset($defaults['amount_label'])) {
238 $defaults['amount_label'] = $priceField['label'];
245 if (empty($defaults['amount_label'])) {
246 $defaults['amount_label'] = ts('Contribution Amount');
249 if (!empty($defaults['value']) && is_array($defaults['value'])) {
251 // CRM-4038: fix value display
252 foreach ($defaults['value'] as & $amount) {
253 $amount = trim(CRM_Utils_Money
::format($amount, ' '));
258 // fix the display of the monetary value, CRM-4038
259 if (isset($defaults['min_amount'])) {
260 $defaults['min_amount'] = CRM_Utils_Money
::format($defaults['min_amount'], NULL, '%a');
262 if (isset($defaults['max_amount'])) {
263 $defaults['max_amount'] = CRM_Utils_Money
::format($defaults['max_amount'], NULL, '%a');
266 if (!empty($defaults['payment_processor'])) {
267 $defaults['payment_processor'] = array_fill_keys(explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
268 $defaults['payment_processor']
277 * @param array $fields the input form values
278 * @param array $files the uploaded files if any
282 * @return true if no errors, else array of errors
286 static function formRule($fields, $files, $self) {
288 //as for separate membership payment we has to have
289 //contribution amount section enabled, hence to disable it need to
290 //check if separate membership payment enabled,
291 //if so disable first separate membership payment option
292 //then disable contribution amount section. CRM-3801,
294 $membershipBlock = new CRM_Member_DAO_MembershipBlock();
295 $membershipBlock->entity_table
= 'civicrm_contribution_page';
296 $membershipBlock->entity_id
= $self->_id
;
297 $membershipBlock->is_active
= 1;
298 $hasMembershipBlk = FALSE;
299 if ($membershipBlock->find(TRUE)) {
300 if (!empty($fields['amount_block_is_active']) &&
301 ($setID = CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $self->_id
, NULL, 1))
303 $extends = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'extends');
304 if ($extends && $extends == CRM_Core_Component
::getComponentID('CiviMember')) {
305 $errors['amount_block_is_active'] = ts('You cannot use a Membership Price Set when the Contribution Amounts section is enabled. Click the Memberships tab above, and select your Membership Price Set on that form. Membership Price Sets may include additional fields for non-membership options that require an additional fee (e.g. magazine subscription) or an additional voluntary contribution.');
309 $hasMembershipBlk = TRUE;
310 if ($membershipBlock->is_separate_payment
&& empty($fields['amount_block_is_active'])) {
311 $errors['amount_block_is_active'] = ts('To disable Contribution Amounts section you need to first disable Separate Membership Payment option from Membership Settings.');
315 //check for the amount label (mandatory)
316 if (!empty($fields['amount_block_is_active']) && empty($fields['amount_label'])) {
317 $errors['amount_label'] = ts('Please enter the contribution amount label.');
319 $minAmount = CRM_Utils_Array
::value('min_amount', $fields);
320 $maxAmount = CRM_Utils_Array
::value('max_amount', $fields);
321 if (!empty($minAmount) && !empty($maxAmount)) {
322 $minAmount = CRM_Utils_Rule
::cleanMoney($minAmount);
323 $maxAmount = CRM_Utils_Rule
::cleanMoney($maxAmount);
324 if ((float ) $minAmount > (float ) $maxAmount) {
325 $errors['min_amount'] = ts('Minimum Amount should be less than Maximum Amount');
329 if (isset($fields['is_pay_later'])) {
330 if (empty($fields['pay_later_text'])) {
331 $errors['pay_later_text'] = ts('Please enter the text for the \'pay later\' checkbox displayed on the contribution form.');
333 if (empty($fields['pay_later_receipt'])) {
334 $errors['pay_later_receipt'] = ts('Please enter the instructions to be sent to the contributor when they choose to \'pay later\'.');
338 // don't allow price set w/ membership signup, CRM-5095
339 if ($priceSetId = CRM_Utils_Array
::value('price_set_id', $fields)) {
340 // don't allow price set w/ membership.
341 if ($hasMembershipBlk) {
342 $errors['price_set_id'] = ts('You cannot enable both a Contribution Price Set and Membership Signup on the same online contribution page.');
346 if (isset($fields['is_recur'])) {
347 if (empty($fields['recur_frequency_unit'])) {
348 $errors['recur_frequency_unit'] = ts('At least one recurring frequency option needs to be checked.');
352 // validation for pledge fields.
353 if (!empty($fields['is_pledge_active'])) {
354 if (empty($fields['pledge_frequency_unit'])) {
355 $errors['pledge_frequency_unit'] = ts('At least one pledge frequency option needs to be checked.');
357 if (!empty($fields['is_recur'])) {
358 $errors['is_recur'] = ts('You cannot enable both Recurring Contributions AND Pledges on the same online contribution page.');
362 // If Contribution amount section is enabled, then
363 // Allow other amounts must be enabled OR the Fixed Contribution
364 // Contribution options must contain at least one set of values.
365 if (!empty($fields['amount_block_is_active'])) {
366 if (empty($fields['is_allow_other_amount']) &&
369 //get the values of amount block
370 $values = CRM_Utils_Array
::value('value', $fields);
372 for ($i = 1; $i < self
::NUM_OPTION
; $i++
) {
373 if ((isset($values[$i]) && (strlen(trim($values[$i])) > 0))) {
378 $errors['amount_block_is_active'] = ts('If you want to enable the \'Contribution Amounts section\', you need to either \'Allow Other Amounts\' and/or enter at least one row in the \'Fixed Contribution Amounts\' table.');
384 if (!empty($fields['payment_processor']) && $financialType = CRM_Contribute_BAO_Contribution
::validateFinancialType($self->_defaultValues
['financial_type_id'])) {
385 $errors['payment_processor'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
388 if (!empty($fields['is_recur_interval'])) {
389 foreach(array_keys($fields['payment_processor']) as $paymentProcessorID) {
390 $paymentProcessorTypeId = CRM_Core_DAO
::getFieldValue(
391 'CRM_Financial_DAO_PaymentProcessor',
393 'payment_processor_type_id'
395 $paymentProcessorType = CRM_Core_PseudoConstant
::paymentProcessorType(false, $paymentProcessorTypeId, 'name');
396 if ($paymentProcessorType == 'Google_Checkout') {
397 $errors['is_recur_interval'] = ts('Google Checkout does not support recurring intervals');
412 public function postProcess() {
413 // get the submitted form values.
414 $params = $this->controller
->exportValues($this->_name
);
416 //update 'is_billing_required'
417 if (empty($params['is_pay_later'])) {
418 $params['is_billing_required'] = 0;
421 if (array_key_exists('payment_processor', $params)) {
422 if (array_key_exists(CRM_Core_DAO
::getFieldValue('CRM_Financial_DAO_PaymentProcessor', 'AuthNet',
423 'id', 'payment_processor_type_id'
425 CRM_Utils_Array
::value('payment_processor', $params)
427 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).'), '', 'alert');
431 // check for price set.
432 $priceSetID = CRM_Utils_Array
::value('price_set_id', $params);
434 // get required fields.
438 'min_amount' => "null",
439 'max_amount' => "null",
440 'is_monetary' => FALSE,
441 'is_pay_later' => FALSE,
442 'is_billing_required' => FALSE,
443 'is_recur_interval' => FALSE,
444 'is_recur_installments' => FALSE,
445 'recur_frequency_unit' => "null",
446 'default_amount_id' => "null",
447 'is_allow_other_amount' => FALSE,
448 'amount_block_is_active' => FALSE,
450 $resetFields = array();
452 $resetFields = array('min_amount', 'max_amount', 'is_allow_other_amount');
455 if (empty($params['is_recur'])) {
456 $resetFields = array_merge($resetFields, array('is_recur_interval', 'recur_frequency_unit'));
459 foreach ($fields as $field => $defaultVal) {
460 $val = CRM_Utils_Array
::value($field, $params, $defaultVal);
461 if (in_array($field, $resetFields)) {
465 if (in_array($field, array(
466 'min_amount', 'max_amount'))) {
467 $val = CRM_Utils_Rule
::cleanMoney($val);
470 $params[$field] = $val;
473 if ($params['is_recur']) {
474 $params['recur_frequency_unit'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
,
475 array_keys($params['recur_frequency_unit'])
477 $params['is_recur_interval'] = CRM_Utils_Array
::value('is_recur_interval', $params, FALSE);
478 $params['is_recur_installments'] = CRM_Utils_Array
::value('is_recur_installments', $params, FALSE);
481 if (array_key_exists('payment_processor', $params) &&
482 !CRM_Utils_System
::isNull($params['payment_processor'])
484 $params['payment_processor'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
, array_keys($params['payment_processor']));
487 $params['payment_processor'] = 'null';
490 $contributionPage = CRM_Contribute_BAO_ContributionPage
::create($params);
491 $contributionPageID = $contributionPage->id
;
493 // prepare for data cleanup.
494 $deleteAmountBlk = $deletePledgeBlk = $deletePriceSet = FALSE;
495 if ($this->_priceSetID
) {
496 $deletePriceSet = TRUE;
498 if ($this->_pledgeBlockID
) {
499 $deletePledgeBlk = TRUE;
501 if (!empty($this->_amountBlock
)) {
502 $deleteAmountBlk = TRUE;
505 if ($contributionPageID) {
507 if (!empty($params['amount_block_is_active'])) {
510 // add/update price set.
511 $deletePriceSet = FALSE;
512 if (!empty($params['price_field_id']) ||
!empty($params['price_field_other'])) {
513 $deleteAmountBlk = TRUE;
516 CRM_Price_BAO_PriceSet
::addTo('civicrm_contribution_page', $contributionPageID, $priceSetID);
520 $deletePriceSet = FALSE;
521 // process contribution amount block
522 $deleteAmountBlk = FALSE;
524 $labels = CRM_Utils_Array
::value('label', $params);
525 $values = CRM_Utils_Array
::value('value', $params);
526 $default = CRM_Utils_Array
::value('default', $params);
529 for ($i = 1; $i < self
::NUM_OPTION
; $i++
) {
530 if (isset($values[$i]) &&
531 (strlen(trim($values[$i])) > 0)
533 $options[] = array('label' => trim($labels[$i]),
534 'value' => CRM_Utils_Rule
::cleanMoney(trim($values[$i])),
537 'is_default' => $default == $i,
541 /* || !empty($params['price_field_value']) || CRM_Utils_Array::value( 'price_field_other', $params )*/
542 if (!empty($options) ||
!empty($params['is_allow_other_amount'])) {
543 $fieldParams['is_quick_config'] = 1;
544 $noContriAmount = NULL;
545 $usedPriceSetId = CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $this->_id
, 3);
546 if (!(!empty($params['price_field_id']) ||
!empty($params['price_field_other'])) && !$usedPriceSetId) {
547 $pageTitle = strtolower(CRM_Utils_String
::munge($this->_values
['title'], '_', 245));
548 $setParams['title'] = $this->_values
['title'];
549 if (!CRM_Core_DAO
::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle, 'id', 'name')) {
550 $setParams['name'] = $pageTitle;
552 elseif (!CRM_Core_DAO
::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle . '_' . $this->_id
, 'id', 'name')) {
553 $setParams['name'] = $pageTitle . '_' . $this->_id
;
556 $timeSec = explode(".", microtime(true));
557 $setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
559 $setParams['is_quick_config'] = 1;
560 $setParams['financial_type_id'] = CRM_Utils_Array
::value('financial_type_id', $this->_values
);
561 $setParams['extends'] = CRM_Core_Component
::getComponentID('CiviContribute');
562 $priceSet = CRM_Price_BAO_PriceSet
::create($setParams);
563 $priceSetId = $priceSet->id
;
565 elseif ($usedPriceSetId && empty($params['price_field_id'])) {
566 $priceSetId = $usedPriceSetId;
569 if ($priceFieldId = CRM_Utils_Array
::value('price_field_id', $params)) {
570 foreach ($params['price_field_value'] as $arrayID => $fieldValueID) {
571 if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) {
572 CRM_Price_BAO_PriceFieldValue
::setIsActive($fieldValueID, '0');
573 unset($params['price_field_value'][$arrayID]);
576 if (implode('', $params['price_field_value'])) {
577 $fieldParams['id'] = CRM_Utils_Array
::value('price_field_id', $params);
578 $fieldParams['option_id'] = $params['price_field_value'];
582 CRM_Price_BAO_PriceField
::setIsActive($priceFieldId, '0');
585 else $priceFieldId = CRM_Utils_Array
::value('price_field_other', $params);
586 $priceSetId = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceField', $priceFieldId, 'price_set_id');
588 CRM_Price_BAO_PriceSet
::addTo('civicrm_contribution_page', $this->_id
, $priceSetId);
589 if (!empty($options)) {
590 $editedFieldParams = array(
591 'price_set_id' => $priceSetId,
592 'name' => 'contribution_amount',
594 $editedResults = array();
596 CRM_Price_BAO_PriceField
::retrieve($editedFieldParams, $editedResults);
597 if (empty($editedResults['id'])) {
598 $fieldParams['name'] = strtolower(CRM_Utils_String
::munge("Contribution Amount", '_', 245));
601 $fieldParams['id'] = CRM_Utils_Array
::value('id', $editedResults);
604 $fieldParams['price_set_id'] = $priceSetId;
605 $fieldParams['is_active'] = 1;
606 $fieldParams['weight'] = 2;
608 if (!empty($params['is_allow_other_amount'])) {
609 $fieldParams['is_required'] = 0;
612 $fieldParams['is_required'] = 1;
614 $fieldParams['label'] = $params['amount_label'];
615 $fieldParams['html_type'] = 'Radio';
616 $fieldParams['option_label'] = $params['label'];
617 $fieldParams['option_amount'] = $params['value'];
618 $fieldParams['financial_type_id'] = CRM_Utils_Array
::value('financial_type_id', $this->_values
);
619 foreach ($options as $value) {
620 $fieldParams['option_weight'][$value['weight']] = $value['weight'];
622 $fieldParams['default_option'] = $params['default'];
623 $priceField = CRM_Price_BAO_PriceField
::create($fieldParams);
625 if (!empty($params['is_allow_other_amount']) && empty($params['price_field_other'])) {
626 $editedFieldParams = array(
627 'price_set_id' => $priceSetId,
628 'name' => 'other_amount',
630 $editedResults = array();
632 CRM_Price_BAO_PriceField
::retrieve($editedFieldParams, $editedResults);
634 if (!$priceFieldID = CRM_Utils_Array
::value('id', $editedResults)) {
635 $fieldParams = array(
636 'name' => 'other_amount',
637 'label' => 'Other Amount',
638 'price_set_id' => $priceSetId,
639 'html_type' => 'Text',
640 'financial_type_id' => CRM_Utils_Array
::value('financial_type_id', $this->_values
),
641 'is_display_amounts' => 0,
644 $fieldParams['option_weight'][1] = 1;
645 $fieldParams['option_amount'][1] = 1;
646 if (!$noContriAmount) {
647 $fieldParams['is_required'] = 1;
648 $fieldParams['option_label'][1] = $fieldParams['label'] = $params['amount_label'];
651 $fieldParams['is_required'] = 0;
652 $fieldParams['option_label'][1] = $fieldParams['label'] = 'Other Amount';
655 $priceField = CRM_Price_BAO_PriceField
::create($fieldParams);
658 if (empty($editedResults['is_active'])) {
659 $fieldParams = $editedResults;
660 if (!$noContriAmount) {
661 $priceFieldValueID = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldID, 'id', 'price_field_id');
662 CRM_Core_DAO
::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', $params['amount_label']);
663 $fieldParams = array(
665 'label' => $params['amount_label'],
666 'id' => $priceFieldID,
669 $fieldParams['is_active'] = 1;
670 $priceField = CRM_Price_BAO_PriceField
::add($fieldParams);
674 elseif (empty($params['is_allow_other_amount']) && !empty($params['price_field_other'])) {
675 CRM_Price_BAO_PriceField
::setIsActive($params['price_field_other'], '0');
677 elseif ($priceFieldID = CRM_Utils_Array
::value('price_field_other', $params)) {
678 $priceFieldValueID = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldID, 'id', 'price_field_id');
679 if (!$noContriAmount) {
680 $fieldParams = array(
682 'label' => $params['amount_label'],
683 'id' => $priceFieldID,
685 CRM_Price_BAO_PriceField
::add($fieldParams);
686 CRM_Core_DAO
::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', $params['amount_label']);
689 CRM_Core_DAO
::setFieldValue('CRM_Price_DAO_PriceField', $priceFieldID, 'is_required', 0 );
690 CRM_Core_DAO
::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', 'Other Amount');
695 if (!empty($params['is_pledge_active'])) {
696 $deletePledgeBlk = FALSE;
697 $pledgeBlockParams = array(
698 'entity_id' => $contributionPageID,
699 'entity_table' => ts('civicrm_contribution_page'),
701 if ($this->_pledgeBlockID
) {
702 $pledgeBlockParams['id'] = $this->_pledgeBlockID
;
704 $pledgeBlock = array(
705 'pledge_frequency_unit', 'max_reminders',
706 'initial_reminder_day', 'additional_reminder_day',
708 foreach ($pledgeBlock as $key) {
709 $pledgeBlockParams[$key] = CRM_Utils_Array
::value($key, $params);
711 $pledgeBlockParams['is_pledge_interval'] = CRM_Utils_Array
::value('is_pledge_interval',
714 // create pledge block.
715 CRM_Pledge_BAO_PledgeBlock
::create($pledgeBlockParams);
720 if (!empty($params['price_field_id']) ||
!empty($params['price_field_other'])) {
721 $usedPriceSetId = CRM_Price_BAO_PriceSet
::getFor('civicrm_contribution_page', $this->_id
, 3);
722 if ($usedPriceSetId) {
723 if (!empty($params['price_field_id'])) {
724 CRM_Price_BAO_PriceField
::setIsActive($params['price_field_id'], '0');
726 if (!empty($params['price_field_other'])) {
727 CRM_Price_BAO_PriceField
::setIsActive($params['price_field_other'], '0');
731 $deleteAmountBlk = TRUE;
732 $deletePriceSet = TRUE;
737 // delete pledge block.
738 if ($deletePledgeBlk) {
739 CRM_Pledge_BAO_PledgeBlock
::deletePledgeBlock($this->_pledgeBlockID
);
742 // delete previous price set.
743 if ($deletePriceSet) {
744 CRM_Price_BAO_PriceSet
::removeFrom('civicrm_contribution_page', $contributionPageID);
747 if ($deleteAmountBlk ) {
748 $priceField = !empty($params['price_field_id']) ?
$params['price_field_id']:CRM_Utils_Array
::value('price_field_other', $params);
750 $priceSetID = CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceField', $priceField, 'price_set_id');
751 CRM_Price_BAO_PriceSet
::setIsQuickConfig($priceSetID,0);
755 parent
::endPostProcess();
759 * Return a descriptive name for the page, used in wizard header
764 public function getTitle() {
765 return ts('Amounts');