<?php

	require("§lib_inc.php");

	set_time_limit(0);

	echo("<html><body>");
	
	$sql_query="truncate table oxg_flashlist";
	mysql_query($sql_query) or mysql_die();

	echo "table vidée<br>";
	
	drop_index_if_exists("IDX_EVT2_FLASH_PLACE", "oxg_events2");
	drop_index_if_exists("IDX_INDI_FLASH", "oxg_individuals");
	drop_index_if_exists("IDX_PATRO_FLASH", "oxg_patronyms");
	mysql_query($sql_query="CREATE INDEX IDX_EVT2_FLASH_PLACE ON oxg_events2 (id_family, id_individu, id_city, id_zone, id_country)") or mysql_die();
	mysql_query($sql_query="CREATE INDEX IDX_INDI_FLASH ON oxg_individuals (id_family, id_individual, id_patronym)") or mysql_die();	
	mysql_query($sql_query="CREATE INDEX IDX_PATRO_FLASH ON oxg_patronyms (id_patronym, libelle)") or mysql_die();	

	$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 oxg_individuals.id_family=evt_lieu.id_family ";
	mysql_query($sql_query) or mysql_die();

	echo "table chargée<br>";

	drop_index_if_exists("IDX_EVT2_FLASH_PLACE", "oxg_events2");
	mysql_query($sql_query="CREATE INDEX IDX_EVT2_FLASH_PLACE ON oxg_events2 (id_family, id_individu, type, id_city, id_zone, id_country)") or mysql_die();

	$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) ";
	mysql_query($sql_query) or mysql_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) ";
	mysql_query($sql_query) or mysql_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) ";
	mysql_query($sql_query) or mysql_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) ";
	mysql_query($sql_query) or mysql_die();

	drop_index_if_exists("IDX_EVT2_FLASH_PLACE", "oxg_events2");

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

//	$sql_query="UNLOCK TABLES";
//	mysql_query($sql_query) or mysql_die();

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

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