Location: PHPKode > projects > PhpInv > phpInv-0.8.0/admin/inc/stats_graph.php
<?

// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version.

// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.

// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the Free Software Foundation, Inc., 59 Temple
// Place - Suite 330, Boston, MA 02111-1307, USA.

// Copyright: (C) 2002/2003 Stefan Cyris 


header ("Content-type: image/png");

// dimension
$height = 400;

// min, max
$result = $DB->query("SELECT COUNT(script), MIN(speed), MAX(speed) FROM ".$DB->tableprefix."stats WHERE script='".$script."'");
$array = $DB->fetch_array($result);
$count = $array[0];
$min = $array[1];
$max = $array[2];
$width = 50 + $count;
if ($width<=100) {
	$width=100;
}
$m = ($height - 100) / ($max - $min);

// Image
$im = ImageCreate ($width, $height);
$background_color = ImageColorAllocate ($im, 255, 255, 255);
$col = ImageColorAllocate ($im, 0, 0, 0);
$red = ImageColorAllocate ($im, 255, 0, 0);
$green = ImageColorAllocate ($im, 0, 255, 0);

// borders
imageline($im,0,$height - 30,$width,$height - 30,$col);
imageline($im,30,0,30,$height,$col);
imageline($im,25,50,30,50,$red);
imageline($im,25,350,30,350,$red);
imagestring($im,1,0,0,"10^-3",$col);
imagestring($im,1,40,0,"sec",$col);
imagestring($im,2,0,50,ceil($max*1000),$red);
imagestring($im,2,0,335,ceil($min*1000),$red);

/*
for ($i=$max;$i>$min-1;$i--) {
	$line = $height - 30 - $i * $scal * $m + $min * $m;
	imagestring($im,2,0,$line - 10,$i . "k",$col);
	imageline($im,25,$line,35,$line,$col);
}
*/


// values
$LimitFrom = $count-500;
if (0>$LimitFrom)
	$LimitFrom = 0;

$result = $DB->query("SELECT * FROM ".$DB->tableprefix."stats WHERE script='".$script."' ORDER BY date LIMIT ".$LimitFrom.", ".$count);

$i=0;
while($array = $DB->fetch_array($result) ) {
	$i++;
	$speed = $array["speed"];
	/*
	print $speed.",";
	print $min.",".$max.",";
	print $m.",";
	print $height - ((($speed - $min) * $m) + 50)."<hr>";
	*/
	imageline($im,30,50,30,350,$red);
	imageline($im,30 + $i,$height - 30,30 + $i,$height - ((($speed - $min) * $m) + 50),$col);
	/*
	if ($stunde == "00" && $minute == "00") {
		imageline($im,30+$i,$height - 30,30+$i,$height-30-(($speed-$min)*$m),$red);
		imagestring($im,1,10+$i,$height-20,$tag . ".". $monat . "." . $jahr,$red);
	}
	*/
}

ImagePNG ($im);

?>
Return current item: PhpInv