<?php

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

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


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

	//set_time_limit(0);
	
	flush();


	$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'];
	}

//création de la table birthday pour y stocker toutes les dates
	mysql_query("DROP TABLE IF EXISTS birthday");
	mysql_query("CREATE TABLE birthday (month INT NOT NULL, day INT NOT NULL)");


	$query = "select libelle from oxg_events where type=$id_type_evnt_date $sReqFam";
	$result = mysql_query($query);
	while($row = mysql_fetch_array($result))
	{
		list($year, $month, $day) = split('[/.-.:. ]', $row['libelle']);

		if ($month!="?") {if ($day!="?") { 
		mysql_query("INSERT INTO birthday VALUES($month,$day)");
		}}

	}


	$month=1;
	$day=1;
	while ($month<13) {
		if ($month==1 | $month==3 | $month==5 | $month==7 | $month==8 | $month==10 | $month==12) { $nb=32;}
		if ($month==4 | $month==6 | $month==9 | $month==11) { $nb=31;}
		if ($month==2) { $nb=30;}
		$day=1;
		while ($day<$nb) {
	mysql_query("INSERT INTO birthday VALUES($month,$day)");
				$day+=1;
				$ligne+=1;
				}
			$month+=1;
			}

//création de la table birthday2 pour y stocker le compte de toutes les dates de l'année
	mysql_query("DROP TABLE IF EXISTS birthday2");
	mysql_query("CREATE TABLE birthday2 (month INT NOT NULL, day INT NOT NULL, total INT)");

	$result = mysql_query("select month, day, count(*) as somme from oxg_birthday GROUP BY month, day");
	while ($row = mysql_fetch_array($result))
	{
	$mois=$row['month'];
	$jour=$row['day'];
	$total=$row['somme']-1;
	mysql_query("INSERT INTO birthday2 VALUES($mois,$jour,$total)");
	}


	echo "done !";

?>
