Location: PHPKode > projects > The Community Wish List Server > wlserver/addtolist.php
<?php

session_start();

// updateuserlist.php
// Allows the user to update the list of people that show up in the drop-down recipient list

require("authenticate.php");

require("php/classes/wishlist.php");
require("php/lib/wishlistlib.php");

$myList = new WishList($_SESSION['currentUser']);
$userName = $myList->name;
$familyArray = getAllButCurrent($_SESSION['currentUser']);

if ( $_POST['a'] == "a" ) {
	confirmAdd();
} else if ($_POST['a'] == "add" ) {
	addName();
}	else {
	displayUserList();
}

function displayUserList() {
	global $familyArray;
	global $userName;
	$familyCount = count($familyArray);
	print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
?>
	<!DOCTYPE html
	PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n");
		" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
	<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
	<link rel="STYLESHEET" type="text/css" href="wishlist.css" />
		<title>Update <?php print $userName; ?>'s Recipient List at StoneGoose.com</title>
	</head>
	<body>
	<p>Your recipient list currently contains:
	<ul>
	<?php
	for ( $i = 0; $i < $familyCount; $i++ ) {
		$familyMember = $familyArray[$i]["userName"];
		$familyMemberKey = $familyArray[$i]["personKey"];
		print("<li>$familyMember</li>\n");
	}
	?>
	</ul>
	<form name="addform" action="addtolist.php" method="post">
	<div class="message_box">
	<div align="center">
	<p>To add someone to your recipient list, enter their first name and last name below:</p>
	<table border="0">
		<tr>
			<th>First Name</th>
			<th>Last Name</th>
		</tr>
		<tr>
			<td><input type="text" size="30" name="fname" /></td>
			<td><input type="text" size="30" name="lname" /></td>
		</tr>
		<tr>
			<td colspan="2" align="center">
				<input type="hidden" name="a" value="a" />
				<input type="submit" value="Add Name" />
			</td>
		</tr>
	</table>
	</div>
	</div>
	</form>
	<p><a href="updateuserlist.php">Back</a></p>
	<p><a href="index.php">Return to your wish list</a></p>
	</body>
	</html>
<?php
}

function confirmAdd() {
	global $familyArray;
	global $a;
	global $userName;
	global $fname,$lname;
	$familyCount = count($familyArray);
	print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
	?>
	<!DOCTYPE html
	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
	<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<link rel="STYLESHEET" type="text/css" href="wishlist.css"
		<title>Update <?php print $userName ?>'s recipient list at StoneGoose.com</title>
	</head>
	<body>
	<?php
	$sSQL = "
		select
			p.personKey as personKey,
			concat(p.fName,' ',p.lName) as foundName
		from
			person p
		where
			lower(p.fName) like lower('$fname') and
			lower(p.lName) like lower('$lname')
		order by
			p.fName";
	$xq = mysql_query($sSQL);
	if (!$xq) die ("Could not execute search query: confirmAdd() in addtolist.php<br />".mysql_error()."<br />$sSQL");
	$list = mysql_num_rows($xq);
	if ($list < 1) {
		print ("<p><b>$fname $lname</b> is not in the Stone Goose user database.</p>\n");
		print ("<p><a href=\"javascript:history.back();\">Try Again</a></p>\n");
		print ("<p><a href=\"index.php\">Back to your wish list</a></p>\n");
	} else {
		$name = mysql_result($xq,0,"foundName");
		$d = mysql_result($xq,0,"personKey");
	?>
		<p>I found <b><?php print $name ?></b> in the database.  Add to your recipient list?</p>
		<form name="confirmaddform" action="addtolist.php method="post">
		<input type="hidden" name="d" value="<?php print $d ?>" />
		<input type="hidden" name="a" value="add" />
		<input type="submit" value="Add To Group" />
		<input type="button" value="Search Again" onClick="javascript:history.back();">
		</form>
	<?php
	}
	print("\t</body>\n");
	print("</html>\n");
}

function addName() {
	global $d;
	global $a;
	$iSQL = "insert into peopleSeeOthers (userKey,showKey) values (".$_SESSION['currentUser'].",$d)";
	$xq=mysql_query($iSQL);
	if (!$xq) die ("Could not update peopleSeeOthers table");
	header ("Location: updateuserlist.php?d=$d&a=a");
}
Return current item: The Community Wish List Server