<?php

	$sPage  = "date_zoom";
	require("admin/§lib_inc.php");
	require("admin/§lib_inc2.php");

	$FAMILY=isset($_REQUEST["FAMILY"])?$_REQUEST["FAMILY"] : -1; 
	$sTitle = decode_lng_text("DETAIL_DATE_TITLE");
	require("§menu.php");
	require("§progress_bar.php");

	$sBeginDate=isset($_REQUEST["DATE_BEG"])?$_REQUEST["DATE_BEG"] : 0; 
	$sEndDate=isset($_REQUEST["DATE_END"])?$_REQUEST["DATE_END"] : 0; 

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

// on test le parametre de limite
if (empty($limite))
	$limite=0;
	
// on determine le nombre de resultats vus par page
if (empty($nb_res_par_page))
	$nb_res_par_page = '100';
$limite_param=$limite;
$limite=intval($limite*$nb_res_par_page);

// on definit le nobmre de page avant les fleches << 1 2 3 >>
// mettre un chiffre pair
$nb_aff_page=9;

	//set_time_limit(0);
	
	flush();

	// tableau du filtrage
	echo "<div id=panel>";
	echo "<form action=\"\" method=get>";
	echo "<input type=hidden name=FAMILY value=\"$FAMILY\">";
	echo "<center>";
	echo "<table border=1><tr>";
	echo "<td>".decode_lng_text('DETAIL_DATE_BEGIN')." ";
	echo "<input type=text name=DATE_BEG value=\"$sBeginDate\" MAXLENGTH=4 SIZE=4></td>";
	echo "<td>".decode_lng_text('DETAIL_DATE_END')." ";
	echo "<input type=text name=DATE_END value=\"$sEndDate\" MAXLENGTH=4 SIZE=4></td>";
	echo "<td><input type=submit value=".decode_lng_text('PRIVATE_ENTER')."></td></tr></table></form>";
	echo "</center>";
	echo "</div>";

	// on recupere la page + les parametres
	$lien = $_SERVER['REQUEST_URI'];
	// on retire le parametre limit
	$pos = strpos($lien,'&limite=');
	if ($pos > 0)
	{
		$lien = substr($lien,0,$pos);
	}
		
	$id_type_evnt_plac="";
	$row_evnt = mysql_fetch_array(mysql_query( "select id_type_event from oxg_events_type WHERE code='DATE'"));
	if($row_evnt)
	{
		$id_type_evnt_date = $row_evnt['id_type_event'];
	}
	
	$tri_year = 'left(devnt,4)';
	$tri_month = 'right(left(devnt,7),2)+100';
	$tri_day = 'left(right(devnt,10),2)+100';

	$req_select = "select devnt, type, id_event from oxg_events2 where devnt<>'' and left(devnt,4)>=$sBeginDate and left(devnt,4)<=$sEndDate $sReqFam ORDER by $tri_year, $tri_month, $tri_day";
	$result2 = mysql_query($req_select);
	$nb_res_max = mysql_num_rows($result2);
	// on test si on affiche la limite de resulats
	if ($limite_param!=-1) { $req_select = $req_select." LIMIT $limite, $nb_res_par_page"; }
	$result = mysql_query($req_select);
	$nb_res = mysql_num_rows($result);
		if ($nb_res>0)
		{
		$limiteplus = intval($limite+$nb_res_par_page);
		if ($limiteplus>$nb_res_max)
			$limiteplus=$nb_res_max;
		$limitemoins = $limite+1;
		//echo "<hr>\n<b> $nb_res_max ";
		//display_lng_text("SEARCH_FOUND_RESULTS");
		//echo "  !</b> \n";
		if (($limite_param!=-1) && ($nb_res_max>$nb_res_par_page))
		{
			// lien pour ne pas mettre de limites de résultats
			echo "<a href=\"$lien&limite=-1\">";
			display_lng_text("SEARCH_NO_LIMITS");
			echo "</a><br>";
			
			//display_lng_text("SEARCH_RESULTS_NUMBERS");
			//echo " $limitemoins => $limiteplus<br>\n";
			display_lng_text("SEARCH_PAGE_NEXT");
			aff_numeros_pages($nb_res_par_page,$nb_aff_page,$nb_res_max,$lien,$limite_param);
			echo "<br>\n";
		}
	}
	else	
		{
		echo "<br>\n";
		display_lng_text("SEARCH_NO_RESULTS");
		echo "<br>\n";
	}	
	$cpt=1;	
	
	//affichage du tableau final selon choix
	echo "<BR>";
	echo "<table>";
	while($row = mysql_fetch_array($result))
	{
	$date1 = $row['devnt'];
	$date1 = str_replace("-0", "-", $date1);
	$date1 = str_replace("-", "/", $date1);
	$date2 = $row['sDtEvnt'];
	echo "<tr><th align=right>".decode_date($date1.":".$date2)."</th>";

		//$result_t = mysql_query( "select type, id_event, info2 from oxg_events where id_event=$row[id_father]");
		//$row_t = mysql_fetch_array($result_t);
		$compagne="";

		$acte=decode_lng_text("GEDTAG_EVEN");
		if ($row['type']==51) { $acte=decode_lng_text("GEDTAG_BIRT")." ".decode_lng_text("GEDTAG_OF"); }
		if ($row['type']==115) { $acte=decode_lng_text("GEDTAG_MARR")." ".decode_lng_text("GEDTAG_BTW"); $compagne = $row['id_event'];}
		if ($row['type']==82) { $acte=decode_lng_text("GEDTAG_DIV")." ".decode_lng_text("GEDTAG_BTW"); $compagne = $row['id_event'];}
		if ($row['type']==77) { $acte=decode_lng_text("GEDTAG_DEAT")." ".decode_lng_text("GEDTAG_OF"); }
		if ($row['type']==55) { $acte=decode_lng_text("GEDTAG_BURI")." ".decode_lng_text("GEDTAG_OF"); }
		if ($row['type']==47) { $acte=decode_lng_text("GEDTAG_BAPM")." ".decode_lng_text("GEDTAG_OF"); }
		if ($row['type']==64) { $acte=decode_lng_text("GEDTAG_BAPM")." ".decode_lng_text("GEDTAG_OF"); }
		echo "<td>".$acte." </th>";

		//affichage de la personne
		$id_ind = donne_ind_evnt($FAMILY, $row['id_event']);
		$result_cont = mysql_query( "select * from oxg_individuals where id_individual=$id_ind $sReqCont $sReqFam");
		if ($row_cont = mysql_fetch_array($result_cont))
			{
			echo affiche_lien_individu($FAMILY, $id_ind);
			}
		else
			{
			echo "X";
			}
		//affichage du conjoint
		if ($compagne != "") {
		$req = "select info2 from oxg_events where id_event=$compagne $sReqFam";
		$res = mysql_query($req);
		$row = mysql_fetch_array($res);
		$compagne = $row['info2'];
			$result_cont = mysql_query( "select * from oxg_individuals where id_individual=$compagne $sReqCont $sReqFam");
			if ($row_cont = mysql_fetch_array($result_cont))
				{
				echo " ".decode_lng_text("GEDTAG_AND")." ".affiche_lien_individu($FAMILY, $compagne, true, false);
				}
			else
				{
				echo " ".decode_lng_text("GEDTAG_AND")." X";
				}
		}

		echo "</td></tr>";
		flush();
	}
	echo "</table>";


	affiche_pied_page(true);

?>

<html>
<script type="text/javascript">
document.getElementById('progress_bar').style.display="none"
</script>
</html>
