mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-27 08:19:45 +01:00
new coded useing select-day, -month, -year
This commit is contained in:
parent
2a39737dc2
commit
ee4ac7ac0b
@ -13,69 +13,85 @@
|
|||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@class date_widget
|
@class datefield_widget
|
||||||
@author ralfbecker
|
@author ralfbecker
|
||||||
@abstract widget that reads dates in via 3 select-boxes
|
@abstract widget that reads a date
|
||||||
@discussion This widget is generates html vi the sbox-class, so it does not work (without an extra implementation) in an other UI
|
@discussion This widget is independent of the UI as it only uses etemplate-widgets and has therefor no render-function
|
||||||
*/
|
*/
|
||||||
class date_widget
|
class date_widget
|
||||||
{
|
{
|
||||||
var $public_functions = array(
|
var $public_functions = array(
|
||||||
'pre_process' => True,
|
'pre_process' => True,
|
||||||
'render' => True,
|
|
||||||
'post_process' => True
|
'post_process' => True
|
||||||
);
|
);
|
||||||
var $human_name = 'Date'; // this is the name for the editor
|
var $human_name = 'Date'; // this is the name for the editor
|
||||||
|
|
||||||
function date_widget($ui='')
|
function date_widget($ui)
|
||||||
{
|
{
|
||||||
switch($ui)
|
|
||||||
{
|
|
||||||
case '':
|
|
||||||
case 'html':
|
|
||||||
$this->ui = 'html';
|
|
||||||
break;
|
|
||||||
case 'gtk':
|
|
||||||
$this->ui = 'gtk';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return "UI='$ui' not implemented";
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
|
function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
|
||||||
{
|
{
|
||||||
$extension_data = $cell['size'];
|
list($data_format,$options) = explode(',',$cell['size']);
|
||||||
if ($cell['size'] != '')
|
$extension_data = $data_format;
|
||||||
|
|
||||||
|
if (!$value)
|
||||||
|
{
|
||||||
|
$value = array(
|
||||||
|
'Y' => '',
|
||||||
|
'm' => '',
|
||||||
|
'd' => ''
|
||||||
|
);
|
||||||
|
}
|
||||||
|
elseif ($data_format != '')
|
||||||
{
|
{
|
||||||
$date = split('[/.-]',$value);
|
$date = split('[/.-]',$value);
|
||||||
$mdy = split('[/.-]',$cell['size']);
|
$mdy = split('[/.-]',$data_format);
|
||||||
for ($value=array(),$n = 0; $n < 3; ++$n)
|
for ($value=array(),$n = 0; $n < 3; ++$n)
|
||||||
{
|
{
|
||||||
switch($mdy[$n])
|
switch($mdy[$n])
|
||||||
{
|
{
|
||||||
case 'Y': $value[0] = $date[$n]; break;
|
case 'Y': $value['Y'] = $date[$n]; break;
|
||||||
case 'm': $value[1] = $date[$n]; break;
|
case 'm': $value['m'] = $date[$n]; break;
|
||||||
case 'd': $value[2] = $date[$n]; break;
|
case 'd': $value['d'] = $date[$n]; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$value = array(date('Y',$value),date('m',$value),date('d',$value));
|
$value = array(
|
||||||
}
|
'Y' => date('Y',$value),
|
||||||
return True; // extra Label is ok
|
'm' => date('m',$value),
|
||||||
|
'd' => date('d',$value)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
$tpl = new etemplate;
|
||||||
|
$tpl->init('*** generated fields for date','','',0,'',0,0); // make an empty template
|
||||||
|
|
||||||
function render(&$cell,$form_name,&$value,$readonly,&$extension_data,&$tmpl)
|
$format = split('[/.-]',$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
|
||||||
|
$fields = array('Y' => 'year', 'm' => 'month', 'd' => 'day');
|
||||||
|
$row = array();
|
||||||
|
for ($n=0; $n < 3; ++$n)
|
||||||
{
|
{
|
||||||
$func = 'render_'.$this->ui;
|
$dcell = $tpl->empty_cell();
|
||||||
|
$dcell['type'] = 'select-'.$fields[$format[$n]];
|
||||||
|
$dcell['name'] = $format[$n];
|
||||||
|
$dcell['help'] = lang($fields[$format[$n]]).': '.$cell['help']; // note: no lang on help, already done
|
||||||
|
$dcell['no_lang'] = True;
|
||||||
|
$row[$tpl->num2chrs($n)] = &$dcell;
|
||||||
|
unset($dcell);
|
||||||
|
}
|
||||||
|
$tpl->data[0] = array();
|
||||||
|
$tpl->data[1] = &$row;
|
||||||
|
$tpl->set_rows_cols();
|
||||||
|
$tpl->size = ',,,,0';
|
||||||
|
|
||||||
if (!method_exists($this,$func))
|
$cell['size'] = $cell['name'];
|
||||||
return False;
|
$cell['type'] = 'template';
|
||||||
|
$cell['name'] = $tpl->name;
|
||||||
|
$cell['obj'] = &$tpl;
|
||||||
|
|
||||||
return $this->$func($cell,$form_name,$value,$readonly,$tmpl);
|
return True; // extra Label is ok
|
||||||
}
|
}
|
||||||
|
|
||||||
function post_process($name,&$value,&$extension_data,&$loop,&$tmpl)
|
function post_process($name,&$value,&$extension_data,&$loop,&$tmpl)
|
||||||
@ -94,7 +110,11 @@
|
|||||||
{
|
{
|
||||||
$value['Y'] = date('Y');
|
$value['Y'] = date('Y');
|
||||||
}
|
}
|
||||||
if ($extension_data)
|
elseif ($value['Y'] < 100)
|
||||||
|
{
|
||||||
|
$value['Y'] += $value['Y'] < 30 ? 2000 : 1900;
|
||||||
|
}
|
||||||
|
if (empty($extension_data))
|
||||||
{
|
{
|
||||||
$value = mktime(0,0,0,$value['m'],$value['d'],$value['Y']);
|
$value = mktime(0,0,0,$value['m'],$value['d'],$value['Y']);
|
||||||
}
|
}
|
||||||
@ -120,13 +140,4 @@
|
|||||||
}
|
}
|
||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
|
|
||||||
function render_html($cell,$form_name,$value,$readonly,&$tmpl)
|
|
||||||
{
|
|
||||||
if ($readonly)
|
|
||||||
{
|
|
||||||
return $GLOBALS['phpgw']->common->dateformatorder($value[0],$value[1],$value[2],True);
|
|
||||||
}
|
|
||||||
return $tmpl->sbox->getDate($form_name.'[Y]',$form_name.'[m]',$form_name.'[d]',$value,$options);
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user