Location: PHPKode > projects > PhpFamilyTree > phpfamilytree/ft_edit_marriages.php
<?
# ft_edit_marriages.php - Manage Marriages
# $Id: ft_edit_marriages.php,v 1.1.1.1 2004/01/01 05:51:24 rocket_169 Exp $
#
# Copyright (c) 2003 The phpFamilyTree Project Team
# Licensed under the GNU GPL. For full terms see the file COPYING.
#
# http://www.phpfamilytree.org
#

require_once ("config.php");
require_once ("functions.php");
require_once ("header.php");

$thispage = "ft_edit_marriages.php";
$action = $_GET["action"];
$id = intval($_GET["id"]);
$form = $_POST["form"];
$date = str_replace("\"","'",$_POST["date"]);
$place = str_replace("\"","'",$_POST["place"]);
$divorced = substr($_POST["divorced"],0,1);
$gender = substr($_POST["gender"],0,1);
$memberid = intval($_POST["memberid"]);
$spouse_id = intval($_POST["spouse"]);

if ($gender=="M") {
	$wife_id=$spouse_id;
	$husband_id=$memberid;
} else {
	$husband_id=$spouse_id;
	$wife_id=$memberid;
}

# PROCESS FORM
if ($form=="form" and logged_in()) {
	$memberid = substr($_POST["memberid"],0,10);
	$insert="INSERT INTO ft_marriages SET
	wife_id=$wife_id, husband_id=$husband_id, place=\"$place\", date=\"$date\", divorced=\"$divorced\"";
	mysql_query($insert) or die(mysql_error());
	$id=$memberid;
}

# DELETE MARRIAGE
if ($action == "del" and logged_in()) {
	mysql_query("DELETE FROM ft_marriages WHERE id=$id LIMIT 1") or die(mysql_error());
	$id = intval($_GET["memberid"]);
}

$membername = getname($id);
$gender = getgender($id);

print "<table width=\"100%\" border=\"0\"><tr>";

# MARRIAGE LIST
print "<td valign=\"top\" id=\"leftpanel\">";
print "<h3>$membername's Marriages</h3>";
$rs=mysql_query("SELECT * FROM ft_marriages WHERE husband_id=$id or wife_id=$id") or die(mysql_error());
print "<table width=\"100%\">";
while ($marriage = mysql_fetch_array($rs)) {
	$marriageid=$marriage["id"];
	if ($gender=="F") {
		$spouseid=$marriage["husband_id"];
	} else {
		$spouseid=$marriage["wife_id"];
	}
	# PRINT MARRIAGE
	print "<tr><td>".getname($spouseid)."</td>";
	print "<td>".$marriage["place"]."</td>";
	print "<td>".$marriage["date"]."</td>";
	print "<td>";
	if ($marriage["divorced"]=="Y") { print "Divorced"; }
	print "</td>";
	print "<td><a href=\"$thispage?action=del&id=$marriageid&memberid=$id\">Delete</a></td>";
	print "</tr>";
	$count++;
}
if (!$count) {
	print "No marriages defined";
}
print "</table>";

# MARRIAGE EDIT/CREATE
print "</td><td>";
if (($action=="add" or $action=="edit") and logged_in()) {
	if ($action == "edit") {
		$rs=mysql_query("SELECT * from ft_marriages WHERE id=$marriageid") or die(mysql_error());
		$marriage = mysql_fetch_array($rs);
		if ($gender=="M") {
			$spouse_id= $marriage["wife_id"];
		} else {
			$spouse_id= $marriage["husband_id"];
		}
		$date= $marriage["date"];
		$place= $marriage["place"];
		$divorced= $marriage["divorced"];
		print "<h3>Editing marriage</h3>";
	} else {
		$spouse_id=0;
		$place="";
		$date="";
		$divorced="N";
		print "<h3>Adding a new marriage for $membername</h3>";
	}
	?>
	<form action="<? print $thispage ?>" method="post">
		<input type="hidden" name="form" value="form">
		<input type="hidden" name="memberid" value="<? print $id ?>">
		<input type="hidden" name="gender" value="<? print $gender ?>">
		<table id="entryform" width="100%">
			<tr>
				<td width="20%">
					Spouse
				</td>
				<td>
					<? spousecombo($spouse_id, $familyid, $memberid, $gender); ?>
				</td>
			</tr>
			<tr>
				<td width="20%">
					Date
				</td>
				<td>
					<input type="text" name="date" value="<? print $date?>">
				</td>
			</tr>
			<tr>
				<td width="20%">
					Place
				</td>
				<td>
					<input type="text" name="place" value="<? print $place?>">
				</td>
			</tr>
			<tr>
				<td width="20%">
					Divorced
				</td>
				<td>
					<? divorcedcombo($divorced); ?>
				</td>
			</tr>
			<tr>
				<td>
				</td>
				<td>
					<input type="submit" value="Submit">
				</td>
			</tr>
		</table>
	</form>
	<?
}

print "</td></tr>";

if (logged_in()) {
	print "<tr><td>";
	print "<a href=\"$thispage?action=add&id=$id\">Add New Marriage for $membername</a><br>";
	print "</td><td></td></tr>";
}

print "</table>";

require_once ("footer.php");
?>
Return current item: PhpFamilyTree