/
date_api.php
208 lines (185 loc) · 6.72 KB
/
date_api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
# Mantis - a php based bugtracking system
# Mantis is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# Mantis 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mantis. If not, see <http://www.gnu.org/licenses/>.
/**
* @package CoreAPI
* @subpackage DateAPI
* @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
* @copyright Copyright (C) 2002 - 2008 Mantis Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
*/
# ## Date API ###
# checks if date is null
function date_is_null( $p_date ) {
return $p_date == date_get_null();
}
# gets null date
function date_get_null() {
return db_unixtimestamp( db_null_date() );
}
# prints the date given the formating string
function print_date( $p_format, $p_date ) {
PRINT date( $p_format, $p_date );
}
function print_month_option_list( $p_month = 0 ) {
for( $i = 1;$i <= 12;$i++ ) {
$month_name = date( 'F', mktime( 0, 0, 0, $i, 1, 2000 ) );
if( $i == $p_month ) {
echo "<option value=\"$i\" selected=\"selected\">$month_name</option>";
} else {
echo "<option value=\"$i\">$month_name</option>";
}
}
}
function print_numeric_month_option_list( $p_month = 0 ) {
for( $i = 1;$i <= 12;$i++ ) {
if( $i == $p_month ) {
echo "<option value=\"$i\" selected=\"selected\">$i</option>";
} else {
echo "<option value=\"$i\">$i</option>";
}
}
}
function print_day_option_list( $p_day = 0 ) {
for( $i = 1;$i <= 31;$i++ ) {
if( $i == $p_day ) {
echo "<option value=\"$i\" selected=\"selected\">$i</option>";
} else {
echo "<option value=\"$i\">$i</option>";
}
}
}
function print_year_option_list( $p_year = 0 ) {
$current_year = date( "Y" );
for( $i = $current_year;$i > 1999;$i-- ) {
if( $i == $p_year ) {
echo "<option value=\"$i\" selected=\"selected\">$i</option>";
} else {
echo "<option value=\"$i\">$i</option>";
}
}
}
function print_year_range_option_list( $p_year = 0, $p_start = 0, $p_end = 0 ) {
$t_current = date( 'Y' );
$t_forward_years = config_get( 'forward_year_count' );
$t_start_year = $p_start;
if( $t_start_year == 0 ) {
$t_backward_years = config_get( 'backward_year_count' );
$t_start_year = $t_current - $t_backward_years;
}
if(( $p_year < $t_start_year ) && ( $p_year != 0 ) ) {
$t_start_year = $p_year;
}
$t_end_year = $p_end;
if( $t_end_year == 0 ) {
$t_end_year = $t_current + $t_forward_years;
}
if( $p_year > $t_end_year ) {
$t_end_year = $p_year + $t_forward_years;
}
for( $i = $t_start_year;$i <= $t_end_year;$i++ ) {
if( $i == $p_year ) {
echo "<option value=\"$i\" selected=\"selected\">$i</option>";
} else {
echo "<option value=\"$i\">$i</option>";
}
}
}
function print_date_selection_set( $p_name, $p_format, $p_date = 0, $p_default_disable = false, $p_allow_blank = false, $p_year_start = 0, $p_year_end = 0 ) {
$t_chars = preg_split( '//', $p_format, -1, PREG_SPLIT_NO_EMPTY );
if( $p_date != 0 ) {
$t_date = preg_split( '/-/', date( 'Y-m-d', $p_date ), -1, PREG_SPLIT_NO_EMPTY );
} else {
$t_date = array(
0,
0,
0,
);
}
$t_disable = '';
if( $p_default_disable == true ) {
$t_disable = ' disabled="disabled"';
}
$t_blank_line = '';
if( $p_allow_blank == true ) {
$t_blank_line = "<option value=\"0\"></option>";
}
foreach( $t_chars as $t_char ) {
if( strcmp( $t_char, "M" ) == 0 ) {
echo "<select ", helper_get_tab_index(), " name=\"" . $p_name . "_month\"$t_disable>";
echo $t_blank_line;
print_month_option_list( $t_date[1] );
echo "</select>\n";
}
if( strcmp( $t_char, "m" ) == 0 ) {
echo "<select ", helper_get_tab_index(), " name=\"" . $p_name . "_month\"$t_disable>";
echo $t_blank_line;
print_numeric_month_option_list( $t_date[1] );
echo "</select>\n";
}
if( strcasecmp( $t_char, "D" ) == 0 ) {
echo "<select ", helper_get_tab_index(), " name=\"" . $p_name . "_day\"$t_disable>";
echo $t_blank_line;
print_day_option_list( $t_date[2] );
echo "</select>\n";
}
if( strcasecmp( $t_char, "Y" ) == 0 ) {
echo "<select ", helper_get_tab_index(), " name=\"" . $p_name . "_year\"$t_disable>";
echo $t_blank_line;
print_year_range_option_list( $t_date[0], $p_year_start, $p_year_end );
echo "</select>\n";
}
}
}
# prints calendar icon and adds required javascript files.
# button_name is name of button that will display calendar icon
# in caste there are more than one calendar on page
function date_print_calendar( $p_button_name = 'trigger' ) {
# @@@ (thraxisp) this may want a browser check ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
if(( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ) {
echo "<style type=\"text/css\">@import url(javascript/jscalendar/calendar-blue.css);</style>\n";
echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar.js\"></script>\n";
echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/lang/calendar-en.js\"></script>\n";
echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar-setup.js\"></script>\n";
$t_icon_path = config_get( 'icon_path' );
$t_cal_icon = $t_icon_path . "calendar-img.gif";
echo "<input type=\"image\" class=\"button\" id=\"" . $p_button_name . "\" src=\"";
echo $t_cal_icon;
$t_format = config_get( 'short_date_format' );
$t_new_format = str_replace( '-', '-%', $t_format );
$t_format = "%" . $t_new_format;
echo "\" onclick=\"return showCalendar ('sel1', '" . $t_format . "', 24, true)\" />";
}
}
# creates javascript calendar objects, point to input element ($p_field_name) that
# diaplays date, and connects it with calendar button ($p_button_name) created with
# date_print_calendar.
# should be called right after </form> tag
function date_finish_calendar( $p_field_name, $p_button_name ) {
# @@@ (thraxisp) this may want a browser check ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
if(( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ) {
$t_format = config_get( 'short_date_format' );
$t_new_format = str_replace( '-', '-%', $t_format );
$t_format = "%" . $t_new_format;
echo "<script type=\"text/javascript\">\n";
echo "Calendar.setup (\n";
echo "{\n";
echo "inputField : \"" . $p_field_name . "\",\n";
echo "ifFormat : \"" . $t_format . "\", \n";
echo "button : \"" . $p_button_name . "\"\n";
echo "}\n";
echo ");\n";
echo "</script>\n";
}
}