<?php

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

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

	$sReqFam="and id_family=$FAMILY";

	$sql_query = "select * from oxg_individuals where id_individual='$INDIVIDU' $sReqFam";
	$result_ind = mysql_query( $sql_query ) or mysql_die();
	$row_ind = mysql_fetch_array($result_ind);

	$sql_query="select libelle from oxg_patronyms where id_patronym='$row_ind[id_patronym]'";
	$result_patro = mysql_query( $sql_query ) or mysql_die();
	$row_patro = mysql_fetch_array($result_patro);

	$sNickname=get_event($INDIVIDU, $sReqFam, "GIVN", "NICK");

	$sTitle = decode_lng_text('IND_FICHE')." ".$row_ind['first_name']." ".$row_patro['libelle'];

	if($sNickname!="")
	{
		if($row_ind['sex']==1)	// Female
		{
			$sTitle.=" dite ".$sNickname;
		}
		else
		{
			$sTitle.=" dit ".$sNickname;
		}
	}

	if(isset($row_ind['sosa']) && $row_ind['sosa']!=-1)
	{
		$sTitle.=" <font color=red>".$row_ind['sosa']."</font>";
	}
	
	require("§menu.php");
	
	if($bSessionOk==false)
	{
		$sReqCont="and contemporary=1";
	}
	else
	{
		$sReqCont="";
	}

	//	set_time_limit(0);
	flush();

	$sql_query = "select right(date_naissance,4) as year1 from oxg_individuals where id_individual='$INDIVIDU' $sReqFam";
	$result_ind = mysql_query( $sql_query );
	while($row_ind = mysql_fetch_array($result_ind))
	{
		$year1 = $row_ind['year1'];
	}

	$sId_Event_Type_Marb=get_id_event_type("MARB");
	$sId_Event_Type_Div=get_id_event_type("DIV");
	$sId_Event_Type_Mar=get_id_event_type("MARR");
	$sId_Event_Type_Union=get_id_event_type("UNION");
	$sId_Event_Type_Date=get_id_event_type("DATE");
	$sId_Event_Type_Birth=get_id_event_type("BIRT");
	$sId_Event_Type_Baptism=get_id_event_type("CHR");
	$sId_Event_Type_Death=get_id_event_type("DEAT");
	$sId_Event_Type_Burial=get_id_event_type("BURI");
	$sId_Event_Type_File=get_id_event_type("FILE");

function affiche_lieu($country, $zone, $city, $sFullPlaceName)
{
	global $bUserPlaceNames, $sql_query;
	
	if($bUserPlaceNames==true and $sFullPlaceName!="")
	{
		return $sFullPlaceName;
	}
	else if($country=="")
	{
		return "";
	}
	else
	{
		$strVille = "";
		$strZone = "";
		$strPays = "";
		$strNote = "";
		$sql_query="select libelle from oxg_countries where id_country=$country";
		$result_pays = mysql_query($sql_query) or mysql_die();
		$row_pays = mysql_fetch_array($result_pays);
		if($zone!="")
		{
			$result_zone = mysql_query( $sql_query="select libelle from oxg_zones where id_country=$country and id_zone=$zone") or mysql_die();
			$row_zone = mysql_fetch_array($result_zone);
			if($city!="")
			{
				$result_ville = mysql_query( $sql_query="select libelle from oxg_cities where id_country=$country and id_zone=$zone and id_city=$city") or mysql_die();
				$row_ville = mysql_fetch_array($result_ville);
				if ($row_ville['libelle']!="")	{ $strVille = $row_ville['libelle'].", "; }
			}
			if ($row_zone['libelle']!="")	{ $strZone = $row_zone['libelle'].", "; }
		}
		if ($row_pays['libelle']!="")	{ $strPays = strtoupper($row_pays['libelle']); }
		if ($sFullPlaceName!="")	{ $strNote = " (".$sFullPlaceName.")"; }
		return $strVille.$strZone.$strPays.$strNote;
	}
}

function decode_place($place)
{
	global $bUserPlaceNames;

	if($bUserPlaceNames==false)
	{
		if (substr($place,-1)==")")
		{
			$place = substr($place, strpos($place, "(")+1, -1);
		}
	}
	return $place;
}

