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 ('' => '--', 'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septimbre', 'Octubre', 'Noviembre', 'Diciembre')
58 parent::HTML_QuickForm_date($elementName, $elementLabel,
59 array_merge(array('language'=>'es','format'=>'d F Y'), $options),
64 // {{{ _createNumericOptionList()
67 * Creates a numeric option list based on a start number and end number
69 * @param int $start The start number
70 * @param int $end The end number
73 * @return array An array of numeric options.
75 function _createNumericOptionList($start, $end) {
78 //Verificar que esto este funcionando bien.
81 for ($i = $start; $i <= $end; $i++) {
82 $options[$i] = sprintf('%02d', $i);
87 } // end func _createNumericOptionList
90 * Devuelve un objeto date
94 * @return object Date.
96 function &getValue() {
97 if ($this->_selectedDate['Y']) {
98 return new Date (sprintf("%04d-%02d-%02d 00:00:00",$this->_selectedDate['Y'],$this->_selectedDate['F'],$this->_selectedDate['d']));
102 } // end func getValue
105 * Verifica que una fecha sea valida.
107 * Verifica que una fecha sea valida. El formato siempre debe ser
113 function validate($valor, $nombre, $formato = '') {
114 // Si viene completamente lleno, se valida con el paquete Validate.
115 if ($valor['Y'] and $valor['d'] and $valor['F']) {
116 $str = sprintf('%4d-%02d-%02d', $valor['Y'], $valor['F'], $valor['d']);
117 return Validate::date($str, array('format' => '%Y-%m-%d'));
118 // Si viene completamente vacio, es valido.
120 elseif (!$valor['Y'] and !$valor['d'] and !$valor['F']) {
122 // Si viene a medio completar, es invalido.
127 } // end func validate