home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / HTML / QuickForm / date.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  32.8 KB  |  528 lines

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