Location: PHPKode > projects > WebArchive > phparchive.0.1.82.beta/includes/modifyform.inc.php
<?php
/**
 *
 * @version $Id: modifyform.inc.php,v 1.16 2004/01/18 20:12:29 freedev Exp $
 * @package wa_includes
 * @author Vincenzo D'Amore <hide@address.com>
 */

/**
 * function: GetNewIdValue
 * @param $iIdForm
 */
function GetNewIdValue($iIdForm)
{
	$IdValue = -1;

	$recNewId = new WARecordset();
	$recNewId->SetupFromGlobalCnn();
	$rec = new WARecordset();
	$rec->SetupFromGlobalCnn();

	$query = "SELECT tbtables.WATableKeyValue, tbtables.WAIdTable FROM tbtables, tbforms WHERE tbtables.WAIdTable = tbforms.WAIdTable AND tbforms.WAIdForm = ".$iIdForm;
	$rec->WAOpenRecordset($query);
	if ($rec->WAFetchRow())
	{
		$IdTable = (int)$rec->WAResult("WAIdTable");
		$IdValue = (int)$rec->WAResult("WATableKeyValue");
		$rec->WACloseRecordset();
		if ($IdTable > 0)
		{
			$query = "UPDATE tbtables SET WATableKeyValue = ". ($IdValue +1) ." WHERE WAIdTable = ".$IdTable;
			if ($IdValue > 0)
				$query .= " AND WATableKeyValue = ".$IdValue;
/*			echo $query; */
			$recNewId->WAOpenRecordset($query);
			if ($recNewId->WANumRows() <= 0)
				$IdValue = -1;
			else
				$IdValue ++;
			$recNewId->WACloseRecordset();
		}
	}
	return $IdValue;
}

/**
 * function: ExecuteSql
 * @param $sSql, &$Form
 * description:
*/
function ExecuteSql($sSql, &$Form)
{
	$bRC = False;
	$rec = new WARecordset();
	$rec->SetConnection($Form);
	$rec->WAOpenRecordset($sSql);
	if ($rec->WANumRows() > 0)
		$bRC = true;
	$rec->WACloseRecordset();
	return $bRC;
}

/**
 * function: ClearAllForms
 * @param none
 * description:
*/

function ClearAllForms()
{
	unset($_SESSION["gaForms"]);
}

/**
 * function: BuildForm
 * @param $IdForm, $iCurrentForm, $bGrantCheck = true
 * description:
*/
function BuildForm($IdForm, $iCurrentForm, $bGrantCheck = true)
{
	$sRC = NULL;

//	$UID = $IdForm."_".$_SESSION["giIdContext"]."_".$iCurrentForm;
	$UID = $_SESSION["giIdContext"]."_".$IdForm."_".$iCurrentForm;
	if ((!isset($_SESSION["gaForms"])) ||
		(!is_array($_SESSION["gaForms"])))
	{
		$_SESSION["gaForms"] = array();
	}

	$gaForms = &$_SESSION["gaForms"];

//	echo "Entering BuildForm ".$UID . "<br>";
//	echo array_key_exists($UID, $gaForms);

	if ((!empty($IdForm)) &&
		(! array_key_exists($UID, $gaForms)) )
//		(! @is_array($gaForms[$UID])) )
	{
//		echo "BuildForm ".$UID."<br>";
		$rec = new WARecordset();
		$rec->SetupFromGlobalCnn();

		$sSqlFields = "SELECT tbtables.WATableKeyField, tbtables.WATableName, tbforms.WAEventHandler, ";
		$sSqlFields .= " tbforms.WADescr, tbforms.WAIdForm, tbforms.WACustomScript, ";
		if ($bGrantCheck)
			$sSqlFields .= " tbgroupsforms.WAActions, ";
		$sSqlFields .= " tbfields.*, tbfieldsdesc.WAFieldShortD ";
		$sSqlFields .= " FROM (((tbfields LEFT JOIN tbfieldsdesc ON tbfields.WAIdField = tbfieldsdesc.WAIdField) ";
		$sSqlFields .= "  INNER JOIN tbforms ON tbfields.WAIdForm = tbforms.WAIdForm) ";
		$sSqlFields .= "  INNER JOIN tbtables ON tbforms.WAIdTable = tbtables.WAIdTable) ";
		if ($bGrantCheck)
			$sSqlFields .= "  INNER JOIN tbgroupsforms ON tbgroupsforms.WAIdForm = tbforms.WAIdForm ";
		$sSqlFields .= " WHERE tbforms.WAIdForm = tbfields.WAIdForm AND";
		$sSqlFields .= " tbforms.WAIdTable = tbtables.WAIdTable AND";
		if ($bGrantCheck)
		{
//			$sSqlFields .= " tbgroupsforms.WAIdGroup = ". $_SESSION["giIdGroup"]. " AND";
			$sSqlFields .= " tbgroupsforms.WAIdGroup in ( ". $_SESSION["giIdGroup"];
			if (!empty($_SESSION["gsOtherGroups"]))
				$sSqlFields .= ", ".$_SESSION["gsOtherGroups"];
			$sSqlFields .= ") AND";
		}
		if ($GLOBALS['WA_LOCATION'] == "IT")
			$sSqlFields .= " (tbfieldsdesc.WAIdLang IS NULL OR tbfieldsdesc.WAIdLang = 1 ) AND";
		else
			$sSqlFields .= " (tbfieldsdesc.WAIdLang IS NULL OR tbfieldsdesc.WAIdLang = 2 ) AND";
		
		$sSqlFields .= " tbforms.WAIdForm = ".$IdForm." ORDER BY tbfields.WASortValue";
		$recFields = $rec->WAOpenRecordset($sSqlFields);
		$Form = array();
		if ($rec->WAFetchRow($recFields))
		{
			$Form = array(
				"WAIdForm"			=> $rec->WAResult("WAIdForm"),
				"WAUID"				=> $UID,
				"WATableName"		=> $rec->WAResult("WATableName"),
				"WACustomScript"	=> $rec->WAResult("WACustomScript"),
				"WAEventHandler"	=> $rec->WAResult("WAEventHandler"),
				"WADescr"			=> $rec->WAResult("WADescr"),
				"WATableKeyField"	=> $rec->WAResult("WATableKeyField"),
				"WACurrentAction"	=> "",
				"WALastAction"		=> "",
				"WAUIDParent"		=> "",
				"WALoadedContents"	=> False,
				"WAUIDChild"		=> "",
				"WAKeyValue"		=> "",
				"WAChildKeyField"	=> "",
				"WAHiddenKeyField" => "",
				"WAHiddenKeyValue" => ""
				);
			$Fields = array();
			$TablesRel = array();
			if ($bGrantCheck)
				$Form["WAActions"] = $rec->WAResult("WAActions");
			$WAId = 0;
			do
			{
			@	$Description = $rec->WAResult("WAFieldShortD");
				if (empty($Description))
					$Description = $rec->WAResult("WADescription");
//				echo $WAKey." ". $WAId."<br>";
				$WAFieldKey = $rec->WAResult("WAField");
				$Fields[$WAFieldKey] = array(
				"WAId"				=> $WAId,
				"WAField"			=> $WAFieldKey,
				"WADescription"		=> $Description,
				"WAIdType"			=> $rec->WAResult("WAIdType"),
				"WASize"			=> $rec->WAResult("WASize"),
				"WAMaxLength"		=> $rec->WAResult("WAMaxLength"),
				"WAIdRefType"		=> $rec->WAResult("WAIdRefType"),
				"WARefTable"		=> $rec->WAResult("WARefTable"),
				"WAIdDisplayType" 	=> $rec->WAResult("WAIdDisplayType"),
				"WARefFieldValue" 	=> $rec->WAResult("WARefFieldValue"),
				"WARefFieldDesc"  	=> $rec->WAResult("WARefFieldDesc"),
				"WAIdLinkedForm"	=> $rec->WAResult("WAIdLinkedForm"),
				"WASortValue"		=> $rec->WAResult("WASortValue"),
				"WAMandatory"		=> $rec->WAResult("WAMandatory"),
				"WARowBreak"		=> $rec->WAResult("WARowBreak"),
				"WASummary"			=> $rec->WAResult("WASummary"),
				"WADefaultValue"	=> $rec->WAResult("WADefaultValue"),
				"WAHidden"			=> $rec->WAResult("WAHidden"),
				"WAPrepAction"		=> $rec->WAResult("WAPrepAction"),
				"WAPostAction"		=> $rec->WAResult("WAPostAction"),
				"WAValue"			=> "",
				"WATag"				=> "");
				if (($Fields[$WAFieldKey]["WAIdType"] == WA_NUMERIC) &&
					(!empty($Fields[$WAFieldKey]["WAIdLinkedForm"])) &&
					(!empty($Fields[$WAFieldKey]["WARefFieldValue"])) )
				{
					$TablesRel[] = array(
					"WAUIDChild"		=>  "",
					"WAField"			=>  $Fields[$WAFieldKey]["WAField"],
					"WAIdFormChild"		=>  $Fields[$WAFieldKey]["WAIdLinkedForm"],
					"WAFieldChild"		=>  $Fields[$WAFieldKey]["WARefFieldValue"],
					"WAIdRelType"		=>  WA_REL_ONE,
					"WADescr"			=>  $Fields[$WAFieldKey]["WADescription"]);
				}
				elseif (($Fields[$WAFieldKey]["WAIdType"] == WA_LIST) &&
					(!empty($Fields[$WAFieldKey]["WAIdLinkedForm"])) &&
					(!empty($Fields[$WAFieldKey]["WARefFieldValue"])) )
				{
					$TablesRel[] = array(
					"WAUIDChild"		=>  "",
					"WAField"			=>  $Fields[$WAFieldKey]["WAField"],
					"WAIdFormChild"		=>  $Fields[$WAFieldKey]["WAIdLinkedForm"],
					"WAFieldChild"		=>  $Fields[$WAFieldKey]["WARefFieldValue"],
					"WAIdRelType"		=>  WA_REL_LIST,
					"WADescr"			=>  $Fields[$WAFieldKey]["WADescription"]);
				}
				$WAId++;
			} while ($rec->WAFetchRow());

			$Fields[$Form["WATableKeyField"]] = array(
			"WAId"				=> $WAId,
			"WAField"			=> $Form["WATableKeyField"],
			"WADescription"		=> $Form["WATableKeyField"],
			"WAIdType"			=> WA_KEYNUM,
			"WASize"			=> "",
			"WAMaxLength"		=> "",
			"WAIdRefType"		=> "",
			"WARefTable"		=> "",
			"WAIdDisplayType" 	=> "",
			"WARefFieldValue" 	=> "",
			"WARefFieldDesc"  	=> "",
			"WAIdLinkedForm"	=> "",
			"WASortValue"		=> "",
			"WAMandatory"		=> "",
			"WARowBreak"		=> "",
			"WASummary"			=> "",
			"WADefaultValue"	=> "",
			"WAHidden"			=> "",
			"WAPrepAction"		=> "",
			"WAPostAction"		=> "",
			"WAValue"			=> "",
			"WATag"				=> "");
			
			$Form["WAFields"] = $Fields;

			$sSqlFields = "SELECT tbtables.WATableKeyField,  tbtablesrel.WAIdFormChild, tbtablesrel.WAFieldChild, tbtablesrel.WADescr FROM tbtablesrel, tbforms, tbtables ";
			$sSqlFields .= " WHERE tbtablesrel.WAIdForm = ".$Form["WAIdForm"] ;
			$sSqlFields .= " AND tbforms.WAIdForm = tbtablesrel.WAIdFormChild";
			$sSqlFields .= " AND tbtables.WAIdTable = tbforms.WAIdTable";
			$sSqlFields .= " ORDER BY tbtablesrel.WASortValue";
			$recTablesRel = new WARecordset();
			$recTablesRel->SetupFromGlobalCnn();
			$recTablesRel->WAOpenRecordset($sSqlFields);
			if ($recTablesRel->WAFetchRow())
			{
				do
				{
					$WAFieldChild = $recTablesRel->WAResult("WAFieldChild");
					if (empty($WAFieldChild))
						$WAFieldChild = $Form["WATableKeyField"];
					$TablesRel[] = array(
					"WAUIDChild"		=>  "",
					"WAField"			=>  $Form["WATableKeyField"],
					"WAIdFormChild"		=>  $recTablesRel->WAResult("WAIdFormChild"),
					"WAFieldChild"		=>  $WAFieldChild,
					"WAIdRelType"		=>  WA_REL_MULTI,
					"WADescr"			=>  $recTablesRel->WAResult("WADescr"));
				} while ($recTablesRel->WAFetchRow());
			}
			$recTablesRel->WACloseRecordset();

			$Form["WATablesRel"] = $TablesRel;

			/*
			$sSql = "SELECT tbdatabases.WAHost, tbdatabases.WADBName, tbdatabases.WAUser,";
//			$sSql .= " tbdatabases.WADateS, tbdatabases.WADateE, tbdatabases.WADateTimeS, tbdatabases.WADateTimeE,";
//			$sSql .= " tbdatabases.WATimeS, tbdatabases.WATimeE, tbdatabases.WAWildcard,";
			$sSql .= " tbdatabases.WAPassword, tbdbtype.WADBType";
			$sSql .= " FROM tbforms, tbtables, tbdatabases, tbdbtype";
			$sSql .= " WHERE tbtables.WAIdDataBase = tbdatabases.WAIdDataBase";
			$sSql .= " AND tbdatabases.WAIdDBType = tbdbtype.WAIdDBType";
			$sSql .= " AND tbtables.WAIdTable = tbforms.WAIdTable AND tbforms.WAIdForm = ".$IdForm;

			$recDbInfo = new WARecordset();
			$recDbInfo->SetupFromGlobalCnn();
			$recDbInfo->WAOpenRecordset($sSql);

			$aDBInfo = array();

			if ($recDbInfo->WAFetchRow())
			{
				$aDBInfo = array(
					"WAHost"			=> $recDbInfo->WAResult("WAHost"),
					"WADBName"			=> $recDbInfo->WAResult("WADBName"),
					"WAUser"			=> $recDbInfo->WAResult("WAUser"),
					"WAPassword"		=> $recDbInfo->WAResult("WAPassword"),
					"WADBType"			=> $recDbInfo->WAResult("WADBType") );

//				$Form["WAWildcard"]		= $recDbInfo->WAResult("WAWildcard");
//				$Form["WADateS"]		= $recDbInfo->WAResult("WADateS");
//				$Form["WADateE"]		= $recDbInfo->WAResult("WADateE");
//				$Form["WADateTimeS"]	= $recDbInfo->WAResult("WADateTimeS");
//				$Form["WADateTimeE"]	= $recDbInfo->WAResult("WADateTimeE");
//				$Form["WATimeS"]		= $recDbInfo->WAResult("WATimeS");
//				$Form["WATimeE"]		= $recDbInfo->WAResult("WATimeE");
			}
			$recDbInfo->WACloseRecordset();

			$Form["WADBInfo"] = $aDBInfo;
*/
			$sRC = $UID;
			$gaForms[$UID] = $Form;
		}
//  	$gaForms[$IdForm] = $Form;
//		echo "<pre>"; print_r($_SESSION["gaForms"]); echo "</pre>";
		$rec->WACloseRecordset();
	}
	else
		$sRC = $UID;
	return $sRC;
}

