<?php

	$sPage  = "stats";
	$TableColor1 = "A6AEDF";
	$TableColor2 = "E1E3F0";
	require("admin/§lib_inc.php");

	$sTitle = decode_lng_text("STATS_TITLE");
	require("§menu.php");

	//set_time_limit(0);
	
	flush();

	$FAMILY=isset($_REQUEST["FAMILY"])?$_REQUEST["FAMILY"] : -1;
	if($FAMILY!=-1)
	{
		$sReqFam="and id_family=$FAMILY";
	}
	else
	{
		$sReqFam="";
	}

	if($bSessionOk==false)
	{
		$sReqCont="and contemporary=1";
	}
	else
	{
		$sReqCont="";
	}
	$sReqCont="";
	
	echo "<P><center><table bgcolor=\"#$TableColor1\" style=\"width: 80%; border-color: #$TableColor1; border-width: 0px; border-style: solid; border-radius: 10px;\" border=\"0\" cellspacing=5><tr><td bgcolor=\"#$TableColor1\" align=center>";
	
	echo "<P><center><table bgcolor=\"#$TableColor2\" style=\"width: 80%; border-color: #$TableColor2; border-width: 0px; border-style: solid; border-radius: 10px;\" border=\"0\" cellspacing=0><tr><td style='border-radius: 10px' bgcolor=\"#$TableColor2\" align=center>";

	echo "<p><table style='border-radius: 10px; width: 80%; text-align: left; width: 100%; border-width : 2px' align=left border=0 cellpadding=0 cellspacing=5><tr><td colspan=2 bgcolor=\"#$TableColor2\" align=left>";
	
	display_lng_text("STATS_INDIS");
//	$result = mysql_query( "select * from oxg_individuals where 1=1 $sReqFam");
//	echo " : ".mysql_num_rows($result);
	$result = mysql_query( "select count(*) as SOMME from oxg_individuals where 1=1 $sReqCont $sReqFam");
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
	echo " : ".number_format($row["SOMME"], 0, ',', ' ');

	$result = mysql_query( "select count(*) as SOMME from oxg_individuals where sex=0 $sReqCont $sReqFam");
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
	echo " (".number_format($row["SOMME"], 0, ',', ' ')." ";
	display_lng_text("STATS_SEXE_M");

	echo " - ";

	$result = mysql_query( "select count(*) as SOMME from oxg_individuals where sex=1 $sReqCont $sReqFam");
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
	echo " ".number_format($row["SOMME"], 0, ',', ' ')." ";
	display_lng_text("STATS_SEXE_F");
	
	echo ")<br>&nbsp;<br>";
	display_lng_text("STATS_PATROS");
	$result = mysql_query( "select count(*) as SOMME from oxg_individuals where 1=1 $sReqCont $sReqFam");
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
	echo " : <b>".number_format($row["SOMME"], 0, ',', ' ')."</b>";

	echo "</tr></td><tr><td style=\"vertical-align: middle;\">";
	echo display_lng_text("STATS_EVENTS");
	echo "</td><td bgcolor=\"#$TableColor2\" align=left>";

	echo "- ";
	echo display_lng_text("STATS_BIRTH");
	$row_evnt = mysql_fetch_array(mysql_query( "select id_type_event from oxg_events_type WHERE code='BIRT'"), MYSQL_ASSOC);
	$id_type_evnt = $row_evnt["id_type_event"];
	$result = mysql_query( "select count(*) as SOMME from oxg_events2 where type='$id_type_evnt' $sReqFam");
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
	echo " : <b>".number_format($row["SOMME"], 0, ',', ' ')."</b><br>";

	echo "- ";
	echo display_lng_text("STATS_MARRI");
	$row_evnt = mysql_fetch_array(mysql_query( "select id_type_event from oxg_events_type WHERE code='MARR'"), MYSQL_ASSOC);
	$id_type_evnt = $row_evnt["id_type_event"];
	$result = mysql_query( "select count(*) as SOMME from oxg_events2 where type='$id_type_evnt' $sReqFam");
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
	echo " : <b>".number_format($row["SOMME"], 0, ',', ' ')."</b><br>";

	echo "- ";
	echo display_lng_text("STATS_DEATH");
	$row_evnt = mysql_fetch_array(mysql_query( "select id_type_event from oxg_events_type WHERE code='DEAT'"), MYSQL_ASSOC);
	$id_type_evnt = $row_evnt["id_type_event"];
	$result = mysql_query( "select count(*) as SOMME from oxg_events2 where type='$id_type_evnt' $sReqFam");
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
	echo " : <b>".number_format($row["SOMME"], 0, ',', ' ')."</b>";
	
	echo "</td></tr></table></td></tr></table></center></p>";
	
