From fcc69847d167aab1d3c40a094a6ca1a21147055a Mon Sep 17 00:00:00 2001 From: wyrie <wyrie@ispconfig3> Date: Thu, 17 Dec 2009 05:55:52 -0500 Subject: [PATCH] Implemented: FS#1003 - Autoresponder: Start and end date (Interface) --- interface/web/mail/lib/lang/en_mail_user.lng | 6 + interface/lib/classes/validate_datetime.inc.php | 138 ++++++++++++++++++++++++++++++++++ interface/lib/lang/en.lng | 1 interface/lib/classes/validate_autoresponder.inc.php | 59 ++++++++++++++ 4 files changed, 203 insertions(+), 1 deletions(-) diff --git a/interface/lib/classes/validate_autoresponder.inc.php b/interface/lib/classes/validate_autoresponder.inc.php new file mode 100755 index 0000000..c8db6a9 --- /dev/null +++ b/interface/lib/classes/validate_autoresponder.inc.php @@ -0,0 +1,59 @@ +<?php +/* +Copyright (c) 2009, Scott Barr <gsbarr@gmail.com> +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of ISPConfig nor the names of its contributors + may be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +include_once('validate_datetime.inc.php'); + +class validate_autoresponder extends validate_datetime +{ + function start_date($field_name, $field_value, $validator) + { + if ($this->_datetime_selected($field_value)) { + return $this->is_future($field_name, $field_value, $validator); + } + } + + function end_date($field_name, $field_value, $validator) + { + global $app; + + $start_date = $app->tform_actions->dataRecord['autoresponder_start_date']; + + $_msg = $this->not_empty('autoresponder_start_date', $start_date, $validator); + if (!$_msg) // Start date set + { + if ( !($_msg = $this->not_empty($field_name, $field_value, $validator)) ) // End date set + { + $validator['compare'] = $this->_get_timestamp_value($start_date); + $_msg = $this->is_greater($field_name, $field_value, $validator); + } + + return $_msg; + } + } +} \ No newline at end of file diff --git a/interface/lib/classes/validate_datetime.inc.php b/interface/lib/classes/validate_datetime.inc.php new file mode 100755 index 0000000..b13e0ac --- /dev/null +++ b/interface/lib/classes/validate_datetime.inc.php @@ -0,0 +1,138 @@ +<?php +/* +Copyright (c) 2009, Scott Barr <gsbarr@gmail.com> +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of ISPConfig nor the names of its contributors + may be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +class validate_datetime +{ + /** + * Check if the parsed datetime selectors are not set + * to it's default value (zero). + * + * @param array $field_value + * @return bool + */ + function _datetime_selected($field_value) + { + if (is_array($field_value) && count($field_value) >= 5) + { + $result = array_filter($field_value, create_function('$dt_unit', 'return ($dt_unit > 0);')); + return (count($result) !== 0); + } + + return false; + } + + /** + * Check wordbook for the existence of an + * error message. If not found will return + * the parsed error message with line break. + * + * @param $errmsg + * @return string + */ + function _get_error($errmsg) + { + global $app; + + $errmsg = (isset($app->tform->wordbook[$errmsg])) ? $app->tform->wordbook[$errmsg] : $errmsg; + $errmsg .= '<br />' . PHP_EOL; + + return $errmsg; + } + + /** + * Helper function - filter the contents of the + * selectors and return the resulting unix timestamp. + * + * @param $field_value + * @return int Unix timestamp + */ + function _get_timestamp_value($field_value) + { + $second = 0; + $filtered_values = array_map(create_function('$item','return (int)$item;'), $field_value); + extract($filtered_values, EXTR_OVERWRITE); + + return mktime($hour, $minute, $second, $month, $day, $year); + } + + /** + * The minimum requirement to submit a datetime field + * is to set the day, month and year values. Check that + * these values are not zero (default). + * + * @param string $field_name + * @param array $field_value + * @param array $validator + * @return string|void Error message if found + */ + function not_empty($field_name, $field_value, $validator) + { + extract($field_value); + if ( !($day > 0 && $month > 0 && $year > 0) ) { + return $this->_get_error($validator['errmsg']); + } + } + + /** + * Check that the selected datetime is in the future. + * + * @param string $field_name + * @param array $field_value + * @param array $validator + * @return string|void Error message if found + */ + function is_future($field_name, $field_value, $validator) + { + $validator['compare'] = mktime(date('H'), (date('i')-30), 0, date('m'), date('d'), date('Y')); // Turn back the clock 30 minutes for slow posters. + return $this->is_greater($field_name, $field_value, $validator); + } + + /** + * Compare the selected datetime to a timestamp + * parsed via the validator array (key: compare). + * + * @param string $field_name + * @param array $field_value + * @param array $validator + * @return string|void Error message if found + */ + function is_greater($field_name, $field_value, $validator) + { + if ( !isset($validator['compare']) || !is_numeric($validator['compare']) || (date('d/m/Y', $validator['compare']) == '01/01/1970') ) { + return $this->_get_error('Could not find a unix timestamp to compare datetime with.'); + } + + $dt_stamp = $this->_get_timestamp_value($field_value); + if ($dt_stamp < $validator['compare']) { + return $this->_get_error($validator['errmsg']); + } + } + + +} \ No newline at end of file diff --git a/interface/lib/lang/en.lng b/interface/lib/lang/en.lng index eb58161..facf513 100644 --- a/interface/lib/lang/en.lng +++ b/interface/lib/lang/en.lng @@ -15,6 +15,7 @@ $wb['error_no_delete_permission'] = 'You dont have the permission to delete this record!'; $wb["page_txt"] = 'Page'; $wb["page_of_txt"] = 'of'; +$wb["page_and_txt"] = 'and'; $wb["page_next_txt"] = 'Next'; $wb["page_back_txt"] = 'Back'; $wb["delete_txt"] = 'Delete'; diff --git a/interface/web/mail/lib/lang/en_mail_user.lng b/interface/web/mail/lib/lang/en_mail_user.lng index ccb9651..6690819 100644 --- a/interface/web/mail/lib/lang/en_mail_user.lng +++ b/interface/web/mail/lib/lang/en_mail_user.lng @@ -7,7 +7,11 @@ $wb["email_error_isemail"] = 'Email address is invalid.'; $wb["email_error_unique"] = 'Duplicate Email address.'; $wb["autoresponder_text_txt"] = 'Text'; -$wb["autoresponder_txt"] = 'Autoresponder'; +$wb["autoresponder_txt"] = 'Active'; +$wb["autoresponder_start_date_txt"] = 'Start on'; +$wb["autoresponder_start_date_isfuture"] = 'Start date cannot be in the past.'; +$wb["autoresponder_end_date_txt"] = 'End by'; +$wb["autoresponder_end_date_isgreater"] = 'End date must be set and be later than start date.'; $wb["no_domain_perm"] = 'You have no permission for this domain.'; $wb["error_no_pwd"] = 'Password is empty.'; $wb["quota_error_isint"] = 'Mailbox size must be a number.'; -- Gitblit v1.9.1