fixed date-widget for 12h timeformat:

- replaced extra am/pm radio buttons with single selectbox with times includeing am/pm (works much better with the existing layouts)
- fixed wired 12h clock: 12am,1am-11am,12pm,1pm-11pm (0-23h)
- added an select-hour widget to the select-widgets for the above
This commit is contained in:
Ralf Becker 2006-06-22 16:14:08 +00:00
parent 19f65c4c0a
commit 12e821b883
2 changed files with 19 additions and 30 deletions

View File

@ -105,7 +105,7 @@
'm' => '',
'd' => '',
'H' => '',
'i' => ''
'i' => '',
);
}
elseif ($data_format != '')
@ -142,21 +142,17 @@
}
$time_0h0 = !(int)$value['H'] && !(int)$value['i'];
$readonly = $cell['readonly'] || $readonlys;
$timeformat = array(3 => 'H', 4 => 'i');
if ($this->timeformat == '12')
if ($this->timeformat == '12' && $readonly && $value['H'] !== '')
{
$value['a'] = $value['H'] < 12 ? 'am' : 'pm';
if ($value['H'] > 12)
{
$value['H'] -= 12;
}
$value['H'] = $value['H'] % 12 ? $value['H'] % 12 : 12; // no leading 0 and 0h => 12am
$timeformat += array(5 => 'a');
}
$format = split('[/.-]',$this->dateformat);
$readonly = $cell['readonly'] || $readonlys;
// no time also if $options&8 and readonly and time=0h0
if ($type != 'date' && !($readonly && ($options & 8) && $time_0h0))
{
@ -164,6 +160,8 @@
}
if ($readonly) // is readonly
{
if ($value['H'] === '') unset($value['a']); // no am/pm if no hour set
$sep = array(
1 => $this->dateformat[1],
2 => $this->dateformat[1],
@ -209,7 +207,7 @@
'm' => 'select-month',
'M' => 'select-month',
'd' => 'select-day',
'H' => 'select-number',
'H' => 'select-hour',
'i' => 'select-number'
);
$opts = array(
@ -282,19 +280,6 @@
unset($dcell);
}
if ($type == 'date-houronly') $n++; // no minutes
if ($n == 4 && $type != 'date' && $this->timeformat == '12')
{
$dcell = $tpl->empty_cell();
$dcell['type'] = 'radio';
$dcell['name'] = 'a';
$dcell['help'] = $cell['help'];
$dcell['size'] = $dcell['label'] = 'am';
$row[$tpl->num2chrs(++$i)] = $dcell;
$dcell['size'] = $dcell['label'] = 'pm';
$row[$tpl->num2chrs(++$i)] = &$dcell;
unset($dcell);
}
}
$tpl->data[0] = array();
$tpl->data[1] = &$row;
@ -525,13 +510,6 @@
$value['d'] = $value['m'] = 1;
$value['Y'] = 1970;
}
if (isset($value['a']))
{
if ($value['a'] == 'pm' && $value['H'] < 12)
{
$value['H'] += 12;
}
}
// checking the date is a correct one
if (!checkdate($value['m'],$value['d'],$value['Y']))
{

View File

@ -47,6 +47,7 @@
'select-month' => 'Select Month',
'select-day' => 'Select Day',
'select-dow' => 'Select Day of week',
'select-hour' => 'Select Hour', // either 0-23 or 0am-11am,12pm,1pm-11pm
'select-number' => 'Select Number',
'select-app' => 'Select Application'
);
@ -426,6 +427,16 @@
$cell['no_lang'] = True;
break;
case 'select-hour':
for ($h = 0; $h <= 23; ++$h)
{
$cell['sel_options'][$h] = $GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ?
(($h % 12 ? $h % 12 : 12).' '.($h < 12 ? lang('am') : lang('pm'))) :
sprintf('%02d',$h);
}
$cell['no_lang'] = True;
break;
case 'select-app': // type2: ''=users enabled apps, 'installed', 'all' = not installed ones too
$apps = array();
foreach ($GLOBALS['egw_info']['apps'] as $app => $data)