Code

Added branches container for old stuff
[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   $x_matches= FALSE;
52   $y_matches= FALSE;
53   foreach (array(7,6,5,4,3,2,1,0) as $font){
54     $fx= ImageFontWidth($font) * strlen("$p%");
55     $fy= ImageFontHeight($font);
57     /* Look if font size matches image size */
58     if ($fx < ($x-2)){
59       $x_matches= TRUE;
60     }
61     if ($fy < ($y-2)){
62       $y_matches= TRUE;
63     }
64     if ($x_matches && $y_matches){
65       break;
66     }
67   }
69   /* Draw image in GD image stream */
70   $im = @imagecreate ($x, $y)
71       or die ("Cannot Initialize new GD image stream");
73   /* Set colors */
74   $bg_color= imagecolorallocate ($im, 255, 255, 255);
75   $br_color= imagecolorallocate ($im, 0,0,0);
76   $fi_color= imagecolorallocate ($im, 0,0,180);
77   $tx_color= imagecolorallocate ($im, 240, 10, 90);
79   /* Draw progress bar */
80   imagerectangle ($im, 0, 0, $x-1, $y-1, $br_color);
81   imagefilledrectangle ($im, 1, 1, (($x - 2) * $p / 100),
82                                      $y - 2, $fi_color);
84   /* Is font to big for progress bar? */
85   if ($font != 0){
86     imagestring ($im, $font, ($x - $fx) / 2, ($y - $fy) / 2, "$p%", $tx_color);
87   }
89   /* Finally draw the image and remove context */
90   header ("Content-type: image/png");
91   imagepng ($im);
92   imagedestroy ($im);
93 ?>