~ubuntu-branches/ubuntu/edgy/smarty/edgy-security

« back to all changes in this revision

Viewing changes to libs/plugins/function.html_select_date.php

  • Committer: Bazaar Package Importer
  • Author(s): Dimitri Fontaine
  • Date: 2005-03-29 11:53:20 UTC
  • mfrom: (0.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050329115320-g3rvndgnn75ogm35
Tags: 2.6.8-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
26
 *             dropdown to include given date unless explicitly set (Monte)
25
27
 * @link http://smarty.php.net/manual/en/language.function.html.select.date.php {html_select_date}
26
28
 *      (Smarty online manual)
27
 
 * @version 1.3.1
 
29
 * @version 1.3.2
28
30
 * @author   Andrei Zmievski
29
31
 * @param array
30
32
 * @param Smarty
122
124
        }
123
125
    }
124
126
 
 
127
    if(preg_match('!^-\d+$!',$time)) {
 
128
        // negative timestamp, use date()
 
129
        $time = date('Y-m-d',$time);
 
130
    }
125
131
    // If $time is not in format yyyy-mm-dd
126
132
    if (!preg_match('/^\d{0,4}-\d{0,2}-\d{0,2}$/', $time)) {
127
 
        // then $time is empty or unix timestamp or mysql timestamp
128
 
        // using smarty_make_timestamp to get an unix timestamp and
 
133
        // use smarty_make_timestamp to get an unix timestamp and
129
134
        // strftime to make yyyy-mm-dd
130
135
        $time = strftime('%Y-%m-%d', smarty_make_timestamp($time));
131
136
    }
132
137
    // Now split this in pieces, which later can be used to set the select
133
138
    $time = explode("-", $time);
134
 
 
 
139
    
135
140
    // make syntax "+N" or "-N" work with start_year and end_year
136
141
    if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) {
137
142
        if ($match[1] == '+') {
147
152
            $start_year = strftime('%Y') - $match[2];
148
153
        }
149
154
    }
 
155
    if (strlen($time[0]) > 0) { 
 
156
        if ($start_year > $time[0] && !isset($params['start_year'])) {
 
157
            // force start year to include given date if not explicitly set
 
158
            $start_year = $time[0];
 
159
        }
 
160
        if($end_year < $time[0] && !isset($params['end_year'])) {
 
161
            // force end year to include given date if not explicitly set
 
162
            $end_year = $time[0];
 
163
        }
 
164
    }
150
165
 
151
166
    $field_order = strtoupper($field_order);
152
167
 
183
198
 
184
199
        $month_result .= smarty_function_html_options(array('output'     => $month_names,
185
200
                                                            'values'     => $month_values,
186
 
                                                            'selected'   => $month_values[(int)$time[1]],
 
201
                                                            'selected'   => $a=$time[1] ? strftime($month_value_format, mktime(0, 0, 0, (int)$time[1], 1, 2000)) : '',
187
202
                                                            'print_result' => false),
188
203
                                                      $smarty);
189
 
 
190
204
        $month_result .= '</select>';
191
205
    }
192
206
 
244
258
            $years = range((int)$start_year, (int)$end_year);
245
259
            if ($reverse_years) {
246
260
                rsort($years, SORT_NUMERIC);
 
261
            } else {
 
262
                sort($years, SORT_NUMERIC);
247
263
            }
248
264
            $yearvals = $years;
249
265
            if(isset($year_empty)) {