From 28acb7f004653adfd20a4c3679a3d13ff5db30e7 Mon Sep 17 00:00:00 2001 From: "o.pinke" Date: Tue, 4 Jul 2023 20:04:48 +0200 Subject: [PATCH] use html5 datetime field --- .../frontendusers/valid_from/valid_from.php | 57 +++++++------------ .../frontendusers/valid_to/valid_to.php | 49 +++++++--------- 2 files changed, 41 insertions(+), 65 deletions(-) diff --git a/conlite/plugins/frontendusers/valid_from/valid_from.php b/conlite/plugins/frontendusers/valid_from/valid_from.php index d699af8..6357417 100644 --- a/conlite/plugins/frontendusers/valid_from/valid_from.php +++ b/conlite/plugins/frontendusers/valid_from/valid_from.php @@ -10,34 +10,26 @@ function frontendusers_valid_from_getTitle () function frontendusers_valid_from_display () { - global $feuser,$db,$belang; + global $feuser; $template = '%s'; - - $currentValue = $feuser->get("valid_from"); - - if ($currentValue == '') { - $currentValue = '1000-01-01'; + + $currentValue = $feuser->get("valid_from"); + + if($currentValue == "0000-00-00 00:00:00" || $currentValue == "") { + $currentValue = null; + } else { + $datetime = new DateTime($currentValue); + $currentValue = $datetime->format('Y-m-d\TH:i'); } - $currentValue = str_replace('00:00:00', '', $currentValue); - - $sValidFrom = ' - - -'; - $sValidFrom .= ' '; - $sValidFrom .= ''; - + + $sValidFrom = ''; + return sprintf($template,$sValidFrom); } @@ -54,14 +46,7 @@ function frontendusers_valid_from_wantedVariables () */ function frontendusers_valid_from_store ($variables) { global $feuser; - - if(Contenido_Security::isMySQLDate($variables["valid_from"], true) - || Contenido_Security::isMySQLDateTime($variables["valid_from"], true) - || empty($variables["valid_from"]) - || $variables["valid_from"] == "0000-00-00" - || $variables["valid_from"] == "1000-01-01") { - - $feuser->set("valid_from", $variables["valid_from"], false); - } -} -?> + if(!is_null($variables["valid_from"])) { + $feuser->set("valid_from", $variables["valid_from"], false); + } +} \ No newline at end of file diff --git a/conlite/plugins/frontendusers/valid_to/valid_to.php b/conlite/plugins/frontendusers/valid_to/valid_to.php index d3008fd..6e3cad9 100644 --- a/conlite/plugins/frontendusers/valid_to/valid_to.php +++ b/conlite/plugins/frontendusers/valid_to/valid_to.php @@ -7,33 +7,30 @@ function frontendusers_valid_to_getTitle () return i18n("Valid to"); } +/** + * @throws Exception + */ function frontendusers_valid_to_display () { - global $feuser,$db,$belang; + global $feuser; $template = '%s'; $currentValue = $feuser->get("valid_to"); - - if ($currentValue == '') { - $currentValue = '1000-01-01'; + + if($currentValue == "0000-00-00 00:00:00" || $currentValue == "") { + $currentValue = ''; + } else { + $datetime = new DateTime($currentValue); + $currentValue = $datetime->format('Y-m-d\TH:i'); } - $currentValue = str_replace('00:00:00', '', $currentValue); - - // js-includes are defined in valid_from - $sValidFrom = ' '; - $sValidFrom .= ''; - + + $sValidFrom = ''; return sprintf($template,$sValidFrom); } @@ -50,14 +47,8 @@ function frontendusers_valid_to_wantedVariables () */ function frontendusers_valid_to_store ($variables) { global $feuser; - - if(Contenido_Security::isMySQLDate($variables["valid_to"], true) - || Contenido_Security::isMySQLDateTime($variables["valid_to"], true) - || empty($variables["valid_to"]) - || $variables["valid_to"] == "0000-00-00" - || $variables["valid_to"] == "1000-01-01") { - + + if(!is_null($variables["valid_to"])) { $feuser->set("valid_to", $variables["valid_to"], false); } -} -?> +} \ No newline at end of file