<?php

	if($sPhpVersion>=540)
	{
		if (session_status() == PHP_SESSION_NONE)
		{
			session_start(); // début de session
		}
	}

	$bSessionOk=checksession();

	$FAMILY=isset($_REQUEST["FAMILY"])?$_REQUEST["FAMILY"] : -1;
	if($FAMILY!=-1)
	{
		$sReqFam="and id_family=$FAMILY";
	}
	else
	{
		$sReqFam="";
	}
	$id_type_evnt_plac=-1;
	$row_evnt = mysql_fetch_array(mysql_query( "select id_type_event from oxg_events_type WHERE code='PLAC'"));
	if($row_evnt)
	{
		$id_type_evnt_plac = $row_evnt['id_type_event'];
	}
// Calcul des 5 lieux les plus présents
	$places = array();
	$sql_query = "select oxg_countries.libelle, oxg_countries.id_country,  count(*) somme from oxg_events, oxg_countries where info1<>-1 and info2<>-1 $sReqFam and oxg_events.info1=oxg_countries.id_country and $id_type_evnt_plac=type group by oxg_countries.libelle order by somme desc LIMIT 5";
	$req=mysql_query($sql_query) or mysql_die();
	$nbre = 0;
	while($row = mysql_fetch_array($req))
	{
		$places[] = array('name'=>$row['libelle'], 'code'=>$row['id_country']);
		$nbre += 1;
	}

	$id_type_evnt_plac=-1;
	$row_evnt = mysql_fetch_array(mysql_query( "select id_type_event from oxg_events_type WHERE code='DATE'"));
	if($row_evnt)
	{
		$id_type_evnt_date = $row_evnt['id_type_event'];
	}
	$sTitleM2=$sTitle;
	$sTitle="";

	$FAMILY=isset($_REQUEST["FAMILY"])?$_REQUEST["FAMILY"] : -1;
	
	if (substr(substr($_SERVER["REQUEST_URI"],-9),0,6)=='?LANG=')
	{
		$link = substr($_SERVER["REQUEST_URI"], 0, (strlen($_SERVER["REQUEST_URI"])-8));
	}
	else
		if (substr(substr($_SERVER["REQUEST_URI"],-9),0,6)=='&LANG=')
	{
		$link = substr($_SERVER["REQUEST_URI"], 0, (strlen($_SERVER["REQUEST_URI"])-9));
	}
	else
	{
		if (substr($_SERVER["REQUEST_URI"],-4)=='.php')
		{
			$link = $_SERVER["REQUEST_URI"]."?";
		}
		else
		{
			if (substr($_SERVER["REQUEST_URI"],-1)=='/')
			{
				$link = $_SERVER["REQUEST_URI"]."index.php?";
			}
			else
			{
				$link = $_SERVER["REQUEST_URI"];
			}
		}
	}
?>

<html>
<head>
<link href="oxygen2.css" rel="stylesheet" type="text/css" media="screen" />
<link href="oxygen_print2.css" rel="stylesheet" type="text/css" media="print" />
</head>

<div id=menutop>

