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$ */
|
|
|
|
|
|
|
|
/*!
|
2002-10-06 02:15:14 +02:00
|
|
|
@class datefield_widget
|
2002-09-02 13:14:30 +02:00
|
|
|
@author ralfbecker
|
2002-10-06 02:15:14 +02:00
|
|
|
@abstract widget that reads a date
|
|
|
|
@discussion This widget is independent of the UI as it only uses etemplate-widgets and has therefor no render-function
|
2002-05-13 23:30:46 +02:00
|
|
|
*/
|
|
|
|
class date_widget
|
|
|
|
{
|
|
|
|
var $public_functions = array(
|
|
|
|
'pre_process' => True,
|
|
|
|
'post_process' => True
|
|
|
|
);
|
|
|
|
var $human_name = 'Date'; // this is the name for the editor
|
|
|
|
|
2002-10-06 02:15:14 +02:00
|
|
|
function date_widget($ui)
|
2002-05-13 23:30:46 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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-06 02:15:14 +02:00
|
|
|
list($data_format,$options) = explode(',',$cell['size']);
|
|
|
|
$extension_data = $data_format;
|
|
|
|
|
|
|
|
if (!$value)
|
|
|
|
{
|
|
|
|
$value = array(
|
|
|
|
'Y' => '',
|
|
|
|
'm' => '',
|
|
|
|
'd' => ''
|
|
|
|
);
|
|
|
|
}
|
|
|
|
elseif ($data_format != '')
|
2002-05-13 23:30:46 +02:00
|
|
|
{
|
|
|
|
$date = split('[/.-]',$value);
|
2002-10-06 02:15:14 +02:00
|
|
|
$mdy = split('[/.-]',$data_format);
|
2002-05-13 23:30:46 +02:00
|
|
|
for ($value=array(),$n = 0; $n < 3; ++$n)
|
|
|
|
{
|
|
|
|
switch($mdy[$n])
|
|
|
|
{
|
2002-10-06 02:15:14 +02:00
|
|
|
case 'Y': $value['Y'] = $date[$n]; break;
|
|
|
|
case 'm': $value['m'] = $date[$n]; break;
|
|
|
|
case 'd': $value['d'] = $date[$n]; break;
|
2002-05-13 23:30:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-10-06 02:15:14 +02:00
|
|
|
$value = array(
|
|
|
|
'Y' => date('Y',$value),
|
|
|
|
'm' => date('m',$value),
|
|
|
|
'd' => date('d',$value)
|
|
|
|
);
|
2002-05-13 23:30:46 +02:00
|
|
|
}
|
2002-10-12 18:39:10 +02:00
|
|
|
$format = split('[/.-]',$sep=$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
|
|
|
|
$sep = $sep[1];
|
|
|
|
if ($cell['readonly'] || $readonlys) // is readonly
|
|
|
|
{
|
|
|
|
for ($str='',$n = 0; $n < 3; ++$n)
|
|
|
|
{
|
|
|
|
$str .= ($str != '' ? $sep : '');
|
|
|
|
$str .= $value[$format[$n]];
|
|
|
|
}
|
|
|
|
$value = $str;
|
|
|
|
$cell['type'] = 'label';
|
|
|
|
$cell['no_lang'] = True;
|
|
|
|
return True;
|
|
|
|
}
|
2002-10-06 02:15:14 +02:00
|
|
|
$tpl = new etemplate;
|
|
|
|
$tpl->init('*** generated fields for date','','',0,'',0,0); // make an empty template
|
2002-05-13 23:30:46 +02:00
|
|
|
|
2002-10-06 02:15:14 +02:00
|
|
|
$fields = array('Y' => 'year', 'm' => 'month', 'd' => 'day');
|
|
|
|
$row = array();
|
|
|
|
for ($n=0; $n < 3; ++$n)
|
|
|
|
{
|
|
|
|
$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';
|
2002-05-13 23:30:46 +02:00
|
|
|
|
2002-10-06 02:15:14 +02:00
|
|
|
$cell['size'] = $cell['name'];
|
|
|
|
$cell['type'] = 'template';
|
|
|
|
$cell['name'] = $tpl->name;
|
|
|
|
$cell['obj'] = &$tpl;
|
2002-09-27 18:17:39 +02:00
|
|
|
|
2002-10-06 02:15:14 +02:00
|
|
|
return True; // extra Label is ok
|
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-06 02:15:14 +02:00
|
|
|
elseif ($value['Y'] < 100)
|
|
|
|
{
|
|
|
|
$value['Y'] += $value['Y'] < 30 ? 2000 : 1900;
|
|
|
|
}
|
|
|
|
if (empty($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-10-12 18:39:10 +02:00
|
|
|
}
|