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