<body bgcolor=#ffffd9>
<table bgcolor="#593408" width="100%" cellspacing=0 cellpadding=10>
<tr><td width="260px"><center><?php display_country_flags("", $link); ?></center></td>
<td><center>
<table border="0" cellspacing="0" cellpadding="5" bgcolor=#ffffd9><tr><th>&nbsp; &nbsp; &nbsp;</th>
<?php

	if($sPage=="index")
	{
		?>
		<th><?php display_lng_text("INDEX_LNK_IDX"); ?></th><th> &nbsp; &nbsp; &nbsp; </th>
		<?php
	}
	else
	{
		?>
		<th><A HREF='index.php?FAMILY=<?php echo $FAMILY?>'><?php display_lng_text("INDEX_LNK_IDX"); ?></a></th><th> &nbsp; &nbsp; &nbsp; </th>
		<?php
	}
	if($sPage=="patro")
	{
		?>
		<th><?php display_lng_text("INDEX_LNK_PATRO"); ?></th><th> &nbsp; &nbsp; &nbsp; </th>
		<?php
	}
	else
	{
		?>
		<th><A HREF='patro.php?FAMILY=<?php echo $FAMILY?>'><?php display_lng_text("INDEX_LNK_PATRO"); ?></a></th><th> &nbsp; &nbsp; &nbsp; </th>
		<?php
	}
	if($sPage=="places")
	{
		?>
		<th><?php display_lng_text("INDEX_LNK_PLACES"); ?></th><th> &nbsp; &nbsp; &nbsp; </th>
		<?php
	}
	else
	{
		?>
		<th><A HREF='idx_lieux.php?FAMILY=<?php echo $FAMILY?>'><?php display_lng_text("INDEX_LNK_PLACES"); ?></a></th><th> &nbsp; &nbsp; &nbsp; </th>
		<?php
	}
	if($sPage=="stats")
	{
		?>
		<th><?php display_lng_text("INDEX_LINK_STATS"); ?></th><th> &nbsp; &nbsp; &nbsp; </th>
		<?php
	}
	else
	{
		?>
		<th><A HREF='top10.php?FAMILY=<?php echo $FAMILY?>'><?php display_lng_text("INDEX_LINK_STATS"); ?></a></th><th> &nbsp; &nbsp; &nbsp; </th>
		<?php
	}
	if($sPage=="family")
	{
		?>
		<th><?php display_lng_text("FAMILY_TITLE"); ?></th><th> &nbsp; &nbsp; &nbsp; </th>
		<?php
	}
	else
	{
		$result = mysql_query( "select count(*) SOMME from oxg_family");
		$row = mysql_fetch_array($result);
		if($row['SOMME']>1)
		{
			?>
			<th><A HREF='family.php?FAMILY=<?php echo $FAMILY?>'><?php display_lng_text("FAMILY_TITLE"); ?></a></th><th> &nbsp; &nbsp; &nbsp; </th>
			<?php
		}
	}
	if($sPage=="search")
	{
		?>
		<th><?php display_lng_text("INDEX_LNK_SEARCH"); ?></th><th> &nbsp; &nbsp; &nbsp; </th>
		<?php
	}
	else
	{
		?>
		<th><A HREF='recherche.php?FAMILY=<?php echo $FAMILY?>'><?php display_lng_text("INDEX_LNK_SEARCH"); ?></a></th><th> &nbsp; &nbsp; &nbsp; </th>
		<?php
	}
	if (isset($_SESSION['privilege']))
	{
		?>
		<th><A HREF='private.php?FAMILY=<?php echo $FAMILY?>&erreur=logout'><?php display_lng_text("INDEX_LNK_LOGOUT"); ?></a></th><th> &nbsp; &nbsp; &nbsp; </th>
		<?php
	}
	else
	{
		$url = str_replace ("&", "*", $_SERVER['REQUEST_URI']);
		?>
		<th><A HREF='private.php?FAMILY=<?php echo $FAMILY?>&URL=<?php echo $url?>'><?php display_lng_text("INDEX_LNK_PRIVATE"); ?></a></th><th> &nbsp; &nbsp; &nbsp; </th>
		<?php
	}
	if (isset($_SESSION['privilege']) and $_SESSION['privilege']=="admin")
	{
		?>
		<th><A HREF='user_admin.php?FAMILY=<?php echo $FAMILY?>'><?php display_lng_text("INDEX_LNK_ADMIN"); ?></a></th><th> &nbsp; &nbsp; &nbsp; </th>
		<?php
	}
	
