Location: PHPKode > projects > WaveWatcher > wavewatcher3/html/table/datatotal.php
<? 
// *** *** *** INPUT VARIABLES *** *** *** 

$interface = empty($interface) ? "3" : $interface;	
$node_id = empty($node_id) ? "10" : $node_id;
$nSizeX = empty($xsize) ? 450 : $xsize < 1 ? 450 : $xsize;						// default width = 450px
$nSizeY = empty($ysize) ? 225 : $ysize < 1 ? 225 : $ysize;						// default height = 225px
$font = empty($font) ? 2 : $font;														// default font = 2
$nHorPos = empty($xpos) ? 24 : $xpos < 1 ? 24 : $xpos;							// default nHorPos = 24 (1 day)
$nVerPos = empty($ypos) ? 5 : $ypos < 1 ? 5 : $ypos;								// default nVerPos = 5
$nDrawMode = empty($drawmode) ? 1 : $drawmode;										// default nDrawMode = 1 (small line)
$nHorGridMode = empty($xgrid) ? 3 : $xgrid;											// default $nHorGridMode = 3 (show all horizontal gridlines)
$nHorGridMode = ($nHorGridMode < 1 || $nHorGridMode > 3) ? 3 : $nHorGridMode;	// make sure it is a correct value
$nVerGridMode = empty($ygrid) ? 3 : $ygrid;											// default $nVerGridMode = 3 (show all vertical gridlines)
$nVerGridMode = ($nVerGridMode < 1 || $nVerGridMode > 3) ? 3 : $nVerGridMode;	// make sure it is a correct value
$dateStopTime = empty($stoptime) ? null : $stoptime;								// default "time now"
$dateStartTime = empty($starttime) ? null : $starttime;							// default "time now - 24h"
$nPresentation = empty($mode) ? 1 : $mode;											// default hours
$nMaxKiloBit = empty($maxkbit) ? 0 : $maxkbit < 1 || $maxkbit > 9999 ? 0 : $maxkbit;		// default: automatic calculation
$nBitsPerDel = empty($kbitperdel) ? 0 : $kbitperdel < 10 || $kbitperdel > 1000 ? 100 : $kbitperdel;	// default 100 kbit

// Sets default value to $nPresentation if its present value is not valid
$nPresentation = $nPresentation != 1 &&  $nPresentation != 2 && $nPresentation != 3 ? 1 : $nPresentation;
// *** *** *** INTERNAL VARIABLES *** *** *** 
$nStopTime = time();
//$nStopTime=1025580616;

for($counter=0;$counter<30;$counter++){$totalinBytes[$counter]=0;}
for($counter=0;$counter<30;$counter++){$totaloutBytes[$counter]=0;}
for($counter=0;$counter<30;$counter++){$intervalTime[$counter]=0;}

// Interval - this is depending on $mode ie 24 hours or 7 days or 28 days
if ($mode==1){
  $interval = 3600; // one hour
  $firstinterval=0;
  $intervalchange=$nStopTime;
  while ($intervalchange){
    if($intervalchange%$interval ==0)break;
    $intervalchange--;
    $firstinterval++;
    }
  $totaltime = 82800 + $firstinterval;
  }
elseif($mode==2){
  $interval = 86400;// one day
  $firstinterval=0;
  $intervalchange=$nStopTime;
  while ($intervalchange){
    if($intervalchange%$interval ==0)break;
    $intervalchange--;
    $firstinterval++;
    }
  $firstinterval = $firstinterval + 7200;
  $totaltime = 518400 + $firstinterval;
  }
else{
  $interval = 86400;
  $firstinterval=0;
  $intervalchange=$nStopTime;
  while ($intervalchange){
     if($intervalchange%$interval ==0)break;
     $intervalchange--;
     $firstinterval++;
     }
  $firstinterval = $firstinterval + 7200;
  $totaltime = 2505600 + $firstinterval;
}
// Calculates $nStartTime from $nStopTime (days if $mode == 2 || 3 otherwise hours)
$nStartTime = $nStopTime - $totaltime;