function load_common_events($ind, $sReqFam)
{
	global $sId_Event_Type_Birth, $sId_Event_Type_Baptism, $sId_Event_Type_Death, $sId_Event_Type_Burial;
	
	$event = array();
	$sql_query = "select * from oxg_events2 where id_individu=$ind $sReqFam and type in ('$sId_Event_Type_Birth', '$sId_Event_Type_Baptism', '$sId_Event_Type_Death', '$sId_Event_Type_Burial')";
	$result_event = mysql_query( $sql_query ) or mysql_die();
	while ($row_event = mysql_fetch_array($result_event))
	{
		$type = $row_event['type'];
		$event[$type] = array(
			'id_family' => $row_event['id_family'],
			'id_father' => $row_event['id_individu'],
			'id_event' => $row_event['id_event'],
			'type' => $row_event['type'],
			'libelle' => $row_event['libelle'],
			'date1' => $row_event['devnt'],
			'date2' => $row_event['sDtEvnt'],
			'place' => $row_event['sPlace'],
			'id_country' => $row_event['id_country'],
			'id_zone' => $row_event['id_zone'],
			'id_city' => $row_event['id_city'],
//			'note' => $note,
//			'info1' => $row_event['info1'],
//			'info2' => $row_event['info2'],
//			'info3' => $row_event['info3']
			);
	}
	return $event;
}

function load_event_union($ind, $conj, $sReqFam)
{
	$event = array();
	$sql_query_event = "select *, oxg_events_type.code from oxg_events, oxg_events_type where (id_father='$ind' and info2='$conj' OR info2='$ind' and id_father='$conj') and type_father=0 and oxg_events_type.id_type_event=oxg_events.type $sReqFam";
	$result_event = mysql_query( $sql_query_event ) or mysql_die();
	while ($row_event = mysql_fetch_array($result_event))
	{
		$sql_query_evt = "select * from oxg_events2 where id_event=$row_event[id_event] $sReqFam";
		$result_evt = mysql_query( $sql_query_evt ) or mysql_die();
		$row_evt = mysql_fetch_array($result_evt);
		$type = $row_event['type'];
		$event[$type] = array(
			'id_family' => $row_event['id_family'],
//			'id_father' => $row_event['id_individu'],
			'id_event' => $row_event['id_event'],
			'type' => $row_event['type'],
			'libelle' => $row_event['libelle'],
			'date1' => $row_evt['devnt'],
			'date2' => $row_evt['sDtEvnt'],
			'place' => $row_evt['sPlace'],
			'id_country' => $row_evt['id_country'],
			'id_zone' => $row_evt['id_zone'],
			'id_city' => $row_evt['id_city'],
//			'note' => $note,
			'info1' => $row_event['info1'],
			'info2' => $row_event['info2'],
			'info3' => $row_event['info3']
			);
	}
	return $event;
}

function load_age ($year1, $year2)
{
	if($year2=="NOWN" || $year2=="NOWN")
	{
		return "";
	}
	if ($year2!="" && $year1!="" && $year2!=null && $year1!=null)
	{
		if ($year2 == $year1)
		{
			$strAge = " < 1 ".decode_lng_text("STATS_OLD_2");
		}
		else if ($year2 > $year1)
		{
			$age = $year2 - $year1;
			$strAge = " ".decode_lng_text("STATS_OLD_1")." ".$age." ".decode_lng_text("STATS_OLD_2");
		}
		else
		{
			$strAge = " date error";
		}
		return $strAge;
	}	
}

function toggle_panel($texte)
{
	echo "<div id='mypanel' class='ddpanel'>";
	echo "<div id='mypanelcontent' class='ddpanelcontent'>";
	echo "<p style='padding:10px'>";
	echo $texte;
	echo "</p>";
	echo "<br style='clear: left' />";
	echo "</div>";
	echo "<div id='mypaneltab' class='ddpaneltab'>";
	echo "<a href='#'><span>More...</span></a>";
	echo "</div>";
	echo "</div>";
}

function load_note($idfather, $sReqFam, $type_father=1)
{
	$libelle="";
	$sql_query = "select libelle, id_event from oxg_events where id_father=$idfather and type=125 and type_father=$type_father $sReqFam";
	$result = mysql_query( $sql_query ) or mysql_die();
	if ($row = mysql_fetch_array($result))
	{
		$libelle = $row['libelle'];
		$sql_query2 = "select libelle, type from oxg_events where id_father=$row[id_event] and (type=68 or type=71) and type_father=1 $sReqFam ORDER BY id_event";
		$result2 = mysql_query( $sql_query2 ) or mysql_die();
		while ($row2 = mysql_fetch_array($result2))
		{
			if ($row2['type']==68) { $libelle = $libelle.$row2['libelle']; }
			if ($row2['type']==71) { $libelle = $libelle."<br>".$row2['libelle']; }
		}
	}
	return $libelle;
}

function load_title($ind, $sReqFam)
{
	$libelle="";
	$sql_query = "select libelle from oxg_events where id_father=$ind and type=167 and type_father=0 $sReqFam";
	$result = mysql_query( $sql_query ) or mysql_die();
	if ($row = mysql_fetch_array($result))
	{
		$libelle = $row['libelle'];
	}
	return $libelle;
}

