22
22
* month values (Gary Loescher)
23
23
* - 1.3.1 added support for choosing format for
24
24
* day values (Marcus Bointon)
25
* - 1.3.2 suppport negative timestamps, force year
25
* - 1.3.2 support negative timestamps, force year
26
26
* dropdown to include given date unless explicitly set (Monte)
27
* - 1.3.4 fix behaviour of 0000-00-00 00:00:00 dates to match that
28
* of 0000-00-00 dates (cybot, boots)
27
29
* @link http://smarty.php.net/manual/en/language.function.html.select.date.php {html_select_date}
28
30
* (Smarty online manual)
30
* @author Andrei Zmievski
32
* @author Andrei Zmievski
33
* @author Monte Ohrt <monte at ohrt dot com>
35
38
function smarty_function_html_select_date($params, &$smarty)
40
require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
37
41
require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
38
42
require_once $smarty->_get_plugin_filepath('function','html_options');
39
43
/* Default values. */
122
$smarty->trigger_error("[html_select_date] unknown parameter $_key", E_USER_WARNING);
127
if(!is_array($_value)) {
128
$extra_attrs .= ' '.$_key.'="'.smarty_function_escape_special_chars($_value).'"';
130
$smarty->trigger_error("html_select_date: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
127
if(preg_match('!^-\d+$!',$time)) {
136
if (preg_match('!^-\d+$!', $time)) {
128
137
// negative timestamp, use date()
129
$time = date('Y-m-d',$time);
138
$time = date('Y-m-d', $time);
131
140
// If $time is not in format yyyy-mm-dd
132
if (!preg_match('/^\d{0,4}-\d{0,2}-\d{0,2}$/', $time)) {
141
if (preg_match('/^(\d{0,4}-\d{0,2}-\d{0,2})/', $time, $found)) {
133
144
// use smarty_make_timestamp to get an unix timestamp and
134
145
// strftime to make yyyy-mm-dd
135
146
$time = strftime('%Y-%m-%d', smarty_make_timestamp($time));
137
148
// Now split this in pieces, which later can be used to set the select
138
149
$time = explode("-", $time);
140
151
// make syntax "+N" or "-N" work with start_year and end_year
141
152
if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) {
142
153
if ($match[1] == '+') {
152
163
$start_year = strftime('%Y') - $match[2];
155
if (strlen($time[0]) > 0) {
166
if (strlen($time[0]) > 0) {
156
167
if ($start_year > $time[0] && !isset($params['start_year'])) {
157
168
// force start year to include given date if not explicitly set
158
169
$start_year = $time[0];
194
207
if (null !== $all_extra){
195
208
$month_result .= ' ' . $all_extra;
197
$month_result .= '>'."\n";
210
$month_result .= $extra_attrs . '>'."\n";
199
212
$month_result .= smarty_function_html_options(array('output' => $month_names,
200
213
'values' => $month_values,
201
'selected' => $a=$time[1] ? strftime($month_value_format, mktime(0, 0, 0, (int)$time[1], 1, 2000)) : '',
214
'selected' => (int)$time[1] ? strftime($month_value_format, mktime(0, 0, 0, (int)$time[1], 1, 2000)) : '',
202
215
'print_result' => false),
204
217
$month_result .= '</select>';
207
220
if ($display_days) {
221
$field_separator_count++;
209
223
if (isset($day_empty)) {
210
224
$days[''] = $day_empty;
230
244
if (null !== $day_extra){
231
245
$day_result .= ' ' . $day_extra;
233
$day_result .= '>'."\n";
247
$day_result .= $extra_attrs . '>'."\n";
234
248
$day_result .= smarty_function_html_options(array('output' => $days,
235
249
'values' => $day_values,
236
250
'selected' => $time[2],
276
291
if (null !== $year_extra){
277
292
$year_result .= ' ' . $year_extra;
279
$year_result .= '>'."\n";
294
$year_result .= $extra_attrs . '>'."\n";
280
295
$year_result .= smarty_function_html_options(array('output' => $years,
281
296
'values' => $yearvals,
282
297
'selected' => $time[0],