Skip to content

Commit fcc6984

Browse files
author
wyrie
committed
Implemented: FS#1003 - Autoresponder: Start and end date (Interface)
1 parent fbec977 commit fcc6984

File tree

4 files changed

+203
-1
lines changed

4 files changed

+203
-1
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/*
3+
Copyright (c) 2009, Scott Barr <gsbarr@gmail.com>
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without modification,
7+
are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice,
10+
this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
* Neither the name of ISPConfig nor the names of its contributors
15+
may be used to endorse or promote products derived from this software without
16+
specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
include_once('validate_datetime.inc.php');
31+
32+
class validate_autoresponder extends validate_datetime
33+
{
34+
function start_date($field_name, $field_value, $validator)
35+
{
36+
if ($this->_datetime_selected($field_value)) {
37+
return $this->is_future($field_name, $field_value, $validator);
38+
}
39+
}
40+
41+
function end_date($field_name, $field_value, $validator)
42+
{
43+
global $app;
44+
45+
$start_date = $app->tform_actions->dataRecord['autoresponder_start_date'];
46+
47+
$_msg = $this->not_empty('autoresponder_start_date', $start_date, $validator);
48+
if (!$_msg) // Start date set
49+
{
50+
if ( !($_msg = $this->not_empty($field_name, $field_value, $validator)) ) // End date set
51+
{
52+
$validator['compare'] = $this->_get_timestamp_value($start_date);
53+
$_msg = $this->is_greater($field_name, $field_value, $validator);
54+
}
55+
56+
return $_msg;
57+
}
58+
}
59+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
/*
3+
Copyright (c) 2009, Scott Barr <gsbarr@gmail.com>
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without modification,
7+
are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice,
10+
this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
* Neither the name of ISPConfig nor the names of its contributors
15+
may be used to endorse or promote products derived from this software without
16+
specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
class validate_datetime
31+
{
32+
/**
33+
* Check if the parsed datetime selectors are not set
34+
* to it's default value (zero).
35+
*
36+
* @param array $field_value
37+
* @return bool
38+
*/
39+
function _datetime_selected($field_value)
40+
{
41+
if (is_array($field_value) && count($field_value) >= 5)
42+
{
43+
$result = array_filter($field_value, create_function('$dt_unit', 'return ($dt_unit > 0);'));
44+
return (count($result) !== 0);
45+
}
46+
47+
return false;
48+
}
49+
50+
/**
51+
* Check wordbook for the existence of an
52+
* error message. If not found will return
53+
* the parsed error message with line break.
54+
*
55+
* @param $errmsg
56+
* @return string
57+
*/
58+
function _get_error($errmsg)
59+
{
60+
global $app;
61+
62+
$errmsg = (isset($app->tform->wordbook[$errmsg])) ? $app->tform->wordbook[$errmsg] : $errmsg;
63+
$errmsg .= '<br />' . PHP_EOL;
64+
65+
return $errmsg;
66+
}
67+
68+
/**
69+
* Helper function - filter the contents of the
70+
* selectors and return the resulting unix timestamp.
71+
*
72+
* @param $field_value
73+
* @return int Unix timestamp
74+
*/
75+
function _get_timestamp_value($field_value)
76+
{
77+
$second = 0;
78+
$filtered_values = array_map(create_function('$item','return (int)$item;'), $field_value);
79+
extract($filtered_values, EXTR_OVERWRITE);
80+
81+
return mktime($hour, $minute, $second, $month, $day, $year);
82+
}
83+
84+
/**
85+
* The minimum requirement to submit a datetime field
86+
* is to set the day, month and year values. Check that
87+
* these values are not zero (default).
88+
*
89+
* @param string $field_name
90+
* @param array $field_value
91+
* @param array $validator
92+
* @return string|void Error message if found
93+
*/
94+
function not_empty($field_name, $field_value, $validator)
95+
{
96+
extract($field_value);
97+
if ( !($day > 0 && $month > 0 && $year > 0) ) {
98+
return $this->_get_error($validator['errmsg']);
99+
}
100+
}
101+
102+
/**
103+
* Check that the selected datetime is in the future.
104+
*
105+
* @param string $field_name
106+
* @param array $field_value
107+
* @param array $validator
108+
* @return string|void Error message if found
109+
*/
110+
function is_future($field_name, $field_value, $validator)
111+
{
112+
$validator['compare'] = mktime(date('H'), (date('i')-30), 0, date('m'), date('d'), date('Y')); // Turn back the clock 30 minutes for slow posters.
113+
return $this->is_greater($field_name, $field_value, $validator);
114+
}
115+
116+
/**
117+
* Compare the selected datetime to a timestamp
118+
* parsed via the validator array (key: compare).
119+
*
120+
* @param string $field_name
121+
* @param array $field_value
122+
* @param array $validator
123+
* @return string|void Error message if found
124+
*/
125+
function is_greater($field_name, $field_value, $validator)
126+
{
127+
if ( !isset($validator['compare']) || !is_numeric($validator['compare']) || (date('d/m/Y', $validator['compare']) == '01/01/1970') ) {
128+
return $this->_get_error('Could not find a unix timestamp to compare datetime with.');
129+
}
130+
131+
$dt_stamp = $this->_get_timestamp_value($field_value);
132+
if ($dt_stamp < $validator['compare']) {
133+
return $this->_get_error($validator['errmsg']);
134+
}
135+
}
136+
137+
138+
}

interface/lib/lang/en.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ $wb['error_no_view_permission'] = 'You dont have the permission to view this rec
1515
$wb['error_no_delete_permission'] = 'You dont have the permission to delete this record!';
1616
$wb["page_txt"] = 'Page';
1717
$wb["page_of_txt"] = 'of';
18+
$wb["page_and_txt"] = 'and';
1819
$wb["page_next_txt"] = 'Next';
1920
$wb["page_back_txt"] = 'Back';
2021
$wb["delete_txt"] = 'Delete';

interface/web/mail/lib/lang/en_mail_user.lng

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ $wb["active_txt"] = 'Active';
77
$wb["email_error_isemail"] = 'Email address is invalid.';
88
$wb["email_error_unique"] = 'Duplicate Email address.';
99
$wb["autoresponder_text_txt"] = 'Text';
10-
$wb["autoresponder_txt"] = 'Autoresponder';
10+
$wb["autoresponder_txt"] = 'Active';
11+
$wb["autoresponder_start_date_txt"] = 'Start on';
12+
$wb["autoresponder_start_date_isfuture"] = 'Start date cannot be in the past.';
13+
$wb["autoresponder_end_date_txt"] = 'End by';
14+
$wb["autoresponder_end_date_isgreater"] = 'End date must be set and be later than start date.';
1115
$wb["no_domain_perm"] = 'You have no permission for this domain.';
1216
$wb["error_no_pwd"] = 'Password is empty.';
1317
$wb["quota_error_isint"] = 'Mailbox size must be a number.';

0 commit comments

Comments
 (0)