From 5e858fb785fe84c0e1948f139ae1630f70731fbe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CVeLiTi=E2=80=9D?= <“info@veliti.nl”>
Date: Thu, 12 Dec 2024 15:28:39 +0100
Subject: [PATCH] CMXX - Relative time on created and last login
---
account.php | 2 +-
assets/functions.php | 74 +++++++++++++++++++++++
contract.php | 2 +-
equipment.php | 15 +++++
product.php | 4 +-
profile.php | 2 +-
rmas.php | 4 +-
settings/translations/translations_DE.php | 18 ++++++
settings/translations/translations_ES.php | 18 ++++++
settings/translations/translations_NL.php | 18 ++++++
settings/translations/translations_PT.php | 18 ++++++
settings/translations/translations_US.php | 18 ++++++
users.php | 2 +-
13 files changed, 187 insertions(+), 8 deletions(-)
diff --git a/account.php b/account.php
index 5959e2e..138f30b 100644
--- a/account.php
+++ b/account.php
@@ -224,7 +224,7 @@ $view .= '
| '.$account_hierarchy->soldto.' |
'.$general_created.' |
-
'.$responses->created.' |
+
'.getRelativeTime($responses->created).' |
| '.$general_createdby.' |
diff --git a/assets/functions.php b/assets/functions.php
index b4a125f..f15059e 100644
--- a/assets/functions.php
+++ b/assets/functions.php
@@ -2837,4 +2837,78 @@ function getLatestVersion($productcode,$token){
//DEFAULT OUTPUT
return $responses;
+}
+
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
+// Timestamp converter ++++++++++++++
+// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
+function getRelativeTime($timestamp) {
+
+ //GET TRANSLATION FILE
+ if(isset($_SESSION['country_code'])){
+ $api_file_language = dirname(__FILE__,2).'/settings/translations/translations_'.strtoupper($_SESSION['country_code']).'.php';
+ if (file_exists($api_file_language)){
+ include $api_file_language; //Include the code
+ }
+ else {
+ include dirname(__FILE__,2).'/settings/translations/translations_US.php';
+ }
+ }
+ else {
+ include dirname(__FILE__,2).'/settings/translations/translations_US.php';
+ }
+
+ // Ensure the timestamp is a valid integer
+ $timestamp = is_numeric($timestamp) ? $timestamp : strtotime($timestamp);
+
+ // Get current timestamp and calculate difference
+ $now = time();
+ $diff = $now - $timestamp;
+
+ // Define time periods
+ $minute = 60;
+ $hour = $minute * 60;
+ $day = $hour * 24;
+ $week = $day * 7;
+ $month = $day * 30;
+ $year = $day * 365;
+
+ // Handle future timestamps
+ if ($diff < 0) {
+ $diff = abs($diff);
+ $suffix = $time_from_now;
+ } else {
+ $suffix = $time_ago;
+ }
+
+ // Determine the appropriate time description
+ if ($diff < $minute) {
+ return $time_just_now;
+ } elseif ($diff < $hour) {
+ $minutes = floor($diff / $minute);
+ return $minutes.$time_minute . ($minutes != 1 ? $time_minutes : '') . " $suffix";
+ } elseif ($diff < $day) {
+ $hours = floor($diff / $hour);
+ return $hours.$time_hour . ($hours != 1 ? $time_hours : '') . " $suffix";
+ } elseif ($diff < $week) {
+ $days = floor($diff / $day);
+
+ // Special handling for today and yesterday
+ if ($days == 0) {
+ return $time_today;
+ } elseif ($days == 1) {
+ return $time_yesterday;
+ }
+
+ return $days.(($days != 1)?$time_days:$time_day) . " $suffix";
+ } elseif ($diff < $month) {
+ $weeks = floor($diff / $week);
+ return $weeks.(($weeks != 1)?$time_weeks:$time_week) . " $suffix";
+ } elseif ($diff < $year) {
+ $months = floor($diff / $month);
+ return $months.(($months != 1)?$time_months:$time_month) . " $suffix";
+ } else {
+ $years = floor($diff / $year);
+ return $years.(($years != 1)?$time_years:$time_year) . " $suffix";
+ }
}
\ No newline at end of file
diff --git a/contract.php b/contract.php
index aa8a03e..7dad873 100644
--- a/contract.php
+++ b/contract.php
@@ -345,7 +345,7 @@ $view .= '
| '.$general_created.' |
- '.$responses->created.' |
+ '.getRelativeTime($responses->created).' |
| '.$general_createdby.' |
diff --git a/equipment.php b/equipment.php
index 224915a..a21f837 100644
--- a/equipment.php
+++ b/equipment.php
@@ -350,6 +350,21 @@ if ($update_allowed === 1){
';
}
+$view .= '
+
+
+
+
+ | '.$general_created.' |
+ '.getRelativeTime($responses->created).' |
+
+
+
+
+';
+
//DISPLAY RELATED COMMUNICATION RECORDS
$soldto_id = explode("-",$partner_data->soldto) ?? '';
$shipto_id = explode("-",$partner_data->shipto) ?? '';
diff --git a/product.php b/product.php
index f18ddaf..b067d12 100644
--- a/product.php
+++ b/product.php
@@ -278,7 +278,7 @@ $view .= '
| '.$general_created.' |
- '.$responses->created.' |
+ '.getRelativeTime($responses->created).' |
| '.$general_createdby.' |
@@ -286,7 +286,7 @@ $view .= '
| '.$general_updated.' |
- '.$responses->updated.' |
+ '.getRelativeTime($responses->updated).' |
| '.$general_updatedby.' |
diff --git a/profile.php b/profile.php
index 1d05f0e..f9e9d1b 100644
--- a/profile.php
+++ b/profile.php
@@ -135,7 +135,7 @@ $view .= '
-
+
';
diff --git a/rmas.php b/rmas.php
index d0ff180..2437f2b 100644
--- a/rmas.php
+++ b/rmas.php
@@ -179,9 +179,9 @@ $view .= '
| '.($rma_rowID ?? 'Request number').' |
'.($rma_status ?? 'Status').' |
- '.$general_created.' |
+ '.getRelativeTime($general_created).' |
'.$general_createdby.' |
- '.$general_updated.' |
+ '.getRelativeTime($general_updated).' |
'.$general_actions.' |
diff --git a/settings/translations/translations_DE.php b/settings/translations/translations_DE.php
index 8b043dc..f92005c 100644
--- a/settings/translations/translations_DE.php
+++ b/settings/translations/translations_DE.php
@@ -79,6 +79,24 @@ $general_logout = 'Abmelden';
$general_yes = 'Ja';
$general_no = 'Nein';
+$time_from_now = 'von jetzt';
+$time_ago = 'her';
+$time_just_now = 'gerade eben';
+$time_minute = ' Minute';
+$time_hour = ' Stunde';
+$time_minutes = ' Minuten';
+$time_hours = ' Stunden';
+$time_today = 'heute';
+$time_yesterday = 'gestern';
+$time_day = ' Tag';
+$time_week = ' Woche';
+$time_month = ' Monat';
+$time_year = ' Jahr';
+$time_days = ' Tage';
+$time_weeks = ' Wochen';
+$time_months = ' Monate';
+$time_years = ' Jahre';
+
$button_apply = 'Anwenden';
$button_cancel = 'Abbrechen';
$button_back = 'Zurück';
diff --git a/settings/translations/translations_ES.php b/settings/translations/translations_ES.php
index f1116fb..d712ef8 100644
--- a/settings/translations/translations_ES.php
+++ b/settings/translations/translations_ES.php
@@ -79,6 +79,24 @@ $general_logout = 'Cerrar sesión';
$general_yes = 'Sí';
$general_no = 'No';
+$time_from_now = 'desde ahora';
+$time_ago = 'atrás';
+$time_just_now = 'justo ahora';
+$time_minute = ' minuto';
+$time_hour = ' hora';
+$time_minutes = ' minutos';
+$time_hours = ' horas';
+$time_today = 'hoy';
+$time_yesterday = 'ayer';
+$time_day = ' día';
+$time_week = ' semana';
+$time_month = ' mes';
+$time_year = ' año';
+$time_days = ' días';
+$time_weeks = ' semanas';
+$time_months = ' meses';
+$time_years = ' años';
+
$button_apply = 'Aplicar';
$button_cancel = 'Cancelar';
$button_back = 'Regresar';
diff --git a/settings/translations/translations_NL.php b/settings/translations/translations_NL.php
index 1f6fc18..72038bd 100644
--- a/settings/translations/translations_NL.php
+++ b/settings/translations/translations_NL.php
@@ -80,6 +80,24 @@ $general_logout = 'Uitloggen';
$general_yes = 'Ja';
$general_no = 'Nee';
+$time_from_now = 'van nu';
+$time_ago = 'geleden';
+$time_just_now = 'zojuist';
+$time_minute = ' minuut';
+$time_hour = ' uur';
+$time_minutes = ' minuten';
+$time_hours = ' uren';
+$time_today = 'vandaag';
+$time_yesterday = 'gisteren';
+$time_day = ' dag';
+$time_week = ' week';
+$time_month = ' maand';
+$time_year = ' jaar';
+$time_days = ' dagen';
+$time_weeks = ' weken';
+$time_months = ' maanden';
+$time_years = ' jaren';
+
$button_apply = 'Toepassen';
$button_cancel = 'Terug';
$button_back = 'Terug';
diff --git a/settings/translations/translations_PT.php b/settings/translations/translations_PT.php
index 3811e46..4d1b401 100644
--- a/settings/translations/translations_PT.php
+++ b/settings/translations/translations_PT.php
@@ -79,6 +79,24 @@ $general_logout = 'Sair';
$general_yes = 'Não';
$general_no = 'Ruim';
+$time_from_now = 'a partir de agora';
+$time_ago = 'atrás';
+$time_just_now = 'agora mesmo';
+$time_minute = ' minuto';
+$time_hour = ' hora';
+$time_minutes = ' minutos';
+$time_hours = ' horas';
+$time_today = 'hoje';
+$time_yesterday = 'ontem';
+$time_day = ' dia';
+$time_week = ' semana';
+$time_month = ' mês';
+$time_year = ' ano';
+$time_days = ' dias';
+$time_weeks = ' semanas';
+$time_months = ' meses';
+$time_years = ' anos';
+
$button_apply = 'Aplicar';
$button_cancel = 'Cancelar';
$button_back = 'Voltar';
diff --git a/settings/translations/translations_US.php b/settings/translations/translations_US.php
index fb16ec8..b275b8a 100644
--- a/settings/translations/translations_US.php
+++ b/settings/translations/translations_US.php
@@ -79,6 +79,24 @@ $general_logout = 'Logout';
$general_yes = 'Yes';
$general_no = 'No';
+$time_from_now = 'from now';
+$time_ago = 'ago';
+$time_just_now = 'just now';
+$time_minute = ' minute';
+$time_hour = ' hour';
+$time_minutes = ' minutes';
+$time_hours = ' hours';
+$time_today = 'today';
+$time_yesterday ='yesterday';
+$time_day = ' day';
+$time_week = ' week';
+$time_month = ' month';
+$time_year = ' year';
+$time_days = ' days';
+$time_weeks = ' weeks';
+$time_months = ' months';
+$time_years = ' years';
+
$button_apply = 'Apply';
$button_cancel = 'Cancel';
$button_back = 'Back';
diff --git a/users.php b/users.php
index 01af64a..6fceda8 100644
--- a/users.php
+++ b/users.php
@@ -156,7 +156,7 @@ $view .= '
'.$partner_hierarchy.' |
'.$$permission_user.' |
'.$response->settings.' |
- '.$response->lastlogin.' |
+ '.getRelativeTime($response->lastlogin).' |
'.$general_view .' |
';