<?php

	$sPage  = "places_map";

	require("admin/§lib_inc.php");

	
	$PAYS=isset($_REQUEST["PAYS"])?$_REQUEST["PAYS"] : 0; 
	$FAMILY=isset($_REQUEST["FAMILY"])?$_REQUEST["FAMILY"] : -1; 

//	set_time_limit(0);
	
	flush();

	if($FAMILY!=-1)
	{
		$sReqFam="and id_family=$FAMILY";
	}
	else
	{
		$sReqFam="";
	}

	$result_info_pays = mysql_query( "select * from oxg_countries where id_country='$PAYS'");
	$row_info_pays = mysql_fetch_array($result_info_pays);
	$extension = strtolower($row_info_pays['extension']);

	$sTitle = $row_info_pays['libelle'];
	require("§menu.php");

	$id_type_evnt_plac=get_id_event_type("PLAC");
	$id_type_evnt_birth=get_id_event_type("BIRT");
	$id_type_evnt_death=get_id_event_type("DEAT");
	$id_type_evnt_marriage=get_id_event_type("MARR");
	
	$filtre = "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'";
//stat du nombre d'événements
	$sql_query="select COUNT(*) as somme from oxg_events2 where id_country=$PAYS $sReqFam $filtre";
	$result = mysql_query($sql_query) or mysql_die();
	$row = mysql_fetch_array($result);
	$nb_ind_pays = $row['somme'];

	$result = mysql_query( "select COUNT(*) as somme from oxg_events2 where 1=1 $sReqFam $filtre");
	$row = mysql_fetch_array($result);
	$nb_ind_total = $row['somme'];
	
	$prc_ind = number_format(($nb_ind_pays*100)/$nb_ind_total,1);

	echo "$nb_ind_pays ";
	if($nb_ind_pays>1)
	{
		display_lng_text("CARTE_PERSONS_EVENTS");
	}
	else
	{
		display_lng_text("CARTE_PERSONS_EVENT");
	}
	echo " $prc_ind% ".decode_lng_text("CARTE_PERSONS_EVENTS_T")."<br>";

//totaux des naissances, décès et mariages
	$result = mysql_query( "select COUNT(*) as somme from oxg_events2 where type=$id_type_evnt_birth $sReqFam");
	$row = mysql_fetch_array($result);
	$nb_birth_total = $row['somme'];
	$result = mysql_query( "select COUNT(*) as somme from oxg_events2 where type=$id_type_evnt_death $sReqFam");
	$row = mysql_fetch_array($result);
	$nb_death_total = $row['somme'];
	$result = mysql_query( "select COUNT(*) as somme from oxg_events2 where type=$id_type_evnt_marriage $sReqFam");
	$row = mysql_fetch_array($result);
	$nb_wedding_total = $row['somme'];
	$result = mysql_query( "select COUNT(*) as somme from oxg_individuals where 1=1 $sReqFam");
	$row = mysql_fetch_array($result);
	$nb_ind_total = $row['somme'];

//stat du nombre de naissances
	if($bSessionOk==false)
	{
		$result = mysql_query( "select COUNT(*) as somme from oxg_individuals where id_pays_naissance=$PAYS $sReqFam");
		$row = mysql_fetch_array($result);
		$nb_birth_ind = $row['somme'];
	
		$prc_ind = number_format(($nb_birth_ind*100)/$nb_ind_total,1);
		$prc_birth = number_format(($nb_birth_ind*100)/$nb_birth_total,1);
	
		echo "$nb_birth_ind ";
		if($nb_birth_ind>1)
		{
			display_lng_text("CARTE_PERSONS_BIRTH");
		}
		else
		{
			display_lng_text("CARTE_PERSON_BIRTH");
		}
		echo " $prc_ind% ".decode_lng_text("CARTE_PERSONS_IND_T")." $prc_birth% ".decode_lng_text("CARTE_PERSONS_BIRTH_T")."<br>";
	}
	