function load_prof($ind, $sReqFam)
{
	$libelle="";
	$sql_query = "select libelle from oxg_events where id_father=$ind and type=129 and type_father=0 $sReqFam";
	$result = mysql_query( $sql_query ) or mysql_die();
	if ($row = mysql_fetch_array($result))
	{
		$libelle = $row['libelle'];
	}
	return $libelle;
}

function balloon($code, $text)
{
	if ($text)
	{
		echo "<div id='balloon$code' class='balloonstyle' style='width: 550px; background-color: lightyellow'>";
		echo $text;
		echo "</div>";
		$plus = " <a rel='balloon$code'>(".decode_lng_text('EVNT_MORE')."...)</a>";
	}
	else
	{
		$plus = "";	
	}
	return $plus;
}

function display_evnt_tree($id_event)
{
	global $sReqFam;
	global $sql_query;
	
	$sql_query = "select id_event, libelle, code from oxg_events, oxg_events_type where id_father=$id_event and type_father=1 and oxg_events.type=oxg_events_type.id_type_event $sReqFam";
	$result_event = mysql_query( $sql_query ) or mysql_die();
	while($row_event = mysql_fetch_array($result_event))
	{
		echo "<br>".decode_lng_text("GEDTAG_".$row_event['code'])." : ";
		if($row_event['code']=="TYPE")
		{
			echo decode_lng_text("GEDTAG_".$row_event['libelle']);
		}
		else
		{
			echo $row_event['libelle'];
		}
		display_evnt_tree($row_event['id_event']);
	}
}

function affichage_tableau_union($id_conjoint)
{
	global $sId_Event_Type_Mar, $style_1, $style_2, $style_3, $style_4, $FAMILY, $INDIVIDU, $sReqFam, $sId_Event_Type_Marb, $sId_Event_Type_Div, $row_ind, $sql_query, $sId_Event_Type_File;
	
	$sLibelleType=decode_lng_text("GEDTAG_UNION");
	echo "<table style='text-align: left; width: 100%;' border='0'";
	echo "cellpadding='2' cellspacing='1' BGCOLOR='black'>";;
	echo "<tbody>";
	echo "<tr>";
	echo $style_1.$sLibelleType."</td>";
	if($id_conjoint!=-1)
	{
		echo $style_4.affiche_lien_individu($FAMILY, $id_conjoint,true,true)."</td>";
		echo "</tr>";
		$event2 = load_event_union($INDIVIDU, $id_conjoint, $sReqFam);
		//Affichage publication des bans
		if (isset($event2[$sId_Event_Type_Marb]['id_event'])==true)
		{
			$note = load_note($event2[$sId_Event_Type_Marb]['id_event'], $sReqFam);
			$plus = balloon('$sId_Event_Type_Marb', $note);
			$country = $event2[$sId_Event_Type_Marb]['id_country'];
			$zone = $event2[$sId_Event_Type_Marb]['id_zone'];
			$city = $event2[$sId_Event_Type_Marb]['id_city'];
			$note = decode_place($event2[$sId_Event_Type_Marb]['place']);
			$year1 = substr($row_ind['date_naissance'],-4);
			$year2 = substr($event2[$sId_Event_Type_Marb]['date1'],0,4);
			$date1 = $event2[$sId_Event_Type_Marb]['date1'];
			$date1 = str_replace("-0", "-", $date1);
			$date1 = str_replace("-", "/", $date1);
			$date2 = $event2[$sId_Event_Type_Marb]['date2'];
			$date = $date1.":".$date2;
			$sLibelleType=decode_lng_text("GEDTAG_".$event2[$sId_Event_Type_Marb]['code']);
			echo "<tr>";
			echo $style_1.decode_lng_text('GEDTAG_MARB').$plus."</td>";
			echo $style_2.decode_date($date).load_age ($year1, $year2)."</td>";
			echo $style_3."<a href='§detail_ind_zone.php?COUNTRY=$country&ZONE=$zone&CITY=$city&FAMILY=$FAMILY'>".affiche_lieu($country,$zone,$city,$note)."</a></td>";
			echo "</tr>";
		}
		//Affichage mariage
		if (isset($event2[$sId_Event_Type_Mar]['id_event'])==true)
		{
			$note = load_note($event2[$sId_Event_Type_Mar]['id_event'], $sReqFam);
			$plus = balloon('$sId_Event_Type_Mar', $note);
			$country = $event2[$sId_Event_Type_Mar]['id_country'];
			$zone = $event2[$sId_Event_Type_Mar]['id_zone'];
			$city = $event2[$sId_Event_Type_Mar]['id_city'];
			$note = decode_place($event2[$sId_Event_Type_Mar]['place']);
			$year1 = substr($row_ind['date_naissance'],-4);
			$year2 = substr($event2[$sId_Event_Type_Mar]['date1'],0,4);
			$date1 = $event2[$sId_Event_Type_Mar]['date1'];
			$date1 = str_replace("-0", "-", $date1);
			$date1 = str_replace("-", "/", $date1);
			$date2 = $event2[$sId_Event_Type_Mar]['date2'];
			$date = $date1.":".$date2;
			if(isset($event2[$sId_Event_Type_Mar]['code']))
			{
				$sLibelleType=decode_lng_text("GEDTAG_".$event2[$sId_Event_Type_Mar]['code']);
			}
			else
			{
				$sLibelleType="";
			}
			echo "<tr>";
			echo $style_1.decode_lng_text('GEDTAG_MARR').$plus;
			//Affichage des photos du mariage
			$libelle="";
			$sql_query = "select libelle, id_event, type from oxg_events where type=$sId_Event_Type_Mar and ((id_father=$INDIVIDU and info2=$id_conjoint) or (info2=$INDIVIDU and id_father=$id_conjoint and type_father=0)) and type_father=0 $sReqFam";
			$result = mysql_query( $sql_query ) or mysql_die();
			while ($row = mysql_fetch_array($result))
			{
				if($row['type']==$sId_Event_Type_File)
				{
					echo " <img src='$row[libelle]' width=200 title='$row[libelle]'><br>";
				}
				else
				{
					$sql_query = "select libelle, type from oxg_events where id_father=$row[id_event] and type=$sId_Event_Type_File and type_father=1 $sReqFam ORDER BY id_event";
					$result2 = mysql_query( $sql_query ) or mysql_die();
					while ($row2 = mysql_fetch_array($result2))
					{
						echo " <img src='$row2[libelle]' width=200 title='$row2[libelle]'><br>";
					}
				}
			}
			echo "</td>";
			echo $style_2.decode_date($date).load_age ($year1, $year2)."</td>";
			echo $style_3."<a href='§detail_ind_zone.php?COUNTRY=$country&ZONE=$zone&CITY=$city&FAMILY=$FAMILY'>".affiche_lieu($country,$zone,$city,$note)."</a></td>";
			echo "</tr>";
		}
		//Affichage divorce
		if (isset($event2[$sId_Event_Type_Div]['id_event'])==true)
		{
			$note = load_note($event2[$sId_Event_Type_Div]['id_event'], $sReqFam);
			$plus = balloon('$sId_Event_Type_Div', $note);
			$country = $event2[$sId_Event_Type_Div]['id_country'];
			$zone = $event2[$sId_Event_Type_Div]['id_zone'];
			$city = $event2[$sId_Event_Type_Div]['id_city'];
			$note = decode_place($event2[$sId_Event_Type_Div]['place']);
			$year1 = substr($row_ind['date_naissance'],-4);
			$year2 = substr($event2[$sId_Event_Type_Div]['date1'],0,4);
			$date1 = $event2[$sId_Event_Type_Div]['date1'];
			$date1 = str_replace("-0", "-", $date1);
			$date1 = str_replace("-", "/", $date1);
			$date2 = $event2[$sId_Event_Type_Div]['date2'];
			$date = $date1.":".$date2;
			$sLibelleType=decode_lng_text("GEDTAG_".$event2[$sId_Event_Type_Div]['code']);
			echo "<tr>";
			echo $style_1.decode_lng_text('GEDTAG_DIV').$plus."</td>";
			echo $style_2.decode_date($date).load_age ($year1, $year2)."</td>";
			echo $style_3."<a href='§detail_ind_zone.php?COUNTRY=$country&ZONE=$zone&CITY=$city&FAMILY=$FAMILY'>".affiche_lieu($country,$zone,$city,$note)."</a></td>";
			echo "</tr>";
		}
	}
	
	//Affichage du ou des enfants de cette union
	$sql_query_child = "select id_individual, sex from oxg_individuals where (id_father='$INDIVIDU' and id_mother='$id_conjoint' OR id_father='$id_conjoint' and id_mother='$INDIVIDU') $sReqFam ORDER BY right(date_naissance,4)";
	$result_child = mysql_query( $sql_query_child ) or mysql_die();
	if (mysql_num_rows($result_child)>0)
	{
		echo $style_1.decode_lng_text('DETAIL_IND_CHILD')."</td>";
		echo $style_4;
		while($row_child = mysql_fetch_array($result_child))
		{
			$flag="";
			if ($row_child['sex']==1) { $flag="female.png"; }
			if ($row_child['sex']==0) { $flag="male.png"; }
			if($flag!="")
			{
				echo "<IMG SRC=$flag> ";
			}
			echo affiche_lien_individu($FAMILY, $row_child['id_individual'], true, true)."<br>";
		}
	}		
	echo "</td>";
	echo "</tr>";
	echo "</tbody>";
	echo "</table>";
	echo "<BR>";
}

