Location: PHPKode > projects > HuMo-gen > admin/include/editor.php
<?php
/**
 * This is the editor 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; }

include ("editor_cls.php");
$editor_cls = New editor_cls;

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

// *** Date functions ***
// 13 OCT 1813 = 13 okt 1813
// BEF 2000 = bef 2000
// ABT 2000 = abt 2000
// AFT 2000 = aft 2000
// BET 1986 AND 1987 = bet 1986 and 1987
function date_show($datum){
	//$tekst = str_replace("BEF", "voor", $tekst);
	return strtolower($datum);
}

function date_process($datum){
	return strtoupper($datum);
}

function text_process($tekst,$long_text=false){
	//$tekst=htmlentities($tekst,ENT_QUOTES,'UTF-8'); 
	if ($long_text==true){
		//$tekst = str_replace("\r\n", "<br>\n", $tekst);
		$tekst = str_replace("\r\n", "\n", $tekst);
	}
	$tekst=veilig($tekst);
	return $tekst;
}

// *** AANTAL personen en gezinnen berekenen ***
function family_tree_update($tree_prefix){
	global $db;
	$persoon=mysql_query("SELECT * FROM ".$tree_prefix."person",$db);
	$personen=mysql_num_rows($persoon);

	$gezin=mysql_query("SELECT * FROM ".$tree_prefix."family",$db);
	$gezinnen=mysql_num_rows($gezin);

	if(function_exists('date_default_timezone_set')){
		date_default_timezone_set('Europe/Amsterdam');
	}
	$datum=date("Y-m-d H:i");

	$sql="UPDATE humo_trees SET
	tree_persons='".$personen."',
	tree_families='".$gezinnen."',
	tree_date='".$datum."'
	WHERE tree_prefix='".$tree_prefix."'";
	mysql_query($sql,$db) or die(mysql_error());
}

// *** Show event options ***
function event_option($event_gedcom,$event){
	global $language;
	$selected=''; if ($event_gedcom==$event){ $selected=' SELECTED'; }
	echo '<option value="'.$event.'"'.$selected.'>'.$language[$event].'</option>';
}

// *** Show texts without <br> and process Aldfaer and other @xx@ texts ***
function text_show($find_text){
	global $db;
	$tekst=$find_text;
	if (substr($find_text, 0, 1)=='@'){
		$zoektekst=mysql_query("SELECT * FROM ".veilig($_SESSION['tree_prefix'])."texts
			WHERE text_gedcomnr='".$find_text."'",$db);
		$zoektekstDb=mysql_fetch_object($zoektekst);
		$tekst=$zoektekstDb->text_text;

		$tekst = str_replace("<br>", "<br>\n", $tekst);
	}
	
	$tekst = str_replace("<br>", "", $tekst);
	return $tekst;
}

function source_edit($source,$source_name){
	global $db, $tree_prefix, $language;

	// *** Source: pull-down menu ***
	$bronqry=mysql_query("SELECT * FROM ".$tree_prefix."sources ORDER BY source_title",$db);
	echo '<select size="1" name="'.$source_name.'2" style="width: 250px">';
	echo '<option value=""></option>';
	while ($bronDb=mysql_fetch_object($bronqry)){
		$selected='';
		if ($bronDb->source_gedcomnr==substr($source,1,-1)){ $selected=' SELECTED'; }
		echo '<option value="@'.$bronDb->source_gedcomnr.'@"'.$selected.'>'.
			 @$bronDb->source_title.' ['.@$bronDb->source_gedcomnr.']</option>';
	}
	echo '</select>';

	// *** Source: text field ***
	$source_value=$source;
	if (substr($source,0,1)=='@'){ $source_value=''; }
	echo ' <b>'.$language["admin_or"].':</b> <input type="text" name="'.$source_name.'" value="'.$source_value.'" size="40">';
}

function witness_edit($witness){
	global $db, $tree_prefix, $language;

	// *** Witness: pull-down menu ***
	$witnessqry=mysql_query("SELECT * FROM ".$tree_prefix."person ORDER BY pers_lastname, pers_firstname",$db);
	echo '<select size="1" name="tekst_vermelding2" style="width: 250px">';
	echo '<option value=""></option>';
	while ($witnessDb=mysql_fetch_object($witnessqry)){
		$selected='';
		if ($witnessDb->pers_gedcomnumber==substr($witness,1,-1)){ $selected=' SELECTED'; }
		echo '<option value="@'.$witnessDb->pers_gedcomnumber.'@"'.$selected.'>'.
			$witnessDb->pers_lastname.', '.$witnessDb->pers_firstname.' '.strtolower(str_replace("_"," ",$witnessDb->pers_prefix)).' ['.$witnessDb->pers_gedcomnumber.']</option>';
	}
	echo '</select>';

	// *** Witness: text field ***
	$witness_value=$witness;
	if (substr($witness,0,1)=='@'){ $witness_value=''; }
	echo ' <b>'.$language["admin_or"].':</b> <input type="text" name="tekst_vermelding" value="'.$witness_value.'" size="40">';
}

function show_person($gedcomnumber, $datum=false){
	global $db, $tree_prefix, $page;
	if ($gedcomnumber){
		$person=mysql_query("SELECT * FROM ".$tree_prefix."person
			WHERE pers_gedcomnumber='$gedcomnumber'",$db);
		$personDb=mysql_fetch_object($person);
		$tekst='<a href="index.php?page='.$page.'&amp;tree='.$tree_prefix.'&amp;person='.$personDb->pers_gedcomnumber.'">'.$personDb->pers_firstname.' '.
			strtolower(str_replace("_"," ",$personDb->pers_prefix)).$personDb->pers_lastname.'</a>';
	}
	else { $tekst='N.N.'; }

	if($datum==true){
		if ($personDb->pers_birth_date){ $tekst.=', * '.date_show($personDb->pers_birth_date); }
	}
	return $tekst;
}

/*
// *** Show message if family tree is selected ***
if (isset($_POST['tree_prefix'])){
	echo '<b>'.$language["editor_intro"].'</b>';
	echo '<br><br>';
}
*/

// *** Use sessions for some parameters ***
$menu_admin='person';
if (isset($_GET["menu_admin"])){
	$menu_admin=$_GET['menu_admin'];
	$_SESSION['admin_menu_admin']=$menu_admin;
}
if (isset($_SESSION['admin_menu_admin'])){ $menu_admin=$_SESSION['admin_menu_admin']; }

if (isset($_POST["tree_prefix"])){
	// *** Show message if family tree is selected ***
	//echo '<b>'.$language["editor_intro"].'</b>';

	$tree_prefix=$_POST['tree_prefix'];
	$_SESSION['admin_tree_prefix']=$tree_prefix;
	unset ($person);
	unset ($_SESSION['admin_person']);

	// *** Select first person to show ***
	$new_nr_qry= "SELECT * FROM ".$tree_prefix."person WHERE pers_favorite LIKE '%_' ORDER BY pers_lastname, pers_firstname LIMIT 0,1";
	$new_nr_result = mysql_query($new_nr_qry,$db);
	@$new_nr=mysql_fetch_object($new_nr_result);
	if (isset($new_nr->pers_gedcomnumber)){
		$person=$new_nr->pers_gedcomnumber;
		$_SESSION['admin_person']=$person;
	}
	else{
		$new_nr_qry= "SELECT * FROM ".$tree_prefix."person LIMIT 0,1";
		$new_nr_result = mysql_query($new_nr_qry,$db);
		@$new_nr=mysql_fetch_object($new_nr_result);
		if (isset($new_nr->pers_gedcomnumber)){
			$person=$new_nr->pers_gedcomnumber;
			$_SESSION['admin_person']=$person;
		}
	}

}
if (isset($_SESSION['admin_tree_prefix'])){ $tree_prefix=$_SESSION['admin_tree_prefix']; }

if (isset($_POST["person"])){
	$person=$_POST['person'];
	$_SESSION['admin_person']=$person;
}
if (isset($_GET["person"])){
	$person=$_GET['person'];
	$_SESSION['admin_person']=$person;
}
if (isset($_SESSION['admin_person'])){ $person=$_SESSION['admin_person']; }

// EVENTUEEL HIER OOK FAMILY_ID OPSLAAN


// *** Check for new person ***
$add_person=false; if (isset($_GET['add_person'])){ $add_person=true; }

// *** Select family tree ***
$tree_prefix_sql = "SELECT * FROM humo_trees WHERE tree_prefix!='LEEG' ORDER BY tree_order";
$tree_prefix_result = mysql_query($tree_prefix_sql,$db);
echo $language["editor_tree"].': ';
echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
echo '<input type="hidden" name="page" value="'.$page.'">';
echo '<select size="1" name="tree_prefix">';
	while ($tree_prefixDb=mysql_fetch_object($tree_prefix_result)){
		$selected='';
		if (isset($tree_prefix)){
			if ($tree_prefixDb->tree_prefix==$tree_prefix){ $selected=' SELECTED'; }
		}
		$treetext_name=database_name($tree_prefixDb->tree_prefix, $Taalkeuze);		
		echo '<option value="'.$tree_prefixDb->tree_prefix.'"'.$selected.'>'.
			@$treetext_name.'</option>';
	}
echo '</select>';
echo ' <input type="Submit" name="submit" value="'.$language["admin_select"].'">';
echo '</form>';

if (isset($tree_prefix)){
	$pers_favorite=''; if (isset($_POST['pers_favorite'])){ $pers_favorite='1'; }
	if(function_exists('date_default_timezone_set')){
		date_default_timezone_set('Europe/Amsterdam');
	}
	$datum=strtoupper(date("d M Y"));
	$tijd=date("H:i:s");

	if (isset($_POST['person_remove'])){
		$new_nr_qry= "SELECT * FROM ".$tree_prefix."person WHERE pers_gedcomnumber='".$person."'";
		$new_nr_result = mysql_query($new_nr_qry,$db);
		$new_nr=mysql_fetch_object($new_nr_result);

		if ($new_nr->pers_fams OR $new_nr->pers_famc){
			echo '<div class="confirm">';
				echo $language["editor_remove_person_warning"];
			echo '</div>';
		}
		else{
			echo '<div class="confirm">';
			echo $language["editor_remove_person"];
			echo ' <form method="post" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
			echo '<input type="hidden" name="page" value="'.$page.'">';
			echo ' <input type="Submit" name="person_remove2" value="'.$language["admin_yes"].'" style="color : red; font-weight: bold;">';
			echo ' <input type="Submit" name="submit" value="'.$language["admin_no"].'" style="color : blue; font-weight: bold;">';
			echo '</form>';
			echo '</div>';
		}
	}
	if (isset($_POST['person_remove2'])){
		echo '<div class="confirm">';

		$sql="DELETE FROM ".$tree_prefix."events WHERE event_person_id='".$person."'";
		$result=mysql_query($sql) or die(mysql_error());

		$sql="DELETE FROM ".$tree_prefix."addresses WHERE address_person_id='".$person."'";
		$result=mysql_query($sql) or die(mysql_error());

		$sql="DELETE FROM ".$tree_prefix."person WHERE pers_gedcomnumber='".$person."'";
		$result=mysql_query($sql) or die(mysql_error());

		echo $language["editor_person_removed"];

		// *** Select new person ***
		$new_nr_qry= "SELECT * FROM ".$tree_prefix."person WHERE pers_favorite LIKE '%_' ORDER BY pers_lastname, pers_firstname LIMIT 0,1";
		$new_nr_result = mysql_query($new_nr_qry,$db);
		$new_nr=mysql_fetch_object($new_nr_result);
		if (isset($new_nr->pers_gedcomnumber)){
			$person=$new_nr->pers_gedcomnumber;
			$_SESSION['admin_person']=$person;
		}
		else{
			$new_nr_qry= "SELECT * FROM ".$tree_prefix."person LIMIT 0,1";
			$new_nr_result = mysql_query($new_nr_qry,$db);
			$new_nr=mysql_fetch_object($new_nr_result);
			if ($new_nr->pers_gedcomnumber){
				$person=$new_nr->pers_gedcomnumber;
				$_SESSION['admin_person']=$person;
			}
		}

		family_tree_update($tree_prefix);

		echo '</div>';
	}

	if (isset($_POST['person_change'])){
		$sql="UPDATE ".$tree_prefix."person SET
		pers_favorite='".$pers_favorite."',
		pers_firstname='".text_process($_POST["pers_firstname"])."',
		pers_callname='".text_process($_POST["pers_callname"])."',
		pers_prefix='".text_process($_POST["pers_prefix"])."',
		pers_lastname='".text_process($_POST["pers_lastname"])."',
		pers_patronym='".text_process($_POST["pers_patronym"])."',
		pers_name_text='".text_process($_POST["pers_name_text"],true)."',
		pers_name_source='".veilig($_POST["pers_name_source"])."',
		pers_alive='".veilig($_POST["levend"])."',
		pers_sexe='".veilig($_POST["sexe"])."',
		pers_own_code='".veilig($_POST["pers_own_code"])."',
		pers_text='".text_process($_POST["tekst"],true)."',
		pers_changed_date='".$datum."',
		pers_changed_time='".$tijd."'
		WHERE pers_gedcomnumber='".veilig($person)."'";
		$result=mysql_query($sql) or die(mysql_error());

		family_tree_update($tree_prefix);
	}

	if (isset($_POST['person_add'])){
		// *** Generate new gedcomnr, find highest gedcomnummer I100: strip I and order by numeric ***
		$new_nr_qry= "SELECT *, ABS(substring(pers_gedcomnumber, 2)) AS gednr
			FROM ".$tree_prefix."person ORDER BY gednr DESC LIMIT 0,1";
		$new_nr_result = mysql_query($new_nr_qry,$db);
		$new_nr=mysql_fetch_object($new_nr_result);
		$new_gedcomnummer='I1';
		if (isset($new_nr->pers_gedcomnumber)){
			$new_gedcomnummer='I'.(substr($new_nr->pers_gedcomnumber,1)+1);
		}

		$sql="INSERT INTO ".$tree_prefix."person SET
			pers_tree_prefix='".$tree_prefix."',
			pers_famc='',
			pers_fams='',
			pers_indexnr='',
			pers_index_bapt='',
			pers_index_death='',
			pers_gedcomnumber='".$new_gedcomnummer."',
			pers_favorite='".$pers_favorite."',
			pers_firstname='".text_process($_POST["pers_firstname"])."',
			pers_callname='".text_process($_POST["pers_callname"])."',
			pers_prefix='".text_process($_POST["pers_prefix"])."',
			pers_lastname='".text_process($_POST["pers_lastname"])."',
			pers_patronym='".text_process($_POST["pers_patronym"])."',
			pers_name_text='".text_process($_POST["pers_name_text"])."',
			pers_name_source='".veilig($_POST["pers_name_source"])."',
			pers_alive='".veilig($_POST["levend"])."',
			pers_sexe='".veilig($_POST["sexe"])."',
			pers_own_code='".veilig($_POST["pers_own_code"])."',
			pers_place_index='',
			pers_text='".text_process($_POST["tekst"])."',
			pers_new_date='".$datum."',
			pers_new_time='".$tijd."'";
		$result=mysql_query($sql) or die(mysql_error());

		// *** Show new person ***
		$person=$new_gedcomnummer;
		$_SESSION['admin_person']=$person;

		family_tree_update($tree_prefix);

		// *** Add child to family, add a new child (new gedcomnumber) ***
		if (isset($_POST['child_connect'])){
			$_POST['child_connect2']=$new_gedcomnummer;
		}	

	}

	if (isset($_POST['pers_birth_date'])){
		$pers_birth_source=veilig($_POST["pers_birth_source"]);
		if ($_POST["pers_birth_source2"]!=''){ $pers_birth_source=veilig($_POST["pers_birth_source2"]); }

		$pers_bapt_source=veilig($_POST["pers_bapt_source"]);
		if ($_POST["pers_bapt_source2"]!=''){ $pers_bapt_source=veilig($_POST["pers_bapt_source2"]); }

		$pers_death_source=veilig($_POST["pers_death_source"]);
		if ($_POST["pers_death_source2"]!=''){ $pers_death_source=veilig($_POST["pers_death_source2"]); }

		$pers_buried_source=veilig($_POST["pers_buried_source"]);
		if ($_POST["pers_buried_source2"]!=''){ $pers_buried_source=veilig($_POST["pers_buried_source2"]); }

    $pers_index_bapt='';
    if ($_POST['pers_bapt_place']){ $pers_index_bapt=$_POST['pers_bapt_place']; }
    if ($_POST['pers_birth_place']){ $pers_index_bapt=$_POST['pers_birth_place']; }
    $pers_index_death='';
    if ($_POST['pers_buried_place']){ $pers_index_death=$_POST['pers_buried_place']; }
    if ($_POST['pers_death_place']){ $pers_index_death=$_POST['pers_death_place']; }

		$sql="UPDATE ".$tree_prefix."person SET
		pers_index_bapt='".$pers_index_bapt."', pers_index_death='".$pers_index_death."',
		pers_birth_date='".date_process(veilig($_POST["pers_birth_date"]))."',
		pers_birth_place='".text_process($_POST["pers_birth_place"])."',
		pers_birth_text='".text_process($_POST["pers_birth_text"],true)."',
		pers_birth_source='".$pers_birth_source."',
		pers_bapt_date='".date_process(veilig($_POST["pers_bapt_date"]))."',
		pers_bapt_place='".text_process($_POST["pers_bapt_place"])."',
		pers_bapt_text='".text_process($_POST["pers_bapt_text"],true)."',
		pers_bapt_source='".$pers_bapt_source."',
		pers_religion='".veilig($_POST["religie"])."',
		pers_death_date='".date_process(veilig($_POST["pers_death_date"]))."',
		pers_death_place='".text_process($_POST["pers_death_place"])."',
		pers_death_text='".text_process($_POST["pers_death_text"],true)."',
		pers_death_source='".$pers_death_source."',
		pers_death_cause='".veilig($_POST["pers_death_cause"])."',
		pers_buried_date='".date_process(veilig($_POST["pers_buried_date"]))."',
		pers_buried_place='".text_process($_POST["pers_buried_place"])."',
		pers_buried_text='".text_process($_POST["pers_buried_text"],true)."',
		pers_buried_source='".$pers_buried_source."',
		pers_cremation='".veilig($_POST["pers_cremation"])."',
		pers_changed_date='".$datum."',
		pers_changed_time='".$tijd."'
		WHERE pers_gedcomnumber='".veilig($person)."'";
		$result=mysql_query($sql) or die(mysql_error());

		family_tree_update($tree_prefix);
	}

	// *** Select person ***
	$search_firstname='';
	if (isset($_POST["search_firstname"])){
		$search_firstname=veilig($_POST['search_firstname']);
		$_SESSION['admin_search_firstname']=$search_firstname;
	}
	if (isset($_SESSION['admin_search_firstname'])){ $search_firstname=$_SESSION['admin_search_firstname']; }

	$search_lastname='';
	if (isset($_POST["search_lastname"])){
		$search_lastname=veilig($_POST['search_lastname']);
		$_SESSION['admin_search_lastname']=$search_lastname;
	}
	if (isset($_SESSION['admin_search_lastname'])){ $search_lastname=$_SESSION['admin_search_lastname']; }

	//echo '<br>'.$language["main_search"].' ';
	echo '<br><form method="POST" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
		echo '<input type="hidden" name="page" value="'.$page.'">';
		print $language["main_firstname"].':';
		print ' <input type="text" class="fonts" name="search_firstname" value="'.$search_firstname.'" size="12"> ';
		print $language["main_lastname"].':';
		print ' <input class="fonts" type="text" name="search_lastname" value="'.$search_lastname.'" size="12">';
		echo ' <input type="hidden" name="tree_prefix" value="'.$tree_prefix.'">';
		print ' <input class="fonts" type="submit" value="'.$language["main_search"].'">';
	print "</form>\n";

	$persoon_qry= "SELECT * FROM ".$tree_prefix."person
		WHERE CONCAT(REPLACE(pers_prefix,'_',' '),pers_lastname) LIKE '%".$search_lastname."%'
		AND pers_firstname LIKE '%".$search_firstname."%'
		ORDER BY pers_lastname, pers_firstname";

	$persoon_result = mysql_query($persoon_qry,$db);
	if ($persoon_result){
	//if ($persoon_result AND mysql_num_rows($persoon_result) > 0){
		//echo '<br>'.$language["editor_person"].': ';
		echo '<b>'.$language["editor_found"].'</b> ';
		echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
		echo '<input type="hidden" name="page" value="'.$page.'">';
		print '<select size="1" name="person" style="width: 200px">';
		while ($persoon=mysql_fetch_object($persoon_result)){
			$selected='';
			if (isset($person)){
				if ($persoon->pers_gedcomnumber==$person){ $selected=' SELECTED'; }
			}

			$prefix1=''; $prefix2='';
			//if($user['soortindex']=="j") {
			//	$prefix1=strtolower(str_replace("_"," ",$persoon->pers_prefix));
			//}
			//else {
				$prefix2=" ".strtolower(str_replace("_"," ",$persoon->pers_prefix));
			//}

			echo '<option value="'.$persoon->pers_gedcomnumber.'"'.$selected.'>'.
				$prefix1.$persoon->pers_lastname.', '.$persoon->pers_firstname.$prefix2.' ['.$persoon->pers_gedcomnumber.']</option>';
		}
		echo '</select>';
		echo ' <input type="Submit" name="submit" value="'.$language["admin_select"].'">';
		echo '</form><br>';

		// *** Favorites ***
		//echo ' '.$language["admin_or"].': ';
		echo ucfirst($language["admin_or"]).' '.strtolower($language["editor_favorite"]).': ';
		
		echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
		echo '<input type="hidden" name="page" value="'.$page.'">';
		$persoon_qry= "SELECT * FROM ".$tree_prefix."person WHERE pers_favorite LIKE '%_' ORDER BY pers_lastname, pers_firstname";
		$persoon_result = mysql_query($persoon_qry,$db);
		print '<select size="1" name="person" style="width: 250px">';
		while ($persoon=mysql_fetch_object($persoon_result)){
			$selected='';
			if (isset($person)){
				if ($persoon->pers_gedcomnumber==$person){ $selected=' SELECTED'; }
			}
			echo '<option value="'.$persoon->pers_gedcomnumber.'"'.$selected.'>'.
				$persoon->pers_lastname.', '.$persoon->pers_firstname.' '.strtolower(str_replace("_"," ",$persoon->pers_prefix)).' ['.$persoon->pers_gedcomnumber.']</option>';
		}
		echo '</select>';
		echo ' <input type="Submit" name="submit" value="'.$language["editor_favorite"].'">';
		echo '</form>';
	}

	// *** Check if this is a new family tree ***
	$persoon2_qry= "SELECT * FROM ".$tree_prefix."person";
	$persoon2_result = mysql_query($persoon2_qry,$db);
	if ($persoon2_result AND mysql_num_rows($persoon2_result) > 0){
		// *** Family tree exists and is filled with data ***
	}
	else{
		echo '<h2>'.$language["editor_tree_new"].'</h2>';
		$_SESSION['tree_prefix']=$tree_prefix;
		$new_nr_qry= "SELECT * FROM ".$tree_prefix."person LIMIT 0,1";
		$new_nr_result = mysql_query($new_nr_qry,$db);
		// *** Create new tables ***
		if (!$new_nr_result){ include ("gedcom_tables.php"); }
		$person=''; $menu_admin='person'; $add_person=1;
	}

}

