<?php

function nb_Children ($parent, $fam, $gen, $affichage, $color1, $color2)
{
	global	$bSosa, $bSessionOk;

	if($fam!=-1)
	{
		$sReqFam="and id_family=$fam";
	}
	else
	{
		$sReqFam="";
	}
	if($bSessionOk==false)
	{
		$sReqCont=" and contemporary=1 ";
	}
	else
	{
		$sReqCont="";
	}
	
	echo "<span>";
	$nb_enfants=0;
	$old_conjoint="";
	$sql_query = "select oxg_individuals.id_individual as id_ind, oxg_individuals.first_name, sex, oxg_patronyms.libelle, id_father, id_mother from oxg_individuals, oxg_patronyms where (id_father=$parent or id_mother=$parent) and oxg_patronyms.id_patronym=oxg_individuals.id_patronym $sReqCont $sReqFam order by id_father, id_mother";
		$sql_query.= ", right(date_naissance,4)";
	$result_ind = mysql_query( $sql_query ) or mysql_die();
	while($row_ind = mysql_fetch_array($result_ind))
	{
		if($parent!=$row_ind['id_father'])
		{
			$id_conjoint=$row_ind['id_father'];
		}
		if($parent!=$row_ind['id_mother'])
		{
			$id_conjoint=$row_ind['id_mother'];
		}
		if($old_conjoint!=$id_conjoint)
		{
			if($nb_enfants!=0)
			{
				echo "</dl>";
			}
			echo "<dt><b>".decode_lng_text('DETAIL_IND_CHILD')." ".decode_lng_text('DETAIL_IND_WITH')." ";
			$result_cont = mysql_query( "select * from oxg_individuals where id_individual=$id_conjoint $sReqCont $sReqFam");
			if ($row_cont = mysql_fetch_array($result_cont))
				{
				//echo affiche_lien_individu($fam,$id_conjoint,true,true);
				echo affiche_lien_arbre2($fam, $id_conjoint, $gen, $affichage, $color1, $color2);
				echo " ";
				echo affiche_lien_individu($fam, $id_conjoint, true, true);
				}
			else
				{
				return decode_lng_text('PRIVATE_MSG');
				}
			echo "</b></dt>";
			$old_conjoint=$id_conjoint;
		}
		if ($row_ind['sex']==1) { $flag="female.png"; }
		if ($row_ind['sex']==0) { $flag="male.png"; }
		echo "<dd>".affiche_lien_arbre2($fam, $row_ind['id_ind'], $gen, $affichage, $color1, $color2);
		echo " ";
		echo "<IMG SRC=$flag> ".affiche_lien_individu($fam, $row_ind['id_ind'], true, true)." </dd>";
		$nb_enfants++;
	}
	if($nb_enfants!=0)
	{
		echo "</dl></dl>";
	}
echo "</span>";
}


function affiche_lien_individu2($id_affichage, $id_family, $id_individual, $ttprenom)
{
	global	$bSosa, $bSessionOk;

	if($id_family!=-1)
	{
		$sReqFam="and id_family=$id_family";
	}
	else
	{
		$sReqFam="";
	}
	if($bSessionOk==false)
	{
		$sReqCont="and contemporary=1";
	}
	else
	{
		$sReqCont="";
	}
	
	$sInd="";
	
	$sReq  = "select first_name, libelle ";
	if($bSosa==true)
	{
		$sReq  .= ", sosa ";
	}
	$sReq .= ", date_naissance, date_deces, id_ville_naissance, id_zone_naissance, id_pays_naissance, id_ville_deces, id_zone_deces, id_pays_deces, lieu_naissance, lieu_deces, contemporary";
	$sReq .= " from oxg_individuals, oxg_patronyms ";
	$sReq .= "where id_individual='$id_individual' ";
	$sReq .= "and oxg_individuals.id_patronym=oxg_patronyms.id_patronym ";
	$sReq .= $sReqFam;

	$result = mysql_query( $sReq ) or mysql_die();
	if ($row = mysql_fetch_array($result));
	{
		if ($id_individual=="-1")
		{
		$sInd.="";
		}
		else
		{
		$sInd.="<A HREF='§detail_individu.php?INDIVIDU=$id_individual&FAMILY=$id_family'>";
		}
		if($row['first_name']=="")
		{
			$sInd.="?";
		}
		else
		{
				$firstname = $row['first_name'];
			if ($ttprenom==2) {
				$firstname = explode(" ",$firstname);
				$firstname = $firstname[0];}
				$sInd.=$firstname;
		}
			$sInd.=" $row[libelle]";
		$sInd.="</A>";
		if($bSosa==true && $row['sosa']!='-1')
		{
			$sInd=$sInd." <strong><font color=red>$row[sosa]</font></strong>";
		}
		
			if ($id_affichage==2)
			{
				$sInd.="<BR>";
				if($row['date_naissance']!="")
				{
					$newdate = decode_date2($row[date_naissance]);
					$sInd.="( ".$newdate;
				}
				else
				{
					$sInd.="( ?";
				}
				if($row['date_deces']!="")
				{
					$sInd.=" - ";
					$newdate = decode_date2($row[date_deces]);
					$sInd.=$newdate;
				}
				else
				{
				if (substr($row[date_naissance],-4)<1910) {$sInd.=" - ?";}
				}
				$sInd.=" )";
			}
			if ($id_affichage==3)
			{
				$sInd.="<BR>";
				
				$newdate ="";
				$ville ="";
				if($row['date_naissance']!="")
				{
				$newdate = decode_date2($row[date_naissance]);
					//if ($row[id_ville_naissance]=="0")
					//{
					//$ville = $row[lieu_naissance];
					//$ville = explode(",",$ville);
					//$ville = $ville[0];
					//}
					//else
					//{
					$result_ville = mysql_query( "select libelle from oxg_cities where id_city='$row[id_ville_naissance]' and id_zone='$row[id_zone_naissance]' and id_country='$row[id_pays_naissance]'" );
					$row_ville = mysql_fetch_array($result_ville);
					$ville = $row_ville[libelle];
					//}
				}
				else
				{
				$newdate="?";
				}
				if ($ville=="") { $ville = "?";	}
				if ($newdate=="?" and $ville=="?")
					{
					$sInd.="° ?<BR>";
					}
				else
					{
					$sInd.="° ".$newdate." - ".$ville."<BR>";
					}
				$newdate ="";
				$ville ="";
				if($row['date_deces']!="")
				{
				$newdate = decode_date2($row[date_deces]);
					//if ($row[id_ville_deces]=="0")
					//{
					//$ville = $row[lieu_deces];
					//$ville = explode(",",$ville);
					//$ville = $ville[0];
					//}
					//else
					//{
					$result_ville = mysql_query( "select libelle from oxg_cities where id_city='$row[id_ville_deces]' and id_zone='$row[id_zone_deces]' and id_country='$row[id_pays_deces]'" );
					$row_ville = mysql_fetch_array($result_ville);
					$ville = $row_ville[libelle];
					//}
				}
			else
				{
				$newdate="?";
				}
			if ($ville=="") { $ville = "?";	}
			if ($newdate=="?" and $ville=="?")
				{
				$sInd.="+ ?<BR>";
				}
			else
				{
				$sInd.="+ ".$newdate." - ".$ville."<BR>";
				}
			}
	}
	if ($row['first_name']=="" AND $row[libelle]=="")
	{
		return "?";
	}
	else
	{	
		if ($bSessionOk==false and $row['contemporary']==0)
		{return decode_lng_text('PRIVATE_MSG');}
		else
		{return $sInd;}
	}
}


