<?php

	$sPage  = "prenoms";
	require("admin/§lib_inc.php");

	require("§menu.php");

	//set_time_limit(0);

	// recup variable du formulaire
	$nbre = @$_GET['nbre'];
	$sexe = @$_GET['sexe'];
	if (empty($nbre)) {$nbre=10;}

	//$sTitle = decode_lng_text("STATS_TITLE");
	if ($sexe == 0) {$sTitle=decode_lng_text("STATS_ARTICLE")." $nbre ".decode_lng_text("STATS_TOP15_FM");}
	if ($sexe == 1) {$sTitle=decode_lng_text("STATS_ARTICLE")." $nbre ".decode_lng_text("STATS_TOP15_FF");}

	$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="";
	}


	echo "<CENTER><H2>";	
	//display_lng_text("STATS_TOP10");

	echo "</H2></CENTER>";	

	echo "<CENTER><TABLE border=1><TR bgcolor=lightblue align=center><TD>";
	echo "#";
	echo "</TD><TD>";
	display_lng_text("STATS_PATRO");
	echo "</TD><TD>";
	display_lng_text("STATS_NB");
	echo "</TD><TD>";
	echo "%";
	echo "</TD></TR>";


	//$result = mysql_query("select first_name from oxg_individuals where sex=$sexe $sReqCont $sReqFam GROUP BY first_name");
	$result = mysql_query("select first_name from oxg_individuals where sex=$sexe $sReqCont $sReqFam");
	$liste = "";
	$total = 0;	
	while ($row = mysql_fetch_array($result))
	{
		if ($liste!="")
		{$liste = $liste." ".$row['first_name'];}
		else
		{$liste = $row['first_name'];}
		$total = $total + 1;
	}

	$liste = explode(" ",$liste);
	$result = array_count_values($liste);
	arsort($result);

	$rank = 0;

	foreach ($result as $key => $val)
	{
	$rank = $rank + 1;
		if ($rank <= $nbre)
		{
		$perc = round($val/$total*100,1);
		$link = "<A HREF='§detail_prenom.php?FIRSTNAME=$key'>$key</A>";
		echo "<TR bgcolor=white align=right><TD>$rank</TD><TD align=left>$link</TD><TD align=center>$val</TD><TD>$perc</TD></TR>";
		}
	}

	echo "</TABLE></CENTER>";


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_F_L");
echo " <input type=text name=nbre value=\"$nbre\" MAXLENGTH=5 SIZE=5></td>\n<td>";
echo "<td>".decode_lng_text("STATS_TOP15_F_C")." ";
if ($sexe==0) {echo "<select name=sexe><OPTION value='0'>".decode_lng_text('STATS_SEXE_M')."</OPTION><OPTION value='1'>".decode_lng_text('STATS_SEXE_F')."</OPTION></select></td>";}
if ($sexe==1) {echo "<select name=sexe><OPTION value='1'>".decode_lng_text('STATS_SEXE_F')."</OPTION><OPTION value='0'>".decode_lng_text('STATS_SEXE_M')."</OPTION></select></td>";}
echo "<td><input type=submit value=".decode_lng_text('PRIVATE_ENTER')."></td>";
echo "</tr></table></form>";
echo "</center>";
echo "</div>";


	affiche_pied_page(true);

?>
