Index: admin_templates/incs/form_blocks.tpl =================================================================== --- admin_templates/incs/form_blocks.tpl (revision 14590) +++ admin_templates/incs/form_blocks.tpl (working copy) @@ -381,6 +381,35 @@ + + + + + + " + style="cursor: pointer; margin-right: 5px" + title="Date selector" + /> + () + + + + + + + + Index: kernel/utility/formatters/date_formatter.php =================================================================== --- kernel/utility/formatters/date_formatter.php (revision 14596) +++ kernel/utility/formatters/date_formatter.php (working copy) @@ -43,7 +43,7 @@ function SetMixedFormat(&$field_options, &$format, $type) { if (!isset($field_options[$type])) { - // default value is date+sepatator+time + // default value is date+separator+time $field_options[$type] = '_regional_DateTimeFormat'; } @@ -101,7 +101,7 @@ } /** - * The method is supposed to alter config options or cofigure object in some way based on its usage of formatters + * The method is supposed to alter config options or configure object in some way based on its usage of formatters * The methods is called for every field with formatter defined when configuring item. * Could be used for adding additional VirtualFields to an object required by some special Formatter * @@ -119,37 +119,39 @@ $field_options['use_timezone'] = true; } - $add_fields = Array(); + // 1. add field to indicate, that date is already combined into one field + $add_fields = Array ( + $field_name . '_combined' => Array ('type' => 'int', 'default' => 0), + ); - // 1. add DATE virtual field + // 2. add DATE virtual field $opts = Array('master_field' => $field_name, 'formatter' => 'kDateFormatter', 'format' => $display_format['date'], 'input_format' => $input_format['date']); $copy_options = Array ('type', 'default', 'required', 'use_timezone', 'error_msgs'); foreach ($copy_options as $copy_option) { - if (array_key_exists($copy_option, $field_options) ) { + if ( array_key_exists($copy_option, $field_options) ) { $opts[$copy_option] = $field_options[$copy_option]; } } - $add_fields[$field_name.'_date'] = $opts; + $add_fields[$field_name . '_date'] = $opts; - // 2. add TIME virtual field + // 3. add TIME virtual field $opts['format'] = $display_format['time']; $opts['input_format'] = $input_format['time']; - $add_fields[$field_name.'_time'] = $opts; + $add_fields[$field_name . '_time'] = $opts; $filter_type = getArrayValue($field_options, 'filter_type'); - if($filter_type == 'range') - { + if ( $filter_type == 'range' ) { $opts['format'] = $field_options['format']; - $add_fields[$field_name.'_rangefrom'] = $opts; - $add_fields[$field_name.'_rangeto'] = $opts; + $add_fields[$field_name . '_rangefrom'] = $opts; + $add_fields[$field_name . '_rangeto'] = $opts; } if ( !$object->isVirtualField($field_name) ) { - // adding caluclated field to format date directly in the query - $object->addCalculatedField($field_name.'_date', '%1$s.'.$field_name); - $object->addCalculatedField($field_name.'_time', '%1$s.'.$field_name); + // adding calculated field to format date directly in the query + $object->addCalculatedField($field_name . '_date', '%1$s.' . $field_name); + $object->addCalculatedField($field_name . '_time', '%1$s.' . $field_name); } $virtual_fields = $object->getVirtualFields(); @@ -191,20 +193,28 @@ */ function UpdateMasterFields($field, $value, &$options, &$object) { - // when in master field - set own value from sub_fields - if ( $sub_fields = getArrayValue($options, 'sub_fields') ) { - // if date is not empty, but time is empty - set time to 0, otherwise master field fomratter will complain - // when we have only date field on form, we need time hidden field always empty, don't ask me why! - if ($object->GetDBField($sub_fields['date']) != '' && $object->GetDBField($sub_fields['time']) == '') { - $empty_time = getArrayValue($options,'empty_time'); - if ($empty_time === false) { + $sub_fields = getArrayValue($options, 'sub_fields'); + $master_field = getArrayValue($options, 'master_field'); + + if ( $master_field ) { + // when in one of sub_fields - call update for master_field to update its value from sub_fields [are you following ? :) ] + $opt = $object->GetFieldOptions($master_field); + $this->UpdateMasterFields($master_field, null, $opt, $object); + } + elseif ( $sub_fields && !$object->GetDBField($field . '_combined') ) { + // when in master field - set own value from sub_fields + if ( $object->GetDBField($sub_fields['date']) != '' && $object->GetDBField($sub_fields['time']) == '' ) { + // when time is not supplied, then use "midnight" (or unit config override) + $empty_time = getArrayValue($options, 'empty_time'); + if ( $empty_time === false ) { $empty_time = adodb_mktime(0, 0, 0); } $object->SetDBField($sub_fields['time'], $empty_time); } - elseif ($object->GetDBField($sub_fields['time']) != '' && $object->GetDBField($sub_fields['date']) == '') { - $empty_date = getArrayValue($options,'empty_date'); - if ($empty_date === false) { + elseif ( $object->GetDBField($sub_fields['time']) != '' && $object->GetDBField($sub_fields['date']) == '' ) { + // when date is not supplied, then use "1970-01-01 00:00:00" instead (or unit config override) + $empty_date = getArrayValue($options, 'empty_date'); + if ( $empty_date === false ) { $empty_date = adodb_mktime(0, 0, 0, 1, 1, 1970); } $object->SetDBField($sub_fields['date'], $empty_date); @@ -213,13 +223,8 @@ $input_format['date'] = $object->GetFieldOption($sub_fields['date'], 'input_format'); $input_format['time'] = $object->GetFieldOption($sub_fields['time'], 'input_format'); - $object->SetField($field, $object->GetField($sub_fields['date'], $input_format['date']).$options['date_time_separator'].$object->GetField($sub_fields['time'], $input_format['time'])); + $object->SetField($field, $object->GetField($sub_fields['date'], $input_format['date']) . $options['date_time_separator'] . $object->GetField($sub_fields['time'], $input_format['time'])); } - // when in one of sub_fields - call update for master_field to update its value from sub_fields [are you following ? :) ] - elseif ($master_field = getArrayValue($options, 'master_field') ) { - $opt = $object->GetFieldOptions($master_field); - $this->UpdateMasterFields($master_field, null, $opt, $object); - } } /**