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 |
|
f8895e
|
21 |
$used = ((isset($_GET['u']) && !empty($_GET['u'])) || $_GET['u']=='0')?(int)$_GET['u']:'??'; |
T |
22 |
$quota = ((isset($_GET['q']) && !empty($_GET['q'])) || $_GET['q']=='0')?(int)$_GET['q']:'??'; |
|
23 |
$width = empty($_GET['w']) ? 100 : (int)$_GET['w']; |
fda695
|
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() |
f8895e
|
62 |
* |
T |
63 |
* @todo Make colors a config option. |
15062e
|
64 |
*/ |
fda695
|
65 |
function genQuota($used, $total, $width, $height) |
3ea0e3
|
66 |
{ |
T |
67 |
$unknown = false; |
f8895e
|
68 |
$border = 0; |
3ea0e3
|
69 |
|
f8895e
|
70 |
$font = 2; |
fda695
|
71 |
$padding = 0; |
3ea0e3
|
72 |
|
T |
73 |
$limit['high'] = 70; |
f8895e
|
74 |
$limit['mid'] = 45; |
T |
75 |
$limit['low'] = 0; |
3ea0e3
|
76 |
|
T |
77 |
// Fill Colors |
f8895e
|
78 |
$color['fill']['high'] = '215, 13, 13'; // Near quota fill color |
T |
79 |
$color['fill']['mid'] = '126, 192, 238'; // Mid-area of quota fill color |
|
80 |
$color['fill']['low'] = '147, 225, 100'; // Far from quota fill color |
3ea0e3
|
81 |
|
T |
82 |
// Background colors |
f8895e
|
83 |
$color['bg']['OL'] = '215, 13, 13'; // Over limit bbackground |
T |
84 |
$color['bg']['Unknown'] = '238, 99, 99'; // Unknown background |
|
85 |
$color['bg']['quota'] = '255, 255, 255'; // Normal quota background |
3ea0e3
|
86 |
|
T |
87 |
// Misc. Colors |
|
88 |
$color['border'] = '0, 0, 0'; |
f8895e
|
89 |
$color['text'] = '102, 102, 102'; |
3ea0e3
|
90 |
|
T |
91 |
|
15062e
|
92 |
/************************************ |
3ea0e3
|
93 |
***** DO NOT EDIT BELOW HERE ***** |
15062e
|
94 |
***********************************/ |
3ea0e3
|
95 |
|
f8895e
|
96 |
// @todo: Set to "??" instead? |
T |
97 |
if (ereg("^[^0-9?]*$", $used) || ereg("^[^0-9?]*$", $total)) { |
3ea0e3
|
98 |
return false; |
f8895e
|
99 |
} |
f11541
|
100 |
|
f8895e
|
101 |
if (strpos($used, '?') !== false || strpos($total, '?') !== false |
T |
102 |
&& $used != 0) { |
3ea0e3
|
103 |
$unknown = true; |
f8895e
|
104 |
} |
3ea0e3
|
105 |
|
T |
106 |
$im = imagecreate($width, $height); |
fda695
|
107 |
|
f8895e
|
108 |
if ($border) { |
fda695
|
109 |
list($r, $g, $b) = explode(',', $color['border']); |
f8895e
|
110 |
|
fda695
|
111 |
$borderc = imagecolorallocate($im, $r, $g, $b); |
f8895e
|
112 |
|
fda695
|
113 |
imageline($im, 0, 0, $width, 0, $borderc); |
T |
114 |
imageline($im, 0, $height-$border, 0, 0, $borderc); |
|
115 |
imageline($im, $width-1, 0, $width-$border, $height, $borderc); |
|
116 |
imageline($im, $width, $height-$border, 0, $height-$border, $borderc); |
f11541
|
117 |
} |
fda695
|
118 |
|
3ea0e3
|
119 |
list($r, $g, $b) = explode(',', $color['text']); |
T |
120 |
$text = imagecolorallocate($im, $r, $g, $b); |
fda695
|
121 |
|
f8895e
|
122 |
if ($unknown) { |
fda695
|
123 |
list($r, $g, $b) = explode(',', $color['bg']['Unknown']); |
T |
124 |
$background = imagecolorallocate($im, $r, $g, $b); |
|
125 |
imagefilledrectangle($im, 0, 0, $width, $height, $background); |
|
126 |
|
|
127 |
$string = 'Unknown'; |
f8895e
|
128 |
$mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1; |
fda695
|
129 |
imagestring($im, $font, $mid, $padding, $string, $text); |
f8895e
|
130 |
} else if ($used > $total) { |
fda695
|
131 |
list($r, $g, $b) = explode(',', $color['bg']['OL']); |
f8895e
|
132 |
|
fda695
|
133 |
$background = imagecolorallocate($im, $r, $g, $b); |
f8895e
|
134 |
|
fda695
|
135 |
imagefilledrectangle($im, 0, 0, $width, $height, $background); |
T |
136 |
|
|
137 |
$string = 'Over Limit'; |
f8895e
|
138 |
$mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1; |
fda695
|
139 |
imagestring($im, $font, $mid, $padding, $string, $text); |
f8895e
|
140 |
} else { |
fda695
|
141 |
list($r, $g, $b) = explode(',', $color['bg']['quota']); |
f8895e
|
142 |
|
fda695
|
143 |
$background = imagecolorallocate($im, $r, $b, $g); |
f8895e
|
144 |
|
fda695
|
145 |
imagefilledrectangle($im, 0, 0, $width, $height, $background); |
T |
146 |
|
|
147 |
$quota = ($used==0)?0:(round($used/$total, 2)*100); |
|
148 |
|
f8895e
|
149 |
if ($quota >= $limit['high']) { |
fda695
|
150 |
list($r, $g, $b) = explode(',', $color['fill']['high']); |
T |
151 |
$fill = imagecolorallocate($im, $r, $g, $b); |
f8895e
|
152 |
} elseif($quota >= $limit['mid']) { |
fda695
|
153 |
list($r, $g, $b) = explode(',', $color['fill']['mid']); |
T |
154 |
$fill = imagecolorallocate($im, $r, $g, $b); |
f8895e
|
155 |
} else { |
T |
156 |
// if($quota >= $limit['low']) |
fda695
|
157 |
list($r, $g, $b) = explode(',', $color['fill']['low']); |
T |
158 |
$fill = imagecolorallocate($im, $r, $g, $b); |
f11541
|
159 |
} |
fda695
|
160 |
|
T |
161 |
$quota_width = $quota / 100 * $width; |
|
162 |
imagefilledrectangle($im, $border, 0, $quota, $height-2*$border, $fill); |
|
163 |
|
f8895e
|
164 |
$string = $quota . '%'; |
T |
165 |
$mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1; |
|
166 |
// Print percent in black |
|
167 |
imagestring($im, $font, $mid, $padding, $string, $text); |
f11541
|
168 |
} |
3ea0e3
|
169 |
|
T |
170 |
header('Content-Type: image/gif'); |
f8895e
|
171 |
|
T |
172 |
// @todo is harcoding GMT necessary? |
|
173 |
header('Expires: ' . gmdate('D, d M Y H:i:s', mktime()+86400) . ' GMT'); |
|
174 |
header('Cache-Control: '); |
|
175 |
header('Pragma: '); |
fda695
|
176 |
|
3ea0e3
|
177 |
imagegif($im); |
T |
178 |
imagedestroy($im); |
|
179 |
} |
|
180 |
|
fda695
|
181 |
genQuota($used, $quota, $width, $height); |
3ea0e3
|
182 |
exit; |
f8895e
|
183 |
?> |