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

	#--------------------------------------------------------------------
	# $Id: medit.php3,v 1.12 2000/12/14 19:13:50 shevett Exp $
	#--------------------------------------------------------------------
?>
	
<tr bgcolor=#000000><td>&nbsp</td></tr>
<tr bgcolor=#BBBBcB>
<td width=100% bgcolor=#202020 align=center>
<table bgcolor=#bbbbbb cellspacing=2>
	<tr bgcolor=bbbbbb>
		<td align=center>
			<?
				if ($row == "0new0") {
					$tmptext="Add new row in";
				} else {
					$tmptext="Edit row $row of";
				}
			?>
			<h3>
			<? 
				echo "$tmptext table $table";
			?> 
		</td>
	</tr>
	<tr bgcolor=bbbbbb><td>
	
	<b><center>
	<table border=1>
		<tr bgcolor=#808080>
			<th><font color=#000000>Field</th>
			<th><font color=#000000>Size</th>
			<th><font color=#000000>Value</th>
		</tr>

		<form method=post action="nbrowse.php3">
		<input type=hidden name=row value="<? echo $row?>">
		<input type=hidden name=table value="<? echo $table?>">
		<input type=hidden name=f_process value="mpost">
	<?
		# Select out the column list...
		$fn = db_listfields($table);
		
		# and the number of columns...
		$n = db_numfields($fn);
		
		$counter	=	0;
		$acounter	=	0;
		$flist		=	"";
		while ($counter < $n ) {
			
			# Scan through the structure of the row, so we can build an expression.

			$ftype	=	db_fieldtype($fn,$counter);
			$fel 		= db_fieldname($fn,$counter);
			if (($ftype != "index")) {
				$farray[$acounter] = $fel;
				$sarray[$acounter] = db_fieldlen($fn,$counter);
				$flist="$fel,$flist"; 
				$acounter++;
			}  
			$counter++;
		}
		
		# Lop off that trailing ','.
		
		$flist=ereg_replace("(),$","\\1","$flist");

		if ($row != "0new0") {
			$pk = db_primarykey($table);
			$w = "$pk[0]=${pk[1]}${row}${pk[1]}";
			LogIt("DEBUG","medit.php3","where is $w");
			LogIt("DEBUG","medit.php3","row is $row");
			$therow	=	db_query("select $flist from $table where $w");
			$varray	=	db_fetch_array($therow);	
		}
		$counter=0;
		while ($counter < $acounter) {
			if ($farray[$counter] != "_rowid") {
				echo "<tr>\n";
				echo "<td>$farray[$counter]</td>\n";
				echo "<td>$sarray[$counter]</td>\n";
				if ($row != "0new0") {
					$val	=	$varray[$farray[$counter]];
				}
				$ftype="";
				if ($farray[$counter] == "passwd") {
					$ftype="type=password";
				}
				# FIXME: needs maxsize based on database query
				echo "<td><input $ftype name=\"$farray[$counter]\" size=$sarray[$counter] value=\"$val\"></td>\n";
				echo "</tr>\n";
			}
			$counter++;
		}
	?>
	<tr bgcolor=#202020><td colspan=3>
		<? PostBar("Save Changes"); ?>
	</td>
	</table></td>
	</tr>
</table>
</tr>
<tr bgcolor=#000000><td>&nbsp</td></tr>
