<?php

	require("lib_inc.php");

	set_time_limit(0);

	echo("<html><body>");
	
	$sql_query="truncate table oxg_flashlist";
	$_SESSION['dbh']->query($sql_query) or mysqli_die()();

	echo "table vidée<br>";

	$sql_query="insert into oxg_flashlist (id_family, country, zone, city, name, pays, ville, birth, wedding, death, other, date_min, date_max) ";
	$sql_query.="select distinct evt_lieu.id_family, evt_lieu.id_country, evt_lieu.id_zone, evt_lieu.id_city, oxg_patronyms.libelle, oxg_countries.libelle, oxg_cities.libelle, 0, 0, 0, 0, '', ''  ";
	$sql_query.="from oxg_events2 evt_lieu, oxg_individuals, oxg_patronyms, oxg_countries, oxg_cities ";
	$sql_query.="where oxg_individuals.id_individual=evt_lieu.id_individu ";
	$sql_query.="and oxg_individuals.id_patronym=oxg_patronyms.id_patronym ";
	$sql_query.="and evt_lieu.id_city<>-1 ";
	$sql_query.="and oxg_countries.id_country=evt_lieu.id_country ";
	$sql_query.="and oxg_cities.id_country=evt_lieu.id_country ";
	$sql_query.="and oxg_cities.id_zone=evt_lieu.id_zone ";
	$sql_query.="and oxg_cities.id_city=evt_lieu.id_city ";
	$sql_query.="and evt_lieu.id_family=oxg_individuals.id_family ";
	$_SESSION['dbh']->query($sql_query) or mysqli_die()();

	echo "table chargée<br>";

	$sql_query="update oxg_flashlist set birth= ";
	$sql_query.="(select total from ";
	$sql_query.="	(select evt_lieu.id_family, evt_lieu.id_country, evt_lieu.id_zone, evt_lieu.id_city, oxg_patronyms.libelle, count(*) total ";
	$sql_query.="	from oxg_events2 evt_lieu ";
	$sql_query.="			, oxg_individuals ";
	$sql_query.="			, oxg_patronyms ";
	$sql_query.="	where evt_lieu.type=51 ";
	$sql_query.="	and evt_lieu.id_city<>-1 ";
	$sql_query.="	and oxg_individuals.id_individual=evt_lieu.id_individu ";
	$sql_query.="	and oxg_individuals.id_family=evt_lieu.id_family ";
	$sql_query.="	and oxg_individuals.id_patronym=oxg_patronyms.id_patronym ";
	$sql_query.="	group by evt_lieu.id_family, evt_lieu.id_country, evt_lieu.id_zone, evt_lieu.id_city, oxg_patronyms.libelle	) evt_naissance ";
	$sql_query.="	where evt_naissance.id_country=oxg_flashlist.country ";
	$sql_query.="	and evt_naissance.id_zone=oxg_flashlist.zone ";
	$sql_query.="	and evt_naissance.id_city=oxg_flashlist.city ";
	$sql_query.="	and evt_naissance.libelle=oxg_flashlist.name ";
	$sql_query.="	and total is not null ";
	$sql_query.="	and evt_naissance.id_family=oxg_flashlist.id_family) ";
	$_SESSION['dbh']->query($sql_query) or mysqli_die()();

	echo "nombres de maissances chargés<br>";

	$sql_query="update oxg_flashlist set wedding= ";
	$sql_query.="(select total from ";
	$sql_query.="	(select evt_lieu.id_family, evt_lieu.id_country, evt_lieu.id_zone, evt_lieu.id_city, oxg_patronyms.libelle, count(*) total ";
	$sql_query.="	from oxg_events2 evt_lieu ";
	$sql_query.="			, oxg_individuals ";
	$sql_query.="			, oxg_patronyms ";
	$sql_query.="	where evt_lieu.type=115 ";
	$sql_query.="	and evt_lieu.id_city<>-1 ";
	$sql_query.="	and oxg_individuals.id_individual=evt_lieu.id_individu ";
	$sql_query.="	and oxg_individuals.id_family=evt_lieu.id_family ";
	$sql_query.="	and oxg_individuals.id_patronym=oxg_patronyms.id_patronym ";
	$sql_query.="	group by evt_lieu.id_family, evt_lieu.id_country, evt_lieu.id_zone, evt_lieu.id_city, oxg_patronyms.libelle	) evt_naissance ";
	$sql_query.="	where evt_naissance.id_country=oxg_flashlist.country ";
	$sql_query.="	and evt_naissance.id_zone=oxg_flashlist.zone ";
	$sql_query.="	and evt_naissance.id_city=oxg_flashlist.city ";
	$sql_query.="	and evt_naissance.libelle=oxg_flashlist.name ";
	$sql_query.="	and total is not null ";
	$sql_query.="	and evt_naissance.id_family=oxg_flashlist.id_family) ";
	$_SESSION['dbh']->query($sql_query) or mysqli_die()();

	echo "nombres de mariages chargés<br>";

	$sql_query="update oxg_flashlist set death= ";
	$sql_query.="(select total from ";
	$sql_query.="	(select evt_lieu.id_family, evt_lieu.id_country, evt_lieu.id_zone, evt_lieu.id_city, oxg_patronyms.libelle, count(*) total ";
	$sql_query.="	from oxg_events2 evt_lieu ";
	$sql_query.="			, oxg_individuals ";
	$sql_query.="			, oxg_patronyms ";
	$sql_query.="	where evt_lieu.type=77 ";
	$sql_query.="	and evt_lieu.id_city<>-1 ";
	$sql_query.="	and oxg_individuals.id_individual=evt_lieu.id_individu ";
	$sql_query.="	and oxg_individuals.id_family=evt_lieu.id_family ";
	$sql_query.="	and oxg_individuals.id_patronym=oxg_patronyms.id_patronym ";
	$sql_query.="	group by evt_lieu.id_family, evt_lieu.id_country, evt_lieu.id_zone, evt_lieu.id_city, oxg_patronyms.libelle	) evt_naissance ";
	$sql_query.="	where evt_naissance.id_country=oxg_flashlist.country ";
	$sql_query.="	and evt_naissance.id_zone=oxg_flashlist.zone ";
	$sql_query.="	and evt_naissance.id_city=oxg_flashlist.city ";
	$sql_query.="	and evt_naissance.libelle=oxg_flashlist.name ";
	$sql_query.="	and total is not null ";
	$sql_query.="	and evt_naissance.id_family=oxg_flashlist.id_family) ";
	$_SESSION['dbh']->query($sql_query) or mysqli_die()();

	echo "nombres de décès chargés<br>";

	$sql_query="update oxg_flashlist set other= ";
	$sql_query.="(select total from ";
	$sql_query.="	(select evt_lieu.id_family, evt_lieu.id_country, evt_lieu.id_zone, evt_lieu.id_city, oxg_patronyms.libelle, count(*) total ";
	$sql_query.="	from oxg_events2 evt_lieu ";
	$sql_query.="			, oxg_individuals ";
	$sql_query.="			, oxg_patronyms ";
	$sql_query.="	where evt_lieu.type not in (77,115,51) ";
	$sql_query.="	and evt_lieu.id_city<>-1 ";
	$sql_query.="	and oxg_individuals.id_individual=evt_lieu.id_individu ";
	$sql_query.="	and oxg_individuals.id_family=evt_lieu.id_family ";
	$sql_query.="	and oxg_individuals.id_patronym=oxg_patronyms.id_patronym ";
	$sql_query.="	group by evt_lieu.id_family, evt_lieu.id_country, evt_lieu.id_zone, evt_lieu.id_city, oxg_patronyms.libelle	) evt_naissance ";
	$sql_query.="	where evt_naissance.id_country=oxg_flashlist.country ";
	$sql_query.="	and evt_naissance.id_zone=oxg_flashlist.zone ";
	$sql_query.="	and evt_naissance.id_city=oxg_flashlist.city ";
	$sql_query.="	and evt_naissance.libelle=oxg_flashlist.name ";
	$sql_query.="	and total is not null ";
	$sql_query.="	and evt_naissance.id_family=oxg_flashlist.id_family) ";
	$_SESSION['dbh']->query($sql_query) or mysqli_die()();

	echo "nombres de d'évènements chargés<br>";

//	$sql_query="UNLOCK TABLES";
//	$_SESSION['dbh']->query($sql_query) or mysqli_die()();

//	echo "tables dé-lockées";
?>

<P>Table oxg_flashlist effectué
	<SCRIPT LANGUAGE="JavaScript">
	<!--
	setTimeout("top.location.href = 'flash0.php?CREAT=AUTO'",1);
	//-->
	</SCRIPT>
</body></html>