/**
 * function: GetGroupInfo
 * @param $IdGroup, &$sGroupName, &$bAdmin
 * description:
*/
function GetGroupInfo($IdGroup, &$sGroupName, &$bAdmin)
{
	$bRC = False;
	$rec = new WARecordset();
	$rec->SetupFromGlobalCnn();

	if ($IdGroup > 0)
	{
		$query = "SELECT * FROM tbgroups WHERE tbusers.WAIdGroup = ".$IdGroup;

		$rec->WAOpenRecordset($query);

		if ($rec->WAFetchRow())
		{
			$GroupName = $rec->WAResult("WAGroupName");
			$bAdmin = $rec->WAResult("WAAdmin");
			$bRC = true;
		}
		else
		{
			$GroupName = "";
			$bAdmin = "";
		}
		$rec->WACloseRecordset();
	}
	return $bRC;
}

/**
 * function: GetUserInfo
 * @param $IdUser, &$Name, &$Surname
 * description:
*/
function GetUserInfo($IdUser, &$Username, &$Name, &$Surname)
{
	$bRC = False;
	$rec = new WARecordset();
	$rec->SetupFromGlobalCnn();

	if ($IdUser > 0)
	{
		$query = "SELECT * FROM tbusers WHERE tbusers.WAIdUser = " . $IdUser ;

		$rec->WAOpenRecordset($query);

		if ($rec->WAFetchRow())
		{
			$Username = $rec->WAResult("WAUser");
			$Name = $rec->WAResult("WAName");
			$Surname = $rec->WAResult("WASurname");
			$bRC = true;
		}
		else
		{
			$Username = "";
			$Name = "";
			$Surname = "";
		}
		$rec->WACloseRecordset();
	}
	return $bRC;
}

function CreateFieldSearchSql(&$Field, &$sSqlFields2)
{
	$aFieldDescList = array();
	$lCount = 0;
	if (strlen($Field["WARefFieldDesc"]) > 0)
	{
		$sSqlFields2 = "SELECT ".$Field["WARefTable"].".".$Field["WARefFieldValue"];
		$aFieldDescList = WASplit(', ', $Field["WARefFieldDesc"]);
		$lCount = count($aFieldDescList);
		for ($i = 0; $i < $lCount; $i++)
		{
			$sSqlFields2 .= ", (".$Field["WARefTable"].".".$aFieldDescList[$i].") AS ".$aFieldDescList[$i]."_".$Field["WAId"];
		}
		$sSqlFields2 .= " FROM ". $Field["WARefTable"];
//		echo $sSqlFields2."<br>";
	}
}

