Location: PHPKode > projects > PhpFamilyTree > phpfamilytree/ft_edit_members.php
<?
# ft_edit_members.php - Manage Family Members
# $Id: ft_edit_members.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_members.php";
$action = $_GET["action"];
$id = substr($_GET["id"],0,10);
$memberid = substr($_GET["memberid"],0,10);
$form = $_POST["form"];
$first = str_replace("\"","'",$_POST["first"]);
$middle = str_replace("\"","'",$_POST["middle"]);
$maiden = str_replace("\"","'",$_POST["maiden"]);
$last = str_replace("\"","'",$_POST["last"]);
$suffix = str_replace("\"","'",$_POST["suffix"]);
$gender = str_replace("\"","'",$_POST["gender"]);
$birthplace = str_replace("\"","'",$_POST["birthplace"]);
$birthdate = str_replace("\"","'",$_POST["birthdate"]);
$deathdate = str_replace("\"","'",$_POST["deathdate"]);
$deathplace = str_replace("\"","'",$_POST["deathplace"]);
$email = str_replace("\"","'",$_POST["email"]);
$webpage = str_replace("\"","'",$_POST["webpage"]);
$father_id = substr($_POST["father_id"],0,10);
$mother_id = substr($_POST["mother_id"],0,10);

# PROCESS FORM
if ($form=="form" and logged_in()) {
	$familyid = substr($_POST["id"],0,10);
	$memberid = substr($_POST["memberid"],0,10);
	$id = $familyid;

	if ($memberid) {
		mysql_query("UPDATE ft_individual SET
		first=\"$first\", middle=\"$middle\",
		maiden=\"$maiden\", last=\"$last\",
		suffix=\"$suffix\", gender=\"$gender\",
		birth=\"$birthdate\",  death=\"$deathdate\",
		place_of_birth=\"$birthplace\",  place_of_death =\"$deathplace\",
		email=\"$email\",   webpage=\"$webpage\",
		father_id=\"$father_id\",   mother_id=\"$mother_id\"
		WHERE id=$memberid") or die(mysql_error());
	} else {
		$insert="INSERT INTO ft_individual SET
		first=\"$first\", middle=\"$middle\",
		maiden=\"$maiden\", last=\"$last\",
		suffix=\"$suffix\", gender=\"$gender\",
		birth=\"$birthdate\",  death =\"$deathdate\",
		place_of_birth=\"$birthplace\",  place_of_death =\"$deathplace\",
		email=\"$email\",   webpage=\"$webpage\",
		father_id=\"$father_id\",   mother_id=\"$mother_id\",
		family_id=$familyid";
		mysql_query($insert) or die(mysql_error());
	}
}


# DELETE MEMBER
if ($action == "del" and logged_in()) {
	$memberid = substr($_GET["memberid"],0,6);
	$familyid = substr($_GET["id"],0,6);
	mysql_query("DELETE FROM ft_individual WHERE id=$memberid and family_id=$familyid LIMIT 1") or die(mysql_error());
}

# RETRIEVE FAMILY NAME
$rs=mysql_query("SELECT id, name FROM ft_families where id=$id") or die(mysql_error());
$family = mysql_fetch_array($rs);
$familyname=$family["name"];
$familyid=$id;

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

# FAMILY MEMBER LIST
print "<td valign=\"top\" id=\"leftpanel\">";
print "<h3>$familyname Family Members</h3>";
$rs=mysql_query("SELECT id FROM ft_individual WHERE family_id=$familyid and father_id=0 and mother_id=0") or die(mysql_error());
print "<table width=\"100%\">";
while ($member = mysql_fetch_array($rs)) {
	printmember($member["id"],1);
	$count++;
}
if (!$count) {
	print "No family members defined";
}

print "</table>";

# MEMBER EDIT/CREATE
print "</td><td>";
if (($action=="add" or $action=="edit") and logged_in()) {
	if ($action == "edit") {
		$rs=mysql_query("SELECT * from ft_individual WHERE id=$memberid") or die(mysql_error());
		$member = mysql_fetch_array($rs);
		$id= $member["id"];
		$first= $member["first"];
		$middle= $member["middle"];
		$maiden= $member["maiden"];
		$last= $member["last"];
		$gender= $member["gender"];
		$suffix= $member["fullname"];
		$birthdate= $member["birth"];
		$birthplace= $member["place_of_birth"];
		$deathdate= $member["death"];
		$birthdeath= $member["place_of_death"];
		$email= $member["email"];
  		$webpage= $member["webpage"];
		$father_id= $member["father_id"];
		$mother_id= $member["mother_id"];
		print "<h3>Editing $fullname</h3>";
	} else {
		$id=0;
		$memberid=0;
		print "<h3>Adding a new member to family $familyname</h3>";
	}
	?>
	<form action="<? print $thispage ?>" method="post">
		<input type="hidden" name="form" value="form">
		<input type="hidden" name="id" value="<? print $familyid ?>">
		<input type="hidden" name="memberid" value="<? print $memberid ?>">
		<table id="entryform" width="100%">
			<tr>
				<td width="20%">
					First Name
				</td>
				<td>
					<input type="text" name="first" value="<? print $first?>">
				</td>
			</tr>
			<tr>
				<td width="20%">
					Middle Name
				</td>
				<td>
					<input type="text" name="middle" value="<? print $middle?>">
				</td>
			</tr>
			<tr>
				<td width="20%">
					Maiden Name
				</td>
				<td>
					<input type="text" name="maiden" value="<? print $maiden?>">
				</td>
			</tr>
			<tr>
				<td width="20%">
					Last Name
				</td>
				<td>
					<input type="text" name="last" value="<? print $last?>">
				</td>
			</tr>
			<tr>
				<td width="20%">
					Suffix
				</td>
				<td>
					<input type="text" name="suffix" value="<? print $suffix?>">
				</td>
			</tr>
			<tr>
				<td width="20%">
					Gender
				</td>
				<td>
					<? gendercombo("$gender") ?>
				</td>
			</tr>
			<tr>
				<td width="20%">
					Date of Birth
				</td>
				<td>
					<input type="text" name="birthdate" value="<? print $birthdate?>">
				</td>
			</tr>
			<tr>
				<td width="20%">
					Place of Birth
				</td>
				<td>
					<input type="text" name="birthplace" value="<? print $birthplace?>">
				</td>
			</tr>
			<tr>
				<td width="20%">
					Date of Death
				</td>
				<td>
					<input type="text" name="deathdate" value="<? print $deathdate?>">
				</td>
			</tr>
			<tr>
				<td width="20%">
					Place of Death
				</td>
				<td>
					<input type="text" name="deathplace" value="<? print $deathplace?>">
				</td>
			</tr>
			<tr>
				<td width="20%">
					e-mail
				</td>
				<td>
					<input type="text" name="email" value="<? print $email?>">
				</td>
			</tr>
			<tr>
				<td width="20%">
					Webpage
				</td>
				<td>
					<input type="text" name="webpage" value="<? print $webpage?>">
				</td>
			</tr>
			<tr>
				<td width="20%">
					Father
				</td>
				<td>
					<? parentcombo($father_id, $familyid, $memberid, "M"); ?>
				</td>
			</tr>
			<tr>
				<td width="20%">
					Mother
				</td>
				<td>
					<? parentcombo($mother_id, $familyid, $memberid, "F"); ?>
				</td>
			</tr>
			<tr>
				<td width="20%">
					Spouse
				</td>
				<td>
					<? spousecombo($spouse_id, $familyid, $memberid, $gender); ?>
				</td>
			</tr>
			<tr>
				<td>
				</td>
				<td>
					<input type="submit" value="Apply Changes">
				</td>
			</tr>
		</table>
	</form>
	<?
}

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

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

print "</table>";

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