<?php

	//$lien ="Router::url('patronymes/flashlist";

	if (!isset($this->request->params[0]) || $this->request->params[0]== "place") {
		$type ="place";
	}
	else{
		$type ="name";
	}
		
	echo "<center><h1>".decode_lng_text('FLASH_TITLE')."</h1></center>";
	

	echo "<div id=panel><center><table>";
	echo "<td>".decode_lng_text('FLASH_ORDER')."</td>";

	if ($type=="") {$type="place";}

	if ($type=="place")
	{
		echo "<td><b>".decode_lng_text('FLASH_PLACE')."</b></td>";
		$sortby = "pays, ville, name";
		$table = "<th><b>".decode_lng_text('GEDTAG_CTRY')."</b></th>";
		$table.= "<th><b>".decode_lng_text('GEDTAG_CITY')."</b></th>";
		$table.= "<th><b>".decode_lng_text('GEDTAG_NAME')."</b></th>";
	}
	else
	{
		echo "<td><a href='".router::url('patronymes/flashlist/place')."'>".decode_lng_text('FLASH_PLACE')."</a></td>";
	}

	if ($type=="name")
	{
		echo "<td><b>".decode_lng_text('FLASH_NAME')."</b></td>";
		$sortby = "name, pays, ville";
		$table = "<th><b>".decode_lng_text('GEDTAG_NAME')."</b></th>";
		$table.= "<th><b>".decode_lng_text('GEDTAG_CTRY')."</b></th>";
		$table.= "<th><b>".decode_lng_text('GEDTAG_CITY')."</b></th>";
	}
	else
	{
		echo "<td><a href='".router::url('patronymes/flashlist/name')."'>".decode_lng_text('FLASH_NAME')."</a></td>";
	}
		$table.= "<th><b><center>".decode_lng_text('GEDTAG_BIRT')."</center></b></th>";
		$table.= "<th><b><center>".decode_lng_text('GEDTAG_MARR')."</center></b></th>";
		$table.= "<th><b><center>".decode_lng_text('GEDTAG_DEAT')."</center></b></th>";
		$table.= "<th><b><center>".decode_lng_text('PATRO_OTHER')."</center></b></th>";
		$table.= "<th><b>min</b></th>";
		$table.= "<th><b>max</b></th><tr>";
	echo "</table>";
	echo "</div>";
	echo "<br>";


		$nb_res_max = count($_SESSION['t_flashlist']);
		
		if ($nb_res_max>0) {

		//on teste le parametre de limite
		if (!isset($this->request->params[1]) ) { $page = 1; }
		else { $page= $this->request->params[1];}
		
		if (empty($nb_res_par_page)) { $nb_res_par_page = 100; }
		$reload = 'patronymes/flashlist/'.$this->request->params[0].'/';

		echo '<div class="pagination" ><center><ul>';
		
 	// mise en place de la pagination		
		$total_pages = ceil($nb_res_max/$nb_res_par_page);
        $i_deb = ($page - 1) * $nb_res_par_page;
		$i_fin = $i_deb + $nb_res_par_page;
		if ($i_fin > $nb_res_max) {
			$i_fin = $nb_res_max;
		}
  
		
		if ($total_pages > 1) {
			echo Pagination($reload, $page, $total_pages);
		}
		
		echo "</ul></div><br/>";
		echo "";	
		//affichage du tableau final selon choix
		echo "<center><table border=1>";
		echo $table;
	
		for($i=$i_deb;$i<$i_fin;$i++) {
				$row=$_SESSION['t_flashlist'][$i];
			$link_city = "<a href='".router::url('lieux/detail_ind_zone/'.$row['country'].'/'.$row['zone'].'/'.$row['city'])."'>".$row['ville']."</a>";
			if ($type=="place") { 
				echo "<td>".$row['pays']."</td><td>".$link_city."</td><td>".$row['name']."</td>";
			}
			else { 
				echo "<td>".$row['name']."</td><td>".$row['pays']."</td><td>".$link_city."</td>";
			}
			echo "<td><center>".$row['birth']."</center></td>";
			echo "<td><center>".$row['wedding']."</center></td>";
			echo "<td><center>".$row['death']."</center></td>";
			echo "<td><center>".$row['other']."</center></td>";
			echo "<td><center>".$row['date_min']."</center></td>";
			echo "<td><center>".$row['date_max']."</center></td><tr>";
		}
		echo "</table></center>";
	}
	else {
		echo "<br>\n";
		display_lng_text("SEARCH_NO_RESULTS");
		echo "<br>\n";
	}	

	
