~ubuntu-branches/ubuntu/natty/moodle/natty

« back to all changes in this revision

Viewing changes to lib/smarty/plugins/function.html_select_date.php

  • Committer: Bazaar Package Importer
  • Author(s): Tomasz Muras
  • Date: 2010-10-30 12:19:28 UTC
  • mfrom: (1.1.12 upstream) (3.1.10 squeeze)
  • Revision ID: james.westby@ubuntu.com-20101030121928-qzobi6mctpnk4dif
Tags: 1.9.9.dfsg2-2
* Added Romanian translation
* Updated Japanese translation (closes: #596820)
* Backporting security fixes from Moodle 1.9.10 (closes: #601384)
   - Updated embedded CAS to 1.1.3
   - Added patch for MDL-24523:
     clean_text() not filtering text in markdown format
   - Added patch for MDL-24810 and upgraded customized HTML Purifier to 4.2.0 
   - Added patch for MDL-24258:
     students can delete their forum posts later than $CFG->maxeditingtime 
     under certain conditions
   - Added patch for MDL-23377:
     Can't delete quiz attempts in course without enrolled students

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
 
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)
29
 
 * @version 1.3.2
30
 
 * @author   Andrei Zmievski
 
31
 * @version 1.3.4
 
32
 * @author Andrei Zmievski
 
33
 * @author Monte Ohrt <monte at ohrt dot com>
31
34
 * @param array
32
35
 * @param Smarty
33
36
 * @return string
34
37
 */
35
38
function smarty_function_html_select_date($params, &$smarty)
36
39
{
 
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. */
78
82
    $day_empty       = null;
79
83
    $month_empty     = null;
80
84
    $year_empty      = null;
 
85
    $extra_attrs     = '';
81
86
 
82
87
    foreach ($params as $_key=>$_value) {
83
88
        switch ($_key) {
119
124
                break;
120
125
 
121
126
            default:
122
 
                $smarty->trigger_error("[html_select_date] unknown parameter $_key", E_USER_WARNING);
123
 
 
 
127
                if(!is_array($_value)) {
 
128
                    $extra_attrs .= ' '.$_key.'="'.smarty_function_escape_special_chars($_value).'"';
 
129
                } else {
 
130
                    $smarty->trigger_error("html_select_date: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
 
131
                }
 
132
                break;
124
133
        }
125
134
    }
126
135
 
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);
130
139
    }
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)) {
 
142
        $time = $found[1];
 
143
    } else {
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));
136
147
    }
137
148
    // Now split this in pieces, which later can be used to set the select
138
149
    $time = explode("-", $time);
139
 
    
 
150
 
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];
153
164
        }
154
165
    }
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];
167
178
 
168
179
    $html_result = $month_result = $day_result = $year_result = "";
169
180
 
 
181
    $field_separator_count = -1;
170
182
    if ($display_months) {
 
183
        $field_separator_count++;
171
184
        $month_names = array();
172
185
        $month_values = array();
173
186
        if(isset($month_empty)) {
194
207
        if (null !== $all_extra){
195
208
            $month_result .= ' ' . $all_extra;
196
209
        }
197
 
        $month_result .= '>'."\n";
 
210
        $month_result .= $extra_attrs . '>'."\n";
198
211
 
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),
203
216
                                                      $smarty);
204
217
        $month_result .= '</select>';
205
218
    }
206
219
 
207
220
    if ($display_days) {
 
221
        $field_separator_count++;
208
222
        $days = array();
209
223
        if (isset($day_empty)) {
210
224
            $days[''] = $day_empty;
230
244
        if (null !== $day_extra){
231
245
            $day_result .= ' ' . $day_extra;
232
246
        }
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],
240
254
    }
241
255
 
242
256
    if ($display_years) {
 
257
        $field_separator_count++;
243
258
        if (null !== $field_array){
244
259
            $year_name = $field_array . '[' . $prefix . 'Year]';
245
260
        } else {
253
268
            if (null !== $year_extra){
254
269
                $year_result .= ' ' . $year_extra;
255
270
            }
256
 
            $year_result .= '>';
 
271
            $year_result .= ' />';
257
272
        } else {
258
273
            $years = range((int)$start_year, (int)$end_year);
259
274
            if ($reverse_years) {
276
291
            if (null !== $year_extra){
277
292
                $year_result .= ' ' . $year_extra;
278
293
            }
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],
303
318
                break;
304
319
        }
305
320
        // Add the field seperator
306
 
        if($i != 2) {
 
321
        if($i < $field_separator_count) {
307
322
            $html_result .= $field_separator;
308
323
        }
309
324
    }