[Phphtmllib-devel] phphtmllib/form/form_elements FEListBox.inc,1.13,1.14
Status: Beta
Brought to you by:
hemna
From: <cu...@us...> - 2004-03-11 06:19:44
|
Update of /cvsroot/phphtmllib/phphtmllib/form/form_elements In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1675/form/form_elements Modified Files: FEListBox.inc Log Message: Added several new date form elements: FEMonths FEYears FEDays FEDate FEDate is a container object that contains the other three. FEDate is not complete but I wanted to commit this before I leave. Still need to set up a validation routine for FEDate. Also need to figure out an elegant way to change element order in FEDate. Possibilities include: set_element_order('Ymd') set_year_first() set_year_second() set_year_third() ... What would be best? Also, I ripped the locales for the months from PEAR. Rather than identifier strings should we set up constants for each locale? What do you think about all this? I think you would prefer FECalendar, but this is a simple solution till something like that could be tackled. I haven't even tested submitting the date element yet so that probably doesn't work yet-- so far I have only worked on the display. culley Index: FEListBox.inc =================================================================== RCS file: /cvsroot/phphtmllib/phphtmllib/form/form_elements/FEListBox.inc,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- FEListBox.inc 20 Nov 2003 23:08:34 -0000 1.13 +++ FEListBox.inc 11 Mar 2004 06:01:14 -0000 1.14 @@ -795,4 +795,262 @@ return $c; } } + +/** + * This class builds a FEDataList that shows + * a select box for Months of the year + * + * @author Culley Harrelson <cu...@fa...> + * + */ + +class FEMonths extends FEListBox { + + /** + * The months array divided up by language + * @var array + */ + var $_locale = array( + 'en' => array ( + 'short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), + 'long' => array ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December') + ), + 'de' => array ( + 'short' => array ('Jan', 'Feb', 'März', 'April', 'Mai', 'Juni', 'Juli', 'Aug', 'Sept', 'Okt', 'Nov', 'Dez'), + 'long' => array ('Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember') + ), + 'fr' => array ( + 'short' => array ('Jan', 'Fev', 'Mar', 'Avr', 'Mai', 'Jun', 'Jul', 'Aou', 'Sep', 'Oct', 'Nov', 'Dec'), + 'long' => array ('Janvier', 'Fevrier', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Decembre') + ), + 'hu' => array ( + 'short' => array ('jan', 'feb', 'márc', 'ápr', 'máj', 'jún', 'júl', 'aug', 'szept', 'okt', 'nov', 'dec'), + 'long' => array ('január', 'február', 'március', 'április', 'május', 'június', 'július', 'augusztus', 'szeptember', 'október', 'november', 'december') + ), + 'pl' => array ( + 'short' => array ('Sty', 'Lut', 'Mar', 'Kwi', 'Maj', 'Cze', 'Lip', 'Sie', 'Wrz', 'Pa¼', 'Lis', 'Gru'), + 'long' => array ('Styczeñ', 'Luty', 'Marzec', 'Kwiecieñ', 'Maj', 'Czerwiec', 'Lipiec', 'Sierpieñ', 'Wrzesieñ', 'Pa¼dziernik', 'Listopad', 'Grudzieñ') + ), + 'sl' => array ( + 'short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Avg', 'Sep', 'Okt', 'Nov', 'Dec'), + 'long' => array ('Januar', 'Februar', 'Marec', 'April', 'Maj', 'Junij', 'Julij', 'Avgust', 'September', 'Oktober', 'November', 'December') + ), + 'ru' => array ( + 'short' => array ('ßíâ', 'Ôåâ', 'Ìàð', 'Àïð', 'Ìàé', 'Èþí', 'Èþë', 'Àâã', 'Ñåí', 'Îêò', 'Íîÿ', 'Äåê'), + 'long' => array ('ßíâàðü', 'Ôåâðàëü', 'Ìàðò', 'Àïðåëü', 'Ìàé', 'Èþíü', 'Èþëü', 'Àâãóñò', 'Ñåíòÿáðü', 'Îêòÿáðü', 'Íîÿáðü', 'Äåêàáðü') + ), + 'es' => array ( + 'short' => array ('Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'), + 'long' => array ('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septimbre', 'Octubre', 'Noviembre', 'Diciembre') + ), + 'da' => array ( + 'short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'), + 'long' => array ('Januar', 'Februar', 'Marts', 'April', 'Maj', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'December') + ), + 'is' => array ( + 'short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Maí', 'Jún', 'Júl', 'Ágú', 'Sep', 'Okt', 'Nóv', 'Des'), + 'long' => array ('Janúar', 'Febrúar', 'Mars', 'Apríl', 'Maí', 'Júní', 'Júlí', 'Ágúst', 'September', 'Október', 'Nóvember', 'Desember') + ), + 'it' => array ( + 'short' => array ('Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago', 'Set', 'Ott', 'Nov', 'Dic'), + 'long' => array ('Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre') + ), + 'sk' => array ( + 'short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Máj', 'Jún', 'Júl', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'), + 'long' => array ('Január', 'Február', 'Marec', 'Apríl', 'Máj', 'Jún', 'Júl', 'August', 'September', 'Október', 'November', 'December') + ), + 'cs' => array ( + 'short' => array ('Led', 'Úno', 'Bøe', 'Dub', 'Kvì', 'Èen', 'Èec', 'Srp', 'Záø', 'Øíj', 'Lis', 'Pro'), + 'long' => array ('Leden', 'Únor', 'Bøezen', 'Duben', 'Kvìten', 'Èerven', 'Èervenec', 'Srpen', 'Záøí', 'Øíjen', 'Listopad', 'Prosinec') + ), + 'hy' => array( + 'short' => array ('ÐÝí','öïñ','Øñï','²åñ','ØÛë','ÐÝë','ÐÉë','ú·ë','êåï','ÐÏï','ÜÛÙ','¸Ïï'), + 'long' => array ('ÐáõÝí³ñ','ö»ïñí³ñ','سñï','²åñÇÉ','سÛÇë','ÐáõÝÇë','ÐáõÉÇë','ú·áëïáë','ê»åï»Ùµ»ñ','ÐáÏï»Ùµ»ñ','ÜáÛ»Ùµ»ñ','¸»Ïï»Ùµ»ñ') + ), + 'nl' => array ( + 'short' => array ('Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'), + 'long' => array ('Januari', 'Februari', 'Maart', 'April', 'Mei', 'Juni', 'Juli', 'Augustus', 'September', 'Oktober', 'November', 'December') + ) + ); + + + /** + * The constructor + * + * @param string text label for the element + * @param boolean is this a required element? + * @param int element width in characters, pixels (px), percentage (%) or elements (em) + * @param int element height in px + * @param string locale one of: en, de, hu, pl, sl, ru, es, da, is, it, sk, cs, hy, nl + * @param string format either long or short + */ + function FEMonths($label, $required = TRUE, $width = NULL, $height = NULL, $locale = 'en', $format = 'long') { + $this->FEListBox($label, $required, $width, $height, array_flip($this->_locale[$locale][$format])); + } +} + +/** + * This class builds a FEDataList that shows + * a select box listing a range of years + * + * @author Culley Harrelson <cu...@fa...> + * + */ + +class FEYears extends FEListBox { + + /** + * The constructor + * + * @param string text label for the element + * @param boolean is this a required element? + * @param int element width in characters, pixels (px), percentage (%) or elements (em) + * @param int element height in px + * @param int min_year + * @param int max_year + */ + function FEYears($label, $required = TRUE, $width = NULL, $height = NULL, $min_year = 2000, $max_year = 2010) { + $this->FEListBox($label, $required, $width, $height, array_flip(range($min_year, $max_year))); + } +} + +/** + * This class builds a FEDataList that shows + * a select box listing the days of the month + * + * @author Culley Harrelson <cu...@fa...> + * + */ + +class FEDays extends FEListBox { + + /** + * The constructor + * + * @param string text label for the element + * @param boolean is this a required element? + * @param int element width in characters, pixels (px), percentage (%) or elements (em) + * @param int element height in px + */ + + function FEDays($label, $required = TRUE, $width = NULL, $height = NULL) { + $this->FEListBox($label, $required, $width, $height, array_flip(range(1, 31))); + } +} + +/** + * This class builds a FEDataList that shows + * a select box listing the days of the month + * + * @author Culley Harrelson <cu...@fa...> + * + */ + +class FEDate extends FEBoxElement { + + /** + * The default locale for the month display + * @var string + */ + var $_locale = 'en'; + + /** + * The month format. Default to the long format. + * @var bool + */ + var $_short_months = false; + + /** + * The earliest year shown in the year list. + * @var int + */ + var $_min_year = 2000; + + /** + * The latest year shown in the year list. + * @var string + */ + var $_max_year = 2010; + + /** + * The constructor + * + * @param string text label for the element + * @param boolean is this a required element? + * @param int element width in characters, pixels (px), percentage (%) or elements (em) + * @param int element height in px + */ + + function FEDate($label, $required = TRUE, $width = NULL, $height = NULL) { + $this->FEBoxElement($label, $required, $width, $height); + } + + /** + * This function builds and returns the + * form element object + * + * @return object + */ + function get_element() { + + $month_format = ($this->_short_months) ? 'short' : 'long'; + $container = new Container(); + $years = new FEYears($this->_element_name . '_years', false, null, null, $this->_min_year, $this->_max_year); + $months = new FEMonths($this->_element_name . '_months', false, null, null, $this->_locale, $month_format); + $days = new FEDays($this->_element_name . '_days'); + + $container->add($months->get_element()); + $container->add($days->get_element()); + $container->add($years->get_element()); + + return $container; + + } + + /** + * this method sets the locale for the Month display + * + * @param string locale + */ + function set_locale($locale = 'en') { + + $this->_locale = $locale; + + } + + /** + * this method toggles the month display between short and long format + * + * @param bool + */ + function set_short_months($short_months = true) { + + $this->_short_months = $short_months; + + } + + /** + * this method sets the earliest year shown in the year list + * + * @param int + */ + function set_min_year($min_year) { + + $this->_min_year = $min_year; + + } + + /** + * this method sets the latest year shown in the year list + * + * @param int + */ + function set_max_year($max_year) { + + $this->_max_year = $max_year; + + } + +} + ?> |