//stat du nombre de décès
	if($bSessionOk==false)
	{
		$result = mysql_query( "select COUNT(*) as somme from oxg_individuals where id_pays_deces=$PAYS $sReqFam");
		$row = mysql_fetch_array($result);
		$nb_death_ind = $row['somme'];
	
		$prc_ind = number_format(($nb_death_ind*100)/$nb_ind_total,1);
		$prc_death = number_format(($nb_death_ind*100)/$nb_death_total,1);
	
		echo "$nb_death_ind ";
		if($nb_death_ind>1)
		{
			display_lng_text("CARTE_PERSONS_DEATH");
		}
		else
		{
			display_lng_text("CARTE_PERSON_DEATH");
		}
		echo " $prc_ind% ".decode_lng_text("CARTE_PERSONS_IND_T")." $prc_death% ".decode_lng_text("CARTE_PERSONS_DEATH_T")."<br>";
	}
	
//stat du nombre des mariages
	$result = mysql_query( "select COUNT(*) as somme from oxg_events2 where type=$id_type_evnt_marriage and id_country=$PAYS $sReqFam");
	$row = mysql_fetch_array($result);
	$nb_wedding_ind = $row['somme'];

	$prc_wedding = number_format(($nb_wedding_ind*100)/$nb_wedding_total,1);

	echo "$nb_wedding_ind ";
	if($nb_wedding_ind>1)
	{
		display_lng_text("CARTE_PERSONS_WEDDING");
	}
	else
	{
		display_lng_text("CARTE_PERSON_WEDDING");
	}
	echo " $prc_wedding% ".decode_lng_text("CARTE_PERSONS_WEDDING_T")."<br>";


	echo "<CENTER><H3>";
	display_lng_text("CARTE_ZONE_SELECT");
	echo "</H3>";

	echo "<MAP name=carte>";
	$result_zones = mysql_query( "select libelle, code, id_zone, pos_remp_x, pos_remp_y, coord_zone, info_map from oxg_zones where id_country=$PAYS and id_zone<>-1");
	while($row_zones = mysql_fetch_array($result_zones))
	{
		$result_info_zone = mysql_query( "select COUNT(*) as somme from oxg_events where info1=$PAYS and info2=$row_zones[id_zone] $sReqFam");
		while($row_info_zone = mysql_fetch_array($result_info_zone))
		{
			echo "<AREA SHAPE=poly ALT='$row_zones[code] : $row_zones[libelle] ($row_info_zone[somme])'";
			if($row_zones['coord_zone']=='')
			{
				$pX=$row_zones['pos_remp_x']-7;
				$pY=$row_zones['pos_remp_y']-7;
				echo " COORDS=$pX,$pY";
				$pX=$row_zones['pos_remp_x']+7;
				$pY=$row_zones['pos_remp_y']-7;
				echo ",$pX,$pY";
				$pX=$row_zones['pos_remp_x']+7;
				$pY=$row_zones['pos_remp_y']+7;
				echo ",$pX,$pY";
				$pX=$row_zones['pos_remp_x']-7;
				$pY=$row_zones['pos_remp_y']+7;
				echo ",$pX,$pY";
			}
			else
			{
				echo " COORDS=$row_zones[coord_zone]";
			}
			if($row_zones['info_map']=="")
			{
				echo " HREF='detail_zone.php?PAYS=$PAYS&ZONE=".$row_zones['id_zone']."&FAMILY=$FAMILY#".$row_zones['id_zone']."'>";
			}
			else
			{
				echo " HREF='detail_carte_zone.php?PAYS=$PAYS&ZONE=".$row_zones['id_zone']."&FAMILY=$FAMILY#".$row_zones['id_zone']."'>";
			}
		}
	}
	echo "</MAP>";
	$fic_name="map$PAYS";
	$fic_name.="00_51.jpg";
	
	$file = @file($fic_name); 
	if($file==true)
	{	
		echo "<img src='$fic_name' useMap=#carte border=0></CENTER>";
	}
	else
	{
		echo "<img src='§carte_img.php?PAYS=$PAYS&FAMILY=$FAMILY' useMap=#carte border=0></CENTER>";
	}
	
	affiche_pied_page(true);
?>
