<?php

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

	$sTitle = decode_lng_text("PATRO_TITLE");
	
	$FAMILY=isset($_REQUEST["FAMILY"])?$_REQUEST["FAMILY"] : -1;
	$INITIALE=isset($_REQUEST["INITIALE"])?$_REQUEST["INITIALE"] : 'A'; 

	require("§menu.php");

	echo "<a name=\"top\"></a>";

//	set_time_limit(0);
	
	flush();

	if($bSessionOk==false)
	{
		$sReqCont="and contemporary=1";
	}
	else
	{
		$sReqCont="";
	}

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


	// Display first character of the names
	echo "<center>";
	for($i=65;$i<=90;$i++)
	{
		$c=chr($i);
		echo "<a href='§patro.php?INITIALE=$c&FAMILY=$FAMILY'><b>$c</b></a> &nbsp;";
	}
	echo "<a href='§patro.php?INITIALE=AUTRES&FAMILY=$FAMILY'><b>";
	display_lng_text("PATRO_OTHER");
	echo "</b></a>";

	echo " &nbsp;<a href='§patro_full.php?FAMILY=$FAMILY'><b>";
	display_lng_text("IDX_LIEUX_ALL");
	echo "</b></a>";

	if($INITIALE=="AUTRES")
	{
		$query = "select COUNT(*) as SOMME from oxg_patronyms, oxg_individuals where oxg_patronyms.id_patronym=oxg_individuals.id_patronym $sReqCont and (ASCII(upper(left(oxg_patronyms.libelle_ord,1)))<65 or ASCII(upper(left(oxg_patronyms.libelle_ord,1)))>90 or oxg_patronyms.libelle_ord='') $sReqFam";
		$result = mysql_query($query);
		if($row = mysql_fetch_array($result))
		{
			$rest = $row['SOMME'];
			if($rest!=0)
			{
				affiche_liste_patro("AUTRES", $FAMILY, $rest);
			}
		}
	}
	else
	{	
//		$query = "select upper(left(oxg_patronyms.libelle_ord,1)) as INITIALE, COUNT(*) as SOMME from oxg_patronyms, oxg_individuals where oxg_patronyms.id_patronym=oxg_individuals.id_patronym $sReqCont and upper(left(oxg_patronyms.libelle_ord,1))='$INITIALE' $sReqFam GROUP BY INITIALE";
//		$result = mysql_query($query);
//		while($row = mysql_fetch_array($result))
		{
//			affiche_liste_patro($row['INITIALE'], $FAMILY, $row['SOMME']);
			affiche_liste_patro($INITIALE, $FAMILY, 0);
		}
	}
	echo "</center>";
	affiche_pied_page(true);
?>
