Location: PHPKode > projects > PhpFamilyTree > phpfamilytree/ft_edit_families.php
<?
# ft_edit_families.php - Manage Families
# $Id: ft_edit_families.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_families.php";
$action = $_GET["action"];
$id = substr($_GET["id"],0,6);
$form = $_POST["form"];
$name = str_replace("\"","'",$_POST["name"]);
$notes = str_replace("\"","'",$_POST["notes"]);

# PROCESS FORM
if ($form=="form" and logged_in()) {
	$id = substr($_POST["id"],0,6);
	if ($id) {
		mysql_query("UPDATE ft_families SET name=\"$name\", notes=\"$notes\" WHERE id=$id") or die(mysql_error());
	} else {
		mysql_query("INSERT INTO ft_families SET name=\"$name\", notes=\"$notes\"") or die(mysql_error());
	}
}

# DELETE FAMILY
if ($action == "del" and logged_in()) {
	mysql_query("DELETE FROM ft_families WHERE id=$id LIMIT 1") or die(mysql_error());
}


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

# FAMILY LIST
print "<td valign=\"top\" id=\"leftpanel\">";
print "<h3>Families</h3>";
$rs=mysql_query("SELECT id, name FROM ft_families") or die(mysql_error());
print "<table width=\"100%\">";
while ($family = mysql_fetch_array($rs)) {
	$rs2 = mysql_query("SELECT count(*) FROM ft_individual where family_id={$family["id"]}") or die(mysql_error());
	$members = mysql_fetch_array($rs2);
	print "<tr><td>";
	print "{$family["name"]} ({$members[0]})</td>";
	if (logged_in()) {
		print "<td><a href=\"$thispage?action=edit&id={$family["id"]}\">Edit</a></td>";
	}
	print "<td><a href=\"ft_edit_members.php?id={$family["id"]}\">Members</a></td>";
	if ($members[0]==0 and logged_in()) {
		print "<td><a href=\"$thispage?action=del&id={$family["id"]}\">Delete</a></td>";
	} else {
		print "<td></td>";
	}
	print "</tr>";
	$count++;
}
if (!$count) {
	print "No families defined";
}
print "</table>";

# FAMILY EDIT/CREATE
print "</td><td>";
if ($action=="add" or $action=="edit") {
	if ($action == "edit") {
		$rs=mysql_query("SELECT id, name, notes FROM ft_families WHERE id=$id") or die(mysql_error());
		$family = mysql_fetch_array($rs);
		$id= $family["id"];
		$name= $family["name"];
		$notes= $family["notes"];
		print "<h3>Editing Family $name</h3>";
	} else {
		$id=0; $name=""; $notes="";
		print "<h3>Adding a new family</h3>";
	}
	?>
	<form action="<? print $thispage ?>" method="post">
		<input type="hidden" name="form" value="form">
		<input type="hidden" name="id" value="<? print $id ?>">
		<table width="100%">
			<tr>
				<td width="20%">
					Family Name
				</td>
				<td>
					<input type="text" name="name" value="<? print $name?>">
				</td>
			</tr>
			<tr>
				<td width="20%">
					Notes
				</td>
				<td>
				  <textarea cols="40" rows="5" name="notes"><? print $notes ?></textarea>
				</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><a href=\"$thispage?action=add\">Add New Family</a></td>
	<td></td>
	</tr>";
}

print "</table>";

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