<?
Header("Content-type: image/png");

ini_set("memory_limit","512M");

$day=$_GET["day"];
$maxcon=$_GET["maxcon"];

$conday=$_GET["conday"];

$avg=$_GET["avg"];

//print ">>".$conday;

/*$requete="select count(\"DATE\") as score,\"DATE\" from \"LOG\" group by \"DATE\" order by score DESC;";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);
$maxcon=$row["score"]-7;
*/

/*$requete="select count(distinct(\"DATE\")) as score2 from \"LOG\"";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);
$day=$row["score2"];
*/

//$day=12;
//$maxcon=23-7;

$larg=$day*30;
$long=$maxcon*15;

$image = imagecreate($larg+30,$long);

$noir = ImageColorAllocate($image,0,0,0); 
$vert = ImageColorAllocate($image,0,255,0);
$rouge = ImageColorAllocate($image,255,0,0);
$blanc = ImageColorAllocate($image,255,255,255);
$bleu = ImageColorAllocate($image,0,0,255);



$cont=(array) null;
$cont=explode("!",$conday);

$peak=(array) null;
$mean=(array) null;

for ($i=0;$i<count($cont)-1;$i++)
{
$tmp=(array) null;
$tmp=explode("@",$cont[$i]);
$date=$tmp[0];
$con=$tmp[1];

imageline($image,$larg/$day*($i+1),$long,$larg/$day*($i+1),$long-($con*10),$rouge);
imagestring($image, 1,$larg/$day*($i+1)-25 ,$long-($con*10)-10,  $date, $blanc);
imagestring($image, 1,$larg/$day*($i+1)-8 ,$long-($con*10)-20,  "($con)", $blanc);

//Rajout
$peak[count($peak)]=($larg/$day*($i+1))."@".(($long-($con*10)));

$mean[count($mean)]=($larg/$day*($i+1))."@".(($long-($con*10))/2);

}



$MEANY=0;
$MEANYp=0;

//Rajout
for ($i=0;$i<count($peak)-1;$i++)
{
$tmp=(array) null;
$tmp=explode("@",$peak[$i]);
$X=$tmp[0];
$Y=$tmp[1];
$tmp2=(array) null;
$tmp2=explode("@",$peak[$i+1]);
$Xp=$tmp2[0];
$Yp=$tmp2[1];



//// AJOUT ///////////////////////////////////////////////////// COURBE BLEUE ///////////////////////
/*if (($MEANY==0)&&($MEANYp==0)) {$MEANY=$Y;$MEANYp=$Yp;}
$MEANY=($MEANY+$Y)/2;
$MEANYp=($MEANYp+$Yp)/2;
//AJOUT
imageline($image,$X,$MEANY,$Xp,$MEANYp,$bleu);
*/
////////////////////////////////////////////////////////////////////////////////////////////////////


imageline($image,$X,$Y,$Xp,$Yp,$vert);



}



imagedashedline($image,0,$long-($avg*20),$larg,$long-($avg*20),$blanc);



/*

$i=1;
$con=2;
imageline($image,$larg/$day*$i,$long,$larg/$day*$i,$long-($con*20),$rouge);
imagestring($image, 1,$larg/$day*$i-25 ,$long-($con*20)-10,  "26/01/2006", $blanc);
imagestring($image, 1,$larg/$day*$i-8 ,$long-($con*20)-20,  "($con)", $blanc);

$i=2;
$con=3;
imageline($image,$larg/$day*$i,$long,$larg/$day*$i,$long-($con*20),$rouge);
imagestring($image, 1,$larg/$day*$i-25 ,$long-($con*20)-10,  "27/01/2006", $blanc);
imagestring($image, 1,$larg/$day*$i-8 ,$long-($con*20)-20,  "($con)", $blanc);
*/








imagepng($image);


?>