<?
	#---------------------------------------------------------------------#
	# This source code is (c)2000 White Pajamas, Inc                      #
	# see http://www.stonekeep.com/license.html for licensing information #
	#---------------------------------------------------------------------#

	#--------------------------------------------------------------------
	# $Id: addrmaint.php3,v 1.11 2000/12/27 21:59:09 shevett Exp $
	#--------------------------------------------------------------------

	$f_label=urldecode($f_label);
	$qstring = "select * from addresses where tag='$f_contact' and label='$f_label'";
	LogIt("DEBUG","addrmaint.php3","query is $qstring");
	$result = db_query("$qstring");
	$currow = db_fetch_array($result);

?>

	<form method="post" action="nbrowse.php3">
	<input type=hidden name="f_process" value="addrpost">
	<input type=hidden name="a_tag" value="<? echo $f_contact ?>">
	<tr bgcolor=#000000>
		<td align=center colspan=3>
		<table bgcolor=#000000 cellspacing=2>
			<tr bgcolor=#bbbbbb valign=top>
			<td align=center>
			<?
				if ($currow && $currow[tag]) {
					echo "Modify address <b>$f_label</b> for contact <b>$f_contact</b>";
					echo "<input type=hidden name=\"f_flag\" value=\"modify\">";
					echo "<input type=hidden name=\"a_main\" value=\"$currow[main]\">";
					echo "<input type=hidden name=\"o_label\" value=\"$currow[label]\">";
				} else {
					echo "Add new address to contact <b>$f_contact</b>";
					echo "<input type=hidden name=\"f_flag\" value=\"add\">";
					# This forces $currow to be an array with all the expected elements are empty.
					unset ($currow);
					$currow[0] = "";
				}
			?>
			</td>
		</tr>
		<tr>
		<td bgcolor=#808080>
		<table><tr>
			<td bgcolor=#808080>
				<i>Label</i><br>
				<select name="a_label">
				<?
				$labelquery = db_query("select tag,descrip from contactlabel where ltype='A' order by tag");
				while ($row=db_fetch_array($labelquery)) {
					if ($row[tag] == $currow[label]) {
						$sel = "selected";
						$selcount = 1;
					} else {
						$sel ="";
					}
					echo "<option value=\"$row[tag]\" $sel> $row[tag] - $row[descrip]";
				}
				$sel = "";
				if ($currow[tag] && $selcount == 0) {
					$sel = "selected";
				}
				echo "<option value=\"userwritein\" $sel> Write in your own in the next column";
				?>
			</select>
			</td>
			<td bgcolor=#808080>
				<i>User Write-In</i><br>
				<input type=text name=a_writeinvalue size=10 value="<? echo $selcount ? "" : $currow[label] ?>"><br>
			</td>
		</tr></table>
		</td>
		</tr>
		<tr>
			<td bgcolor=#808080>
				<i>Address</i><br>
				<!-- FIXME: needs maxsize based on database query -->
				<input type=text name=a_address1 size=40 value="<? echo $currow[address1] ?>"><br>
				<!-- FIXME: needs maxsize based on database query -->
				<input type=text name=a_address2 size=40 value="<? echo $currow[address2] ?>">
			</td>
		</tr>
		<tr>
			<td bgcolor=#808080>
				<i>City</i><br>
				<!-- FIXME: needs maxsize based on database query -->
				<input type=text name=a_city size=40 value="<? echo $currow[city] ?>">
			</td>
		</tr>
		<tr>
			<td bgcolor=#808080>
				<i>State</i><br>
				<!-- FIXME: needs maxsize based on database query -->
				<input type=text name=a_state size=10 value="<? echo $currow[state] ?>">
			</td>
		</tr>
		<tr>
			<td bgcolor=#808080>
				<i>Postal Code</i><br>
				<!-- FIXME: needs maxsize based on database query -->
				<input type=text name="a_pcode" size=20 value="<? echo $currow[pcode] ?>">
			</td>
		</tr>
		<tr bgcolor=#000000 valign=top><td align=center>
		<?
			PostBar("Post Address Information");
		?>
		</tr>
		</table>
	</td>
	</tr>
	
	</form>
