Location: PHPKode > projects > HuMo-gen > admin/include/gedcom_export.php
<?php

/**
 * This is the gedcom processing file for HuMo-gen.
 *
 * If you are reading this in your web browser, your server is probably
 * not configured correctly to run PHP applications!
 *
 * See the manual for basic setup instructions
 *
 * http://www.huubmons.nl/software/
 *
 * ----------
 *
 * Copyright (C) 2008-2009 Huub Mons,
 * Klaas de Winkel, Jan Maat, Jeroen Beemster, Louis Ywema, Theo Huitema,
 * Ren� Janssen, Yossi Beck
 * and others.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// *** Safety line ***
if (!defined('ADMIN_PAGE')){ exit; }

global $Taalkeuze;
include ('../include/database_name.php');

echo '<H1 align=center>'.$language["export_name"].'</H1>';

function decode($buffer){
	//$buffer = html_entity_decode($buffer, ENT_NOQUOTES, 'ISO-8859-15');
	//$buffer = html_entity_decode($buffer, ENT_QUOTES, 'ISO-8859-15');
	return $buffer;
}

// NOTE regel max. zo'n 80 karakters lang (Aldfaer ongeveer 60 kar., BK ongeveer 230)
// ALDFAER:
// 1 CONC Jan & Mien / Beert & Dina: 2 broers getrouwd met 2 zussen.
// 1 CONT
// 1 CONT Beert ontmoette in WOII een Canadese (of Engelse?) vliegenier en bracht hem naar de ondergrondse.
// 1 CONC bla bla meer over bekend.
// eerste deel NIET verwerken, maar bij aanroepen toevoegen (kan zijn: 2 NOTE of 3 NOTE)
function process_text($level,$text){
	$text = str_replace("<br>", "", $text);
	$regel=explode("\n",$text);
	// *** If text is too long split it ***
	$text=''; $text_processed='';
	for ($j=0; $j<=(count($regel)-1); $j++){
		$text=$regel[$j]."\n";
		if (strlen($regel[$j])>80){
			$words = explode(" ", $regel[$j]);
			$new_line=''; $new_line2=''; $characters=0;
			for ($x=0; $x<=(count($words)-1); $x++){
				if($x>0){ $new_line.=' '; $new_line2.=' '; }
				$new_line.=$words[$x]; $new_line2.=$words[$x];
				$characters=(strlen($new_line2));
				if ($characters>75){
				  $new_line.="\n".$level." CONC"; $new_line2='';
				}
			}
			$text=$new_line."\n";
		}

		// *** First line is x NOTE, only CONT at higher lines ***
		if ($j>0){ $text= $level.' CONT '.$text; }
		$text_processed.=$text;
	}
	return $text_processed;
}

@set_time_limit(3000);

$myFile = "backup_tmp/gedcom.ged";
// *** FOR TESTING PURPOSES ONLY ***
if (file_exists("../../gedcom-bestanden")){
	$myFile="../../gedcom-bestanden/gedcom.ged";
}

// *** Gedcom bestand weer verwijderen ***
if (isset($_POST['remove_gedcom'])){
	unlink($myFile);
	echo '<h2>'.$language["export_removed"].'</h2>';
}

//TIJDELIJK REGEL
echo ' <h3 style="color: red;">The gedcom export is not completely ready yet! De gedcom uitvoer is nog niet helemaal klaar!</h3>';

echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
echo '<input type="hidden" name="page" value="'.$page.'">';
echo '<table class="humo">';

echo '<tr><td>'.$language["export_tree_select"].'</td>';
echo '<td>';
	$tree_sql = "SELECT * FROM humo_trees WHERE tree_prefix!='LEEG' ORDER BY tree_order";
	$tree_result = mysql_query($tree_sql,$db);
	echo '<select size="1" name="tree">';
		while ($treeDb=mysql_fetch_object($tree_result)){
			$treetext_name=database_name($treeDb->tree_prefix, $Taalkeuze);		
			$selected='';
			if (isset($tree)){ if ($treeDb->tree_prefix==$tree){ $selected=' SELECTED'; } }
			echo '<option value="'.$treeDb->tree_prefix.'"'.$selected.'>'.@$treetext_name.'</option>';
		}
	echo '</select>';
echo '</td>';
echo '</tr>';

echo '<tr><td>'.$language["export_texts"].'</td><td>';
$selected=''; if (isset($_POST['gedcom_texts']) AND $_POST['gedcom_texts']=='no'){ $selected=' SELECTED'; }
echo '<select size="1" name="gedcom_texts">';
	echo '<option value="yes">'.$language["admin_yes"].'</option>';
	echo '<option value="no"'.$selected.'>'.$language["admin_no"].'</option>';
echo '</select>';
echo '</td></tr>';

echo '<tr><td>'.$language["export_sources"].'</td><td>';
$selected=''; if (isset($_POST['gedcom_sources']) AND $_POST['gedcom_sources']=='no'){ $selected=' SELECTED'; }
echo '<select size="1" name="gedcom_sources">';
	echo '<option value="yes">'.$language["admin_yes"].'</option>';
	echo '<option value="no"'.$selected.'>'.$language["admin_no"].'</option>';
echo '</select>';
echo '</td></tr>';

//VERTALEN
echo '<tr><td>Character set</td><td>';
echo '<select size="1" name="gedcom_char_set">';
	echo '<option value="ASCII">ASCII</option>';
	$selected=''; if (isset($_POST['gedcom_char_set']) AND $_POST['gedcom_char_set']=='UTF-8'){ $selected=' SELECTED'; }
	echo '<option value="UTF-8"'.$selected.'>UTF-8</option>';
echo '</select>';
echo '</td></tr>';

echo '<tr><td>'.$language["export_gedcom"].'</td><td>';
echo ' <input type="Submit" name="submit" value="'.$language["admin_select"].'">';
echo '</td></tr>';

echo '</table>';
echo '</form>';

if (isset($_POST["tree"])){

	$gedcom_texts='';
	if (isset($_POST['gedcom_texts'])){	$gedcom_texts=$_POST['gedcom_texts']; }

	$gedcom_sources='';
	if (isset($_POST['gedcom_sources'])){	$gedcom_sources=$_POST['gedcom_sources']; }

	$gedcom_char_set='';
	if (isset($_POST['gedcom_char_set'])){	$gedcom_char_set=$_POST['gedcom_char_set']; }

	$tree=veilig($_POST["tree"]);
	echo '<p>'.$language["export_info"].'<br>';
	$fh = fopen($myFile, 'w') or die("can't open file");

// *** Gedcom header ***
$buffer="0 HEAD\n";
$buffer.="1 SOUR HuMo-gen\n";
$buffer.="2 VERS 3.2b\n";
$buffer.="2 NAME HuMo-gen\n";
$buffer.="2 CORP HuMo-gen genealogical software\n";
$buffer.="3 ADDR http://www.huubmons.nl/software\n";
$buffer.="1 SUBM Unknown\n";
$buffer.="1 GEDC\n";
$buffer.="2 VERS 5.5\n";
$buffer.="2 FORM Lineage-Linked\n";
//$buffer.="1 CHAR ANSI\n";

if ($gedcom_char_set=='UTF-8'){
	$buffer.="1 CHAR UTF-8\n";
}
else{
	$buffer.="1 CHAR ASCII\n";
}

fwrite($fh, $buffer);
//$buffer = str_replace("\n", "<br>", $buffer);
//echo '<p>'.$buffer;

/*
0 @I1181@ INDI
1 RIN 1181
1 REFN Eigencode
1 NAME Voornaam/Achternaam/
1 SEX M
1 BIRT
2 DATE 21 FEB 1960
2 PLAC 1e woonplaats
1 RESI
2 ADDR 2e woonplaats
1 RESI
2 ADDR 3e woonplaats
1 RESI
2 ADDR 4e woonplaats
1 OCCU 1e beroep
1 OCCU 2e beroep
1 EVEN
2 TYPE living
1 _COLOR 0
1 NOTE @N51@
1 FAMS @F10@
1 FAMC @F8@
1 _NEW
2 TYPE 2
2 DATE 8 JAN 2005
3 TIME 20:31:24
*/

