till
2008-02-20 d4517648ad79cc62e590b851afa69858393cf8dc
commit | author | age
3ea0e3 1 <?php
T 2 /*
3  +-----------------------------------------------------------------------+
f11541 4  | program/bin/quotaimg.php                                              |
3ea0e3 5  |                                                                       |
T 6  | This file is part of the RoundCube Webmail client                     |
5349b7 7  | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland                 |
3ea0e3 8  | Licensed under the GNU GPL                                            |
T 9  |                                                                       |
10  | PURPOSE:                                                              |
11  |   Create a GIF image showing the mailbox quot as bar                  |
12  |                                                                       |
13  +-----------------------------------------------------------------------+
14  | Author: Brett Patterson <brett2@umbc.edu>                             |
15  +-----------------------------------------------------------------------+
16
15062e 17  $Id: $
3ea0e3 18
T 19 */
20
21 $used  = ((isset($_GET['u']) && !empty($_GET['u'])) || $_GET['u']=='0')?(int)$_GET['u']:'??';
22 $quota = ((isset($_GET['q']) && !empty($_GET['q'])) || $_GET['q']=='0')?(int)$_GET['q']:'??';
fda695 23 $width = empty($_GET['w']) ? 100 : (int)$_GET['w'];
T 24 $height = empty($_GET['h']) ? 14 : (int)$_GET['h'];
3ea0e3 25
15062e 26 /**
T 27  * Quota display
28  * 
29  *    Modify the following few elements to change the display of the image.
30  *    Modifiable attributes are:
31  *    bool    border    ::    Defines whether you want to show a border around it?
32  *    bool    unknown    ::    Leave default; Defines whether quota is "unknown"
33  *
34  *    int        height    ::    Defines height of the image
35  *    int        width    ::    Defines width of the image
36  *    int        font    ::    Changes the font size & font used in the GD library.
37  *                        Available values are from 1 to 5.
38  *    int        padding    ::    Changes the offset (in pixels) from the top of the image
39  *                      to where the top of the text will be aligned. User
40  *                      greater than 0 to ensure text is off the border.
41  *    array    limit    ::    Holds the integer values of in an associative array as
42  *                      to what defines the upper and lower levels for quota
43  *                      display.
44  *                        High - Quota is nearing capacity.
45  *                        Mid  - Quota is around the middle
46  *                        Low  - Currently not used.
47  *    array    color    ::    An associative array of strings of comma separated
48  *                      values (R,G,B) for use in color creation.  Define the
49  *                      RGB values you'd like to use. A list of colors (and
50  *                      their RGB values) can be found here:
51  *                        http://www.december.com/html/spec/colorcodes.html
52  * 
53  * @return void
54  * 
55  * @param mixed $used   The amount used, or ?? if unknown.
56  * @param mixed $total  The total available, or ?? if unknown.
57  * @param int   $width  Width of the image.
58  * @param int   $height Height of the image.
59  * 
60  * @see rcube_imap::get_quota()
61  * @see iil_C_GetQuota()
62  */
fda695 63 function genQuota($used, $total, $width, $height)
3ea0e3 64 {
T 65     $unknown = false;
fda695 66     $border = 0;
3ea0e3 67
T 68     $font = 2;
fda695 69     $padding = 0;
3ea0e3 70
T 71     $limit['high'] = 70;
72     $limit['mid'] = 45;
73     $limit['low'] = 0;
74
75     // Fill Colors
fda695 76     $color['fill']['high'] = '215, 13, 13';    // Near quota fill color
3ea0e3 77     $color['fill']['mid'] = '126, 192, 238';// Mid-area of quota fill color
fda695 78     $color['fill']['low'] = '147, 225, 100';    // Far from quota fill color
3ea0e3 79
T 80     // Background colors
fda695 81     $color['bg']['OL'] = '215, 13, 13';        // Over limit bbackground
3ea0e3 82     $color['bg']['Unknown'] = '238, 99, 99';// Unknown background
T 83     $color['bg']['quota'] = '255, 255, 255';// Normal quota background
84
85     // Misc. Colors
86     $color['border'] = '0, 0, 0';
fda695 87     $color['text'] = '102, 102, 102';
3ea0e3 88
T 89
15062e 90     /************************************
3ea0e3 91      *****    DO NOT EDIT BELOW HERE    *****
15062e 92      ***********************************/
3ea0e3 93
f11541 94     if (ereg("^[^0-9?]*$", $used) || ereg("^[^0-9?]*$", $total))
3ea0e3 95         return false; 
f11541 96
T 97     if (strpos($used, '?')!==false || strpos($total, '?')!==false && $used != 0)
3ea0e3 98         $unknown = true; 
T 99
100     $im = imagecreate($width, $height);
fda695 101
f11541 102     if ($border)
T 103     {
fda695 104         list($r, $g, $b) = explode(',', $color['border']);
T 105         $borderc = imagecolorallocate($im, $r, $g, $b);
106         imageline($im, 0, 0, $width, 0, $borderc);
107         imageline($im, 0, $height-$border, 0, 0, $borderc);
108         imageline($im, $width-1, 0, $width-$border, $height, $borderc);
109         imageline($im, $width, $height-$border, 0, $height-$border, $borderc);
f11541 110     }
fda695 111         
3ea0e3 112     list($r, $g, $b) = explode(',', $color['text']);
T 113     $text = imagecolorallocate($im, $r, $g, $b);
fda695 114
f11541 115     if ($unknown)
T 116     {
fda695 117         list($r, $g, $b) = explode(',', $color['bg']['Unknown']);
T 118         $background = imagecolorallocate($im, $r, $g, $b);
119         imagefilledrectangle($im, 0, 0, $width, $height, $background);
120
121         $string = 'Unknown';
122         $mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1;
123         imagestring($im, $font, $mid, $padding, $string, $text);
f11541 124     }
T 125     else if ($used > $total)
126     {
fda695 127         list($r, $g, $b) = explode(',', $color['bg']['OL']);
T 128         $background = imagecolorallocate($im, $r, $g, $b);
129         imagefilledrectangle($im, 0, 0, $width, $height, $background);
130
131         $string = 'Over Limit';
132         $mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1;
133         imagestring($im, $font, $mid, $padding, $string, $text);
f11541 134     }
fda695 135     else
f11541 136     {
fda695 137         list($r, $g, $b) = explode(',', $color['bg']['quota']);
T 138         $background = imagecolorallocate($im, $r, $b, $g);
139         imagefilledrectangle($im, 0, 0, $width, $height, $background);
140         
141         $quota = ($used==0)?0:(round($used/$total, 2)*100);
142
f11541 143         if ($quota >= $limit['high'])
T 144         {
fda695 145             list($r, $g, $b) = explode(',', $color['fill']['high']);
T 146             $fill = imagecolorallocate($im, $r, $g, $b);
f11541 147         }
fda695 148         elseif($quota >= $limit['mid'])
f11541 149         {
fda695 150             list($r, $g, $b) = explode(',', $color['fill']['mid']);
T 151             $fill = imagecolorallocate($im, $r, $g, $b);
f11541 152         }
fda695 153         else // if($quota >= $limit['low'])
f11541 154         {
fda695 155             list($r, $g, $b) = explode(',', $color['fill']['low']);
T 156             $fill = imagecolorallocate($im, $r, $g, $b);
f11541 157         }
fda695 158
T 159         $quota_width = $quota / 100 * $width;
160         imagefilledrectangle($im, $border, 0, $quota, $height-2*$border, $fill);
161
162         $string = $quota.'%';
163         $mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1;
164         imagestring($im, $font, $mid, $padding, $string, $text); // Print percent in black
f11541 165     }
3ea0e3 166
T 167     header('Content-Type: image/gif');
f11541 168     header("Expires: ".gmdate("D, d M Y H:i:s", mktime()+86400)." GMT");
fda695 169     header("Cache-Control: ");
T 170     header("Pragma: ");
171     
3ea0e3 172     imagegif($im);
T 173     imagedestroy($im);
174 }
175
176
fda695 177 genQuota($used, $quota, $width, $height);
3ea0e3 178 exit;
5349b7 179 ?>