forked from extern/egroupware
fix for bug [ 1049574 ] Windows does not support dates prior 1970-01-01
using adodb's datelibary instead of the regular php-functions: date, mktime, ... also added input-validation for dates
This commit is contained in:
parent
8518892d9a
commit
22f7aaf56c
@ -12,18 +12,25 @@
|
|||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*!
|
/**
|
||||||
@class date_widget
|
* eTemplate extension to input or display date and/or time values
|
||||||
@author ralfbecker
|
*
|
||||||
@abstract widget that reads a date and/or time
|
* Contains the following widgets: Date, Date+Time, Time, Hour
|
||||||
@param Options/$cell['size'] = $format[,$options],
|
*
|
||||||
@param $format: ''=timestamp or eg. 'Y-m-d H:i' for 2002-12-31 23:59
|
* Supported attributes: format[,options]
|
||||||
@param $options: &1 = year is int-input not selectbox, &2 = show a [Today] button, \
|
* format: ''=timestamp, or eg. 'Y-m-d H:i' for 2002-12-31 23:59
|
||||||
&4 = 1min steps for time (default is 5min, with fallback to 1min if value is not in 5min-steps),
|
* options: &1 = year is int-input not selectbox, &2 = show a [Today] button, (html-UI always uses jscal and dont care for &1+&2)
|
||||||
&8 = dont show time for readonly and type date-time if time is 0:00,
|
* &4 = 1min steps for time (default is 5min, with fallback to 1min if value is not in 5min-steps),
|
||||||
&16 = prefix r/o display with dow
|
* &8 = dont show time for readonly and type date-time if time is 0:00,
|
||||||
@discussion This widget is independent of the UI as it only uses etemplate-widgets and has therefor no render-function
|
* &16 = prefix r/o display with dow
|
||||||
*/
|
*
|
||||||
|
* This widget is independent of the UI as it only uses etemplate-widgets and has therefor no render-function.
|
||||||
|
* Uses the adodb datelibary to overcome the windows-limitation to not allow dates before 1970
|
||||||
|
*
|
||||||
|
* @package etemplate
|
||||||
|
* @author RalfBecker-AT-outdoor-training.de
|
||||||
|
* @license GPL
|
||||||
|
*/
|
||||||
class date_widget
|
class date_widget
|
||||||
{
|
{
|
||||||
var $public_functions = array(
|
var $public_functions = array(
|
||||||
@ -36,6 +43,8 @@
|
|||||||
'date-timeonly' => 'Time', // time
|
'date-timeonly' => 'Time', // time
|
||||||
'date-houronly' => 'Hour', // hour
|
'date-houronly' => 'Hour', // hour
|
||||||
);
|
);
|
||||||
|
var $dateformat; // eg. Y-m-d, d-M-Y
|
||||||
|
var $timeformat; // 12 or 24
|
||||||
|
|
||||||
function date_widget($ui)
|
function date_widget($ui)
|
||||||
{
|
{
|
||||||
@ -48,6 +57,7 @@
|
|||||||
$this->jscal = &$GLOBALS['phpgw']->jscalendar;
|
$this->jscal = &$GLOBALS['phpgw']->jscalendar;
|
||||||
}
|
}
|
||||||
$this->timeformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat'];
|
$this->timeformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat'];
|
||||||
|
$this->dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
|
||||||
}
|
}
|
||||||
|
|
||||||
function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
|
function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
|
||||||
@ -55,7 +65,10 @@
|
|||||||
$type = $cell['type'];
|
$type = $cell['type'];
|
||||||
list($data_format,$options) = explode(',',$cell['size']);
|
list($data_format,$options) = explode(',',$cell['size']);
|
||||||
if ($type == 'date-houronly' && empty($data_format)) $data_format = 'H';
|
if ($type == 'date-houronly' && empty($data_format)) $data_format = 'H';
|
||||||
$extension_data = $data_format;
|
$extension_data = array(
|
||||||
|
'data_format' => $data_format,
|
||||||
|
'type' => $type,
|
||||||
|
);
|
||||||
|
|
||||||
if (!$value)
|
if (!$value)
|
||||||
{
|
{
|
||||||
@ -88,12 +101,12 @@
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$value = array(
|
$value = array(
|
||||||
'Y' => date('Y',$value),
|
'Y' => adodb_date('Y',$value),
|
||||||
'm' => date('m',$value),
|
'm' => adodb_date('m',$value),
|
||||||
'M' => substr(lang(date('F',$value)),0,3),
|
'M' => substr(lang(adodb_date('F',$value)),0,3),
|
||||||
'd' => date('d',$value),
|
'd' => adodb_date('d',$value),
|
||||||
'H' => date('H',$value),
|
'H' => adodb_date('H',$value),
|
||||||
'i' => date('i',$value)
|
'i' => adodb_date('i',$value)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$time_0h0 = !(int)$value['H'] && !(int)$value['i'];
|
$time_0h0 = !(int)$value['H'] && !(int)$value['i'];
|
||||||
@ -109,7 +122,7 @@
|
|||||||
}
|
}
|
||||||
$timeformat += array(5 => 'a');
|
$timeformat += array(5 => 'a');
|
||||||
}
|
}
|
||||||
$format = split('[/.-]',$sep=$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
|
$format = split('[/.-]',$this->dateformat);
|
||||||
|
|
||||||
$readonly = $cell['readonly'] || $readonlys;
|
$readonly = $cell['readonly'] || $readonlys;
|
||||||
|
|
||||||
@ -121,8 +134,8 @@
|
|||||||
if ($readonly) // is readonly
|
if ($readonly) // is readonly
|
||||||
{
|
{
|
||||||
$sep = array(
|
$sep = array(
|
||||||
1 => $sep[1],
|
1 => $this->dateformat[1],
|
||||||
2 => $sep[1],
|
2 => $this->dateformat[1],
|
||||||
3 => ' ',
|
3 => ' ',
|
||||||
4 => ':'
|
4 => ':'
|
||||||
);
|
);
|
||||||
@ -132,7 +145,7 @@
|
|||||||
{
|
{
|
||||||
if (!$n && $options & 16 )
|
if (!$n && $options & 16 )
|
||||||
{
|
{
|
||||||
$str = lang(date('l',mktime(12,0,0,$value['m'],$value['d'],$value['Y']))).' ';
|
$str = lang(adodb_date('l',adodb_mktime(12,0,0,$value['m'],$value['d'],$value['Y']))).' ';
|
||||||
}
|
}
|
||||||
$str .= ($str != '' ? $sep[$n] : '') . $value[$format[$n]];
|
$str .= ($str != '' ? $sep[$n] : '') . $value[$format[$n]];
|
||||||
}
|
}
|
||||||
@ -209,7 +222,7 @@
|
|||||||
if (($js = $tmpl->java_script()))
|
if (($js = $tmpl->java_script()))
|
||||||
{
|
{
|
||||||
$dcell['needed'] = True; // to get a button
|
$dcell['needed'] = True; // to get a button
|
||||||
$dcell['onchange'] = "this.form.elements['$name"."[Y]'].value='".date('Y')."'; this.form.elements['$name"."[m]'].value='".date('n')."';this.form.elements['$name"."[d]'].value='".(0+date('d'))."'; return false;";
|
$dcell['onchange'] = "this.form.elements['$name"."[Y]'].value='".adodb_date('Y')."'; this.form.elements['$name"."[m]'].value='".adodb_date('n')."';this.form.elements['$name"."[d]'].value='".(0+adodb_date('d'))."'; return false;";
|
||||||
}
|
}
|
||||||
$dcell['type'] = $js ? 'button' : 'checkbox';
|
$dcell['type'] = $js ? 'button' : 'checkbox';
|
||||||
$row[$tpl->num2chrs(++$i)] = &$dcell;
|
$row[$tpl->num2chrs(++$i)] = &$dcell;
|
||||||
@ -254,7 +267,7 @@
|
|||||||
|
|
||||||
function post_process($name,&$value,&$extension_data,&$loop,&$tmpl,$value_in)
|
function post_process($name,&$value,&$extension_data,&$loop,&$tmpl,$value_in)
|
||||||
{
|
{
|
||||||
//echo "<p>date_widget::post_process('$name','$extension_data') value="; print_r($value); echo ", value_in="; print_r($value_in); echo "</p>\n";
|
//echo "<p>date_widget::post_process('$name','$extension_data[type]','$extension_data[data_format]') value="; print_r($value); echo ", value_in="; print_r($value_in); echo "</p>\n";
|
||||||
if (!isset($value) && !isset($value_in))
|
if (!isset($value) && !isset($value_in))
|
||||||
{
|
{
|
||||||
return False;
|
return False;
|
||||||
@ -264,7 +277,7 @@
|
|||||||
$set = array('Y','m','d');
|
$set = array('Y','m','d');
|
||||||
foreach($set as $d)
|
foreach($set as $d)
|
||||||
{
|
{
|
||||||
$value[$d] = date($d);
|
$value[$d] = adodb_date($d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isset($value_in['str']) && !empty($value_in['str']))
|
if (isset($value_in['str']) && !empty($value_in['str']))
|
||||||
@ -282,11 +295,11 @@
|
|||||||
{
|
{
|
||||||
if (!$value['m'])
|
if (!$value['m'])
|
||||||
{
|
{
|
||||||
$value['m'] = date('m');
|
$value['m'] = adodb_date('m');
|
||||||
}
|
}
|
||||||
if (!$value['Y'])
|
if (!$value['Y'])
|
||||||
{
|
{
|
||||||
$value['Y'] = date('Y');
|
$value['Y'] = adodb_date('Y');
|
||||||
}
|
}
|
||||||
elseif ($value['Y'] < 100)
|
elseif ($value['Y'] < 100)
|
||||||
{
|
{
|
||||||
@ -305,15 +318,22 @@
|
|||||||
$value['H'] += 12;
|
$value['H'] += 12;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (empty($extension_data))
|
// checking the date is a correct one
|
||||||
|
if (!checkdate($value['m'],$value['d'],$value['Y']))
|
||||||
{
|
{
|
||||||
$value = mktime(intval($value['H']),intval($value['i']),0,$value['m'],$value['d'],$value['Y']);
|
$GLOBALS['phpgw_info']['etemplate']['validation_errors'][$name] = lang("'%1' is not a valid date !!!",
|
||||||
|
$GLOBALS['phpgw']->common->dateformatorder($value['Y'],$value['m'],$value['d'],true));
|
||||||
|
}
|
||||||
|
$data_format = $extension_data['data_format'];
|
||||||
|
if (empty($data_format))
|
||||||
|
{
|
||||||
|
$value = adodb_mktime((int) $value['H'],(int) $value['i'],0,$value['m'],$value['d'],$value['Y']);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for ($n = 0,$str = ''; $n < strlen($extension_data); ++$n)
|
for ($n = 0,$str = ''; $n < strlen($data_format); ++$n)
|
||||||
{
|
{
|
||||||
if (strstr('YmdHi',$c = $extension_data[$n]))
|
if (strstr('YmdHi',$c = $data_format[$n]))
|
||||||
{
|
{
|
||||||
$str .= sprintf($c=='Y'?'%04d':'%02d',$value[$c]);
|
$str .= sprintf($c=='Y'?'%04d':'%02d',$value[$c]);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
%s onchange etemplate de %s onChange
|
%s onchange etemplate de %s onChange
|
||||||
%s readonly etemplate de %s Schreibschutz
|
%s readonly etemplate de %s Schreibschutz
|
||||||
'%1' has an invalid format !!! etemplate de '%1' hat ein ungültiges Format !!!
|
'%1' has an invalid format !!! etemplate de '%1' hat ein ungültiges Format !!!
|
||||||
|
'%1' is not a valid date !!! etemplate de '%1' ist ein ungültiges Datum !!!
|
||||||
'%1' is not a valid floatingpoint number !!! etemplate de '%1' ist keine gültige Kommazahl !!!
|
'%1' is not a valid floatingpoint number !!! etemplate de '%1' ist keine gültige Kommazahl !!!
|
||||||
'%1' is not a valid integer !!! etemplate de '%1' ist keine gültige Ganzzahl !!!
|
'%1' is not a valid integer !!! etemplate de '%1' ist keine gültige Ganzzahl !!!
|
||||||
a pattern to be searched for etemplate de ein Muster nach dem gesucht werden soll
|
a pattern to be searched for etemplate de ein Muster nach dem gesucht werden soll
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
%s onchange etemplate en %s onChange
|
%s onchange etemplate en %s onChange
|
||||||
%s readonly etemplate en %s readonly
|
%s readonly etemplate en %s readonly
|
||||||
'%1' has an invalid format !!! etemplate en '%1' has an invalid format !!!
|
'%1' has an invalid format !!! etemplate en '%1' has an invalid format !!!
|
||||||
|
'%1' is not a valid date !!! etemplate en '%1' is not a valid date !!!
|
||||||
'%1' is not a valid floatingpoint number !!! etemplate en '%1' is not a valid floatingpoint number !!!
|
'%1' is not a valid floatingpoint number !!! etemplate en '%1' is not a valid floatingpoint number !!!
|
||||||
'%1' is not a valid integer !!! etemplate en '%1' is not a valid integer !!!
|
'%1' is not a valid integer !!! etemplate en '%1' is not a valid integer !!!
|
||||||
a pattern to be searched for etemplate en a pattern to be searched for
|
a pattern to be searched for etemplate en a pattern to be searched for
|
||||||
|
Loading…
Reference in New Issue
Block a user