<?php

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

	$FAMILY=isset($_REQUEST["FAMILY"])?$_REQUEST["FAMILY"] : -1; 

	$sTitle = decode_lng_text("BIRTHDAY_TITLE");
	require("§menu.php");
	require("§progress_bar.php");

	// recup variable du formulaire
	$DAY=isset($_REQUEST["DAY"])?$_REQUEST["DAY"] : 0;
	$MONTH=isset($_REQUEST["MONTH"])?$_REQUEST["MONTH"] : 0;
	$WHEN=isset($_REQUEST["WHEN"])?$_REQUEST["WHEN"] : 0;
	$limite=isset($_REQUEST["limite"])?$_REQUEST["limite"] : 0;
	$contempo = @$_GET['contempo'];
	$choice = @$_GET['choice'];
	if ($choice=="") {$choice="all";}

	//date_default_timezone_set('Europe/Paris');		//seulement pour la version PHP 5
	if ($DAY=="") {$DAY=date('j');}
	if ($MONTH=="") {$MONTH=date('n');}
	$month=decode_lng_text("MONTH$MONTH");
	if ($WHEN=="") {$WHEN='today';}
	if ($WHEN=="today") {$period=1;}
	if ($WHEN=="tomorrow") {$DAY++;$period=1;}
	if ($WHEN=="week") {$DAY++;$period=7;}
	if ($WHEN=="month") {$DAY++;$period=30;}

$Days_in_Month = Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
$limit=$Days_in_Month[$MONTH-1];
if ($DAY>$limit) {$MONTH+=1;$month=decode_lng_text("MONTH$MONTH");$DAY=1;}

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


	//set_time_limit(0);
	
	flush();


// affichage du babeau de critères
echo "<form action=\"\" method='get'>";
echo "<input type=hidden name=FAMILY value=\"$FAMILY\">";
echo "<input type=hidden name=limite value=\"$limite\">";
echo "<center>";
echo "<table border=1>";

echo "<tr><td>".decode_lng_text("INDEX_EVENT")." :</td>";
echo "<td colspan='4' rowspan='1'>";
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>";

echo "<td>";
display_lng_text("BIRTHDAY_CONTEMPO");
echo " : </td><td><select name=contempo>";
echo "<OPTION value=\"all\">";
display_lng_text("SEARCH_SEXE_NO");
echo "</OPTION>";
echo "<OPTION ";
if ($contempo=="yes")
echo "SELECTED ";
echo "value=\"yes\">";
display_lng_text("BIRTHDAY_WITH");
echo "</OPTION>";
echo "<OPTION ";
if ($contempo=="no")
echo "SELECTED ";
echo "value=\"no\">";
display_lng_text("BIRTHDAY_WITHOUT");
echo "</OPTION>";
echo "</SELECT></td>\n</tr>";

echo "<tr><td>".decode_lng_text("BIRTHDAY_WHEN")." :</td>";
echo "<td colspan='4' rowspan='1'>";
if ($WHEN=='today') {$check='checked';} else {$check='';}
echo "<input type='radio' name='WHEN' value='today' $check>&nbsp;".decode_lng_text("BIRTHDAY_TODAY")."&nbsp;&nbsp;&nbsp;";
if ($WHEN=='tomorrow') {$check='checked';} else {$check='';}
echo "<input type='radio' name='WHEN' value='tomorrow' $check>&nbsp;".decode_lng_text("BIRTHDAY_TOMOROW")."&nbsp;&nbsp;&nbsp;";
if ($WHEN=='week') {$check='checked';} else {$check='';}
echo "<input type='radio' name='WHEN' value='week' $check>&nbsp;".decode_lng_text("BIRTHDAY_WEEK")."&nbsp;&nbsp;&nbsp;";
if ($WHEN=='month') {$check='checked';} else {$check='';}
echo "<input type='radio' name='WHEN' value='month' $check>&nbsp;".decode_lng_text("BIRTHDAY_MONTH")."&nbsp;&nbsp;&nbsp;";
echo "</td>";
echo "<td><center><input type=submit value=".decode_lng_text('PRIVATE_ENTER')."></center></td>";
echo "</tr>";


echo "</table></form>";
echo "</center>";


	$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'];
	}
	$table=array();

for ($j=0; $j<$period; $j++) {
	$tri_year = 'left(devnt,4)';
	$tri_month = 'right(left(devnt,7),2)+100';
	$tri_day = 'left(right(devnt,11),2)+100';
	if ($choice=="birth") {$filter=" and type=51";}
	if ($choice=="wedding") {$filter=" and type=115";}
	if ($choice=="death") {$filter=" and type=77";}
	if ($choice=="other") {$filter="and type!=51 and type!=115 and type!=77";}
	if ($choice=="all") {$filter="";}
	$result = mysql_query( "select devnt, id_individu, type, id_event from oxg_events2 where right(left(devnt,7),2)+100='$MONTH'+100 and right(devnt,2)+100='$DAY'+100 and left(devnt,4)>$limite $sReqFam $filter ORDER by $tri_year, $tri_month, $tri_day");
	while($row = mysql_fetch_array($result))
	{
		$year = substr($row['devnt'], 0, 4);
		$ligne = "<tr><th align=right>".$DAY." ".$month." ".$year."</th>";

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

		$acte=decode_lng_text("GEDTAG_EVEN");
		$compagne="";
		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']==77) { $acte=decode_lng_text("GEDTAG_DEAT")." ".decode_lng_text("GEDTAG_OF"); }
		$ligne.= "<td>".$acte." </th>";

		$id_ind=donne_ind_evnt($FAMILY, $row['id_event']);
		$filter="";
		if ($contempo=="yes") {$filter=" and contemporary=0";}
		if ($contempo=="no") {$filter=" and contemporary=1";}
		$result_ind = mysql_query( "select contemporary from oxg_individuals where id_individual=$id_ind $sReqFam $filter");
		if ($row_ind = mysql_fetch_array($result_ind))
			{
			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 $sReqFam");
				if ($row_cont = mysql_fetch_array($result_cont))
					{
					$compagne = " ".decode_lng_text("GEDTAG_AND")." ".affiche_lien_individu($FAMILY, $compagne, true, false);
					}
				else
					{
					$compagne = " ".decode_lng_text("GEDTAG_AND")." X";
					}
				}
			$ligne.= "".affiche_lien_individu($FAMILY, $id_ind).$compagne;
			$ligne.= "</td></tr>";
			$table[]=$ligne;
			}

		flush();
	}
	$Days_in_Month = Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	$limit=$Days_in_Month[$MONTH-1];
	if ($DAY==$limit) {$MONTH+=1;$month=decode_lng_text("MONTH$MONTH");$DAY=1;} else {$DAY+=1;}
}

	echo "<table>";
	echo implode($table) ;
	echo "</table>";
	if (count($table)==0) {echo "<BR><BR><BR>Il n'y a pas de résultat";}


	affiche_pied_page(true);

?>


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