source: github/bin/quotaimg.php @ 5349b78

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since 5349b78 was 5349b78, checked in by svncommit <devs@…>, 6 years ago

Update copyright notice

  • Property mode set to 100644
File size: 5.8 KB
Line 
1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | program/bin/quotaimg.php                                              |
6 |                                                                       |
7 | This file is part of the RoundCube Webmail client                     |
8 | Copyright (C) 2005-2007, 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$width = empty($_GET['w']) ? 100 : (int)$_GET['w'];
25$height = empty($_GET['h']) ? 14 : (int)$_GET['h'];
26
27function genQuota($used, $total, $width, $height)
28{
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;
56        $border = 0;
57
58        $font = 2;
59        $padding = 0;
60
61        $limit['high'] = 70;
62        $limit['mid'] = 45;
63        $limit['low'] = 0;
64
65        // Fill Colors
66        $color['fill']['high'] = '215, 13, 13'; // Near quota fill color
67        $color['fill']['mid'] = '126, 192, 238';// Mid-area of quota fill color
68        $color['fill']['low'] = '147, 225, 100';        // Far from quota fill color
69
70        // Background colors
71        $color['bg']['OL'] = '215, 13, 13';             // Over limit bbackground
72        $color['bg']['Unknown'] = '238, 99, 99';// Unknown background
73        $color['bg']['quota'] = '255, 255, 255';// Normal quota background
74
75        // Misc. Colors
76        $color['border'] = '0, 0, 0';
77        $color['text'] = '102, 102, 102';
78
79
80        /****************************
81         *****  DO NOT EDIT BELOW HERE  *****
82         ****************************/
83
84        if (ereg("^[^0-9?]*$", $used) || ereg("^[^0-9?]*$", $total))
85                return false; 
86
87        if (strpos($used, '?')!==false || strpos($total, '?')!==false && $used != 0)
88                $unknown = true; 
89
90        $im = imagecreate($width, $height);
91
92        if ($border)
93        {
94                list($r, $g, $b) = explode(',', $color['border']);
95                $borderc = imagecolorallocate($im, $r, $g, $b);
96                imageline($im, 0, 0, $width, 0, $borderc);
97                imageline($im, 0, $height-$border, 0, 0, $borderc);
98                imageline($im, $width-1, 0, $width-$border, $height, $borderc);
99                imageline($im, $width, $height-$border, 0, $height-$border, $borderc);
100        }
101               
102        list($r, $g, $b) = explode(',', $color['text']);
103        $text = imagecolorallocate($im, $r, $g, $b);
104
105        if ($unknown)
106        {
107                list($r, $g, $b) = explode(',', $color['bg']['Unknown']);
108                $background = imagecolorallocate($im, $r, $g, $b);
109                imagefilledrectangle($im, 0, 0, $width, $height, $background);
110
111                $string = 'Unknown';
112                $mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1;
113                imagestring($im, $font, $mid, $padding, $string, $text);
114        }
115        else if ($used > $total)
116        {
117                list($r, $g, $b) = explode(',', $color['bg']['OL']);
118                $background = imagecolorallocate($im, $r, $g, $b);
119                imagefilledrectangle($im, 0, 0, $width, $height, $background);
120
121                $string = 'Over Limit';
122                $mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1;
123                imagestring($im, $font, $mid, $padding, $string, $text);
124        }
125        else
126        {
127                list($r, $g, $b) = explode(',', $color['bg']['quota']);
128                $background = imagecolorallocate($im, $r, $b, $g);
129                imagefilledrectangle($im, 0, 0, $width, $height, $background);
130               
131                $quota = ($used==0)?0:(round($used/$total, 2)*100);
132
133                if ($quota >= $limit['high'])
134                {
135                        list($r, $g, $b) = explode(',', $color['fill']['high']);
136                        $fill = imagecolorallocate($im, $r, $g, $b);
137                }
138                elseif($quota >= $limit['mid'])
139                {
140                        list($r, $g, $b) = explode(',', $color['fill']['mid']);
141                        $fill = imagecolorallocate($im, $r, $g, $b);
142                }
143                else // if($quota >= $limit['low'])
144                {
145                        list($r, $g, $b) = explode(',', $color['fill']['low']);
146                        $fill = imagecolorallocate($im, $r, $g, $b);
147                }
148
149                $quota_width = $quota / 100 * $width;
150                imagefilledrectangle($im, $border, 0, $quota, $height-2*$border, $fill);
151
152                $string = $quota.'%';
153                $mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1;
154                imagestring($im, $font, $mid, $padding, $string, $text); // Print percent in black
155        }
156
157        header('Content-Type: image/gif');
158        header("Expires: ".gmdate("D, d M Y H:i:s", mktime()+86400)." GMT");
159        header("Cache-Control: ");
160        header("Pragma: ");
161       
162        imagegif($im);
163        imagedestroy($im);
164}
165
166
167genQuota($used, $quota, $width, $height);
168exit;
169?>
Note: See TracBrowser for help on using the repository browser.