function CreateForm(&$formValues, &$_POST)
{
	$Form = &$formValues["Form"];
	$Fields = &$Form["WAFields"];

//	echo "<pre>"; print_r($Form); echo "</pre>";
//	echo $Form["WALoadedContents"]. " ". $Form["WATableKeyValue"] ." && ".$Form["WATableKeyField"]." && ".$formValues["bVerify"]."<br>";
	if ((!empty($Form["WATableKeyField"])) &&
		(!empty($Form["WAKeyValue"])) &&
		(!$formValues["bVerify"]) )
	{
		if (!$Form["WALoadedContents"])
		{
			if (LoadDbContents($Form))
				LoadContents($Form, $_POST);
		}
	}

//	echo "<pre>"; print_r($Form); echo "</pre>";
//	echo "<pre>"; print_r($_POST); echo "</pre>";
//	ShowArrayContent($Form);

	// Ricerca le informazioni legate nella tabella tbFields dove
	// trovare le indicazione per realizzare la form
	$OldRowBreak = -1;
	reset($Fields);
	$iCounter = 0;
//	while($CurKey = Key($Fields))
//	{
	while (list($CurKey, $Field) = each ($Fields))
	{
//		$CurField = $Form["WAUID"]."_".$Field["WAField"];
//		$Field = &$Fields[$CurKey];
		if ($OldRowBreak == -1)
		{
			echo "<tr>";
			echo "<td width='25%' nowrap valign='top'>";
		}

		if ((!empty($Field["WAPrepAction"])) &&
			(function_exists($Field["WAPrepAction"])) )
 			$Field["WAPrepAction"]($Form, $_POST);

		restore_error_handler();

		$CurField = $Form["WAUID"]."_".$Field["WAField"];
		if (($formValues["bSummary"] && !$Field["WASummary"]) ||
			 ($Field["WAHidden"]) ) //
//			 && (empty($Field["WAIdLinkedForm"])) )
		{
		}
		else
		{
			if (($Field["WAIdType"] != WA_KEYNUM) &&
				($Field["WAIdType"] != WA_KEYUSEROWNER) &&
				($Field["WAIdType"] != WA_KEYGROUPOWNER) &&
				($Field["WAIdType"] != WA_USERID) &&
				($Field["WAField"] != $Form["WAHiddenKeyField"]))
			{
				echo "&nbsp;\n";
				if ($Field["WAMandatory"] != 0)
					echo "<span class=\"FieldStdM\">";
				else
					echo "<span class=\"FieldStd\">";
				echo htmlentities($Field["WADescription"]);
				echo "</span>\n";
				echo "&nbsp;\n";
			}
			elseif ((($Field["WAIdType"] == WA_KEYUSEROWNER) || 
					 ($Field["WAIdType"] == WA_KEYGROUPOWNER) || 
					 ($Field["WAIdType"] == WA_USERID)) &&
					($_SESSION["giAdmin"]) )
			{
				echo "&nbsp;\n";
				if ($Field["WAMandatory"] != 0)
					echo "<span class=\"FieldStdM\">";
				else
					echo "<span>";
				echo htmlentities($Field["WADescription"]);
				echo "</span>\n";
				echo "&nbsp;\n";
			}
		}
		if ($Field["WAField"] == $Form["WAHiddenKeyField"])
		{
			if (empty($Form["WAHiddenKeyValue"]))
				echo "<input type='hidden' name='text".$CurField."' value=''>";
			else
				echo "<input type='hidden' name='text".$CurField."' value='".$Form["WAHiddenKeyValue"]."'>";
		}
		elseif ($Field["WAIdType"] == WA_KEYNUM)
		{
			if (empty($Form["WAKeyValue"]))
				echo "<input type='hidden' name='text".$CurField."' value=''>";
			else
				echo "<input type='hidden' name='text".$CurField."' value='".$Field["WATag"]."'>";
//			echo "<span class='Inputs'>\n". htmlentities(stripcslashes($Field["WATag"]), ENT_QUOTES)."</span>\n";
		}
		elseif ((($Field["WAIdType"] == WA_USERID) ||
				 ($Field["WAIdType"] == WA_KEYUSEROWNER) ))
		{
			if ($_SESSION["giAdmin"])
			{
				if (!$formValues["bVerify"])
				{
					$query = "SELECT * FROM tbusers ORDER BY WAUser";
					echo "<span class='FieldStd'>\n";
					$usersList = new WARecordset();
					$usersList->SetupFromGlobalCnn();
					$usersList->WAOpenRecordset($query);
					echo "<select class='Selects' name='text".$CurField."'>";
					echo "<option value=''>--";
					while ($usersList->WAFetchRow())
					{
						$optValue = $usersList->WAResult("WAIdUser");
						$sUserInfo = $usersList->WAResult("WAUser");
						echo "<option value='".$optValue."'";
						// Se c'e' un valore precedemente selezionato lo imposta come default
						if (!empty($Field["WATag"]) &&
							($Field["WATag"] == $optValue))
							echo " selected";
						echo ">";
						echo htmlentities($sUserInfo, ENT_QUOTES);
					}
					echo "</select>";
					$usersList->WACloseRecordset() ;
				}
				else
				{
					echo "<span class='InputsVerify'>\n";
					$sUser = "";
					$sUserName = "";
					$sUserSurname = "";
					GetUserInfo($Field["WATag"], $sUser, $sUserName, $sUserSurname);
					$sUserInfo = $sUser;
					echo "<input type='hidden' name='text".$CurField."' value='".$Field["WATag"]."'>";
					echo "&nbsp;".htmlentities($sUserInfo, ENT_QUOTES)."&nbsp;";
				}
				echo "</span>";
			}
		}
		elseif ($Field["WAIdType"] == WA_KEYGROUPOWNER)
		{
			if ($_SESSION["giAdmin"])
			{
				if (!$formValues["bVerify"])
				{
					$query = "SELECT * FROM tbgroups ORDER BY WAGroupName";
					echo "<span class='FieldStd'>\n";
					$usersList = new WARecordset();
					$usersList->SetupFromGlobalCnn();
					$usersList->WAOpenRecordset($query);
					echo "<select class='Selects' name='text".$CurField."'>";
					echo "<option value=''>--";
					while ($usersList->WAFetchRow())
					{
						$optValue = $usersList->WAResult("WAIdGroup");
						$sUserInfo = $usersList->WAResult("WAGroupName");
						echo "<option value='".$optValue."'";
						// Se c'e' un valore precedemente selezionato lo imposta come default
						if (!empty($Field["WATag"]) &&
							($Field["WATag"] == $optValue))
							echo " selected";
						echo ">";
						echo htmlentities($sUserInfo, ENT_QUOTES);
					}
					echo "</select>";
					$usersList->WACloseRecordset() ;
				}
				else
				{
					echo "<span class='InputsVerify'>\n";
					$bAdmin = 0;
					$sGroupName = "";
					GetGroupInfo($Field["WATag"], $sGroupName, $bAdmin);
					echo "<input type='hidden' name='text".$CurField."' value='".$Field["WATag"]."'>";
					echo "&nbsp;".htmlentities($sGroupName, ENT_QUOTES)."&nbsp;";
				}
				echo "</span>";
			}
		}
		elseif (($formValues["bSummary"]) && (!$Field["WASummary"]) )
//				 (empty($Field["WAIdLinkedForm"])) )
		{
			// Do nothing
		}
		elseif (($Field["WAIdType"] == WA_LIST) &&
				(!empty($Field["WARefTable"])) &&
				(!empty($Field["WAField"])) )
		{
//			echo "<pre>"; print_r($Field); echo "</pre>";

			$aFieldDescList = WASplit(', ', $Field["WARefFieldDesc"]);
			$lCount = count($aFieldDescList);

			$sSqlFields2 = "";
			CreateFieldSearchSql($Field, $sSqlFields2);

//			echo $sSqlFields2."<br>";
			if ($formValues["bVerify"])
			{
				echo "<span class='InputsVerify'>\n";
				if (!empty($Field["WATag"]) )
				{
					$sSqlFields2 .= " WHERE ".$Field["WARefTable"].".".$Field["WARefFieldValue"];
					$sSqlFields2 .= " IN ( ".$Field["WATag"]." )";
					$sSqlFields2 .=" ORDER BY ".$Field["WARefFieldDesc"];
					$valueList = new WARecordset();
					$valueList->SetConnection($Form);
					$valueList->WAOpenRecordset($sSqlFields2);
					$optValue = "";
					while ($valueList->WAFetchRow())
					{
						if (!empty($optValue))
						echo ",&nbsp;";
						$optValue = $valueList->WAResult($Field["WARefFieldValue"]);
						for ($i = 0; $i < $lCount; $i++)
						{
							if ($i > 0)
								echo "&nbsp;";
							echo htmlentities($valueList->WAResult($aFieldDescList[$i]."_".$Field["WAId"]), ENT_QUOTES);
						}
					}
					$valueList->WACloseRecordset() ;
				}
			}
			else
			{
				echo "<span class='FieldStd'>\n";
				echo "<select class='Selects' name='sele".$CurField."' multiple size='".$Field["WASize"]."'>";
				if (!empty($Field["WATag"]) )
				{
					$sSqlFields2 .= " WHERE ".$Field["WARefTable"].".".$Field["WARefFieldValue"];
					$sSqlFields2 .= " IN ( ".$Field["WATag"]." )";
					$sSqlFields2 .=" ORDER BY ".$Field["WARefFieldDesc"];
					$valueList = new WARecordset();
					$valueList->SetConnection($Form);
					$valueList->WAOpenRecordset($sSqlFields2);
					while ($valueList->WAFetchRow())
					{
						$optValue = $valueList->WAResult($Field["WARefFieldValue"]);
						echo "<option value='$optValue'>";
						for ($i = 0; $i < $lCount; $i++)
						{
							if ($i > 0)
								echo "&nbsp;";
							echo htmlentities($valueList->WAResult($aFieldDescList[$i]."_".$Field["WAId"]), ENT_QUOTES);
						}
						echo "</option>";
					}
					$valueList->WACloseRecordset() ;
				}
				else
					echo "<option value=''>";
				echo "</select>";
			}
			echo "<input type='hidden' name='text".$CurField."' value='".$Field["WATag"]."'>\n";
			echo "</span>\n";
		}
		elseif ((!empty($Field["WARefTable"])) && (!empty($Field["WAIdDisplayType"])) )
		{
			if (!empty($Field["WARefTable"]) &&
				($Field["WAIdDisplayType"] == WA_DISPLAY_COMBO))
			{
//				echo "<pre>"; print_r($Field); echo "</pre>";

				$aFieldDescList = WASplit(', ', $Field["WARefFieldDesc"]);
				$lCount = count($aFieldDescList);

				$sSqlFields2 = "";
				CreateFieldSearchSql($Field, $sSqlFields2);

//				echo $sSqlFields2."<br>";
				if ($formValues["bVerify"])
				{
					echo "<span class='InputsVerify'>\n";
					echo "<input type='hidden' name='text".$CurField."' value='".$Field["WATag"]."'>";
					if (!empty($Field["WATag"]))
					{
						$sSqlFields2 .= " WHERE " . $Field["WARefFieldValue"] . " = ";
						if ($Field["WAIdType"] == WA_NUMERIC)
							$sSqlFields2 .= $Field["WATag"];
						if ($Field["WAIdType"] == WA_STRING)
							$sSqlFields2 .= "'".htmlentities(stripcslashes($Field["WATag"]), ENT_QUOTES)."'";
	//					echo "$sSqlFields2 <br>".$Field["WATag"];
						$valueList = new WARecordset();
						$valueList->SetConnection($Form);
						$valueList->WAOpenRecordset($sSqlFields2);
						if ($valueList->WAFetchRow())
						{
//							echo $valueList->WAResult($Field["WARefFieldDesc"]);
							for ($i = 0; $i < $lCount; $i++)
							{
								echo "&nbsp;";
								echo htmlentities($valueList->WAResult($aFieldDescList[$i]."_".$Field["WAId"]), ENT_QUOTES);
							}
							echo "&nbsp;";
						}
						$valueList->WACloseRecordset() ;
					}
				}
				else
				{
					echo "<span class='FieldStd'>\n";
					$sSqlFields2 .=" ORDER BY ".$Field["WARefFieldDesc"];
					$valueList = new WARecordset();
					$valueList->SetConnection($Form);
					$valueList->WAOpenRecordset($sSqlFields2);
					echo "<select class='Selects' name='text".$CurField."'>";
					echo "<option value=''>--";
					while ($valueList->WAFetchRow())
					{
						$optValue = $valueList->WAResult($Field["WARefFieldValue"]);
						echo "<option value='$optValue'";
						// Se c'e' un valore precedemente selezionato lo imposta come default
						if (!empty($Field["WATag"]) &&
							($Field["WATag"] == $optValue))
							echo " selected";
						echo ">";
						for ($i = 0; $i < $lCount; $i++)
						{
							if ($i > 0)
								echo "&nbsp;";
							echo htmlentities($valueList->WAResult($aFieldDescList[$i]."_".$Field["WAId"]), ENT_QUOTES);
						}
					}
					echo "</select>";
					$valueList->WACloseRecordset() ;
				}
				echo "</span>\n";
			}
			if (!empty($Field["WARefTable"]) &&
				($Field["WAIdDisplayType"] == WA_DISPLAY_COSTANT))
			{
				$aFieldDescList = WASplit(', ', $Field["WARefFieldDesc"]);
				$lCount = count($aFieldDescList);

				$sSqlFields2 = "";
				CreateFieldSearchSql($Field, $sSqlFields2);

	//			echo $sSqlFields2."<br>";
				if ($formValues["bVerify"])
				{
					echo "<span class='InputsVerify'>\n";
					echo "<input type='hidden' name='text".$CurField."' value='".$Field["WATag"]."'>";
				}
				else
				{
					echo "<span class='Inputs'>\n";
					if (empty($Field["WATag"]))
						echo "&nbsp;";
					echo "<input type='hidden' name='text".$CurField."' value='".$Field["WATag"]."'>";
				}
				if (!empty($Field["WATag"]))
				{
					$sSqlFields2 .= " WHERE " . $Field["WARefFieldValue"] . " = ";
					if ($Field["WAIdType"] == WA_NUMERIC)
						$sSqlFields2 .= $Field["WATag"];
					if ($Field["WAIdType"] == WA_STRING)
						$sSqlFields2 .= "'".htmlentities(stripcslashes($Field["WATag"]), ENT_QUOTES)."'";
//					echo "$sSqlFields2 <br>".$Field["WATag"];

					$valueList = new WARecordset();
					$valueList->SetConnection($Form);
					$valueList->WAOpenRecordset($sSqlFields2);
					if ($valueList->WAFetchRow())
					{
						for ($i = 0; $i < $lCount; $i++)
						{
							echo "&nbsp;";
							echo htmlentities($valueList->WAResult($aFieldDescList[$i]."_".$Field["WAId"]), ENT_QUOTES);
						}
						echo "&nbsp;";
					}
					$valueList->WACloseRecordset() ;
				}
				echo "</span>\n";
			}
		}
//		elseif ((empty($Field["WAIdLinkedForm"])) &&
//				(empty($Field["WARefTable"])))
		else
		{
			if ($Field["WAIdType"] == WA_FILE)
			{
				$sFile = htmlentities(stripcslashes($Field["WATag"]), ENT_QUOTES);
				$sFileName = basename($sFile);
				if (!$formValues["bVerify"])
				{
					echo "<span class='FieldStd'>\n";
					echo "<input type='hidden' name='text".$CurField."' value='".$sFile."'>";
					echo "<input type='text' name='disp".$CurField."'";
					echo " size='".WA_FILENAME_SIZE."' maxlength='".WA_FILENAME_MAXSIZE."'";
					echo " value='".$sFileName."'";
					echo " readonly >\n";
					echo "&nbsp;";
					if (!empty($sFile))
						echo "&nbsp;<input class='Buttons' type='button' name='cmdDownload' value='".WA_CMD_DOWNLOAD."' onclick=\"javascript:ShowAttachment('".$GLOBALS['WA_DOWNLOAD_URI'].$sFile."')\">";
					echo "&nbsp;<input class='Buttons' type='button' name='cmdUpload' value='".WA_CMD_ATTACH."' onclick=\"javascript:UploadPopup('".$Form['WAUID']."', '".$CurField."')\">";
//					echo "&nbsp;<input class='Buttons' type='button' name='cmdUpload' value='".WA_CMD_ATTACH."' onclick=\"javascript:UploadPopup('".$GLOBALS['WA_ABSOLUTE_URI']."', '".$Form['WAUID']."', '".$CurField."')\">";
					echo "&nbsp;<input class='Buttons' type='button' name='cmdDelete' value='".WA_CMD_DELETE."' onclick=\"javascript:DeleteAttachment('".$Form["WAUID"]."', '".$CurField."')\">";
				}
				else
				{
					echo "<span class='FieldStd'>\n";
					echo "<input type='hidden' name='text".$CurField."'";
						echo " value='".$sFile."'>\n";
					echo "<a class='Buttons' ";
						echo (!empty($sFileName)) ? " href='javascript:doNothing();' onclick='javascript:ShowAttachment(\"".$GLOBALS['WA_DOWNLOAD_URI'].$sFile."\")'" : "";
						echo ">\n &nbsp;".$sFileName."&nbsp;";
					echo "</a>\n";
				}
				echo "</span>\n";
			}
			elseif ($Field["WAIdType"] == WA_IMAGE)
			{
				$sFile = htmlentities(stripcslashes($Field["WATag"]), ENT_QUOTES);
				$sFileName = basename($sFile);
				if (!$formValues["bVerify"])
				{
					echo "<span class='FieldStd'>\n";
					echo "<input type='hidden' name='text".$CurField."' value='".$sFile."'>";
					echo "<input type='text' name='disp".$CurField."'";
					echo " size='".WA_FILENAME_SIZE."' maxlength='".WA_FILENAME_MAXSIZE."'";
					echo " value='".$sFileName."'";
					echo " readonly >\n";
					echo "&nbsp;";
					if (!empty($sFile))
						echo "&nbsp;<input class='Buttons' type='button' name='cmdDownload' value='".WA_CMD_DOWNLOAD."' onclick=\"javascript:ShowAttachment('".$GLOBALS['WA_DOWNLOAD_URI'].$sFile."')\">";
					echo "&nbsp;<input class='Buttons' type='button' name='cmdUpload' value='".WA_CMD_ATTACH."' onclick='javascript:UploadPopup(".$Form["WAUID"].", \"".$CurField."\")'>";
					echo "&nbsp;<input class='Buttons' type='button' name='cmdDelete' value='".WA_CMD_DELETE."' onclick='javascript:DeleteAttachment(".$Form["WAUID"].", \"".$CurField."\")'>";
				}
				else
				{
					echo "<span class='FieldStd'>\n";
					echo "<input type='hidden' name='text".$CurField."'";
						echo " value='".$sFile."'>\n";
					echo "<a class='Buttons' ";
						echo (!empty($sFileName)) ? " href='javascript:doNothing();' onclick='javascript:ShowAttachment(\"".$GLOBALS['WA_DOWNLOAD_URI'].$sFile."\")'" : "";
						echo ">\n &nbsp;".$sFileName."&nbsp;";
					echo "</a>\n";
				}
				echo "</span>\n";
			}
			elseif ($Field["WAIdType"] == WA_LONGTEXT)
			{
				if ($formValues["bVerify"])
				{
					echo "<span class='InputsVerify'>\n";
					echo "<input type='hidden' name='text".$CurField."' value='".htmlentities(stripcslashes($Field["WATag"]), ENT_QUOTES)."'>";
					echo htmlentities(stripcslashes($Field["WATag"]), ENT_QUOTES);
				}
				else
				{
					echo "<span class='FieldStd'>\n";
					echo "<TEXTAREA class='InputsTextArea' name='text".$CurField."'";
					echo " COLS='".$Field["WASize"]."'";
					echo " ROWS='".$Field["WAMaxLength"]."'>";
					echo htmlentities(stripcslashes($Field["WATag"]), ENT_QUOTES);
					echo "</TEXTAREA>";
				}
				echo "</span>\n";
			}
			elseif (($Field["WAIdType"] == WA_STRING) || ($Field["WAIdType"] == WA_NUMERIC))
			{
				if ($formValues["bVerify"])
				{
					echo "<span class='InputsVerify'>\n";
					echo "<input type='hidden' name='text".$CurField."' value='".htmlentities(stripcslashes($Field["WATag"]), ENT_QUOTES)."'>";
					echo htmlentities(stripcslashes($Field["WATag"]), ENT_QUOTES);
				}
				else
				{
					echo "<span class='FieldStd'>\n";
					echo "<input class='Inputs' type='text' name='text".$CurField."'";
					echo " size='".$Field["WASize"]."'";
					echo " maxlength='".$Field["WAMaxLength"]."'";
					echo " value='".htmlentities(stripcslashes($Field["WATag"]), ENT_QUOTES)."'>\n";
				}
				echo "</span>\n";
			}
			elseif ($Field["WAIdType"] == WA_PASSWORD)
			{
				if ($formValues["bVerify"])
				{
					echo "<span class='InputsVerify'>\n";
					echo "<input type='hidden' name='text".$CurField."' value='".md5(stripcslashes($Field["WATag"][0]))."'>";
					echo "<input type='hidden' name='text".$CurField."_repeat' value='".md5(stripcslashes($Field["WATag"][1]))."'>";
					echo "**********  **********";
				}
				else
				{
					echo "<span class='FieldStd'>\n";
					echo "<input class='Inputs' type='password' name='text".$CurField."'";
					echo " size='".$Field["WASize"]."'";
					echo " maxlength='".$Field["WAMaxLength"]."'";
					echo " value=''>\n";
					echo "<input class='Inputs' type='password' name='text".$CurField."_repeat'";
					echo " size='".$Field["WASize"]."'";
					echo " maxlength='".$Field["WAMaxLength"]."'";
					echo " value=''>\n";
				}
				echo "</span>\n";
			}
			elseif ($Field["WAIdType"] == WA_BOOLEAN)
			{
				if ($formValues["bVerify"]) 
				{
					echo "<span class='InputsVerify'>\n";
					echo "<input type='hidden' name='text".$CurField."' value='".htmlentities(stripcslashes($Field["WATag"]), ENT_QUOTES)."'>";
					echo ($Field["WATag"] == "TRUE") ? WA_LBL_TRUE : WA_LBL_FALSE;
				}
				else
				{
					echo "<span class='FieldStd'>\n";
					echo "<select class='Selects' name='text".$CurField."'>\n";
					echo "<option class='Selects' value=''>--";
					echo "<option value='TRUE'";
					if ((!empty($Field["WATag"])) && 
						($Field["WATag"] == "TRUE") )
						echo " selected ";
					echo ">".WA_LBL_TRUE;
					echo "<option value='FALSE'";
					if ((!empty($Field["WATag"])) && 
						($Field["WATag"] == "FALSE") )
						echo " selected ";
					echo ">".WA_LBL_FALSE;
					echo "</select>";
				}
				echo "</span>\n";
			}
			elseif ($Field["WAIdType"] == WA_DATE)
			{
				if (!isset($Field["WATag"]["seleGiorno"]))
				{
					$Field["WATag"]["seleGiorno"] = "";
				}
				if (!isset($Field["WATag"]["seleMese"]))
				{
					$Field["WATag"]["seleMese"] = "";
				}
				if (!isset($Field["WATag"]["seleAnno"]))
				{
					$Field["WATag"]["seleAnno"] = "";
				}
				if ($formValues["bVerify"])
				{
					echo "<span class='InputsVerify'>\n";
					echo "<input type='hidden' name='seleGiorno".$CurField."' value='".$Field["WATag"]["seleGiorno"]."'>";
					echo "<input type='hidden' name='seleMese".$CurField."' value='".$Field["WATag"]["seleMese"]."'>";
					echo "<input type='hidden' name='seleAnno".$CurField."' value='".$Field["WATag"]["seleAnno"]."'>";
					echo str_pad($Field["WATag"]["seleGiorno"], 2, "0",  STR_PAD_LEFT) . "/";
					echo str_pad($Field["WATag"]["seleMese"], 2, "0",  STR_PAD_LEFT) . "/";
					echo str_pad($Field["WATag"]["seleAnno"], 2, "0",  STR_PAD_LEFT) . " ";
				}
				else
				{
					echo "<span class='FieldStd'>\n";
					echo "<select class='Selects' name='seleGiorno".$CurField."'>\n";
					echo "<option class='Selects' value=''>--";
					for ($i = 1; $i <= 31; $i++)
					{
						echo "<option value='". $i ."'";
						if ($Field["WATag"]["seleGiorno"] == $i)
							echo " selected ";
						echo ">", $i;
					}
					echo "</select>";
					echo "&nbsp;<select class='Selects' name='seleMese".$CurField."'>\n";
					echo "<option class='Selects' value=''>--";
					for ($i = 1; $i <= 12; $i++)
					{
						echo "<option value='". $i ."'";
						if ($Field["WATag"]["seleMese"] == $i)
							echo " selected";
						echo ">". $i;
					}
					echo "</select>";
					echo "&nbsp;<input class='Inputs' type='text' name='seleAnno" . $CurField. "' size='4' maxlength='4'";
					echo " value='".$Field["WATag"]["seleAnno"]."'>\n";
					$curStack = "'".$Form["WAUID"]. "', '".$CurField."'";
					echo "&nbsp; <a href=\"javascript:ChooseDate(".$curStack.");\"><img src='images/choosedate.gif' align='middle' border='0'></a>";
				}
				echo "</span>\n";
			}
			elseif ($Field["WAIdType"] == WA_DATETIME)
			{
				if (!is_array($Field["WATag"]))
				{
					$Field["WATag"] = array();
					$Field["WATag"]["seleGiorno"] = "";
					$Field["WATag"]["seleMese"] = "";
					$Field["WATag"]["seleAnno"] = "";
					$Field["WATag"]["seleOra"] = "";
					$Field["WATag"]["seleMinuto"] = "";
					$Field["WATag"]["seleSecondo"] = "";
				}
				if (!isset($Field["WATag"]["seleGiorno"]))
				{
					$Field["WATag"]["seleGiorno"] = "";
				}
				if (!isset($Field["WATag"]["seleMese"]))
				{
					$Field["WATag"]["seleMese"] = "";
				}
				if (!isset($Field["WATag"]["seleAnno"]))
				{
					$Field["WATag"]["seleAnno"] = "";
				}
				if ($formValues["bVerify"])
				{
					echo "<span class='InputsVerify'>\n";
					echo "<input type='hidden' name='seleGiorno".$CurField."' value='".$Field["WATag"]["seleGiorno"]."'>";
					echo "<input type='hidden' name='seleMese".$CurField."' value='".$Field["WATag"]["seleMese"]."'>";
					echo "<input type='hidden' name='seleAnno".$CurField."' value='".$Field["WATag"]["seleAnno"]."'>";
					echo "<input type='hidden' name='seleOra".$CurField."' value='".$Field["WATag"]["seleOra"]."'>";
					echo "<input type='hidden' name='seleMinuto".$CurField."' value='".$Field["WATag"]["seleMinuto"]."'>";
					echo "<input type='hidden' name='seleSecondo".$CurField."' value='".$Field["WATag"]["seleSecondo"]."'>";

					
					if ((!empty($Field["WATag"]["seleGiorno"])) ||
						(!empty($Field["WATag"]["seleMese"])) ||
						(!empty($Field["WATag"]["seleAnno"])) )
					{
						echo str_pad($Field["WATag"]["seleGiorno"], 2, "0",  STR_PAD_LEFT) . "/";
						echo str_pad($Field["WATag"]["seleMese"], 2, "0",  STR_PAD_LEFT) . "/";
						echo str_pad($Field["WATag"]["seleAnno"], 2, "0",  STR_PAD_LEFT) . " ";
						$Field["WATag"]["seleOra"] = str_pad($Field["WATag"]["seleOra"], 2, "0",  STR_PAD_LEFT);
						$Field["WATag"]["seleMinuto"] = str_pad($Field["WATag"]["seleMinuto"], 2, "0",  STR_PAD_LEFT);
						$Field["WATag"]["seleSecondo"] = str_pad($Field["WATag"]["seleSecondo"], 2, "0",  STR_PAD_LEFT);
						echo $Field["WATag"]["seleOra"].":".$Field["WATag"]["seleMinuto"].":".$Field["WATag"]["seleSecondo"];
					}
				}
				else
				{
					echo "<span class='FieldStd'>\n";
					echo "<select class='Selects' name='seleGiorno".$CurField."'>\n";
					echo "<option class='Selects' value=''>--";
					for ($i = 1; $i <= 31; $i++)
					{
						echo "<option value='". $i ."'";
						if ($Field["WATag"]["seleGiorno"] == $i)
							echo " selected ";
						echo ">", $i;
					}
					echo "</select>";
					echo "&nbsp;<select class='Selects' name='seleMese".$CurField."'>\n";
					echo "<option class='Selects' value=''>--";
					for ($i = 1; $i <= 12; $i++)
					{
						echo "<option value='". $i ."'";
						if ($Field["WATag"]["seleMese"] == $i)
							echo " selected";
						echo ">". $i;
					}
					echo "</select>";
					echo "&nbsp;<input class='Inputs' type='text' name='seleAnno" . $CurField. "' size='4' maxlength='4'";
					echo " value='".$Field["WATag"]["seleAnno"]."'>\n";
					$curStack = "'".$Form["WAUID"]. "', '".$CurField."'";
					echo "&nbsp;<input type='image' src='images/choosedate.gif' align='absmiddle' border='0' onclick=\"javascript:ChooseDate(".$curStack.");return false;\">&nbsp;";
					echo "<input type='text' name='seleOra".$CurField."' value='".$Field["WATag"]["seleOra"]."' size='2'>\n";
					echo "<input type='text' name='seleMinuto".$CurField."' value='".$Field["WATag"]["seleMinuto"]."' size='2'>\n";
					echo "<input type='text' name='seleSecondo".$CurField."' value='".$Field["WATag"]["seleSecondo"]."' size='2'>\n";
				}
				echo "</span>\n";
			}
			elseif ($Field["WAIdType"] == WA_TIME)
			{
				if (!is_array($Field["WATag"]))
				{
					$Field["WATag"] = array();
					$Field["WATag"]["seleOra"] = "";
					$Field["WATag"]["seleMinuto"] = "";
					$Field["WATag"]["seleSecondo"] = "";
				}
				if ($formValues["bVerify"])
				{
					echo "<span class='InputsVerify'>\n";
					echo "<input type='hidden' name='seleOra".$CurField."' value='".$Field["WATag"]["seleOra"]."'>";
					echo "<input type='hidden' name='seleMinuto".$CurField."' value='".$Field["WATag"]["seleMinuto"]."'>";
					echo "<input type='hidden' name='seleSecondo".$CurField."' value='".$Field["WATag"]["seleSecondo"]."'>";

					if ((!empty($Field["WATag"]["seleOra"])) ||
						(!empty($Field["WATag"]["seleMinuto"])) ||
						(!empty($Field["WATag"]["seleSecondo"])) )
					{
						$Field["WATag"]["seleOra"] = str_pad($Field["WATag"]["seleOra"], 2, "0",  STR_PAD_LEFT);
						$Field["WATag"]["seleMinuto"] = str_pad($Field["WATag"]["seleMinuto"], 2, "0",  STR_PAD_LEFT);
						$Field["WATag"]["seleSecondo"] = str_pad($Field["WATag"]["seleSecondo"], 2, "0",  STR_PAD_LEFT);
						echo $Field["WATag"]["seleOra"].":".$Field["WATag"]["seleMinuto"].":".$Field["WATag"]["seleSecondo"];
					}
				}
				else
				{
					echo "<span class='FieldStd'>\n";					
					echo "<input type='text' name='seleOra".$CurField."' value='".$Field["WATag"]["seleOra"]."' size='2'>\n";
					echo "<input type='text' name='seleMinuto".$CurField."' value='".$Field["WATag"]["seleMinuto"]."' size='2'>\n";
					echo "<input type='text' name='seleSecondo".$CurField."' value='".$Field["WATag"]["seleSecondo"]."' size='2'>\n";
				}
				echo "</span>\n";
			}
			else
			{
				echo "<span class='FieldStd'>Invalid Type</span>\n";
			}
		}

		if ((!empty($Field["WAIdLinkedForm"])) &&
			(($Field["WAField"] != $Form["WAHiddenKeyField"])) )
		{
			if ($formUIDLinked = BuildForm($Field["WAIdLinkedForm"], $formValues["CurrentForm"] + 1))
			{
				if ((!$formValues["bVerify"])
						&& (!$formValues["bSummary"]))
				{
					if ((!empty($Field["WATag"])) && (($Field["WAIdType"] == WA_NUMERIC) || ($Field["WAIdType"] == WA_LIST) ))
					{
						echo "&nbsp;<input type='button' class='Buttons' onclick=\"javascript:SelectRecord('".$Form["WAUID"]."','";
						echo $formUIDLinked."','". $Field["WAField"]."','";
						echo $Field["WARefFieldValue"]."','";
						echo (($Field["WAIdType"] == WA_LIST) ? "1" : "0");
						echo "' )\" value='". WA_CMD_VIEW ."'>";
						echo "&nbsp;<input type='button' class='Buttons' onclick=\"javascript:DeleteListFieldElement('".$Form["WAUID"]."','";
						echo $Field["WAField"]."','".WA_MSG_WARNING_NOELEMSELECTED."')\" value='". WA_CMD_DELETE ."'>";
					}
					echo "&nbsp;<input type='button' class='Buttons' onclick=\"javascript:SelectRecord('".$Form["WAUID"]."','";
					echo $formUIDLinked."','". $Field["WAField"]."','','";
					echo (($Field["WAIdType"] == WA_LIST) ? "1" : "0");
					echo "')\" value='". WA_CMD_FIND ."'>";
				}
			}
		}

		if (($formValues["bSummary"] && $Field["WASummary"]) || (!$formValues["bSummary"]) )
		{
			if ((!empty($Field["WAPostAction"])) &&
				(function_exists($Field["WAPostAction"])) )
				$Field["WAPostAction"]($Form, $_POST);
			restore_error_handler();
		}

		if ($Field["WARowBreak"])
			echo "</td></tr>\n";
		$OldRowBreak = $Field["WARowBreak"];
//		next($Fields);
		$iCounter++;
	}
	if ($Field["WARowBreak"] != -1)
		echo "</td></tr>\n";
}