function affiche_lien_arbre2($id_family, $id_individual, $gen, $affichage, $color1, $color2)
{
	global	$bSosa, $bSessionOk;

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

	$sReq  = "select id_father, id_mother from oxg_individuals where id_individual=$id_individual $sReqCont $sReqFam";
	$result = mysql_query( $sReq ) or mysql_die();
	$sLink="";
	if($row = mysql_fetch_array($result))
	{
		if($row['id_father']!=-1 || $row['id_mother']!=-1)
		{
			$sLink ="<A HREF='§arbre_individu.php?INDIVIDU=$id_individual&FAMILY=$id_family&gen=$gen&affichage=$affichage&color1=$color1&color2=$color2'><IMG SRC='tree2.png' ALT=\"";
			$sLink.=decode_lng_text("DETAIL_IND_ARBRE");
			$sLink.="\"></A>";
		}
	}
	return $sLink;
}


function decode_date2($sDate)
{
list($day, $month, $year, $year2) = split(' ', $sDate);
if ($year=="" & $month!="" & $day!="avant" & $day!="après") {$year=$month;$month=$day;$day="";}
if($month=="janvier") {$month="01";}
if($month=="février") {$month="02";}
if($month=="mars") {$month="03";}
if($month=="avril") {$month="04";}
if($month=="mai") {$month="05";}
if($month=="juin") {$month="06";}
if($month=="juillet") {$month="07";}
if($month=="août") {$month="08";}
if($month=="septembre") {$month="09";}
if($month=="octobre") {$month="10";}
if($month=="novembre") {$month="11";}
if($month=="décembre") {$month="12";}

if ($day=="") {return "?/$month/$year";} else
if ($day=="autour") {return "$day $month $year";} else
if ($day=="entre") {return "$day $month et $year2";} else
if ($day=="avant") {if ($year=="") {return "$day $month";} else {return "$day $month/$year";} } else
if ($day=="après") {if ($year=="") {return "$day $month";} else {return "$day $month/$year";} } else
if ($month=="") {return "$day";} else 	{if (intval($day)<10) {$day="0".$day;}
return "$day/$month/$year";}
}


class color_picker{
	var $name;
	var $first_option;
	var $kolor_arr = array(
		", no color",
		"c0c0c0, ",
		"4c4c4c, ",
		"ccccff, ",
		"9966cc, ",
		"ccffff, ",
		"00cccc, ",
		"008000, ",
		"0099ff, ",
		"0066cc, ",
		"0000ff, ",
		"ffff66, ",
		"ffcc99, ",
		"eb613d, ",
		"ff3366, ",
		"ff0000, ",
		"4c1900, ",
		"000000, ",
		"FFFFFF, ",
		);
}


function color_picker($name = "my_color", $firts_option = "select color...")
	{
	$this->name = $name;
	$this->first_option = $firts_option;
	}


function color_select($color)
	{
	echo "<select name=\"".$this->name."\">\n";
	//echo "<option value=\"".$name."\" style=\"background-color:".$this->first_option."\">".$this->first_option."</option>\n";
	echo "<option value=\"".$this->first_option."\" style=\"background-color:".$this->first_option."\"></option>\n";
	for($i=0;$i<count($this->kolor_arr);$i++){
		$wiersz = explode(",",$this->kolor_arr[$i]);
		$value = $wiersz[0];
		$color = $wiersz[1];
		echo "<option value=\"".$value."\" style=\"background-color:".$value."\">".$color."</option>\n";
		}
	echo "</SELECT>\n\n";
	}

?>
