forked from extern/egroupware
- new preference number_format, to specify number_format (currently only
used in eTemplate) - added basic support for DateTime / egw_time to eTemplate date-widget
This commit is contained in:
parent
b307d2a5cf
commit
47b2216554
@ -89,6 +89,7 @@ class date_widget
|
||||
*/
|
||||
function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
|
||||
{
|
||||
//echo "<p>".__METHOD__."($name,$value=".egw_time::to($value).",".array2string($cell).")</p>\n";
|
||||
$type = $cell['type'];
|
||||
switch ($type)
|
||||
{
|
||||
@ -123,7 +124,7 @@ class date_widget
|
||||
'i' => '',
|
||||
);
|
||||
}
|
||||
elseif ($data_format != '')
|
||||
elseif (!is_object($value) && $data_format != '') // we ignore format for objects
|
||||
{
|
||||
$date = preg_split('/[- \\/.:,]/',$value);
|
||||
//echo "date=<pre>"; print_r($date); echo "</pre>";
|
||||
@ -155,15 +156,9 @@ class date_widget
|
||||
else
|
||||
{
|
||||
// for the timeformats we use only seconds, no timezone conversation between server-time and UTC
|
||||
if (substr($type,-4) == 'only') $value -= adodb_date('Z',0);
|
||||
if (substr($type,-4) == 'only' && is_numeric($value)) $value -= adodb_date('Z',0);
|
||||
|
||||
$value = array(
|
||||
'Y' => (int) adodb_date('Y',$value),
|
||||
'm' => (int) adodb_date('m',$value),
|
||||
'd' => (int) adodb_date('d',$value),
|
||||
'H' => (int) adodb_date('H',$value),
|
||||
'i' => (int) adodb_date('i',$value)
|
||||
);
|
||||
$value = egw_time::to($value,'date_array');
|
||||
}
|
||||
if ($type == 'date-since')
|
||||
{
|
||||
@ -416,6 +411,11 @@ class date_widget
|
||||
$value = $empty_not_0 && (string) $value === '' || !$empty_not_0 && !$value ? '' :
|
||||
($unit == 'm' ? (int) $value : round($value / 60 / ($unit == 'd' ? $hours_per_day : 1),3));
|
||||
|
||||
// use decimal separator from user prefs
|
||||
if ($GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0] != '.')
|
||||
{
|
||||
$value = str_replace('.',$GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0],$value);
|
||||
}
|
||||
if (!$readonly && strlen($input_format) > 1) // selectbox to switch between hours and days
|
||||
{
|
||||
$value = array(
|
||||
|
@ -1144,8 +1144,7 @@ class etemplate extends boetemplate
|
||||
}
|
||||
if (($type == 'float' || !is_numeric($pre)) && $value && $pre)
|
||||
{
|
||||
$value = str_replace(array(' ',','),array('','.'),$value);
|
||||
$value = is_numeric($pre) ? number_format($value,$pre,'.','') : sprintf($pre,$value);
|
||||
$value = is_numeric($pre) ? self::number_format($value,$pre,$readonly) : sprintf($pre,$value);
|
||||
}
|
||||
$cell_options .= ',,'.($cell['type'] == 'int' ? '/^-?[0-9]*$/' : '/^-?[0-9]*[,.]?[0-9]*$/');
|
||||
// fall-through
|
||||
@ -1790,6 +1789,28 @@ class etemplate extends boetemplate
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a number according to user prefs with decimal and thousands separator (later only for readonly)
|
||||
*
|
||||
* @param int|float|string $number
|
||||
* @param int $num_decimal_places=2
|
||||
* @param boolean $readonly=true
|
||||
* @return string
|
||||
*/
|
||||
static public function number_format($number,$num_decimal_places=2,$readonly=true)
|
||||
{
|
||||
static $dec_separator,$thousands_separator;
|
||||
if (is_null($dec_separator))
|
||||
{
|
||||
$dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0];
|
||||
if (empty($dec_separator)) $dec_separator = '.';
|
||||
$thousands_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][1];
|
||||
}
|
||||
if ((string)$number === '') return '';
|
||||
|
||||
return number_format(str_replace(' ','',$number),$num_decimal_places,$dec_separator,$readonly ? $thousands_separator : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrive options for selectboxes and similar widgets (eg. the tree)
|
||||
*
|
||||
|
@ -353,6 +353,23 @@ class preferences_hooks
|
||||
'admin' => false,
|
||||
'default'=> 'iso-8859-1',
|
||||
),
|
||||
'number_format' => array(
|
||||
'type' => 'select',
|
||||
'label' => 'Number format',
|
||||
'name' => 'number_format',
|
||||
'values' => array(
|
||||
'.' => '1234.56',
|
||||
',' => '1234,56',
|
||||
'.,' => '1,234.56',
|
||||
',.' => '1.234,56',
|
||||
'. ' => '1 234.56',
|
||||
', ' => '1 234,56',
|
||||
),
|
||||
'help' => 'Thousands separator is only used for displaying and not for editing numbers.',
|
||||
'xmlrpc' => True,
|
||||
'admin' => false,
|
||||
'default'=> '.',
|
||||
),
|
||||
);
|
||||
// disable thumbnails, if no size configured by admin
|
||||
if (!$GLOBALS['egw_info']['server']['link_list_thumbnail']) unset($settings['link_list_thumbnail']);
|
||||
|
Loading…
Reference in New Issue
Block a user