function DeleteMultiValue(&$Form, $KeyListValue)
{
	$bRC = false;
	$Fields = &$Form["WAFields"];
	if ((!empty($Form["WATableKeyField"])) && 
		(!empty($KeyListValue)) )
	{
		foreach ($Fields as $Field)
		{
			if (($Field["WAIdType"] == WA_LIST) &&
				(!empty($Field["WAField"])) )
			{
				$sSql = "DELETE FROM ".$Field["WAField"];
				$sSql .= " WHERE ".$Form["WATableKeyField"]." in (".$KeyListValue.")";
				ExecuteSql($sSql, $Form);
				$bRC = true;
			}
		}
	}
	return $bRC;
}

function InsertMultiValue(&$Form)
{
	$bRC = false;
	$Fields = &$Form["WAFields"];
	if ((!empty($Form["WATableKeyField"])) &&
		(!empty($Form["WAKeyValue"])) )
	{
		foreach ($Fields as $Field)
		{
			if (($Field["WAIdType"] == WA_LIST) &&
				(!empty($Field["WAField"])) &&
				(!empty($Field["WARefFieldValue"])))
			{
				if (!empty($Field["WATag"]))
					$CurValue = $Field["WATag"];
				else
					$CurValue = $Field["WADefaultValue"];
				if (!empty($CurValue))
				{
					$aListValues = WASplit(', ', $CurValue);
					$lCount = count($aListValues);
					for ($i = 0; $i < $lCount; $i++)
					{
						$sSql = "INSERT INTO ".$Field["WAField"]." (";
						$sSql .= $Form["WATableKeyField"].", ".$Field["WARefFieldValue"].") VALUES (";
						$sSql .= $Form["WAKeyValue"].", ".$aListValues[$i].")";
						ExecuteSql($sSql, $Form);
						$bRC = true;
					}
				}
			}
		}
	}
	return $bRC;
}

