2002-05-13 23:30:46 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare - eTemplate Extension - Date Widget *
|
|
|
|
* http://www.phpgroupware.org *
|
|
|
|
* Written by Ralf Becker <RalfBecker@outdoor-training.de> *
|
|
|
|
* -------------------------------------------- *
|
|
|
|
* This program is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU General Public License as published by the *
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your *
|
|
|
|
* option) any later version. *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@class date_widget
|
2002-09-02 13:14:30 +02:00
|
|
|
@author ralfbecker
|
2002-05-13 23:30:46 +02:00
|
|
|
@abstract widget that reads dates in via 3 select-boxes
|
2002-09-02 13:14:30 +02:00
|
|
|
@discussion This widget is generates html vi the sbox-class, so it does not work (without an extra implementation) in an other UI
|
2002-05-13 23:30:46 +02:00
|
|
|
*/
|
|
|
|
class date_widget
|
|
|
|
{
|
|
|
|
var $public_functions = array(
|
|
|
|
'pre_process' => True,
|
|
|
|
'render' => True,
|
|
|
|
'post_process' => True
|
|
|
|
);
|
|
|
|
var $human_name = 'Date'; // this is the name for the editor
|
|
|
|
|
2002-09-27 18:17:39 +02:00
|
|
|
function date_widget($ui='')
|
2002-05-13 23:30:46 +02:00
|
|
|
{
|
|
|
|
switch($ui)
|
|
|
|
{
|
|
|
|
case '':
|
|
|
|
case 'html':
|
|
|
|
$this->ui = 'html';
|
|
|
|
break;
|
|
|
|
case 'gtk':
|
|
|
|
$this->ui = 'gtk';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return "UI='$ui' not implemented";
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-01 20:26:30 +02:00
|
|
|
function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
|
2002-05-13 23:30:46 +02:00
|
|
|
{
|
2002-10-01 20:26:30 +02:00
|
|
|
$extension_data = $cell['size'];
|
2002-05-13 23:30:46 +02:00
|
|
|
if ($cell['size'] != '')
|
|
|
|
{
|
|
|
|
$date = split('[/.-]',$value);
|
|
|
|
$mdy = split('[/.-]',$cell['size']);
|
|
|
|
for ($value=array(),$n = 0; $n < 3; ++$n)
|
|
|
|
{
|
|
|
|
switch($mdy[$n])
|
|
|
|
{
|
|
|
|
case 'Y': $value[0] = $date[$n]; break;
|
|
|
|
case 'm': $value[1] = $date[$n]; break;
|
|
|
|
case 'd': $value[2] = $date[$n]; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$value = array(date('Y',$value),date('m',$value),date('d',$value));
|
|
|
|
}
|
|
|
|
return True; // extra Label is ok
|
|
|
|
}
|
|
|
|
|
2002-09-27 18:17:39 +02:00
|
|
|
function render(&$cell,$form_name,&$value,$readonly,&$extension_data,&$tmpl)
|
2002-05-13 23:30:46 +02:00
|
|
|
{
|
|
|
|
$func = 'render_'.$this->ui;
|
|
|
|
|
2002-09-27 18:17:39 +02:00
|
|
|
if (!method_exists($this,$func))
|
|
|
|
return False;
|
|
|
|
|
|
|
|
return $this->$func($cell,$form_name,$value,$readonly,$tmpl);
|
2002-05-13 23:30:46 +02:00
|
|
|
}
|
|
|
|
|
2002-10-01 20:26:30 +02:00
|
|
|
function post_process($name,&$value,&$extension_data,&$loop,&$tmpl)
|
2002-05-13 23:30:46 +02:00
|
|
|
{
|
|
|
|
if (!isset($value))
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
if ($value['d'])
|
|
|
|
{
|
|
|
|
if (!$value['m'])
|
|
|
|
{
|
|
|
|
$value['m'] = date('m');
|
|
|
|
}
|
|
|
|
if (!$value['Y'])
|
|
|
|
{
|
|
|
|
$value['Y'] = date('Y');
|
|
|
|
}
|
2002-10-01 20:26:30 +02:00
|
|
|
if ($extension_data)
|
2002-05-13 23:30:46 +02:00
|
|
|
{
|
|
|
|
$value = mktime(0,0,0,$value['m'],$value['d'],$value['Y']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-10-01 20:26:30 +02:00
|
|
|
for ($n = 0,$str = ''; $n < strlen($extension_data); ++$n)
|
2002-05-13 23:30:46 +02:00
|
|
|
{
|
2002-10-01 20:26:30 +02:00
|
|
|
if (strstr('Ymd',$c = $extension_data[$n]))
|
2002-05-13 23:30:46 +02:00
|
|
|
{
|
|
|
|
$str .= sprintf($c=='Y'?'%04d':'%02d',$value[$c]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$str .= $c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$value = $str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$value = '';
|
|
|
|
}
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2002-09-27 18:17:39 +02:00
|
|
|
function render_html($cell,$form_name,$value,$readonly,&$tmpl)
|
2002-05-13 23:30:46 +02:00
|
|
|
{
|
|
|
|
if ($readonly)
|
|
|
|
{
|
|
|
|
return $GLOBALS['phpgw']->common->dateformatorder($value[0],$value[1],$value[2],True);
|
|
|
|
}
|
2002-09-27 18:17:39 +02:00
|
|
|
return $tmpl->sbox->getDate($form_name.'[Y]',$form_name.'[m]',$form_name.'[d]',$value,$options);
|
2002-05-13 23:30:46 +02:00
|
|
|
}
|
|
|
|
}
|