1 <?php /* vim: set binary expandtab tabstop=4 shiftwidth=4 textwidth=80:
2 -------------------------------------------------------------------------------
4 -------------------------------------------------------------------------------
5 This file is part of mlib.
7 mlib is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2 of the License, or (at your option)
12 mlib is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License; if not,
17 write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------
20 Creado: jue jun 5 17:59:44 ART 2003
21 Autor: Martin Marrese <mmarre@mecon.gov.ar>
22 -------------------------------------------------------------------------------
24 -----------------------------------------------------------------------------*/
26 require_once 'HTML/QuickForm/date.php';
27 require_once 'Date.php';
28 require_once 'Validate.php';
31 * Class to dynamically create HTML Select elements from a date
32 * Modificado para que cumpla con los requisitos de mecon
35 class MLIB_HTML_QuickForm_mdate extends HTML_QuickForm_date {
41 * @param string $elementName (optional)Input field name attribute
42 * @param string $value (optional)Input field value
43 * @param mixed $attributes (optional)Either a typical HTML attribute string
44 * or an associative array. Date format is passed along the attributes.
48 function MLIB_HTML_QuickForm_mdate($elementName=null, $elementLabel=null, $options=array(), $attributes=null) {
49 $this->_locale = array ('es' => array (
50 'weekdays_short'=> array ('' => '--', 'Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb'),
51 'weekdays_long' => array ('' => '--', 'Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'),
52 'months_short' => array ('' => '--', 'Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'),
53 'months_long' => array ('' => '--',
54 'Enero', 'Febrero', 'Marzo',
55 'Abril', 'Mayo', 'Junio',
56 'Julio', 'Agosto', 'Septiembre',
57 'Octubre', 'Noviembre', 'Diciembre')
60 parent::HTML_QuickForm_date($elementName, $elementLabel,
61 array_merge(array('language'=>'es','format'=>'d F Y'), $options),
66 * Creates an option list containing the numbers from the start number to the end, inclusive
68 * @param int The start number
69 * @param int The end number
70 * @param int Increment by this value
72 * @return array An array of numeric options.
74 function _createOptionList($start, $end, $step = 1) {
75 for ($i = $start, $options = array('' => '--'); $start > $end? $i >= $end: $i <= $end; $i += $step) {
76 $options[$i] = sprintf('%02d', $i);
79 } // end func _createOptionList
82 * Devuelve un objeto date
86 * @return object Date.
88 function &getValue() {
90 $date = parent::getValue();
93 return new Date (@sprintf("%04d-%02d-%02d %02d:%02d:00",
94 $date['Y'][0], $date['F'][0],
95 $date['d'][0], $date['H'][0],
100 } // end func getValue
103 * Verifica que una fecha sea valida.
105 * Verifica que una fecha sea valida. El formato siempre debe ser
111 function validate($valor, $nombre, $formato = '') {
112 // Si viene completamente lleno, se valida con el paquete Validate
113 if ($valor['Y'] and $valor['d'] and $valor['F']) {
114 $str = sprintf('%4d-%02d-%02d', $valor['Y'], $valor['F'], $valor['d']);
115 return Validate::date($str, array('format' => '%Y-%m-%d'));
116 // Si viene completamente vacio, es valido.
118 elseif (!$valor['Y'] and !$valor['d'] and !$valor['F']) {
120 // Si viene a medio completar, es invalido.
125 } // end func validate