function CreateInsertSql(&$Form, &$sSql, &$sMissingFields, &$KeyValue, $bCommit)
{
	$bRC = true;
	$sFields = "";
	$sValues = "";
	$Fields = &$Form["WAFields"];
//	$FormDBInfo = &$Form["WADBInfo"];
	$FormDBInfo = &$GLOBALS["WADBInfo"];

	$sSql = "INSERT INTO ". $Form["WATableName"] ." (";

	foreach ($Fields as $Field)
	{
		if (!empty($Field["WATag"]))
			$CurValue = $Field["WATag"];
		else
			$CurValue = $Field["WADefaultValue"];

		if ((!empty($CurValue) && (!is_array($Field["WATag"])) &&
			($Field["WAIdType"] != WA_LIST) ) ||
			($Field["WAIdType"] == WA_KEYNUM))
		{
			if (($Field["WAIdType"] == WA_STRING) ||
				($Field["WAIdType"] == WA_FILE) ||
				($Field["WAIdType"] == WA_IMAGE) ||
				($Field["WAIdType"] == WA_LONGTEXT) )
			{
				if (!empty($sFields )) { $sFields .= ", ";	$sValues .= ", "; }
				$sFields .= $Field["WAField"];
				$sValues .= "'" . str_replace("'", "''", stripslashes($CurValue)) . "'";
			}
			elseif ($Field["WAIdType"] == WA_BOOLEAN)
			{
				if (!empty($sFields )) { $sFields .= ", ";	$sValues .= ", "; }
				$sFields .= $Field["WAField"];
				if ($CurValue == "TRUE")
					$sValues .= "-1";
				else
					$sValues .= "0";
			}
			elseif (($Field["WAIdType"] == WA_NUMERIC) ||
					($Field["WAIdType"] == WA_USERID) )
			{
				$Value = (int)$CurValue;
				if (!empty($sFields )) { $sFields .= ", ";	$sValues .= ", "; }
				$sFields .= $Field["WAField"];
				$sValues .=  $Value;
			}
			elseif (($Field["WAIdType"] == WA_KEYUSEROWNER) )
			{
				if (!empty($sFields )) { $sFields .= ", ";	$sValues .= ", "; }
				$sFields .= $Field["WAField"];
				if ($_SESSION["giAdmin"])
				{
					$Value = (int)$CurValue;
					$sValues .=  $Value;
				}
				else
					$sValues .= $_SESSION["giIdUser"];
			}
			elseif (($Field["WAIdType"] == WA_KEYGROUPOWNER) )
			{
				if (!empty($sFields )) { $sFields .= ", ";	$sValues .= ", "; }
				$sFields .= $Field["WAField"];
				if ($_SESSION["giAdmin"])
				{
					$Value = (int)$CurValue;
					$sValues .=  $Value;
				}
				else
					$sValues .= $_SESSION["giIdGroup"];
			}
			elseif ($Field["WAIdType"] == WA_KEYNUM)
			{
				if ($bCommit)
				{
					$IdValue = GetNewIdValue($Form["WAIdForm"]);
					if ($IdValue > 0)
					{
						if (!empty($sFields )) { $sFields .= ", ";	$sValues .= ", "; }
						$sFields .= $Field["WAField"];
						$sValues .= $IdValue;
						$KeyValue = $IdValue;
					}
					else
					{
						$bRC = False;
						if (!empty($sMissingFields )) $sMissingFields .= ", ";
						$sMissingFields .= $Field["WADescription"]. " (Chiave errata) ";
					}
				}
			}
			else
			{
				if (!empty($sFields )) { $sFields .= ", ";	$sValues .= ", "; }
				$sFields .= $Field["WAField"];
				$sValues .= "-1";
				$KeyValue = "-1";
			}
		}
		elseif (($Field["WAIdType"] == WA_DATE) &&
				(!empty($CurValue["seleGiorno"])) &&
				(!empty($CurValue["seleMese"])) &&
				(!empty($CurValue["seleAnno"])) )
		{
			if (!empty($sFields )) { $sFields .= ", ";	$sValues .= ", "; }
			$sFields .= $Field["WAField"];
			$sValues .=  $GLOBALS[$FormDBInfo["WADBType"]]["WADateS"] . $CurValue["seleAnno"] . "/";
			$sValues .=  $CurValue["seleMese"] . "/";
			$sValues .=  $CurValue["seleGiorno"] . $GLOBALS[$FormDBInfo["WADBType"]]["WADateE"];
		}
		elseif (($Field["WAIdType"] == WA_DATETIME) &&
				(!empty($CurValue["seleGiorno"])) &&
				(!empty($CurValue["seleMese"])) &&
				(!empty($CurValue["seleAnno"])) )
		{
			if (!empty($sFields )) { $sFields .= ", ";	$sValues .= ", "; }
			if (!isset($Field["WATag"]["seleOra"]))
				$Field["WATag"]["seleOra"] = 0;
			if (!isset($Field["WATag"]["seleMinuto"]))
				$Field["WATag"]["seleMinuto"] = 0;
			if (!isset($Field["WATag"]["seleSecondo"]))
				$Field["WATag"]["seleSecondo"] = 0;
			$sFields .= $Field["WAField"];
			$sValues .=  $GLOBALS[$FormDBInfo["WADBType"]]["WADateTimeS"] . $CurValue["seleAnno"] . "/";
			$sValues .=  $CurValue["seleMese"] . "/";
			$sValues .=  $CurValue["seleGiorno"] . " ";
			$sValues .=  $CurValue["seleOra"] . ":";
			$sValues .=  $CurValue["seleMinuto"] . ":";
			$sValues .=  $CurValue["seleSecondo"] . $GLOBALS[$FormDBInfo["WADBType"]]["WADateTimeE"];
		}
		elseif (($Field["WAIdType"] == WA_TIME) && 
				( (!empty($Field["WATag"]["seleOra"])) ||
				(!empty($Field["WATag"]["seleMinuto"])) ||
				(!empty($Field["WATag"]["seleSecondo"]))) )
		{
			if (!empty($sFields )) { $sFields .= ", ";	$sValues .= ", "; }
/*
			if (!isset($Field["WATag"]["seleOra"]))
				$Field["WATag"]["seleOra"] = "00";
			if (!isset($Field["WATag"]["seleMinuto"]))
				$Field["WATag"]["seleMinuto"] = "00";
			if (!isset($Field["WATag"]["seleSecondo"]))
				$Field["WATag"]["seleSecondo"] = "00";
*/
			$sFields .= $Field["WAField"];
			$sValues .=  $GLOBALS[$FormDBInfo["WADBType"]]["WATimeS"] . $CurValue["seleOra"] . ":";
			$sValues .=  $CurValue["seleMinuto"] . ":";
			$sValues .=  $CurValue["seleSecondo"] . $GLOBALS[$FormDBInfo["WADBType"]]["WATimeE"];
		}
		elseif ($Field["WAIdType"] == WA_PASSWORD)
		{
			if (!empty($sFields )) { $sFields .= ", ";	$sValues .= ", "; }
			$sFields .= $Field["WAField"];
			if ($CurValue[0] == $CurValue[1])
				$sValues .= "'".$CurValue[0]."'";
			else
			{
				$bRC = False;
				if (!empty($sMissingFields )) $sMissingFields .= ", ";
				$sMissingFields .= $Field["WADescription"]. " Invalid ";
			}
		}
		elseif ($Field["WAIdType"] == WA_USERID)
		{
			if (!empty($sFields )) { $sFields .= ", ";	$sValues .= ", "; }
			$sFields .= $Field["WAField"];
			if ($_SESSION["giAdmin"])
			{
				$Value = (int)$CurValue;
				$sValues .=  $Value;
			}
			else
				$sValues .= $_SESSION["giIdUser"];
		}
		elseif ($Field["WAIdType"] == WA_KEYUSEROWNER)
		{
			if (!empty($sFields )) { $sFields .= ", ";	$sValues .= ", "; }
			$sFields .= $Field["WAField"];
			if ($_SESSION["giAdmin"])
			{
				$Value = (int)$CurValue;
				$sValues .=  $Value;
			}
			else
				$sValues .= $_SESSION["giIdUser"];
		}
		elseif ($Field["WAIdType"] == WA_KEYGROUPOWNER)
		{
			if (!empty($sFields )) { $sFields .= ", ";	$sValues .= ", "; }
			$sFields .= $Field["WAField"];
			if ($_SESSION["giAdmin"])
			{
				$Value = (int)$CurValue;
				$sValues .=  $Value;
			}
			else
				$sValues .= $_SESSION["giIdGroup"];
		}
		elseif ($Field["WAIdType"] != WA_LIST)
		{
			if ($Field["WAMandatory"] != 0)
			{
				$bRC = False;
				if (!empty($sMissingFields )) $sMissingFields .= ", ";
				$sMissingFields .= $Field["WADescription"];
			}
			else
			{
				if (!empty($sFields )) { $sFields .= ", ";	$sValues .= ", "; }
				$sFields .= $Field["WAField"];
				$sValues .= "NULL";
			}
		}
	}
	$sSql .= $sFields . ") VALUES (" . $sValues . ")";
//	echo $sSql . "<BR>" . $sMissingFields . "<BR>";
	return $bRC;
}

