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->_options = 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')
62 parent::HTML_QuickForm_date($elementName, $elementLabel,
63 array_merge(array('language'=>'es','format'=>'d F Y'), $options),
68 // {{{ _createNumericOptionList()
71 * Creates a numeric option list based on a start number and end number
73 * @param int $start The start number
74 * @param int $end The end number
77 * @return array An array of numeric options.
79 function _createNumericOptionList($start, $end) {
82 //Verificar que esto este funcionando bien.
85 for ($i = $start; $i <= $end; $i++) {
86 $options[$i] = sprintf('%02d', $i);
91 } // end func _createNumericOptionList
94 * Devuelve un objeto date
98 * @return object Date.
100 function &getValue() {
101 if ($this->_selectedDate['Y']) {
102 return new Date (@sprintf("%04d-%02d-%02d %02d:%02d:00",
103 $this->_selectedDate['Y'], $this->_selectedDate['F'],
104 $this->_selectedDate['d'], $this->_selectedDate['H'],
105 $this->_selectedDate['i']));
109 } // end func getValue
112 * Verifica que una fecha sea valida.
114 * Verifica que una fecha sea valida. El formato siempre debe ser
120 function validate($valor, $nombre, $formato = '') {
121 // Si viene completamente lleno, se valida con el paquete Validate.
122 if ($valor['Y'] and $valor['d'] and $valor['F']) {
123 $str = sprintf('%4d-%02d-%02d', $valor['Y'], $valor['F'], $valor['d']);
124 return Validate::date($str, array('format' => '%Y-%m-%d'));
125 // Si viene completamente vacio, es valido.
127 elseif (!$valor['Y'] and !$valor['d'] and !$valor['F']) {
129 // Si viene a medio completar, es invalido.
134 } // end func validate