<?php


	//$phase = isset($this->request->params[0]) ? 1 : 0;
	$page = isset($this->request->params[0])?$this->request->params[0] : 1; 
	if ($page== 'S') {$page=1;}

	echo "<center><h1>".decode_lng_text("BIRTHDAY_TITLE")."</h1></center></br>";

	$choice = $_SESSION['s_choice'];
	$period = $_SESSION['s_period'];

	echo "<form action=".Router::url('statistiques/birthday/S')." method='post'>";

	echo "<center>";
	echo "<table border=1 >";
	echo "</td></tr>";

	echo "<tr><td ><strong>".decode_lng_text("INDEX_EVENT")."</strong> &nbsp;&nbsp;";

	if ($choice=='birth') {$check='checked';} else {$check='';}
	echo "<input type='radio' name='choice' value='birth' ".$check.">&nbsp;".decode_lng_text("GEDTAG_BIRT")."&nbsp;&nbsp;&nbsp;";
	if ($choice=='wedding') {$check='checked';} else {$check='';}
	echo "<input type='radio' name='choice' value='wedding' ".$check.">&nbsp;".decode_lng_text("GEDTAG_MARR")."&nbsp;&nbsp;&nbsp;";
	if ($choice=='death') {$check='checked';} else {$check='';}
	echo "<input type='radio' name='choice' value='death' ".$check.">&nbsp;".decode_lng_text("GEDTAG_DEAT")."&nbsp;&nbsp;&nbsp;";
	if ($choice=='other') {$check='checked';} else {$check='';}
	echo "<input type='radio' name='choice' value='other' ".$check.">&nbsp;".decode_lng_text("PATRO_OTHER")."&nbsp;&nbsp;&nbsp;";
	if ($choice=='all') {$check='checked';} else {$check='';}
	echo "<input type='radio' name='choice' value='all' ".$check.">&nbsp;".decode_lng_text("IDX_LIEUX_ALL")."&nbsp;&nbsp;";
	echo "</td></tr>";
	
	echo "<tr><td ><center><strong>".decode_lng_text("BIRTHDAY_WHEN")."</strong> &nbsp;&nbsp;";

	if ($period=='today') {$check='checked';} else {$check='';}
	echo "<input type='radio' name='period' value='today' ".$check.">&nbsp;".decode_lng_text("BIRTHDAY_TODAY")."&nbsp;&nbsp;&nbsp;";
	if ($period=='tomorrow') {$check='checked';} else {$check='';}
	echo "<input type='radio' name='period' value='tomorrow' ".$check.">&nbsp;".decode_lng_text("BIRTHDAY_TOMOROW")."&nbsp;&nbsp;&nbsp;";
	if ($period=='week') {$check='checked';} else {$check='';}
	echo "<input type='radio' name='period' value='week' ".$check.">&nbsp;".decode_lng_text("BIRTHDAY_WEEK")."&nbsp;&nbsp;&nbsp;";
	if ($period=='month') {$check='checked';} else {$check='';}
	echo "<input type='radio' name='period' value='month' ".$check.">&nbsp;".decode_lng_text("BIRTHDAY_MONTH")."&nbsp;&nbsp;&nbsp;";

	echo "</center></td></tr></table></br>";
	
	echo "<center><input type=submit value=".decode_lng_text('PRIVATE_ENTER')." onClick='AttenteVisibility();'></center>";
	echo "</form></br>";
	
//var_dump($_SESSION['t_results_out']);
	
/*
*     Affichage du résultat
*/

	echo "<div> <img src='".IMAGES."ligne_orange.png' width=100% height='2px'></div>";
	echo "<div id='recherches_resultats' style='visibility:display;text-align:left;'>";
	echo "<table >";
	
	$nb_res_max = count($_SESSION['t_results_out']);

	if ($nb_res_max==0) 	{
		echo decode_lng_text("BIRTHDAY_NONE");
	}
	else {
		
		echo "<p style='color:#cc0000'><b><i><color=red>". $nb_res_max.' '.display_lng_text("SEARCH_FOUND_RESULTS")."</i></b></p>";
		
		if (empty($nb_res_par_page)) { $nb_res_par_page = 30; }
		
// 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 ($page == '-1') {
			$i_deb = 0;
			$i_fin = $nb_res_max;
			echo display_lng_text("SEARCH_RESULTS_NUMBERS")."&nbsp";
			echo $i_deb + 1 ." - ".$i_fin."<br>";
			echo "<a href=".Router::url('statistiques/birthday/1').">";
			echo display_lng_text("SEARCH_WITH_LIMITS");
			echo "</a></br></br>";
			
		}
		else {
			echo display_lng_text("SEARCH_RESULTS_NUMBERS")."&nbsp";
			echo $i_deb + 1 ." - ".$i_fin."</br></br>";
			$reload = 'statistiques/birthday/';

			
			

			if ($total_pages > 1) {
				echo '<div class="pagination"><ul>';	
				echo Pagination($reload, $page, $total_pages);

			
				echo "</ul></div>"; 
			
				// lien pour ne pas mettre de limites de résultats
				echo "<a href=".Router::url('statistiques/birthday/-1').">";
				echo display_lng_text("SEARCH_NO_LIMITS");
				echo "</a></br></br>";
			}
		}

		
		echo "<table>";
		$j=1;
		$row_out=array();

		for($i=$i_deb;$i<$i_fin;$i++) {
			$row_out=$_SESSION['t_results_out'][$i];
			//var_dump($row_out);


			// Affichage de la personne

			echo "<tr><th align=right>".decode_date($row_out['date'])."</th>";
			echo "<td>".$row_out['acte']." </th>";
			echo $row_out['nom_indiv'];

			//affichage du conjoint
				if($row_out['nom_compagne'] != '') {
					echo " ".decode_lng_text("GEDTAG_AND")." ".$row_out['nom_compagne'];

				}
			}
		
	echo "</table>";
	}
		echo "</br><div> <img src='".IMAGES."ligne_orange.png' width=100% height='2px'></div>";
	
	echo "</div>";