/*	$result = mysql_query("select count(*) as somme from oxg_individuals where id_father!='-1' $sReqCont $sReqFam or id_mother!='-1' $sReqCont $sReqFam GROUP BY id_father, id_mother");
	$nbcouple = 0;
	$nbchildren = 0;
	while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{	$nbcouple += 1;
		$nbchildren += $row["somme"];
	}
	echo "<p>";
	echo display_lng_text("STATS_NB_CPL")." : <b>$nbcouple</b> ";

	$id_type_evnt_marr=0;
	$row_evnt = mysql_fetch_array(mysql_query( "select id_type_event from oxg_events_type WHERE code='MARR'"), MYSQL_ASSOC);
	$id_type_evnt_marr = $row_evnt["id_type_event"];
	$nbMarr = 0;
	$result = mysql_query( "select count(*) as SOMME from oxg_events2 where type='$id_type_evnt_marr' $sReqFam");
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
	$nbMarr = $row["SOMME"];
	
	if($nbMarr!=0)
	{
		display_lng_text('DETAIL_IND_WITH');
		echo " <b>$nbMarr</b> ";
		display_lng_text('GEDTAG_MARR');
	}
	echo "</p>";


	if ($nbcouple != 0) { $child = round($nbchildren/$nbcouple,2); } else { $child = 0; }
	display_lng_text("STATS_NB_CHIL");
	echo " : <b>$child</b></br>";
	
	//Calcul de la + grande famille
	$maxi = 0;
	$result = mysql_query("select count(*) as somme from oxg_individuals where id_father!='-1' $sReqCont $sReqFam or id_mother!='-1' $sReqCont $sReqFam GROUP BY id_father, id_mother");
	while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
		if ($row["somme"]>$maxi)
			{
			$maxi = $row["somme"];
			}
		}
	echo decode_lng_text("STATS_TOP15_FAM")." : <b>$maxi</b> ".decode_lng_text("STATS_TOP15_CHILDREN");
	
	echo "<P>";*/
	
	$here=decode_lng_text("STATS_HERE");	

//	echo decode_lng_text("STATS_TOP15_AGE")." ><a href='top_age.php?FAMILY=$FAMILY'><b>$here</b></a><<P>";

	echo "<center><table bgcolor=\"#$TableColor2\" style=\"width: 80%; border-color: #$TableColor2; border-width: 1px; border-style: solid; border-radius: 10px;\" border=\"0\"><tr><td align=center bgcolor=\"#$TableColor2\"><br>";
	
	echo decode_lng_text("STATS_ARTICLE")." 15 ".decode_lng_text("STATS_TOP15_PATRO")." ><a href='top_patro.php?FAMILY=$FAMILY&nbre=15'><b>$here</b></a><<br>&nbsp;<br>";

	echo decode_lng_text("STATS_ARTICLE")." 15 ".decode_lng_text("STATS_TOP15_FM")." ><a href='top_prenoms.php?FAMILY=$FAMILY&nbre=15&sexe=0'><b>$here</b></a><<br>&nbsp;<br>";

	echo decode_lng_text("STATS_ARTICLE")." 15 ".decode_lng_text("STATS_TOP15_FF")." ><a href='top_prenoms.php?FAMILY=$FAMILY&nbre=15&sexe=1'><b>$here</b></a><<br>&nbsp;<br>";

	echo decode_lng_text("STATS_ARTICLE")." 15 ".decode_lng_text("STATS_TOP15_B")." ><a href='top_date.php?FAMILY=$FAMILY&date=b&nbre=15'><b>$here</b></a><<br>&nbsp;<br>";

	echo decode_lng_text("STATS_ARTICLE")." 15 ".decode_lng_text("STATS_TOP15_M")." ><a href='top_date.php?FAMILY=$FAMILY&date=w&nbre=15'><b>$here</b></a><<br>&nbsp;<br>";

	echo decode_lng_text("STATS_ARTICLE")." 15 ".decode_lng_text("STATS_TOP15_D")." ><a href='top_date.php?FAMILY=$FAMILY&date=d&nbre=15'><b>$here</b></a><<br>&nbsp;<br>";

	echo "</td></tr></table></center><br>";	

	echo "</td></tr></table></center><br>&nbsp;<br>";
	
	echo "</TABLE></CENTER>";

	affiche_pied_page(true);

?>
