[imp] Patch: IMP CVS-HEAD quota reporting

Michael Cochrane mike@graftonhall.co.nz
Tue, 23 Jul 2002 15:30:53 +0100


And a patch to implement the rest of the changes:

 - Mike :-)

Index: imp/lib/Quota.php
===================================================================
RCS file: /httpd/horde/imp/lib/Quota.php,v
retrieving revision 1.3
diff -I$Horde -I$Revision -I$Date -u -r1.3 Quota.php
--- imp/lib/Quota.php	2002/07/22 17:03:07	1.3
+++ imp/lib/Quota.php	2002/07/23 14:28:39
@@ -102,10 +102,15 @@
      */
     function _quotaHtml($used, $total)
     {
-        $used = $used / (1024 * 1024.0);
-        $total = $total / (1024 * 1024.0);
+        if (!empty($used) && !empty($total)) {
+            $used = $used / (1024 * 1024.0);
+            $total = $total / (1024 * 1024.0);
 
-        $percent = ($used * 100) / $total;
+            $percent = ($used * 100) / $total;
+        } else {
+            $percent = false;
+        }
+
         if ($percent >= 90) {
             $class = 'quotaalert';
         } elseif ($percent >= 75) {
@@ -114,7 +119,11 @@
             $class = 'control';
         }
 
-        $message = sprintf("%.2fMB / %.2fMB  (%.2f%%)", $used, $total, $percent);
+        if ($percent !== false) {
+            $message = sprintf(_("Quota status:")) . sprintf(" %.2fMB / %.2fMB
 (%.2f%%)", $used, $total, $percent);
+        } else {
+            $message = sprintf(_("Quota status: NO LIMIT"));
+        }
         
         include IMP_TEMPLATES . '/quota/quota.inc';
     }


Quoting Michael Cochrane <mike@graftonhall.co.nz>:

> I have a different patch that covers some of the same issues with the units
> in a
> slightly nicer way....  this will probably get wrapped weird but it
> multiplies
> all the values in courier.php and cyrus.php byt 1024 to get them to bytes... 
> 
> as other qouta driver (like the 'awk' method and my mdaemon one) will be able
> to
> calculate quotas in bytes so why loose precision earlier than need be... 
> 
> - Mike :-)
> 
> Index: imp/lib/Quota/courier.php
> ===================================================================
> RCS file: /repository/imp/lib/Quota/courier.php,v
> retrieving revision 1.1
> diff -I$Horde -I$Revision -I$Date -r1.1 courier.php
> 50c50
> <                 return $this->_quotaHTML($quota['usage'], $quota['limit']);
> ---
> >                 return $this->_quotaHTML($quota['usage'] * 1024,
> $quota['limit'] * 1024);
> Index: imp/lib/Quota/cyrus.php
> ===================================================================
> RCS file: /repository/imp/lib/Quota/cyrus.php,v
> retrieving revision 1.1
> diff -I$Horde -I$Revision -I$Date -r1.1 cyrus.php
> 56c56
> <                 return $this->_quotaHTML($quota['usage'], $quota['limit']);
> ---
> >                 return $this->_quotaHTML($quota['usage'] * 1024,
> $quota['limit'] * 1024);
> 
> 
> 
> Quoting Leena Heino <Leena.Heino@uta.fi>:
> 
> > This patch fixes:
> > - In Cyrus IMAP if user has unlimited mailquota then getquota returns
> > empty values.
> > - Quota values should be calculated to MB not GB
> > - Adds text "Quota status:" before quota usage values.
> > 
> > --- imp/lib/Quota.php.orig	Mon Jul 22 20:03:07 2002
> > +++ imp/lib/Quota.php	Tue Jul 23 16:53:28 2002
> > @@ -102,10 +102,14 @@
> >       */
> >      function _quotaHtml($used, $total)
> >      {
> > -        $used = $used / (1024 * 1024.0);
> > -        $total = $total / (1024 * 1024.0);
> > +	if ($used != "" && total != "") {
> > +            $used = $used / 1024.0;
> > +            $total = $total / 1024.0;
> > +            $percent = ($used * 100) / $total;
> > +	} else {
> > +            $percent = 0;
> > +        }
> > 
> > -        $percent = ($used * 100) / $total;
> >          if ($percent >= 90) {
> >              $class = 'quotaalert';
> >          } elseif ($percent >= 75) {
> > @@ -114,7 +118,11 @@
> >              $class = 'control';
> >          }
> > 
> > -        $message = sprintf("%.2fMB / %.2fMB  (%.2f%%)", $used, $total,
> > $percent);
> > +	if ($used != "" && total != "") {
> > +            $message = sprintf(_("Quota status:")) . sprintf(" %.2fMB /
> > %.2fMB  (%.2f%%)", $used, $total, $percent);
> > +	} else {
> > +            $message = sprintf(_("Quota status: NO LIMIT"));
> > +        }
> > 
> >          include IMP_TEMPLATES . '/quota/quota.inc';
> >      }
> > 
> > -- 
> >   -- Leena Heino (liinu at uta.fi)
> > 
> > 
> > -- 
> > IMP mailing list
> > Frequently Asked Questions: http://horde.org/faq/
> > To unsubscribe, mail: imp-unsubscribe@lists.horde.org
> 
> 
> -- 
> 
> Everybody is somebody else's weirdo.
> signature from Siglets.com
> 
> -------------------------------------------------------------------------
> This mail sent from Mike's CVS HEAD install of IMP: http://horde.org/imp/
> 
> 
> -- 
> IMP mailing list
> Frequently Asked Questions: http://horde.org/faq/
> To unsubscribe, mail: imp-unsubscribe@lists.horde.org


-- 

Do not hit at all if it can be avoided, but never hit softly. - Theodore Roosevelt
signature from Siglets.com

-------------------------------------------------------------------------
This mail sent from Mike's CVS HEAD install of IMP: http://horde.org/imp/