1 <?php /* vim: set binary expandtab tabstop=4 shiftwidth=4 textwidth=80:
2 -------------------------------------------------------------------------------
5 -------------------------------------------------------------------------------
6 This file is part of meconlib.
8 meconlib is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2 of the License, or (at your option)
13 meconlib is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License; if not,
18 write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 Boston, MA 02111-1307 USA
20 -------------------------------------------------------------------------------
21 Creado: jue jun 5 17:59:44 ART 2003
22 Autor: Martin Marrese <mmarre@mecon.gov.ar>
23 -------------------------------------------------------------------------------
25 -----------------------------------------------------------------------------*/
27 require_once 'HTML/QuickForm/date.php';
28 require_once 'Date.php';
29 require_once 'Validate.php';
32 * Class to dynamically create HTML Select elements from a date
33 * Modificado para que cumpla con los requisitos de mecon
36 class MECON_HTML_QuickForm_mdate extends HTML_QuickForm_date {
42 * @param string $elementName (optional)Input field name attribute
43 * @param string $value (optional)Input field value
44 * @param mixed $attributes (optional)Either a typical HTML attribute string
45 * or an associative array. Date format is passed along the attributes.
49 function MECON_HTML_QuickForm_mdate($elementName=null, $elementLabel=null, $options=array(), $attributes=null) {
50 $this->_locales = array ('es' => array (
51 'weekdays_short'=> array ('' => '--', 'Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb'),
52 'weekdays_long' => array ('' => '--', 'Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'),
53 'months_short' => array ('' => '--', 'Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'),
54 'months_long' => array ('' => '--',
55 'Enero', 'Febrero', 'Marzo',
56 'Abril', 'Mayo', 'Junio',
57 'Julio', 'Agosto', 'Septiembre',
58 'Octubre', 'Noviembre', 'Diciembre')
61 parent::HTML_QuickForm_date($elementName, $elementLabel,
62 array_merge(array('language'=>'es','format'=>'d F Y'), $options),
67 // {{{ _createNumericOptionList()
70 * Creates a numeric option list based on a start number and end number
72 * @param int $start The start number
73 * @param int $end The end number
76 * @return array An array of numeric options.
78 function _createNumericOptionList($start, $end) {
81 //Verificar que esto este funcionando bien.
84 for ($i = $start; $i <= $end; $i++) {
85 $options[$i] = sprintf('%02d', $i);
90 } // end func _createNumericOptionList
93 * Devuelve un objeto date
97 * @return object Date.
99 function &getValue() {
100 if ($this->_selectedDate['Y']) {
101 return new Date (@sprintf("%04d-%02d-%02d %02d:%02d:00",
102 $this->_selectedDate['Y'], $this->_selectedDate['F'],
103 $this->_selectedDate['d'], $this->_selectedDate['H'],
104 $this->_selectedDate['i']));
108 } // end func getValue
111 * Verifica que una fecha sea valida.
113 * Verifica que una fecha sea valida. El formato siempre debe ser
119 function validate($valor, $nombre, $formato = '') {
120 // Si viene completamente lleno, se valida con el paquete Validate.
121 if ($valor['Y'] and $valor['d'] and $valor['F']) {
122 $str = sprintf('%4d-%02d-%02d', $valor['Y'], $valor['F'], $valor['d']);
123 return Validate::date($str, array('format' => '%Y-%m-%d'));
124 // Si viene completamente vacio, es valido.
126 elseif (!$valor['Y'] and !$valor['d'] and !$valor['F']) {
128 // Si viene a medio completar, es invalido.
133 } // end func validate