$persoon_qry= "SELECT * FROM ".$tree."person";
$persoon_result = mysql_query($persoon_qry,$db);
while ($persoon=mysql_fetch_object($persoon_result)){
	// 0 @I1181@ INDI *** Gedcomnumber ***
	$buffer='0 @'.$persoon->pers_gedcomnumber."@ INDI\n";

	// 1 RIN 1181
	$buffer.='1 RIN '.substr($persoon->pers_gedcomnumber,1)."\n";

	// 1 REFN Code *** Own code ***
	if ($persoon->pers_own_code){
		$buffer.='1 REFN '.$persoon->pers_own_code."\n";
	}

	// 1 NAME Firstname/Lastname/ *** Name ***
	$buffer.='1 NAME '.$persoon->pers_firstname.'/';
	$buffer.=str_replace("_", " ", $persoon->pers_prefix);
	$buffer.=$persoon->pers_lastname."/\n";

	// *** Sexe ***
	$buffer.='1 SEX '.$persoon->pers_sexe."\n";

	// *** Birth data ***
	if ($persoon->pers_birth_date OR $persoon->pers_birth_place OR $persoon->pers_birth_text){
		$buffer.="1 BIRT\n";
		if ($persoon->pers_birth_date){
			$buffer.='2 DATE '.$persoon->pers_birth_date."\n";
		}
		if ($persoon->pers_birth_place){
			$buffer.='2 PLAC '.$persoon->pers_birth_place."\n";
		}
		if ($gedcom_sources=='yes' AND $persoon->pers_birth_source){
			 $buffer.='2 SOUR '.process_text(3,$persoon->pers_birth_source); }
		if ($gedcom_texts=='yes' AND $persoon->pers_birth_text){
			$buffer.='2 NOTE '.process_text(3,$persoon->pers_birth_text); }
	}

	// *** Christened data ***
	if ($persoon->pers_bapt_date OR $persoon->pers_bapt_place OR $persoon->pers_bapt_text){
		$buffer.="1 CHR\n";
		if ($persoon->pers_bapt_date){
			$buffer.='2 DATE '.$persoon->pers_bapt_date."\n";
		}
		if ($persoon->pers_bapt_place){
			$buffer.='2 PLAC '.$persoon->pers_bapt_place."\n";
		}
		if ($gedcom_sources=='yes' AND $persoon->pers_bapt_source){
			 $buffer.='2 SOUR '.process_text(3,$persoon->pers_bapt_source); }
		if ($gedcom_texts=='yes' AND $persoon->pers_bapt_text){
			$buffer.='2 NOTE '.process_text(3,$persoon->pers_bapt_text); }
	}

	// *** Death data ***
	if ($persoon->pers_death_date OR $persoon->pers_death_place OR $persoon->pers_death_text){
		$buffer.="1 DEAT\n";
		if ($persoon->pers_death_date){
			$buffer.='2 DATE '.$persoon->pers_death_date."\n";
		}
		if ($persoon->pers_death_place){
			$buffer.='2 PLAC '.$persoon->pers_death_place."\n";
		}
		if ($gedcom_sources=='yes' AND $persoon->pers_death_source){
			$buffer.='2 SOUR '.process_text(3,$persoon->pers_death_source); }
		if ($gedcom_texts=='yes' AND $persoon->pers_death_text){
			$buffer.='2 NOTE '.process_text(3,$persoon->pers_death_text); }
	}

	// *** Buried data ***
	if ($persoon->pers_buried_date OR $persoon->pers_buried_place OR $persoon->pers_buried_text){
		$buffer.="1 BURI\n";
		if ($persoon->pers_buried_date){
			$buffer.='2 DATE '.$persoon->pers_buried_date."\n";
		}
		if ($persoon->pers_buried_place){
			$buffer.='2 PLAC '.$persoon->pers_buried_place."\n";
		}
		if ($gedcom_sources=='yes' AND $persoon->pers_buried_source){
			$buffer.='2 SOUR '.process_text(3,$persoon->pers_buried_source); }
		if ($gedcom_texts=='yes' AND $persoon->pers_buried_text){
			$buffer.='2 NOTE '.process_text(3,$persoon->pers_buried_text); }
	}

	// *** Living place ***
	// 1 RESI
	// 2 ADDR Ridderkerk
	// 1 RESI
	// 2 ADDR Slikkerveer
	$adresqry=mysql_query("SELECT * FROM ".$tree."addresses
		WHERE address_person_id='$persoon->pers_gedcomnumber'",$db);
	while($adresDb=mysql_fetch_object($adresqry)){
		$buffer.="1 RESI\n";
		$buffer.='2 ADDR'."\n";
		$buffer.='3 CITY '.$adresDb->address_place."\n";		
	}

	// *** Occupation ***
	$beroepqry=mysql_query("SELECT * FROM ".$tree."events
		WHERE event_person_id='$persoon->pers_gedcomnumber' AND event_kind='beroep'",$db);
	while($beroepDb=mysql_fetch_object($beroepqry)){
		$buffer.='1 OCCU '.$beroepDb->event_event."\n";
	}

	// *** Person source ***
	if ($gedcom_sources=='yes'){ 
		$bronqry=mysql_query("SELECT * FROM ".$tree."events
			WHERE event_person_id='$persoon->pers_gedcomnumber' AND event_kind='bron'",$db);
		while($bronDb=mysql_fetch_object($bronqry)){
			if ($bronDb->event_source){
				$buffer.='1 SOUR '.$bronDb->event_source."\n";
			}
		}
	}

	// *** Person pictures ***
	$bronqry=mysql_query("SELECT * FROM ".$tree."events
		WHERE event_person_id='$persoon->pers_gedcomnumber' AND event_kind='afbeelding'",$db);
	while($bronDb=mysql_fetch_object($bronqry)){
		if ($bronDb->event_event){
			$buffer.="1 OBJE\n";
			$buffer.="2 FORM jpg\n";
			$buffer.='2 FILE '.$bronDb->event_event."\n";
			$buffer.='2 DATE '.$bronDb->event_date."\n";

			if ($gedcom_texts=='yes' AND $bronDb->event_text){
				$buffer.='2 NOTE '.process_text(3,$bronDb->event_text); }

			if ($gedcom_sources=='yes' AND $bronDb->event_source){
				$buffer.='2 SOUR '.process_text(3,$bronDb->event_source); }
		}
	}

	// *** Person Note ***
	if ($gedcom_texts=='yes' AND $persoon->pers_text){
		$buffer.='1 NOTE '.process_text(2,$persoon->pers_text);
	}

	// *** FAMS ***
	if ($persoon->pers_fams){
		$family=explode(";",$persoon->pers_fams);
		for ($i=0; $i<=substr_count($persoon->pers_fams, ";"); $i++){
			$buffer.='1 FAMS @'.$family[$i]."@\n";
		}
	}

	// *** FAMC ***
	if ($persoon->pers_famc){
		$buffer.='1 FAMC @'.$persoon->pers_famc."@\n";
	}

	// *** Privacy filter ***
	if ($persoon->pers_alive == 'HZ_levend'){
		$buffer.="1 EVEN\n";
		$buffer.="2 TYPE living\n";
	}

	// *** Date and time new in database ***
	// 1_NEW
	// 2 DATE 04 AUG 2004
	// 3 TIME 13:39:58
	if ($persoon->pers_new_date){
		$buffer.="1 _NEW\n";
		$buffer.="2 DATE ".$persoon->pers_new_date."\n";
		if ($persoon->pers_new_time){
			$buffer.="3 TIME ".$persoon->pers_new_time."\n";
		}
	}

	// *** Date and time changed in database ***
	// 1_CHAN
	// 2 DATE 04 AUG 2004
	// 3 TIME 13:39:58
	if ($persoon->pers_changed_date){
		$buffer.="1 CHAN\n";
		$buffer.="2 DATE ".$persoon->pers_changed_date."\n";
		if ($persoon->pers_changed_time){
			$buffer.="3 TIME ".$persoon->pers_changed_time."\n";
		}
	}

	// *** Write person data ***
	$buffer=decode($buffer);
	fwrite($fh, $buffer);
	// *** Show person data on screen ***
	//$buffer = str_replace("\n", "<br>", $buffer);
	//echo $buffer;
}

/*
0 @F1@ FAM
1 HUSB @I2@
1 WIFE @I3@
1 MARL
2 DATE 25 AUG 1683
2 PLAC Arnhem
1 MARR
2 TYPE civil
2 DATE 30 NOV 1683
2 PLAC Arnhem
2 NOTE @N311@
1 CHIL @I4@
1 CHIL @I5@
1 CHIL @I6@
*/

// *** FAMILY DATA ***
$gezin_qry=mysql_query("SELECT * FROM ".$tree."family",$db);
while($gezin=mysql_fetch_object($gezin_qry)){
	// 0 @I1181@ INDI *** Gedcomnumber ***
	$buffer='0 @'.$gezin->fam_gedcomnumber."@ FAM\n";

	if ($gezin->fam_man){
		$buffer.='1 HUSB @'.$gezin->fam_man."@\n";
	}

	if ($gezin->fam_woman){
		$buffer.='1 WIFE @'.$gezin->fam_woman."@\n";
	}

	// *** Ondertrouw data ***
	if ($gezin->fam_marr_notice_date OR $gezin->fam_marr_notice_place OR $gezin->fam_marr_notice_text){
		$buffer.="1 MARB\n";
		$buffer.="2 TYPE civil\n";
		if ($gezin->fam_marr_notice_date){
			$buffer.='2 DATE '.$gezin->fam_marr_notice_date."\n";
		}
		if ($gezin->fam_marr_notice_place){
			$buffer.='2 PLAC '.$gezin->fam_marr_notice_place."\n";
		}
		if ($gedcom_sources=='yes' AND $gezin->fam_marr_notice_source){
			$buffer.='2 SOUR '.process_text(3,$gezin->fam_marr_notice_source); }
		if ($gedcom_texts=='yes' AND $gezin->fam_marr_notice_text){
			$buffer.='2 NOTE '.process_text(3,$gezin->fam_marr_notice_text); }
	}

	// *** Ondertrouw kerk data ***
	if ($gezin->fam_marr_church_notice_date OR $gezin->fam_marr_church_notice_place OR $gezin->fam_marr_church_notice_text){
		$buffer.="1 MARB\n";
		$buffer.="2 TYPE religous\n";
		if ($gezin->fam_marr_church_notice_date){
			$buffer.='2 DATE '.$gezin->fam_marr_church_notice_date."\n";
		}
		if ($gezin->fam_marr_church_notice_place){
			$buffer.='2 PLAC '.$gezin->fam_marr_church_notice_place."\n";
		}
		if ($gedcom_sources=='yes' AND $gezin->fam_marr_church_notice_source){
			$buffer.='2 SOUR '.process_text(3,$gezin->fam_marr_church_notice_source); }
		if ($gedcom_texts=='yes' AND $gezin->fam_marr_church_notice_text){
			$buffer.='2 NOTE '.process_text(3,$gezin->fam_marr_church_notice_text); }
	}

	// *** Trouw data ***
	if ($gezin->fam_marr_date OR $gezin->fam_marr_place OR $gezin->fam_marr_text){
		$buffer.="1 MARR\n";
		$buffer.="2 TYPE civil\n";
		if ($gezin->fam_marr_date){
			$buffer.='2 DATE '.$gezin->fam_marr_date."\n";
		}
		if ($gezin->fam_marr_place){
			$buffer.='2 PLAC '.$gezin->fam_marr_place."\n";
		}
		if ($gedcom_sources=='yes' AND $gezin->fam_marr_source){
			$buffer.='2 SOUR '.process_text(3,$gezin->fam_marr_source); }
		if ($gedcom_texts=='yes' AND $gezin->fam_marr_text){
			$buffer.='2 NOTE '.process_text(3,$gezin->fam_marr_text); }
	}

	// *** Trouw kerk data ***
	if ($gezin->fam_marr_church_date OR $gezin->fam_marr_church_place OR $gezin->fam_marr_church_text){
		$buffer.="1 MARR\n";
		$buffer.="2 TYPE religous\n";
		if ($gezin->fam_marr_church_date){
			$buffer.='2 DATE '.$gezin->fam_marr_church_date."\n";
		}
		if ($gezin->fam_marr_church_place){
			$buffer.='2 PLAC '.$gezin->fam_marr_church_place."\n";
		}
		if ($gedcom_sources=='yes' AND $gezin->fam_marr_church_source){
			$buffer.='2 SOUR '.process_text(3,$gezin->fam_marr_church_source); }
		if ($gedcom_texts=='yes' AND $gezin->fam_marr_church_text){
			$buffer.='2 NOTE '.process_text(3,$gezin->fam_marr_church_text); }
	}

	// *** Divorsed data ***
	if ($gezin->fam_div_date OR $gezin->fam_div_place OR $gezin->fam_div_text){
		$buffer.="1 DIV\n";
		if ($gezin->fam_div_date){
			$buffer.='2 DATE '.$gezin->fam_div_date."\n";
		}
		if ($gezin->fam_div_place){
			$buffer.='2 PLAC '.$gezin->fam_div_place."\n";
		}
		if ($gedcom_sources=='yes' AND $gezin->fam_div_source){
			$buffer.='2 SOUR '.process_text(3,$gezin->fam_div_source); }
		if ($gedcom_texts=='yes' AND $gezin->fam_div_text){
			$buffer.='2 NOTE '.process_text(3,$gezin->fam_div_text); }
	}

	if ($gezin->fam_children){
		$child=explode(";",$gezin->fam_children);
		for ($i=0; $i<=substr_count($gezin->fam_children, ";"); $i++){
			$buffer.='1 CHIL @'.$child[$i]."@\n";
		}
	}

// Bron bij gezin is niet in gebruik?
	// *** Family source ***
	//if ($gedcom_sources=='yes'){ 
	//	$bronqry=mysql_query("SELECT * FROM ".$tree."events
	//		WHERE event_family_id='$gezin->fam_gedcomnumber' AND event_kind='bron'",$db);
	//		while($bronDb=mysql_fetch_object($bronqry)){
	//		if ($bronDb->event_source){
	//			$buffer.='1 SOUR '.$bronDb->event_source."\n";
	//		}
	//	}
	//}

	// *** Family Note ***
	if ($gedcom_texts=='yes' AND $gezin->fam_text){
		$buffer.='1 NOTE '.process_text(2,$gezin->fam_text);
	}

	// *** Date and time new in database ***
	// 1_NEW
	// 2 DATE 04 AUG 2004
	// 3 TIME 13:39:58
	if ($gezin->fam_new_date){
		$buffer.="1 _NEW\n";
		$buffer.="2 DATE ".$gezin->fam_new_date."\n";
		if ($gezin->fam_new_time){
			$buffer.="3 TIME ".$gezin->fam_new_time."\n";
		}
	}

	// *** Date and time changed in database ***
	// 1_CHAN
	// 2 DATE 04 AUG 2004
	// 3 TIME 13:39:58
	if ($gezin->fam_changed_date){
		$buffer.="1 CHAN\n";
		$buffer.="2 DATE ".$gezin->fam_changed_date."\n";
		if ($gezin->fam_changed_time){
			$buffer.="3 TIME ".$gezin->fam_changed_time."\n";
		}
	}

	// *** Write family data ***
	$buffer=decode($buffer);
	fwrite($fh, $buffer);
	// *** Show family data on screen ***
	//$buffer = str_replace("\n", "<br>", $buffer);
	//echo $buffer;
}


// *** Sources ***
//0 @S1@ SOUR
//1 TITL Persoonskaarten
//1 DATE 24 JAN 2003
//1 PLAC Heerhugowaard
//1 REFN Pers-v
//1 PHOTO @#APLAATJES\AKTEMONS.GIF GIF@
//2 DSCR Afbeelding van Persoonskaarten
//1 PHOTO @#APLAATJES\HUUB&LIN.JPG JPG@
//2 DSCR Beschrijving
//1 NOTE Persoonskaarten (van overleden personen) besteld bij CBVG te Den Haag.
if ($gedcom_sources=='yes'){
	$gezin_qry=mysql_query("SELECT * FROM ".$tree."sources",$db);
	while($gezin=mysql_fetch_object($gezin_qry)){
		// 0 @I1181@ INDI *** Gedcomnumber ***
		$buffer='0 @'.$gezin->source_gedcomnr."@ SOUR\n";

		if ($gezin->source_title){ $buffer.='1 TITLE '.$gezin->source_title."\n"; }
		if ($gezin->source_abbr){ $buffer.='1 ABBR '.$gezin->source_abbr."\n"; }
		if ($gezin->source_date){ $buffer.='1 DATE '.$gezin->source_date."\n"; }
		if ($gezin->source_place){ $buffer.='1 PLAC '.$gezin->source_place."\n"; }
		if ($gezin->source_publ){ $buffer.='1 PUBL '.$gezin->source_publ."\n"; }
		if ($gezin->source_refn){ $buffer.='1 REFN '.$gezin->source_refn."\n"; }
		if ($gezin->source_auth){ $buffer.='1 AUTH '.$gezin->source_auth."\n"; }
		if ($gezin->source_subj){ $buffer.='1 SUBJ '.$gezin->source_subj."\n"; }
		if ($gezin->source_item){ $buffer.='1 ITEM '.$gezin->source_item."\n"; }
		if ($gezin->source_kind){ $buffer.='1 KIND '.$gezin->source_kind."\n"; }
		if ($gezin->source_text){ $buffer.='1 NOTE '.process_text(2,$gezin->source_text); }

		// photo = old gedcom tag?
		if ($gezin->source_photo){ $buffer.='1 PHOT '.$gezin->source_photo."\n"; }

		// source_repo_name, source_repo_caln, source_repo_page.

		// *** Write source data ***
		$buffer=decode($buffer);
		fwrite($fh, $buffer);
		// *** Show source data on screen ***
		//$buffer = str_replace("\n", "<br>", $buffer);
		//echo $buffer;
	}
}

// *** Addresses ***
// 0 @R155@ RESI
// 1 ADDR Straat
// 1 PLAC Plaats
$gezin_qry=mysql_query("SELECT * FROM ".$tree."addresses
	WHERE address_gedcomnr LIKE '_%'",$db);
while($gezin=mysql_fetch_object($gezin_qry)){
	// 0 @I1181@ INDI *** Gedcomnumber ***
	$buffer='0 @'.$gezin->address_gedcomnr."@ RESI\n";

	if ($gezin->address_address){ $buffer.='1 ADDR '.$gezin->address_address."\n"; }
	if ($gezin->address_zip){ $buffer.='1 ZIP '.$gezin->address_zip."\n"; }
	if ($gezin->address_date){ $buffer.='1 DATE '.$gezin->address_date."\n"; }
	if ($gezin->address_place){ $buffer.='1 PLAC '.$gezin->address_place."\n"; }
	if ($gezin->address_phone){ $buffer.='1 PHON '.$gezin->address_phone."\n"; }
	if ($gedcom_sources=='yes' AND $gezin->address_source){
		$buffer.='1 SOUR '.$gezin->address_source."\n"; }
	if ($gezin->address_text){ $buffer.='1 NOTE '.process_text(2,$gezin->address_text); }

// photo

	// *** Write source data ***
	$buffer=decode($buffer);
	fwrite($fh, $buffer);
	// *** Show source data on screen ***
	//$buffer = str_replace("\n", "<br>", $buffer);
	//echo $buffer;
}

fwrite($fh, '0 TRLR');

fclose($fh);

echo '<p>'.$language["export_generated"].'<br>';

//echo '<p><a href="'.$myFile.'" target="_blank">Download gedcom file</a>';

echo '<form method="POST" action="'.$myFile.'" target="_blank">';
echo ' <input type="Submit" name="submit" value="'.$language["export_download"].'">';
echo '<input type="hidden" name="page" value="'.$page.'">';
echo '</form><br>';

echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
echo ' <input type="Submit" name="remove_gedcom" value="'.$language["export_remove"].'">';
echo '<input type="hidden" name="page" value="'.$page.'">';
echo '</form>';

} // einde tree
?>
Return current item: HuMo-gen