<?php

	$patronymes = $_SESSION['t_patronymes'];
	echo "<div>";	
	echo "<center><h1>".decode_lng_text('PATRO_TITLE')."</h1></center>";

	echo "<a name=\"top\"></a>";
	echo "<center>";
	for($i=65;$i<=90;$i++)
	{
		$lettre=chr($i);
		echo "<a href='".Router::url('patronymes/index/'.$lettre)."'><b>$lettre</b></a> &nbsp;";
	}
	echo "<a href='".Router::url('patronymes/index/Autres')."'><b>";
	echo display_lng_text("PATRO_OTHER");
	echo "</b></a> &nbsp;";

	echo "<a href='".Router::url('patronymes/index/Tous')."'><b>";
	//echo " &nbsp;<a href='patro_full.php?FAMILY=$FAMILY'><b>"; 
	echo display_lng_text("IDX_LIEUX_ALL");
	echo "</b></a>";
	echo "</center>";
	$INITIALE = $_SESSION['initiale'];
	if($INITIALE=='Tous') {
	}
	elseif($INITIALE=='Autres') {
			echo "<H3>";
			echo display_lng_text("PATRO_LIST_NO_LETTER");
			echo "  <a name=".$INITIALE."></a>";
			echo "</H3>";
		//	$sql_query="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 GROUP BY oxg_patronyms.id_patronym, oxg_patronyms.libelle, oxg_patronyms.libelle_ord having (ASCII(upper(left(oxg_patronyms.libelle_ord,1)))<65 or ASCII(upper(left(oxg_patronyms.libelle_ord,1)))>90) ORDER BY oxg_patronyms.libelle_ord, oxg_patronyms.id_patronym";
		}
		else {
			echo "<H3>";
			echo display_lng_text("PATRO_LIST_BEGINNING");
			echo " <a name=".$INITIALE.">".$INITIALE."</a>";
			echo "</H3>";
			
		// 	$sql_query="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";
		}
	foreach ($patronymes as $k => $row ) {

		//var_dump($patronymes[$k]);
		$row2 = $patronymes[$k];
			//var_dump($row2);
			if($row2['nombre']!=0) 	{
				if($INITIALE=='Tous') {
					if($row2['initiale']!=$reserve_initiale) {
						$reserve_initiale=$row2['initiale'];
						afficher_titre($row2['initiale']);
					}
				}
				echo "<a href='".Router::url('patronymes/detail_patro/'.$row2['id_patronym'])."'>";
				if($row2['nom']=="")
				{
					echo "?</a> (".$row2['nombre'].")<br>";
				}
				else
				{
					echo $row2['nom']."</a> (".$row2['nombre'].")<br>";
				}
			}
		
	}
	
	echo "<p><a href=\"#top\">";
	display_lng_text("PATRO_LIST_TOP");
	echo "</a></p>";

	
function afficher_titre($initiale) {
	
	if($initiale=='?') {
		echo "<H3>";
		echo display_lng_text("PATRO_LIST_NO_LETTER");
		echo "  <a name=".$initiale."></a>";
		echo "</H3>";
	//	$sql_query="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 GROUP BY oxg_patronyms.id_patronym, oxg_patronyms.libelle, oxg_patronyms.libelle_ord having (ASCII(upper(left(oxg_patronyms.libelle_ord,1)))<65 or ASCII(upper(left(oxg_patronyms.libelle_ord,1)))>90) ORDER BY oxg_patronyms.libelle_ord, oxg_patronyms.id_patronym";
	}
	else {
		echo "<H3>";
		echo display_lng_text("PATRO_LIST_BEGINNING");
		echo " <a name=".$initiale.">".$initiale."</a>";
		echo "</H3>";
		
	// 	$sql_query="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";
	}
}
	
	
// fin du div Corps
?>