From 3ea0e3202a73eb7efcbf0b825582a6d3504658aa Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Fri, 01 Sep 2006 09:43:14 -0400
Subject: [PATCH] Quota display as image

---
 program/include/rcube_shared.inc |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/program/include/rcube_shared.inc b/program/include/rcube_shared.inc
index 768ae3f..af4c295 100644
--- a/program/include/rcube_shared.inc
+++ b/program/include/rcube_shared.inc
@@ -1299,12 +1299,25 @@
   }
 
 
-function show_bytes($numbytes)
+// create a human readable string for a number of bytes
+function show_bytes($bytes)
   {
-  if ($numbytes > 1024)
-    return sprintf('%d KB', round($numbytes/1024));
+  if ($bytes > 1073741824)
+    {
+    $gb = $bytes/1073741824;
+    $str = sprintf($gb>=10 ? "%d GB" : "%.1f GB", $gb);
+    }
+  else if ($bytes > 1048576)
+    {
+    $mb = $bytes/1048576;
+    $str = sprintf($mb>=10 ? "%d MB" : "%.1f MB", $mb);
+    }
+  else if ($bytes > 1024)
+    $str = sprintf("%d KB",  round($bytes/1024));
   else
-    return sprintf('%d B', $numbytes);
+    $str = sprintf('%d B', $bytes);
+
+  return $str;
   }
 
 

--
Gitblit v1.9.1