From e195de79fd8077e640c89facf2cf942c2a81cc48 Mon Sep 17 00:00:00 2001 From: Lester Caine Date: Mon, 18 May 2026 09:09:12 +0100 Subject: Move from jscalendar to browser based date and time picker --- smartyplugins/function.bit_select_datetime.php | 122 ++++++------------------- 1 file changed, 27 insertions(+), 95 deletions(-) diff --git a/smartyplugins/function.bit_select_datetime.php b/smartyplugins/function.bit_select_datetime.php index 77e20a8..6d06905 100755 --- a/smartyplugins/function.bit_select_datetime.php +++ b/smartyplugins/function.bit_select_datetime.php @@ -3,116 +3,48 @@ namespace Bitweaver\Plugins; /** * Smarty plugin - * - * - * + * * @package Smarty * @subpackage plugins */ /** - * smarty_function_bit_select_datetime - * - * NOTE: This code looks good but needs intensive testing, especially with different date/time formats. - * - * This function generates HTML code that adds a date picker to an HTML form. - * Depending on Bitweaver settings (Administration/Themes/Theme Settings) - * this can be the ordinary Smarty way of date/time picking (see html_select_date and html_select_time functions) - * or a nice javascript calendar. + * smarty_function_bit_select_datetime * - * Parameters: - * name The name of the inputfield. Use this to identify the date/datetime input from other inputs. (will be used for - * {formlabel label="Test JSCalendar"} - * {forminput} - * {bit_select_datetime name="mydate2" time=$gContent->mInfo.start} - * {/forminput} - * - * - * Later, in edit.php, use this code to obtain the timestamp in UTC: - * $timestamp = $gBitSystem->mServerTimestamp->getUTCFromDisplayDate(_REQUEST['mydate2']) + * Parameters: + * name Field name. Defaults to 'date'. A hidden field with this name carries the Unix timestamp. + * showtime Show time selector. 'true' (default) or 'false'. + * time Unix timestamp to display. Defaults to now. * + * Server usage: $_REQUEST[$name] contains a Unix timestamp. */ function smarty_function_bit_select_datetime( $pParams, &$gBitSmarty ) { - global $gBitSystem; - global $gBitUser; - - // Default values - $name = 'date'; // ID of the input field - // unsupported as of now $format = $gBitSystem->getConfig( 'site_short_date_format' ).' '.$gBitSystem->getConfig( 'site_short_time_format' ); // date format used - $showtime = 'true'; //true: show time; false: pick date only - $time = time(); // override the currently set date + global $gBitSystem, $gBitUser; - //extract actual parameters from the params hashmap. + $name = 'date'; + $showtime = 'true'; + $time = time(); extract( $pParams ); - //calculate a name we can use for additional (internal) fields - $nname = str_replace('[', '_', str_replace(']', '_', $name)); - - if( $gBitSystem->isFeatureActive( 'site_use_jscalendar' ) ) { - // A readonly field will be used to display the currently selected value. - //A button besides the field will bring up the calendar (style similar to other PIM rich client applications) - //It is the readonly input field that will be evaluated back on the server + $nname = str_replace( ['[', ']'], '_', $name ); + $time = (int) $time; + $dtId = "{$nname}_dt"; + $tsId = "{$nname}_ts"; - //unsupported $format = preg_replace( "/%Z/", "", $format ); // JSCalendar does not know about time zones - $html_result = "\n"; - $html_result .= "\n"; - $html_result .= "\n"; + if( $showtime === 'true' ) { + $dtValue = date( 'Y-m-d\TH:i', $time ); + $inputType = 'datetime-local'; } else { - // $gBitSmarty->loadPlugin( 'smarty_modifier_html_select_date' ); - // $gBitSmarty->loadPlugin( 'smarty_modifier_html_select_time' ); - - // we use html_select_date and html_select_time to pick a date, which generate a number of select fields. - //On every change a hidden field will be updated via javascript. - //it's the hidden field that is evaluated back on the server. - - $pDate = [ - 'prefix' => $nname, - 'all_extra' => "onchange=\"bit_select_datetime_{$nname}()\"", - 'time' => $time, - ]; - - $pTime = [ - 'prefix' => $nname, - 'all_extra' => "onchange=\"bit_select_datetime_{$nname}()\"", - 'display_seconds' => false, - 'time' => $time, - ]; - - $html_result = ""; - $html_result .= smarty_function_html_select_date( $pDate, $gBitSmarty ); - if( $showtime == 'true' ) { - $html_result .= smarty_function_html_select_time( $pTime, $gBitSmarty ); - $html_result .= "\n"; - } else { - $html_result .= "\n"; - } + $dtValue = date( 'Y-m-d', $time ); + $inputType = 'date'; } - return $html_result."(".$gBitUser->getPreference('site_display_utc').")\n"; + // Display input updates the hidden Unix-timestamp field on change. + $html = "\n"; + $html .= "\n"; + + return $html . "(" . $gBitUser->getPreference( 'site_display_utc' ) . ")\n"; } -- cgit v1.3