function CheckMultiList(&$Form)
{
	$bRC = False;
	$Fields = &$Form["WAFields"];

	foreach ($Fields as $Field)
	{
		if ($Field["WAIdType"] == WA_LIST)
		{
			if (($Field["WATag"] != $Field["WAValue"]))
			{
				$bRC = true;
			}
		}
	}

	return $bRC;
}

function ValidateForm(&$Form, &$sMissingFields, &$bExecute)
{
	$bRC = false;
	$bMandatory = false;
	$bModified = false;
	$bCommit = false;
	$Fields = &$Form["WAFields"];

	foreach ($Fields as $Field)
	{
		if ($Field["WAMandatory"] != 0) 
		{
			if ((!is_array($Field["WATag"])) &&
				(empty($Field["WATag"])) &&
				(strlen($Field["WATag"]) == 0))
			{
				if (!empty($sMissingFields )) $sMissingFields .= ", ";
					$sMissingFields .= $Field["WADescription"];
				$bMandatory = true;
	//			echo "Manca: ".$Field["WADescription"]."<br>";
			}
			elseif ($Field["WAIdType"] == WA_PASSWORD)
			{
				// Check if the password are retyped correctly
				if ($Field["WATag"][0] != $Field["WATag"][1])
				{
					if (!empty($sMissingFields )) $sMissingFields .= ", ";
						$sMissingFields .= $Field["WADescription"];
					$bMandatory = true;
				}
				elseif ($Field["WATag"][0] == md5(""))
				{
					if (!empty($sMissingFields )) $sMissingFields .= ", ";
						$sMissingFields .= $Field["WADescription"];
					$bMandatory = true;
				}
				elseif ($Field["WATag"][0] != $Field["WAValue"][0])
				{
					$bModified = true;
					$bExecute = true;
				}
			}
		}
		elseif ($Field["WAIdType"] == WA_PASSWORD)
		{
			// Check if the password are retyped equally
			if ($Field["WATag"][0] != $Field["WATag"][1])
			{
				if (!empty($sMissingFields )) $sMissingFields .= ", ";
					$sMissingFields .= $Field["WADescription"];
				$bMandatory = true;
				$bExecute = true;
			}
		}
		if	((!is_array($Field["WATag"])) &&
			($Field["WATag"] != $Field["WAValue"]))
		{
			$bModified = true;
			if ($Field["WAIdType"] != WA_LIST)
				$bExecute = true;
		}
	}
	if ($bModified)
		$bRC = true;
	if ($bMandatory)
		$bRC = False;
	return $bRC;
}


