3 +-----------------------------------------------------------------------+
6 | This file is part of the RoundCube Webmail client |
7 | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland |
8 | Licensed under the GNU GPL |
11 | Create a GIF image showing the mailbox quot as bar |
13 +-----------------------------------------------------------------------+
14 | Author: Brett Patterson <brett2@umbc.edu> |
15 +-----------------------------------------------------------------------+
17 $Id: quotaimg.php 2237 2009-01-17 01:55:39Z till $
21 define('INSTALL_PATH', realpath(dirname(__FILE__).'/..') . '/');
22 require INSTALL_PATH . 'program/include/iniset.php';
24 $RCMAIL = rcmail::get_instance();
26 $used = isset($_GET['u']) ? intval($_GET['u']) : '??';
27 $quota = isset($_GET['q']) ? intval($_GET['q']) : '??';
28 $width = empty($_GET['w']) ? 100 : min(300, intval($_GET['w']));
29 $height = empty($_GET['h']) ? 14 : min(50, intval($_GET['h']));
34 * Modify the following few elements to change the display of the image.
35 * Modifiable attributes are:
36 * bool border :: Defines whether you want to show a border around it?
37 * bool unknown :: Leave default; Defines whether quota is "unknown"
39 * int height :: Defines height of the image
40 * int width :: Defines width of the image
41 * int font :: Changes the font size & font used in the GD library.
42 * Available values are from 1 to 5.
43 * int padding :: Changes the offset (in pixels) from the top of the image
44 * to where the top of the text will be aligned. User
45 * greater than 0 to ensure text is off the border.
46 * array limit :: Holds the integer values of in an associative array as
47 * to what defines the upper and lower levels for quota
49 * High - Quota is nearing capacity.
50 * Mid - Quota is around the middle
51 * Low - Currently not used.
52 * array color :: An associative array of strings of comma separated
53 * values (R,G,B) for use in color creation. Define the
54 * RGB values you'd like to use. A list of colors (and
55 * their RGB values) can be found here:
56 * http://www.december.com/html/spec/colorcodes.html
60 * @param mixed $used The amount used, or ?? if unknown.
61 * @param mixed $total The total available, or ?? if unknown.
62 * @param int $width Width of the image.
63 * @param int $height Height of the image.
65 * @see rcube_imap::get_quota()
66 * @see iil_C_GetQuota()
68 * @todo Make colors a config option.
70 function genQuota($used, $total, $width, $height)
83 $color['fill']['high'] = '243, 49, 49'; // Near quota fill color
84 $color['fill']['mid'] = '245, 173, 60'; // Mid-area of quota fill color
85 $color['fill']['low'] = '145, 225, 100'; // Far from quota fill color
88 $color['bg']['OL'] = '215, 13, 13'; // Over limit bbackground
89 $color['bg']['Unknown'] = '238, 99, 99'; // Unknown background
90 $color['bg']['quota'] = '255, 255, 255'; // Normal quota background
93 $color['border'] = '0, 0, 0';
94 $color['text']['high'] = '255, 255, 255'; // white text for red background
95 $color['text']['mid'] = '102, 102, 102';
96 $color['text']['low'] = '102, 102, 102';
97 $color['text']['normal'] = '102, 102, 102';
100 /************************************
101 ***** DO NOT EDIT BELOW HERE *****
102 ***********************************/
104 // @todo: Set to "??" instead?
105 if (ereg("^[^0-9?]*$", $used) || ereg("^[^0-9?]*$", $total)) {
109 if (strpos($used, '?') !== false || strpos($total, '?') !== false && $used != 0) {
113 $im = imagecreate($width, $height);
116 list($r, $g, $b) = explode(',', $color['border']);
118 $borderc = imagecolorallocate($im, $r, $g, $b);
120 imageline($im, 0, 0, $width, 0, $borderc);
121 imageline($im, 0, $height-$border, 0, 0, $borderc);
122 imageline($im, $width-1, 0, $width-$border, $height, $borderc);
123 imageline($im, $width, $height-$border, 0, $height-$border, $borderc);
127 list($r, $g, $b) = explode(',', $color['text']['normal']);
128 $text = imagecolorallocate($im, $r, $g, $b);
129 list($r, $g, $b) = explode(',', $color['bg']['Unknown']);
130 $background = imagecolorallocate($im, $r, $g, $b);
132 imagefilledrectangle($im, 0, 0, $width, $height, $background);
135 $mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1;
136 imagestring($im, $font, $mid, $padding, $string, $text);
137 } else if ($used > $total) {
138 list($r, $g, $b) = explode(',', $color['text']['normal']);
139 $text = imagecolorallocate($im, $r, $g, $b);
140 list($r, $g, $b) = explode(',', $color['bg']['OL']);
141 $background = imagecolorallocate($im, $r, $g, $b);
143 imagefilledrectangle($im, 0, 0, $width, $height, $background);
145 $string = 'Over Limit';
146 $mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1;
147 imagestring($im, $font, $mid, $padding, $string, $text);
149 list($r, $g, $b) = explode(',', $color['bg']['quota']);
150 $background = imagecolorallocate($im, $r, $b, $g);
152 imagefilledrectangle($im, 0, 0, $width, $height, $background);
154 $quota = ($used==0)?0:(round($used/$total, 2)*100);
156 if ($quota >= $limit['high']) {
157 list($r, $g, $b) = explode(',', $color['text']['high']);
158 $text = imagecolorallocate($im, $r, $g, $b);
159 list($r, $g, $b) = explode(',', $color['fill']['high']);
160 $fill = imagecolorallocate($im, $r, $g, $b);
161 } elseif($quota >= $limit['mid']) {
162 list($r, $g, $b) = explode(',', $color['text']['mid']);
163 $text = imagecolorallocate($im, $r, $g, $b);
164 list($r, $g, $b) = explode(',', $color['fill']['mid']);
165 $fill = imagecolorallocate($im, $r, $g, $b);
167 // if($quota >= $limit['low'])
168 list($r, $g, $b) = explode(',', $color['text']['low']);
169 $text = imagecolorallocate($im, $r, $g, $b);
170 list($r, $g, $b) = explode(',', $color['fill']['low']);
171 $fill = imagecolorallocate($im, $r, $g, $b);
174 $quota_width = $quota / 100 * $width;
175 imagefilledrectangle($im, $border, 0, $quota_width, $height-2*$border, $fill);
177 $string = $quota . '%';
178 $mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1;
179 // Print percent in black
180 imagestring($im, $font, $mid, $padding, $string, $text);
183 header('Content-Type: image/gif');
187 header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$maxage). ' GMT');
188 header('Cache-Control: max-age=' . $maxage);
194 if (!empty($RCMAIL->user->ID) && $width > 1 && $height > 1) {
195 genQuota($used, $quota, $width, $height);
198 header("HTTP/1.0 403 Forbidden");
199 echo "Requires a valid user session and positive values";