Content-type: text/html X-Powered-By: PHP/4.3.10 <?
include("config.php");
    
$nowdate = getdate();
    
$days = $_REQUEST[days];
    
$weeks = $_REQUEST[weeks];
    if(
$_REQUEST[month])
        
$nowdate[mon] = $_REQUEST[month];
    if(
$_REQUEST[day])
        
$nowdate[mday] = $_REQUEST[day];
    
$admin = 0;
    if(
$_REQUEST[admin]=="xxxxxx")
        
$admin = 1;

    
$view = "week";
    if(
$_REQUEST[view])
        
$view = $_REQUEST[view];
    if(
$weeks)
       
$view="month";

    if(
$days < 1)
        
$days=7;
    if(
$weeks < 1)
          
$weeks = 1;
        if(
$weeks > 1)
          
$days=$weeks*7;

    
$day = $_REQUEST[day];
    if(
$day < 1)
        
$day=date("z")+2-$days;

    
//echo month=$
    
$date = mktime(0,0,0,$nowdate[mon],$nowdate[mday],$nowdate[year]);
    
$oneday = 86400; //seconds in one day
    
$startdate = $date - (($days-1) * $oneday);

    if(
strlen($_REQUEST[rain]))
       
writeRain(date("z", $startdate)+$days, $_REQUEST[rain]);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html40/loose.dtd">
<html>
<header>
<title>Router Stats</title>
</header>
<body>
<?//echo "Rainpath is $rainpath<br>"?>
<?
//echo "date is $date<br>"?>
<?
//echo "oneday is $oneday<br>"?>
<?
//echo "startdate is $startdate<br>"?>
<A href="router.php?days=7&day=<?echo $nowdate[mday]?>&month=<?echo $nowdate[mon]?>">View 7 days Detail</A> - or -
<A href="router.php?weeks=4&day=<?echo $nowdate[mday]?>&month=<?echo $nowdate[mon]?>">View 4 Weeks Overview</A>
<table cellpadding="0" cellspacing="1px">
<?
  
if($view=="week")
  {
    for(
$x=$startdate; $x<=$date; $x+=$oneday)
    {
      
$rain = getRain(date("z", $x)+1);
      
?><tr><td><?echo date("D d M",$x)?><BR><?echo $rain?>mm rain</td><td><embed src="svg2.php?fnumber=<?echo date("z",$x)+1?>" width="800" height="300" type="image/svg+xml"></embed></td></tr><?
    
}
  }
  if(
$view=="month")
  {
    
$x=$startdate;
    
?><tr><?
    
for($c=0; $c<7; $c++)
    {
      
?><TD align="center"><?echo date("D", $x+($c*$oneday))?></TD><?
    
}
    
?></tr><?
    
for($r=0; $r<$weeks; $r++)
    {
      
?><tr><?
      
for($d=0; $d<7; $d++)
      {
        
?><TD><embed src="svg2.php?fnumber=<?echo date("z",$x)+1?>&size=0&rulers=0&grid=1" width="140" height="150" type="image/svg+xml"></embed></TD><?
        $x
+=$oneday;
      }
      
?></tr><?
    
}
  }
?>
</table>
</body>

</html>
<?
function getRain($r)
{
  global
$rainpath;
  
$name = sprintf("$rainpath-%03d", $r);
//  print("<!--Opening Rain $name-->\n");
  
$fp=fopen($name, "r");
  if(!
$fp)
    return
0;
  
$rain = fgets($fp);
  
fclose($fp);
  return
$rain;
}

function
writeRain($d, $r)
{
  global
$rainpath;
  
$name = sprintf("$rainpath-%03d", $d);
  
$fp=fopen($name, "w");
  if(!
$fp)
    return
0;
  
fputs($fp, $r);
  
fclose($fp);
}
?>