if (isset($person)){
	//echo '<div id="header">';
	echo '<div id="tree_menu">';
	echo '<ul>';
		$selecteer=''; if ($menu_admin=='person'){ $selecteer=' id="current"'; }
		echo '<li'.$selecteer.'><a href="index.php?page='.$page.'&amp;menu_admin=person">'.$language["editor_person"]."</a></li>";
		$selecteer=''; if ($menu_admin=='person_data'){ $selecteer=' id="current"'; }
		echo '<li'.$selecteer.'><a href="index.php?page='.$page.'&amp;menu_admin=person_data">'.$language["editor_pers_data"]."</a></li>";
		$selecteer=''; if ($menu_admin=='person_data_list'){ $selecteer=' id="current"'; }
		echo '<li'.$selecteer.'><a href="index.php?page='.$page.'&amp;menu_admin=person_data_list">'.$language["editor_pers_events"]."</a></li>";
		$selecteer=''; if ($menu_admin=='marriage'){ $selecteer=' id="current"'; }

		echo ' <li><a href="index.php?page='.$page.'&amp;menu_admin=person&amp;add_person=1">
		<img src="images/person_connect.gif" border="0" title="'.$language["editor_add_person"].'" alt="'.$language["editor_add_person"].'">
		</a></li>';

		echo '<li'.$selecteer.'><a href="index.php?page='.$page.'&amp;menu_admin=marriage">'.$language["editor_marriage"]."</a></li>";
		$selecteer=''; if ($menu_admin=='marriage_data_list'){ $selecteer=' id="current"'; }
		echo '<li'.$selecteer.'><a href="index.php?page='.$page.'&amp;menu_admin=marriage_data_list">'.$language["editor_marr_events"]."</a></li>";
		$selecteer=''; if ($menu_admin=='sources'){ $selecteer=' id="current"'; }

		echo ' <li><a href="index.php?page='.$page.'&amp;menu_admin=marriage&amp;add_marriage=1">
		<img src="images/family_connect.gif" border="0" title="'.$language["editor_add_marriage"].'" alt="'.$language["editor_add_marriage"].'">
		</a></li>';

		echo '<li'.$selecteer.'><a href="index.php?page='.$page.'&amp;menu_admin=sources">* '.$language["source_sources"]."</a></li>";
		$selecteer=''; if ($menu_admin=='adresses'){ $selecteer=' id="current"'; }
		echo '<li'.$selecteer.'><a href="index.php?page='.$page.'&amp;menu_admin=adresses">* '.$language["address_addresses"]."</a></li>";
	echo '</ul>';

	echo '</div>';
	// *** Align content to the left ***
	echo '<div style="float: left;">';

	// *****************
	// *** Show data ***
	// *****************
	echo $language["editor_examples1"].'<br>'; 
	echo $language["editor_examples2"].'<br>';

	// *** Family move down ***
	if (isset($_GET['fam_down'])){
		$child_array_org=explode(";",veilig($_GET['fam_array']));
		$child_array=$child_array_org;
		$child_array_id=veilig($_GET['fam_down']);
		$child_array[$child_array_id]=$child_array_org[($child_array_id+1)];
		$child_array[$child_array_id+1]=$child_array_org[($child_array_id)];
		$fams='';
		for ($k=0; $k<count($child_array); $k++){
			if ($k>0){ $fams.=';'; }
			$fams.=$child_array[$k];
		}
		$sql="UPDATE ".$tree_prefix."person SET
		pers_fams='".$fams."',
		pers_changed_date='".$datum."',
		pers_changed_time='".$tijd."'
		WHERE pers_id='".veilig($_GET["person_id"])."'";
		$result=mysql_query($sql) or die(mysql_error());
	}

	// *** Family move up ***
	if (isset($_GET['fam_up'])){
		$child_array_org=explode(";",veilig($_GET['fam_array']));
		$child_array=$child_array_org;
		$child_array_id=veilig($_GET['fam_up'])-1;
		$child_array[$child_array_id+1]=$child_array_org[($child_array_id)];
		$child_array[$child_array_id]=$child_array_org[($child_array_id+1)];
		$fams='';
		for ($k=0; $k<count($child_array); $k++){
			if ($k>0){ $fams.=';'; }
			$fams.=$child_array[$k];
		}
		$sql="UPDATE ".$tree_prefix."person SET
		pers_fams='".$fams."',
		pers_changed_date='".$datum."',
		pers_changed_time='".$tijd."'
		WHERE pers_id='".veilig($_GET["person_id"])."'";
		$result=mysql_query($sql) or die(mysql_error());
	}

	// *** Family disconnect ***
	if (isset($_GET['fam_remove'])){
		$new_nr_qry= "SELECT * FROM ".$tree_prefix."family WHERE fam_gedcomnumber='".veilig($_GET['fam_remove'])."'";
		$new_nr_result = mysql_query($new_nr_qry,$db);
		$new_nr=mysql_fetch_object($new_nr_result);
		if ($new_nr->fam_children){
			echo '<div class="confirm">';
         echo $language["editor_marriage_message"];
			echo '</div>';
		}
		else{
			echo '<div class="confirm">';
         echo $language["editor_marriage_remove"];
			echo ' <form method="post" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
			echo '<input type="hidden" name="page" value="'.$page.'">';
			echo '<input type="hidden" name="fam_remove" value="'.veilig($_GET['fam_remove']).'">';
			echo ' <input type="Submit" name="fam_remove2" value="'.$language["admin_yes"].'" style="color : red; font-weight: bold;">';
			echo ' <input type="Submit" name="submit" value="'.$language["admin_no"].'" style="color : blue; font-weight: bold;">';
			echo '</form>';
			echo '</div>';
		}
	}
	if (isset($_POST['fam_remove2'])){
		echo '<div class="confirm">';

		$fam_remove=veilig($_POST['fam_remove']);

		// *** Remove fams number from man and woman ***
		$new_nr_qry= "SELECT * FROM ".$tree_prefix."family WHERE fam_gedcomnumber='".$fam_remove."'";
		$new_nr_result = mysql_query($new_nr_qry,$db);
		$new_nr=mysql_fetch_object($new_nr_result);

		if (isset($new_nr->fam_man)){
			$fams_man_qry= "SELECT * FROM ".$tree_prefix."person WHERE pers_gedcomnumber='".$new_nr->fam_man."'";
			$fams_man_result = mysql_query($fams_man_qry,$db);
			$fams_db=mysql_fetch_object($fams_man_result);
			$fams=explode(";",$fams_db->pers_fams);
			foreach ($fams as $key => $value) {
				if ($fams[$key] != $fam_remove){ $fams2[]=$fams[$key]; }
			}
			$fams3='';
			$pers_indexnr=''; if ($fams_db->pers_famc){ $pers_indexnr=$fams_db->pers_famc; }
			if (isset($fams2[0])){
				$fams3 = implode(";", $fams2);
				$pers_indexnr=$fams2[0];
			}
			$sql="UPDATE ".$tree_prefix."person SET
				pers_fams='".$fams3."',
				pers_indexnr='".$pers_indexnr."',
				pers_changed_date='".$datum."',
				pers_changed_time='".$tijd."'
				WHERE pers_id='".$fams_db->pers_id."'";
			$result=mysql_query($sql) or die(mysql_error());
		}

		unset ($fams2);
		if (isset($new_nr->fam_woman)){
			$fams_man_qry= "SELECT * FROM ".$tree_prefix."person WHERE pers_gedcomnumber='".$new_nr->fam_woman."'";
			$fams_man_result = mysql_query($fams_man_qry,$db);
			$fams_db=mysql_fetch_object($fams_man_result);
			$fams=explode(";",$fams_db->pers_fams);
			foreach ($fams as $key => $value) {
				if ($fams[$key] != $fam_remove){ $fams2[]=$fams[$key]; }
			}
			$fams3='';
			$pers_indexnr=''; if ($fams_db->pers_famc){ $pers_indexnr=$fams_db->pers_famc; }
			if (isset($fams2[0])){
				$fams3 = implode(";", $fams2);
				$pers_indexnr=$fams2[0];
			}
			$sql="UPDATE ".$tree_prefix."person SET
				pers_fams='".$fams3."',
				pers_indexnr='".$pers_indexnr."',
				pers_changed_date='".$datum."',
				pers_changed_time='".$tijd."'
				WHERE pers_id='".$fams_db->pers_id."'";
			$result=mysql_query($sql) or die(mysql_error());
		}

		$sql="DELETE FROM ".$tree_prefix."events WHERE event_family_id='".$fam_remove."'";
		$result=mysql_query($sql) or die(mysql_error());

		$sql="DELETE FROM ".$tree_prefix."addresses WHERE address_family_id='".$fam_remove."'";
		$result=mysql_query($sql) or die(mysql_error());

		$sql="DELETE FROM ".$tree_prefix."family WHERE fam_gedcomnumber='".$fam_remove."'";
		$result=mysql_query($sql) or die(mysql_error());

		family_tree_update($tree_prefix);
      echo $language["editor_marriage_removed"];
		echo '</div>';
	}

	// *** Add parents to person ***
	if (isset($_GET['add_parents'])){
		echo '<div class="confirm">';
		echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
		echo '<input type="hidden" name="page" value="'.$page.'">';
		$parents= "SELECT * FROM ".$tree_prefix."family";
		$parents_result = mysql_query($parents,$db);
		echo $language["editor_parents_connect"].' ';
		print '<select size="1" name="add_parents" style="width: 250px">';
		while ($parentsDb=mysql_fetch_object($parents_result)){
			$oudertekst='';
			//*** Father ***
			if ($parentsDb->fam_man){
				$oudertekst.=show_person($parentsDb->fam_man);
			}
			else{
				$oudertekst=$language["nn"];
			}
			$oudertekst.=' '.$language["editor_and"].' ';

			//*** Mother ***
			if ($parentsDb->fam_woman){
				$oudertekst.=show_person($parentsDb->fam_woman);
			}
			else{
				$oudertekst.=$language["nn"];
			}

			echo '<option value="'.$parentsDb->fam_gedcomnumber.'">'.
				$oudertekst.' ['.$parentsDb->fam_gedcomnumber.']</option>';
		}
		echo '</select>';
		echo ' <input type="Submit" name="submit" value="'.$language["admin_select"].'">';
		echo '</form>';
		echo '</div>';
	}

	if (isset($_POST['add_parents'])){
		echo '<div class="confirm">';

		$parents= "SELECT * FROM ".$tree_prefix."family
			WHERE fam_gedcomnumber='".veilig($_POST['add_parents'])."'";
		$parents_result = mysql_query($parents,$db);
		$parentsDb=mysql_fetch_object($parents_result);

		if ($parentsDb->fam_children){
			$kinderen.=$parentsDb->fam_children.';'.$person;
		}
		else{
			$kinderen=$person;
		}

		$sql="UPDATE ".$tree_prefix."family SET
		fam_children='".$kinderen."',
		fam_changed_date='".$datum."',
		fam_changed_time='".$tijd."'
		WHERE fam_gedcomnumber='".veilig($_POST['add_parents'])."'";
		$result=mysql_query($sql) or die(mysql_error());

		// *** Add parents to child record ***
		$sql="UPDATE ".$tree_prefix."person SET
		pers_famc='".veilig($_POST['add_parents'])."',
		pers_changed_date='".$datum."',
		pers_changed_time='".$tijd."'
		WHERE pers_gedcomnumber='".$person."'";
		$result=mysql_query($sql) or die(mysql_error());

		family_tree_update($tree_prefix);
		echo $language["editor_parents_connected"];
		echo '</div>';
	}

	// *** Add child to family ***
	if (isset($_POST['child_connect2'])){
		
		if (isset($_POST["children"])){
			$sql="UPDATE ".$tree_prefix."family SET
			fam_children='".veilig($_POST["children"]).';'.veilig($_POST["child_connect2"])."',
			fam_changed_date='".$datum."',
			fam_changed_time='".$tijd."'
			WHERE fam_gedcomnumber='".veilig($_POST['family_id'])."'";
		}
		else{
			$sql="UPDATE ".$tree_prefix."family SET
			fam_children='".veilig($_POST["child_connect2"])."',
			fam_changed_date='".$datum."',
			fam_changed_time='".$tijd."'
			WHERE fam_gedcomnumber='".veilig($_POST['family_id'])."'";
		}
		$result=mysql_query($sql) or die(mysql_error());

		// *** Add parents to child record ***
		$sql="UPDATE ".$tree_prefix."person SET
		pers_famc='".veilig($_POST['family_id'])."',
		pers_changed_date='".$datum."',
		pers_changed_time='".$tijd."'
		WHERE pers_gedcomnumber='".veilig($_POST["child_connect2"])."'";
		$result=mysql_query($sql) or die(mysql_error());

		family_tree_update($tree_prefix);
	}

	// *** Disconnect child ***
	if (isset($_GET['child_disconnect'])){
		echo '<div class="confirm">';
      echo $language["editor_child_disconnect"];
		echo ' <form method="post" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
		echo '<input type="hidden" name="page" value="'.$_GET['page'].'">';
		echo '<input type="hidden" name="family_id" value="'.$_GET['family_id'].'">';
		echo '<input type="hidden" name="child_disconnect2" value="'.$_GET['child_disconnect'].'">';
		echo '<input type="hidden" name="child_disconnect_gedcom" value="'.$_GET['child_disconnect_gedcom'].'">';
		echo ' <input type="Submit" name="child_disconnecting" value="'.$language["admin_yes"].'" style="color : red; font-weight: bold;">';
		echo ' <input type="Submit" name="submit" value="'.$language["admin_no"].'" style="color : blue; font-weight: bold;">';
		echo '</form>';
		echo '</div>';
	}
	if (isset($_POST['child_disconnecting'])){
		$sql="UPDATE ".$tree_prefix."family SET
		fam_children='".veilig($_POST["child_disconnect2"])."',
		fam_changed_date='".$datum."',
		fam_changed_time='".$tijd."'
		WHERE fam_id='".veilig($_POST["family_id"])."'";
		$result=mysql_query($sql) or die(mysql_error());

		// *** Add parents to child record ***
		$sql="UPDATE ".$tree_prefix."person SET
		pers_famc='',
		pers_changed_date='".$datum."',
		pers_changed_time='".$tijd."'
		WHERE pers_gedcomnumber='".veilig($_POST["child_disconnect_gedcom"])."'";
		$result=mysql_query($sql) or die(mysql_error());
	}

	// *** Child move down ***
	if (isset($_GET['child_down'])){
		$child_array_org=explode(";",veilig($_GET['child_array']));
		$child_array=$child_array_org;
		$child_array_id=veilig($_GET['child_down']);
		$child_array[$child_array_id]=$child_array_org[($child_array_id+1)];
		$child_array[$child_array_id+1]=$child_array_org[($child_array_id)];
		$kinderen='';
		for ($k=0; $k<count($child_array); $k++){
			if ($k>0){ $kinderen.=';'; }
			$kinderen.=$child_array[$k];
		}
		$sql="UPDATE ".$tree_prefix."family SET
		fam_children='".$kinderen."',
		fam_changed_date='".$datum."',
		fam_changed_time='".$tijd."'
		WHERE fam_id='".veilig($_GET["family_id"])."'";
		$result=mysql_query($sql) or die(mysql_error());
	}

	// *** Child move up ***
	if (isset($_GET['child_up'])){
		$child_array_org=explode(";",veilig($_GET['child_array']));
		$child_array=$child_array_org;
		$child_array_id=veilig($_GET['child_up'])-1;
		$child_array[$child_array_id+1]=$child_array_org[($child_array_id)];
		$child_array[$child_array_id]=$child_array_org[($child_array_id+1)];
		$kinderen='';
		for ($k=0; $k<count($child_array); $k++){
			if ($k>0){ $kinderen.=';'; }
			$kinderen.=$child_array[$k];
		}
		$sql="UPDATE ".$tree_prefix."family SET
		fam_children='".$kinderen."',
		fam_changed_date='".$datum."',
		fam_changed_time='".$tijd."'
		WHERE fam_id='".veilig($_GET["family_id"])."'";
		$result=mysql_query($sql) or die(mysql_error());
	}

	if ($add_person==true){
		$pers_firstname=''; $pers_callname='';
		$pers_prefix=''; $pers_lastname=''; $pers_patronym='';
		$pers_name_text=''; $pers_name_source='';
		$levend=''; $sexe=''; $pers_own_code=''; $tekst='';
		$pers_favorite='';
	}
	else{
		$persoon_qry= "SELECT * FROM ".$tree_prefix."person WHERE pers_gedcomnumber='".$person."'";
		$persoon_result = mysql_query($persoon_qry,$db);
		$persoon=mysql_fetch_object($persoon_result);

		$pers_firstname=$persoon->pers_firstname; $pers_callname=$persoon->pers_callname;
		$pers_prefix=$persoon->pers_prefix; $pers_lastname=$persoon->pers_lastname; $pers_patronym=$persoon->pers_patronym;
		$pers_name_text=$persoon->pers_name_text; $pers_name_source=$persoon->pers_name_source;
		$levend=$persoon->pers_alive; $sexe=$persoon->pers_sexe;
		$pers_own_code=$persoon->pers_own_code; $tekst=$persoon->pers_text;
		$pers_favorite=@$persoon->pers_favorite;
	}

	// *** Text area size ***
	$veld_datum=20;
	$veld_plaats=40;
	$veld_tekst='style="height: 40px; width:500px"';
	$veld_tekst_groot='style="height: 200px; width:500px"';

	// *******************
	// *** Show person ***
	// *******************
	if ($menu_admin=='person'){

		// *** Add child to family, 1st option: select a child from a pull-down list ***
		if (isset($_GET['child_connect'])){
			echo '<div class="confirm">';
			echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
			echo '<input type="hidden" name="page" value="'.$page.'">';
			if (isset($_GET['children'])){
				echo '<input type="hidden" name="children" value="'.$_GET['children'].'">';
			}
			echo '<input type="hidden" name="family_id" value="'.$_GET['family_id'].'">';
			$persoon_qry= "SELECT * FROM ".$tree_prefix."person WHERE pers_famc='' ORDER BY pers_lastname, pers_firstname";
			$persoon_result = mysql_query($persoon_qry,$db);
			//if (isset($_GET['child_connect'])){
				echo $language["editor_select_child"].' ';
				print '<select size="1" name="child_connect2">';
			//}
			while ($persoon=mysql_fetch_object($persoon_result)){
				echo '<option value="'.$persoon->pers_gedcomnumber.'">'.
					$persoon->pers_lastname.', '.$persoon->pers_firstname.' '.strtolower(str_replace("_"," ",$persoon->pers_prefix)).' ['.$persoon->pers_gedcomnumber.']</option>';
			}
			echo '</select>';
			echo ' <input type="Submit" name="submit" value="'.$language["admin_select"].'">';
			echo '</form>';
			echo '</div>';
			echo '<p>'.$language["editor_add_child"].'<br>';
		}

		echo '<table class="humo standaard" border="1">';

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

		// *** Add child to family, 2nd option: add a new child ***
		if (isset($_GET['child_connect'])){
			echo '<input type="hidden" name="child_connect" value="'.$_GET['child_connect'].'">';
			if (isset($_GET['children'])){
				echo '<input type="hidden" name="children" value="'.$_GET['children'].'">';

			}
			echo '<input type="hidden" name="family_id" value="'.$_GET['family_id'].'">';
		}

		print '<tr class="tabel_kop"><th>'.$language["groups_option"].'</th><th colspan="2">'.$language["groups_value"].'</th></tr>';

		if ($add_person==false){
		echo '<tr><td>'.$language["editor_parents"].'</td><td colspan="2">';
		$oudertekst='';

		if ($persoon->pers_famc){
			// *** Search for parents ***
			$gezinouders=mysql_query("SELECT * FROM ".$tree_prefix."family
				WHERE fam_gedcomnumber='$persoon->pers_famc'",$db);
			$gezinoudersDb=mysql_fetch_object($gezinouders);

			//*** Father ***
			if ($gezinoudersDb->fam_man){
				$oudertekst.=show_person($gezinoudersDb->fam_man);
			}
			else{
				$oudertekst=$language["nn"];
			}
			$oudertekst.=' '.$language["editor_and"].' ';

			//*** Mother ***
			if ($gezinoudersDb->fam_woman){
				$oudertekst.=show_person($gezinoudersDb->fam_woman);
			}
			else{
				$oudertekst.=$language["nn"];
			}
		}
		else{
			echo '<a href="index.php?page='.$page.'&amp;menu_admin=person&amp;add_parents=1"><img src="images/family_connect.gif" border="0" alt="fam_connect"></a>';
		}
		echo $oudertekst.'</td></tr>';
	}

	// *** Quickchoice/ favorite menu ***
	$checked=''; if ($pers_favorite=='1'){$checked='checked';}
	print '<tr><td>'.$language["editor_favorite"].'</td><td></td><td><input type="Checkbox" name="pers_favorite" value="1" '.$checked.'>'.$language["editor_favorites_add"].'</td></tr>';

		// *** Naam ***
		echo '<tr><td rowspan="6">'.$language["editor_name"].'</td>';
		echo '<td><b>'.$language["editor_firstname"].'</b> - '.$language["editor_usualname"].'</td><td><input type="text" name="pers_firstname" value="'.$pers_firstname.'"  size="40"> <input type="text" name="pers_callname" value="'.$pers_callname.'" size="30"></td></tr>';
		echo '<tr><td>'.$language["editor_prefix"].'</td><td><input type="text" name="pers_prefix" value="'.$pers_prefix.'" size="10">'.$language["editor_prefix_exmp"].'</td></tr>';
		echo '<tr><td><b>'.$language["editor_lastname"].'</b></td><td><input type="text" name="pers_lastname" value="'.$pers_lastname.'" size="60"></td></tr>';
		echo '<tr><td>'.$language["editor_patronymic"].'</td><td><input type="text" name="pers_patronym" value="'.$pers_patronym.'" size="60"></td></tr>';
		echo '<tr><td>'.$language["editor_nametext"].'</td><td><textarea rows="1" name="pers_name_text" '.$veld_tekst.'>'.text_show($pers_name_text).'</textarea></td></tr>';
		echo '<tr><td>'.$language["editor_namesource"].'</td><td><input type="text" name="pers_name_source" value="'.$pers_name_source.'" size="60"></td></tr>';

		// *** Levend ***
		echo '<tr><td>'.$language["editor_alive"].'</td><td>'.$language["editor_privacyfilter"].'</td><td>';
			$selected_lev='lev';
			if ($levend=='HZ_ovl' OR $levend=='Aldfaer_ovl'){ $selected_lev='ovl'; }

			$selected=''; if ($selected_lev=='lev'){ $selected=' CHECKED'; }
			echo ' <input type="radio" name="levend" value="HZ_levend"'.$selected.'> '.$language["editor_alive"];

			$selected=''; if ($selected_lev=='ovl'){ $selected=' CHECKED'; }
			echo ' <input type="radio" name="levend" value="HZ_ovl"'.$selected.'> '.$language["editor_deceased"];
		echo '</td></tr>';

		// *** Sexe ***
		$kleur='';
		// *** If sexe = unknown then show a red line (new person = other colour). ***
		if ($sexe==''){ $kleur=' bgcolor="#FF0000"'; }
		if ($add_person==true AND $sexe==''){ $kleur=' bgcolor="#CCFFFF"'; }

		echo '<tr><td>'.$language["editor_sexe"].'</td><td></td><td'.$kleur.'>';
			$selected=''; if ($sexe=='M'){ $selected=' CHECKED'; }
			echo '<input type="radio" name="sexe" value="M"'.$selected.'> '.$language["editor_man"];
			$selected=''; if ($sexe=='F'){ $selected=' CHECKED'; }
			echo ' <input type="radio" name="sexe" value="F"'.$selected.'> '.$language["editor_woman"];
			$selected=''; if ($sexe==''){ $selected=' CHECKED'; }
			echo ' <input type="radio" name="sexe" value=""'.$selected.'> ?';
		echo '</td></tr>';

		// *** Eigen Code ***
		echo '<tr><td>'.$language["editor_own_code"].'</td><td></td>';
		echo '<td><input type="text" name="pers_own_code" value="'.$pers_own_code.'" size="60"></td></tr>';

		echo '<tr><td>'.$language["editor_text"].'</td>';
		echo '<td colspan="2"><textarea rows="1" name="tekst" style="height: 60px; width:650px">'.text_show($tekst).'</textarea></td></tr>';

		if ($add_person==false){
			echo '<tr><td>'.$language["admin_change"].'</td><td colspan="2"><input type="Submit" name="person_change" value="'.$language["admin_change"].'">';

			echo ' '.$language["admin_or"].' ';
			echo '<input type="Submit" name="person_remove" value="'.$language["admin_remove"].'">';
			echo '</td></tr>';
		}
		else{
			echo '<tr><td>'.$language["admin_add"].'</td><td colspan="2"><input type="Submit" name="person_add" value="'.$language["admin_add"].'"></td></tr>';
		}
		echo '</form>';

		if ($add_person==false){
		if ($persoon->pers_fams){
			// *** Search for own family ***
			$fams1=explode(";",$persoon->pers_fams);
			$fam_count=substr_count($persoon->pers_fams, ";");
			for ($i=0; $i<=$fam_count; $i++){
				$gezin=mysql_query("SELECT * FROM ".$tree_prefix."family
				  WHERE fam_gedcomnumber='".$fams1[$i]."'",$db);
				$gezinDb=mysql_fetch_object($gezin);

				echo '<tr><td>'.$language["editor_marriage"].' '.($i+1).'</td><td valign="top">';
				echo '<a href="index.php?page='.$page.'&amp;fam_remove='.$gezinDb->fam_gedcomnumber.'"><img src="images/family_disconnect.gif" border="0" title="'.$language["editor_remove_rel"].'" alt="'.$language["editor_remove_rel"].'"></a>';
				if ($i<$fam_count){
				  echo ' <a href="index.php?page='.$page.'&amp;person_id='.$persoon->pers_id.'&amp;fam_down='.$i.'&amp;fam_array='.$persoon->pers_fams.'"><img src="images/pijl-laag.gif" border="0" alt="fam_down"></a> ';
				}
				else{
				  echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
				}
				if ($i>0){
				  echo ' <a href="index.php?page='.$page.'&amp;person_id='.$persoon->pers_id.'&amp;fam_up='.$i.'&amp;fam_array='.$persoon->pers_fams.'"><img src="images/pijl-hoog.gif" border="0" alt="fam_up"></a> ';
				}
				else{
				  //echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
				}

				echo '</td><td>';

				echo show_person($gezinDb->fam_man);
				echo ' '.$language["editor_and"].' ';
				echo show_person($gezinDb->fam_woman);

				if ($gezinDb->fam_marr_date){ echo ', X '.date_show($gezinDb->fam_marr_date); }
				echo '<br>';

				if ($gezinDb->fam_children){

				  echo $language["editor_children"].':<br>';
				  $kind=explode(";",$gezinDb->fam_children);
				  $child_count=substr_count($gezinDb->fam_children, ";");
				  for ($j=0; $j<=$child_count; $j++){
				    // *** Create new children variabele, for disconnect child ***
				    $kinderen='';
				    for ($k=0; $k<=substr_count($gezinDb->fam_children, ";"); $k++){
				      if ($k!=$j){ $kinderen.=$kind[$k].';'; }
				    }
				    $kinderen=substr($kinderen,0,-1); // *** strip last ; character ***
				    echo '<a href="index.php?page='.$page.'&amp;family_id='.$gezinDb->fam_id.'&amp;child_disconnect='.$kinderen.
				      '&amp;child_disconnect_gedcom='.$kind[$j].'">
				      <img src="images/person_disconnect.gif" border="0" title="'.$language["editor_disconnect_child"].'" alt="'.$language["editor_disconnect_child"].'"></a>';
				    if ($j<$child_count){
				      echo ' <a href="index.php?page='.$page.'&amp;family_id='.$gezinDb->fam_id.'&amp;child_down='.$j.'&amp;child_array='.
				        $gezinDb->fam_children.'"><img src="images/pijl-laag.gif" border="0" alt="child_down"></a>';

				    }
				    else{ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; }
				    if ($j>0){
				      echo ' <a href="index.php?page='.$page.'&amp;family_id='.$gezinDb->fam_id.'&amp;child_up='.$j.'&amp;child_array='.
				        $gezinDb->fam_children.'"><img src="images/pijl-hoog.gif" border="0" alt="child_up"></a> ';
				    }
				    else{ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; }
				    if ($j<9){ echo '0'; }
				    echo ($j+1).') '.show_person($kind[$j],true).'<br>';
				  }
				}

				echo '<a href="index.php?page='.$page.'&amp;family_id='.$gezinDb->fam_gedcomnumber;
				if ($gezinDb->fam_children){ echo '&amp;children='.$gezinDb->fam_children; }
				echo '&amp;child_connect=1&amp;add_person=1"><img src="images/person_connect.gif" border="0" title="'.$language["editor_connect_child"].'" alt="'.$language["editor_connect_child"].'"></a><br>';

				echo '</td></tr>';
			}
		}
		}
		echo '</table>';

		// *** Example in IFRAME ***
		if ($add_person==false){
			echo '<p>'.$language["editor_preview"].'<br>';
			$family='&amp;id='; if (isset($fams1[0])){ $family='&amp;id='.$fams1[0]; }
			echo '<iframe src ="../gezin.php?database='.$tree_prefix.$family.'&amp;hoofdpersoon='.$person.'" width="100%" height="300">';
			echo '  <p>Your browser does not support iframes.</p>';
			echo '</iframe>';
		}

	}

	// ************************
	// *** Show person data ***
	// ************************
	if ($menu_admin=='person_data'){
		echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
		echo '<input type="hidden" name="page" value="'.$page.'">';

		echo '<table class="humo standaard" border="1">';
		print '<tr class="tabel_kop"><th>'.$language["groups_option"].'</th><th colspan="2">'.$language["groups_value"].'</th></tr>';

		// *** Birth ***
		echo '<tr><td rowspan="3">'.$language["editor_birth"].'</td>';
		echo '<td>'.$language["editor_date"].' - '.$language["editor_place"].'</td><td><input type="text" name="pers_birth_date" value="'.date_show($persoon->pers_birth_date).'" size="'.$veld_datum.'"> <input type="text" name="pers_birth_place" value="'.$persoon->pers_birth_place.'" size="'.$veld_plaats.'"></td></tr>';
		echo '<tr><td>'.$language["source_source"].'</td><td>';
			source_edit($persoon->pers_birth_source,'pers_birth_source');
		echo '</td></tr>';
		echo '<tr><td>'.$language["editor_text"].'</td><td><textarea rows="1" name="pers_birth_text" '.$veld_tekst.'>'.
			text_show($persoon->pers_birth_text).'</textarea>';
		echo '</td></tr>';

		// *** Doop ***
		echo '<tr><td rowspan="4">'.$language["editor_baptise"].'</td>';
		echo '<td>'.$language["editor_date"].' - '.$language["editor_place"].'</td><td><input type="text" name="pers_bapt_date" value="'.date_show($persoon->pers_bapt_date).'" size="'.$veld_datum.'"> <input type="text" name="pers_bapt_place" value="'.$persoon->pers_bapt_place.'" size="'.$veld_plaats.'"></td></tr>';
		echo '<tr><td>'.$language["editor_religion"].'</td><td><input type="text" name="religie" value="'.$persoon->pers_religion.'" size="20"></td></tr>';
		echo '<tr><td>'.$language["source_source"].'</td><td>';
			source_edit($persoon->pers_bapt_source,'pers_bapt_source');
		echo '</td></tr>';
		echo '<tr><td>'.$language["editor_text"].'</td><td><textarea rows="1" name="pers_bapt_text" '.$veld_tekst.'>'.
			text_show($persoon->pers_bapt_text).'</textarea>';
		echo '</td></tr>';

		// *** Overlijden ***
		echo '<tr><td rowspan="4">'.$language["editor_died"].'</td>';
		echo '<td>'.$language["editor_date"].' - '.$language["editor_place"].'</td><td><input type="text" name="pers_death_date" value="'.date_show($persoon->pers_death_date).'" size="'.$veld_datum.'"> <input type="text" name="pers_death_place" value="'.$persoon->pers_death_place.'" size="'.$veld_plaats.'"></td></tr>';
		echo '<tr><td>'.$language["editor_cause"].'</td><td>';
		echo '<select size="1" name="pers_death_cause">';
			echo '<option value=""></option>';
			$selected=''; if ($persoon->pers_death_cause=='murdered'){ $selected=' SELECTED'; }
			echo '<option value="murdered"'.$selected.'>'.$language["pers_murdered"].'</option>';

			$selected=''; if ($persoon->pers_death_cause=='drowned'){ $selected=' SELECTED'; }
			echo '<option value="drowned"'.$selected.'>'.$language["pers_drowned"].'</option>';

			$selected=''; if ($persoon->pers_death_cause=='perished'){ $selected=' SELECTED'; }
			echo '<option value="perished"'.$selected.'>'.$language["pers_perished"].'</option>';

			$selected=''; if ($persoon->pers_death_cause=='killed in action'){ $selected=' SELECTED'; }
			echo '<option value="killed in action"'.$selected.'>'.$language["pers_killed_in_action"].'</option>';

			$selected=''; if ($persoon->pers_death_cause=='being missed'){ $selected=' SELECTED'; }
			echo '<option value="being missed"'.$selected.'>'.$language["pers_being_missed"].'</option>';

			$selected=''; if ($persoon->pers_death_cause=='committed suicide'){ $selected=' SELECTED'; }
			echo '<option value="committed suicide"'.$selected.'>'.$language["pers_committed_suicide"].'</option>';

			$selected=''; if ($persoon->pers_death_cause=='executed'){ $selected=' SELECTED'; }
			echo '<option value="executed"'.$selected.'>'.$language["pers_executed"].'</option>';

			$selected=''; if ($persoon->pers_death_cause=='died young'){ $selected=' SELECTED'; }
			echo '<option value="died young"'.$selected.'>'.$language["pers_died_young"].'</option>';

			$selected=''; if ($persoon->pers_death_cause=='died unmarried'){ $selected=' SELECTED'; }
			echo '<option value="died unmarried"'.$selected.'>'.$language["pers_died_unmarried"].'</option>';

			$selected=''; if ($persoon->pers_death_cause=='registration'){ $selected=' SELECTED'; }
			echo '<option value="registration"'.$selected.'>'.$language["pers_death_registration"].'</option>';

			$selected=''; if ($persoon->pers_death_cause=='declared death'){ $selected=' SELECTED'; }
			echo '<option value="declared death"'.$selected.'>'.$language["pers_declared_death"].'</option>';
		echo '</select>';
		echo '</td></tr>';
		echo '<tr><td>'.$language["source_source"].'</td><td>';
			source_edit($persoon->pers_death_source,'pers_death_source');
		echo '</td></tr>';
		echo '<tr><td>'.$language["editor_text"].'</td><td><textarea rows="1" name="pers_death_text" '.
			$veld_tekst.'>'.text_show($persoon->pers_death_text).'</textarea>';
		echo '</td></tr>';

		// *** Begraven ***
		echo '<tr><td rowspan="3">'.$language["editor_burial"].'</td>';
		echo '<td>'.$language["editor_date"].' - '.$language["editor_place"].'</td><td><input type="text" name="pers_buried_date" value="'.date_show($persoon->pers_buried_date).'" size="'.$veld_datum.'"> <input type="text" name="pers_buried_place" value="'.$persoon->pers_buried_place.'" size="'.$veld_plaats.'"></td></tr>';
		echo '<tr><td>'.$language["source_source"].'</td><td>';
			source_edit($persoon->pers_buried_source,'pers_buried_source');
		echo '</td></tr>';
		echo '<tr><td>'.$language["editor_text"].'</td>';
		echo '<td><textarea rows="1" name="pers_buried_text" '.$veld_tekst.'>'.
			text_show($persoon->pers_buried_text).'</textarea></td></tr>';
		echo '<tr><td>'.$language["editor_burial2"].'/<br>'.$language["editor_burial3"].'</td><td></td><td>';
			$selected=''; if ($persoon->pers_cremation==''){ $selected=' CHECKED'; }
			echo '<input type="radio" name="pers_cremation" value=""'.$selected.'> '.$language["editor_burial2"];
			$selected=''; if ($persoon->pers_cremation=='1'){ $selected=' CHECKED'; }
			echo ' <input type="radio" name="pers_cremation" value="1"'.$selected.'> '.$language["editor_burial3"];
		echo '</td></tr>';

		echo '<tr><td>'.$language["admin_change"].'</td><td colspan="2"><input type="Submit" name="submit" value="'.$language["admin_change"].'"></td></tr>';
		echo '</table>';
		echo '</form>';
	}

	// *******************************
	// *** Show person data events ***
	// *******************************
	if ($menu_admin=='person_data_list'){

		// *** Picture list for selecting pictures ***
		$datasql = mysql_query("SELECT * FROM humo_trees WHERE tree_prefix='".$tree_prefix."'",$db);
		$dataDb=mysql_fetch_object($datasql);
		$PAD=$dataDb->tree_pict_path;
		$dir='../'.$PAD;
		if (file_exists($dir)){
			$dh  = opendir($dir);
			while (false !== ($filename = readdir($dh))) {
				if (substr($filename,0,6)!='thumb_' AND $filename!='.' AND $filename!='..'){
					$picture_array[]=$filename;
				}
			}
		}
		// *** Order pictures by alphabet ***
		@sort($picture_array);
		$nr_pictures=count($picture_array);

		// *** Show/ edit living places ***
		$editor_cls->living_place();

		if (isset($_POST['person_event_add'])){
			// *** Generate new order number ***
			$event_sql="SELECT * FROM ".$tree_prefix."events
				WHERE event_person_id='".$person."' AND event_kind='".$_POST["soort_vermelding"]."'
				ORDER BY event_order DESC LIMIT 0,1";
			$event_qry=mysql_query($event_sql,$db);
			$eventDb=mysql_fetch_object($event_qry);
			$event_order=0;
			if (isset($eventDb->event_order)){
				$event_order=$eventDb->event_order;
			}
			$event_order++;

			$sql="INSERT INTO ".$tree_prefix."events SET
				event_person_id='".$person."',
				event_kind='".$_POST["soort_vermelding"]."',
				event_order='".$event_order."',
				event_new_date='".$datum."',
				event_new_time='".$tijd."'";
			$result=mysql_query($sql) or die(mysql_error());
		}

		if (isset($_POST['person_event_change'])){

			// *** Upload photo ***
			if (isset($_FILES['photo_upload']) AND $_FILES['photo_upload']['name']){
			if ( $_FILES['photo_upload']['type']=="image/pjpeg" || $_FILES['photo_upload']['type']=="image/jpeg"){
				$fout="";
				// 100000=100kb.
				if($_FILES['photo_upload']['size']>2000000){
					$fout=$language["editor_photo_too_large"];
				}
				if (!$fout){
					$pad_afbeelding=$dir.$_FILES['photo_upload']['name'];        //ORIGINEEL
					$pad_thumb=$dir.'thumb_'.$_FILES['photo_upload']['name'];     //THUMB

					if (!move_uploaded_file($_FILES['photo_upload']['tmp_name'],$pad_afbeelding)){
						echo $language["editor_upload_failed"];
					}
					else{
						// *** Resize uploaded picture ***
						if (strtolower(substr($pad_afbeelding, -3)) == "jpg"){
							//Breedte en hoogte origineel bepalen
							list($width, $height) = getimagesize($pad_afbeelding);
						
							$thumb_height=120;
							$newheight=$thumb_height;
							$factor=$height/$newheight;
							$newwidth=$width/$factor;						

							$thumb = imagecreatetruecolor($newwidth, $newheight);
							$source = imagecreatefromjpeg($pad_afbeelding);

							// Resize
							imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
							@imagejpeg($thumb, $pad_thumb);
						}

						$_POST['tekst_vermelding']=$_FILES['photo_upload']['name'];

						// *** Add picture to array ***
						$picture_array[]=$_FILES['photo_upload']['name'];

						// *** Re-order pictures by alphabet ***
						@sort($picture_array);
						$nr_pictures=count($picture_array);
					}
				}
				else{
					print "<FONT COLOR=red>$fout</FONT>";
				}
			}
			else{		
				echo '<FONT COLOR=red>'.$language["editor_no_jpg"].'</font>';
			}
			}


			$bron=veilig($_POST["bron"]);
			if (isset($_POST["bron2"]) AND $_POST["bron2"]!=''){ $bron=veilig($_POST["bron2"]); }

			$event_event=text_process($_POST["tekst_vermelding"]);
			if (isset($_POST["tekst_vermelding2"]) AND $_POST["tekst_vermelding2"]!=''){ $event_event=text_process($_POST["tekst_vermelding2"]); }

			$sql="UPDATE ".$tree_prefix."events SET
			event_event='".$event_event."',
			event_date='".date_process(veilig($_POST["datum"]))."',
			event_source='".$bron."',
			event_place='".text_process($_POST["plaats"])."',
			event_changed_date='".$datum."', ";
			if (isset($_POST["event_gedcom"])){
				$sql.="event_gedcom='".text_process($_POST["event_gedcom"])."',";
			}
			if (isset($_POST["tekst"])){
				$sql.="event_text='".text_process($_POST["tekst"])."',";
			}
			$sql.=" event_changed_time='".$tijd."'";
			$sql.=" WHERE event_id='".veilig($_POST["person_event_change"])."'";
			$result=mysql_query($sql) or die(mysql_error());

			family_tree_update($tree_prefix);
		}

		// *** Remove event ***
		if (isset($_GET['person_event_drop'])){
			echo '<div class="confirm">';
			echo $language["editor_remove_event_warning"];
			echo ' <form method="post" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
			echo '<input type="hidden" name="page" value="'.$_GET['page'].'">';
			echo '<input type="hidden" name="event_kind" value="'.$_GET['event_kind'].'">';
			echo '<input type="hidden" name="person_event_drop" value="'.$_GET['person_event_drop'].'">';
			echo ' <input type="Submit" name="person_event_drop2" value="'.$language["admin_yes"].'" style="color : red; font-weight: bold;">';
			echo ' <input type="Submit" name="submit" value="'.$language["admin_no"].'" style="color : blue; font-weight: bold;">';
			echo '</form>';
			echo '</div>';
		}
		if (isset($_POST['person_event_drop2'])){
			$event_kind=veilig($_POST['event_kind']);
			$event_order_id=veilig($_POST['person_event_drop']);

			$sql="DELETE FROM ".$tree_prefix."events
				WHERE event_person_id='".$person."' AND event_kind='".$event_kind."' AND event_order='".$event_order_id."'";
			$result=mysql_query($sql) or die(mysql_error());

			$event_sql="SELECT * FROM ".$tree_prefix."events
				WHERE event_person_id='".$person."' AND event_kind='".$event_kind."' AND event_order>'".$event_order_id."' ORDER BY event_order";
			$event_qry=mysql_query($event_sql,$db);
			while($eventDb=mysql_fetch_object($event_qry)){
				$sql="UPDATE ".$tree_prefix."events SET
				event_order='".($eventDb->event_order-1)."',
				event_changed_date='".$datum."',
				event_changed_time='".$tijd."'
				WHERE event_id='".$eventDb->event_id."'";
				$result=mysql_query($sql) or die(mysql_error());
			}
		}

		if (isset($_GET['person_event_down'])){
			$event_kind=veilig($_GET['event_kind']);
			$event_order=veilig($_GET["person_event_down"]);

			$sql="UPDATE ".$tree_prefix."events SET event_order='99'
			WHERE event_person_id='".$person."'
			AND event_kind='".$event_kind."'
			AND event_order='".$event_order."'";
			$result=mysql_query($sql) or die(mysql_error());

			$sql="UPDATE ".$tree_prefix."events SET event_order='".$event_order."'
			WHERE event_person_id='".$person."'
			AND event_kind='".$event_kind."'
			AND event_order='".($event_order+1)."'";
			$result=mysql_query($sql) or die(mysql_error());

			$sql="UPDATE ".$tree_prefix."events SET event_order='".($event_order+1)."'
			WHERE event_person_id='".$person."'
			AND event_kind='".$event_kind."'
			AND event_order=99";
			$result=mysql_query($sql) or die(mysql_error());
		}

		if (isset($_GET['person_event_up'])){
			$event_kind=veilig($_GET['event_kind']);
			$event_order=veilig($_GET["person_event_up"]);

			$sql="UPDATE ".$tree_prefix."events SET
			event_order='99'
			WHERE event_person_id='".$person."'
			AND event_kind='".$event_kind."'
			AND event_order='".$event_order."'";
			$result=mysql_query($sql) or die(mysql_error());

			$sql="UPDATE ".$tree_prefix."events SET
			event_order='".$event_order."'
			WHERE event_person_id='".$person."'
			AND event_kind='".$event_kind."'
			AND event_order='".($event_order-1)."'";
			$result=mysql_query($sql) or die(mysql_error());

			$sql="UPDATE ".$tree_prefix."events SET
			event_order='".($event_order-1)."'
			WHERE event_person_id='".$person."'
			AND event_kind='".$event_kind."'
			AND event_order=99";
			$result=mysql_query($sql) or die(mysql_error());
		}

		echo '<p><table class="humo standaard" border="1">';
		print '<tr class="tabel_kop"><th>'.$language["groups_option"].'</th><th colspan="2">'.$language["groups_value"].'</th></tr>';

		$data_list_qry=mysql_query("SELECT * FROM ".$tree_prefix."events
			WHERE event_person_id='$person' ORDER BY event_kind, event_order",$db);
		while($data_listDb=mysql_fetch_object($data_list_qry)){
			echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data">';
			echo '<input type="hidden" name="page" value="'.$page.'">';
			echo '<input type="hidden" name="person_event_change" value="'.$data_listDb->event_id.'">';

			// *** Hide text field ***
			$regels=3;
			if ($data_listDb->event_kind!='beroep' AND $data_listDb->event_kind!='bron' AND $data_listDb->event_kind!='adres'){ $regels=4; }

			echo '<tr><td rowspan="'.$regels.'">';

				echo ' <a href="index.php?page='.$page.'&amp;event_kind='.$data_listDb->event_kind.'&amp;person_event_drop='.
				  $data_listDb->event_order.'"><img src="images/button_drop.png" border="0" alt="down"></a>';

				// *** Count number of events ***
				$count_event=mysql_query("SELECT * FROM ".$tree_prefix."events
				  WHERE event_person_id='$person' AND event_kind='".$data_listDb->event_kind."'",$db);
				$count=mysql_num_rows($count_event);

				if ($data_listDb->event_order<$count){
				  echo ' <a href="index.php?page='.$page.'&amp;person_event_down='.$data_listDb->event_order.'&amp;event_kind='.$data_listDb->event_kind.'"><img src="images/pijl-laag.gif" border="0" alt="down"></a>';
				}
				else{
				  echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
				}

				if ($data_listDb->event_order>1){
				  echo ' <a href="index.php?page='.$page.'&amp;person_event_up='.$data_listDb->event_order.'&amp;event_kind='.$data_listDb->event_kind.'"><img src="images/pijl-hoog.gif" border="0" alt="down"></a>';
				}
				else{
				  echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
				}

				if ($data_listDb->event_kind=='adres'){ echo $language["editor_address"].'<br>'; }
				elseif ($data_listDb->event_kind=='afbeelding'){ echo $language["editor_picture"].'<br>'; }
				elseif ($data_listDb->event_kind=='beroep'){ echo $language["editor_profession"].'<br>'; }
				elseif ($data_listDb->event_kind=='bron'){ echo $language["source_source"].'<br>'; }
				elseif ($data_listDb->event_kind=='gebeurtenis'){ echo $language["editor_event"].'<br>'; }
				elseif ($data_listDb->event_kind=='geboorteaangifte'){ echo $language["editor_birth_declaration"].'<br>'; }
				elseif ($data_listDb->event_kind=='doopgetuige'){ echo $language["editor_baptwitness"].'<br>'; }
				elseif ($data_listDb->event_kind=='overlijdensaangifte'){ echo $language["editor_death_declaration"].'<br>'; }
				elseif ($data_listDb->event_kind=='begrafenisgetuige'){ echo $language["editor_burial_witness"].'<br>'; }
				elseif ($data_listDb->event_kind=='naam'){ echo $language["editor_name"].'<br>'; }
				elseif ($data_listDb->event_kind=='predikaat'){ echo $language["editor_nobility"].'<br>'; }
				elseif ($data_listDb->event_kind=='titel'){ echo $language["editor_title"].'<br>'; }
				elseif ($data_listDb->event_kind=='heerlijkheid'){ echo $language["editor_lordship"].'<br>'; }
				else { echo ucfirst($data_listDb->event_kind).'<br>'; }

				if ($data_listDb->event_kind=='gebeurtenis'){
					echo '<select size="1" name="event_gedcom" style="width: 150px">';
					//$selected=''; if ($data_listDb->event_gedcom=='EVEN'){ $selected=' SELECTED'; }
					//echo '<option value="EVEN"'.$selected.'>'.$language["EVEN"].'</option>';
					event_option($data_listDb->event_gedcom,'EVEN');
					event_option($data_listDb->event_gedcom,'ARVL');
					event_option($data_listDb->event_gedcom,'BAPM');
					event_option($data_listDb->event_gedcom,'DPRT');
					event_option($data_listDb->event_gedcom,'LEGI');
					event_option($data_listDb->event_gedcom,'MILI');
					event_option($data_listDb->event_gedcom,'SLGL');
					event_option($data_listDb->event_gedcom,'TXPY');
					event_option($data_listDb->event_gedcom,'ADOP');
					event_option($data_listDb->event_gedcom,'_ADPF');
					event_option($data_listDb->event_gedcom,'_ADPM');
					event_option($data_listDb->event_gedcom,'BAPL');
					event_option($data_listDb->event_gedcom,'BARM');
					event_option($data_listDb->event_gedcom,'BASM');
					event_option($data_listDb->event_gedcom,'BLES');
					event_option($data_listDb->event_gedcom,'CENS');
					event_option($data_listDb->event_gedcom,'CHRA');
					event_option($data_listDb->event_gedcom,'CONF');
					event_option($data_listDb->event_gedcom,'CONL');
					event_option($data_listDb->event_gedcom,'EMIG');
					event_option($data_listDb->event_gedcom,'ENDL');
					event_option($data_listDb->event_gedcom,'FCOM');
					event_option($data_listDb->event_gedcom,'_FNRL');
					event_option($data_listDb->event_gedcom,'GRAD');
					event_option($data_listDb->event_gedcom,'IMMI');
					event_option($data_listDb->event_gedcom,'NATU');
					event_option($data_listDb->event_gedcom,'ORDN');
					event_option($data_listDb->event_gedcom,'PROB');
					event_option($data_listDb->event_gedcom,'RETI');
					event_option($data_listDb->event_gedcom,'SLGC');
					event_option($data_listDb->event_gedcom,'WILL');
					event_option($data_listDb->event_gedcom,'_YART');
					event_option($data_listDb->event_gedcom,'_INTE');
					event_option($data_listDb->event_gedcom,'_BRTM');
					event_option($data_listDb->event_gedcom,'_NMAR');
					event_option($data_listDb->event_gedcom,'NCHI');
					event_option($data_listDb->event_gedcom,'EDUC');
					event_option($data_listDb->event_gedcom,'NATI');
					event_option($data_listDb->event_gedcom,'CAST');
					event_option($data_listDb->event_gedcom,'AFN');
					event_option($data_listDb->event_gedcom,'SSN');
					event_option($data_listDb->event_gedcom,'IDNO');
					event_option($data_listDb->event_gedcom,'_HEIG');
					event_option($data_listDb->event_gedcom,'_WEIG');
					event_option($data_listDb->event_gedcom,'_EYEC');
					event_option($data_listDb->event_gedcom,'_HAIR');
					event_option($data_listDb->event_gedcom,'_MEDC');
					event_option($data_listDb->event_gedcom,'PROP');
					echo '</select>';
				}

				if ($data_listDb->event_kind=='naam'){
					echo '<select size="1" name="event_gedcom" style="width: 150px">';

					$event='_AKAN'; $selected=''; if ($data_listDb->event_gedcom==$event){ $selected=' SELECTED'; }
					echo '<option value="'.$event.'"'.$selected.'>'.$language['name_AKAN'].'</option>';

					$event='NICK'; $selected=''; if ($data_listDb->event_gedcom==$event){ $selected=' SELECTED'; }
					echo '<option value="'.$event.'"'.$selected.'>'.$language['name_NICK'].'</option>';

					$event='_ALIA'; $selected=''; if ($data_listDb->event_gedcom==$event){ $selected=' SELECTED'; }
					echo '<option value="'.$event.'"'.$selected.'>'.$language['name_ALIA'].'</option>';

					$event='_SHON'; $selected=''; if ($data_listDb->event_gedcom==$event){ $selected=' SELECTED'; }
					echo '<option value="'.$event.'"'.$selected.'>'.$language['name_SHON'].'</option>';

					$event='_ADPN'; $selected=''; if ($data_listDb->event_gedcom==$event){ $selected=' SELECTED'; }
					echo '<option value="'.$event.'"'.$selected.'>'.$language['name_ADPN'].'</option>';

					$event='_HEBN'; $selected=''; if ($data_listDb->event_gedcom==$event){ $selected=' SELECTED'; }
					echo '<option value="'.$event.'"'.$selected.'>'.$language['name_HEBN'].'</option>';

					$event='_CENN'; $selected=''; if ($data_listDb->event_gedcom==$event){ $selected=' SELECTED'; }
					echo '<option value="'.$event.'"'.$selected.'>'.$language['name_CENN'].'</option>';

					$event='_MARN'; $selected=''; if ($data_listDb->event_gedcom==$event){ $selected=' SELECTED'; }
					echo '<option value="'.$event.'"'.$selected.'>'.$language['name_MARN'].'</option>';

					$event='_GERN'; $selected=''; if ($data_listDb->event_gedcom==$event){ $selected=' SELECTED'; }
					echo '<option value="'.$event.'"'.$selected.'>'.$language['name_GERN'].'</option>';

					$event='_FARN'; $selected=''; if ($data_listDb->event_gedcom==$event){ $selected=' SELECTED'; }
					echo '<option value="'.$event.'"'.$selected.'>'.$language['name_FARN'].'</option>';

					$event='_BIRN'; $selected=''; if ($data_listDb->event_gedcom==$event){ $selected=' SELECTED'; }
					echo '<option value="'.$event.'"'.$selected.'>'.$language['name_BIRN'].'</option>';

					$event='_INDN'; $selected=''; if ($data_listDb->event_gedcom==$event){ $selected=' SELECTED'; }
					echo '<option value="'.$event.'"'.$selected.'>'.$language['name_INDN'].'</option>';

					$event='_FKAN'; $selected=''; if ($data_listDb->event_gedcom==$event){ $selected=' SELECTED'; }
					echo '<option value="'.$event.'"'.$selected.'>'.$language['name_FKAN'].'</option>';

					$event='_CURN'; $selected=''; if ($data_listDb->event_gedcom==$event){ $selected=' SELECTED'; }
					echo '<option value="'.$event.'"'.$selected.'>'.$language['name_CURN'].'</option>';

					$event='_SLDN'; $selected=''; if ($data_listDb->event_gedcom==$event){ $selected=' SELECTED'; }
					echo '<option value="'.$event.'"'.$selected.'>'.$language['name_SLDN'].'</option>';

					$event='_RELN'; $selected=''; if ($data_listDb->event_gedcom==$event){ $selected=' SELECTED'; }
					echo '<option value="'.$event.'"'.$selected.'>'.$language['name_RELN'].'</option>';

					$event='_OTHN'; $selected=''; if ($data_listDb->event_gedcom==$event){ $selected=' SELECTED'; }
					echo '<option value="'.$event.'"'.$selected.'>'.$language['name_OTHN'].'</option>';

					$event='_FRKA'; $selected=''; if ($data_listDb->event_gedcom==$event){ $selected=' SELECTED'; }
					echo '<option value="'.$event.'"'.$selected.'>'.$language['name_FRKA'].'</option>';

					echo '</select>';
				}

				if ($data_listDb->event_kind=='afbeelding'){
					$duim='';
					if (file_exists('../'.$PAD.'thumb_'.$data_listDb->event_event)){ $duim='thumb_'; }

					//if(substr($PAD.$data_listDb->event_event,-3,3)=="pdf") {
					$extensions_check=substr($PAD.$data_listDb->event_event,-3,3);
					if($extensions_check=="pdf") {
						echo '<a href="../'.$PAD.$data_listDb->event_event.'"><img src="../images/pdf.jpeg"></a>';
					}

					// *** Show AVI Video file ***
					elseif($extensions_check=="avi") {
						echo '<a href="'.$PAD.$data_listDb->event_event.'" target="_blank"><img src="../images/video-file.png"></a>';
					}
					// *** Show WMV Video file ***
					elseif($extensions_check=="wmv") {
						echo '<a href="'.$PAD.$data_listDb->event_event.'" target="_blank"><img src="../images/video-file.png"></a>';
					}
					// *** Show MPG Video file ***
					elseif($extensions_check=="mpg") {
						echo '<a href="'.$PAD.$data_listDb->event_event.'" target="_blank"><img src="../images/video-file.png"></a>';
					}
					// *** Show MOV Video file ***
					elseif($extensions_check=="mov") {
						echo '<a href="'.$PAD.$data_listDb->event_event.'" target="_blank"><img src="../images/video-file.png"></a>';
					}			

					else{
						//echo '<img src="../'.$PAD.$duim.strtolower($data_listDb->event_event).'" width="100px"></a>';
						//echo '<img src="../'.$PAD.$duim.$data_listDb->event_event.'" width="100px"></a>';
						echo '<img src="../'.$PAD.$duim.$data_listDb->event_event.'" width="100px">';
					}
				}

			echo '</td>';

			echo '<td>'.$language["editor_date"].' - '.$language["editor_place"].'</td><td><input type="text" name="datum" value="'.date_show($data_listDb->event_date).'" size="'.$veld_datum.'"> <input type="text" name="plaats" value="'.$data_listDb->event_place.'" size="'.$veld_datum.'">';
			echo '&nbsp;&nbsp;&nbsp; '.$language["admin_change"].': <BUTTON TYPE="submit" name="submit" title="submit" class="knop"><img src="images/submit.gif" width="16"></BUTTON>';
			echo '</td></tr>';
			if ($data_listDb->event_kind=='bron'){
				echo '<tr><td>'.$language["editor_event_sourcerole"].'</td>';
			}
			elseif ($data_listDb->event_kind=='adres'){
				echo '<tr><td>'.$language["editor_event_addressrole"].'</td>';
			}
			else{
				echo '<tr><td>'.ucfirst($data_listDb->event_kind).'</td>';
			}

			// *** Getuigen en aangifte personen ***
			if ($data_listDb->event_kind=='doopgetuige' OR $data_listDb->event_kind=='geboorteaangifte' OR
			$data_listDb->event_kind=='overlijdensaangifte' OR $data_listDb->event_kind=='begrafenisgetuige'){
				echo '<td>';
				witness_edit($data_listDb->event_event);
			}

			elseif ($data_listDb->event_kind=='afbeelding'){
				// *** Show pull-down list pictures ***
				echo '<td><select size="1" name="tekst_vermelding">';
				echo '<option value=""></option>';
				for ($picture_nr=0; $picture_nr<$nr_pictures; $picture_nr++){
					$selected=''; if ($picture_array[$picture_nr]==$data_listDb->event_event){ $selected=' SELECTED'; }
					echo '<option value="'.$picture_array[$picture_nr].'"'.$selected.'>'.$picture_array[$picture_nr].'</option>';
				}
				echo '</select>';

				echo ' <b>'.$language["admin_or"].' upload (max. size 2 MB):</b>';
				echo ' <input type="file" name="photo_upload">';			
			}

			else{
				echo '<td><input type="text" name="tekst_vermelding" value="'.$data_listDb->event_event.'" size="60">';
			}

			if ($data_listDb->event_kind=='bron'){ echo ' '.$language["editor_event_kind_source"]; }
			elseif ($data_listDb->event_kind=='adres'){ echo ' '.$language["editor_event_kind_address"]; }
			elseif ($data_listDb->event_kind=='predikaat'){ echo ' '.$language["editor_event_kind_nobility"]; }
			elseif ($data_listDb->event_kind=='titel'){ echo ' '.$language["editor_event_kind_title"]; }
			elseif ($data_listDb->event_kind=='heerlijkheid'){
				echo ' '.$language["editor_event_kind_lordship"];
			}

			echo '</td></tr>';

			if ($data_listDb->event_kind=='adres'){
				echo '<tr><td>Adres</td><td>';
			}
			else{
				echo '<tr><td>'.$language["source_source"].'</td><td>';
			}

			if ($data_listDb->event_kind=='adres'){
// Voorlopig ADRESSEN alleen tonen als er een gedcom nummer staat...
				//$adresqry=mysql_query("SELECT * FROM ".$tree_prefix."addresses",$db);
				$adresqry=mysql_query("SELECT * FROM ".$tree_prefix."addresses WHERE address_gedcomnr LIKE '_%'
				  ORDER BY address_place, address_address",$db);
				echo '<select size="1" name="bron">';
				echo '<option value=""></option>';
				while ($adresDb=mysql_fetch_object($adresqry)){
				  $selected='';
				  if (substr($data_listDb->event_source,1,-1)==$adresDb->address_gedcomnr){ $selected=' SELECTED'; }
				  echo '<option value="@'.$adresDb->address_gedcomnr.'@"'.$selected.'>'.
				    @$adresDb->address_place.', '.$adresDb->address_address.' ['.@$adresDb->address_gedcomnr.']</option>';
				}
				echo '</select>';
			}
			else{
				// *** Edit source ***
				source_edit($data_listDb->event_source,'bron');
			}

			echo '</td></tr>';

			if ($data_listDb->event_kind!='beroep'
				AND $data_listDb->event_kind!='bron' AND $data_listDb->event_kind!='adres'){
				echo '<tr><td>'.$language["editor_text"].'</td><td><textarea rows="1" name="tekst" '.$veld_tekst.'>'.
				text_show($data_listDb->event_text).'</textarea></td></tr>';
			}

			//echo '<tr><td>'.$language["admin_change"].'</td><td><BUTTON TYPE="submit" name="submit" title="submit" class="knop"><img src="images/submit.gif" width="16"></BUTTON></td></tr>';

			echo '</form>';
		}
		
		echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
			echo '<input type="hidden" name="page" value="'.$page.'">';
			echo '<tr bgcolor="#CCFFFF"><td>'.$language["admin_add"].'</td><td colspan="2">';

			echo '<select size="1" name="soort_vermelding">';
			echo '<option value="adres">'.$language["editor_address"].'</option>';
			echo '<option value="afbeelding">'.$language["editor_picture"].'</option>';
			echo '<option value="beroep">'.$language["editor_profession"].'</option>';
			echo '<option value="bron">'.$language["source_source"].'</option>';
			echo '<option value="gebeurtenis">'.$language["editor_event"].'</option>';
			echo '<option value="geboorteaangifte">'.$language["editor_birth_declaration"].'</option>';
			echo '<option value="doopgetuige">'.$language["editor_baptwitness"].'</option>';
			echo '<option value="overlijdensaangifte">'.$language["editor_death_declaration"].'</option>';
			echo '<option value="begrafenisgetuige">'.$language["editor_burial_witness"].'</option>';
			echo '<option value="naam">'.$language["editor_name"].'</option>';
			echo '<option value="predikaat">'.$language["editor_nobility"].'</option>';
			echo '<option value="titel">'.$language["editor_title"].'</option>';
			echo '<option value="heerlijkheid">'.$language["editor_lordship"].'</option>';
			echo '</select>';

			echo' <input type="Submit" name="person_event_add" value="'.$language["editor_event_add"].'"></td><tr>';
		echo '</form>';

		echo '</table>';
	}

	// *** Marriage ***
	if (isset($_POST['marriage_add'])){
		// *** Generate new gedcomnr, find highest gedcomnummer F100: strip F and order by numeric ***
		$new_nr_qry= "SELECT *, ABS(substring(fam_gedcomnumber, 2)) AS gednr
			FROM ".$tree_prefix."family ORDER BY gednr DESC LIMIT 0,1";
		$new_nr_result = mysql_query($new_nr_qry,$db);
		$new_nr=mysql_fetch_object($new_nr_result);
		$new_gedcomnummer='F1';
		if (isset($new_nr->fam_gedcomnumber)){
			$new_gedcomnummer='F'.(substr($new_nr->fam_gedcomnumber,1)+1);
		}

		$fam_relation_source=veilig($_POST["fam_relation_source"]);
		if ($_POST["fam_relation_source2"]!=''){ $fam_relation_source=veilig($_POST["fam_relation_source2"]); }

		$fam_marr_notice_source=veilig($_POST["fam_marr_notice_source"]);
		if ($_POST["fam_marr_notice_source2"]!=''){ $fam_marr_notice_source=veilig($_POST["fam_marr_notice_source2"]); }

		$fam_marr_source=veilig($_POST["fam_marr_source"]);
		if ($_POST["fam_marr_source2"]!=''){ $fam_marr_source=veilig($_POST["fam_marr_source2"]); }

		$fam_marr_church_source=veilig($_POST["fam_marr_church_source"]);
		if ($_POST["fam_marr_church_source2"]!=''){ $fam_marr_church_source=veilig($_POST["fam_marr_church_source2"]); }

		$fam_marr_church_notice_source=veilig($_POST["fam_marr_church_notice_source"]);
		if ($_POST["fam_marr_church_notice_source2"]!=''){ $fam_marr_church_notice_source=veilig($_POST["fam_marr_church_notice_source2"]); }

		$fam_div_source=veilig($_POST["fam_div_source"]);
		if ($_POST["fam_div_source2"]!=''){ $fam_div_source=veilig($_POST["fam_div_source2"]); }

		$sql="INSERT INTO ".$tree_prefix."family SET
		fam_gedcomnumber='".$new_gedcomnummer."',
		fam_kind='".veilig($_POST["soort"])."',
		fam_man='".veilig($_POST["connect_man"])."',
		fam_woman='".veilig($_POST["connect_vrouw"])."',
		fam_relation_date='".date_process(veilig($_POST["fam_relation_date"]))."',
		fam_relation_place='".text_process($_POST["fam_relation_place"])."',
		fam_relation_text='".text_process($_POST["fam_relation_text"],true)."',
		fam_relation_source='".$fam_relation_source."',
		fam_marr_notice_date='".date_process(veilig($_POST["fam_marr_notice_date"]))."',
		fam_marr_notice_place='".text_process($_POST["fam_marr_notice_place"])."',
		fam_marr_notice_text='".text_process($_POST["fam_marr_notice_text"],true)."',
		fam_marr_notice_source='".$fam_marr_notice_source."',
		fam_marr_date='".date_process(veilig($_POST["fam_marr_date"]))."',
		fam_marr_place='".text_process($_POST["fam_marr_place"])."',
		fam_marr_text='".text_process($_POST["fam_marr_text"],true)."',
		fam_marr_source='".$fam_marr_source."',
		fam_marr_authority='".veilig($_POST["fam_marr_authority"])."',
		fam_marr_church_date='".date_process(veilig($_POST["fam_marr_church_date"]))."',
		fam_marr_church_place='".text_process($_POST["fam_marr_church_place"])."',
		fam_marr_church_text='".text_process($_POST["fam_marr_church_text"],true)."',
		fam_marr_church_source='".$fam_marr_church_source."',
		fam_marr_church_notice_date='".date_process(veilig($_POST["fam_marr_church_notice_date"]))."',
		fam_marr_church_notice_place='".text_process($_POST["fam_marr_church_notice_place"])."',
		fam_marr_church_notice_text='".text_process($_POST["fam_marr_church_notice_text"],true)."',
		fam_marr_church_notice_source='".$fam_marr_church_notice_source."',
		fam_religion='".veilig($_POST["religie"])."',
		fam_div_date='".date_process(veilig($_POST["fam_div_date"]))."',
		fam_div_place='".text_process($_POST["fam_div_place"])."',
		fam_div_text='".text_process($_POST["fam_div_text"],true)."',
		fam_div_source='".$fam_div_source."',
		fam_div_authority='".veilig($_POST["fam_div_authority"])."',
		fam_text='".text_process($_POST["fam_text"],true)."',
		fam_new_date='".$datum."',
		fam_new_time='".$tijd."'";
		$result=mysql_query($sql) or die(mysql_error());

		// *** Add marriage to person records MAN and WOMAN ***
		$man_qry= "SELECT * FROM ".$tree_prefix."person WHERE pers_gedcomnumber='".veilig($_POST['connect_man'])."'";
		$man_result = mysql_query($man_qry,$db);
		if ($man_result){
			$man_db=mysql_fetch_object($man_result);
			$fams=$man_db->pers_fams;
			if ($fams){
				$fams1=explode(";",$fams); $pers_indexnr=$fams1[0];
				$fams.=';'.$new_gedcomnummer;
			}
			else{
				$pers_indexnr=$new_gedcomnummer;
				$fams=$new_gedcomnummer;
			}
			$sql="UPDATE ".$tree_prefix."person SET
				pers_fams='".$fams."',
				pers_indexnr='".$pers_indexnr."',
				pers_changed_date='".$datum."',
				pers_changed_time='".$tijd."'
				WHERE pers_id='".$man_db->pers_id."'";
			$result=mysql_query($sql) or die(mysql_error());
		}

		$vrouw_qry= "SELECT * FROM ".$tree_prefix."person WHERE pers_gedcomnumber='".veilig($_POST['connect_vrouw'])."'";
		$vrouw_result = mysql_query($vrouw_qry,$db);
		if ($vrouw_result){
			$vrouw_db=mysql_fetch_object($vrouw_result);
			$fams=$vrouw_db->pers_fams;
			if ($fams){
				$fams1=explode(";",$fams); $pers_indexnr=$fams1[0];
				$fams.=';'.$new_gedcomnummer;
			}
			else{
				$pers_indexnr=$new_gedcomnummer;
				 $fams=$new_gedcomnummer;
			}
			$sql="UPDATE ".$tree_prefix."person SET
				pers_fams='".$fams."',
				pers_indexnr='".$pers_indexnr."',
				pers_changed_date='".$datum."',
				pers_changed_time='".$tijd."'
				WHERE pers_id='".$vrouw_db->pers_id."'";
			$result=mysql_query($sql) or die(mysql_error());
		}

		// *** Show new family ***
		$_POST['marriage_nr']=$new_gedcomnummer;

		// *** Select new connected person ***
		if (veilig($_POST["connect_vrouw"])){ $person=veilig($_POST["connect_vrouw"]); }
		if (veilig($_POST["connect_man"])){ $person=veilig($_POST["connect_man"]); }
		$persoon_qry= "SELECT * FROM ".$tree_prefix."person WHERE pers_gedcomnumber='".$person."'";
		$persoon_result = mysql_query($persoon_qry,$db);
		$persoon=mysql_fetch_object($persoon_result);

		family_tree_update($tree_prefix);
	}

	if ($menu_admin=='marriage' AND $persoon->pers_fams){
		// *** Switch parents ***
		if (isset($_POST['parents_switch'])){
			$sql="UPDATE ".$tree_prefix."family SET
			fam_man='".veilig($_POST["connect_vrouw"])."',
			fam_woman='".veilig($_POST["connect_man"])."'
			WHERE fam_gedcomnumber='".veilig($_POST['marriage'])."'";
			$result=mysql_query($sql) or die(mysql_error());
		}

		if (isset($_POST['marriage_change'])){
			$fam_relation_source=veilig($_POST["fam_relation_source"]);
			if ($_POST["fam_relation_source2"]!=''){ $fam_relation_source=veilig($_POST["fam_relation_source2"]); }

			$fam_marr_notice_source=veilig($_POST["fam_marr_notice_source"]);
			if ($_POST["fam_marr_notice_source2"]!=''){ $fam_marr_notice_source=veilig($_POST["fam_marr_notice_source2"]); }

			$fam_marr_source=veilig($_POST["fam_marr_source"]);
			if ($_POST["fam_marr_source2"]!=''){ $fam_marr_source=veilig($_POST["fam_marr_source2"]); }

			$fam_marr_church_source=veilig($_POST["fam_marr_church_source"]);
			if ($_POST["fam_marr_church_source2"]!=''){ $fam_marr_church_source=veilig($_POST["fam_marr_church_source2"]); }

			$fam_marr_church_notice_source=veilig($_POST["fam_marr_church_notice_source"]);
			if ($_POST["fam_marr_church_notice_source2"]!=''){ $fam_marr_church_notice_source=veilig($_POST["fam_marr_church_notice_source2"]); }

			$fam_div_source=veilig($_POST["fam_div_source"]);
			if ($_POST["fam_div_source2"]!=''){ $fam_div_source=veilig($_POST["fam_div_source2"]); }

			$sql="UPDATE ".$tree_prefix."family SET
			fam_kind='".veilig($_POST["soort"])."',
			fam_man='".veilig($_POST["connect_man"])."',
			fam_woman='".veilig($_POST["connect_vrouw"])."',
			fam_relation_date='".date_process(veilig($_POST["fam_relation_date"]))."',
			fam_relation_end_date='".date_process(veilig($_POST["fam_relation_end_date"]))."',
			fam_relation_place='".text_process($_POST["fam_relation_place"])."',
			fam_relation_text='".text_process($_POST["fam_relation_text"],true)."',
			fam_relation_source='".$fam_relation_source."',
			fam_marr_notice_date='".date_process(veilig($_POST["fam_marr_notice_date"]))."',
			fam_marr_notice_place='".text_process($_POST["fam_marr_notice_place"])."',
			fam_marr_notice_text='".text_process($_POST["fam_marr_notice_text"],true)."',
			fam_marr_notice_source='".$fam_marr_notice_source."',
			fam_marr_date='".date_process(veilig($_POST["fam_marr_date"]))."',
			fam_marr_place='".text_process($_POST["fam_marr_place"])."',
			fam_marr_text='".text_process($_POST["fam_marr_text"],true)."',
			fam_marr_source='".$fam_marr_source."',
			fam_marr_authority='".veilig($_POST["fam_marr_authority"])."',
			fam_marr_church_date='".date_process(veilig($_POST["fam_marr_church_date"]))."',
			fam_marr_church_place='".text_process($_POST["fam_marr_church_place"])."',
			fam_marr_church_text='".text_process($_POST["fam_marr_church_text"],true)."',
			fam_marr_church_source='".$fam_marr_church_source."',
			fam_marr_church_notice_date='".date_process(veilig($_POST["fam_marr_church_notice_date"]))."',
			fam_marr_church_notice_place='".text_process($_POST["fam_marr_church_notice_place"])."',
			fam_marr_church_notice_text='".text_process($_POST["fam_marr_church_notice_text"],true)."',
			fam_marr_church_notice_source='".$fam_marr_church_notice_source."',
			fam_religion='".veilig($_POST["religie"])."',
			fam_div_date='".date_process(veilig($_POST["fam_div_date"]))."',
			fam_div_place='".text_process($_POST["fam_div_place"])."',
			fam_div_text='".text_process($_POST["fam_div_text"],true)."',
			fam_div_source='".$fam_div_source."',
			fam_div_authority='".veilig($_POST["fam_div_authority"])."',
			fam_text='".text_process($_POST["fam_text"],true)."',
			fam_changed_date='".$datum."',
			fam_changed_time='".$tijd."'
			WHERE fam_gedcomnumber='".veilig($_POST['marriage'])."'";
			$result=mysql_query($sql) or die(mysql_error());

			family_tree_update($tree_prefix);
		}
	}

	// ***********************
	// *** Select marriage ***
	// ***********************
	if (($menu_admin=='marriage' OR $menu_admin=='marriage_data_list') AND !isset($_GET['add_marriage']) ) {
		echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
		echo '<input type="hidden" name="page" value="'.$page.'">';

		if ($persoon->pers_fams){
			echo '<br>'.$language["editor_marriage"].': ';
			$fams1=explode(";",$persoon->pers_fams);
			$marriage=$fams1[0];
			if (isset($_POST['marriage_nr'])){ $marriage=$_POST['marriage_nr']; }
			print '<select size="1" name="marriage_nr">';
			for ($i=0; $i<=substr_count($persoon->pers_fams, ";"); $i++){
				$gezin=mysql_query("SELECT * FROM ".$tree_prefix."family
				  WHERE fam_gedcomnumber='".$fams1[$i]."'",$db);
				$gezinDb=mysql_fetch_object($gezin);
				$selected=''; if ($marriage==$gezinDb->fam_gedcomnumber){ $selected=' SELECTED'; }
				echo '<option value="'.$gezinDb->fam_gedcomnumber.'"'.$selected.'>'.
				show_person($gezinDb->fam_man).' '.$language["editor_and"].' '.show_person($gezinDb->fam_woman).' ['.$gezinDb->fam_gedcomnumber.']</option>';
			}
			echo '</select>';
			echo ' <input type="Submit" name="submit" value="'.$language["admin_select"].'">';
		}
		//else{
		//  echo ' <input type="hidden" name="marriage_nr" value="0">';
		//}
		echo '</form>';
	}

	// **************************
	// *** Show marriage data ***
	// **************************
	if (($menu_admin=='marriage' AND $persoon->pers_fams) OR isset($_GET['add_marriage'])){
		echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
		echo '<input type="hidden" name="page" value="'.$page.'">';

		echo '<table class="humo standaard" border="1">';
		print '<tr class="tabel_kop"><th>'.$language["groups_option"].'</th><th colspan="2">'.$language["groups_value"].'</th></tr>';

		// *** Search for own family ***
		//$fams1=explode(";",$persoon->pers_fams);
		//for ($i=0; $i<=substr_count($persoon->pers_fams, ";"); $i++){
		//  $gezin=mysql_query("SELECT * FROM ".$tree_prefix."family
		//  WHERE fam_gedcomnumber='".$fams1[$i]."'",$db);

		if (isset($_GET['add_marriage'])){
			$man=''; $vrouw='';
			$soort='';
			$fam_relation_date=''; $fam_relation_end_date=''; $fam_relation_place=''; $fam_relation_source=''; $fam_relation_text='';
			$fam_marr_notice_date=''; $fam_marr_notice_place=''; $fam_marr_notice_source=''; $fam_marr_notice_text='';
			$fam_marr_date=''; $fam_marr_place=''; $fam_marr_source=''; $fam_marr_text=''; $fam_marr_authority='';
			$fam_marr_church_notice_date=''; $fam_marr_church_notice_place=''; $fam_marr_church_notice_source=''; $fam_marr_church_notice_text='';
			$fam_marr_church_date=''; $fam_marr_church_place=''; $fam_marr_church_source=''; $fam_marr_church_text='';
			$religie='';
			$fam_div_date=''; $fam_div_place=''; $fam_div_source=''; $fam_div_text=''; $fam_div_authority='';
			$fam_text='';

			// *** If a new wedding is added, already show the latest selected person ***
			if (isset($person)){
				$qry= "SELECT * FROM ".$tree_prefix."person WHERE pers_gedcomnumber='".$person."'";
				$result = mysql_query($qry,$db);
				if ($sexe=='F'){ $vrouw=$person;	}
					else{ $man=$person; }
			}

		}
		else{
			$gezin=mysql_query("SELECT * FROM ".$tree_prefix."family
				WHERE fam_gedcomnumber='".$marriage."'",$db);
			$gezinDb=mysql_fetch_object($gezin);
			$soort=$gezinDb->fam_kind;
			$man=$gezinDb->fam_man; $vrouw=$gezinDb->fam_woman;
			$fam_relation_date=date_show($gezinDb->fam_relation_date); $fam_relation_end_date=date_show($gezinDb->fam_relation_end_date);
			$fam_relation_place=$gezinDb->fam_relation_place; $fam_relation_source=$gezinDb->fam_relation_source; $fam_relation_text=text_show($gezinDb->fam_relation_text);
			$fam_marr_notice_date=date_show($gezinDb->fam_marr_notice_date); $fam_marr_notice_place=$gezinDb->fam_marr_notice_place; $fam_marr_notice_source=$gezinDb->fam_marr_notice_source;
			$fam_marr_notice_text=text_show($gezinDb->fam_marr_notice_text);
			$fam_marr_date=date_show($gezinDb->fam_marr_date); $fam_marr_place=$gezinDb->fam_marr_place; $fam_marr_source=$gezinDb->fam_marr_source;
			$fam_marr_text=text_show($gezinDb->fam_marr_text); $fam_marr_authority=text_show($gezinDb->fam_marr_authority);
			$fam_marr_church_notice_date=date_show($gezinDb->fam_marr_church_notice_date); $fam_marr_church_notice_place=$gezinDb->fam_marr_church_notice_place;
			$fam_marr_church_notice_source=$gezinDb->fam_marr_church_notice_source; $fam_marr_church_notice_text=text_show($gezinDb->fam_marr_church_notice_text);
			$fam_marr_church_date=date_show($gezinDb->fam_marr_church_date); $fam_marr_church_place=$gezinDb->fam_marr_church_place; $fam_marr_church_source=$gezinDb->fam_marr_church_source;
			$fam_marr_church_text=text_show($gezinDb->fam_marr_church_text);
			$religie=$gezinDb->fam_religion;
			$fam_div_date=date_show($gezinDb->fam_div_date); $fam_div_place=$gezinDb->fam_div_place;
			$fam_div_source=$gezinDb->fam_div_source; $fam_div_text=text_show($gezinDb->fam_div_text);
			$fam_div_authority=text_show($gezinDb->fam_div_authority);
			$fam_text=text_show($gezinDb->fam_text);
		}

		echo '<tr><td><b>'.$language["editor_marriage"].'</b></td><td colspan="2">';

		echo show_person($man);
		echo ' '.$language["editor_and"].' ';
		echo show_person($vrouw).'<br>';

		print '<select size="1" name="connect_man" style="width: 250px">';
		echo '<option value=""></option>';
		$persoon_qry= "SELECT * FROM ".$tree_prefix."person ORDER BY pers_lastname, pers_firstname";
		$persoon_result = mysql_query($persoon_qry,$db);
		while ($persoon=mysql_fetch_object($persoon_result)){
			$selected='';
			if (isset($man)){
				if ($persoon->pers_gedcomnumber==$man){ $selected=' SELECTED'; }
			}
			echo '<option value="'.$persoon->pers_gedcomnumber.'"'.$selected.'>'.
				$persoon->pers_lastname.', '.$persoon->pers_firstname.' '.strtolower(str_replace("_"," ",$persoon->pers_prefix)).' ['.$persoon->pers_gedcomnumber.']</option>';
		}
		echo '</select>';

		echo ' '.$language["editor_and"].' ';

		print '<select size="1" name="connect_vrouw" style="width: 250px">';
		echo '<option value=""></option>';
		$persoon_qry= "SELECT * FROM ".$tree_prefix."person ORDER BY pers_lastname, pers_firstname";
		$persoon_result = mysql_query($persoon_qry,$db);
		while ($persoon=mysql_fetch_object($persoon_result)){
			$selected='';
			if (isset($vrouw)){
				if ($persoon->pers_gedcomnumber==$vrouw){ $selected=' SELECTED'; }
			}
			echo '<option value="'.$persoon->pers_gedcomnumber.'"'.$selected.'>'.
				$persoon->pers_lastname.', '.$persoon->pers_firstname.' '.strtolower(str_replace("_"," ",$persoon->pers_prefix)).' ['.$persoon->pers_gedcomnumber.']</option>';
		}
		echo '</select>';

		if (!isset($_GET['add_marriage'])){
			echo ' <BUTTON TYPE="submit" name="parents_switch" title="Switch Persons" class="knop"><img src="images/turn_around.gif" width="17"></BUTTON>';
		}

		echo '</td></tr>';

		// *** $marriage is leeg bij losse personen ***
		if (isset($marriage)){
			echo '<input type="hidden" name="marriage" value="'.$marriage.'">';
		}
		echo '<tr><td>'.$language["editor_type"].'</td><td></td><td>';
		echo '<select size="1" name="soort">';
			echo '<option value="">'.$language["fam_married"].'</option>';

			$selected=''; if ($soort=='living together'){ $selected=' SELECTED'; }
			echo '<option value="living together"'.$selected.'>'.$language["fam_living_together"].'</option>';

			$selected=''; if ($soort=='living apart together'){ $selected=' SELECTED'; }
			echo '<option value="living apart together"'.$selected.'>'.$language["fam_living_apart_together"].'</option>';

			$selected=''; if ($soort=='intentionally unmarried mother'){ $selected=' SELECTED'; }
			echo '<option value="intentionally unmarried mother"'.$selected.'>'.$language["fam_intentionally unmarried mother"].'</option>';

			$selected=''; if ($soort=='homosexual'){ $selected=' SELECTED'; }
			echo '<option value="homosexual"'.$selected.'>'.$language["fam_homosexual"].'</option>';

			$selected=''; if ($soort=='non-marital'){ $selected=' SELECTED'; }
			echo '<option value="non-marital"'.$selected.'>'.$language["fam_non_marital"].'</option>';

			$selected=''; if ($soort=='extramarital'){ $selected=' SELECTED'; }
			echo '<option value="extramarital"'.$selected.'>'.$language["fam_extramarital"].'</option>';

			$selected=''; if ($soort=='partners'){ $selected=' SELECTED'; }
			echo '<option value="partners"'.$selected.'>'.$language["fam_partners"].'</option>';

			$selected=''; if ($soort=='registered'){ $selected=' SELECTED'; }
			echo '<option value="registered"'.$selected.'>'.$language["fam_registered"].'</option>';
			
			$selected=''; if ($soort=='unknown'){ $selected=' SELECTED'; }
			echo '<option value="unknown"'.$selected.'>'.$language["fam_unknown_relation"].'</option>';

		echo '</select>';
		echo '</td></tr>';

		// *** Samenwonen ***
		echo '<tr><td rowspan="3">'.$language["fam_living_together"].'</td>';
		echo '<td>'.$language["editor_date"].' - '.$language["editor_place"].'</td><td><input type="text" name="fam_relation_date" value="'.$fam_relation_date.'" size="'.$veld_datum.'"> <input type="text" name="fam_relation_place" value="'.$fam_relation_place.'" size="'.$veld_plaats.'"></td></tr>';
		echo '<tr><td>'.$language["source_source"].'</td><td>';
			source_edit($fam_relation_source,'fam_relation_source');
		echo '</td></tr>';
		echo '<tr><td>'.$language["editor_text"].'</td><td><textarea rows="1" name="fam_relation_text" '.$veld_tekst.'>'.$fam_relation_text.'</textarea></td></tr>';

		// *** Einde samenwonen ***
		echo '<tr><td>'.$language["fam_living_together"].'</td>';
		//echo '<td>'.$language["editor_date"].' - '.$language["editor_place"].'</td><td><input type="text" name="fam_relation_date" value="'.$fam_relation_date.'" size="'.$veld_datum.'"> <input type="text" name="fam_relation_place" value="'.$fam_relation_place.'" size="'.$veld_plaats.'"></td></tr>';
		echo '<td>'.$language["editor_enddate"].'</td><td><input type="text" name="fam_relation_end_date" value="'.$fam_relation_end_date.'" size="'.$veld_datum.'"></td></tr>';
		//echo '<tr><td>'.$language["source_source"].'</td><td>';
		//	source_edit($fam_relation_source,'fam_relation_source');
		//echo '</td></tr>';
		//echo '<tr><td>'.$language["editor_text"].'</td><td><textarea rows="1" name="fam_relation_text" '.$veld_tekst.'>'.$fam_relation_text.'</textarea></td></tr>';

		// *** Ondertrouw ***
		echo '<tr><td rowspan="3">'.$language["editor_marriage_notice"].'</td>';
		echo '<td>'.$language["editor_date"].' - '.$language["editor_place"].'</td><td><input type="text" name="fam_marr_notice_date" value="'.$fam_marr_notice_date.'" size="'.$veld_datum.'"> <input type="text" name="fam_marr_notice_place" value="'.$fam_marr_notice_place.'" size="'.$veld_plaats.'"></td></tr>';
		echo '<tr><td>'.$language["source_source"].'</td><td>';
		source_edit($fam_marr_notice_source,'fam_marr_notice_source');
		echo '</td></tr>';
		echo '<tr><td>'.$language["editor_text"].'</td><td><textarea rows="1" name="fam_marr_notice_text" '.$veld_tekst.'>'.$fam_marr_notice_text.'</textarea></td></tr>';

		// *** Huwelijk ***
		echo '<tr><td rowspan="4">'.$language["editor_marriage"].'</td>';
		echo '<td>'.$language["editor_date"].' - '.$language["editor_place"].'</td><td><input type="text" name="fam_marr_date" value="'.$fam_marr_date.'" size="'.$veld_datum.'"> <input type="text" name="fam_marr_place" value="'.$fam_marr_place.'" size="'.$veld_plaats.'"></td></tr>';
		echo '<tr><td>'.$language["editor_registrar"].'</td><td><input type="text" name="fam_marr_authority" value="'.$fam_marr_authority.'" size="60"></td></tr>';
		echo '<tr><td>'.$language["source_source"].'</td><td>';
		source_edit($fam_marr_source,'fam_marr_source');
		echo '</td></tr>';
		echo '<tr><td>'.$language["editor_text"].'</td><td><textarea rows="1" name="fam_marr_text" '.$veld_tekst.'>'.$fam_marr_text.'</textarea></td></tr>';

		// *** Kerk ondertrouw ***
		echo '<tr><td rowspan="3">'.$language["editor_prenuptial"].'</td>';
		echo '<td>'.$language["editor_date"].' - '.$language["editor_place"].'</td><td><input type="text" name="fam_marr_church_notice_date" value="'.$fam_marr_church_notice_date.'" size="'.$veld_datum.'"> <input type="text" name="fam_marr_church_notice_place" value="'.$fam_marr_church_notice_place.'" size="'.$veld_plaats.'"></td></tr>';
		echo '<tr><td>'.$language["source_source"].'</td><td>';
		source_edit($fam_marr_church_notice_source,'fam_marr_church_notice_source');
		echo '</td></tr>';
		echo '<tr><td>'.$language["editor_text"].'</td><td><textarea rows="1" name="fam_marr_church_notice_text" '.$veld_tekst.'>'.$fam_marr_church_notice_text.'</textarea></td></tr>';

		// *** Kerk huwelijk ***
		echo '<tr><td rowspan="3">'.$language["editor_churchmarriage"].'</td>';
		echo '<td>'.$language["editor_date"].' - '.$language["editor_place"].'</td><td><input type="text" name="fam_marr_church_date" value="'.$fam_marr_church_date.'" size="'.$veld_datum.'"> <input type="text" name="fam_marr_church_place" value="'.$fam_marr_church_place.'" size="'.$veld_plaats.'"></td></tr>';
		echo '<tr><td>'.$language["source_source"].'</td><td>';
		source_edit($fam_marr_church_source,'fam_marr_church_source');
		echo '</td></tr>';
		echo '<tr><td>'.$language["editor_text"].'</td><td><textarea rows="1" name="fam_marr_church_text" '.$veld_tekst.'>'.$fam_marr_church_text.'</textarea></td></tr>';

		// *** Religion ***
		echo '<tr><td rowspan="1">'.$language["editor_religion"].'</td>';
		echo '<td>'.$language["editor_religion"].'</td><td><input type="text" name="religie" value="'.$religie.'" size="60"></td></tr>';

		// *** Scheiding ***
		echo '<tr><td rowspan="4">'.$language["editor_divorce"].'</td>';
		echo '<td>'.$language["editor_date"].' - '.$language["editor_place"].'</td><td><input type="text" name="fam_div_date" value="'.$fam_div_date.'" size="'.$veld_datum.'"> <input type="text" name="fam_div_place" value="'.$fam_div_place.'" size="'.$veld_plaats.'"></td></tr>';
		echo '<tr><td>'.$language["editor_registrar"].'</td><td><input type="text" name="fam_div_authority" value="'.$fam_div_authority.'" size="60"></td></tr>';
		echo '<tr><td>'.$language["source_source"].'</td><td>';
		source_edit($fam_div_source,'fam_div_source');
		echo '</td></tr>';
		echo '<tr><td>'.$language["editor_text"].'</td><td><textarea rows="1" name="fam_div_text" '.$veld_tekst.'>'.$fam_div_text.'</textarea></td></tr>';

		echo '<tr><td>'.$language["editor_text"].'</td>';
		echo '<td colspan="2"><textarea rows="1" name="fam_text" style="height: 120px; width:700px">'.$fam_text.'</textarea></td></tr>';

		if (isset($_GET['add_marriage'])){
			echo '<tr><td>'.$language["admin_add"].'</td><td colspan="2"><input type="Submit" name="marriage_add" value="'.$language["admin_add"].'"></td></tr>';
		}
		else{
			echo '<tr><td>'.$language["admin_change"].'</td><td colspan="2"><input type="Submit" name="marriage_change" value="'.$language["admin_change"].'"></td></tr>';
		}

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

	// *********************************
	// *** Show marriage data events ***
	// *********************************
	if ($menu_admin=='marriage_data_list' AND $persoon->pers_fams){

		if (isset($_POST['marriage_event_add'])){
			// *** Generate new order number ***
			$event_sql="SELECT * FROM ".$tree_prefix."events
				WHERE event_family_id='".$marriage."' AND event_kind='".$_POST["soort_vermelding"]."'
				ORDER BY event_order DESC LIMIT 0,1";
			$event_qry=mysql_query($event_sql,$db);
			$eventDb=mysql_fetch_object($event_qry);
			$event_order=0;
			if (isset($eventDb->event_order)){
				$event_order=$eventDb->event_order;
			}
			$event_order++;

			$sql="INSERT INTO ".$tree_prefix."events SET
				event_family_id='".$marriage."',
				event_kind='".$_POST["soort_vermelding"]."',
		 event_order='".$event_order."',
				event_new_date='".$datum."',
				event_new_time='".$tijd."'";
			$result=mysql_query($sql) or die(mysql_error());
		}

		if (isset($_POST['marriage_event_change'])){
			$bron=veilig($_POST["bron"]);
			if (isset($_POST["bron2"]) AND $_POST["bron2"]!=''){ $bron=veilig($_POST["bron2"]); }

			$event_event=text_process($_POST["tekst_vermelding"]);
			if (isset($_POST["tekst_vermelding2"]) AND $_POST["tekst_vermelding2"]!=''){ $event_event=text_process($_POST["tekst_vermelding2"]); }

			$sql="UPDATE ".$tree_prefix."events SET
			event_event='".$event_event."',";
			if (isset($_POST["event_gedcom"])){
				$sql.="event_gedcom='".veilig($_POST["event_gedcom"])."',";
			}
			$sql.="event_date='".date_process(veilig($_POST["datum"]))."',
			event_source='".$bron."',
			event_place='".text_process($_POST["plaats"])."',
			event_changed_date='".$datum."',
			event_changed_time='".$tijd."'";
			if (isset($_POST["tekst"])){
				$sql.=", event_text='".text_process($_POST["tekst"])."'";
			}
			$sql.=" WHERE event_id='".veilig($_POST["marriage_event_id"])."'";
			$result=mysql_query($sql) or die(mysql_error());

			family_tree_update($tree_prefix);
		}

		// *** Remove event ***
		if (isset($_GET['family_event_drop'])){
			echo '<div class="confirm">';

			echo $language["editor_remove_event_warning"].' ';
			echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
			echo '<input type="hidden" name="page" value="'.$_GET['page'].'">';
			echo '<input type="hidden" name="event_kind" value="'.$_GET['event_kind'].'">';
			echo '<input type="hidden" name="family_event_drop" value="'.$_GET['family_event_drop'].'">';
			echo ' <input type="Submit" name="family_event_drop2" value="'.$language["admin_yes"].'" style="color : red; font-weight: bold;">';
			echo ' <input type="Submit" name="submit" value="'.$language["admin_no"].'" style="color : blue; font-weight: bold;">';
			echo '</form>';
			echo '</div>';
		}
		if (isset($_POST['family_event_drop2'])){
			$event_kind=veilig($_POST['event_kind']);
			$event_order_id=veilig($_POST['family_event_drop']);

			$sql="DELETE FROM ".$tree_prefix."events
				WHERE event_family_id='".$marriage."' AND event_kind='".$event_kind."'
				AND event_order='".$event_order_id."'";
			$result=mysql_query($sql) or die(mysql_error());

			$event_sql="SELECT * FROM ".$tree_prefix."events
				WHERE event_family_id='".$marriage."' AND event_kind='".$event_kind."'
				AND event_order>'".$event_order_id."' ORDER BY event_order";
			$event_qry=mysql_query($event_sql,$db);
			while($eventDb=mysql_fetch_object($event_qry)){
				$sql="UPDATE ".$tree_prefix."events SET
				event_order='".($eventDb->event_order-1)."',
				event_changed_date='".$datum."',
				event_changed_time='".$tijd."'
				WHERE event_id='".$eventDb->event_id."'";
				$result=mysql_query($sql) or die(mysql_error());
			}
		}

		if (isset($_GET['family_event_down'])){
			$event_kind=veilig($_GET['event_kind']);
			$event_order=veilig($_GET["family_event_down"]);

			$sql="UPDATE ".$tree_prefix."events SET event_order='99'
			WHERE event_family_id='".$marriage."'
			AND event_kind='".$event_kind."'
			AND event_order='".$event_order."'";
			$result=mysql_query($sql) or die(mysql_error());

			$sql="UPDATE ".$tree_prefix."events SET event_order='".$event_order."'
			WHERE event_family_id='".$marriage."'
			AND event_kind='".$event_kind."'
			AND event_order='".($event_order+1)."'";
			$result=mysql_query($sql) or die(mysql_error());

			$sql="UPDATE ".$tree_prefix."events SET event_order='".($event_order+1)."'
			WHERE event_family_id='".$marriage."'
			AND event_kind='".$event_kind."'
			AND event_order=99";
			$result=mysql_query($sql) or die(mysql_error());
		}

		if (isset($_GET['family_event_up'])){
			$event_kind=veilig($_GET['event_kind']);
			$event_order=veilig($_GET["family_event_up"]);

			$sql="UPDATE ".$tree_prefix."events SET
			event_order='99'
			WHERE event_family_id='".$marriage."'
			AND event_kind='".$event_kind."'
			AND event_order='".$event_order."'";
			$result=mysql_query($sql) or die(mysql_error());

			$sql="UPDATE ".$tree_prefix."events SET
			event_order='".$event_order."'
			WHERE event_family_id='".$marriage."'
			AND event_kind='".$event_kind."'
			AND event_order='".($event_order-1)."'";
			$result=mysql_query($sql) or die(mysql_error());

			$sql="UPDATE ".$tree_prefix."events SET
			event_order='".($event_order-1)."'
			WHERE event_family_id='".$marriage."'
			AND event_kind='".$event_kind."'
			AND event_order=99";
			$result=mysql_query($sql) or die(mysql_error());
		}

		echo '<table class="humo standaard" border="1">';
		print '<tr class="tabel_kop"><th>'.$language["groups_option"].'</th><th colspan="2">'.$language["groups_value"].'</th></tr>';

		$data_list_qry=mysql_query("SELECT * FROM ".$tree_prefix."events
			WHERE event_family_id='$marriage' ORDER BY event_kind, event_order",$db);
		while($data_listDb=mysql_fetch_object($data_list_qry)){
			echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
			echo '<input type="hidden" name="page" value="'.$page.'">';
			echo '<input type="hidden" name="marriage_nr" value="'.$marriage.'">';
			echo '<input type="hidden" name="marriage_event_id" value="'.$data_listDb->event_id.'">';

			echo '<tr><td rowspan="4">';

				echo ' <a href="index.php?page='.$page.'&amp;event_kind='.$data_listDb->event_kind.'&amp;family_event_drop='.
				  $data_listDb->event_order.'"><img src="images/button_drop.png" border="0" alt="down"></a>';

				// *** Count number of events ***
				$count_event=mysql_query("SELECT * FROM ".$tree_prefix."events
				  WHERE event_family_id='$marriage' AND event_kind='".$data_listDb->event_kind."'",$db);
				$count=mysql_num_rows($count_event);

				if ($data_listDb->event_order<$count){
				  echo ' <a href="index.php?page='.$page.'&amp;family_event_down='.$data_listDb->event_order.'&amp;event_kind='.$data_listDb->event_kind.'"><img src="images/pijl-laag.gif" border="0" alt="down"></a>';
				}
				else{
				  echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
				}

				if ($data_listDb->event_order>1){
				  echo ' <a href="index.php?page='.$page.'&amp;family_event_up='.$data_listDb->event_order.'&amp;event_kind='.$data_listDb->event_kind.'"><img src="images/pijl-hoog.gif" border="0" alt="down"></a>';

				}
				else{
				  echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
				}

				if ($data_listDb->event_kind=='gebeurtenis'){ echo $language['editor_event'].'<br>'; }
				elseif ($data_listDb->event_kind=='trgetuige'){ echo $language['editor_marriage_witness'].'<br>'; }
				elseif ($data_listDb->event_kind=='kerktrgetuige'){ echo $language['editor_marriage_witness_rel'].'<br>'; }
				else { echo $data_listDb->event_kind.'<br>'; }

				if ($data_listDb->event_kind=='gebeurtenis'){
				  echo '<select size="1" name="event_gedcom" style="width: 150px">';
				    event_option($data_listDb->event_gedcom,'EVEN');
				    event_option($data_listDb->event_gedcom,'_MBON');
				    event_option($data_listDb->event_gedcom,'MARC');
				    event_option($data_listDb->event_gedcom,'MARL');
				    event_option($data_listDb->event_gedcom,'MARS');
				    event_option($data_listDb->event_gedcom,'DIVF');
				    event_option($data_listDb->event_gedcom,'ANUL');
				    event_option($data_listDb->event_gedcom,'ENGA');
				    event_option($data_listDb->event_gedcom,'SLGS');
				  echo '</select>';
				}
			echo '</td>';

			echo '<td>'.$language["editor_date"].' - '.$language["editor_place"].'</td><td><input type="text" name="datum" value="'.date_show($data_listDb->event_date).'" size="'.$veld_datum.'"> <input type="text" name="plaats" value="'.$data_listDb->event_place.'" size="'.$veld_datum.'">';
			echo '&nbsp;&nbsp;&nbsp; '.$language["admin_change"].': <BUTTON TYPE="submit" name="marriage_event_change" title="submit" class="knop"><img src="images/submit.gif" width="16"></BUTTON>';
			echo '</td></tr>';

			//echo '<tr><td>Tekst gebeurtenis</td>';
			echo '<tr><td>'.ucfirst($data_listDb->event_kind).'</td>';

			// *** Getuigen en aangifte personen ***
			if ($data_listDb->event_kind=='trgetuige' OR $data_listDb->event_kind=='kerktrgetuige'){
				echo '<td>';
				witness_edit($data_listDb->event_event);
			}
			else{
				echo '<td><input type="text" name="tekst_vermelding" value="'.$data_listDb->event_event.'" size="60">';
			}

			echo '<tr><td>'.$language["source_source"].'</td><td>';
			source_edit($data_listDb->event_source,'bron');
			echo '</td></tr>';

			echo '<tr><td>'.$language["editor_text"].'</td><td><textarea rows="1" name="tekst" '.$veld_tekst.'>'.
				text_show($data_listDb->event_text).'</textarea></td></tr>';

			echo '</form>';
		}

		echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
		echo '<input type="hidden" name="page" value="'.$page.'">';
		echo '<input type="hidden" name="marriage_nr" value="'.$marriage.'">';
		echo '<tr bgcolor="#CCFFFF"><td>'.$language["admin_add"].'</td><td colspan="2">';
			echo '<select size="1" name="soort_vermelding">';
			//echo '<option value="adres">Adres</option>';
			//echo '<option value="afbeelding">Afbeelding</option>';
			//echo '<option value="bron">'.$language["source_source"].'</option>';
			echo '<option value="gebeurtenis">'.$language["editor_event"].'</option>';
			echo '<option value="trgetuige">'.$language["editor_marriage_witness"].'</option>';
			echo '<option value="kerktrgetuige">'.$language["editor_marriage_witness_rel"].'</option>';
			echo '</select>';
		echo ' <input type="Submit" name="marriage_event_add" value="'.$language["editor_event_add"].'"></td><tr>';
		echo '</table>';
		echo '</form>';
	}

	// ********************
	// *** Show sources ***
	// ********************
	if ($menu_admin=='sources'){
		if (isset($_POST['source_add'])){
			// *** Generate new gedcomnr, find highest gedcomnummer I100: strip I and order by numeric ***
			$new_nr_qry= "SELECT *, ABS(substring(source_gedcomnr, 2)) AS gednr
				FROM ".$tree_prefix."sources ORDER BY gednr DESC LIMIT 0,1";
			$new_nr_result = mysql_query($new_nr_qry,$db);
			$new_nr=mysql_fetch_object($new_nr_result);

			//$new_gedcomnummer='S'.(substr($new_nr->source_gedcomnr,1)+1);
			$new_gedcomnummer='S1';
			if (isset($new_nr->source_gedcomnr)){
				$new_gedcomnummer='S'.(substr($new_nr->source_gedcomnr,1)+1);
			}

			$sql="INSERT INTO ".$tree_prefix."sources SET
				source_gedcomnr='".$new_gedcomnummer."',
				source_title='".text_process($_POST['source_title'])."',
				source_date='".veilig($_POST['source_date'])."',
				source_place='".text_process($_POST['source_place'])."',
				source_publ='".text_process($_POST['source_publ'])."',
				source_refn='".text_process($_POST['source_refn'])."',
				source_auth='".text_process($_POST['source_auth'])."',
				source_subj='".text_process($_POST['source_subj'])."',
				source_item='".text_process($_POST['source_item'])."',
				source_kind='".text_process($_POST['source_kind'])."',
				source_repo_caln='".text_process($_POST['source_repo_caln'])."',
				source_repo_page='".veilig($_POST['source_repo_page'])."',
				source_text='".text_process($_POST['source_text'])."',
				source_new_date='".$datum."',
				source_new_time='".$tijd."'";
			$result=mysql_query($sql) or die(mysql_error());

			$new_source_qry= "SELECT * FROM ".$tree_prefix."sources ORDER BY source_id DESC LIMIT 0,1";
			$new_source_result = mysql_query($new_source_qry,$db);
			$new_source=mysql_fetch_object($new_source_result);
			$_POST['bron_id']=$new_source->source_id;
		}

		if (isset($_POST['source_change'])){
			$sql="UPDATE ".$tree_prefix."sources SET
			source_title='".text_process($_POST['source_title'])."',
			source_date='".date_process(veilig($_POST['source_date']))."',
			source_place='".text_process($_POST['source_place'])."',
			source_publ='".text_process($_POST['source_publ'])."',
			source_refn='".text_process($_POST['source_refn'])."',
			source_auth='".text_process($_POST['source_auth'])."',
			source_subj='".text_process($_POST['source_subj'])."',
			source_item='".text_process($_POST['source_item'])."',
			source_kind='".text_process($_POST['source_kind'])."',
			source_repo_caln='".text_process($_POST['source_repo_caln'])."',
			source_repo_page='".text_process($_POST['source_repo_page'])."',
			source_text='".text_process($_POST['source_text'],true)."',
			source_changed_date='".$datum."',
			source_changed_time='".$tijd."'
			WHERE source_id='".veilig($_POST["bron_id"])."'";
			$result=mysql_query($sql) or die(mysql_error());

			family_tree_update($tree_prefix);
		}



		if (isset($_POST['source_remove'])){
			echo '<div class="confirm">';
      	echo $language["editor_source_remove"];
			echo ' <form method="post" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
			echo '<input type="hidden" name="page" value="'.$page.'">';
			echo '<input type="hidden" name="bron_id" value="'.$_POST['bron_id'].'">';
			echo ' <input type="Submit" name="source_remove2" value="'.$language["admin_yes"].'" style="color : red; font-weight: bold;">';
			echo ' <input type="Submit" name="submit" value="'.$language["admin_no"].'" style="color : blue; font-weight: bold;">';
			echo '</form>';
			echo '</div>';
		}
		if (isset($_POST['source_remove2'])){
			echo '<div class="confirm">';

			// *** Find gedcomnumber, needed for events query ***
			$bronqry=mysql_query("SELECT * FROM ".$tree_prefix."sources
			WHERE source_id='".veilig($_POST["bron_id"])."'",$db);
			$bronDb=mysql_fetch_object($bronqry);

			// *** Delete source references ***
			$sql="DELETE FROM ".veilig($_SESSION['tree_prefix'])."events
			WHERE	event_kind='bron' AND event_source='@".$bronDb->source_gedcomnr."@'";
			$result=mysql_query($sql,$db);

			// *** Delete person sources ***
			$sql="UPDATE ".veilig($_SESSION['tree_prefix'])."person
			SET pers_name_source='' WHERE pers_name_source='@".$bronDb->source_gedcomnr."@'";
			$result=mysql_query($sql,$db);

			$sql="UPDATE ".veilig($_SESSION['tree_prefix'])."person
			SET pers_birth_source='' WHERE pers_birth_source='@".$bronDb->source_gedcomnr."@'";
			$result=mysql_query($sql,$db);

			$sql="UPDATE ".veilig($_SESSION['tree_prefix'])."person
			SET pers_bapt_source='' WHERE pers_bapt_source='@".$bronDb->source_gedcomnr."@'";
			$result=mysql_query($sql,$db);

			$sql="UPDATE ".veilig($_SESSION['tree_prefix'])."person
			SET pers_death_source='' WHERE pers_death_source='@".$bronDb->source_gedcomnr."@'";
			$result=mysql_query($sql,$db);

			$sql="UPDATE ".veilig($_SESSION['tree_prefix'])."person
			SET pers_buried_source='' WHERE pers_buried_source='@".$bronDb->source_gedcomnr."@'";
			$result=mysql_query($sql,$db);

			// **** Delete family sources ***
			$sql="UPDATE ".veilig($_SESSION['tree_prefix'])."family
			SET fam_relation_source='' WHERE fam_relation_source='@".$bronDb->source_gedcomnr."@'";
			$result=mysql_query($sql,$db);

			$sql="UPDATE ".veilig($_SESSION['tree_prefix'])."family
			SET fam_marr_notice_source='' WHERE fam_marr_notice_source='@".$bronDb->source_gedcomnr."@'";
			$result=mysql_query($sql,$db);

			$sql="UPDATE ".veilig($_SESSION['tree_prefix'])."family
			SET fam_marr_source='' WHERE fam_marr_source='@".$bronDb->source_gedcomnr."@'";
			$result=mysql_query($sql,$db);

			$sql="UPDATE ".veilig($_SESSION['tree_prefix'])."family
			SET fam_marr_church_notice_source='' WHERE fam_marr_church_notice_source='@".$bronDb->source_gedcomnr."@'";
			$result=mysql_query($sql,$db);

			$sql="UPDATE ".veilig($_SESSION['tree_prefix'])."family
			SET fam_marr_church_source='' WHERE fam_marr_church_source='@".$bronDb->source_gedcomnr."@'";
			$result=mysql_query($sql,$db);

			$sql="UPDATE ".veilig($_SESSION['tree_prefix'])."family
			SET fam_div_source='' WHERE fam_div_source='@".$bronDb->source_gedcomnr."@'";
			$result=mysql_query($sql,$db);

			// *** Delete source ***
			$sql="DELETE FROM ".$tree_prefix."sources
			WHERE source_id='".veilig($_POST["bron_id"])."'";
			$result=mysql_query($sql,$db);

			echo $language["editor_source_removed"];

			echo '</div>';
		}

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

		$bronqry=mysql_query("SELECT * FROM ".$tree_prefix."sources ORDER BY source_title",$db);
		echo $language["source_source"].': ';
		echo '<select size="1" name="bron_id">';
		echo '<option value=""></option>'; // *** For new source in new database... ***
		while ($bronDb=mysql_fetch_object($bronqry)){
			$selected='';
			if (isset($_POST['bron_id'])){
				if ($_POST['bron_id']==$bronDb->source_id){$selected=' SELECTED';}
			}
			echo '<option value="'.$bronDb->source_id.'"'.$selected.'>'.@$bronDb->source_title.
				' ['.@$bronDb->source_gedcomnr.']</option>'; 
		}
		echo '</select>';
		echo ' <input type="Submit" name="select_source" value="'.$language["admin_select"].'">';


		echo ' '.$language["admin_or"].': ';
		echo '<input type="Submit" name="add_source" value="'.$language["editor_add_source"].'">';

		echo '</form>';

		// *** Show selected source ***
		if (isset($_POST['bron_id'])){
			echo '<table class="humo standaard" border="1">';
			print '<tr class="tabel_kop"><th>'.$language["groups_option"].'</th><th colspan="2">'.$language["groups_value"].'</th></tr>';

			if (isset($_POST['add_source'])){
				$source_title=''; $source_date=''; $source_place=''; $source_publ=''; $source_refn='';
				$source_auth=''; $source_auth=''; $source_subj=''; $source_item=''; $source_kind='';
				$source_text='';
				$source_repo_caln=''; $source_repo_page='';
			}
			else{
				@$bron=mysql_query("SELECT * FROM ".$tree_prefix."sources
				  WHERE source_id='".veilig($_POST["bron_id"])."'",$db);
				@$bronDb=mysql_fetch_object($bron) or die("Geen geldig bronnummer.");
				$source_title=$bronDb->source_title; $source_date=$bronDb->source_date;
				$source_place=$bronDb->source_place; $source_publ=$bronDb->source_publ;
				$source_refn=$bronDb->source_refn; $source_auth=$bronDb->source_auth;
				$source_auth=$bronDb->source_auth; $source_subj=$bronDb->source_subj;
				$source_item=$bronDb->source_item; $source_kind=$bronDb->source_kind;
				$source_text=$bronDb->source_text;
				$source_repo_caln=$bronDb->source_repo_caln; $source_repo_page=$bronDb->source_repo_page;
			}

			echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
			echo '<input type="hidden" name="page" value="'.$page.'">';
			echo '<input type="hidden" name="bron_id" value="'.$_POST['bron_id'].'">';

			echo '<tr><td>'.$language["source_title"].'</td><td><input type="text" name="source_title" value="'.$source_title.'" size="60"></td></tr>';
			echo '<tr><td>'.$language["source_subject"].'</td><td><input type="text" name="source_subj" value="'.$source_subj.'" size="60"></td></tr>';
			echo '<tr><td>'.$language["editor_date"].' - '.$language["editor_place"].'</td><td><input type="text" name="source_date" value="'.date_show($source_date).'" size="20"> <input type="text" name="source_place" value="'.$source_place.'" size="50"></td></tr>';
			echo '<tr><td>'.$language["source_publication"].'</td><td><input type="text" name="source_publ" value="'.$source_publ.'" size="60"> http://... wordt als een link weergegeven.</td></tr>';
			echo '<tr><td>'.$language["source_own_code"].'</td><td><input type="text" name="source_refn" value="'.$source_refn.'" size="60"></td></tr>';
			echo '<tr><td>'.$language["source_author"].'</td><td><input type="text" name="source_auth" value="'.$source_auth.'" size="60"></td></tr>';
			echo '<tr><td>'.$language["source_nr"].'</td><td><input type="text" name="source_item" value="'.$source_item.'" size="60"></td></tr>';
			echo '<tr><td>'.$language["source_kind"].'</td><td><input type="text" name="source_kind" value="'.$source_kind.'" size="60"></td></tr>';
			echo '<tr><td>'.$language["source_archive"].'</td><td><input type="text" name="source_repo_caln" value="'.$source_repo_caln.'" size="60"></td></tr>';
			echo '<tr><td>'.$language["source_page"].'</td><td><input type="text" name="source_repo_page" value="'.$source_repo_page.'" size="60"></td></tr>';
			echo '<tr><td>'.$language["editor_text"].'</td><td><textarea rows="1" name="source_text" '.$veld_tekst_groot.'>'.
			text_show($source_text).'</textarea></td></tr>';

			if (isset($_POST['add_source'])){
				echo '<tr><td>'.$language["admin_add"].'</td><td><input type="Submit" name="source_add" value="'.$language["admin_add"].'"></td></tr>';
			}
			else{
				echo '<tr><td>'.$language["admin_change"].'</td><td><input type="Submit" name="source_change" value="'.$language["admin_change"].'">';

				echo ' '.$language["admin_or"].' ';
				echo '<input type="Submit" name="source_remove" value="'.$language["admin_remove"].'">';

				echo '</td></tr>';
			}

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

			// *** Source example in IFRAME ***
			if (!isset($_POST['add_source'])){
				echo '<p>'.$language["editor_preview"].'<br>';
				echo '<iframe src ="../source.php?database='.$tree_prefix.'&amp;id='.$bronDb->source_gedcomnr.'" width="100%" height="300">';
				echo '  <p>Your browser does not support iframes.</p>';
				echo '</iframe>';
			}
		}

	}

	// *********************
	// *** Show adresses ***
	// *********************
	if ($menu_admin=='adresses'){
		if (isset($_POST['address_add'])){
			// *** Generate new gedcomnr, find highest gedcomnummer I100: strip I and order by numeric ***
			$new_nr_qry= "SELECT *, ABS(substring(address_gedcomnr, 2)) AS gednr
				FROM ".$tree_prefix."addresses ORDER BY gednr DESC LIMIT 0,1";
			$new_nr_result = mysql_query($new_nr_qry,$db);
			$new_nr=mysql_fetch_object($new_nr_result);
			//$new_gedcomnummer='R'.(substr($new_nr->address_gedcomnr,1)+1);
			$new_gedcomnummer='R1';
			if (isset($new_nr->address_gedcomnr)){
				$new_gedcomnummer='R'.(substr($new_nr->address_gedcomnr,1)+1);
			}

			$sql="INSERT INTO ".$tree_prefix."addresses SET
				address_gedcomnr='".$new_gedcomnummer."',
				address_address='".text_process($_POST['address_address'])."',
				address_date='".veilig($_POST['address_date'])."',
				address_zip='".veilig($_POST['address_zip'])."',
				address_place='".text_process($_POST['address_place'])."',
				address_phone='".veilig($_POST['address_phone'])."',
				address_photo='".veilig($_POST['address_photo'])."',
				address_source='".veilig($_POST['address_source'])."',
				address_text='".text_process($_POST['address_text'])."',
				address_new_date='".$datum."',
				address_new_time='".$tijd."'";
			$result=mysql_query($sql) or die(mysql_error());

			$new_address_qry= "SELECT * FROM ".$tree_prefix."addresses ORDER BY address_id DESC LIMIT 0,1";
			$new_address_result = mysql_query($new_address_qry,$db);
			$new_address=mysql_fetch_object($new_address_result);
			$_POST['adres_id']=$new_address->address_id;
		}

		if (isset($_POST['address_change'])){
			$sql="UPDATE ".$tree_prefix."addresses SET
				address_address='".text_process($_POST['address_address'])."',
				address_date='".date_process(veilig($_POST['address_date']))."',
				address_zip='".veilig($_POST['address_zip'])."',
				address_place='".text_process($_POST['address_place'])."',
				address_phone='".veilig($_POST['address_phone'])."',
				address_photo='".veilig($_POST['address_photo'])."',
				address_source='".veilig($_POST['address_source'])."',
				address_text='".text_process($_POST['address_text'],true)."',
				address_changed_date='".$datum."',
				address_changed_time='".$tijd."'
			WHERE address_id='".veilig($_POST["adres_id"])."'";
			$result=mysql_query($sql) or die(mysql_error());

			family_tree_update($tree_prefix);
		}

		if (isset($_POST['address_remove'])){
			echo '<div class="confirm">';
      	echo $language["editor_address_remove"];
			echo ' <form method="post" action="'.$_SERVER['PHP_SELF'].'" style="display : inline;">';
			echo '<input type="hidden" name="page" value="'.$page.'">';
			echo '<input type="hidden" name="adres_id" value="'.$_POST['adres_id'].'">';
			echo ' <input type="Submit" name="address_remove2" value="'.$language["admin_yes"].'" style="color : red; font-weight: bold;">';
			echo ' <input type="Submit" name="submit" value="'.$language["admin_no"].'" style="color : blue; font-weight: bold;">';
			echo '</form>';
			echo '</div>';
		}
		if (isset($_POST['address_remove2'])){
			echo '<div class="confirm">';
			// *** Find gedcomnumber, needed for events query ***
			$adresqry=mysql_query("SELECT * FROM ".$tree_prefix."addresses
			WHERE address_id='".veilig($_POST["adres_id"])."'",$db);
			$adresDb=mysql_fetch_object($adresqry);

			// *** Delete address references ***
			$sql="DELETE FROM ".veilig($_SESSION['tree_prefix'])."events
			WHERE	event_kind='adres' AND event_source='@".$adresDb->address_gedcomnr."@'";
			$result=mysql_query($sql,$db);

			// *** Delete address ***
			$sql="DELETE FROM ".$tree_prefix."addresses
			WHERE address_id='".veilig($_POST["adres_id"])."'";
			$result=mysql_query($sql,$db);

			echo $language["editor_address_removed"];
			echo '</div>';
		}

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

		$adresqry=mysql_query("SELECT * FROM ".$tree_prefix."addresses
			WHERE address_gedcomnr LIKE '_%' ORDER BY address_place, address_address",$db);
		echo $language["address_address"].' ';
		echo '<select size="1" name="adres_id">';
		echo '<option value=""></option>'; // *** For new address in new database... ***
		while ($adresDb=mysql_fetch_object($adresqry)){
			$selected='';
			if (isset($_POST['adres_id'])){
				if ($_POST['adres_id']==$adresDb->address_id){$selected=' SELECTED';}
			}
			echo '<option value="'.$adresDb->address_id.'"'.$selected.'>'.
			@$adresDb->address_place.', '.$adresDb->address_address.' ['.@$adresDb->address_gedcomnr.']</option>';
		}
		echo '</select>';
		echo ' <input type="Submit" name="submit" value="'.$language["admin_select"].'">';


		echo ' '.$language["admin_or"].': ';
		echo '<input type="Submit" name="add_address" value="'.$language["editor_add_address"].'">';

		echo '</form>';

		// *** Show selected address ***
		if (isset($_POST['adres_id'])){
			echo '<table class="humo standaard" border="1">';
			print '<tr class="tabel_kop"><th>'.$language["groups_option"].'</th><th colspan="2">'.$language["groups_value"].'</th></tr>';

			if (isset($_POST['add_address'])){
				$address_address=''; $address_date=''; $address_zip=''; $address_place=''; $address_phone='';
				$address_photo=''; $address_source=''; $address_text='';
			}
			else{
				@$adres=mysql_query("SELECT * FROM ".$tree_prefix."addresses WHERE address_id='".veilig($_POST["adres_id"])."'",$db);
				@$adresDb=mysql_fetch_object($adres) or die("Geen geldig adres nummer.");

				$address_address=$adresDb->address_address; $address_date=$adresDb->address_date;
				$address_zip=$adresDb->address_zip; $address_place=$adresDb->address_place;
				$address_phone=$adresDb->address_phone; $address_photo=$adresDb->address_photo;
				$address_source=$adresDb->address_source; $address_text=$adresDb->address_text;
			}

			echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
			echo '<input type="hidden" name="page" value="'.$page.'">';
			echo '<input type="hidden" name="adres_id" value="'.$_POST['adres_id'].'">';
			echo '<tr><td>'.$language["address_address"].'</td><td><input type="text" name="address_address" value="'.$address_address.'" size="60"></td></tr>';
			echo '<tr><td>'.$language["editor_date"].' - '.$language["editor_place"].'</td><td><input type="text" name="address_date" value="'.date_show($address_date).'" size="20"> <input type="text" name="address_place" value="'.$address_place.'" size="50"></td></tr>';
			echo '<tr><td>'.$language["address_zip"].'</td><td><input type="text" name="address_zip" value="'.$address_zip.'" size="60"></td></tr>';
			echo '<tr><td>'.$language["address_phone"].'</td><td><input type="text" name="address_phone" value="'.$address_phone.'" size="60"></td></tr>';
			echo '<tr><td>'.$language["editor_picture"].'</td><td><input type="text" name="address_photo" value="'.$address_photo.'" size="60"></td></tr>';
			echo '<tr><td>'.$language["source_source"].'</td><td><input type="text" name="address_source" value="'.$address_source.'" size="60"></td></tr>';
			echo '<tr><td>'.$language["editor_text"].'</td><td><textarea rows="1" name="address_text" '.$veld_tekst.'>'.
			text_show($address_text).'</textarea></td></tr>';

			if (isset($_POST['add_address'])){
				echo '<tr><td>'.$language["admin_add"].'</td><td><input type="Submit" name="address_add" value="'.$language["admin_add"].'"></td></tr>';
			}
			else{
				echo '<tr><td>'.$language["admin_change"].'</td><td><input type="Submit" name="address_change" value="'.$language["admin_change"].'">';
				echo ' '.$language["admin_or"].' ';
				echo '<input type="Submit" name="address_remove" value="'.$language["admin_remove"].'">';
				echo '</td></tr>';
			}

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

			// *** Example in IFRAME ***
			if (!isset($_POST['add_address'])){
				echo '<p>'.$language["editor_preview"].'<br>';
				echo '<iframe src ="../address.php?database='.$tree_prefix.'&gedcomnummer='.$adresDb->address_gedcomnr.'" width="100%" height="300">';
				echo '  <p>Your browser does not support iframes.</p>';
				echo '</iframe>';
			}

		}

	}

	echo '</div>'; // float left
}
?>
Return current item: HuMo-gen