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

	#--------------------------------------------------------------------
	# $Id: mpost.php3,v 1.12 2000/12/14 19:13:52 shevett Exp $
	#--------------------------------------------------------------------
	

	# What fields are we updating?
	$fl	=	db_listfields($table);
	
	# and how many are there?
	$n	=	db_numfields($fl);
	
	$counter=0;
	$istring="";
	$flstring = "";
	$seperator="";
	while ($counter < $n) {
		$fname = db_fieldname($fl,$counter);
		$ftype = db_fieldtype($fl,$counter);
		if ($ftype != "index") {
			$flstring=$flstring."$seperator"."$fname";
			eval("\$val=\"\$$fname\";");

			# If it's a password, md5 it before posting it.  Make
			# sure it's not an already md5()'ed passwd.

			if (("$fname" == "passwd") && (strlen($val) <> 32)) {
				$val = md5("$val");
			}
			if (($ftype == "char") ||
			    ($ftype == "string") ||
					($ftype == "blob") ||
			    eregi("char",$ftype) ) {
				$istring=$istring ."$seperator". "'" . addslashes($val) . "'";
			} else {
				if (StrLen("$val") != 0) {
					$istring=$istring ."$seperator". "$val"; 
				} else {
					$istring=$istring . "$seperator"."NULL";
				}
			}
			$seperator=",";
		}
		$counter++;
	}
	
	if ("$row" != "0new0") {
		$pk = db_primarykey($table);
		$result=db_query("delete from $table where $pk[0] = ${pk[1]}${row}${pk[1]}");
	}

	$result = db_query("insert into $table ($flstring) values ($istring)");
	if (db_affected_rows($result) == 0) {
		if ($sys_logerr) {
			LogIt("ERR","mpost.php3","insert into $table ($flstring) values ($istring)");
		}
		$lastresult[0] = 1;
		$lastresult[1] = "Table update FAILED!";
	} else {
		$lastresult[0] = 0;
		$lastresult[1] = "Modifications to table $table SUCCESSFUL.";
	}

?>