function CreateModifySql(&$Form, &$sSql, &$sMissingFields)
{
	$bRC = true;
	$sPairs = "";
	$sWhere = "";
	$Fields = &$Form["WAFields"];
//	$FormDBInfo = &$Form["WADBInfo"];
	$FormDBInfo = &$GLOBALS["WADBInfo"];

	$sSql = "Update ". $Form["WATableName"];
	foreach ($Fields as $Field)
	{
		if (($Field["WAMandatory"] != 0) &&
			(empty($Field["WATag"])) &&
			(strlen($Field["WATag"]) == 0))
		{
			$bRC = False;
		}

		if (($Field["WAIdType"] == WA_KEYNUM) || 
			($Field["WAIdType"] == WA_KEYUSEROWNER) ||
			($Field["WAIdType"] == WA_KEYGROUPOWNER) ||
			((!is_array($Field["WATag"])) && ($Field["WATag"] != $Field["WAValue"]) &&
			($Field["WAIdType"] != WA_LIST) ))
		{
//			echo $Field["WATag"]." != ".$Field["WAValue"]."<BR>";
			if (($Field["WAIdType"] == WA_STRING) ||
				($Field["WAIdType"] == WA_FILE) ||
				($Field["WAIdType"] == WA_IMAGE) ||
				($Field["WAIdType"] == WA_LONGTEXT) )
			{
				if (!empty($sPairs )) { $sPairs .= ", "; }
				$sPairs .= $Field["WAField"]. "= '" . str_replace("'", "''", $Field["WATag"]) . "'";
			}
			elseif ($Field["WAIdType"] == WA_BOOLEAN)
			{
				if (!empty($sPairs )) { $sPairs .= ", "; }
				$sPairs .= $Field["WAField"];
				if ($Field["WATag"] == "TRUE")
					$sPairs .=  "= -1";
				else
					$sPairs .= "= 0";
			}
			elseif (($Field["WAIdType"] == WA_NUMERIC) ||
					($Field["WAIdType"] == WA_USERID) )
			{
				$Value = (int)$Field["WATag"];
				if (!empty($sPairs )) { $sPairs .= ", ";}
				if (strlen($Field["WATag"]) == 0)
					$sPairs .= $Field["WAField"] ." = NULL";
				else
					$sPairs .= $Field["WAField"] ." = ". $Value;
			}
			elseif ((($Field["WAIdType"] == WA_KEYUSEROWNER) || 
					 ($Field["WAIdType"] == WA_KEYGROUPOWNER)) && 
					($_SESSION["giAdmin"]))
			{
				if ($Field["WATag"] != $Field["WAValue"])
				{
					$Value = (int)$Field["WATag"];
					if (!empty($sPairs )) { $sPairs .= ", ";}
					if (strlen($Field["WATag"]) == 0)
						$sPairs .= $Field["WAField"] ." = NULL";
					else
						$sPairs .= $Field["WAField"] ." = ". $Value;
				}
			}
			elseif ($Field["WAIdType"] == WA_KEYNUM)
			{
				if (!empty($sWhere)) $sWhere .= " AND ";
				$sWhere .= $Field["WAField"] ." = ". $Field["WATag"];
				if (empty($Field["WATag"]))
				{
//					echo "WA_KEYNUM<br>";
					$bRC = False;
				}
			}
			elseif (($Field["WAIdType"] == WA_KEYUSEROWNER)  && 
					(!$_SESSION["giAdmin"]))
			{
				if (!empty($sWhere)) $sWhere .= " AND ";
				$sWhere .= $Field["WAField"] ." = ". $_SESSION["giIdUser"];
			}
			elseif (($Field["WAIdType"] == WA_KEYGROUPOWNER) && 
					(!$_SESSION["giAdmin"]))
			{
				if (!empty($sWhere)) $sWhere .= " AND ";
				$sWhere .= $Field["WAField"] ." = ". $_SESSION["giIdGroup"];
			}
		}
		elseif (($Field["WAIdType"] == WA_DATE) &&
				(!empty($Field["WATag"]["seleGiorno"])) &&
				(!empty($Field["WATag"]["seleMese"])) &&
				(!empty($Field["WATag"]["seleAnno"])) )
		{
			if (($Field["WATag"]["seleGiorno"] != $Field["WAValue"]["seleGiorno"]) ||
				($Field["WATag"]["seleMese"] != $Field["WAValue"]["seleMese"]) ||
				($Field["WATag"]["seleAnno"] != $Field["WAValue"]["seleAnno"]))
			{
				if (!empty($sPairs )) { $sPairs .= ", ";}
				$sPairs .= $Field["WAField"];
				$sPairs .=  " = ".$GLOBALS[$FormDBInfo["WADBType"]]["WADateS"] . $Field["WATag"]["seleAnno"] . "/";
				$sPairs .=  $Field["WATag"]["seleMese"] . "/";
				$sPairs .=  $Field["WATag"]["seleGiorno"] . $GLOBALS[$FormDBInfo["WADBType"]]["WADateE"];
			}
		}
		elseif (($Field["WAIdType"] == WA_DATETIME) &&
				(!empty($Field["WATag"]["seleGiorno"])) &&
				(!empty($Field["WATag"]["seleMese"])) &&
				(!empty($Field["WATag"]["seleAnno"])) )
		{
			if (($Field["WATag"]["seleGiorno"] != $Field["WAValue"]["seleGiorno"]) ||
				($Field["WATag"]["seleMese"] != $Field["WAValue"]["seleMese"]) ||
				($Field["WATag"]["seleAnno"] != $Field["WAValue"]["seleAnno"]) ||
				($Field["WATag"]["seleOra"] != $Field["WAValue"]["seleOra"]) ||
				($Field["WATag"]["seleMinuto"] != $Field["WAValue"]["seleMinuto"]) ||
				($Field["WATag"]["seleSecondo"] != $Field["WAValue"]["seleSecondo"]))
			{
				if (!empty($sPairs )) { $sPairs .= ", ";}
/*
				if (!isset($Field["WATag"]["seleOra"]))
					$Field["WATag"]["seleOra"] = 0;
				if (!isset($Field["WATag"]["seleMinuto"]))
					$Field["WATag"]["seleMinuto"] = 0;
				if (!isset($Field["WATag"]["seleSecondo"]))
					$Field["WATag"]["seleSecondo"] = 0;
*/
				$sPairs .= $Field["WAField"];
				$sPairs .=  " = ".$GLOBALS[$FormDBInfo["WADBType"]]["WADateTimeS"] . $Field["WATag"]["seleAnno"] . "/";
				$sPairs .=  $Field["WATag"]["seleMese"] . "/";
				$sPairs .=  $Field["WATag"]["seleGiorno"];
 				if ( (!empty($Field["WATag"]["seleOra"])) ||
				(!empty($Field["WATag"]["seleMinuto"])) ||
				(!empty($Field["WATag"]["seleSecondo"])))
				{
					$sPairs .= " ".$Field["WATag"]["seleOra"] . ":";
					$sPairs .=  $Field["WATag"]["seleMinuto"] . ":";
					$sPairs .=  $Field["WATag"]["seleSecondo"] ;
				}
				$sPairs .=  $GLOBALS[$FormDBInfo["WADBType"]]["WADateTimeE"];
			}
		}
		elseif (($Field["WAIdType"] == WA_TIME) &&
				( (!empty($Field["WATag"]["seleOra"])) ||
				(!empty($Field["WATag"]["seleMinuto"])) ||
				(!empty($Field["WATag"]["seleSecondo"]))) )
		{
			if (($Field["WATag"]["seleOra"] != $Field["WAValue"]["seleOra"]) ||
				($Field["WATag"]["seleMinuto"] != $Field["WAValue"]["seleMinuto"]) ||
				($Field["WATag"]["seleSecondo"] != $Field["WAValue"]["seleSecondo"]))
			{
				if (!empty($sPairs )) { $sPairs .= ", ";}
/*
				if (!isset($Field["WATag"]["seleOra"]))
					$Field["WATag"]["seleOra"] = 0;
				if (!isset($Field["WATag"]["seleMinuto"]))
					$Field["WATag"]["seleMinuto"] = 0;
				if (!isset($Field["WATag"]["seleSecondo"]))
					$Field["WATag"]["seleSecondo"] = 0;
*/				$sPairs .= $Field["WAField"];
				$sPairs .=  " = ".$GLOBALS[$FormDBInfo["WADBType"]]["WATimeS"] . $Field["WATag"]["seleOra"] . ":";
				$sPairs .=  $Field["WATag"]["seleMinuto"] . ":";
				$sPairs .=  $Field["WATag"]["seleSecondo"] . $GLOBALS[$FormDBInfo["WADBType"]]["WATimeE"];
			}
		}
		elseif ($Field["WAIdType"] == WA_PASSWORD)
		{
			if (!empty($sPairs )) { $sPairs .= ", "; }
			if ($Field["WATag"][0] == $Field["WATag"][1])
				$sPairs .= $Field["WAField"]. "= '" . $Field["WATag"][0] . "'";
			else 
			{
				$bRC = False;
				if (!empty($sMissingFields )) $sMissingFields .= ", ";
				$sMissingFields .= $Field["WADescription"]. " Invalid ";
			}
		}
		elseif ($Field["WAIdType"] != WA_LIST)
		{
			if (($Field["WATag"] != $Field["WAValue"]))
			{
				if (!empty($sPairs )) { $sPairs .= ", ";}
				$sPairs .= $Field["WAField"] ." = NULL";
			}
		}
	}
	if (!empty($sPairs))
		$sSql .= " SET " .$sPairs;
	else
		$bRC = false;
	if (!empty($sWhere))
		$sSql .= " WHERE " . $sWhere;
	else
		$bRC = false;
//	echo $sSql . "<BR>" .  $bRC. " " . false . "<BR>" . $sMissingFields . "<BR>";
	return $bRC;
}

function CreateDeleteSql(&$Form, $sDeleteList, &$sSql)
{
	$bRC = False;
	$sSql = "DELETE FROM ".$Form["WATableName"];
	$sWhere = "";
	if ((!empty($sDeleteList)) && (!empty($Form["WATableKeyField"])))
	{
		$token = strtok($sDeleteList, ",");
		while ($token)
		{
			if (!empty($sWhere))
				$sWhere .= " or ";
			$sWhere .= $Form["WATableKeyField"] . "=" . $token;
		    $token = strtok(",");
		}
	}
	$sSql .= " WHERE " . $sWhere;
	if (!empty($sWhere))
		$bRC = true;
//	echo $sSql ."<br>";
	return $bRC;
}

?>
Return current item: WebArchive