From 57ae1959301de9b0d2d8cbedbed8918b91788614 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Mon, 18 Jan 2021 21:22:29 +0100 Subject: [PATCH] for percentage calculation always use bytes so we don't compare KiB with GiB or similar Signed-off-by: Michael Kaufmann --- admin_index.php | 10 +++++++++- customer_index.php | 11 ++++++++++- templates/Sparkle/admin/index/index.tpl | 4 ++-- templates/Sparkle/customer/index/index.tpl | 6 +++--- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/admin_index.php b/admin_index.php index f677e55c..2dcd7aae 100644 --- a/admin_index.php +++ b/admin_index.php @@ -77,7 +77,9 @@ if ($page == 'overview') { $overview = Database::pexecute_first($overview_stmt, $params); $dec_places = Settings::Get('panel.decimal_places'); + $overview['traffic_bytes_used'] = $overview['traffic_used'] * 1024; $overview['traffic_used'] = \Froxlor\PhpHelper::sizeReadable($overview['traffic_used'] * 1024, null, 'bi'); + $overview['diskspace_bytes_used'] = $overview['diskspace_used'] * 1024; $overview['diskspace_used'] = \Froxlor\PhpHelper::sizeReadable($overview['diskspace_used'] * 1024, null, 'bi'); $number_domains_stmt = Database::prepare(" @@ -113,11 +115,17 @@ if ($page == 'overview') { } $dec_places = Settings::Get('panel.decimal_places'); + // get everything in bytes for the percentage calculation on the dashboard + $userinfo['diskspace_bytes'] = ($userinfo['diskspace'] > -1) ? $userinfo['diskspace'] * 1024 : -1; + $userinfo['diskspace_bytes_used'] = $userinfo['diskspace_used'] * 1024; + $userinfo['traffic_bytes'] = ($userinfo['traffic'] > -1) ? $userinfo['traffic'] * 1024 : - 1; + $userinfo['traffic_bytes_used'] = $userinfo['traffic_used'] * 1024; + $userinfo['diskspace'] = ($userinfo['diskspace'] > -1) ? \Froxlor\PhpHelper::sizeReadable($userinfo['diskspace'] * 1024, null, 'bi') : - 1; $userinfo['diskspace_used'] = \Froxlor\PhpHelper::sizeReadable($userinfo['diskspace_used'] * 1024, null, 'bi'); $userinfo['traffic'] = ($userinfo['traffic'] > -1) ? \Froxlor\PhpHelper::sizeReadable($userinfo['traffic'] * 1024, null, 'bi') : - 1; $userinfo['traffic_used'] = \Froxlor\PhpHelper::sizeReadable($userinfo['traffic_used'] * 1024, null, 'bi'); - $userinfo = \Froxlor\PhpHelper::strReplaceArray('-1', $lng['customer']['unlimited'], $userinfo, 'customers domains diskspace traffic mysqls emails email_accounts email_forwarders email_quota ftps subdomains'); + $userinfo = \Froxlor\PhpHelper::strReplaceArray('-1', $lng['customer']['unlimited'], $userinfo, 'customers domains diskspace diskspace_bytes traffic traffic_bytes mysqls emails email_accounts email_forwarders email_quota ftps subdomains'); $userinfo['custom_notes'] = ($userinfo['custom_notes'] != '') ? nl2br($userinfo['custom_notes']) : ''; diff --git a/customer_index.php b/customer_index.php index 105a1fa8..96e533ed 100644 --- a/customer_index.php +++ b/customer_index.php @@ -93,21 +93,30 @@ if ($page == 'overview') { 'cid' => $userinfo['customerid'] )); + // get everything in bytes for the percentage calculation on the dashboard + $userinfo['diskspace_bytes'] = ($userinfo['diskspace'] > -1) ? $userinfo['diskspace'] * 1024 : -1; + $userinfo['traffic_bytes'] = ($userinfo['traffic'] > -1) ? $userinfo['traffic'] * 1024 : - 1; + $userinfo['traffic_bytes_used'] = $userinfo['traffic_used'] * 1024; + if ($usages) { $userinfo['diskspace_used'] = \Froxlor\PhpHelper::sizeReadable($usages['webspace'] * 1024, null, 'bi'); $userinfo['mailspace_used'] = \Froxlor\PhpHelper::sizeReadable($usages['mail'] * 1024, null, 'bi'); $userinfo['dbspace_used'] = \Froxlor\PhpHelper::sizeReadable($usages['mysql'] * 1024, null, 'bi'); $userinfo['total_used'] = \Froxlor\PhpHelper::sizeReadable(($usages['webspace'] + $usages['mail'] + $usages['mysql']) * 1024, null, 'bi'); + $userinfo['diskspace_bytes_used'] = $usages['webspace'] * 1024; + $userinfo['total_bytes_used'] = ($usages['webspace'] + $usages['mail'] + $usages['mysql']) * 1024; } else { $userinfo['diskspace_used'] = 0; $userinfo['mailspace_used'] = 0; $userinfo['dbspace_used'] = 0; $userinfo['total_used'] = 0; + $userinfo['diskspace_bytes_used'] = 0; + $userinfo['total_bytes_used'] = 0; } $userinfo['diskspace'] = ($userinfo['diskspace'] > -1) ? \Froxlor\PhpHelper::sizeReadable($userinfo['diskspace'] * 1024, null, 'bi') : - 1; $userinfo['traffic'] = ($userinfo['traffic'] > -1) ? \Froxlor\PhpHelper::sizeReadable($userinfo['traffic'] * 1024, null, 'bi') : - 1; $userinfo['traffic_used'] = \Froxlor\PhpHelper::sizeReadable($userinfo['traffic_used'] * 1024, null, 'bi'); - $userinfo = \Froxlor\PhpHelper::strReplaceArray('-1', $lng['customer']['unlimited'], $userinfo, 'diskspace traffic mysqls emails email_accounts email_forwarders email_quota ftps subdomains'); + $userinfo = \Froxlor\PhpHelper::strReplaceArray('-1', $lng['customer']['unlimited'], $userinfo, 'diskspace diskspace_bytes traffic traffic_bytes mysqls emails email_accounts email_forwarders email_quota ftps subdomains'); $userinfo['custom_notes'] = ($userinfo['custom_notes'] != '') ? nl2br($userinfo['custom_notes']) : ''; diff --git a/templates/Sparkle/admin/index/index.tpl b/templates/Sparkle/admin/index/index.tpl index 858c7a5d..1b14a334 100644 --- a/templates/Sparkle/admin/index/index.tpl +++ b/templates/Sparkle/admin/index/index.tpl @@ -45,7 +45,7 @@ $header
- +
{$lng['customer']['diskspace']}
@@ -58,7 +58,7 @@ $header
- +
{$lng['customer']['traffic']}
diff --git a/templates/Sparkle/customer/index/index.tpl b/templates/Sparkle/customer/index/index.tpl index 21d3b79d..f649e2ff 100644 --- a/templates/Sparkle/customer/index/index.tpl +++ b/templates/Sparkle/customer/index/index.tpl @@ -9,7 +9,7 @@ $header
- +
{$lng['customer']['total_diskspace']}
@@ -37,7 +37,7 @@ $header
- +
{$lng['customer']['diskspace']}
@@ -51,7 +51,7 @@ $header
- +
{$lng['customer']['traffic']}