[imp] IMP Quota Display

Alain Fauconnet alain at ait.ac.th
Tue Aug 17 00:16:16 PDT 2004


On Tue, Aug 17, 2004 at 08:02:10AM +0600, Gajen Anandamuruga wrote:
> Hi all
>  
> I am using Horde with IMP on Red Hat 8
>  
> I tried the function about the 'show_imp-quota' to display the quota in the
> IMP login.  I am using soft quota for all my users. How far this function is
> accurate?
>  
> Is there are any better functions similar to the quota displayed in Yahoo
> mail so that the quota can be displayed in graphical format with percentage?

I use the PHP code below. Can't remember where I've found this one.
It's been modified to find the current quota and usage  for  the  user
from the MySQL DB we keep this in (we don't use filesystem quotas,  we
have our  own  quota  system).  So  you  have  to  adapt  it  to  your
environment. The part that draws the quota bar is unmodified, though.
It requires the GD module in PHP.

Greets,
_Alain_

----------------------- quotabar.php --------------------------------
<?

//
//  quotabar 0.2 (c) 2001 nick ustinov (nick at inbox.lv)
//
//  use this lib to display user's mailbox used/quota bar
//  this lib requires gd with png support installed in php
//  tested with imp 2.3.7-cvs
//
//  quick usage:
//
//      1) modify variables below
//      2) <img src="http://www.yourhost.com/pathtoquotabat/quotabar.php?imapuser=###user###">
// 
//      for example, to show it up in imp, insert it somewhere like this:
//              <img src=http://www.yourhost.com/horde/imp/quotabar.php?imapuser
=$HTTP_SESSION_VARS['imp']['user']>
//
//

// -- modify!

$db_host = '127.0.0.1';
$db_name = 'disk_quota';
$db_table = 'disk_usage';
$db_user = 'xxxxxxx';
$db_passwd = 'xxxxxxx';

$width = 150;
$height = 16;

// -- do not modify below!

function quota_bar($taken, $total, $width, $height) {
//    if ($taken>$total) $taken=$total;
    $bar_end = $taken*$width/$total;
    $im = ImageCreate ($width, $height);
    $background_color = ImageColorAllocate ($im, 255, 255, 255);
    $text_color = ImageColorAllocate ($im, 255, 255, 255);
    $free_color = ImageColorAllocate ($im, 150, 150, 150);
    
    $percent=$taken*100/$total;
    
    $taken_color = ImageColorAllocate ($im, 0, 153, 0); 
    if ($percent>=50) { $taken_color = ImageColorAllocate ($im, 255, 255, 51);
                        $text_color = ImageColorAllocate ($im, 0, 0, 0);
                     }
    if ($percent>=70) { $taken_color = ImageColorAllocate ($im, 255, 153, 51);
                        $text_color = ImageColorAllocate ($im, 255, 255, 255);
                     }
    if ($percent>=90) { $taken_color = ImageColorAllocate ($im, 255, 0, 0);
                        $text_color = ImageColorAllocate ($im, 255, 255, 255);
                     }
    
    ImageFilledRectangle($im, 0, 0, $bar_end, $height, $taken_color);
    ImageFilledRectangle($im, $bar_end+1, 0, $width-1, $height-1, $free_color);
    ImageString ($im, 1, 6, $height/2-4,  $taken."K", $text_color);
    $offset = $width - (strlen($total) + 1) * 6;
    ImageString ($im, 1, $offset, $height/2-4,  $total."K", $text_color);
    $howfull = sprintf("%.0f", $taken/$total*100);
    $offset = $width / 2 - strlen($howfull) * 4;
    ImageString ($im, 3, $offset, 2,  $howfull."%", $text_color);  
    Header("Content-type: image/png");
    ImagePng($im);
}

function draw_bar($mailbox, $width, $height) {
    global $db_host, $db_name, $db_table, $db_user, $db_passwd;

    @$link = mysql_connect($db_host, $db_user, $db_passwd) or die;
    @mysql_select_db($db_name) or die;
    $query = "SELECT current_usage, hard_quota from $db_table where user = '$mai
lbox'";
    @$result = mysql_query($query) or die;
    @$line = mysql_fetch_array($result, MYSQL_ASSOC);
    if ($line) {
        $taken = $line["current_usage"];
        $total = $line["hard_quota"];
        @mysql_close($link);
        quota_bar($taken, $total, $width, $height);
    } else {
        @mysql_close($link);
        return;
    }
}

$imapuser = $HTTP_GET_VARS['imapuser'];
draw_bar($imapuser, $width, $height);

?>
----------------------- quotabar.php --------------------------------



More information about the imp mailing list