Cześć,
Mam taki problem jak na zdjęciu zakreślony czerwoną otoczką pokazuje mi jakąś lipę..
Chciałbym, żeby mi pokazywał np: dniami (1,2,3,4,5,6,7) albo (pon, wto itd)
Poniżej pokazuje wam kod..
Gdzie tkwi błąd?
<?php
if(!$_GET['popup']==1)
{
header("Content-type: image/png"); TrafficGraph($_GET['nodeid'],$_GET['bar']);
}
?>
<HTML>
<HEAD>
<script TYPE="text/javascript" LANGUAGE="JavaScript" SRC="img/autoiframe.js"></SCRIPT>
</HEAD>
<BODY>
<TABLE HEIGHT=150 WIDTH=510 VALIGN=TOP HALIGN=RIGHT BORDER=0 id="table">
<TR HEIGHT=150 WIDTH=510 >
<TD HEIGHT=150 WIDTH=510 >
<?
print("<img src=?m=trafficgraph&nodeid=".$_GET['nodeid']."&bar=".$_GET['bar'].">"); ?>
</TD></TR>
</TABLE>
<script TYPE="text/javascript" LANGUAGE="JavaScript">
<!--
parent.document.getElementById('autoiframe').width = document.getElementById('table').offsetWidth;
//-->
</SCRIPT>
</BODY>
</HTML>
<?
function TrafficGraph ($nodeid,$quantum)
{
//brak obsługi przedzialu, std. co przedzial
$godzina=60*60;
$dzien=$godzina*24;
$miesiac=$dzien*30;
$rok=$miesiac*12;
$movx=80;
$movy=25;
$quantum=$godzina*34;
$ymax=150;
$xmax=500;
if($stats = $DB->GetRow('SELECT SUM(download) AS download, SUM(upload) AS upload
FROM stats WHERE nodeid=? AND dt>?',
array($nodeid, $currenttime-$quantum))) {
$result['downavg'] = $stats['download']/$quantum;
$result['upavg'] = $stats['upload']/$quantum;
}
$sql_query="SELECT customers.lastname,customers.name FROM customers LEFT JOIN nodes ON (customers.id = nodes.ownerid) WHERE nodes.id=?";
$user=$DB->GetRow($sql_query,array($nodeid)); $node=$DB->GetRow('SELECT nodes.name,inet_ntoa(nodes.ipaddr) AS adres FROM nodes WHERE id=?',array($nodeid));
$traffimage=imagecreate($xmax,$ymax);
imagesetthickness($traffimage,2);
$background=imagecolorallocate($traffimage,240,240,240);
$textcolor=imagecolorallocate($traffimage,0,0,0);
$downloadcolor=imagecolorallocate($traffimage,0,180,0);
$uploadcolor=imagecolorallocate($traffimage,0,0,255);
$redcolor=imagecolorallocatealpha($traffimage,255,0,0,70);
imageline($traffimage,0,0,$xmax,0,$textcolor);
imageline($traffimage,0,$ymax-1,$xmax,$ymax-1,$textcolor);
imageline($traffimage,0,0,0,$ymax,$textcolor);
imageline($traffimage,$xmax-1,0,$xmax-1,$ymax,$textcolor);
$trans_maks = $DB->GetRow('SELECT MAX(upload) AS upload,MAX(download) AS download, MAX(dt) as lastdt FROM stats WHERE nodeid=? AND dt>?', array($nodeid, $currenttime-$quantum)); $lastcount = $DB->GetRow('SELECT upload, download FROM stats where nodeid=? AND dt=?',array($nodeid,$trans_maks['lastdt'])); $upl_maks = (int)($trans_maks['upload']/300);
$dwl_maks = (int)($trans_maks['download']/300);
if($upl_maks>$dwl_maks)
$stats_maks=$upl_maks;
else
$stats_maks=$dwl_maks;
$stats_maks=$stats_maks*8;
$podst=$stats_maks;
$dana=$stats_maks;
$nkrotnosc=0;
while ($dana>1)
{
$dana=$dana/2;
$nkrotnosc++;
}
$stats_maks=pow(2,$nkrotnosc);
$dziel=$stats_maks/4;
do
{
while ($stats_maks-$dziel>$podst)
{
$stats_maks=$stats_maks-$dziel;
}
$dziel=$dziel/2;
}
while ($dziel>1024*1024);
$stats_maks=$stats_maks/8;
$posx=0;
$lastfirst=1;
$sredniadwl=0;
$sredniaupl=0;
$sredniadzielnik=0;
$styleline=array($textcolor,IMG_COLOR_TRANSPARENT
,IMG_COLOR_TRANSPARENT
); imagesetstyle($traffimage,$styleline);
$sql_query="SELECT AVG(upload) AS upload, AVG(download) AS download, CEIL(dt/?)*? AS dts, COUNT(*) as wierszy FROM stats WHERE nodeid=? AND dt>? GROUP BY CEIL(dt/?) ORDER BY dts ASC";
$stats1=$DB->GetAll($sql_query,array($quantum/400
,$quantum/400
,$nodeid, $currenttime-$quantum,$quantum/400
));
$posx=1;
if (!($fp = fopen('/tmp/danetest.txt', 'w'))) { return;
}
fprintf($fp,"%f:%f\n",$podst,$stats_maks);
$lastdts=0;
foreach($stats1 as $statsline)
{
$download=$statsline['download']/300;
$upload=$statsline['upload']/300;
fprintf($fp,"%f:%f:%d\n",$download,$upload,$dts);
$download=($download/$stats_maks);
$upload=($upload/$stats_maks);
$download=$download*99;
$upload=$upload*99;
$dts=$statsline['dts'];
if($lastdts==0)
{
$lastdts=$dts;
}
$zerowanie=1;
$n=1;
$currentdts=$lastdts;
while(($dts-$lastdts)>(($quantum/400)*$n))
{
$currentdts=(int)($currentdts+$quantum/400);
fprintf($fp,"dts %d: last %d: quantum %f: curr %d\n",$dts,$lastdts,($quantum/400)*$n,$currentdts);
$zerowanie=0;
$upload=0;
$download=0;
imagesetthickness($traffimage,0);
imageline
($traffimage,$movx+$posx,135
-25
,$movx+$posx,135
-25
-floor($download),$downloadcolor); imageline($traffimage,$movx+$posx-1,135-24-$lastupload,$movx+$posx,135-24-$upload,$uploadcolor);
$timehnow=date("H",$currentdts); $timemnow=date("i",$currentdts); if($timemnow<="4")
{
imageline($traffimage,$movx+$posx,135-25,$movx+$posx,10,IMG_COLOR_STYLED);
imageline($traffimage,$movx+$posx,135-22,$movx+$posx,135-25,$textcolor);
if($timehnow=="0")
imageline($traffimage,$movx+$posx,135-25,$movx+$posx,10,$redcolor);
imagestring($traffimage,1,$movx+$posx-4,135-20,$timehnow,$textcolor);
}
$posx++;
$n++;
}
if($zerowanie==0)
{
$lastupload=0;
}
imagesetthickness($traffimage,0);
imageline
($traffimage,$movx+$posx,135
-25
,$movx+$posx,135
-25
-floor($download),$downloadcolor);
if ($lastfirst==1)
{
$lastfirst=0;
imagesetpixel($traffimage,$movx+$posx,135-25-$upload,$uploadcolor);
}
else
{
imageline($traffimage,$movx+$posx-1,135-24-$lastupload,$movx+$posx,135-24-$upload,$uploadcolor);
}
$lastupload=$upload;
$timehnow=date("H",$dts); $timemnow=date("i",$dts); if($timemnow<="4")
{
imageline($traffimage,$movx+$posx,135-25,$movx+$posx,10,IMG_COLOR_STYLED);
imageline($traffimage,$movx+$posx,135-22,$movx+$posx,135-25,$textcolor);
if($timehnow=="0")
imageline($traffimage,$movx+$posx,135-25,$movx+$posx,10,$redcolor);
imagestring($traffimage,1,$movx+$posx-4,135-20,$timehnow,$textcolor);
}
$lastdts=$dts;
$posx++;
$zerowanie=0;
}
imageline($traffimage,$movx,135-24,$movx,10,$textcolor);
imageline($traffimage,$movx+400,135-24,$movx+400,10,$textcolor);
imageline($traffimage,$movx-2,135-24,$movx+402,135-24,$textcolor);
imageline($traffimage,$movx-2,10,$movx+402,10,$textcolor);
$stats_maks=$stats_maks*8;
if ($stats_maks/1024>1)
{
$przedrostek="kb";
$stats_maks1=$stats_maks/1024;
}
if ($stats_maks/(1024*1024)>1)
{
$przedrostek="Mb";
$stats_maks1=$stats_maks/(1024*1024);
}
$n=0;
for($i=0;$i<=105;$i=$i+(101/4))
{
imageline($traffimage,$movx-2,10+$i,$movx+2,10+$i,$textcolor);
imageline($traffimage,$movx-2+400,10+$i,$movx+2+400,10+$i,$textcolor);
imageline($traffimage,$movx+4,10+$i,$movx-4+400,10+$i,IMG_COLOR_STYLED);
imagestring
($traffimage,1
,$movx-40
,6
+$i,str_pad(round($stats_maks1-($stats_maks1/4
*$n),1)." ".$przedrostek,7," ",STR_PAD_LEFT
),$textcolor); $n++;
}
$red1=imagecolorallocate($traffimage,255,0,0);
$values=array($movx+401
,135
-27
,$movx+401
,135
-21
,$movx+406
,135
-24
); imagefilledpolygon($traffimage, $values, 3, $red1);
imagestringup($traffimage, 2, 1, $ymax-5, iconv("UTF-8","ISO-8859-2",$user['lastname']." ".$user['name']), $textcolor);
imagestringup($traffimage, 1, 15, $ymax-5, $node['name']." - ".$node['adres'], $textcolor);
imagestring
($traffimage, 2
, 45
, $ymax-27, "MAX: ".str_pad(round($dwl_maks/1024,2),7," ",STR_PAD_LEFT
)." kB/s",$downloadcolor); imagestring
($traffimage, 2
, 45
, $ymax-15, "MAX: ".str_pad(round($upl_maks/1024,2),7," ",STR_PAD_LEFT
)." kB/s",$uploadcolor); imagestring
($traffimage, 2
, 165
, $ymax-27, iconv
("UTF-8","ISO-8859-2","ĹšREDNIA: ").str_pad(round(($result['downavg'])/1024,2),7," ",STR_PAD_LEFT
)." kB/s",$downloadcolor); imagestring
($traffimage, 2
, 165
, $ymax-15, iconv
("UTF-8","ISO-8859-2","ĹšREDNIA: ").str_pad(round(($result['upavg'])/1024,2),7," ",STR_PAD_LEFT
)." kB/s",$uploadcolor); imagestring
($traffimage, 2
, 310
, $ymax-27, "TERAZ: ".str_pad(round(($lastcount['download'])/(1024*300),2),7," ",STR_PAD_LEFT
)." kB/s",$downloadcolor); imagestring
($traffimage, 2
, 310
, $ymax-15, "TERAZ: ".str_pad(round(($lastcount['upload'])/(1024*300),2),7," ",STR_PAD_LEFT
)." kB/s",$uploadcolor); imagestring($traffimage, 2, 440, $ymax-27, "DOWNLOAD",$downloadcolor);
imagestring($traffimage, 2, 440, $ymax-15, "UPLOAD",$uploadcolor);
imagepng($traffimage);
imagedestroy($traffimage);
}