<?php
	$sPage="stats_day";
	require("admin/§lib_inc.php");

	$indice_mois=isset($_REQUEST["indice_mois"])?$_REQUEST["indice_mois"] : -1; 
	$indice_annee=isset($_REQUEST["indice_annee"])?$_REQUEST["indice_annee"] : -1; 
	$indice_jour=isset($_REQUEST["indice_jour"])?$_REQUEST["indice_jour"] : -1; 

	$sTitle  = display_lng_text("STATS_DAY_TITLE");
	$sTitle .= " ";
	$sTitle .= $indice_jour;
	$sTitle .= "/";
	$sTitle .= $indice_mois;
	$sTitle .= "/";
	$sTitle .= $indice_annee;
	require("§menu.php");
?>
<BR>
<P>
<TABLE BORDER WIDTH="95%"><TR bgcolor=lightblue>
<TD><CENTER><B><?php display_lng_text("STATS_IP") ?></B></CENTER></TD>
<TD><CENTER><B><?php display_lng_text("STATS_HOUR_GEGIN") ?></B></CENTER></TD>
<TD><CENTER><B><?php display_lng_text("STATS_HOUR_END") ?></B></CENTER></TD>
<TD><CENTER><B><?php display_lng_text("STATS_HITS") ?></B></CENTER></TD>
</TR>
<?php
	$old_id="";
	$cpt_lig=0;
	$old_ip=0;
	$debut_jour=mktime(0,0,0,$indice_mois,$indice_jour,$indice_annee);
	$debut_jour_suivant=$debut_jour+3600*24;

	mysql_query("SET OPTION SQL_BIG_SELECTS=1");

	$sql_query="select IP, PROVIDER, min(HEURE) as H_MIN, max(HEURE) as H_MAX, count(*) as SOMME from OXG_VISITES WHERE HEURE>$debut_jour AND HEURE<$debut_jour_suivant group by IP order by H_MIN";
	
	$result = mysql_query( $sql_query ) or mysql_die();
	while($row = mysql_fetch_array($result))
	{
		if($old_ip!=$row["IP"])
		{
			$cpt_lig++;
			$old_ip=$row["IP"];
		}
		if($cpt_lig&1)
		{
			echo "<TR BGCOLOR=#CCCCCC>";
		}
		else
		{
			echo "<TR BGCOLOR=#B5B5B5>";
		}
		echo "<TD><B><A HREF='§stats_visitor.php?indice_mois=$indice_mois&indice_annee=$indice_annee&indice_jour=$indice_jour&ip=$row[IP]'>$row[IP]</A></B><BR>";
		if($row["PROVIDER"]=="")
		{
			echo gethostbyaddr($row['IP']);
		}
		else
		{
			echo $row["PROVIDER"];
		}
		$sql_query="select PROVENANCE from OXG_VISITES WHERE IP='$row[IP]' AND HEURE>$debut_jour AND HEURE<$debut_jour_suivant order by length(PROVENANCE) desc";
		$result2 = mysql_query( $sql_query ) or mysql_die();
		if($row2 = mysql_fetch_array($result2))
		{
			if(strlen($row2["PROVENANCE"])>2)
			{
				$sProvSQL=formatage_chaine_sql($row2[PROVENANCE]);
				if(substr($sProvSQL,0,3)=="www")
				{
					$sProvSQL = "http://" . $sProvSQL;
				}
				$sql_query="select NULL from oxg_REFERENCEMENT WHERE ADRESSE=left('$sProvSQL',length(ADRESSE)) and SITE_VALIDE=1";
				$resultRef = mysql_query( $sql_query ) or mysql_die();
				if($rowRef = mysql_fetch_array($resultRef))
				{
					echo "<br><font color=red><b>$row2[PROVENANCE]</b></font>";
				}
				else
				{
					echo "<br>$row2[PROVENANCE]";
				}
			}
		}
		echo "</TD>";
		echo "<TD>";
		echo date("H:i", $row["H_MIN"]);
		echo "</TD><TD>";
		echo date("H:i", $row["H_MAX"]);
		echo "</TD>";
		echo "<TD>$row[SOMME]</TD>";
		echo "</TR>";
		flush();
	}
?>
</TABLE>
<?php
	affiche_pied_page(false);
?>