<?
/***************************************************************/
/* */
/* TelDaBase */
/* ========= */
/* */
/* Copyright (C) 2004 Wolfgang Barthel */
/* */
/* http://www.teldabase.de */
/* hide@address.com */
/* */
/* see index.php and LICENSE */
/* */
/***************************************************************/
/***************************************************************/
/* stat_img_old.php */
/* ================ */
/* Funktionen zum Anzeigen der Statistik-Bilder */
/* wird als <img src="stat_img.php /"> eingebunden */
/* ersetzt durch stat_img.php */
/***************************************************************/
require("conf.php");
$xwidth = 500;
$ywidth = $xwidth * 0.6;
$link = mysql_connect($tdb["host"],$tdb["user"],$tdb["pass"])
or die ("TelDaBase mysql-Server konnte nicht kontaktiert werden");
mysql_select_db ($tdb["db"], $link)
or die ("TelDaBase mysql-Server konnte nicht kontaktiert werden");
if(isset($_GET["bewohnerid"]))
$query = "select Konto.rechnung_id, date_format(rech_datum,\"%d.%m.%Y\") as rech_date,
kon_betrag / -100 as rech_betrag from Rechnungen
left join Konto on (Rechnungen.rechnung_id = Konto.rechnung_id)
where bewohner_id = '" . $_GET["bewohnerid"] . "'";
else
$query = "select rechnung_id, date_format(rech_datum,\"%d.%m.%Y\") as rech_date, rech_betrag from Rechnungen order by rech_datum asc;";
$result = mysql_query($query)
or die ("Query |$query| failed:" . mysql_error());
$num_rechnungen = mysql_numrows($result);
if($num_rechnungen == 0)
{
return;
}
// $im = @imagecreatetruecolor($xwidth * 1.2, $ywidth * 1.2)
$im = imagecreate($xwidth * 1.2, $ywidth * 1.2)
or die("Cannot Initialize new GD image stream");
$xspace = $xwidth / $num_rechnungen;
$white = ImageColorAllocate($im, 255, 255, 255);
$black = ImageColorAllocate($im, 0, 0, 0);
imagecolortransparent($im, $black);
$linecolor = $black;
$fontsize = $xwidth / 100 + 6;
$font = dirname($_SERVER["SCRIPT_FILENAME"])."/FreeSans.ttf";
$xfactor = 0.2;
$xaxisfactor = 0.7 * $xfactor;
$yfactor = 1.1;
$max_rech_betrag = 0.01;
/* Als x-Achsenbeschriftung nicht mehr als 10 Daten zeigen */
if($num_rechnungen > 10)
$xlegendskip = $num_rechnungen / 5;
for($i = 0; $i < $num_rechnungen; $i++)
{
$row = mysql_fetch_assoc($result);
$rech_betrag[$i] = round($row["rech_betrag"] / 100, 2);
if($rech_betrag[$i] > $max_rech_betrag)
$max_rech_betrag = $rech_betrag[$i];
$basex = $xfactor * $xwidth + $xspace * $i;
$basey = $ywidth * 1.1;
if($i % $xlegendskip == 0)
$ttbox = imagettftext($im, $fontsize, 90, $basex, $basey,
$black, $font, $row["rech_date"]);
else
{
$ttbox = imagettfbbox($fontsize, 90, $font, $row["rech_date"]);
$ttbox[0] += $basex;
$ttbox[3] += $basey;
$ttbox[4] += $basex;
}
$xpos[$i] = 0.5 * ($ttbox[0] + $ttbox[4]);
}
$yscale = ( $ttbox[3] / $yfactor / $yfactor ) / $max_rech_betrag;
/* Koordinatenachsen */
imageline($im, $xaxisfactor * .9 * $xwidth, $ttbox[3] /$yfactor , 1.1 * $xwidth,
$ttbox[3] /$yfactor, $linecolor);
imageline($im, $xaxisfactor * $xwidth, $ttbox[3] , $xaxisfactor * $xwidth,
0.05*$ywidth, $linecolor);
/* Beschriftung der y-Achse */
$schrittweite = 10 * round ($max_rech_betrag / 50);
if($schrittweite < 5) /* bei $schrittweite=0 gäbe es sonst eine Endlosschleife */
$schrittweite = 5;
for($ywert = 0; $ywert < $max_rech_betrag; $ywert += $schrittweite)
{
$ylabelpos = $ttbox[3] / $yfactor - $ywert * $yscale;
imageline($im, $xaxisfactor * $xwidth -2 , $ylabelpos , $xaxisfactor * $xwidth +2,
$ylabelpos, $linecolor);
imagettftext($im, $fontsize, 0, 0.5 * $xaxisfactor * $xwidth , $ylabelpos + $fontsize / 2,
$black, $font, $ywert . "");
}
for($i = 0; $i < $num_rechnungen; $i++)
{
$ypos[$i] = $ttbox[3] / $yfactor - $rech_betrag[$i] * $yscale;
imagerectangle($im, $xpos[$i] - 1, $ypos[$i] - 1, $xpos[$i] + 1, $ypos[$i] + 1, $black);
}
for($i = 0; $i < $num_rechnungen - 1; $i++)
{
imageline($im, $xpos[$i], $ypos[$i], $xpos[$i+1], $ypos[$i+1], $black);
}
header("Content-type: image/jpeg");
Imagejpeg($im);
ImageDestroy($im);
?>