Code

Added futur base selector class
[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   /* Check for parameter completenes */
24   if (!isset($_GET['x']) || !isset($_GET['y']) || !isset($_GET['p'])){
25     die ("Missing parameters!");
26   }
27   if (!is_numeric($_GET['x']) || !is_numeric($_GET['y'])){
28     die ("Parameters must be numeric!");
29   }
31   $p= (int)($_GET['p']);
32   $x= (int)($_GET['x']);
33   $y= (int)($_GET['y']);
35   /* Check percentage */
36   if ($p < 0){
37     $p= 0;
38   } elseif ($p > 100){
39     $p= 100;
40   }
41   $p= intval ($p);
43   /* Check dimensions */
44   if ($x < 3 || $x > 1000){
45     $x= 180;
46   }
47   if ($y < 3 || $y > 700){
48     $y= 20;
49   }
51   if(!function_exists("imagecreate")){
52     syslog(LOG_ERR, "GOsa is missing the gd library, please install php5-gd to be able to see progress images.");
53     echo "Please install the php5-gd library, GOsa can't create images without it.";
54     exit();
55   }else{
57     $x_matches= FALSE;
58     $y_matches= FALSE;
59     foreach (array(7,6,5,4,3,2,1,0) as $font){
60       $fx= ImageFontWidth($font) * strlen("$p%");
61       $fy= ImageFontHeight($font);
63       /* Look if font size matches image size */
64       if ($fx < ($x-2)){
65         $x_matches= TRUE;
66       }
67       if ($fy < ($y-2)){
68         $y_matches= TRUE;
69       }
70       if ($x_matches && $y_matches){
71         break;
72       }
73     }
75     /* Draw image in GD image stream */
76     $im = imagecreate ($x, $y)
77       or die ("Cannot Initialize new GD image stream");
79     /* Set colors */
80     $bg_color= imagecolorallocate ($im, 255, 255, 255);
81     $br_color= imagecolorallocate ($im, 0,0,0);
82     $fi_color= imagecolorallocate ($im, 0,0,180);
83     $tx_color= imagecolorallocate ($im, 240, 10, 90);
85     /* Draw progress bar */
86     imagerectangle ($im, 0, 0, $x-1, $y-1, $br_color);
87     imagefilledrectangle ($im, 1, 1, (($x - 2) * $p / 100),
88         $y - 2, $fi_color);
90     /* Is font to big for progress bar? */
91     if ($font != 0){
92       imagestring ($im, $font, ($x - $fx) / 2, ($y - $fy) / 2, "$p%", $tx_color);
93     }
95     /* Finally draw the image and remove context */
96     header ("Content-type: image/png");
97     imagepng ($im);
98     imagedestroy ($im);
99   }
100 ?>