From 09fbb309d749fed05577ddce0f08ce797d089488 Mon Sep 17 00:00:00 2001 From: yashodha Date: Wed, 4 Apr 2018 14:46:38 +0530 Subject: [PATCH] CRM-21854 - Contribution start date and end dates are not respected --- .../FutureContributionPageException.php | 25 +++++++++++++++++++ .../PastContributionPageException.php | 25 +++++++++++++++++++ CRM/Contribute/Form/ContributionBase.php | 4 +-- CRM/Contribute/Form/ContributionPage.php | 10 +------- .../Form/ContributionPage/Settings.php | 8 ++---- .../Form/ContributionPage/Settings.tpl | 8 ++---- 6 files changed, 57 insertions(+), 23 deletions(-) create mode 100644 CRM/Contribute/Exception/FutureContributionPageException.php create mode 100644 CRM/Contribute/Exception/PastContributionPageException.php diff --git a/CRM/Contribute/Exception/FutureContributionPageException.php b/CRM/Contribute/Exception/FutureContributionPageException.php new file mode 100644 index 0000000000..5deeb178f4 --- /dev/null +++ b/CRM/Contribute/Exception/FutureContributionPageException.php @@ -0,0 +1,25 @@ +id = $id; + CRM_Core_Error::debug_log_message('Access to contribution page with start date in future attempted - page number ' . $id); + } + + /** + * Get Contribution page ID. + * + * @return int + */ + public function getID() { + return $this->id; + } + +} diff --git a/CRM/Contribute/Exception/PastContributionPageException.php b/CRM/Contribute/Exception/PastContributionPageException.php new file mode 100644 index 0000000000..fc7c8b3182 --- /dev/null +++ b/CRM/Contribute/Exception/PastContributionPageException.php @@ -0,0 +1,25 @@ +id = $id; + CRM_Core_Error::debug_log_message('Access to contribution page with past end date attempted - page number ' . $id); + } + + /** + * Get Contribution page ID. + * + * @return int + */ + public function getID() { + return $this->id; + } + +} diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index df82cb3042..3167a5665e 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -316,12 +316,12 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { $endDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('end_date', $this->_values)); $now = date('YmdHis'); if ($endDate && $endDate < $now) { - throw new Exception(ts('The page you requested has past its end date on '. CRM_Utils_Date::customFormat($endDate) ), $this->_id); + throw new CRM_Contribute_Exception_PastContributionPageException(ts('The page you requested has past its end date on '. CRM_Utils_Date::customFormat($endDate) ), $this->_id); } $startDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('start_date', $this->_values)); if ($startDate && $startDate > $now) { - throw new Exception(ts('The page you requested will be active from '. CRM_Utils_Date::customFormat($startDate)), $this->_id); + throw new CRM_Contribute_Exception_FutureContributionPageException(ts('The page you requested will be active from '. CRM_Utils_Date::customFormat($startDate)), $this->_id); } $this->assignBillingType(); diff --git a/CRM/Contribute/Form/ContributionPage.php b/CRM/Contribute/Form/ContributionPage.php index 138e98bb41..dd3ebd52b8 100644 --- a/CRM/Contribute/Form/ContributionPage.php +++ b/CRM/Contribute/Form/ContributionPage.php @@ -332,14 +332,6 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form { if ($this->_priceSetID) { $defaults['price_set_id'] = $this->_priceSetID; } - - if (!empty($defaults['end_date'])) { - list($defaults['end_date'], $defaults['end_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['end_date']); - } - - if (!empty($defaults['start_date'])) { - list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['start_date']); - } } else { $defaults['is_active'] = 1; @@ -353,7 +345,7 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form { ), '1'); } else { - # CRM 10860 + // CRM-10860 $defaults['recur_frequency_unit'] = array('month' => 1); } diff --git a/CRM/Contribute/Form/ContributionPage/Settings.php b/CRM/Contribute/Form/ContributionPage/Settings.php index a69e654ad2..7e3d96136c 100644 --- a/CRM/Contribute/Form/ContributionPage/Settings.php +++ b/CRM/Contribute/Form/ContributionPage/Settings.php @@ -223,8 +223,8 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ } // add optional start and end dates - $this->addDateTime('start_date', ts('Start Date')); - $this->addDateTime('end_date', ts('End Date')); + $this->add('datepicker', 'start_date', ts('Start Date')); + $this->add('datepicker', 'end_date', ts('End Date')); $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Settings', 'formRule'), $this); @@ -334,10 +334,6 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ $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']) { diff --git a/templates/CRM/Contribute/Form/ContributionPage/Settings.tpl b/templates/CRM/Contribute/Form/ContributionPage/Settings.tpl index eb85deaa44..ac35f62903 100644 --- a/templates/CRM/Contribute/Form/ContributionPage/Settings.tpl +++ b/templates/CRM/Contribute/Form/ContributionPage/Settings.tpl @@ -95,15 +95,11 @@ {$form.start_date.label} {help id="id-start_date"} - - {include file="CRM/common/jcalendar.tpl" elementName=start_date} - + {$form.start_date.html} {$form.end_date.label} - - {include file="CRM/common/jcalendar.tpl" elementName=end_date} - + {$form.end_date.html}  {$form.honor_block_is_active.html}{$form.honor_block_is_active.label} {help id="id-honoree_section"} -- 2.25.1