<?php

	require("§lib_inc.php");

	set_time_limit(0);
	
	flush();

	//on vide la base avant d'insérer de nouvelles lignes
	mysql_query("truncate table oxg_stat_index");

	//stat pour chacune des familles
	$result = mysql_query( "select id_family from oxg_family where 1=1") or mysql_die();
	while($row = mysql_fetch_array($result))
	{
		$fml=$row['id_family'];
		$sReqFam="and id_family=$fml";
		create_stat($fml, $sReqFam);
		update_stat($fml, $sReqFam, "birth", "51,47,48,64");
		update_stat($fml, $sReqFam, "death", "77,55");
		update_stat($fml, $sReqFam, "wedding", "115");
	}

	//stat globale pour l'ensemble des familles
	$fml=-1;
	$sReqFam="";
	create_stat($fml, $sReqFam);
	update_stat($fml, $sReqFam, "birth", "51,47,48,64");
	update_stat($fml, $sReqFam, "death", "77,55");
	update_stat($fml, $sReqFam, "wedding", "115");

function create_stat($fml,$sReqFam)
{
	mysql_query("INSERT INTO oxg_stat_index (id_family) VALUES ($fml)") or mysql_die();
	$sRexclusion = "and type<>'45' and type<>'99' and type<>'125' and type<>'129' and type<>'148' and type<>'156' and type<>'163' and type<>'167' and type<>'179'";
	mysql_query("update oxg_stat_index set event=(select count(*) from oxg_events2 where 1=1 $sRexclusion $sReqFam) where id_family=$fml") or mysql_die();
	mysql_query("update oxg_stat_index set event_d=(select count(*) from oxg_events2 where devnt<>'0000-00-00' $sRexclusion $sReqFam) where id_family=$fml") or mysql_die();
	mysql_query("update oxg_stat_index set event_p=(select count(*) from oxg_events2 where id_country<>-1 $sRexclusion $sReqFam) where id_family=$fml") or mysql_die();
}

function update_stat($fml, $sReqFam, $evt_name, $evt_type)
{
	mysql_query("update oxg_stat_index set $evt_name=(select count(*) from oxg_events2 where oxg_events2.type in ($evt_type) $sReqFam) where id_family=$fml") or mysql_die();
	mysql_query("update oxg_stat_index set ".$evt_name."_d=(select count(*) from oxg_events2 where oxg_events2.type in ($evt_type) and devnt<>'0000-00-00' $sReqFam) where id_family=$fml") or mysql_die();
	mysql_query("update oxg_stat_index set ".$evt_name."_p=(select count(*) from oxg_events2 where oxg_events2.type in ($evt_type) and id_country<>-1 $sReqFam) where id_family=$fml") or mysql_die();
}

?>

<P>Table oxg_stat_index effectué
<?php
$CREAT=isset($_REQUEST["CREAT"])?$_REQUEST["CREAT"] : "";
if($CREAT=="AUTO")
{
	echo ("<p>");
	display_lng_text("ADM_DATA");
?>
	<SCRIPT LANGUAGE="JavaScript">
	<!--
	setTimeout("top.location.href = '§cal.php?CREAT=AUTO'",1);
	//-->
	</SCRIPT>
<?php
}
else
{
affiche_pied_page_admin(true);
}
?>
</body></html>