<?php

	$sPage  = "places_zones";
	require("admin/§lib_inc.php");

	$FAMILY=isset($_REQUEST["FAMILY"])?$_REQUEST["FAMILY"] : -1; 
	$COUNTRY=isset($_REQUEST["PAYS"])?$_REQUEST["PAYS"] : 0; 
	$ZONE=isset($_REQUEST["ZONE"])?$_REQUEST["ZONE"] : 0; 
	$event=isset($_REQUEST["event"])?$_REQUEST["event"] : "all";
	
	$sTitle = decode_lng_text("DETAIL_ZONE_TITLE");
	$result = mysql_query( $sql_query="select oxg_countries.id_country, oxg_countries.libelle from oxg_countries where oxg_countries.id_country=$COUNTRY") or mysql_die();
	if($row = mysql_fetch_array($result))
	{
		$sTitle .= " : ".$row['libelle'];
	}
	$result_zone = mysql_query( $sql_query="select oxg_zones.code, oxg_zones.id_zone, oxg_zones.libelle, oxg_zones.info_map from oxg_zones where oxg_zones.id_country=$COUNTRY and oxg_zones.id_zone=$ZONE") or mysql_die();
	$row_zone = mysql_fetch_array($result_zone);
	if ($row_zone['libelle']!="")
	{
		$sTitle .= " : ".$row_zone['libelle'];
	}
	if ($row_zone['info_map']!="")
	{
		$sTypeInfoMap=substr($row_zone['info_map'], 0, 1);
		if($sTypeInfoMap=="!")
		{
			$sInfoMap=substr($row_zone['info_map'], 1);
			list($dlMinX, $dlMinY, $ulGrossissementX, $ulGrossissementY, $ulOffset)=preg_split("/[\s;]+/", $sInfoMap);
			$bModeCarte="MODE_CARTE_GOOGLE";
			list($width, $height, $type, $attr) = getimagesize("mpz".($COUNTRY*65536+$ZONE)."_9999.jpg");
		}
		else
		{
			$bModeCarte="";
		}
	}
	else
	{
		$bModeCarte="";
	}
	require("§menu.php");

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

	if(!function_exists('mysqli_connect'))
	{
		mysql_query($sql_query="SET OPTION SQL_BIG_SELECTS=1") or mysql_die();
	}

	$sql_query  = "select oxg_cities.code, oxg_cities.id_city, oxg_cities.libelle, longitude, latitude, count(*) as somme ";
	$sql_query .= "from oxg_cities, oxg_events2 ";
	$sql_query .= "where oxg_events2.id_country=$COUNTRY and oxg_events2.id_zone=$ZONE ";
	$sql_query .= "and oxg_cities.id_zone=$ZONE and oxg_cities.id_country=$COUNTRY ";
	$sql_query .= "and oxg_cities.id_city=oxg_events2.id_city ";
	$sql_query .= $sReqFam;
	$sql_query .= $sReqFiltre;
	$sql_query .= "group by oxg_cities.code, oxg_cities.id_city, oxg_cities.libelle ";
	$sql_query .= "order by oxg_cities.libelle, oxg_cities.code ";

	echo "<center><table><tr><td>";
	if($bModeCarte=="MODE_CARTE_GOOGLE")
	{
		echo "<map name=\"carte\">";
	}
	$iLineCount=0;
	$CityList="<table BORDER=0><tr><td>";
	$result_ville = mysql_query( $sql_query ) or mysql_die();
	while($row_ville = mysql_fetch_array($result_ville))
	{
		if($bModeCarte=="MODE_CARTE_GOOGLE")
		{
			$dMinX=$dlMinX;
			$dMinY=$dlMinY;
			$dMinX/=10000;
			$dMinY/=10000;
			$dGrossissementX=$ulGrossissementX;
			$dGrossissementY=$ulGrossissementY;
			$dGrossissementX/=10000;
			$dGrossissementY/=10000;
			$dPixelX=$ulOffset+($row_ville[longitude]-$dMinX)*$dGrossissementX;
			$dPixelY=$height-$ulOffset-($row_ville[latitude]-$dMinY)*$dGrossissementY;
			$ulPixelX=floor($dPixelX);
			$ulPixelY=floor($dPixelY);
			echo "<area shape=\"circle\" coords=\"".$ulPixelX.",".$ulPixelY.",10\" onmouseover=\"showmenu('t".$row_ville[id_city]."')\" onmouseout=\"hidemenu('t".$row_ville[id_city]."')\">";
			echo "<table class=\"menu\" id=\"t".$row_ville[id_city]."\">";
			echo "<tr><th valign=\"bottom\" align=\"right\" height=\"".($ulPixelY-7)."\" width=\"".($ulPixelX-2)."\"><font class=\"f1\" color=\"#000000\">".$row_ville[libelle]." ".$row_ville[code]."</font></th></tr>";
			echo "</table>";
		}
		$CityList.="<a href='§detail_ind_zone.php?COUNTRY=$COUNTRY&ZONE=$ZONE&CITY=$row_ville[id_city]&FAMILY=$FAMILY&event=$event' onmouseover=\"showmenu('t".$row_ville[id_city]."')\" onmouseout=\"hidemenu('t".$row_ville[id_city]."')\">$row_ville[libelle] $row_ville[code] ($row_ville[somme])</a>";
		if($iLineCount==3)
		{
			$CityList.="</td></tr><tr><td>";
			$iLineCount=0;
		}
		else
		{	
			$CityList.="</td><td>";
			$iLineCount++;
		}
	}
	if($bModeCarte=="MODE_CARTE_GOOGLE")
	{
		echo "</map>";
	}
	echo "<img src='mpz".($COUNTRY*65536+$ZONE)."_9999.jpg' useMap=\"#carte\"></center></td>";
	
	echo "<td>".$CityList."</td></tr></table></td></tr></table>";

	// Unknown places of the zone
	$sql_query  = "select count(*) as CNT ";
	$sql_query .= "from oxg_events2 ";
	$sql_query .= "where id_country=$COUNTRY and id_zone=$ZONE and id_city is null $sReqCont ";
	$sql_query .= $sReqFam;
	$sql_query .= $sReqFiltre;
	$result_ind = mysql_query( $sql_query ) or mysql_die();
	if($row_ind = mysql_fetch_array($result_ind))
	{
		if($row_ind['CNT']!="0")
		{
			echo "<p><a href='§detail_ind_zone.php?COUNTRY=$COUNTRY&ZONE=$ZONE&CITY=-1&FAMILY=$FAMILY&event=$event'>";
			display_lng_text("DETAIL_ZONE_UNKNOWN");
			echo " ($row_ind[CNT])";
			echo "</a></p>";
		}
	}
	affiche_pied_page(true);
?>

<style type="text/css">
a{ color:black ; text-decoration:none }
a:hover{ color:red }
td.menu{ text-align:center}
table.menu{position:absolute; visibility:hidden}
span.blue{color:yellow}
</style>
<script type="text/javascript">
function showmenu(id)
{
	if (document.getElementById)
	{
		document.getElementById(id).style.visibility="visible";
	}
	else if (document.all)
	{
		document.all[id].style.visibility="visible";
	}
	else if (document.layers)
	{
		document.layers[id].visibility="visible";
	}
}
function hidemenu(id)
{
	if (document.getElementById)
	{
		document.getElementById(id).style.visibility="hidden";
	}
	else if (document.all)
	{
		document.all[id].style.visibility="hidden";
	}
	else if (document.layers)
	{
		document.layers[id].visibility="hidden";
	}
}
</script>