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