<?php

	$sPage="recherche";
	$sTitle="";

	require("admin/§lib_inc.php");
	require("admin/§lib_inc2.php");

	$sTitle = decode_lng_text("STATS_ARTICLE")." $nbre ".decode_lng_text("STATS_TOP15_PATRO");
	require("§menu.php");

	//set_time_limit(0);

	// recup variable du formulaire
	$nbre=isset($_REQUEST["nbre"])?$_REQUEST["nbre"] : 0; 
	$FAMILY=isset($_REQUEST["FAMILY"])?$_REQUEST["FAMILY"] : -1; 
	
	flush();

	if($bSessionOk==false)
	{
		$sReqCont="and contemporary=1";
	}
	else
	{
		$sReqCont="";
	}
	if($FAMILY!=-1)
	{
		$sReqFam="and id_family=$FAMILY";
	}
	else
	{
		$sReqFam="";
	}

	if(intval($nbre)>1)
	{
		echo "<CENTER><TABLE border=1><TR bgcolor=lightblue align=center><TD>";
		display_lng_text("STATS_PATRO");
		echo "</TD><TD>";
		display_lng_text("STATS_NB");
		echo "</TD></TR>";

		$result = mysql_query("	select id_patronym, COUNT(*) as SOMME from oxg_individuals where 1=1 $sReqCont $sReqFam GROUP BY id_patronym ORDER BY SOMME desc limit $nbre");

		while ($row = mysql_fetch_array($result))
		{
			$result2 = mysql_query("select libelle from oxg_patronyms where id_patronym=$row[id_patronym]");
			$row2 = mysql_fetch_array($result2);
			echo "<TR bgcolor=white><TD><A HREF='§detail_patro.php?PATRO=$row[id_patronym]&FAMILY=$FAMILY'>$row2[libelle]</A></TD><TD align=center>$row[SOMME]</TD></TR>";
		}
		echo "</TABLE></CENTER>";
	}
	else
	{
		echo " ";
		echo "valeur incorrecte";
		echo "</b> ";
		display_lng_text("SEARCH_PARAM_IGNORED");
		echo "<br>\n";
	}

	echo "<div id=panel>";
	echo "<br/>";
	echo "<br/>";
	echo "<form action=\"\" method=get>";
	echo "<input type=hidden name=FAMILY value=\"$FAMILY\">";
	echo "<center>";
	echo "<table border=1><tr><td>";
	echo decode_lng_text("STATS_TOP15_PATRO_L");
	echo " <input type=text name=nbre value=\"$nbre\" MAXLENGTH=5 SIZE=5></td>\n<td>";
	echo "<td><input type=submit value=".decode_lng_text('PRIVATE_ENTER')."></td></tr></table></form>";
	echo "</center>";
	echo "</div>";

	affiche_pied_page(true);
	@mysql_close($dbh);
?>