<?
include("./functions.php");
$db db_connect();


if ( 
"" == $date || "" == $column )
    
$q1 mysql_query("SELECT temp_inside,time_recieved FROM weather WHERE time_recieved >= DATE_SUB(now(),INTERVAL 1 DAY) AND time_recieved <= now()"$db);
    else
    
$q1 mysql_query("SELECT $column,time_recieved FROM weather WHERE time_recieved >= DATE_SUB('$date',INTERVAL 1 DAY) AND time_recieved <= '$date'"$db);

if (
0):
for (
$i=0$i <= 24 $i++ )
    {
    if (
12 == $i)
        
$xtics sprintf("%s\"%s\" %d,",$xtics"Noon"$i*100);
    else if (
24 == $i)
        
$xtics sprintf("%s\"%s\" %d",$xtics$i$i*100);
    else
        
$xtics sprintf("%s\"%s\" %d,",$xtics$i$i*100);
    }
printf("XTICS = %s\n",$xtics);
endif;

$samples=0;
$fp fopen("/tmp/" $column ".dat","w");
while ( 
$cur_wx mysql_fetch_array($q1) )
//for ( $i=0 ; $i<48 ; $i++ )
    
{
    if ( ! 
$cur_wx mysql_fetch_array($q1) )
        break;
    
$samples++;
    
$data $cur_wx[0];
    
$stamp $cur_wx[time_recieved];
        
/* 2000-08-04 13:47:40
         * 0123456789012345678
         */
        
$year substr($stamp,0,4);
        
$month substr($stamp,5,2);
        
$date substr($stamp,8,2);
        
$hour substr($stamp,11,2);
        
$min substr($stamp,14,2);
        
$sec substr($stamp,17,2);

    
$hour_percent = ($min/60) * 100;
    
$scale_time = ($hour*100) + $hour_percent;    /* is this right? */

    
fputs($fp,sprintf("%d\t%s\n",$scale_time,$data));

    }
fclose($fp);

if ( 
$samples )
    {
    
header("Content-type: image/gif");
    
passthru("/usr/bin/gnuplot < /usr/local/weather/" $column ".plot | /usr/bin/ppmtogif 2> /dev/null");
    } else  {
    
header("Content-type: image/gif");
    
passthru("/bin/cat /home/httpd/html/wxsrv/no-graph.gif");
    }
?>