?>
</tr></table>
</td></tr></table>
</div>
<table border=0 width=100%><tr><td>
<?php
	echo "<a name=\"top\"></a>";
	
	echo "<table>";
	echo "<tr><td id=menucote></td><td valign='top'>";
	echo "<tr><td width='300px' id=menucote>";
	echo "<table>";
	echo "<tbody><tr><td bgcolor='#593408' width='25%'><br>";
	echo "<font color='#fceed0' face='helvetica'><b>".decode_lng_text('INDEX_IND')."</b></font><br><br>";
	echo "<table border='0' cellpadding='10' cellspacing='0' width='98%'>";
	echo "<tbody><tr><td bgcolor='#fceed0' width='100%'><font color='#fceed0'>";
	echo "<a href='patro.php?FAMILY=$FAMILY'>".decode_lng_text('INDEX_LNK_PATRO')."</a></font><br>";
	echo "<font color='#fceed0'><a href='flashlist.php?FAMILY=$FAMILY'>".decode_lng_text('FLASH_TITLE')."</a></font><br>";
	echo "<font color='#fceed0'><a href='top10.php?FAMILY=$FAMILY'>".decode_lng_text('INDEX_LINK_STATS')."</a></font><br>";
	echo "<font color='#fceed0'><a href='recherche.php?FAMILY=$FAMILY'>".decode_lng_text('INDEX_LNK_SEARCH')."</a></font><br>";
	echo "</td></tr></tbody></table><br>";
	echo "<font color='#fceed0' face='helvetica'><b>".decode_lng_text('INDEX_LNK_PLACES')."</b></font><br><br>";
	echo "<table border='0' cellpadding='10' cellspacing='0' width='98%'>";
	echo "<tbody><tr><td bgcolor='#fceed0' width='100%'>";
	echo "<font color='#fceed0'><a href='idx_lieux.php?FAMILY=$FAMILY&amp;event=birth'>".decode_lng_text('GEDTAG_BIRT')."</a></font><br>";
	echo "<font color='#fceed0'><a href='idx_lieux.php?FAMILY=$FAMILY&amp;event=death'>".decode_lng_text('GEDTAG_DEAT')."</a></font><br>";
	echo "<font color='#fceed0'><a href='idx_lieux.php?FAMILY=$FAMILY'>".decode_lng_text('IDX_LIEUX_ALL')."</a></font><br>";
	echo "</td></tr></tbody></table><br>";
	echo "<font color='#fceed0' face='helvetica'><b>".decode_lng_text('GEDTAG_DATE')."</b></font><br><br>";
	echo "<table border='0' cellpadding='10' cellspacing='0' width='98%'>";
	echo "<tbody><tr><td bgcolor='#fceed0' width='100%'>";
	echo "<font color='#fceed0'><a href='birthday.php?FAMILY=$FAMILY'>".decode_lng_text('BIRTHDAY_INDEX')."</a></font><br>";
	echo "</td></tr></tbody></table><br>";
	echo "<font color='#fceed0' face='helvetica'><b>".decode_lng_text('IDX_LIEUX_MAP')."</b></font><br><br>";
	echo "<table border='0' cellpadding='10' cellspacing='0' width='98%'>";
	echo "<tbody><tr><td bgcolor='#fceed0' width='100%'>";
	$i = 0;
	while ($i < $nbre)
	{
		echo "<font color='#fceed0'><a href='carte.php?FAMILY=".$FAMILY."&PAYS=".$places[$i]['code']."'>".$places[$i]['name']."</a></font><br>";
		$i += 1;
	}
	echo "</td></tr></tbody></table>";
	echo "<br></td></tr></tbody></table>";
	echo "</td><td width='80%'>";
	echo "<center><h1>".$sTitleM2."</h1></center>";
	echo "<table cellpadding='10'cellspacing='0' width='100%' class='contour'>";
//	echo "<tr><td bgcolor='#593408' align='center'><font color='#fceed0' face='helvetica'><strong>&nbsp;Arbre</strong></font></td></tr><tr><td bgcolor='#fceed0'><br>";
	echo "<tr><td bgcolor='#fceed0'>";
?>