CMXX - Relative time on created and last login

This commit is contained in:
“VeLiTi”
2024-12-12 15:28:39 +01:00
parent 1b17a98e1f
commit 5e858fb785
13 changed files with 187 additions and 8 deletions

View File

@@ -224,7 +224,7 @@ $view .= '<div class="content-block">
<td>'.$account_hierarchy->soldto.'</td>
</tr>
<td>'.$general_created.'</td>
<td>'.$responses->created.'</td>
<td>'.getRelativeTime($responses->created).'</td>
</tr>
<tr>
<td>'.$general_createdby.'</td>

View File

@@ -2838,3 +2838,77 @@ 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";
}
}

View File

@@ -345,7 +345,7 @@ $view .= '<div class="content-block">
<table>
<tr>
<td style="width:25%;">'.$general_created.'</td>
<td>'.$responses->created.'</td>
<td>'.getRelativeTime($responses->created).'</td>
</tr>
<tr>
<td style="width:25%;">'.$general_createdby.'</td>

View File

@@ -350,6 +350,21 @@ if ($update_allowed === 1){
';
}
$view .= '<div class="content-block">
<div class="block-header">
<i class="fa-solid fa-bars fa-sm"></i>'.$tab3.'
</div>
<div class="table order-table">
<table>
<tr>
<td style="width:25%;">'.$general_created.'</td>
<td>'.getRelativeTime($responses->created).'</td>
</tr>
</table>
</div>
</div>
';
//DISPLAY RELATED COMMUNICATION RECORDS
$soldto_id = explode("-",$partner_data->soldto) ?? '';
$shipto_id = explode("-",$partner_data->shipto) ?? '';

View File

@@ -278,7 +278,7 @@ $view .= '<div class="content-block">
<table>
<tr>
<td style="width:25%;">'.$general_created.'</td>
<td>'.$responses->created.'</td>
<td>'.getRelativeTime($responses->created).'</td>
</tr>
<tr>
<td style="width:25%;">'.$general_createdby.'</td>
@@ -286,7 +286,7 @@ $view .= '<div class="content-block">
</tr>
<tr>
<td style="width:25%;">'.$general_updated.'</td>
<td>'.$responses->updated.'</td>
<td>'.getRelativeTime($responses->updated).'</td>
</tr>
<tr>
<td style="width:25%;">'.$general_updatedby.'</td>

View File

@@ -135,7 +135,7 @@ $view .= '<div class="content-block tab-content">
<label for="">'.$general_created.'</label>
<input id="name" type="text" name="" placeholder="'.$general_created.'" value="'.$user['created'].'" readonly>
<label for="">'.$User_lastlogin.'</label>
<input id="name" type="text" name="" placeholder="'.$User_lastlogin.'" value="'.$user['lastlogin'].'" readonly>
<input id="name" type="text" name="" placeholder="'.$User_lastlogin.'" value="'.getRelativeTime($user['lastlogin']).'" readonly>
</div>
</div>';

View File

@@ -179,9 +179,9 @@ $view .= '
<tr>
<th class="responsive-hidden">'.($rma_rowID ?? 'Request number').'</th>
<th>'.($rma_status ?? 'Status').'</th>
<th>'.$general_created.'</th>
<th>'.getRelativeTime($general_created).'</th>
<th>'.$general_createdby.'</th>
<th>'.$general_updated.'</th>
<th>'.getRelativeTime($general_updated).'</th>
<th>'.$general_actions.'</th>
</tr>
</thead>

View File

@@ -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';

View File

@@ -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';

View File

@@ -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';

View File

@@ -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';

View File

@@ -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';

View File

@@ -156,7 +156,7 @@ $view .= '
<td>'.$partner_hierarchy.'</td>
<td>'.$$permission_user.'</td>
<td>'.$response->settings.'</td>
<td class="responsive-hidden">'.$response->lastlogin.'</td>
<td class="responsive-hidden">'.getRelativeTime($response->lastlogin).'</td>
<td><a href="index.php?page=user&id='.$response->id.'" class="btn_link">'.$general_view .'</a></td>
</tr>
';