<?php
function affiche_liste_patro($INITIALE, $FAMILY, $somme)
{
	global $bSessionOk;

	if($bSessionOk==false)
	{
		$sReqCont="and contemporary=1";
	}
	else
	{
		$sReqCont="";
	}
	if($FAMILY!=-1)
	{
		$sReqFam="and id_family=$FAMILY";
	}
	else
	{
		$sReqFam="";
	}
	if($INITIALE=='AUTRES')
	{
		echo "<H3>";
		display_lng_text("PATRO_LIST_NO_LETTER");
		echo " <a name=\"AUTRES\"></a>";
//		display_lng_text("PATRO_PEOPLE");
		echo "</H3>";
		$sql_query_patro="select oxg_patronyms.id_patronym, oxg_patronyms.libelle_ord, COUNT(*) as SOMME from oxg_patronyms, oxg_individuals where oxg_patronyms.id_patronym=oxg_individuals.id_patronym $sReqFam $sReqCont and (upper(left(oxg_patronyms.libelle_ord,1))<'A' or upper(left(oxg_patronyms.libelle_ord,1))>'Z') GROUP BY oxg_patronyms.id_patronym, oxg_patronyms.libelle, oxg_patronyms.libelle_ord ORDER BY oxg_patronyms.libelle_ord, oxg_patronyms.id_patronym";
	}
	else
	{
		echo "<H3>";
		display_lng_text("PATRO_LIST_BEGINNING");
		echo " <a name=\"$INITIALE\">$INITIALE</a>";
		echo "</H3>";
		$sql_query_patro="select oxg_patronyms.id_patronym, oxg_patronyms.libelle_ord from oxg_patronyms where upper(left(oxg_patronyms.libelle_ord,1))='$INITIALE' ORDER BY oxg_patronyms.libelle_ord, oxg_patronyms.id_patronym";
	}
	
	flush();

//	mysql_query($sql_query="SET OPTION SQL_BIG_SELECTS=1") or mysql_die($sql_query);

	$result = mysql_query( $sql_query=$sql_query_patro ) or mysql_die();
	while($row = mysql_fetch_array($result))
	{
		$sql_query="select count(*) as SOMME from oxg_individuals where id_patronym=$row[id_patronym] $sReqFam $sReqCont";
		$result2 = mysql_query( $sql_query ) or mysql_die();
		$row2 = mysql_fetch_array($result2);
		if($row2['SOMME']!=0)
		{
			echo "<A HREF='§detail_patro.php?PATRO=$row[id_patronym]&FAMILY=$FAMILY'>";
			if($row['libelle_ord']=="")
			{
				echo "?</A> ($row2[SOMME])<BR>";
			}
			else
			{
				echo "$row[libelle_ord]</A> ($row2[SOMME])<BR>";
			}
			
			flush();
		}
	}
	echo "<p><a href=\"#top\">";
	display_lng_text("PATRO_LIST_TOP");
	echo "</a></p>";
}
?>