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->_locale = 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 * Creates an option list containing the numbers from the start number to the end, inclusive
69 * @param int The start number
70 * @param int The end number
71 * @param int Increment by this value
73 * @return array An array of numeric options.
75 function _createOptionList($start, $end, $step = 1) {
76 for ($i = $start, $options = array('' => '--'); $start > $end? $i >= $end: $i <= $end; $i += $step) {
77 $options[$i] = sprintf('%02d', $i);
80 } // end func _createOptionList
83 * Devuelve un objeto date
87 * @return object Date.
89 function &getValue() {
91 $date = parent::getValue();
94 return new Date (@sprintf("%04d-%02d-%02d %02d:%02d:00",
95 $date['Y'], $date['F'],
96 $date['d'], $date['H'],
101 } // end func getValue
104 * Verifica que una fecha sea valida.
106 * Verifica que una fecha sea valida. El formato siempre debe ser
112 function validate($valor, $nombre, $formato = '') {
113 // Si viene completamente lleno, se valida con el paquete Validate.
114 if ($valor['Y'] and $valor['d'] and $valor['F']) {
115 $str = sprintf('%4d-%02d-%02d', $valor['Y'], $valor['F'], $valor['d']);
116 return Validate::date($str, array('format' => '%Y-%m-%d'));
117 // Si viene completamente vacio, es valido.
119 elseif (!$valor['Y'] and !$valor['d'] and !$valor['F']) {
121 // Si viene a medio completar, es invalido.
126 } // end func validate