First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
|
@ -0,0 +1,286 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* form to process actions fo adding product to contribution page
|
||||
*/
|
||||
class CRM_Contribute_Form_ContributionPage_AddProduct extends CRM_Contribute_Form_ContributionPage {
|
||||
|
||||
protected $_products;
|
||||
|
||||
protected $_pid;
|
||||
|
||||
/**
|
||||
* Pre process the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
$this->_products = CRM_Contribute_PseudoConstant::products($this->_id);
|
||||
$this->_pid = CRM_Utils_Request::retrieve('pid', 'Positive',
|
||||
$this, FALSE, 0
|
||||
);
|
||||
|
||||
if ($this->_pid) {
|
||||
$dao = new CRM_Contribute_DAO_PremiumsProduct();
|
||||
$dao->id = $this->_pid;
|
||||
$dao->find(TRUE);
|
||||
$temp = CRM_Contribute_PseudoConstant::products();
|
||||
$this->_products[$dao->product_id] = $temp[$dao->product_id];
|
||||
}
|
||||
|
||||
//$this->_products = array_merge(array('' => '-- Select Product --') , $this->_products );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* Note that in edit/view mode the default values are retrieved from the database.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
|
||||
if ($this->_pid) {
|
||||
$dao = new CRM_Contribute_DAO_PremiumsProduct();
|
||||
$dao->id = $this->_pid;
|
||||
$dao->find(TRUE);
|
||||
$defaults['product_id'] = $dao->product_id;
|
||||
$defaults['financial_type_id'] = $dao->financial_type_id;
|
||||
$defaults['weight'] = $dao->weight;
|
||||
}
|
||||
else {
|
||||
$dao = new CRM_Contribute_DAO_Product();
|
||||
$dao->id = key($this->_products);
|
||||
$dao->find(TRUE);
|
||||
$defaults['financial_type_id'] = $dao->financial_type_id;
|
||||
}
|
||||
if (!isset($defaults['weight']) || !($defaults['weight'])) {
|
||||
$pageID = CRM_Utils_Request::retrieve('id', 'Positive',
|
||||
$this, FALSE, 0
|
||||
);
|
||||
$dao = new CRM_Contribute_DAO_Premium();
|
||||
$dao->entity_table = 'civicrm_contribution_page';
|
||||
$dao->entity_id = $pageID;
|
||||
$dao->find(TRUE);
|
||||
$premiumID = $dao->id;
|
||||
|
||||
$sql = 'SELECT max( weight ) as max_weight FROM civicrm_premiums_product WHERE premiums_id = %1';
|
||||
$params = array(1 => array($premiumID, 'Integer'));
|
||||
$dao = CRM_Core_DAO::executeQuery($sql, $params);
|
||||
$dao->fetch();
|
||||
$defaults['weight'] = $dao->max_weight + 1;
|
||||
}
|
||||
RETURN $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$urlParams = 'civicrm/admin/contribute/premium';
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id);
|
||||
$session->pushUserContext($url);
|
||||
if (CRM_Utils_Request::retrieve('confirmed', 'Boolean',
|
||||
CRM_Core_DAO::$_nullObject, '', '', 'GET'
|
||||
)
|
||||
) {
|
||||
$dao = new CRM_Contribute_DAO_PremiumsProduct();
|
||||
$dao->id = $this->_pid;
|
||||
$dao->delete();
|
||||
CRM_Core_Session::setStatus(ts('Selected Premium Product has been removed from this Contribution Page.'), ts('Saved'), 'success');
|
||||
CRM_Utils_System::redirect($url);
|
||||
}
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Delete'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->_action & CRM_Core_Action::PREVIEW) {
|
||||
CRM_Contribute_BAO_Premium::buildPremiumPreviewBlock($this, NULL, $this->_pid);
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Done with Preview'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id);
|
||||
$session->pushUserContext($url);
|
||||
|
||||
$this->add('select', 'product_id', ts('Select the Product') . ' ', $this->_products, TRUE);
|
||||
|
||||
$this->addElement('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_PremiumsProduct', 'weight'));
|
||||
|
||||
$financialType = CRM_Contribute_PseudoConstant::financialType();
|
||||
$premiumFinancialType = array();
|
||||
CRM_Core_PseudoConstant::populate(
|
||||
$premiumFinancialType,
|
||||
'CRM_Financial_DAO_EntityFinancialAccount',
|
||||
$all = TRUE,
|
||||
$retrieve = 'entity_id',
|
||||
$filter = NULL,
|
||||
'account_relationship = 8'
|
||||
);
|
||||
|
||||
$costFinancialType = array();
|
||||
CRM_Core_PseudoConstant::populate(
|
||||
$costFinancialType,
|
||||
'CRM_Financial_DAO_EntityFinancialAccount',
|
||||
$all = TRUE,
|
||||
$retrieve = 'entity_id',
|
||||
$filter = NULL,
|
||||
'account_relationship = 7'
|
||||
);
|
||||
$productFinancialType = array_intersect($costFinancialType, $premiumFinancialType);
|
||||
foreach ($financialType as $key => $financialTypeName) {
|
||||
if (!in_array($key, $productFinancialType)) {
|
||||
unset($financialType[$key]);
|
||||
}
|
||||
}
|
||||
// Check permissioned financial types
|
||||
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialType, CRM_Core_Action::ADD);
|
||||
if (count($financialType)) {
|
||||
$this->assign('financialType', $financialType);
|
||||
}
|
||||
$this->add(
|
||||
'select',
|
||||
'financial_type_id',
|
||||
ts('Financial Type'),
|
||||
array('' => ts('- select -')) + $financialType
|
||||
);
|
||||
$this->addRule('weight', ts('Please enter integer value for weight'), 'integer');
|
||||
$session->pushUserContext(CRM_Utils_System::url($urlParams, 'action=update&reset=1&id=' . $this->_id));
|
||||
|
||||
if ($this->_single) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Save'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// get the submitted form values.
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
$urlParams = 'civicrm/admin/contribute/premium';
|
||||
if ($this->_action & CRM_Core_Action::PREVIEW) {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id);
|
||||
$single = $session->get('singleForm');
|
||||
CRM_Utils_System::redirect($url);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id);
|
||||
$dao = new CRM_Contribute_DAO_PremiumsProduct();
|
||||
$dao->id = $this->_pid;
|
||||
$dao->delete();
|
||||
CRM_Core_Session::setStatus(ts('Selected Premium Product has been removed from this Contribution Page.'), ts('Saved'), 'success');
|
||||
CRM_Utils_System::redirect($url);
|
||||
}
|
||||
else {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$url = CRM_Utils_System::url($urlParams, 'reset=1&action=update&id=' . $this->_id);
|
||||
if ($this->_pid) {
|
||||
$params['id'] = $this->_pid;
|
||||
}
|
||||
$dao = new CRM_Contribute_DAO_Premium();
|
||||
$dao->entity_table = 'civicrm_contribution_page';
|
||||
$dao->entity_id = $this->_id;
|
||||
$dao->find(TRUE);
|
||||
$premiumID = $dao->id;
|
||||
$params['premiums_id'] = $premiumID;
|
||||
|
||||
$oldWeight = NULL;
|
||||
if ($this->_pid) {
|
||||
$oldWeight = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PremiumsProduct', $this->_pid, 'weight', 'id');
|
||||
}
|
||||
|
||||
// updateOtherWeights needs to filter on premiums_id
|
||||
$filter = array('premiums_id' => $params['premiums_id']);
|
||||
$params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Contribute_DAO_PremiumsProduct', $oldWeight, $params['weight'], $filter);
|
||||
|
||||
$dao = new CRM_Contribute_DAO_PremiumsProduct();
|
||||
$dao->copyValues($params);
|
||||
$dao->save();
|
||||
CRM_Utils_System::redirect($url);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Add Premium to Contribution Page');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,843 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* form to process actions on the group aspect of Custom Data
|
||||
*/
|
||||
class CRM_Contribute_Form_ContributionPage_Amount extends CRM_Contribute_Form_ContributionPage {
|
||||
|
||||
/**
|
||||
* Contribution amount block.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_amountBlock = array();
|
||||
|
||||
/**
|
||||
* Constants for number of options for data types of multiple option.
|
||||
*/
|
||||
const NUM_OPTION = 11;
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
|
||||
// do u want to allow a free form text field for amount
|
||||
$this->addElement('checkbox', 'is_allow_other_amount', ts('Allow other amounts'), NULL, array('onclick' => "minMax(this);showHideAmountBlock( this, 'is_allow_other_amount' );"));
|
||||
$this->add('text', 'min_amount', ts('Minimum Amount'), array('size' => 8, 'maxlength' => 8));
|
||||
$this->addRule('min_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('9.99', ' '))), 'money');
|
||||
|
||||
$this->add('text', 'max_amount', ts('Maximum Amount'), array('size' => 8, 'maxlength' => 8));
|
||||
$this->addRule('max_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
|
||||
|
||||
//CRM-12055
|
||||
$this->add('text', 'amount_label', ts('Contribution Amounts Label'));
|
||||
|
||||
$default = array($this->createElement('radio', NULL, NULL, NULL, 0));
|
||||
$this->add('hidden', "price_field_id", '', array('id' => "price_field_id"));
|
||||
$this->add('hidden', "price_field_other", '', array('id' => "price_field_option"));
|
||||
for ($i = 1; $i <= self::NUM_OPTION; $i++) {
|
||||
// label
|
||||
$this->add('text', "label[$i]", ts('Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'));
|
||||
|
||||
$this->add('hidden', "price_field_value[$i]", '', array('id' => "price_field_value[$i]"));
|
||||
|
||||
// value
|
||||
$this->add('text', "value[$i]", ts('Value'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value'));
|
||||
$this->addRule("value[$i]", ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
|
||||
|
||||
// default
|
||||
$default[] = $this->createElement('radio', NULL, NULL, NULL, $i);
|
||||
}
|
||||
|
||||
$this->addGroup($default, 'default');
|
||||
|
||||
$this->addElement('checkbox', 'amount_block_is_active', ts('Contribution Amounts section enabled'), NULL, array('onclick' => "showHideAmountBlock( this, 'amount_block_is_active' );"));
|
||||
|
||||
$this->addElement('checkbox', 'is_monetary', ts('Execute real-time monetary transactions'));
|
||||
|
||||
$paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getAllPaymentProcessors('live');
|
||||
$recurringPaymentProcessor = $futurePaymentProcessor = $paymentProcessor = array();
|
||||
|
||||
if (!empty($paymentProcessors)) {
|
||||
foreach ($paymentProcessors as $id => $processor) {
|
||||
if ($id != 0) {
|
||||
$paymentProcessor[$id] = $processor['name'];
|
||||
}
|
||||
if (CRM_Utils_Array::value('is_recur', $processor)) {
|
||||
$recurringPaymentProcessor[] = $id;
|
||||
}
|
||||
if (CRM_Utils_Array::value('object', $processor) && $processor['object']->supports('FutureRecurStartDate')) {
|
||||
$futurePaymentProcessor[] = $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($recurringPaymentProcessor)) {
|
||||
$this->assign('recurringPaymentProcessor', $recurringPaymentProcessor);
|
||||
}
|
||||
if (count($futurePaymentProcessor)) {
|
||||
$this->assign('futurePaymentProcessor', $futurePaymentProcessor);
|
||||
}
|
||||
if (count($paymentProcessor)) {
|
||||
$this->assign('paymentProcessor', $paymentProcessor);
|
||||
}
|
||||
|
||||
$this->addCheckBox('payment_processor', ts('Payment Processor'),
|
||||
array_flip($paymentProcessor),
|
||||
NULL, NULL, NULL, NULL,
|
||||
array(' ', ' ', ' ', '<br/>')
|
||||
);
|
||||
|
||||
//check if selected payment processor supports recurring payment
|
||||
if (!empty($recurringPaymentProcessor)) {
|
||||
$this->addElement('checkbox', 'is_recur', ts('Recurring Contributions'), NULL,
|
||||
array('onclick' => "showHideByValue('is_recur',true,'recurFields','table-row','radio',false);")
|
||||
);
|
||||
$this->addCheckBox('recur_frequency_unit', ts('Supported recurring units'),
|
||||
CRM_Core_OptionGroup::values('recur_frequency_units', FALSE, FALSE, TRUE),
|
||||
NULL, NULL, NULL, NULL,
|
||||
array(' ', ' ', ' ', '<br/>'), TRUE
|
||||
);
|
||||
$this->addElement('checkbox', 'is_recur_interval', ts('Support recurring intervals'));
|
||||
$this->addElement('checkbox', 'is_recur_installments', ts('Offer installments'));
|
||||
}
|
||||
|
||||
// add pay later options
|
||||
$this->addElement('checkbox', 'is_pay_later', ts('Pay later option'), NULL);
|
||||
$this->addElement('textarea', 'pay_later_text', ts('Pay later label'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'pay_later_text'),
|
||||
FALSE
|
||||
);
|
||||
$this->add('wysiwyg', 'pay_later_receipt', ts('Pay Later Instructions'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'pay_later_receipt'));
|
||||
$this->addElement('checkbox', 'is_billing_required', ts('Billing address required'));
|
||||
|
||||
//add partial payment options
|
||||
|
||||
// add price set fields
|
||||
$price = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviContribute');
|
||||
if (CRM_Utils_System::isNull($price)) {
|
||||
$this->assign('price', FALSE);
|
||||
}
|
||||
else {
|
||||
$this->assign('price', TRUE);
|
||||
}
|
||||
$this->add('select', 'price_set_id', ts('Price Set'),
|
||||
array(
|
||||
'' => ts('- none -'),
|
||||
) + $price,
|
||||
NULL, array('onchange' => "showHideAmountBlock( this.value, 'price_set_id' );")
|
||||
);
|
||||
//CiviPledge fields.
|
||||
$config = CRM_Core_Config::singleton();
|
||||
if (in_array('CiviPledge', $config->enableComponents)) {
|
||||
$this->assign('civiPledge', TRUE);
|
||||
$this->addElement('checkbox', 'is_pledge_active', ts('Pledges'),
|
||||
NULL, array('onclick' => "showHideAmountBlock( this, 'is_pledge_active' ); return showHideByValue('is_pledge_active',true,'pledgeFields','table-row','radio',false);")
|
||||
);
|
||||
$this->addCheckBox('pledge_frequency_unit', ts('Supported pledge frequencies'),
|
||||
CRM_Core_OptionGroup::values('recur_frequency_units', FALSE, FALSE, TRUE),
|
||||
NULL, NULL, NULL, NULL,
|
||||
array(' ', ' ', ' ', '<br/>'), TRUE
|
||||
);
|
||||
$this->addElement('checkbox', 'is_pledge_interval', ts('Allow frequency intervals'));
|
||||
$this->addElement('text', 'initial_reminder_day', ts('Send payment reminder'), array('size' => 3));
|
||||
$this->addElement('text', 'max_reminders', ts('Send up to'), array('size' => 3));
|
||||
$this->addElement('text', 'additional_reminder_day', ts('Send additional reminders'), array('size' => 3));
|
||||
if (!empty($futurePaymentProcessor)) {
|
||||
// CRM-18854
|
||||
$this->addElement('checkbox', 'adjust_recur_start_date', ts('Adjust Recurring Start Date'), NULL,
|
||||
array('onclick' => "showHideByValue('adjust_recur_start_date',true,'recurDefaults','table-row','radio',false);")
|
||||
);
|
||||
$this->addDate('pledge_calendar_date', ts('Specific Calendar Date'));
|
||||
$month = CRM_Utils_Date::getCalendarDayOfMonth();
|
||||
$this->add('select', 'pledge_calendar_month', ts('Specific day of Month'), $month);
|
||||
$pledgeDefaults = array(
|
||||
'contribution_date' => ts('Day of Contribution'),
|
||||
'calendar_date' => ts('Specific Calendar Date'),
|
||||
'calendar_month' => ts('Specific day of Month'),
|
||||
);
|
||||
$this->addRadio('pledge_default_toggle', ts('Recurring Contribution Start Date Default'), $pledgeDefaults, array('allowClear' => FALSE), '<br/><br/>');
|
||||
$this->addElement('checkbox', 'is_pledge_start_date_visible', ts('Show Recurring Donation Start Date?'), NULL);
|
||||
$this->addElement('checkbox', 'is_pledge_start_date_editable', ts('Allow Edits to Recurring Donation Start date?'), NULL);
|
||||
}
|
||||
}
|
||||
|
||||
//add currency element.
|
||||
$this->addCurrency('currency', ts('Currency'));
|
||||
|
||||
$this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Amount', 'formRule'), $this);
|
||||
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. Note that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = parent::setDefaultValues();
|
||||
|
||||
if (empty($defaults['pay_later_text'])) {
|
||||
$defaults['pay_later_text'] = ts('I will send payment by check');
|
||||
}
|
||||
|
||||
if (!empty($defaults['amount_block_is_active'])) {
|
||||
|
||||
if ($priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, NULL)) {
|
||||
if ($isQuick = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config')) {
|
||||
$this->assign('isQuick', $isQuick);
|
||||
//$priceField = CRM_Core_DAO::getFieldValue( 'CRM_Price_DAO_PriceField', $priceSetId, 'id', 'price_set_id' );
|
||||
$options = $pFIDs = array();
|
||||
$priceFieldParams = array('price_set_id' => $priceSetId);
|
||||
$priceFields = CRM_Core_DAO::commonRetrieveAll('CRM_Price_DAO_PriceField', 'price_set_id', $priceSetId, $pFIDs, $return = array(
|
||||
'html_type',
|
||||
'name',
|
||||
'is_active',
|
||||
'label',
|
||||
));
|
||||
foreach ($priceFields as $priceField) {
|
||||
if ($priceField['id'] && $priceField['html_type'] == 'Radio' && $priceField['name'] == 'contribution_amount') {
|
||||
$defaults['price_field_id'] = $priceField['id'];
|
||||
$priceFieldOptions = CRM_Price_BAO_PriceFieldValue::getValues($priceField['id'], $options, 'id', 1);
|
||||
if (empty($priceFieldOptions)) {
|
||||
continue;
|
||||
}
|
||||
$countRow = 0;
|
||||
$defaults['amount_label'] = $priceField['label'];
|
||||
foreach ($options as $optionId => $optionValue) {
|
||||
$countRow++;
|
||||
$defaults['value'][$countRow] = $optionValue['amount'];
|
||||
$defaults['label'][$countRow] = CRM_Utils_Array::value('label', $optionValue);
|
||||
$defaults['name'][$countRow] = CRM_Utils_Array::value('name', $optionValue);
|
||||
$defaults['weight'][$countRow] = $optionValue['weight'];
|
||||
|
||||
$defaults["price_field_value"][$countRow] = $optionValue['id'];
|
||||
if ($optionValue['is_default']) {
|
||||
$defaults['default'] = $countRow;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ($priceField['id'] && $priceField['html_type'] == 'Text' && $priceField['name'] = 'other_amount' && $priceField['is_active']) {
|
||||
$defaults['price_field_other'] = $priceField['id'];
|
||||
if (!isset($defaults['amount_label'])) {
|
||||
$defaults['amount_label'] = $priceField['label'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($defaults['amount_label'])) {
|
||||
$defaults['amount_label'] = ts('Contribution Amount');
|
||||
}
|
||||
|
||||
if (!empty($defaults['value']) && is_array($defaults['value'])) {
|
||||
|
||||
// CRM-4038: fix value display
|
||||
foreach ($defaults['value'] as & $amount) {
|
||||
$amount = trim(CRM_Utils_Money::format($amount, ' '));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fix the display of the monetary value, CRM-4038
|
||||
if (isset($defaults['min_amount'])) {
|
||||
$defaults['min_amount'] = CRM_Utils_Money::format($defaults['min_amount'], NULL, '%a');
|
||||
}
|
||||
if (isset($defaults['max_amount'])) {
|
||||
$defaults['max_amount'] = CRM_Utils_Money::format($defaults['max_amount'], NULL, '%a');
|
||||
}
|
||||
|
||||
if (!empty($defaults['payment_processor'])) {
|
||||
$defaults['payment_processor'] = array_fill_keys(explode(CRM_Core_DAO::VALUE_SEPARATOR,
|
||||
$defaults['payment_processor']
|
||||
), '1');
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Global form rule.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
* @param array $files
|
||||
* The uploaded files if any.
|
||||
* @param $self
|
||||
*
|
||||
*
|
||||
* @return bool|array
|
||||
* true if no errors, else array of errors
|
||||
*/
|
||||
public static function formRule($fields, $files, $self) {
|
||||
$errors = array();
|
||||
//as for separate membership payment we has to have
|
||||
//contribution amount section enabled, hence to disable it need to
|
||||
//check if separate membership payment enabled,
|
||||
//if so disable first separate membership payment option
|
||||
//then disable contribution amount section. CRM-3801,
|
||||
|
||||
$membershipBlock = new CRM_Member_DAO_MembershipBlock();
|
||||
$membershipBlock->entity_table = 'civicrm_contribution_page';
|
||||
$membershipBlock->entity_id = $self->_id;
|
||||
$membershipBlock->is_active = 1;
|
||||
$hasMembershipBlk = FALSE;
|
||||
if ($membershipBlock->find(TRUE)) {
|
||||
if (!empty($fields['amount_block_is_active']) &&
|
||||
($setID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $self->_id, NULL, 1))
|
||||
) {
|
||||
$extends = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'extends');
|
||||
if ($extends && $extends == CRM_Core_Component::getComponentID('CiviMember')) {
|
||||
$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.');
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
$hasMembershipBlk = TRUE;
|
||||
if ($membershipBlock->is_separate_payment && empty($fields['amount_block_is_active'])) {
|
||||
$errors['amount_block_is_active'] = ts('To disable Contribution Amounts section you need to first disable Separate Membership Payment option from Membership Settings.');
|
||||
}
|
||||
|
||||
//CRM-16165, Don't allow reccuring contribution if membership block contain any renewable membership option
|
||||
$membershipTypes = unserialize($membershipBlock->membership_types);
|
||||
if (!empty($fields['is_recur']) && !empty($membershipTypes)) {
|
||||
if (!$membershipBlock->is_separate_payment) {
|
||||
$errors['is_recur'] = ts('You need to enable Separate Membership Payment when online contribution page is configured for both Membership and Recurring Contribution.');
|
||||
}
|
||||
elseif (count(array_filter($membershipTypes)) != 0) {
|
||||
$errors['is_recur'] = ts('You cannot enable both Recurring Contributions and Auto-renew memberships on the same online contribution page.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CRM-18854 Check if recurring start date is in the future.
|
||||
if (CRM_Utils_Array::value('pledge_calendar_date', $fields)) {
|
||||
if (date('Ymd') > date('Ymd', strtotime($fields['pledge_calendar_date']))) {
|
||||
$errors['pledge_calendar_date'] = ts('The recurring start date cannot be prior to the current date.');
|
||||
}
|
||||
}
|
||||
|
||||
//check for the amount label (mandatory)
|
||||
if (!empty($fields['amount_block_is_active']) && empty($fields['price_set_id']) && empty($fields['amount_label'])) {
|
||||
$errors['amount_label'] = ts('Please enter the contribution amount label.');
|
||||
}
|
||||
$minAmount = CRM_Utils_Array::value('min_amount', $fields);
|
||||
$maxAmount = CRM_Utils_Array::value('max_amount', $fields);
|
||||
if (!empty($minAmount) && !empty($maxAmount)) {
|
||||
$minAmount = CRM_Utils_Rule::cleanMoney($minAmount);
|
||||
$maxAmount = CRM_Utils_Rule::cleanMoney($maxAmount);
|
||||
if ((float ) $minAmount > (float ) $maxAmount) {
|
||||
$errors['min_amount'] = ts('Minimum Amount should be less than Maximum Amount');
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($fields['is_pay_later'])) {
|
||||
if (empty($fields['pay_later_text'])) {
|
||||
$errors['pay_later_text'] = ts('Please enter the text for the \'pay later\' checkbox displayed on the contribution form.');
|
||||
}
|
||||
if (empty($fields['pay_later_receipt'])) {
|
||||
$errors['pay_later_receipt'] = ts('Please enter the instructions to be sent to the contributor when they choose to \'pay later\'.');
|
||||
}
|
||||
}
|
||||
|
||||
// don't allow price set w/ membership signup, CRM-5095
|
||||
if ($priceSetId = CRM_Utils_Array::value('price_set_id', $fields)) {
|
||||
// don't allow price set w/ membership.
|
||||
if ($hasMembershipBlk) {
|
||||
$errors['price_set_id'] = ts('You cannot enable both a Contribution Price Set and Membership Signup on the same online contribution page.');
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (isset($fields['is_recur'])) {
|
||||
if (empty($fields['recur_frequency_unit'])) {
|
||||
$errors['recur_frequency_unit'] = ts('At least one recurring frequency option needs to be checked.');
|
||||
}
|
||||
}
|
||||
|
||||
// validation for pledge fields.
|
||||
if (!empty($fields['is_pledge_active'])) {
|
||||
if (empty($fields['pledge_frequency_unit'])) {
|
||||
$errors['pledge_frequency_unit'] = ts('At least one pledge frequency option needs to be checked.');
|
||||
}
|
||||
if (!empty($fields['is_recur'])) {
|
||||
$errors['is_recur'] = ts('You cannot enable both Recurring Contributions AND Pledges on the same online contribution page.');
|
||||
}
|
||||
}
|
||||
|
||||
// If Contribution amount section is enabled, then
|
||||
// Allow other amounts must be enabled OR the Fixed Contribution
|
||||
// Contribution options must contain at least one set of values.
|
||||
if (!empty($fields['amount_block_is_active'])) {
|
||||
if (empty($fields['is_allow_other_amount']) &&
|
||||
!$priceSetId
|
||||
) {
|
||||
//get the values of amount block
|
||||
$values = CRM_Utils_Array::value('value', $fields);
|
||||
$isSetRow = FALSE;
|
||||
for ($i = 1; $i < self::NUM_OPTION; $i++) {
|
||||
if ((isset($values[$i]) && (strlen(trim($values[$i])) > 0))) {
|
||||
$isSetRow = TRUE;
|
||||
}
|
||||
}
|
||||
if (!$isSetRow) {
|
||||
$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.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($fields['payment_processor']) && $financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($self->_defaultValues['financial_type_id'])) {
|
||||
$errors['payment_processor'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
|
||||
}
|
||||
|
||||
if (!empty($fields['is_recur_interval'])) {
|
||||
foreach (array_keys($fields['payment_processor']) as $paymentProcessorID) {
|
||||
$paymentProcessorTypeId = CRM_Core_DAO::getFieldValue(
|
||||
'CRM_Financial_DAO_PaymentProcessor',
|
||||
$paymentProcessorID,
|
||||
'payment_processor_type_id'
|
||||
);
|
||||
$paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(FALSE, $paymentProcessorTypeId, 'name');
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// get the submitted form values.
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
//update 'is_billing_required'
|
||||
if (empty($params['is_pay_later'])) {
|
||||
$params['is_billing_required'] = 0;
|
||||
}
|
||||
|
||||
if (array_key_exists('payment_processor', $params)) {
|
||||
if (array_key_exists(CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', 'AuthNet',
|
||||
'id', 'payment_processor_type_id'
|
||||
),
|
||||
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).'), '', 'alert');
|
||||
}
|
||||
}
|
||||
|
||||
// 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_billing_required' => FALSE,
|
||||
'is_recur_interval' => FALSE,
|
||||
'is_recur_installments' => 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 (empty($params['is_recur'])) {
|
||||
$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);
|
||||
$params['is_recur_installments'] = CRM_Utils_Array::value('is_recur_installments', $params, FALSE);
|
||||
}
|
||||
|
||||
if (CRM_Utils_Array::value('adjust_recur_start_date', $params)) {
|
||||
$fieldValue = '';
|
||||
$pledgeDateFields = array(
|
||||
'calendar_date' => 'pledge_calendar_date',
|
||||
'calendar_month' => 'pledge_calendar_month',
|
||||
);
|
||||
if ($params['pledge_default_toggle'] == 'contribution_date') {
|
||||
$fieldValue = json_encode(array('contribution_date' => date('m/d/Y')));
|
||||
}
|
||||
else {
|
||||
foreach ($pledgeDateFields as $key => $pledgeDateField) {
|
||||
if (CRM_Utils_Array::value($pledgeDateField, $params) && $params['pledge_default_toggle'] == $key) {
|
||||
$fieldValue = json_encode(array($key => $params[$pledgeDateField]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$params['pledge_start_date'] = $fieldValue;
|
||||
}
|
||||
else {
|
||||
$params['pledge_start_date'] = '';
|
||||
$params['adjust_recur_start_date'] = 0;
|
||||
$params['is_pledge_start_date_visible'] = 0;
|
||||
$params['is_pledge_start_date_editable'] = 0;
|
||||
}
|
||||
if (!CRM_Utils_Array::value('is_pledge_start_date_visible', $params)) {
|
||||
$params['is_pledge_start_date_visible'] = 0;
|
||||
}
|
||||
if (!CRM_Utils_Array::value('is_pledge_start_date_editable', $params)) {
|
||||
$params['is_pledge_start_date_editable'] = 0;
|
||||
}
|
||||
|
||||
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 (!empty($params['amount_block_is_active'])) {
|
||||
// handle price set.
|
||||
if ($priceSetID) {
|
||||
// add/update price set.
|
||||
$deletePriceSet = FALSE;
|
||||
if (!empty($params['price_field_id']) || !empty($params['price_field_other'])) {
|
||||
$deleteAmountBlk = TRUE;
|
||||
}
|
||||
|
||||
CRM_Price_BAO_PriceSet::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,
|
||||
);
|
||||
}
|
||||
}
|
||||
/* || !empty($params['price_field_value']) || CRM_Utils_Array::value( 'price_field_other', $params )*/
|
||||
if (!empty($options) || !empty($params['is_allow_other_amount'])) {
|
||||
$fieldParams['is_quick_config'] = 1;
|
||||
$noContriAmount = NULL;
|
||||
$usedPriceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 3);
|
||||
if (!(!empty($params['price_field_id']) || !empty($params['price_field_other'])) && !$usedPriceSetId) {
|
||||
$pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245));
|
||||
$setParams['title'] = $this->_values['title'];
|
||||
if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle, 'id', 'name')) {
|
||||
$setParams['name'] = $pageTitle;
|
||||
}
|
||||
elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $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['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
|
||||
$setParams['extends'] = CRM_Core_Component::getComponentID('CiviContribute');
|
||||
$priceSet = CRM_Price_BAO_PriceSet::create($setParams);
|
||||
$priceSetId = $priceSet->id;
|
||||
}
|
||||
elseif ($usedPriceSetId && empty($params['price_field_id'])) {
|
||||
$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_PriceFieldValue::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_PriceField::setIsActive($priceFieldId, '0');
|
||||
}
|
||||
}
|
||||
else {
|
||||
$priceFieldId = CRM_Utils_Array::value('price_field_other', $params);
|
||||
}
|
||||
$priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $priceFieldId, 'price_set_id');
|
||||
}
|
||||
CRM_Price_BAO_PriceSet::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_PriceField::retrieve($editedFieldParams, $editedResults);
|
||||
if (empty($editedResults['id'])) {
|
||||
$fieldParams['name'] = strtolower(CRM_Utils_String::munge("Contribution Amount", '_', 245));
|
||||
}
|
||||
else {
|
||||
$fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults);
|
||||
}
|
||||
|
||||
$fieldParams['price_set_id'] = $priceSetId;
|
||||
$fieldParams['is_active'] = 1;
|
||||
$fieldParams['weight'] = 2;
|
||||
|
||||
if (!empty($params['is_allow_other_amount'])) {
|
||||
$fieldParams['is_required'] = 0;
|
||||
}
|
||||
else {
|
||||
$fieldParams['is_required'] = 1;
|
||||
}
|
||||
$fieldParams['label'] = $params['amount_label'];
|
||||
$fieldParams['html_type'] = 'Radio';
|
||||
$fieldParams['option_label'] = $params['label'];
|
||||
$fieldParams['option_amount'] = $params['value'];
|
||||
$fieldParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
|
||||
foreach ($options as $value) {
|
||||
$fieldParams['option_weight'][$value['weight']] = $value['weight'];
|
||||
}
|
||||
$fieldParams['default_option'] = $params['default'];
|
||||
$priceField = CRM_Price_BAO_PriceField::create($fieldParams);
|
||||
}
|
||||
if (!empty($params['is_allow_other_amount']) && empty($params['price_field_other'])) {
|
||||
$editedFieldParams = array(
|
||||
'price_set_id' => $priceSetId,
|
||||
'name' => 'other_amount',
|
||||
);
|
||||
$editedResults = array();
|
||||
|
||||
CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
|
||||
|
||||
if (!$priceFieldID = CRM_Utils_Array::value('id', $editedResults)) {
|
||||
$fieldParams = array(
|
||||
'name' => 'other_amount',
|
||||
'label' => ts('Other Amount'),
|
||||
'price_set_id' => $priceSetId,
|
||||
'html_type' => 'Text',
|
||||
'financial_type_id' => CRM_Utils_Array::value('financial_type_id', $this->_values),
|
||||
'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] = $fieldParams['label'] = $params['amount_label'];
|
||||
}
|
||||
else {
|
||||
$fieldParams['is_required'] = 0;
|
||||
$fieldParams['option_label'][1] = $fieldParams['label'] = ts('Other Amount');
|
||||
}
|
||||
|
||||
$priceField = CRM_Price_BAO_PriceField::create($fieldParams);
|
||||
}
|
||||
else {
|
||||
if (empty($editedResults['is_active'])) {
|
||||
$fieldParams = $editedResults;
|
||||
if (!$noContriAmount) {
|
||||
$priceFieldValueID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldID, 'id', 'price_field_id');
|
||||
CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', $params['amount_label']);
|
||||
$fieldParams = array(
|
||||
'is_required' => 1,
|
||||
'label' => $params['amount_label'],
|
||||
'id' => $priceFieldID,
|
||||
);
|
||||
}
|
||||
$fieldParams['is_active'] = 1;
|
||||
$priceField = CRM_Price_BAO_PriceField::add($fieldParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (empty($params['is_allow_other_amount']) && !empty($params['price_field_other'])) {
|
||||
CRM_Price_BAO_PriceField::setIsActive($params['price_field_other'], '0');
|
||||
}
|
||||
elseif ($priceFieldID = CRM_Utils_Array::value('price_field_other', $params)) {
|
||||
$priceFieldValueID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldID, 'id', 'price_field_id');
|
||||
if (!$noContriAmount) {
|
||||
$fieldParams = array(
|
||||
'is_required' => 1,
|
||||
'label' => $params['amount_label'],
|
||||
'id' => $priceFieldID,
|
||||
);
|
||||
CRM_Price_BAO_PriceField::add($fieldParams);
|
||||
CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', $params['amount_label']);
|
||||
}
|
||||
else {
|
||||
CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceField', $priceFieldID, 'is_required', 0);
|
||||
CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', ts('Other Amount'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($params['is_pledge_active'])) {
|
||||
$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',
|
||||
'pledge_start_date',
|
||||
'is_pledge_start_date_visible',
|
||||
'is_pledge_start_date_editable',
|
||||
);
|
||||
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
|
||||
);
|
||||
$pledgeBlockParams['pledge_start_date'] = CRM_Utils_Array::value('pledge_start_date',
|
||||
$params, FALSE
|
||||
);
|
||||
// create pledge block.
|
||||
CRM_Pledge_BAO_PledgeBlock::create($pledgeBlockParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!empty($params['price_field_id']) || !empty($params['price_field_other'])) {
|
||||
$usedPriceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 3);
|
||||
if ($usedPriceSetId) {
|
||||
if (!empty($params['price_field_id'])) {
|
||||
CRM_Price_BAO_PriceField::setIsActive($params['price_field_id'], '0');
|
||||
}
|
||||
if (!empty($params['price_field_other'])) {
|
||||
CRM_Price_BAO_PriceField::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_PriceSet::removeFrom('civicrm_contribution_page', $contributionPageID);
|
||||
}
|
||||
|
||||
if ($deleteAmountBlk) {
|
||||
$priceField = !empty($params['price_field_id']) ? $params['price_field_id'] : CRM_Utils_Array::value('price_field_other', $params);
|
||||
if ($priceField) {
|
||||
$priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $priceField, 'price_set_id');
|
||||
CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
parent::endPostProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Amounts');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,208 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form to process actions on the group aspect of Custom Data.
|
||||
*/
|
||||
class CRM_Contribute_Form_ContributionPage_Custom extends CRM_Contribute_Form_ContributionPage {
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
|
||||
// Register 'contact_1' model
|
||||
$entities = array();
|
||||
$entities[] = array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel');
|
||||
$allowCoreTypes = array_merge(array('Contact', 'Individual'), CRM_Contact_BAO_ContactType::subTypes('Individual'));
|
||||
$allowSubTypes = array();
|
||||
|
||||
// Register 'contribution_1'
|
||||
$financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'financial_type_id');
|
||||
$allowCoreTypes[] = 'Contribution';
|
||||
//CRM-15427
|
||||
$allowSubTypes['ContributionType'] = array($financialTypeId);
|
||||
$entities[] = array(
|
||||
'entity_name' => 'contribution_1',
|
||||
'entity_type' => 'ContributionModel',
|
||||
'entity_sub_type' => '*',
|
||||
);
|
||||
|
||||
// If applicable, register 'membership_1'
|
||||
$member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id);
|
||||
if ($member && $member['is_active']) {
|
||||
//CRM-15427
|
||||
$entities[] = array(
|
||||
'entity_name' => 'membership_1',
|
||||
'entity_type' => 'MembershipModel',
|
||||
'entity_sub_type' => '*',
|
||||
);
|
||||
$allowCoreTypes[] = 'Membership';
|
||||
$allowSubTypes['MembershipType'] = explode(',', $member['membership_types']);
|
||||
}
|
||||
//CRM-15427
|
||||
$this->addProfileSelector('custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $entities, TRUE);
|
||||
$this->addProfileSelector('custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $entities, TRUE);
|
||||
|
||||
$this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Custom', 'formRule'), $this);
|
||||
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* Note that in edit/view mode the default values are retrieved from the database.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = parent::setDefaultValues();
|
||||
|
||||
$defaults['custom_pre_id'] = $this->_values['custom_pre_id'];
|
||||
$defaults['custom_post_id'] = $this->_values['custom_post_id'];
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// get the submitted form values.
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$params['id'] = $this->_id;
|
||||
}
|
||||
|
||||
$transaction = new CRM_Core_Transaction();
|
||||
|
||||
// also update uf join table
|
||||
$ufJoinParams = array(
|
||||
'is_active' => 1,
|
||||
'module' => 'CiviContribute',
|
||||
'entity_table' => 'civicrm_contribution_page',
|
||||
'entity_id' => $this->_id,
|
||||
);
|
||||
|
||||
// first delete all past entries
|
||||
CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams);
|
||||
|
||||
if (!empty($params['custom_pre_id'])) {
|
||||
$ufJoinParams['weight'] = 1;
|
||||
$ufJoinParams['uf_group_id'] = $params['custom_pre_id'];
|
||||
CRM_Core_BAO_UFJoin::create($ufJoinParams);
|
||||
}
|
||||
|
||||
unset($ufJoinParams['id']);
|
||||
|
||||
if (!empty($params['custom_post_id'])) {
|
||||
$ufJoinParams['weight'] = 2;
|
||||
$ufJoinParams['uf_group_id'] = $params['custom_post_id'];
|
||||
CRM_Core_BAO_UFJoin::create($ufJoinParams);
|
||||
}
|
||||
|
||||
$transaction->commit();
|
||||
parent::endPostProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Include Profiles');
|
||||
}
|
||||
|
||||
/**
|
||||
* Global form rule.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
*
|
||||
* @param $files
|
||||
* @param object $form
|
||||
*
|
||||
* @return bool|array
|
||||
* true if no errors, else array of errors
|
||||
*/
|
||||
public static function formRule($fields, $files, $form) {
|
||||
$errors = array();
|
||||
$preProfileType = $postProfileType = NULL;
|
||||
// for membership profile make sure Membership section is enabled
|
||||
// get membership section for this contribution page
|
||||
$dao = new CRM_Member_DAO_MembershipBlock();
|
||||
$dao->entity_table = 'civicrm_contribution_page';
|
||||
$dao->entity_id = $form->_id;
|
||||
|
||||
$membershipEnable = FALSE;
|
||||
|
||||
if ($dao->find(TRUE) && $dao->is_active) {
|
||||
$membershipEnable = TRUE;
|
||||
}
|
||||
|
||||
if ($fields['custom_pre_id']) {
|
||||
$preProfileType = CRM_Core_BAO_UFField::getProfileType($fields['custom_pre_id']);
|
||||
}
|
||||
|
||||
if ($fields['custom_post_id']) {
|
||||
$postProfileType = CRM_Core_BAO_UFField::getProfileType($fields['custom_post_id']);
|
||||
}
|
||||
|
||||
$errorMsg = ts('You must enable the Membership Block for this Contribution Page if you want to include a Profile with Membership fields.');
|
||||
|
||||
if (($preProfileType == 'Membership') && !$membershipEnable) {
|
||||
$errors['custom_pre_id'] = $errorMsg;
|
||||
}
|
||||
|
||||
if (($postProfileType == 'Membership') && !$membershipEnable) {
|
||||
$errors['custom_post_id'] = $errorMsg;
|
||||
}
|
||||
|
||||
$behalf = (!empty($form->_values['onbehalf_profile_id'])) ? $form->_values['onbehalf_profile_id'] : NULL;
|
||||
if ($fields['custom_pre_id']) {
|
||||
$errorMsg = ts('You should move the membership related fields in the "On Behalf" profile for this Contribution Page');
|
||||
if ($preProfileType == 'Membership' && $behalf) {
|
||||
$errors['custom_pre_id'] = isset($errors['custom_pre_id']) ? $errors['custom_pre_id'] . $errorMsg : $errorMsg;
|
||||
}
|
||||
}
|
||||
|
||||
if ($fields['custom_post_id']) {
|
||||
$errorMsg = ts('You should move the membership related fields in the "On Behalf" profile for this Contribution Page');
|
||||
if ($postProfileType == 'Membership' && $behalf) {
|
||||
$errors['custom_post_id'] = isset($errors['custom_post_id']) ? $errors['custom_post_id'] . $errorMsg : $errorMsg;
|
||||
}
|
||||
}
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is to build the form for Deleting Group.
|
||||
*/
|
||||
class CRM_Contribute_Form_ContributionPage_Delete extends CRM_Contribute_Form_ContributionPage {
|
||||
|
||||
/**
|
||||
* Page title.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_title;
|
||||
|
||||
/**
|
||||
* Check if there are any related contributions.
|
||||
*/
|
||||
protected $_relatedContributions;
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
//Check if there are contributions related to Contribution Page
|
||||
|
||||
parent::preProcess();
|
||||
|
||||
//check for delete
|
||||
if (!CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
}
|
||||
|
||||
$dao = new CRM_Contribute_DAO_Contribution();
|
||||
$dao->contribution_page_id = $this->_id;
|
||||
|
||||
if ($dao->find(TRUE)) {
|
||||
$this->_relatedContributions = TRUE;
|
||||
$this->assign('relatedContributions', TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->_title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title');
|
||||
$this->assign('title', $this->_title);
|
||||
|
||||
//if there are contributions related to Contribution Page
|
||||
//then onle cancel button is displayed
|
||||
$buttons = array();
|
||||
if (!$this->_relatedContributions) {
|
||||
$buttons[] = array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Delete Contribution Page'),
|
||||
'isDefault' => TRUE,
|
||||
);
|
||||
}
|
||||
|
||||
$buttons[] = array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
);
|
||||
|
||||
$this->addButtons($buttons);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form when submitted.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$transaction = new CRM_Core_Transaction();
|
||||
|
||||
// first delete the join entries associated with this contribution page
|
||||
$dao = new CRM_Core_DAO_UFJoin();
|
||||
|
||||
$params = array(
|
||||
'entity_table' => 'civicrm_contribution_page',
|
||||
'entity_id' => $this->_id,
|
||||
);
|
||||
$dao->copyValues($params);
|
||||
$dao->delete();
|
||||
|
||||
//next delete the membership block fields
|
||||
$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
|
||||
$dao = new CRM_PCP_DAO_PCPBlock();
|
||||
$dao->entity_table = 'civicrm_contribution_page';
|
||||
$dao->entity_id = $this->_id;
|
||||
$dao->delete();
|
||||
|
||||
// need to delete premiums. CRM-4586
|
||||
CRM_Contribute_BAO_Premium::deletePremium($this->_id);
|
||||
|
||||
// price set cleanup, CRM-5527
|
||||
CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $this->_id);
|
||||
|
||||
// finally delete the contribution page
|
||||
$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)), ts('Deleted'), 'success');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form to process actions on Premiums.
|
||||
*/
|
||||
class CRM_Contribute_Form_ContributionPage_Premium extends CRM_Contribute_Form_ContributionPage {
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
if (isset($this->_id)) {
|
||||
$dao = new CRM_Contribute_DAO_Premium();
|
||||
$dao->entity_table = 'civicrm_contribution_page';
|
||||
$dao->entity_id = $this->_id;
|
||||
$dao->find(TRUE);
|
||||
CRM_Core_DAO::storeValues($dao, $defaults);
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Premium');
|
||||
$this->addElement('checkbox', 'premiums_active', ts('Premiums Section Enabled?'), NULL);
|
||||
|
||||
$this->addElement('text', 'premiums_intro_title', ts('Title'), $attributes['premiums_intro_title']);
|
||||
|
||||
$this->add('textarea', 'premiums_intro_text', ts('Introductory Message'), 'rows=5, cols=50');
|
||||
|
||||
$this->add('text', 'premiums_contact_email', ts('Contact Email') . ' ', $attributes['premiums_contact_email']);
|
||||
|
||||
$this->addRule('premiums_contact_email', ts('Please enter a valid email address.') . ' ', 'email');
|
||||
|
||||
$this->add('text', 'premiums_contact_phone', ts('Contact Phone'), $attributes['premiums_contact_phone']);
|
||||
|
||||
$this->addRule('premiums_contact_phone', ts('Please enter a valid phone number.'), 'phone');
|
||||
|
||||
$this->addElement('checkbox', 'premiums_display_min_contribution', ts('Display Minimum Contribution Amount?'));
|
||||
|
||||
// CRM-10999 Control label and position for No Thank-you radio button
|
||||
$this->add('text', 'premiums_nothankyou_label', ts('No Thank-you Label'), $attributes['premiums_nothankyou_label']);
|
||||
$positions = array(1 => ts('Before Premiums'), 2 => ts('After Premiums'));
|
||||
$this->add('select', 'premiums_nothankyou_position', ts('No Thank-you Option'), $positions);
|
||||
$showForm = TRUE;
|
||||
|
||||
if ($this->_single) {
|
||||
if ($this->_id) {
|
||||
$daoPremium = new CRM_Contribute_DAO_Premium();
|
||||
$daoPremium->entity_id = $this->_id;
|
||||
$daoPremium->entity_table = 'civicrm_contribution_page';
|
||||
$daoPremium->premiums_active = 1;
|
||||
if ($daoPremium->find(TRUE)) {
|
||||
$showForm = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->assign('showForm', $showForm);
|
||||
|
||||
parent::buildQuickForm();
|
||||
$this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Premium', 'formRule'), $this);
|
||||
|
||||
$premiumPage = new CRM_Contribute_Page_Premium();
|
||||
$premiumPage->browse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation.
|
||||
*
|
||||
* @param array $params
|
||||
* (ref.) an assoc array of name/value pairs.
|
||||
*
|
||||
* @return bool|array
|
||||
* mixed true or array of errors
|
||||
*/
|
||||
public static function formRule($params) {
|
||||
$errors = array();
|
||||
if (!empty($params['premiums_active'])) {
|
||||
if (empty($params['premiums_nothankyou_label'])) {
|
||||
$errors['premiums_nothankyou_label'] = ts('No Thank-you Label is a required field.');
|
||||
}
|
||||
}
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// get the submitted form values.
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
// we do this in case the user has hit the forward/back button
|
||||
|
||||
$dao = new CRM_Contribute_DAO_Premium();
|
||||
$dao->entity_table = 'civicrm_contribution_page';
|
||||
$dao->entity_id = $this->_id;
|
||||
$dao->find(TRUE);
|
||||
$premiumID = $dao->id;
|
||||
if ($premiumID) {
|
||||
$params['id'] = $premiumID;
|
||||
}
|
||||
|
||||
$params['premiums_active'] = CRM_Utils_Array::value('premiums_active', $params, FALSE);
|
||||
$params['premiums_display_min_contribution'] = CRM_Utils_Array::value('premiums_display_min_contribution', $params, FALSE);
|
||||
$params['entity_table'] = 'civicrm_contribution_page';
|
||||
$params['entity_id'] = $this->_id;
|
||||
|
||||
$dao = new CRM_Contribute_DAO_Premium();
|
||||
$dao->copyValues($params);
|
||||
$dao->save();
|
||||
parent::endPostProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Premiums');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,427 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ContributionPage {
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = parent::setDefaultValues();
|
||||
$soft_credit_types = CRM_Core_OptionGroup::values('soft_credit_type', TRUE, FALSE, FALSE, NULL, 'name');
|
||||
|
||||
if ($this->_id) {
|
||||
$title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage',
|
||||
$this->_id,
|
||||
'title'
|
||||
);
|
||||
CRM_Utils_System::setTitle(ts('Title and Settings') . " ($title)");
|
||||
|
||||
foreach (array('on_behalf', 'soft_credit') as $module) {
|
||||
$ufJoinDAO = new CRM_Core_DAO_UFJoin();
|
||||
$ufJoinDAO->module = $module;
|
||||
$ufJoinDAO->entity_id = $this->_id;
|
||||
$ufJoinDAO->entity_table = 'civicrm_contribution_page';
|
||||
if ($ufJoinDAO->find(TRUE)) {
|
||||
$jsonData = CRM_Contribute_BAO_ContributionPage::formatModuleData($ufJoinDAO->module_data, TRUE, $module);
|
||||
if ($module == 'soft_credit') {
|
||||
$defaults['honoree_profile'] = $ufJoinDAO->uf_group_id;
|
||||
$defaults = array_merge($defaults, $jsonData);
|
||||
$defaults['honor_block_is_active'] = $ufJoinDAO->is_active;
|
||||
}
|
||||
else {
|
||||
$defaults['onbehalf_profile_id'] = $ufJoinDAO->uf_group_id;
|
||||
$defaults = array_merge($defaults, $jsonData);
|
||||
$defaults['is_organization'] = $ufJoinDAO->is_active;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($module == 'soft_credit') {
|
||||
$ufGroupDAO = new CRM_Core_DAO_UFGroup();
|
||||
$ufGroupDAO->name = 'honoree_individual';
|
||||
if ($ufGroupDAO->find(TRUE)) {
|
||||
$defaults['honoree_profile'] = $ufGroupDAO->id;
|
||||
}
|
||||
$defaults['soft_credit_types'] = array(
|
||||
CRM_Utils_Array::value('in_honor_of', $soft_credit_types),
|
||||
CRM_Utils_Array::value('in_memory_of', $soft_credit_types),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$ufGroupDAO = new CRM_Core_DAO_UFGroup();
|
||||
$ufGroupDAO->name = 'on_behalf_organization';
|
||||
if ($ufGroupDAO->find(TRUE)) {
|
||||
$defaults['onbehalf_profile_id'] = $ufGroupDAO->id;
|
||||
}
|
||||
$defaults['for_organization'] = ts('I am contributing on behalf of an organization.');
|
||||
$defaults['is_for_organization'] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$ufGroupDAO = new CRM_Core_DAO_UFGroup();
|
||||
$ufGroupDAO->name = 'honoree_individual';
|
||||
if ($ufGroupDAO->find(TRUE)) {
|
||||
$defaults['honoree_profile'] = $ufGroupDAO->id;
|
||||
}
|
||||
$defaults['soft_credit_types'] = array(
|
||||
CRM_Utils_Array::value('in_honor_of', $soft_credit_types),
|
||||
CRM_Utils_Array::value('in_memory_of', $soft_credit_types),
|
||||
);
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
|
||||
$this->_first = TRUE;
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage');
|
||||
|
||||
// financial Type
|
||||
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, CRM_Core_Action::ADD);
|
||||
$financialOptions = array(
|
||||
'options' => $financialTypes,
|
||||
);
|
||||
if (!CRM_Core_Permission::check('administer CiviCRM Financial Types')) {
|
||||
$financialOptions['context'] = 'search';
|
||||
}
|
||||
$this->addSelect('financial_type_id', $financialOptions, TRUE);
|
||||
|
||||
// name
|
||||
$this->add('text', 'title', ts('Title'), $attributes['title'], TRUE);
|
||||
|
||||
//CRM-7362 --add campaigns.
|
||||
CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
|
||||
|
||||
$this->add('wysiwyg', 'intro_text', ts('Introductory Message'), $attributes['intro_text']);
|
||||
|
||||
$this->add('wysiwyg', 'footer_text', ts('Footer Message'), $attributes['footer_text']);
|
||||
|
||||
//Register schema which will be used for OnBehalOf and HonorOf profile Selector
|
||||
CRM_UF_Page_ProfileEditor::registerSchemas(array('OrganizationModel', 'HouseholdModel'));
|
||||
|
||||
// is on behalf of an organization ?
|
||||
$this->addElement('checkbox', 'is_organization', ts('Allow individuals to contribute and / or signup for membership on behalf of an organization?'), NULL, array('onclick' => "showHideByValue('is_organization',true,'for_org_text','table-row','radio',false);showHideByValue('is_organization',true,'for_org_option','table-row','radio',false);"));
|
||||
|
||||
//CRM-15787 - If applicable, register 'membership_1'
|
||||
$member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id);
|
||||
$coreTypes = array('Contact', 'Organization');
|
||||
|
||||
$entities[] = array(
|
||||
'entity_name' => array('contact_1'),
|
||||
'entity_type' => 'OrganizationModel',
|
||||
);
|
||||
|
||||
if ($member && $member['is_active']) {
|
||||
$coreTypes[] = 'Membership';
|
||||
$entities[] = array(
|
||||
'entity_name' => array('membership_1'),
|
||||
'entity_type' => 'MembershipModel',
|
||||
);
|
||||
}
|
||||
|
||||
$allowCoreTypes = array_merge($coreTypes, CRM_Contact_BAO_ContactType::subTypes('Organization'));
|
||||
$allowSubTypes = array();
|
||||
|
||||
$this->addProfileSelector('onbehalf_profile_id', ts('Organization Profile'), $allowCoreTypes, $allowSubTypes, $entities);
|
||||
|
||||
$options = array();
|
||||
$options[] = $this->createElement('radio', NULL, NULL, ts('Optional'), 1);
|
||||
$options[] = $this->createElement('radio', NULL, NULL, ts('Required'), 2);
|
||||
$this->addGroup($options, 'is_for_organization', '');
|
||||
$this->add('textarea', 'for_organization', ts('On behalf of Label'), array('rows' => 2, 'cols' => 50));
|
||||
|
||||
// collect goal amount
|
||||
$this->add('text', 'goal_amount', ts('Goal Amount'), array('size' => 8, 'maxlength' => 12));
|
||||
$this->addRule('goal_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
|
||||
|
||||
// is confirmation page enabled?
|
||||
$this->addElement('checkbox', 'is_confirm_enabled', ts('Use a confirmation page?'));
|
||||
|
||||
// is this page shareable through social media ?
|
||||
$this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?'));
|
||||
|
||||
// is this page active ?
|
||||
$this->addElement('checkbox', 'is_active', ts('Is this Online Contribution Page Active?'));
|
||||
|
||||
// should the honor be enabled
|
||||
$this->addElement('checkbox', 'honor_block_is_active', ts('Honoree Section Enabled'), NULL, array('onclick' => "showHonor()"));
|
||||
|
||||
$this->add('text', 'honor_block_title', ts('Honoree Section Title'), array('maxlength' => 255, 'size' => 45));
|
||||
|
||||
$this->add('textarea', 'honor_block_text', ts('Honoree Introductory Message'), array('rows' => 2, 'cols' => 50));
|
||||
|
||||
$this->addSelect('soft_credit_types', array(
|
||||
'label' => ts('Honor Types'),
|
||||
'entity' => 'ContributionSoft',
|
||||
'field' => 'soft_credit_type_id',
|
||||
'multiple' => TRUE,
|
||||
'class' => 'huge',
|
||||
));
|
||||
|
||||
$entities = array(
|
||||
array(
|
||||
'entity_name' => 'contact_1',
|
||||
'entity_type' => 'IndividualModel',
|
||||
),
|
||||
);
|
||||
|
||||
$allowCoreTypes = array_merge(array(
|
||||
'Contact',
|
||||
'Individual',
|
||||
'Organization',
|
||||
'Household',
|
||||
), CRM_Contact_BAO_ContactType::subTypes('Individual'));
|
||||
$allowSubTypes = array();
|
||||
|
||||
$this->addProfileSelector('honoree_profile', ts('Honoree Profile'), $allowCoreTypes, $allowSubTypes, $entities);
|
||||
|
||||
if (!empty($this->_submitValues['honor_block_is_active'])) {
|
||||
$this->addRule('soft_credit_types', ts('At least one value must be selected if Honor Section is active'), 'required');
|
||||
$this->addRule('honoree_profile', ts('Please select a profile used for honoree'), 'required');
|
||||
}
|
||||
|
||||
// add optional start and end dates
|
||||
$this->addDateTime('start_date', ts('Start Date'));
|
||||
$this->addDateTime('end_date', ts('End Date'));
|
||||
|
||||
$this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Settings', 'formRule'), $this);
|
||||
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $values
|
||||
* Posted values of the form.
|
||||
*
|
||||
* @param $files
|
||||
* @param $self
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($values, $files, $self) {
|
||||
$errors = array();
|
||||
$contributionPageId = $self->_id;
|
||||
//CRM-4286
|
||||
if (strstr($values['title'], '/')) {
|
||||
$errors['title'] = ts("Please do not use '/' in Title");
|
||||
}
|
||||
|
||||
// ensure on-behalf-of profile meets minimum requirements
|
||||
if (!empty($values['is_organization'])) {
|
||||
if (empty($values['onbehalf_profile_id'])) {
|
||||
$errors['onbehalf_profile_id'] = ts('Please select a profile to collect organization information on this contribution page.');
|
||||
}
|
||||
else {
|
||||
$requiredProfileFields = array('organization_name', 'email');
|
||||
if (!CRM_Core_BAO_UFGroup::checkValidProfile($values['onbehalf_profile_id'], $requiredProfileFields)) {
|
||||
$errors['onbehalf_profile_id'] = ts('Profile does not contain the minimum required fields for an On Behalf Of Organization');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//CRM-11494
|
||||
$start = CRM_Utils_Date::processDate($values['start_date']);
|
||||
$end = CRM_Utils_Date::processDate($values['end_date']);
|
||||
if (($end < $start) && ($end != 0)) {
|
||||
$errors['end_date'] = ts('End date should be after Start date.');
|
||||
}
|
||||
|
||||
if (!empty($self->_values['payment_processor']) && $financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($values['financial_type_id'])) {
|
||||
$errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
|
||||
}
|
||||
|
||||
//dont allow on behalf of save when
|
||||
//pre or post profile consists of membership fields
|
||||
if ($contributionPageId && !empty($values['is_organization'])) {
|
||||
$ufJoinParams = array(
|
||||
'module' => 'CiviContribute',
|
||||
'entity_table' => 'civicrm_contribution_page',
|
||||
'entity_id' => $contributionPageId,
|
||||
);
|
||||
|
||||
list($contributionProfiles['custom_pre_id'],
|
||||
$contributionProfiles['custom_post_id']
|
||||
) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
|
||||
|
||||
$conProfileType = NULL;
|
||||
if ($contributionProfiles['custom_pre_id']) {
|
||||
$preProfileType = CRM_Core_BAO_UFField::getProfileType($contributionProfiles['custom_pre_id']);
|
||||
if ($preProfileType == 'Membership') {
|
||||
$conProfileType = "'Includes Profile (top of page)'";
|
||||
}
|
||||
}
|
||||
|
||||
if ($contributionProfiles['custom_post_id']) {
|
||||
$postProfileType = CRM_Core_BAO_UFField::getProfileType($contributionProfiles['custom_post_id']);
|
||||
if ($postProfileType == 'Membership') {
|
||||
$conProfileType = empty($conProfileType) ? "'Includes Profile (bottom of page)'" : "{$conProfileType} and 'Includes Profile (bottom of page)'";
|
||||
}
|
||||
}
|
||||
if (!empty($conProfileType)) {
|
||||
$errors['is_organization'] = ts("You should move the membership related fields configured in %1 to the 'On Behalf' profile for this Contribution Page", array(1 => $conProfileType));
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// get the submitted form values.
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
// we do this in case the user has hit the forward/back button
|
||||
if ($this->_id) {
|
||||
$params['id'] = $this->_id;
|
||||
}
|
||||
else {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$params['created_id'] = $session->get('userID');
|
||||
$params['created_date'] = date('YmdHis');
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$params['currency'] = $config->defaultCurrency;
|
||||
}
|
||||
|
||||
$params['is_confirm_enabled'] = CRM_Utils_Array::value('is_confirm_enabled', $params, FALSE);
|
||||
$params['is_share'] = CRM_Utils_Array::value('is_share', $params, FALSE);
|
||||
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
|
||||
$params['is_credit_card_only'] = CRM_Utils_Array::value('is_credit_card_only', $params, FALSE);
|
||||
$params['honor_block_is_active'] = CRM_Utils_Array::value('honor_block_is_active', $params, FALSE);
|
||||
$params['is_for_organization'] = !empty($params['is_organization']) ? CRM_Utils_Array::value('is_for_organization', $params, FALSE) : 0;
|
||||
|
||||
$params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time'], TRUE);
|
||||
$params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], $params['end_date_time'], TRUE);
|
||||
|
||||
$params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']);
|
||||
|
||||
if (!$params['honor_block_is_active']) {
|
||||
$params['honor_block_title'] = NULL;
|
||||
$params['honor_block_text'] = NULL;
|
||||
}
|
||||
|
||||
$dao = CRM_Contribute_BAO_ContributionPage::create($params);
|
||||
|
||||
$ufJoinParams = array(
|
||||
'is_organization' => array(
|
||||
'module' => 'on_behalf',
|
||||
'entity_table' => 'civicrm_contribution_page',
|
||||
'entity_id' => $dao->id,
|
||||
),
|
||||
'honor_block_is_active' => array(
|
||||
'module' => 'soft_credit',
|
||||
'entity_table' => 'civicrm_contribution_page',
|
||||
'entity_id' => $dao->id,
|
||||
),
|
||||
);
|
||||
|
||||
foreach ($ufJoinParams as $index => $ufJoinParam) {
|
||||
if (!empty($params[$index])) {
|
||||
// first delete all past entries
|
||||
CRM_Core_BAO_UFJoin::deleteAll($ufJoinParam);
|
||||
$ufJoinParam['uf_group_id'] = $params[$index];
|
||||
$ufJoinParam['weight'] = 1;
|
||||
$ufJoinParam['is_active'] = 1;
|
||||
if ($index == 'honor_block_is_active') {
|
||||
$ufJoinParam['uf_group_id'] = $params['honoree_profile'];
|
||||
$ufJoinParam['module_data'] = CRM_Contribute_BAO_ContributionPage::formatModuleData($params, FALSE, 'soft_credit');
|
||||
}
|
||||
else {
|
||||
$ufJoinParam['uf_group_id'] = $params['onbehalf_profile_id'];
|
||||
$ufJoinParam['module_data'] = CRM_Contribute_BAO_ContributionPage::formatModuleData($params, FALSE, 'on_behalf');
|
||||
}
|
||||
CRM_Core_BAO_UFJoin::create($ufJoinParam);
|
||||
}
|
||||
else {
|
||||
if ($index == 'honor_block_is_active') {
|
||||
$params['honor_block_title'] = NULL;
|
||||
$params['honor_block_text'] = NULL;
|
||||
}
|
||||
else {
|
||||
$params['for_organization'] = NULL;
|
||||
}
|
||||
|
||||
//On subsequent honor_block_is_active uncheck, disable(don't delete)
|
||||
//that particular honoree profile entry in UFjoin table, CRM-13981
|
||||
$ufId = CRM_Core_BAO_UFJoin::findJoinEntryId($ufJoinParam);
|
||||
if ($ufId) {
|
||||
$ufJoinParam['uf_group_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParam);
|
||||
$ufJoinParam['is_active'] = 0;
|
||||
CRM_Core_BAO_UFJoin::create($ufJoinParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->set('id', $dao->id);
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
$url = 'civicrm/admin/contribute/amount';
|
||||
$urlParams = "action=update&reset=1&id={$dao->id}";
|
||||
// special case for 'Save and Done' consistency.
|
||||
if ($this->controller->getButtonName('submit') == '_qf_Amount_upload_done') {
|
||||
$url = 'civicrm/admin/contribute';
|
||||
$urlParams = 'reset=1';
|
||||
CRM_Core_Session::setStatus(ts("'%1' information has been saved.",
|
||||
array(1 => $this->getTitle())
|
||||
), ts('Saved'), 'success');
|
||||
}
|
||||
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams));
|
||||
}
|
||||
parent::endPostProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Title and Settings');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,224 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper class to build navigation links.
|
||||
*/
|
||||
class CRM_Contribute_Form_ContributionPage_TabHeader {
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function build(&$form) {
|
||||
$tabs = $form->get('tabHeader');
|
||||
if (!$tabs || empty($_GET['reset'])) {
|
||||
$tabs = self::process($form);
|
||||
$form->set('tabHeader', $tabs);
|
||||
}
|
||||
$form->assign_by_ref('tabHeader', $tabs);
|
||||
CRM_Core_Resources::singleton()
|
||||
->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
|
||||
->addSetting(array(
|
||||
'tabSettings' => array(
|
||||
'active' => self::getCurrentTab($tabs),
|
||||
),
|
||||
));
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function process(&$form) {
|
||||
if ($form->getVar('_id') <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$tabs = array(
|
||||
'settings' => array(
|
||||
'title' => ts('Title'),
|
||||
'link' => NULL,
|
||||
'valid' => FALSE,
|
||||
'active' => FALSE,
|
||||
'current' => FALSE,
|
||||
),
|
||||
'amount' => array(
|
||||
'title' => ts('Amounts'),
|
||||
'link' => NULL,
|
||||
'valid' => FALSE,
|
||||
'active' => FALSE,
|
||||
'current' => FALSE,
|
||||
),
|
||||
'membership' => array(
|
||||
'title' => ts('Memberships'),
|
||||
'link' => NULL,
|
||||
'valid' => FALSE,
|
||||
'active' => FALSE,
|
||||
'current' => FALSE,
|
||||
),
|
||||
'thankyou' => array(
|
||||
'title' => ts('Receipt'),
|
||||
'link' => NULL,
|
||||
'valid' => FALSE,
|
||||
'active' => FALSE,
|
||||
'current' => FALSE,
|
||||
),
|
||||
'friend' => array(
|
||||
'title' => ts('Tell a Friend'),
|
||||
'link' => NULL,
|
||||
'valid' => FALSE,
|
||||
'active' => FALSE,
|
||||
'current' => FALSE,
|
||||
),
|
||||
'custom' => array(
|
||||
'title' => ts('Profiles'),
|
||||
'link' => NULL,
|
||||
'valid' => FALSE,
|
||||
'active' => FALSE,
|
||||
'current' => FALSE,
|
||||
),
|
||||
'premium' => array(
|
||||
'title' => ts('Premiums'),
|
||||
'link' => NULL,
|
||||
'valid' => FALSE,
|
||||
'active' => FALSE,
|
||||
'current' => FALSE,
|
||||
),
|
||||
'widget' => array(
|
||||
'title' => ts('Widgets'),
|
||||
'link' => NULL,
|
||||
'valid' => FALSE,
|
||||
'active' => FALSE,
|
||||
'current' => FALSE,
|
||||
),
|
||||
'pcp' => array(
|
||||
'title' => ts('Personal Campaigns'),
|
||||
'link' => NULL,
|
||||
'valid' => FALSE,
|
||||
'active' => FALSE,
|
||||
'current' => FALSE,
|
||||
),
|
||||
);
|
||||
|
||||
$contribPageId = $form->getVar('_id');
|
||||
CRM_Utils_Hook::tabset('civicrm/admin/contribute', $tabs, array('contribution_page_id' => $contribPageId));
|
||||
$fullName = $form->getVar('_name');
|
||||
$className = CRM_Utils_String::getClassName($fullName);
|
||||
|
||||
// Hack for special cases.
|
||||
switch ($className) {
|
||||
case 'Contribute':
|
||||
$attributes = $form->getVar('_attributes');
|
||||
$class = strtolower(basename(CRM_Utils_Array::value('action', $attributes)));
|
||||
break;
|
||||
|
||||
case 'MembershipBlock':
|
||||
$class = 'membership';
|
||||
break;
|
||||
|
||||
default:
|
||||
$class = strtolower($className);
|
||||
break;
|
||||
}
|
||||
|
||||
if (array_key_exists($class, $tabs)) {
|
||||
$tabs[$class]['current'] = TRUE;
|
||||
$qfKey = $form->get('qfKey');
|
||||
if ($qfKey) {
|
||||
$tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
|
||||
}
|
||||
}
|
||||
|
||||
if ($contribPageId) {
|
||||
$reset = !empty($_GET['reset']) ? 'reset=1&' : '';
|
||||
|
||||
foreach ($tabs as $key => $value) {
|
||||
if (!isset($tabs[$key]['qfKey'])) {
|
||||
$tabs[$key]['qfKey'] = NULL;
|
||||
}
|
||||
|
||||
$tabs[$key]['link'] = CRM_Utils_System::url(
|
||||
"civicrm/admin/contribute/{$key}",
|
||||
"{$reset}action=update&id={$contribPageId}{$tabs[$key]['qfKey']}"
|
||||
);
|
||||
$tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE;
|
||||
}
|
||||
//get all section info.
|
||||
$contriPageInfo = CRM_Contribute_BAO_ContributionPage::getSectionInfo(array($contribPageId));
|
||||
|
||||
foreach ($contriPageInfo[$contribPageId] as $section => $info) {
|
||||
if (!$info) {
|
||||
$tabs[$section]['valid'] = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $form
|
||||
*/
|
||||
public static function reset(&$form) {
|
||||
$tabs = self::process($form);
|
||||
$form->set('tabHeader', $tabs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $tabs
|
||||
*
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getCurrentTab($tabs) {
|
||||
static $current = FALSE;
|
||||
|
||||
if ($current) {
|
||||
return $current;
|
||||
}
|
||||
|
||||
if (is_array($tabs)) {
|
||||
foreach ($tabs as $subPage => $pageVal) {
|
||||
if ($pageVal['current'] === TRUE) {
|
||||
$current = $subPage;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$current = $current ? $current : 'settings';
|
||||
return $current;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form to configure thank-you messages and receipting features for an online contribution page.
|
||||
*/
|
||||
class CRM_Contribute_Form_ContributionPage_ThankYou extends CRM_Contribute_Form_ContributionPage {
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* Note that in edit/view mode the default values are retrieved from the database.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
return parent::setDefaultValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->registerRule('emailList', 'callback', 'emailList', 'CRM_Utils_Rule');
|
||||
|
||||
// thank you title and text (html allowed in text)
|
||||
$this->add('text', 'thankyou_title', ts('Thank-you Page Title'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'thankyou_title'), TRUE);
|
||||
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'thankyou_text') + array('class' => 'collapsed');
|
||||
$this->add('wysiwyg', 'thankyou_text', ts('Thank-you Message'), $attributes);
|
||||
$this->add('wysiwyg', 'thankyou_footer', ts('Thank-you Footer'), $attributes);
|
||||
|
||||
$this->addElement('checkbox', 'is_email_receipt', ts('Email Receipt to Contributor?'), NULL, array('onclick' => "showReceipt()"));
|
||||
$this->add('text', 'receipt_from_name', ts('Receipt From Name'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'receipt_from_name'));
|
||||
$this->add('text', 'receipt_from_email', ts('Receipt From Email'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'receipt_from_email'));
|
||||
$this->add('textarea', 'receipt_text', ts('Receipt Message'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'receipt_text'));
|
||||
|
||||
$this->add('text', 'cc_receipt', ts('CC Receipt To'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'cc_receipt'));
|
||||
$this->addRule('cc_receipt', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
|
||||
|
||||
$this->add('text', 'bcc_receipt', ts('BCC Receipt To'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage', 'bcc_receipt'));
|
||||
$this->addRule('bcc_receipt', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
|
||||
|
||||
parent::buildQuickForm();
|
||||
$this->addFormRule(array('CRM_Contribute_Form_ContributionPage_ThankYou', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global form rule.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
* @param array $files
|
||||
* The uploaded files if any.
|
||||
* @param array $options
|
||||
* Additional user data.
|
||||
*
|
||||
* @return bool|array
|
||||
* true if no errors, else array of errors
|
||||
*/
|
||||
public static function formRule($fields, $files, $options) {
|
||||
$errors = array();
|
||||
|
||||
// if is_email_receipt is set, the receipt message must be non-empty
|
||||
if (!empty($fields['is_email_receipt'])) {
|
||||
//added for CRM-1348
|
||||
$email = trim(CRM_Utils_Array::value('receipt_from_email', $fields));
|
||||
if (empty($email) || !CRM_Utils_Rule::email($email)) {
|
||||
$errors['receipt_from_email'] = ts('A valid Receipt From Email address must be specified if Email Receipt to Contributor is enabled');
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// get the submitted form values.
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
$params['id'] = $this->_id;
|
||||
$params['is_email_receipt'] = CRM_Utils_Array::value('is_email_receipt', $params, FALSE);
|
||||
if (!$params['is_email_receipt']) {
|
||||
$params['receipt_from_name'] = NULL;
|
||||
$params['receipt_from_email'] = NULL;
|
||||
$params['receipt_text'] = NULL;
|
||||
$params['cc_receipt'] = NULL;
|
||||
$params['bcc_receipt'] = NULL;
|
||||
}
|
||||
|
||||
$dao = CRM_Contribute_BAO_ContributionPage::create($params);
|
||||
parent::endPostProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Thanks and Receipt');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,279 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Contribute_Form_ContributionPage_Widget extends CRM_Contribute_Form_ContributionPage {
|
||||
protected $_colors;
|
||||
|
||||
protected $_widget;
|
||||
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
$this->_widget = new CRM_Contribute_DAO_Widget();
|
||||
$this->_widget->contribution_page_id = $this->_id;
|
||||
if (!$this->_widget->find(TRUE)) {
|
||||
$this->_widget = NULL;
|
||||
}
|
||||
else {
|
||||
$this->assign('widget_id', $this->_widget->id);
|
||||
|
||||
// check of home url is set, if set then it flash widget might be in use.
|
||||
$this->assign('showStatus', FALSE);
|
||||
if ($this->_widget->url_homepage) {
|
||||
$this->assign('showStatus', TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('cpageId', $this->_id);
|
||||
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage',
|
||||
$this->_id,
|
||||
'title'
|
||||
);
|
||||
|
||||
$this->_fields = array(
|
||||
'title' => array(
|
||||
ts('Title'),
|
||||
'text',
|
||||
FALSE,
|
||||
$title,
|
||||
),
|
||||
'url_logo' => array(
|
||||
ts('URL to Logo Image'),
|
||||
'text',
|
||||
FALSE,
|
||||
NULL,
|
||||
),
|
||||
'button_title' => array(
|
||||
ts('Button Title'),
|
||||
'text',
|
||||
FALSE,
|
||||
ts('Contribute!'),
|
||||
),
|
||||
);
|
||||
|
||||
$this->_colorFields = array(
|
||||
'color_title' => array(
|
||||
ts('Title Text Color'),
|
||||
'text',
|
||||
FALSE,
|
||||
'#2786C2',
|
||||
),
|
||||
'color_bar' => array(
|
||||
ts('Progress Bar Color'),
|
||||
'text',
|
||||
FALSE,
|
||||
'#2786C2',
|
||||
),
|
||||
'color_main_text' => array(
|
||||
ts('Additional Text Color'),
|
||||
'text',
|
||||
FALSE,
|
||||
'#FFFFFF',
|
||||
),
|
||||
'color_main' => array(
|
||||
ts('Background Color'),
|
||||
'text',
|
||||
FALSE,
|
||||
'#96C0E7',
|
||||
),
|
||||
'color_main_bg' => array(
|
||||
ts('Background Color Top Area'),
|
||||
'text',
|
||||
FALSE,
|
||||
'#B7E2FF',
|
||||
),
|
||||
'color_bg' => array(
|
||||
ts('Border Color'),
|
||||
'text',
|
||||
FALSE,
|
||||
'#96C0E7',
|
||||
),
|
||||
'color_about_link' => array(
|
||||
ts('Button Text Color'),
|
||||
'text',
|
||||
FALSE,
|
||||
'#556C82',
|
||||
),
|
||||
'color_button' => array(
|
||||
ts('Button Background Color'),
|
||||
'text',
|
||||
FALSE,
|
||||
'#FFFFFF',
|
||||
),
|
||||
'color_homepage_link' => array(
|
||||
ts('Homepage Link Color'),
|
||||
'text',
|
||||
FALSE,
|
||||
'#FFFFFF',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
// check if there is a widget already created
|
||||
if ($this->_widget) {
|
||||
CRM_Core_DAO::storeValues($this->_widget, $defaults);
|
||||
}
|
||||
else {
|
||||
foreach ($this->_fields as $name => $val) {
|
||||
$defaults[$name] = $val[3];
|
||||
}
|
||||
foreach ($this->_colorFields as $name => $val) {
|
||||
$defaults[$name] = $val[3];
|
||||
}
|
||||
$defaults['about'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage',
|
||||
$this->_id,
|
||||
'intro_text'
|
||||
);
|
||||
}
|
||||
|
||||
$showHide = new CRM_Core_ShowHideBlocks();
|
||||
$showHide->addHide('id-colors');
|
||||
$showHide->addToTemplate();
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
public function buildQuickForm() {
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Widget');
|
||||
|
||||
$this->addElement('checkbox',
|
||||
'is_active',
|
||||
ts('Enable Widget?'),
|
||||
NULL,
|
||||
array('onclick' => "widgetBlock(this)")
|
||||
);
|
||||
|
||||
$this->add('wysiwyg', 'about', ts('About'), $attributes['about']);
|
||||
|
||||
foreach ($this->_fields as $name => $val) {
|
||||
$this->add($val[1],
|
||||
$name,
|
||||
$val[0],
|
||||
$attributes[$name],
|
||||
$val[2]
|
||||
);
|
||||
}
|
||||
foreach ($this->_colorFields as $name => $val) {
|
||||
$this->add($val[1],
|
||||
$name,
|
||||
$val[0],
|
||||
$attributes[$name],
|
||||
$val[2]
|
||||
);
|
||||
}
|
||||
|
||||
$this->assign_by_ref('fields', $this->_fields);
|
||||
$this->assign_by_ref('colorFields', $this->_colorFields);
|
||||
|
||||
$this->_refreshButtonName = $this->getButtonName('refresh');
|
||||
$this->addElement('submit',
|
||||
$this->_refreshButtonName,
|
||||
ts('Save and Preview')
|
||||
);
|
||||
parent::buildQuickForm();
|
||||
$this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Widget', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation.
|
||||
*
|
||||
* @param array $params
|
||||
* (ref.) an assoc array of name/value pairs.
|
||||
*
|
||||
* @param $files
|
||||
* @param $self
|
||||
*
|
||||
* @return bool|array
|
||||
* mixed true or array of errors
|
||||
*/
|
||||
public static function formRule($params, $files, $self) {
|
||||
$errors = array();
|
||||
if (!empty($params['is_active'])) {
|
||||
if (empty($params['title'])) {
|
||||
$errors['title'] = ts('Title is a required field.');
|
||||
}
|
||||
if (empty($params['about'])) {
|
||||
$errors['about'] = ts('About is a required field.');
|
||||
}
|
||||
|
||||
foreach ($params as $key => $val) {
|
||||
if (substr($key, 0, 6) == 'color_' && empty($params[$key])) {
|
||||
$errors[$key] = ts('%1 is a required field.', array(1 => $self->_colorFields[$key][0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
public function postProcess() {
|
||||
//to reset quickform elements of next (pcp) page.
|
||||
if ($this->controller->getNextName('Widget') == 'PCP') {
|
||||
$this->controller->resetPage('PCP');
|
||||
}
|
||||
|
||||
// get the submitted form values.
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
if ($this->_widget) {
|
||||
$params['id'] = $this->_widget->id;
|
||||
}
|
||||
$params['contribution_page_id'] = $this->_id;
|
||||
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
|
||||
$params['url_homepage'] = 'null';
|
||||
|
||||
$widget = new CRM_Contribute_DAO_Widget();
|
||||
$widget->copyValues($params);
|
||||
$widget->save();
|
||||
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
if ($buttonName == $this->_refreshButtonName) {
|
||||
return;
|
||||
}
|
||||
parent::endPostProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Widget Settings');
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue