<?php

function affiche_ligne($id_family, $id_individual)
{
	global	$bSosa, $bSessionOk;

	if($id_family!=-1)
	{
		$sReqFam="and id_family=$id_family";
	}
	else
	{
		$sReqFam="";
	}
	
	$sInd="";
	
	$sReq  = "select first_name, libelle ";
	if($bSosa==true)
	{
		$sReq  .= ", sosa ";
	}
	$sReq .= ", date_naissance, date_deces ";
	$sReq .= " from oxg_individuals, oxg_patronyms ";
	$sReq .= "where id_individual='$id_individual' ";
	$sReq .= "and oxg_individuals.id_patronym=oxg_patronyms.id_patronym ";
	$sReq .= $sReqFam;

	$result = mysql_query( $sReq ) or mysql_die();
	if($row = mysql_fetch_array($result));
	{
		$sInd.="<TD>";
		$sInd.="<A HREF='§detail_individu.php?INDIVIDU=$id_individual&FAMILY=$id_family'>";
		if($row['first_name']=="")
		{
			$sInd.="?";
		}
		else
		{
			$sInd.=$row['first_name'];
		}
			$sInd.=" $row[libelle]";
		$sInd.="</A>";
		if($bSosa==true && $row['sosa']!='-1')
		{
			$sInd=$sInd." <strong><font color=red>$row[sosa]</font></strong>";
		}
		$sInd.="</TD><TD>";
		if($row['date_naissance']!="")
		{
			$sInd.="<CENTER>$row[date_naissance]</CENTER>";
		}
		else
		{
			$sInd.="<CENTER>?</CENTER>";
		}
		$sInd.="</TD><TD>";
		if($row['date_deces']!="")
		{
			$sInd.="<CENTER>$row[date_deces]</CENTER>";
		}
		else
		{
			if (substr($row['date_naissance'],-4)<1910)
			{$sInd.="<CENTER>?</CENTER>";} else
			{$sInd.="<CENTER>-</CENTER>";}
		}
		$sInd.="</TD>";
	}
	return $sInd;
}


	//début du script
	$sPage  = "asc";
	require("admin/§lib_inc.php");

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

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


//	set_time_limit(0);
	
	flush();
	
	$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 * 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);

	$sTitle = $row_ind['first_name']." ".$row_patro['libelle'];

	require("§menu.php");
	require("§progress_bar.php");


// recup variable du formulaire
	$gen_limit = @$_GET['gen_limit'];
	if  ($gen_limit=="") {$gen_limit=5;}
	$affichage = @$_GET['affichage'];
	if  ($affichage=="") {$affichage=1;}

echo "<div id=panel>";
echo "<form action=\"\" method=get>";
echo "<input type=hidden name=INDIVIDU value=\"$INDIVIDU\">";
echo "<input type=hidden name=FAMILY value=\"$FAMILY\">";
echo "<center>";
echo "<table border=1><tr>";
echo "<td>".decode_lng_text('TREE_NBGEN')." ";
echo  "<input type=text name=gen_limit value=\"$gen_limit\" MAXLENGTH=2 SIZE=2></td>";
echo "<td>".decode_lng_text('LIST_SHOW')." ";
if ($affichage==1) {echo "<select name=affichage><OPTION value='1'>".decode_lng_text('LIST_LIST')."</OPTION><OPTION value='2'>".decode_lng_text('LIST_CHAR')."</OPTION></select></td>";}
if ($affichage==2) {echo "<select name=affichage><OPTION value='2'>".decode_lng_text('LIST_CHAR')."</OPTION><OPTION value='1'>".decode_lng_text('LIST_LIST')."</OPTION></select></td>";}
echo "<td><input type=submit></td>";
echo "</tr></table></form>";
echo "</center>";
echo "</div>";

	echo "<br>";
	echo "<H3>";
	echo decode_lng_text('LIST_ASC_TITLE');
	echo "</H3>";

if ($affichage==1) {
echo "<BR><B>".decode_lng_text('LIST_GEN')." 1</B><BR>";
echo affiche_lien_individu($FAMILY,$INDIVIDU,true,true)."<BR>";
			}
if ($affichage==2) {
echo "<TABLE border=1>";
echo "<TD><B></TD><TD><B>".decode_lng_text('LIST_BIRTH_DATE')."</B></TD><TD><B>".decode_lng_text('LIST_DEATH_DATE')."</B></TD><TD><B>".decode_lng_text('LIST_PARENT')."</B></TD></TR>";
echo "<TD><BR><B>".decode_lng_text('LIST_GEN')." 1</B><BR></TD></TR>";
echo "".affiche_ligne($FAMILY,$INDIVIDU)."</TD></TR>";
			}

$all_count=1;
$new_tab = Array();
$new_tab[] = $INDIVIDU;
$G=1;
for ($L=2; $L<$gen_limit+1; $L++)
{
$new_gen = 0;
	if (count($new_tab)>0) {
		$tab = Array();
		$tab = $new_tab;
		$new_tab = Array();
		$count = count($tab);
		for ($i = 0; $i < $count; $i++) {
			// Affichage des parents
			$ind=$tab[$i];
			$result = mysql_query("SELECT id_father, id_mother FROM oxg_individuals WHERE id_individual=$ind $sReqFam");
			$row = mysql_fetch_array($result);
			$father=$row['id_father'];
			$mother=$row['id_mother'];
	if ($affichage==1) {
			if($new_gen==0 and ($father!="-1" or $mother!="-1")) {echo "<BR><B>".decode_lng_text('LIST_GEN')." $L</B><BR>";$new_gen=1;$G++;}
			if($father!="-1" and $father!="")
				{
				echo affiche_lien_individu($FAMILY, $father,true,true)."<I> ".decode_lng_text('LIST_FATHER')." ".affiche_lien_individu($FAMILY,$ind,true,false)."</I><BR>";
				$new_tab[]=$father;
				}
			if($mother!="-1" and $mother!="")
				{
				echo affiche_lien_individu($FAMILY, $mother,true,true)."<I> ".decode_lng_text('LIST_MOTHER')." ".affiche_lien_individu($FAMILY,$ind,true,false)."</I><BR>";
				$new_tab[]=$mother;
				}
	}
	if ($affichage==2) {
			if($new_gen==0 and ($father!="-1" or $mother!="-1")) {echo "<TD><BR><B>".decode_lng_text('LIST_GEN')." $L</B></TD></TR>";$new_gen=1;$G++;}
			if($father!="-1" and $father!="")
				{
				echo affiche_ligne($FAMILY, $father)."<I><TD> ".decode_lng_text('LIST_FATHER')." ".affiche_lien_individu($FAMILY,$ind)."</I></TD></TR>";
				$new_tab[]=$father;
				}
			if($mother!="-1" and $mother!="")
				{
				echo affiche_ligne($FAMILY, $mother)."<I><TD> ".decode_lng_text('LIST_MOTHER')." ".affiche_lien_individu($FAMILY,$ind)."</I></TD></TR>";
				$new_tab[]=$mother;
				}
	}
		}
	$all_count=$all_count+count($new_tab);
	$new_gen=0;
	}
}
if ($affichage==2) {echo "</TABLE>";}

echo "<BR>";
echo "<BR>";
$max=1;
for ($i=1; $i<=$G; $L++)
	{$max=$max*2;$i=$i+1;}
$max=$max-1;
echo decode_lng_text('LIST_TOTAL')." $all_count ".decode_lng_text('LIST_PEOPLE')." / $G ".decode_lng_text('LIST_GEN')." (max=$max)";

	affiche_pied_page(true);

?>

<html>
<script type="text/javascript">
document.getElementById('progress_bar').style.display="none"
</script>
</html>