//Vérification si accès zone privée
$result_ind = mysql_query( "select * from oxg_individuals where id_individual='$INDIVIDU' $sReqCont $sReqFam");
if ($row_ind = mysql_fetch_array($result_ind))
{
	//Affichage du sexe
	$flag="";
	if ($row_ind['sex']==1) { $flag="female.png"; }
	if ($row_ind['sex']==0) { $flag="male.png"; }
	echo "<div id=button>";
	if($flag!="")
	{
		echo "  <IMG SRC=$flag WIDTH=24 HEIGHT=24> ";
	}
	
	//Affichage du lien vers l'arbre vertical et horizontal
	echo affiche_lien_arbre($FAMILY, $INDIVIDU);
	echo " ";
	//Affichage du lien vers la liste de déscendance
	echo "<A HREF='§asc_individu.php?INDIVIDU=$INDIVIDU&FAMILY=$FAMILY'><IMG SRC='list1.png' ALT='Voir liste des ascendants'></A>";
	echo " ";
	$req_ = "select count(*) as SOMME from oxg_individuals where (id_father='$INDIVIDU' or id_mother='$INDIVIDU') $sReqFam";
	$result_ = mysql_query( $req_ ) or mysql_die();
	$row_ = mysql_fetch_array($result_);
	if ($row_['SOMME'] != 0)
	{
		//Affichage du lien vers la liste de déscendance
		echo "<A HREF='§desc_individu.php?INDIVIDU=$INDIVIDU&FAMILY=$FAMILY'><IMG SRC='list2.png' ALT='".decode_lng_text('DETAIL_IND_DESC')."'></A>";
	}
	echo "</div>";
	echo "<BR>";
	
	//variables de styles pour les tableaux
	$style_1 = "<td style='width: 20%; background-color: rgb(66, 90, 116);'>";
	$style_2 = "<td style='width: 25%; background-color: rgb(255, 255, 255);'>";
	$style_3 = "<td style='width: 55%; background-color: rgb(255, 255, 255);'>";
	$style_4 = "<td style='width: 80%; background-color: rgb(255, 255, 255);' colspan='2' row_indspan='1'>";
		
	//Recherche de l'individu et affichage du tableau principal
	$sql_query_ind = "select * from oxg_patronyms, oxg_individuals where oxg_individuals.id_individual='$INDIVIDU' and oxg_patronyms.id_patronym=oxg_individuals.id_patronym $sReqFam";
	$result_ind = mysql_query( $sql_query_ind ) or mysql_die();
	$row_ind = mysql_fetch_array($result_ind);
	echo "<table style='text-align: left; width: 100%;' border='0'";
	echo "cellpadding='2' cellspacing='1' BGCOLOR='black'>";
	echo "<tbody>";
	echo "<tr BGCOLOR='white'>";
	//Affichage du prénom
	echo $style_1.decode_lng_text('SEARCH_FISRT_NAME')."</td>";
	echo $style_4.$row_ind['first_name']."</td>";
	echo "</tr>";
	//Affichage du nom
	echo "<tr>";
	echo $style_1.decode_lng_text('SEARCH_LAST_NAME')."</td>";
	echo $style_4.$row_ind['libelle']."</td>";
	echo "</tr>";
	// Display Nickname
	$sNickname=get_event($INDIVIDU, $sReqFam, "GIVN", "NICK");
	if($sNickname!="")
	{
		echo "<tr>";
		echo $style_1.decode_lng_text('GEDTAG_NICK')."</td>";
		echo $style_4.$sNickname."</td>";
		echo "</tr>";
	}
	//Affichage du titre
	$title = load_title ($INDIVIDU, $sReqFam);
	if ($title)
	{
		echo "<tr>";
		echo $style_1.decode_lng_text('GEDTAG_TITL')."</td>";
		echo $style_4.$title."</td>";
		echo "</tr>";
	}
	//Affichage de la profession
	$prof = load_prof ($INDIVIDU, $sReqFam);
	if ($prof)
	{
		echo "<tr>";
		echo $style_1.decode_lng_text('GEDTAG_OCCU')."</td>";
		echo $style_4.$prof."</td>";
		echo "</tr>";
	}

	$event = load_common_events($INDIVIDU, $sReqFam);
	// Display birth
	if (isset($event[$sId_Event_Type_Birth]['id_event'])==true)
	{
		$note = load_note($event[$sId_Event_Type_Birth]['id_event'], $sReqFam);
		$plus = balloon('$sId_Event_Type_Birth', $note);
		$country = $event[$sId_Event_Type_Birth]['id_country'];
		$zone = $event[$sId_Event_Type_Birth]['id_zone'];
		$city = $event[$sId_Event_Type_Birth]['id_city'];
		if(isset($event[$sId_Event_Type_Birth]['place']))
		{
			$note = decode_place($event[$sId_Event_Type_Birth]['place']);
		}
		else
		{
			$note="";
		}
		echo "<tr>";
		echo $style_1.decode_lng_text('GEDTAG_BIRT').$plus."</td>";
		//echo "<td style='width: 25%; background-color: rgb(204, 255, 255);'>".decode_date($event[$sId_Event_Type_Birth]['date'])."</td>";
		echo $style_2.decode_date_evnt($event[$sId_Event_Type_Birth])."</td>";
		echo $style_3."<a href='§detail_ind_zone.php?COUNTRY=$country&ZONE=$zone&CITY=$city&FAMILY=$FAMILY'>".affiche_lieu($country,$zone,$city,$note)."</a></td>";
		echo "</tr>";
	}
	// Display Batism
	if (isset($event[$sId_Event_Type_Baptism]['id_event']))
	{
		$note = load_note($event[$sId_Event_Type_Baptism]['id_event'], $sReqFam);
		$plus = balloon('$sId_Event_Type_Baptism', $note);
		$country = $event[$sId_Event_Type_Baptism]['id_country'];
		$zone = $event[$sId_Event_Type_Baptism]['id_zone'];
		$city = $event[$sId_Event_Type_Baptism]['id_city'];
		$note = decode_place($event[$sId_Event_Type_Baptism]['place']);
		echo "<tr>";
		echo $style_1.decode_lng_text('GEDTAG_BAPM').$plus."</td>";
		echo $style_2.decode_date_evnt($event[$sId_Event_Type_Baptism])."</td>";
		echo $style_3."<a href='§detail_ind_zone.php?COUNTRY=$country&ZONE=$zone&CITY=$city&FAMILY=$FAMILY'>".affiche_lieu($country, $zone, $city, $note)."</a></td>";
		echo "</tr>";
	}
	// Display death
	if (isset($event[$sId_Event_Type_Death]['id_event']))
	{
		$note = load_note($event[$sId_Event_Type_Death]['id_event'], $sReqFam);
		$plus = balloon('$sId_Event_Type_Death', $note);
		$country = $event[$sId_Event_Type_Death]['id_country'];
		$zone = $event[$sId_Event_Type_Death]['id_zone'];
		$city = $event[$sId_Event_Type_Death]['id_city'];
		$note = decode_place($event[$sId_Event_Type_Death]['place']);
		$year1 = substr($row_ind['date_naissance'],-4);
		$year2 = substr($event[$sId_Event_Type_Death]['date2'],-4);
		echo "<tr>";
		echo $style_1.decode_lng_text('GEDTAG_DEAT').$plus."</td>";
		//echo "<td style='width: 25%; background-color: rgb(204, 255, 255);'>".decode_date($event[$sId_Event_Type_Death]['date']).load_age ($year1, $year2)."</td>";
		echo $style_2.decode_date_evnt($event[$sId_Event_Type_Death]).load_age ($year1, $year2)."</td>";
		echo $style_3."<a href='§detail_ind_zone.php?COUNTRY=$country&ZONE=$zone&CITY=$city&FAMILY=$FAMILY'>".affiche_lieu($country, $zone, $city, $note)."</a></td>";
		echo "</tr>";
	}
	// Display Burial
	if (isset($event[$sId_Event_Type_Burial]['id_event']))
	{
		$note = load_note($event[$sId_Event_Type_Burial]['id_event'], $sReqFam);
		$plus = balloon('$sId_Event_Type_Burial', $note);
		$country = $event[$sId_Event_Type_Burial]['id_country'];
		$zone = $event[$sId_Event_Type_Burial]['id_zone'];
		$city = $event[$sId_Event_Type_Burial]['id_city'];
		$note = decode_place($event[$sId_Event_Type_Burial]['place']);
		echo "<tr>";
		echo $style_1.decode_lng_text('GEDTAG_BURI').$plus."</td>";
		echo $style_2.decode_date_evnt($event[$sId_Event_Type_Burial])."</td>";
		echo $style_3."<a href='§detail_ind_zone.php?COUNTRY=$country&ZONE=$zone&CITY=$city&FAMILY=$FAMILY'>".affiche_lieu($country, $zone, $city, $note)."</a></td>";
		echo "</tr>";
	}
	// End of table
	echo "</tbody>";
	echo "</table>";
	echo "<BR>";

	// Display parent table
	echo "<table style='text-align: left; width: 100%;' border='0'";
	echo "cellpadding='2' cellspacing='1' BGCOLOR='black'>";
	echo "<tbody>";
	echo "<tr>";
	echo $style_1.decode_lng_text('DETAIL_IND_FATHER')."</td>";
	echo $style_4.affiche_lien_individu($FAMILY, $row_ind['id_father'],true,true)."</td>";
	echo "</tr>";
	echo "<tr>";
	echo $style_1.decode_lng_text('DETAIL_IND_MOTHER')."</td>";
	echo $style_4.affiche_lien_individu($FAMILY, $row_ind['id_mother'],true,true)."</td>";
	echo "</tr>";
	echo "</tbody>";
	echo "</table>";
	echo "<BR>";

	// Display union table
	$sql_query_union="";
	
	$array_conjoints = array();
	$array_conjoints_mar = array();
	
	$sql_query="select id_individu, id_partner from oxg_events2 where id_individu=$INDIVIDU and type=$sId_Event_Type_Union $sReqFam";
	$result_conjoints = mysql_query( $sql_query ) or mysql_die();
	while($row_conjoints = mysql_fetch_array($result_conjoints))
	{
		if($sql_query_union!="")
		{
			$sql_query_union.= " or ";
		}
		$sql_query_union.="((oxg_events_mar.id_individu=$INDIVIDU and oxg_events_mar.id_partner=".$row_conjoints['id_partner'].") or (oxg_events_mar.id_partner=".$row_conjoints['id_partner']." and oxg_events_mar.id_individu=$INDIVIDU)) ";
		array_push($array_conjoints, $row_conjoints['id_partner']);
	}

	if($sql_query_union!="")
	{
		$sql_query="select oxg_events_mar.id_partner, oxg_events_mar.id_individu from oxg_events2 oxg_events_mar where (".$sql_query_union.") ";
		$sql_query.="and oxg_events_mar.type=$sId_Event_Type_Mar ";
		$sql_query.="order by oxg_events_mar.devnt";
	}
	else
	{
		$sql_query = "select id_individu, id_partner from oxg_events2 where id_individu=$INDIVIDU and type=$sId_Event_Type_Union $sReqFam";
	}
	$result_fam = mysql_query( $sql_query ) or mysql_die();
	while($row_fam = mysql_fetch_array($result_fam))
	{
		$id_conjoint=$row_fam['id_partner'];
		if($id_conjoint==$INDIVIDU)
		{
			$id_conjoint=$row_fam['id_individu'];
		}
		affichage_tableau_union($id_conjoint);
		array_push($array_conjoints_mar, $id_conjoint);
	}
	foreach ($array_conjoints as $conjoint)
	{
		if(in_array($conjoint, $array_conjoints_mar)==false)
		{
			affichage_tableau_union($conjoint);
		}
	}	
		
	// Display children if joint is known
	$id_conjoint = "-1";
	$sql_query_child = "select id_individual, sex from oxg_individuals where (id_father='$INDIVIDU' and id_mother='$id_conjoint' OR id_father='$id_conjoint' and id_mother='$INDIVIDU') $sReqFam ";
	$result_child = mysql_query( $sql_query_child ) or mysql_die();
	if (mysql_num_rows($result_child)>0)
	{
		echo "<table style='text-align: left; width: 100%;' border='0'";
		echo "cellpadding='2' cellspacing='1' BGCOLOR='black'>";;
		echo "<tbody>";
		echo "<tr>";
		echo $style_1."Union</td>";
		echo $style_4."?</td>";
		echo "</tr>";
		echo $style_1.decode_lng_text('DETAIL_IND_CHILD')."</td>";
		echo $style_4;
		while($row_child = mysql_fetch_array($result_child))
		{
			$flag="";
			if ($row_child['sex']==1) { $flag="female.png"; }
			if ($row_child['sex']==0) { $flag="male.png"; }
			if($flag!="")
			{
				echo "<IMG SRC=$flag> ";
			}
			echo affiche_lien_individu($FAMILY, $row_child['id_individual'], true, true)."<br>";
		}
		echo "</td>";
		echo "</tr>";
		echo "</tbody>";
		echo "</table>";
		echo "<BR>";
	}

	// Affichage des autres évènements de la personne
	$year = substr($row_ind['date_naissance'],-4);
	$sql_query_evt = "select * from oxg_events2, oxg_events_type where id_individu='$INDIVIDU' and oxg_events_type.code not in ('GIVN','UNION','NOTE','OCCU','NAME') and oxg_events2.type=oxg_events_type.id_type_event and type not in ($sId_Event_Type_Birth, $sId_Event_Type_Baptism, $sId_Event_Type_Death, $sId_Event_Type_Burial, $sId_Event_Type_Mar) $sReqFam order by left(devnt,4)";
	$result_evt = mysql_query( $sql_query_evt ) or mysql_die();
	echo "<table style='text-align: left; width: 100%;' border='0'";
	echo "cellpadding='2' cellspacing='1' BGCOLOR='black'>";
	echo "<tbody>";
	while($row_evt = mysql_fetch_array($result_evt))
	{
		$note = load_note ($row_evt['id_event'], $sReqFam);
		$plus = balloon($row_evt['id_event'], $note);
		$year1 = substr($row_ind['date_naissance'],-4);
		$year2 = substr($row_evt['devnt'],0,4);
		$date1 = $row_evt['devnt'];
		$date1 = str_replace("-0", "-", $date1);
		$date1 = str_replace("-", "/", $date1);
		$date2 = $row_evt['sDtEvnt'];
		$date = $date1.":".$date2;
		if($row_evt['code']=="?")
		{
			$sLibelleType=substr($row_evt['libelle'], 0, strpos($row_evt['libelle'], " "));
		}
		else if($row_evt['code']!="")
		{
			$sLibelleType=decode_lng_text("GEDTAG_".$row_evt['code']);
		}
		else
		{
			$sql_query_event = "select libelle from oxg_events where type=169 and id_father=$row_evt[id_event] $sReqFam";
			$result_event = mysql_query( $sql_query_event ) or mysql_die();
			$row_event = mysql_fetch_array($result_event);
			$sLibelleType=$row_event['libelle'];
			if ($sLibelleType=="")
			{
				$sLibelleType="Divers";
			}
		}
		echo "<tr>";
		echo $style_1.$sLibelleType.$plus."</td>";
		$country = $row_evt['id_country'];
		$zone = $row_evt['id_zone'];
		$city = $row_evt['id_city'];
		if($row_evt['code']=="?")
		{
			echo $style_4.substr($row_evt['libelle'], strpos($row_evt['libelle'], " ")+1);
		}
		else if($country=="" && $zone=="" && $city=="" && $date==":")
		{
			if($row_evt['code']=="ASSO")
			{
				echo $style_4.affiche_lien_individu($FAMILY, $row_evt['libelle'],true,true);
			}
			else
			{
				echo "$style_4".$row_evt['libelle'];
			}
			display_evnt_tree($row_evt['id_event']);
		}
		else
		{
			echo $style_2.decode_date($date).load_age($year1, $year2)."</td>";
			$note = decode_place($row_evt['sPlace']);
			echo $style_3."<a href='§detail_ind_zone.php?COUNTRY=$country&ZONE=$zone&CITY=$city&FAMILY=$FAMILY'>".affiche_lieu($country,$zone,$city,$note)."</a>";
		}
		echo "</td></tr>";
	}
	echo "</tr>";
	echo "</tbody>";
	echo "</table>";
	echo "<BR>";

	// Affichage des notes sur la personne
	$note = load_note ($INDIVIDU, $sReqFam, 0);
	if ($note)
	{
		echo "<table style='text-align: left; width: 100%;' border='0'";
		echo "cellpadding='2' cellspacing='1' BGCOLOR='black'>";
		echo "<tbody>";
		echo "<tr>";
		echo $style_1."Notes"."</td>";
		echo $style_4.$note."</td>";
		echo "</tr>";
		echo "</tbody>";
		echo "</table>";
		echo "<BR>";
	}

	//Affichage des photos de la personne
	$libelle="";
	$sql_query = "select libelle, id_event, type from oxg_events where type!=$sId_Event_Type_Mar and (id_father=$INDIVIDU or (info2=$INDIVIDU and type_father=0)) and type_father=0 $sReqFam";
	$result = mysql_query( $sql_query ) or mysql_die();
	while ($row = mysql_fetch_array($result))
	{
		if($row['type']==$sId_Event_Type_File)
		{
			echo "<img src='$row[libelle]' title='$row[libelle]'><br>";
		}
		else
		{
			$sql_query = "select libelle, type from oxg_events where id_father=$row[id_event] and type=$sId_Event_Type_File and type_father=1 $sReqFam ORDER BY id_event";
			$result2 = mysql_query( $sql_query ) or mysql_die();
			while ($row2 = mysql_fetch_array($result2))
			{
				echo "<img src='$row2[libelle]' title='$row2[libelle]'><br>";
			}
		}
	}
}
else
{
//echo "Vous n'avez pas accès à ces informations.";
echo "<BR>";
display_lng_text("PRIVATE_ERROR");
echo "<BR>";
}

	affiche_pied_page(true);

?>

<link rel="stylesheet" type="text/css" href="balloontip.css" />
<script type="text/javascript" src="balloontip.js">
/***********************************************
* Rich HTML Balloon Tooltip- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
</script>