// *** *** *** DATABASE ACCESS *** *** *** 
require_once("../classes/dbconnection.php");

$dbcn = new DBConnection();
$dbcn->Connect();

$query = "SELECT utime, rxbytes, txbytes FROM node_interface_log WHERE node_id = $node_id and interface = $interface and utime > $nStartTime and utime < $nStopTime ORDER BY utime desc";
$result = $dbcn->Query($query);
$dbcn->Disconnect();
$nInBytesOld	= 0;
$nOutBytesOld	= 0;
$intervalCounter=0;
$intervalLimit=$nStopTime -  $firstinterval;
while (list($time, $inbytes, $outbytes) = $dbcn->FetchRow($result)){

  while($time < $intervalLimit){
      //if the reading is outside the set interval move limit and storage place
    $intervalTime[$intervalCounter]=$intervalLimit;  
    $intervalLimit =$intervalLimit - $interval;
    $intervalCounter++;
   }
   $difinBytes = $nInBytesOld - $inbytes;
   $difoutBytes =$nOutBytesOld - $outbytes;
   if ($difinBytes > 0){
     $totalinBytes[$intervalCounter] = $totalinBytes[$intervalCounter] + $difinBytes;
   }
if ($difoutBytes > 0){
     $totaloutBytes[$intervalCounter] = $totaloutBytes[$intervalCounter] + $difoutBytes;
   }			
	
    $nInBytesOld = $inbytes;
    $nOutBytesOld = $outbytes;
	
}
//put the last time in the right place
$intervalTime[$intervalCounter]=$intervalLimit;
$dbcn->Connect();
$query = "SELECT node_ip, node_name FROM nodes WHERE node_id = $node_id";
$result = $dbcn->Query($query);
$dbcn->Disconnect();
List($node_ip, $node_name) = $dbcn->FetchRow($result);										
// nodes ip-address
// *** *** *** !END! DATABASE ACCESS !END! *** *** ***
	print "<table width=\"320\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#000000\" align=\"center\"><tr><td>";
	print "<table width=\"320\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\"><tr>";
print "<td bgcolor=\"#515173\"><font face=\"arial\" size=\"2\" color=\"FFFFFF\">"."<b><center>".$node_name." "." "." ".$node_ip."</b></center></td></tr>\n";
print "<td bgcolor=\"#515173\"><font face=\"arial\" size=\"2\" color=\"FFFFFF\">Data throughput amounts for interface nr. ".$interface."</td></tr>\n";
                print "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\">";
                print "<tr>";
                print "<td width=\"120\" bgcolor=\"#F2F2F2\">Period Start</td>\n";
		print "<td width=\"200\" bgcolor=\"#F2F2F2\">";
		print "Total throughput in MBytes (Incoming)";
		print "</td>";
                print "<td width=\"200\" bgcolor=\"#F2F2F2\">";
		print "Total throughput in MBytes (Outgoing)";
                print "</td>";
		print "</tr>";
for ($counter=0;$counter<=$intervalCounter;$counter++){
#$adjustedTime=$intervalTime[$counter] +3600;// wintertime 
$adjustedTime=$intervalTime[$counter];// summertime
$strPeriod= strftime("%y-%m-%d %R", $adjustedTime);
		print "<tr><td width=\"120\" bgcolor=\"#F2F2F2\">".$strPeriod."</td>\n";
		print "<td width=\"200\" bgcolor=\"#f2f2f2\">";
		$mbytes = round(($totalinBytes[$counter]/1000000),1);
		print ("$mbytes"."<br>\n");
		print "</td>";
                print "<td width=\"200\" bgcolor=\"#f2f2f2\">";
                $mbytes = round(($totaloutBytes[$counter]/1000000),1);
                print ("$mbytes"."<br>\n");
                print "</td></tr>";

		}
                print "</table>";
                print "</td><tr></table>";

  
?>
Return current item: WaveWatcher