320 |
jpm |
1 |
<?php
|
|
|
2 |
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
|
|
3 |
// +----------------------------------------------------------------------+
|
|
|
4 |
// | PHP Version 4 |
|
|
|
5 |
// +----------------------------------------------------------------------+
|
|
|
6 |
// | Copyright (c) 1997-2003 The PHP Group |
|
|
|
7 |
// +----------------------------------------------------------------------+
|
|
|
8 |
// | This source file is subject to version 2.0 of the PHP license, |
|
|
|
9 |
// | that is bundled with this package in the file LICENSE, and is |
|
|
|
10 |
// | available at through the world-wide-web at |
|
|
|
11 |
// | http://www.php.net/license/2_02.txt. |
|
|
|
12 |
// | If you did not receive a copy of the PHP license and are unable to |
|
|
|
13 |
// | obtain it through the world-wide-web, please send a note to |
|
|
|
14 |
// | license@php.net so we can mail you a copy immediately. |
|
|
|
15 |
// +----------------------------------------------------------------------+
|
|
|
16 |
// | Authors: Alexey Borzov <avb@php.net> |
|
|
|
17 |
// | Adam Daniel <adaniel1@eesus.jnj.com> |
|
|
|
18 |
// | Bertrand Mansion <bmansion@mamasam.com> |
|
|
|
19 |
// +----------------------------------------------------------------------+
|
|
|
20 |
//
|
|
|
21 |
// $Id: date.php,v 1.1 2005-03-30 08:50:33 jpm Exp $
|
|
|
22 |
|
|
|
23 |
require_once 'HTML/QuickForm/group.php';
|
|
|
24 |
require_once 'HTML/QuickForm/select.php';
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Class for a group of elements used to input dates (and times).
|
|
|
28 |
*
|
|
|
29 |
* Inspired by original 'date' element but reimplemented as a subclass
|
|
|
30 |
* of HTML_QuickForm_group
|
|
|
31 |
*
|
|
|
32 |
* @author Alexey Borzov <avb@php.net>
|
|
|
33 |
* @access public
|
|
|
34 |
*/
|
|
|
35 |
class HTML_QuickForm_date extends HTML_QuickForm_group
|
|
|
36 |
{
|
|
|
37 |
// {{{ properties
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Various options to control the element's display.
|
|
|
41 |
*
|
|
|
42 |
* Currently known options are
|
|
|
43 |
* 'language': date language
|
|
|
44 |
* 'format': Format of the date, based on PHP's date() function.
|
|
|
45 |
* The following characters are recognised in format string:
|
|
|
46 |
* D => Short names of days
|
|
|
47 |
* l => Long names of days
|
|
|
48 |
* d => Day numbers
|
|
|
49 |
* M => Short names of months
|
|
|
50 |
* F => Long names of months
|
|
|
51 |
* m => Month numbers
|
|
|
52 |
* Y => Four digit year
|
|
|
53 |
* y => Two digit year
|
|
|
54 |
* h => 12 hour format
|
|
|
55 |
* H => 23 hour format
|
|
|
56 |
* i => Minutes
|
|
|
57 |
* s => Seconds
|
|
|
58 |
* a => am/pm
|
|
|
59 |
* A => AM/PM
|
|
|
60 |
* 'minYear': Minimum year in year select
|
|
|
61 |
* 'maxYear': Maximum year in year select
|
|
|
62 |
* 'addEmptyOption': Should an empty option be added to the top of
|
|
|
63 |
* each select box?
|
|
|
64 |
* 'emptyOptionValue': The value passed by the empty option.
|
|
|
65 |
* 'emptyOptionText': The text displayed for the empty option.
|
|
|
66 |
* 'optionIncrement': Step to increase the option values by (works for 'i' and 's')
|
|
|
67 |
*
|
|
|
68 |
* @access private
|
|
|
69 |
* @var array
|
|
|
70 |
*/
|
|
|
71 |
var $_options = array(
|
|
|
72 |
'language' => 'en',
|
|
|
73 |
'format' => 'dMY',
|
|
|
74 |
'minYear' => 2001,
|
|
|
75 |
'maxYear' => 2010,
|
|
|
76 |
'addEmptyOption' => false,
|
|
|
77 |
'emptyOptionValue' => '',
|
|
|
78 |
'emptyOptionText' => ' ',
|
|
|
79 |
'optionIncrement' => array('i' => 1, 's' => 1)
|
|
|
80 |
);
|
|
|
81 |
|
|
|
82 |
/**
|
|
|
83 |
* These complement separators, they are appended to the resultant HTML
|
|
|
84 |
* @access private
|
|
|
85 |
* @var array
|
|
|
86 |
*/
|
|
|
87 |
var $_wrap = array('', '');
|
|
|
88 |
|
|
|
89 |
/**
|
|
|
90 |
* Options in different languages
|
|
|
91 |
*
|
|
|
92 |
* Note to potential translators: to avoid encoding problems please send
|
|
|
93 |
* your translations with "weird" letters encoded as HTML Unicode entities
|
|
|
94 |
*
|
|
|
95 |
* @access private
|
|
|
96 |
* @var array
|
|
|
97 |
*/
|
|
|
98 |
var $_locale = array(
|
|
|
99 |
'en' => array (
|
|
|
100 |
'weekdays_short'=> array ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'),
|
|
|
101 |
'weekdays_long' => array ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'),
|
|
|
102 |
'months_short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'),
|
|
|
103 |
'months_long' => array ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December')
|
|
|
104 |
),
|
|
|
105 |
'de' => array (
|
|
|
106 |
'weekdays_short'=> array ('So', 'Mon', 'Di', 'Mi', 'Do', 'Fr', 'Sa'),
|
|
|
107 |
'weekdays_long' => array ('Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'),
|
|
|
108 |
'months_short' => array ('Jan', 'Feb', 'März', 'April', 'Mai', 'Juni', 'Juli', 'Aug', 'Sept', 'Okt', 'Nov', 'Dez'),
|
|
|
109 |
'months_long' => array ('Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember')
|
|
|
110 |
),
|
|
|
111 |
'fr' => array (
|
|
|
112 |
'weekdays_short'=> array ('Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'),
|
|
|
113 |
'weekdays_long' => array ('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'),
|
|
|
114 |
'months_short' => array ('Jan', 'Fev', 'Mar', 'Avr', 'Mai', 'Jun', 'Jul', 'Aou', 'Sep', 'Oct', 'Nov', 'Dec'),
|
|
|
115 |
'months_long' => array ('Janvier', 'Fevrier', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Decembre')
|
|
|
116 |
),
|
|
|
117 |
'fr' => array (
|
|
|
118 |
'weekdays_short'=> array ('Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'),
|
|
|
119 |
'weekdays_long' => array ('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'),
|
|
|
120 |
'months_short' => array ('Jan', 'Fev', 'Mar', 'Avr', 'Mai', 'Jun', 'Jul', 'Aou', 'Sep', 'Oct', 'Nov', 'Dec'),
|
|
|
121 |
'months_long' => array ('Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre')
|
|
|
122 |
),
|
|
|
123 |
'hu' => array (
|
|
|
124 |
'weekdays_short'=> array ('V', 'H', 'K', 'Sze', 'Cs', 'P', 'Szo'),
|
|
|
125 |
'weekdays_long' => array ('vasárnap', 'hétfő', 'kedd', 'szerda', 'csütörtök', 'péntek', 'szombat'),
|
|
|
126 |
'months_short' => array ('jan', 'feb', 'márc', 'ápr', 'máj', 'jún', 'júl', 'aug', 'szept', 'okt', 'nov', 'dec'),
|
|
|
127 |
'months_long' => array ('január', 'február', 'március', 'április', 'május', 'június', 'július', 'augusztus', 'szeptember', 'október', 'november', 'december')
|
|
|
128 |
),
|
|
|
129 |
'pl' => array (
|
|
|
130 |
'weekdays_short'=> array ('Nie', 'Pn', 'Wt', 'Śr', 'Czw', 'Pt', 'Sob'),
|
|
|
131 |
'weekdays_long' => array ('Niedziela', 'Poniedziałek', 'Wtorek', 'Środa', 'Czwartek', 'Piątek', 'Sobota'),
|
|
|
132 |
'months_short' => array ('Sty', 'Lut', 'Mar', 'Kwi', 'Maj', 'Cze', 'Lip', 'Sie', 'Wrz', 'Paź', 'Lis', 'Gru'),
|
|
|
133 |
'months_long' => array ('Styczeń', 'Luty', 'Marzec', 'Kwiecień', 'Maj', 'Czerwiec', 'Lipiec', 'Sierpień', 'Wrzesień', 'Październik', 'Listopad', 'Grudzień')
|
|
|
134 |
),
|
|
|
135 |
'sl' => array (
|
|
|
136 |
'weekdays_short'=> array ('Ned', 'Pon', 'Tor', 'Sre', 'Cet', 'Pet', 'Sob'),
|
|
|
137 |
'weekdays_long' => array ('Nedelja', 'Ponedeljek', 'Torek', 'Sreda', 'Cetrtek', 'Petek', 'Sobota'),
|
|
|
138 |
'months_short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Avg', 'Sep', 'Okt', 'Nov', 'Dec'),
|
|
|
139 |
'months_long' => array ('Januar', 'Februar', 'Marec', 'April', 'Maj', 'Junij', 'Julij', 'Avgust', 'September', 'Oktober', 'November', 'December')
|
|
|
140 |
),
|
|
|
141 |
'ru' => array (
|
|
|
142 |
'weekdays_short'=> array ('Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'),
|
|
|
143 |
'weekdays_long' => array ('Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'),
|
|
|
144 |
'months_short' => array ('Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек'),
|
|
|
145 |
'months_long' => array ('Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь')
|
|
|
146 |
),
|
|
|
147 |
'es' => array (
|
|
|
148 |
'weekdays_short'=> array ('Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb'),
|
|
|
149 |
'weekdays_long' => array ('Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'),
|
|
|
150 |
'months_short' => array ('Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'),
|
|
|
151 |
'months_long' => array ('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septimbre', 'Octubre', 'Noviembre', 'Diciembre')
|
|
|
152 |
),
|
|
|
153 |
'da' => array (
|
|
|
154 |
'weekdays_short'=> array ('Søn', 'Man', 'Tir', 'Ons', 'Tor', 'Fre', 'Lør'),
|
|
|
155 |
'weekdays_long' => array ('Søndag', 'Mandag', 'Tirsdag', 'Onsdag', 'Torsdag', 'Fredag', 'Lørdag'),
|
|
|
156 |
'months_short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'),
|
|
|
157 |
'months_long' => array ('Januar', 'Februar', 'Marts', 'April', 'Maj', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'December')
|
|
|
158 |
),
|
|
|
159 |
'is' => array (
|
|
|
160 |
'weekdays_short'=> array ('Sun', 'Mán', 'Þri', 'Mið', 'Fim', 'Fös', 'Lau'),
|
|
|
161 |
'weekdays_long' => array ('Sunnudagur', 'Mánudagur', 'Þriðjudagur', 'Miðvikudagur', 'Fimmtudagur', 'Föstudagur', 'Laugardagur'),
|
|
|
162 |
'months_short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Maí', 'Jún', 'Júl', 'Ágú', 'Sep', 'Okt', 'Nóv', 'Des'),
|
|
|
163 |
'months_long' => array ('Janúar', 'Febrúar', 'Mars', 'Apríl', 'Maí', 'Júní', 'Júlí', 'Ágúst', 'September', 'Október', 'Nóvember', 'Desember')
|
|
|
164 |
),
|
|
|
165 |
'it' => array (
|
|
|
166 |
'weekdays_short'=> array ('Dom', 'Lun', 'Mar', 'Mer', 'Gio', 'Ven', 'Sab'),
|
|
|
167 |
'weekdays_long' => array ('Domenica', 'Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato'),
|
|
|
168 |
'months_short' => array ('Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago', 'Set', 'Ott', 'Nov', 'Dic'),
|
|
|
169 |
'months_long' => array ('Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre')
|
|
|
170 |
),
|
|
|
171 |
'sk' => array (
|
|
|
172 |
'weekdays_short'=> array ('Ned', 'Pon', 'Uto', 'Str', 'Štv', 'Pia', 'Sob'),
|
|
|
173 |
'weekdays_long' => array ('Nedeža', 'Pondelok', 'Utorok', 'Streda', 'Štvrtok', 'Piatok', 'Sobota'),
|
|
|
174 |
'months_short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Máj', 'Jún', 'Júl', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'),
|
|
|
175 |
'months_long' => array ('Január', 'Február', 'Marec', 'Apríl', 'Máj', 'Jún', 'Júl', 'August', 'September', 'Október', 'November', 'December')
|
|
|
176 |
),
|
|
|
177 |
'cs' => array (
|
|
|
178 |
'weekdays_short'=> array ('Ne', 'Po', 'Út', 'St', 'Čt', 'Pá', 'So'),
|
|
|
179 |
'weekdays_long' => array ('Neděle', 'Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota'),
|
|
|
180 |
'months_short' => array ('Led', 'Úno', 'Bře', 'Dub', 'Kvě', 'Čen', 'Čec', 'Srp', 'Zář', 'Říj', 'Lis', 'Pro'),
|
|
|
181 |
'months_long' => array ('Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec')
|
|
|
182 |
),
|
|
|
183 |
'hy' => array (
|
|
|
184 |
'weekdays_short'=> array ('Կրկ', 'Երկ', 'Երք', 'Չրք', 'Հնգ', 'Ուր', 'Շբթ'),
|
|
|
185 |
'weekdays_long' => array ('Կիրակի', 'Երկուշաբթի', 'Երեքշաբթի', 'Չորեքշաբթի', 'Հինգշաբթի', 'Ուրբաթ', 'Շաբաթ'),
|
|
|
186 |
'months_short' => array ('Հնվ', 'Փտր', 'Մրտ', 'Ապր', 'Մյս', 'Հնս', 'Հլս', 'Օգս', 'Սպտ', 'Հկտ', 'Նյմ', 'Դկտ'),
|
|
|
187 |
'months_long' => array ('Հունվար', 'Փետրվար', 'Մարտ', 'Ապրիլ', 'Մայիս', 'Հունիս', 'Հուլիս', 'Օգոստոս', 'Սեպտեմբեր', 'Հոկտեմբեր', 'Նոյեմբեր', 'Դեկտեմբեր')
|
|
|
188 |
),
|
|
|
189 |
'nl' => array (
|
|
|
190 |
'weekdays_short'=> array ('Zo', 'Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za'),
|
|
|
191 |
'weekdays_long' => array ('Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag'),
|
|
|
192 |
'months_short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'),
|
|
|
193 |
'months_long' => array ('Januari', 'Februari', 'Maart', 'April', 'Mei', 'Juni', 'Juli', 'Augustus', 'September', 'Oktober', 'November', 'December')
|
|
|
194 |
),
|
|
|
195 |
'et' => array (
|
|
|
196 |
'weekdays_short'=> array ('P', 'E', 'T', 'K', 'N', 'R', 'L'),
|
|
|
197 |
'weekdays_long' => array ('Pühapäev', 'Esmaspäev', 'Teisipäev', 'Kolmapäev', 'Neljapäev', 'Reede', 'Laupäev'),
|
|
|
198 |
'months_short' => array ('Jaan', 'Veebr', 'Märts', 'Aprill', 'Mai', 'Juuni', 'Juuli', 'Aug', 'Sept', 'Okt', 'Nov', 'Dets'),
|
|
|
199 |
'months_long' => array ('Jaanuar', 'Veebruar', 'Märts', 'Aprill', 'Mai', 'Juuni', 'Juuli', 'August', 'September', 'Oktoober', 'November', 'Detsember')
|
|
|
200 |
),
|
|
|
201 |
'tr' => array (
|
|
|
202 |
'weekdays_short'=> array ('Paz', 'Pzt', 'Sal', 'Çar', 'Per', 'Cum', 'Cts'),
|
|
|
203 |
'weekdays_long' => array ('Pazar', 'Pazartesi', 'Salı', 'Çarşamba', 'Perşembe', 'Cuma', 'Cumartesi'),
|
|
|
204 |
'months_short' => array ('Ock', 'Şbt', 'Mrt', 'Nsn', 'Mys', 'Hzrn', 'Tmmz', 'Ağst', 'Eyl', 'Ekm', 'Ksm', 'Arlk'),
|
|
|
205 |
'months_long' => array ('Ocak', 'Şubat', 'Mart', 'Nisan', 'Mayıs', 'Haziran', 'Temmuz', 'Ağustos', 'Eylül', 'Ekim', 'Kasım', 'Aralık')
|
|
|
206 |
),
|
|
|
207 |
'no' => array (
|
|
|
208 |
'weekdays_short'=> array ('Søn', 'Man', 'Tir', 'Ons', 'Tor', 'Fre', 'Lør'),
|
|
|
209 |
'weekdays_long' => array ('Søndag', 'Mandag', 'Tirsdag', 'Onsdag', 'Torsdag', 'Fredag', 'Lørdag'),
|
|
|
210 |
'months_short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Des'),
|
|
|
211 |
'months_long' => array ('Januar', 'Februar', 'Mars', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Desember')
|
|
|
212 |
),
|
|
|
213 |
'eo' => array (
|
|
|
214 |
'weekdays_short'=> array ('Dim', 'Lun', 'Mar', 'Mer', 'Ĵaŭ', 'Ven', 'Sab'),
|
|
|
215 |
'weekdays_long' => array ('Dimanĉo', 'Lundo', 'Mardo', 'Merkredo', 'Ĵaŭdo', 'Vendredo', 'Sabato'),
|
|
|
216 |
'months_short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Aŭg', 'Sep', 'Okt', 'Nov', 'Dec'),
|
|
|
217 |
'months_long' => array ('Januaro', 'Februaro', 'Marto', 'Aprilo', 'Majo', 'Junio', 'Julio', 'Aŭgusto', 'Septembro', 'Oktobro', 'Novembro', 'Decembro')
|
|
|
218 |
),
|
|
|
219 |
'ua' => array (
|
|
|
220 |
'weekdays_short'=> array('Ндл', 'Пнд', 'Втр', 'Срд', 'Чтв', 'Птн', 'Сбт'),
|
|
|
221 |
'weekdays_long' => array('Неділя', 'Понеділок', 'Вівторок', 'Середа', 'Четвер', 'П\'ятниця', 'Субота'),
|
|
|
222 |
'months_short' => array('Січ', 'Лют', 'Бер', 'Кві', 'Тра', 'Чер', 'Лип', 'Сер', 'Вер', 'Жов', 'Лис', 'Гру'),
|
|
|
223 |
'months_long' => array('Січень', 'Лютий', 'Березень', 'Квітень', 'Травень', 'Червень', 'Липень', 'Серпень', 'Вересень', 'Жовтень', 'Листопад', 'Грудень')
|
|
|
224 |
)
|
|
|
225 |
);
|
|
|
226 |
|
|
|
227 |
// }}}
|
|
|
228 |
// {{{ constructor
|
|
|
229 |
|
|
|
230 |
/**
|
|
|
231 |
* Class constructor
|
|
|
232 |
*
|
|
|
233 |
* @access public
|
|
|
234 |
* @param string Element's name
|
|
|
235 |
* @param mixed Label(s) for an element
|
|
|
236 |
* @param array Options to control the element's display
|
|
|
237 |
* @param mixed Either a typical HTML attribute string or an associative array
|
|
|
238 |
*/
|
|
|
239 |
function HTML_QuickForm_date($elementName = null, $elementLabel = null, $options = array(), $attributes = null)
|
|
|
240 |
{
|
|
|
241 |
$this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
|
|
|
242 |
$this->_persistantFreeze = true;
|
|
|
243 |
$this->_appendName = true;
|
|
|
244 |
$this->_type = 'date';
|
|
|
245 |
// set the options, do not bother setting bogus ones
|
|
|
246 |
if (is_array($options)) {
|
|
|
247 |
foreach ($options as $name => $value) {
|
|
|
248 |
if ('language' == $name) {
|
|
|
249 |
$this->_options['language'] = isset($this->_locale[$value])? $value: 'en';
|
|
|
250 |
} elseif (isset($this->_options[$name])) {
|
|
|
251 |
if (is_array($value)) {
|
|
|
252 |
$this->_options[$name] = @array_merge($this->_options[$name], $value);
|
|
|
253 |
} else {
|
|
|
254 |
$this->_options[$name] = $value;
|
|
|
255 |
}
|
|
|
256 |
}
|
|
|
257 |
}
|
|
|
258 |
}
|
|
|
259 |
}
|
|
|
260 |
|
|
|
261 |
// }}}
|
|
|
262 |
// {{{ _createElements()
|
|
|
263 |
|
|
|
264 |
function _createElements()
|
|
|
265 |
{
|
|
|
266 |
$this->_separator = $this->_elements = array();
|
|
|
267 |
$separator = '';
|
|
|
268 |
$locale =& $this->_locale[$this->_options['language']];
|
|
|
269 |
$backslash = false;
|
|
|
270 |
for ($i = 0, $length = strlen($this->_options['format']); $i < $length; $i++) {
|
|
|
271 |
$sign = $this->_options['format']{$i};
|
|
|
272 |
if ($backslash) {
|
|
|
273 |
$backslash = false;
|
|
|
274 |
$separator .= $sign;
|
|
|
275 |
} else {
|
|
|
276 |
$loadSelect = true;
|
|
|
277 |
switch ($sign) {
|
|
|
278 |
case 'D':
|
|
|
279 |
// Sunday is 0 like with 'w' in date()
|
|
|
280 |
$options = $locale['weekdays_short'];
|
|
|
281 |
break;
|
|
|
282 |
case 'l':
|
|
|
283 |
$options = $locale['weekdays_long'];
|
|
|
284 |
break;
|
|
|
285 |
case 'd':
|
|
|
286 |
$options = $this->_createOptionList(1, 31);
|
|
|
287 |
break;
|
|
|
288 |
case 'M':
|
|
|
289 |
$options = $locale['months_short'];
|
|
|
290 |
array_unshift($options , '');
|
|
|
291 |
unset($options[0]);
|
|
|
292 |
break;
|
|
|
293 |
case 'm':
|
|
|
294 |
$options = $this->_createOptionList(1, 12);
|
|
|
295 |
break;
|
|
|
296 |
case 'F':
|
|
|
297 |
$options = $locale['months_long'];
|
|
|
298 |
array_unshift($options , '');
|
|
|
299 |
unset($options[0]);
|
|
|
300 |
break;
|
|
|
301 |
case 'Y':
|
|
|
302 |
$options = $this->_createOptionList(
|
|
|
303 |
$this->_options['minYear'],
|
|
|
304 |
$this->_options['maxYear'],
|
|
|
305 |
$this->_options['minYear'] > $this->_options['maxYear']? -1: 1
|
|
|
306 |
);
|
|
|
307 |
break;
|
|
|
308 |
case 'y':
|
|
|
309 |
$options = $this->_createOptionList(
|
|
|
310 |
$this->_options['minYear'],
|
|
|
311 |
$this->_options['maxYear'],
|
|
|
312 |
$this->_options['minYear'] > $this->_options['maxYear']? -1: 1
|
|
|
313 |
);
|
|
|
314 |
array_walk($options, create_function('&$v,$k','$v = substr($v,-2);'));
|
|
|
315 |
break;
|
|
|
316 |
case 'h':
|
|
|
317 |
$options = $this->_createOptionList(1, 12);
|
|
|
318 |
break;
|
|
|
319 |
case 'H':
|
|
|
320 |
$options = $this->_createOptionList(0, 23);
|
|
|
321 |
break;
|
|
|
322 |
case 'i':
|
|
|
323 |
$options = $this->_createOptionList(0, 59, $this->_options['optionIncrement']['i']);
|
|
|
324 |
break;
|
|
|
325 |
case 's':
|
|
|
326 |
$options = $this->_createOptionList(0, 59, $this->_options['optionIncrement']['s']);
|
|
|
327 |
break;
|
|
|
328 |
case 'a':
|
|
|
329 |
$options = array('am' => 'am', 'pm' => 'pm');
|
|
|
330 |
break;
|
|
|
331 |
case 'A':
|
|
|
332 |
$options = array('AM' => 'AM', 'PM' => 'PM');
|
|
|
333 |
break;
|
|
|
334 |
case '\\':
|
|
|
335 |
$backslash = true;
|
|
|
336 |
$loadSelect = false;
|
|
|
337 |
break;
|
|
|
338 |
default:
|
|
|
339 |
$separator .= (' ' == $sign? ' ': $sign);
|
|
|
340 |
$loadSelect = false;
|
|
|
341 |
}
|
|
|
342 |
|
|
|
343 |
if ($loadSelect) {
|
|
|
344 |
if (0 < count($this->_elements)) {
|
|
|
345 |
$this->_separator[] = $separator;
|
|
|
346 |
} else {
|
|
|
347 |
$this->_wrap[0] = $separator;
|
|
|
348 |
}
|
|
|
349 |
$separator = '';
|
|
|
350 |
// Should we add an empty option to the top of the select?
|
|
|
351 |
if ($this->_options['addEmptyOption']) {
|
|
|
352 |
// Preserve the keys
|
|
|
353 |
$options = array($this->_options['emptyOptionValue'] => $this->_options['emptyOptionText']) + $options;
|
|
|
354 |
}
|
|
|
355 |
$this->_elements[] =& new HTML_QuickForm_select($sign, null, $options, $this->getAttributes());
|
|
|
356 |
}
|
|
|
357 |
}
|
|
|
358 |
}
|
|
|
359 |
$this->_wrap[1] = $separator . ($backslash? '\\': '');
|
|
|
360 |
}
|
|
|
361 |
|
|
|
362 |
// }}}
|
|
|
363 |
// {{{ _createOptionList()
|
|
|
364 |
|
|
|
365 |
/**
|
|
|
366 |
* Creates an option list containing the numbers from the start number to the end, inclusive
|
|
|
367 |
*
|
|
|
368 |
* @param int The start number
|
|
|
369 |
* @param int The end number
|
|
|
370 |
* @param int Increment by this value
|
|
|
371 |
* @access private
|
|
|
372 |
* @return array An array of numeric options.
|
|
|
373 |
*/
|
|
|
374 |
function _createOptionList($start, $end, $step = 1)
|
|
|
375 |
{
|
|
|
376 |
for ($i = $start, $options = array(); $start > $end? $i >= $end: $i <= $end; $i += $step) {
|
|
|
377 |
$options[$i] = sprintf('%02d', $i);
|
|
|
378 |
}
|
|
|
379 |
return $options;
|
|
|
380 |
}
|
|
|
381 |
|
|
|
382 |
// }}}
|
|
|
383 |
// {{{ setValue()
|
|
|
384 |
|
|
|
385 |
function setValue($value)
|
|
|
386 |
{
|
|
|
387 |
if (empty($value)) {
|
|
|
388 |
$value = array();
|
|
|
389 |
} elseif (is_scalar($value)) {
|
|
|
390 |
if (!is_numeric($value)) {
|
|
|
391 |
$value = strtotime($value);
|
|
|
392 |
}
|
|
|
393 |
// might be a unix epoch, then we fill all possible values
|
|
|
394 |
$arr = explode('-', date('w-d-n-Y-h-H-i-s-a-A', (int)$value));
|
|
|
395 |
$value = array(
|
|
|
396 |
'D' => $arr[0],
|
|
|
397 |
'l' => $arr[0],
|
|
|
398 |
'd' => $arr[1],
|
|
|
399 |
'M' => $arr[2],
|
|
|
400 |
'm' => $arr[2],
|
|
|
401 |
'F' => $arr[2],
|
|
|
402 |
'Y' => $arr[3],
|
|
|
403 |
'y' => $arr[3],
|
|
|
404 |
'h' => $arr[4],
|
|
|
405 |
'H' => $arr[5],
|
|
|
406 |
'i' => $arr[6],
|
|
|
407 |
's' => $arr[7],
|
|
|
408 |
'a' => $arr[8],
|
|
|
409 |
'A' => $arr[9]
|
|
|
410 |
);
|
|
|
411 |
}
|
|
|
412 |
parent::setValue($value);
|
|
|
413 |
}
|
|
|
414 |
|
|
|
415 |
// }}}
|
|
|
416 |
// {{{ toHtml()
|
|
|
417 |
|
|
|
418 |
function toHtml()
|
|
|
419 |
{
|
|
|
420 |
include_once('HTML/QuickForm/Renderer/Default.php');
|
|
|
421 |
$renderer =& new HTML_QuickForm_Renderer_Default();
|
|
|
422 |
$renderer->setElementTemplate($this->_wrap[0] . '{element}' . $this->_wrap[1]);
|
|
|
423 |
parent::accept($renderer);
|
|
|
424 |
return $renderer->toHtml();
|
|
|
425 |
}
|
|
|
426 |
|
|
|
427 |
// }}}
|
|
|
428 |
// {{{ accept()
|
|
|
429 |
|
|
|
430 |
function accept(&$renderer, $required = false, $error = null)
|
|
|
431 |
{
|
|
|
432 |
$renderer->renderElement($this, $required, $error);
|
|
|
433 |
}
|
|
|
434 |
|
|
|
435 |
// }}}
|
|
|
436 |
// {{{ onQuickFormEvent()
|
|
|
437 |
|
|
|
438 |
function onQuickFormEvent($event, $arg, &$caller)
|
|
|
439 |
{
|
|
|
440 |
if ('updateValue' == $event) {
|
|
|
441 |
// we need to call setValue(), 'cause the default/constant value
|
|
|
442 |
// may be in fact a timestamp, not an array
|
|
|
443 |
return HTML_QuickForm_element::onQuickFormEvent($event, $arg, $caller);
|
|
|
444 |
} else {
|
|
|
445 |
return parent::onQuickFormEvent($event, $arg, $caller);
|
|
|
446 |
}
|
|
|
447 |
}
|
|
|
448 |
|
|
|
449 |
// }}}
|
|
|
450 |
}
|
|
|
451 |
?>
|