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

	#--------------------------------------------------------------------
	# $Id: mbrowse.php3,v 1.19 2000/12/14 19:13:49 shevett Exp $
	#--------------------------------------------------------------------

	LogIt("DEBUG","mbrowse.php3","mbrowse starting on table $table");
?>

<form method="post" action="nbrowse.php3">
<input type="hidden" name="f_func" value="medit">
<input type="hidden" name="table" value="<? echo $table ?>">
<input type="hidden" name="row" value="0new0">

<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 colspan=2 align=center>
			<h3>Browse table '<? echo $table ?>'
		</td>
	</tr>
	<tr bgcolor=bbbbbb><td>
	<?
	
	echo "<p><center>";
	$fn = db_listfields("$table");
	$n = db_numfields($fn);
	LogIt("DEBUG","mbrowse.php3","there are $n columns in this table.");
	echo "<table border=1><tr bgcolor=#808080>";
	$counter=0;
	$apos=0;
	echo "<th><font color=#000000>Function</th>\n";
	$flist="";
	while ($counter < $n) {
		$f = db_fieldname($fn,$counter);   
		$t = db_fieldflags($fn,$counter);
		$z = db_fieldtype($fn,$counter);
		LogIt("DEBUG","mbrowse.php3","column $n in table $table is $f");
		if ((ereg("primary_key","$t")) or (ereg("primary key","$t"))) {
			$pkcolumn=$f;
		}
		$farray[$apos]=$f;
		$zarray[$apos]=$z;
		if ($flist) {
			$flist="$flist,$f";
		} else {
			$flist=$f;
		}
		$ch = db_query("select dheading,dflags from dictionary where dtable='$table' and dcolumn='$f'") ;
		if (db_numrows($ch)) {
			$f = db_result($ch,0,0); 
			$flags[$apos] = db_result($ch,0,"dflags");
		}
		echo "<th><font color=#000000>$f</th>\n";
		$apos++;
		$counter++;
	}
	echo "</tr>";
	$rows=db_query("select $flist from $table");
	$nr = db_numrows($rows);
	$counter=0;
	$flipper=0;
	while ($counter < $nr) {
		$icount=0;
		$bgcol = ($flipper) ? $sys_col[bghigh] : $sys_col[bgwhite] ;
		$flipper = (! $flipper) ;
		echo "<tr bgcolor=\"$bgcol\">";
		echo "<td>";
		$rowarray = db_fetch_array($rows);
		echo "<a href=\"nbrowse.php3?f_func=medit&table=$table&row=$rowarray[$pkcolumn]\">Edit</a>";
		echo " | ";
		echo "<a href=\"nbrowse.php3?f_func=mdelete&table=$table&row=$rowarray[$pkcolumn]&pkcolumn=$pkcolumn\">Dlte</a>";
		echo "</td>";
		while ($icount < count($farray)) {
			$fn = $farray[$icount];
			$val = db_result($rows,$counter,"$fn");
			echo "<td>";
			if ($fn == "passwd") {
				echo "[md5]";
			} else {
				if (ereg("D",$flags[$icount])) {
					if ($val) {
						echo date($sys_datefmt,$val);
					} else {
						echo "Never";
					}
				} else {
					echo "$val&nbsp;";
				}
			}
			echo "</td>";
			$icount++;
		}
		echo "</tr>";
		$counter++;
	}
	$colcount = count($farray) + 1;
	?>
	<tr bgcolor=#000000>
	<td colspan=<? echo $colcount ?> align=center>
	<? PostBar("Add a new row"); ?>
	</td></tr></table></td></tr>
</table>
</tr><tr bgcolor=#000000><td>&nbsp</td></tr>
