Code

Updated styles
[gosa.git] / gosa-core / html / progress.php
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 session_cache_limiter("private");
25 /* Check for parameter completenes */
26 if (!isset($_GET['x']) || !isset($_GET['y']) || !isset($_GET['p'])){
27   die ("Missing parameters!");
28 }
29 if (!is_numeric($_GET['x']) || !is_numeric($_GET['y'])){
30   die ("Parameters must be numeric!");
31 }
33 $p= (int)($_GET['p']);
34 $x= (int)($_GET['x']);
35 $y= (int)($_GET['y']);
37 /* Check percentage */
38 if ($p < 0){
39   $p= 0;
40 } elseif ($p > 100){
41   $p= 100;
42 }
43 $p= intval ($p);
45 /* Check dimensions */
46 if ($x < 3 || $x > 1000){
47   $x= 180;
48 }
49 if ($y < 3 || $y > 700){
50   $y= 20;
51 }
53 if(!function_exists("imagecreate")){
54   syslog(LOG_ERR, "GOsa is missing the gd library, please install php5-gd to be able to see progress images.");
55   echo "Please install the php5-gd library, GOsa can't create images without it.";
56   exit();
57 }else{
59   $x_matches= FALSE;
60   $y_matches= FALSE;
61   foreach (array(7,6,5,4,3,2,1,0) as $font){
62     $fx= ImageFontWidth($font) * strlen("$p%");
63     $fy= ImageFontHeight($font);
65     /* Look if font size matches image size */
66     if ($fx < ($x-2)){
67       $x_matches= TRUE;
68     }
69     if ($fy < ($y-2)){
70       $y_matches= TRUE;
71     }
72     if ($x_matches && $y_matches){
73       break;
74     }
75   }
77   /* Draw image in GD image stream */
78   $im = imagecreate ($x, $y)
79     or die ("Cannot Initialize new GD image stream");
81   /* Set colors */
82   $bg_color= imagecolorallocate ($im, 255, 255, 255);
83   $br_color= imagecolorallocate ($im, 0,0,0);
84   $fi_color= imagecolorallocate ($im, 0,0,180);
85   $tx_color= imagecolorallocate ($im, 240, 10, 90);
87   /* Draw progress bar */
88   imagerectangle ($im, 0, 0, $x-1, $y-1, $br_color);
89   imagefilledrectangle ($im, 1, 1, (($x - 2) * $p / 100),
90       $y - 2, $fi_color);
92   /* Is font to big for progress bar? */
93   if ($font != 0){
94     imagestring ($im, $font, ($x - $fx) / 2, ($y - $fy) / 2, "$p%", $tx_color);
95   }
97   /* Finally draw the image and remove context */
98   header ("Content-type: image/png");
99   imagepng ($im);
100   imagedestroy ($im);
102 ?>