Location: PHPKode > projects > WebArchive > phparchive.0.1.82.beta/includes/contents.inc.php
<?php
/**
 * Contents

 * Long description for testing purpose

 * @version $Id: contents.inc.php,v 1.10 2004/01/18 20:08:42 freedev Exp $
 * @author Vincenzo DAmore <hide@address.com>
 * @filesource
 * @package wa_includes
 */

/**
 * function UnlinkAttachments
 * another contributor authored this function
 * @author Vincenzo DAmore <hide@address.com>
 */

function UnlinkAttachments(&$Form, $KeyName, $sDeleteList)
{
	$Fields = &$Form["WAFields"];

	$bRC = False;
	$sSql = "SELECT * FROM ".$Form["WATableName"];
	$sWhere = "";
	if ((!empty($sDeleteList)) && (!empty($KeyName)))
	{
		$token = strtok($sDeleteList, ",");
		while ($token)
		{
			if (!empty($sWhere))
				$sWhere .= " or ";
			$sWhere .= $KeyName . "=" . $token;
		    $token = strtok(",");
		}
		$sSql .= " WHERE " . $sWhere;
		if (!empty($sWhere))
		{
			$recValues = new WARecordset();
			$recValues->SetConnection($Form);
			$recValues->WAOpenRecordset($sSql);
			if ($recValues->WAFetchRow())
			{
				do
				{
					reset($Fields);
					while (list($Key, $Field) = each ($Fields))
					{
						if (($Field["WAIdType"] == WA_FILE) ||
							($Field["WAIdType"] == WA_IMAGE) )
						{
							$Fields[$Key]["WAValue"] = $recValues->WAResult($Field["WAField"]);
							$path_parts = pathinfo($Fields[$Key]["WAValue"]);
							if (is_dir($GLOBALS['WA_UPLOAD_DIR'].$path_parts["dirname"]))
								unlink($GLOBALS['WA_UPLOAD_DIR'].$Fields[$Key]["WAValue"]);
//								unlink($sUserDir."/".$path_parts["basename"]);
								echo "unlink " . $GLOBALS['WA_UPLOAD_DIR'].$Fields[$Key]["WAValue"];
							rmdir($GLOBALS['WA_UPLOAD_DIR'].$path_parts["dirname"]);
						}
					}
				}
				while ($recValues->WAFetchRow());
			}
			$recValues->WACloseRecordset();
		}
	}
	return $bRC;
}

/**
 * Load fields with the given recordset
 * 
 * @author Vincenzo DAmore <hide@address.com>
 */

function Recordset2Fields(&$Fields, &$recValues, &$Form)
{
	$bRC = False;
	reset($Fields);
	while (list($Key, $Field) = each ($Fields))
	{
		if ($Field["WAIdType"] == WA_LIST)
		{
			$sSql = "SELECT ".$Field["WAField"].".".$Field["WARefFieldValue"];
			$sSql .= " FROM ".$Field["WAField"];
			$sSql .= " WHERE ".$Form["WATableKeyField"]." = ".$Form["WAKeyValue"];
			$valueList = new WARecordset();
			$valueList->SetConnection($Form);
			$valueList->WAOpenRecordset($sSql);
			$Fields[$Key]["WAValue"] = "";
			while ($valueList->WAFetchRow())
			{
				if (!empty($Fields[$Key]["WAValue"]))
					$Fields[$Key]["WAValue"] .= ", ";
				$Fields[$Key]["WAValue"] .= $valueList->WAResult($Field["WARefFieldValue"]);
			}
			$valueList->WACloseRecordset();
		}
		elseif (!empty($Field["WARefTable"]))
		{
			$Fields[$Key]["WAValue"] = $recValues->WAResult($Field["WAField"]);
		}
		elseif ($Field["WAIdType"] == WA_KEYUSEROWNER)
		{
			if ($_SESSION["giAdmin"])
				$Fields[$Key]["WAValue"] = $recValues->WAResult($Field["WAField"]);
			else
				$Fields[$Key]["WAValue"] = $_SESSION["giIdUser"];
		}
		elseif ($Field["WAIdType"] == WA_KEYGROUPOWNER)
		{
			if ($_SESSION["giAdmin"])
				$Fields[$Key]["WAValue"] = $recValues->WAResult($Field["WAField"]);
			else
				$Fields[$Key]["WAValue"] = $_SESSION["giIdGroup"];
		}
		elseif (($Field["WAIdType"] == WA_KEYNUM) ||
				($Field["WAIdType"] == WA_STRING) ||
				($Field["WAIdType"] == WA_NUMERIC) ||
				($Field["WAIdType"] == WA_FILE) ||
				($Field["WAIdType"] == WA_IMAGE) ||
				($Field["WAIdType"] == WA_USERID) ||
				($Field["WAIdType"] == WA_LONGTEXT) )
		{
			$Fields[$Key]["WAValue"] = $recValues->WAResult($Field["WAField"]);
		}
		elseif ($Field["WAIdType"] == WA_PASSWORD) 
		{
			$Fields[$Key]["WAValue"] = array();
			$Fields[$Key]["WAValue"][0] = $recValues->WAResult($Field["WAField"]);
			$Fields[$Key]["WAValue"][1] = $recValues->WAResult($Field["WAField"]);
		}
		elseif ($Field["WAIdType"] == WA_BOOLEAN)
		{
			$Fields[$Key]["WAValue"] = ($recValues->WAResult($Field["WAField"])) ? "TRUE" : "FALSE";
		}
		elseif ($Field["WAIdType"] == WA_DATE)
		{
			$Fields[$Key]["WAValue"] = array();
			$Fields[$Key]["WAValue"]["seleAnno"] = substr($recValues->WAResult($Field["WAField"]), 0, 4);
			$Fields[$Key]["WAValue"]["seleMese"] = substr($recValues->WAResult($Field["WAField"]), 5, 2);
			$Fields[$Key]["WAValue"]["seleGiorno"] = substr($recValues->WAResult($Field["WAField"]), 8, 2);
		}
		elseif ($Field["WAIdType"] == WA_DATETIME)
		{
			$Fields[$Key]["WAValue"] = array();
			$Fields[$Key]["WAValue"]["seleAnno"] = substr($recValues->WAResult($Field["WAField"]), 0, 4);
			$Fields[$Key]["WAValue"]["seleMese"] = substr($recValues->WAResult($Field["WAField"]), 5, 2);
			$Fields[$Key]["WAValue"]["seleGiorno"] = substr($recValues->WAResult($Field["WAField"]), 8, 2);
			$Fields[$Key]["WAValue"]["seleOra"] = substr($recValues->WAResult($Field["WAField"]), 11, 2);
			$Fields[$Key]["WAValue"]["seleMinuto"] = substr($recValues->WAResult($Field["WAField"]), 14, 2);
			$Fields[$Key]["WAValue"]["seleSecondo"] = substr($recValues->WAResult($Field["WAField"]), 17, 2);
		}
		elseif ($Field["WAIdType"] == WA_TIME)
		{
			$Fields[$Key]["WAValue"] = array();
			$Fields[$Key]["WAValue"]["seleOra"] = substr($recValues->WAResult($Field["WAField"]), 0, 2);
			$Fields[$Key]["WAValue"]["seleMinuto"] = substr($recValues->WAResult($Field["WAField"]), 3, 2);
			$Fields[$Key]["WAValue"]["seleSecondo"] = substr($recValues->WAResult($Field["WAField"]), 6, 2);
		}
		else
		{
			$Fields[$Key]["WAValue"] = "";
		}
		$Fields[$Key]["WATag"] = $Fields[$Key]["WAValue"];
	}
	return $bRC;
}

function LoadDbContents(&$Form)
{
//	echo "LoadDbContents ".$Form["WAUID"]." in Session<br>";
	$bRC = False;
	$Fields = &$Form["WAFields"];

	$recValues = new WARecordset();
	$recValues->SetConnection($Form);

	if ((!empty($Form["WATableKeyField"])) && (!empty($Form["WAKeyValue"])) )
	{
		$sSqlValues = "SELECT * FROM " . $Form["WATableName"] . " WHERE " . $Form["WATableKeyField"] . " = " . $Form["WAKeyValue"] ;
		if ($recValues->WAOpenRecordset($sSqlValues))
		{
			if ($recValues->WAFetchRow())
			{
				Recordset2Fields($Fields, $recValues, $Form);
				$bRC = True;
			}
		}
		$recValues->WACloseRecordset();
	}
	return $bRC;
}

function ClearContents(&$Form, &$_POST)
{
//	echo "ClearContents ".$Form["WAUID"]." in Session<br>";
	$Fields = &$Form["WAFields"];
	reset ($Fields);
	while (list($Key, $Field) = each ($Fields))
	{
		$CurField = $Form["WAUID"]."_".$Field["WAField"];
		if ($Field["WAIdType"] == WA_DATE)
		{
			if (is_array($Field["WATag"]))
			{
				$_POST["seleAnno".$CurField] = NULL;
				$_POST["seleMese".$CurField] = NULL;
				$_POST["seleGiorno".$CurField] = NULL;
			}
		}
		elseif ($Field["WAIdType"] == WA_DATETIME)
		{
			if (is_array($Field["WATag"]))
			{
				$_POST["seleAnno".$CurField] = NULL;
				$_POST["seleMese".$CurField] = NULL;
				$_POST["seleGiorno".$CurField] = NULL;
				$_POST["seleOra".$CurField] = NULL;
				$_POST["seleMinuto".$CurField] = NULL;
				$_POST["seleSecondo".$CurField] = NULL;
			}
		}
		elseif ($Field["WAIdType"] == WA_TIME)
		{
			if (is_array($Field["WATag"]))
			{
				$_POST["seleOra".$CurField] = NULL;
				$_POST["seleMinuto".$CurField] = NULL;
				$_POST["seleSecondo".$CurField] = NULL;
			}
		}
		else
		{
			$_POST["text".$CurField] = "";
		}
		$Fields[$Key]["WATag"] = NULL;
		$Fields[$Key]["WAValue"] = NULL;
	}
	$Form["WALoadedContents"] = False;
}

function SetKeyInfo(&$Form, &$_POST)
{
	$bRC = False;
	$formUID = $Form["WAUID"];
//	if (!empty($_POST[$formUID."_KeyField"]))
//		$Form["WATableKeyField"] = $_POST[$formUID."_KeyField"];
	if (!empty($_POST[$formUID."_KeyValue"]))
		$Form["WAKeyValue"] = $_POST[$formUID."_KeyValue"];

	if (!empty($_POST[$formUID."_hdnChildIdForm"]))
	{
		$Form["WAUIDChild"] = $_POST[$formUID."_hdnChildIdForm"];
	}
	if (!empty($_POST[$formUID.'_hdnChildKeyField']))
		$Form["WAChildKeyField"] = $_POST[$formUID.'_hdnChildKeyField'];
	if (!empty($_POST[$formUID.'_hdnChildRelType']))
		$Form["WAChildRelType"] = $_POST[$formUID.'_hdnChildRelType'];

//	echo $formUID." = SetKeyInfo(WAKeyField:".$Form["WATableKeyField"]." WAKeyValue:".$Form["WATableKeyValue"]." WAUIDChild:".$Form["WAUIDChild"].")<br>";
//	if ((!empty($_POST[$formUID."_KeyField"])) &&
//		(!empty($_POST[$formUID."_KeyValue"])) )
	if (!empty($_POST[$formUID."_KeyValue"])) 
	{
		$bRC = True;
		$Form["WALoadedContents"] = False;
	}
	return $bRC;
}

function DelKeyInfo(&$Form, &$_POST)
{
	$formUID = $Form["WAUID"];
//	$_POST[$formUID."_KeyField"] = "";
	$_POST[$formUID."_KeyValue"] = "";
	$_POST[$formUID."_hdnChildIdForm"] = "";
//	$Form["WATableKeyField"] = "";
	$Form["WAKeyValue"] = "";
	$Form["WAUIDChild"] = "";
	$Form["WAChildKeyField"] = "";
	$Form["WALoadedContents"] = False;
//	echo "DelKeyInfo $formUID in Session<br>";
}

function SetHttpPostForm(&$Form, &$_POST, $FieldName, $Value)
{
	$Fields = &$Form["WAFields"];
	$Field = &$Fields[$FieldName];
	$CurField = $Form["WAUID"]."_".$Field["WAField"];
	if ($Field["WAIdType"] == WA_KEYNUM)
	{
		$_POST["text".$CurField] = $Field["WATag"];
	}
	elseif ($Field["WAIdType"] == WA_KEYUSEROWNER)
	{
		if ($_SESSION["giAdmin"])
			$_POST["text".$CurField] = $Value;
		else
			$_POST["text".$CurField] = $_SESSION["giIdUser"];
	}
	elseif ($Field["WAIdType"] == WA_KEYGROUPOWNER)
	{
		if ($_SESSION["giAdmin"])
			$_POST["text".$CurField] = $Value;
		else
			$_POST["text".$CurField] = $_SESSION["giIdGroup"];
	}
	elseif (($Field["WAIdType"] == WA_STRING) || 
			($Field["WAIdType"] == WA_NUMERIC) ||
			($Field["WAIdType"] == WA_LIST) ||
			($Field["WAIdType"] == WA_FILE) ||
			($Field["WAIdType"] == WA_IMAGE) ||
			($Field["WAIdType"] == WA_USERID) ||
			($Field["WAIdType"] == WA_LONGTEXT) )
	{
		$_POST["text".$CurField] = $Value;
	}
	elseif ($Field["WAIdType"] == WA_PASSWORD)
	{
		$_POST["text".$CurField] = $Value;
		$_POST["text".$CurField."_repeat"] = $Value;
	}
	elseif ($Field["WAIdType"] == WA_BOOLEAN)
	{
		$_POST["text".$CurField] = $Value;
	}
	elseif ($Field["WAIdType"] == WA_DATE)
	{
		if (is_array($Field["WATag"]))
		{
			$_POST["seleAnno".$CurField] = $Value["seleAnno"];
			$_POST["seleMese".$CurField] = $Value["seleMese"];
			$_POST["seleGiorno".$CurField] = $Value["seleGiorno"] ;
		}
	}
	elseif ($Field["WAIdType"] == WA_DATETIME)
	{
		if (is_array($Value))
		{
			$_POST["seleAnno".$CurField] = $Value["seleAnno"];
			$_POST["seleMese".$CurField] = $Value["seleMese"];
			$_POST["seleGiorno".$CurField] = $Value["seleGiorno"] ;
			$_POST["seleOra".$CurField] = $Value["seleOra"];
			$_POST["seleMinuto".$CurField] = $Value["seleMinuto"];
			$_POST["seleSecondo".$CurField] = $Value["seleSecondo"];
		}
	}
	elseif ($Field["WAIdType"] == WA_TIME)
	{
		if (is_array($Value))
		{
			$_POST["seleOra".$CurField] = $Value["seleOra"];
			$_POST["seleMinuto".$CurField] = $Value["seleMinuto"];
			$_POST["seleSecondo".$CurField] = $Value["seleSecondo"];
		}
	}
	else
	{
		$_POST["text".$CurField] = $Value;
	}
}

function SaveContents(&$Form, &$_POST, &$aMessage, $bInit = False)
{
	$Fields = &$Form["WAFields"];
//	echo "<pre>"; print_r($Fields); echo "</pre>";
//	echo "<pre>"; print_r($_POST); echo "</pre>";
	reset($Fields);
	while (list($Key, $Field) = each ($Fields))
	{
		$CurField = $Form["WAUID"]."_".$Field["WAField"];
		if ($Field["WAIdType"] == WA_KEYUSEROWNER)
		{
			if (isset($_POST["text".$CurField]))
			{
				if ($_SESSION["giAdmin"])
					$Fields[$Key]["WATag"] = $_POST["text".$CurField];
				else
					$Fields[$Key]["WATag"] = $_SESSION["giIdUser"];
			}
		}
		elseif ($Field["WAIdType"] == WA_KEYGROUPOWNER)
		{
			if (isset($_POST["text".$CurField]))
			{
				if ($_SESSION["giAdmin"])
					$Fields[$Key]["WATag"] = $_POST["text".$CurField];
				else
					$Fields[$Key]["WATag"] = $_SESSION["giIdGroup"];
			}
		}
		elseif ($Field["WAIdType"] == WA_USERID)
		{
			if (isset($_POST["text".$CurField]))
			{
				if ($_SESSION["giAdmin"])
					$Fields[$Key]["WATag"] = $_POST["text".$CurField];
			}
		}
		elseif (($Field["WAIdType"] == WA_KEYNUM) ||
				($Field["WAIdType"] == WA_STRING) ||
				($Field["WAIdType"] == WA_NUMERIC) ||
				($Field["WAIdType"] == WA_LIST) ||
				($Field["WAIdType"] == WA_FILE) ||
				($Field["WAIdType"] == WA_IMAGE) ||
				($Field["WAIdType"] == WA_LONGTEXT) )
		{
			if (isset($_POST["text".$CurField]))
				$Fields[$Key]["WATag"] = stripslashes($_POST["text".$CurField]);
//			else
//				$Fields[$Key]["WATag"] = "";
		}
		elseif ($Field["WAIdType"] == WA_PASSWORD)
		{
			$Fields[$Key]["WATag"] = array();
			if (isset($_POST["text".$CurField]))
				$Fields[$Key]["WATag"][0] = md5(stripslashes($_POST["text".$CurField]));
			if (isset($_POST["text".$CurField."_repeat"]))
				$Fields[$Key]["WATag"][1] = md5(stripslashes($_POST["text".$CurField."_repeat"]));
		}
		elseif ($Field["WAIdType"] == WA_BOOLEAN)
		{
			if (isset($_POST["text".$CurField]))
				$Fields[$Key]["WATag"] = $_POST["text".$CurField];
//			else
//				$Fields[$Key]["WATag"] = "";
		}
		elseif ($Field["WAIdType"] == WA_DATE)
		{
			$Fields[$Key]["WATag"] = array();
			if (isset($_POST["seleAnno".$CurField]))
			{
				$Fields[$Key]["WATag"]["seleAnno"] = $_POST["seleAnno".$CurField];
				$Fields[$Key]["WATag"]["seleMese"] = $_POST["seleMese".$CurField];
				$Fields[$Key]["WATag"]["seleGiorno"] = $_POST["seleGiorno".$CurField];
			}
		}
		elseif ($Field["WAIdType"] == WA_DATETIME)
		{
			$Fields[$Key]["WATag"] = array();
			if (isset($_POST["seleAnno".$CurField]))
			{
				$Fields[$Key]["WATag"]["seleAnno"] = $_POST["seleAnno".$CurField];
				$Fields[$Key]["WATag"]["seleMese"] = $_POST["seleMese".$CurField];
				$Fields[$Key]["WATag"]["seleGiorno"] = $_POST["seleGiorno".$CurField];
				$Fields[$Key]["WATag"]["seleOra"] = $_POST["seleOra".$CurField];
				$Fields[$Key]["WATag"]["seleMinuto"] = $_POST["seleMinuto".$CurField];
				$Fields[$Key]["WATag"]["seleSecondo"] = $_POST["seleSecondo".$CurField];
			}
		}
		elseif ($Field["WAIdType"] == WA_TIME)
		{
			$Fields[$Key]["WATag"] = array();
			if (isset($_POST["seleOra".$CurField]))
			{
				$Fields[$Key]["WATag"]["seleOra"] = $_POST["seleOra".$CurField];
				$Fields[$Key]["WATag"]["seleMinuto"] = $_POST["seleMinuto".$CurField];
				$Fields[$Key]["WATag"]["seleSecondo"] = $_POST["seleSecondo".$CurField];
			}
		}
		else
		{
			if (isset($_POST["text".$CurField]))
				$Fields[$Key]["WATag"] = stripslashes($_POST["text".$CurField]);
		}
		if ($bInit)
			$Fields[$Key]["WAValue"] = $Fields[$Key]["WATag"];
	}
}

function LoadContents(&$Form, &$_POST)
{
//	echo "LoadContents ".$Form["WAUID"]." in Session<br>";
	$Fields = &$Form["WAFields"];
	reset($Fields);
	while (list($Key, $Field) = each ($Fields))
	{
		$CurField = $Form["WAUID"]."_".$Field["WAField"];
		if ($Field["WAIdType"] == WA_KEYNUM)
		{
			$_POST["text".$CurField] = $Field["WATag"];
		}
		elseif ($Field["WAIdType"] == WA_KEYUSEROWNER)
		{
			if ($_SESSION["giAdmin"])
				$_POST["text".$CurField] = $Field["WATag"];
			else
				$_POST["text".$CurField] = $_SESSION["giIdUser"];
		}
		elseif ($Field["WAIdType"] == WA_KEYGROUPOWNER)
		{
			if ($_SESSION["giAdmin"])
				$_POST["text".$CurField] = $Field["WATag"];
			else
				$_POST["text".$CurField] = $_SESSION["giIdGroup"];
		}
		elseif (($Field["WAIdType"] == WA_STRING) ||
				($Field["WAIdType"] == WA_NUMERIC) ||
				($Field["WAIdType"] == WA_LIST) ||
				($Field["WAIdType"] == WA_FILE) ||
				($Field["WAIdType"] == WA_IMAGE) ||
				($Field["WAIdType"] == WA_USERID) ||
				($Field["WAIdType"] == WA_LONGTEXT) )
		{
			$_POST["text".$CurField] = $Field["WATag"];
		}
		elseif ($Field["WAIdType"] == WA_PASSWORD)
		{
			if (is_array($Field["WATag"]))
			{
				$_POST["text".$CurField] = $Field["WATag"][0];
				$_POST["text".$CurField."_repeat"] = $Field["WATag"][1];
			}
		}
		elseif ($Field["WAIdType"] == WA_BOOLEAN)
		{
			$_POST["text".$CurField] = $Field["WATag"];
		}
		elseif ($Field["WAIdType"] == WA_DATE)
		{
			if (is_array($Field["WATag"]))
			{
				$_POST["seleAnno".$CurField] = $Field["WATag"]["seleAnno"];
				$_POST["seleMese".$CurField] = $Field["WATag"]["seleMese"];
				$_POST["seleGiorno".$CurField] = $Field["WATag"]["seleGiorno"] ;
			}
		}
		elseif ($Field["WAIdType"] == WA_DATETIME)
		{
			if (is_array($Field["WATag"]))
			{
				$_POST["seleAnno".$CurField] = $Field["WATag"]["seleAnno"];
				$_POST["seleMese".$CurField] = $Field["WATag"]["seleMese"];
				$_POST["seleGiorno".$CurField] = $Field["WATag"]["seleGiorno"] ;
				$_POST["seleOra".$CurField] = $Field["WATag"]["seleOra"];
				$_POST["seleMinuto".$CurField] = $Field["WATag"]["seleMinuto"];
				$_POST["seleSecondo".$CurField] = $Field["WATag"]["seleSecondo"];
			}
		}
		elseif ($Field["WAIdType"] == WA_TIME)
		{
			if (is_array($Field["WATag"]))
			{
				$_POST["seleOra".$CurField] = $Field["WATag"]["seleOra"];
				$_POST["seleMinuto".$CurField] = $Field["WATag"]["seleMinuto"];
				$_POST["seleSecondo".$CurField] = $Field["WATag"]["seleSecondo"];
			}
		}
		else
		{
			$_POST["text".$CurField] = $Field["WATag"];
		}
	}
	$Form["WALoadedContents"] = True;
}

function ShowChildForms(&$Form, &$_POST, &$ChildUIDForm, &$aMessage, $iCurrentForm)
{
//	echo "ShowChildForms ".$Form["WAUIDChild"]." ".$Form["WAKeyValue"]."<br>";
	$bSummary = False;

	if ((!empty($Form["WAUIDChild"])) ||
		((!empty($Form["WAKeyValue"])) && (!empty($Form["WATableKeyField"]))) )
	{
		$TableRel = "";
		$TablesRel = &$Form["WATablesRel"];
//			echo "<pre>"; print_r($TablesRel); echo "</pre>";
		if (($Form["WACurrentAction"] != "VI") &&
			($Form["WACurrentAction"] != "VM") )
		{
			if (count($TablesRel))
			{
				echo "<form name='formLinked_".$Form["WAUID"]."' class='Form' onsubmit='return setSubmitFired();' action=''>";
				if ($GLOBALS['WA_PRIVATE_SESSIONS'])
					echo '<INPUT type="hidden" name="'. WA_SESSION_NAME.'" value="'.session_id().'" >';
				echo "<!--- List Linked Table Start -->";
				echo '<table border="0" cellpadding="0" cellspacing="0" width="98%" class="FormTableE">';
				echo '<tr><td class="ButtonsTable">';
				reset($TablesRel);
//				foreach ($TablesRel as $TableRel)
				while (list($Key, $TableRel) = each($TablesRel))
				{
					$WAIdFormChild = $TableRel["WAIdFormChild"];
					if ($TableRel["WAUIDChild"] = BuildForm($WAIdFormChild, $iCurrentForm + 1))
					{
//						echo '<pre>'.$TableRel["WADescr"].' -> $TableRel["WAUIDChild"] = '.$TableRel["WAUIDChild"].' $Form["WAUIDChild"] = '.$Form["WAUIDChild"].' </pre>';
						if (($TableRel["WAUIDChild"] != $Form["WAUIDChild"] ) &&
							($TableRel["WAIdRelType"] == WA_REL_MULTI))
						{
							echo "<input type='button' class='Buttons' onclick=\"javascript:ShowChildForm('".$Form["WAUID"]."','".$TableRel["WAUIDChild"]."','".$TableRel["WAFieldChild"]."','".$TableRel["WAIdRelType"]."')\"";
							echo " value='".htmlentities(stripcslashes($TableRel["WADescr"]), ENT_QUOTES)."'>&nbsp;";
						}
					}
/*
					else
					{
						echo "Attenzione: Form ".htmlentities(stripcslashes($TableRel["WADescr"]), ENT_QUOTES)." non abilitata";
					}
*/
				}
				echo "</td></tr></table></form>";
			}
		}
		echo "<!--- List Linked Table End -->";
		echo "</td></tr><tr><td>";

		reset($TablesRel);
		while (list($Key, $TableRel) = each ($TablesRel))
		{
			$WAIdFormChild = $TableRel["WAIdFormChild"];

			if ($TableRel["WAUIDChild"] = BuildForm($WAIdFormChild, $iCurrentForm + 1 ))
			{
				if (($TableRel["WAUIDChild"] == $Form["WAUIDChild"] ) && ($TableRel["WAIdRelType"] == $Form["WAChildRelType"]))
				{
/*					echo "<pre>"; print_r($TableRel); echo "</pre>";				
					echo '<pre>$TableRel["WAUIDChild"]('.$TableRel["WAUIDChild"].') == $Form["WAUIDChild"]('.$Form["WAUIDChild"].") && <br>".
						 '$Form["WAChildRelType"]('.$Form["WAChildRelType"].') == $TableRel["WAIdRelType"]('.$TableRel["WAIdRelType"].') &&<br> '.
						 '$TableRel["WAFieldChild"]('.$TableRel["WAFieldChild"].') == $Form["WAChildKeyField"]('.$Form["WAChildKeyField"].') ||<br> '.
//						 $Form["WAUID"].' $Form["WACurrentAction"]('.$Form["WACurrentAction"].') $Form["WALastAction"]('.$Form["WALastAction"].')<br> '.
						 '$TableRel["WAField"]('.$TableRel["WAField"].') == $Form["WAChildKeyField"]('.$Form["WAChildKeyField"].')  <br>'.
						 '$TableRel["WAField"]('.$TableRel["WAField"].') == $Form["WAChildKeyField"]('.$Form["WAChildKeyField"].')  <br>';
*/
					if (($TableRel["WAFieldChild"] == $Form["WAChildKeyField"])  ||
						 ($TableRel["WAField"] == $Form["WAChildKeyField"]) ) 
					{
						$aForms = &$_SESSION["gaForms"];
						$FormRel = &$aForms[$TableRel["WAUIDChild"]];
						$FormRel["WAUIDParent"] = $Form["WAUID"];
	
						if ((empty($FormRel["WACurrentAction"])) &&
							($TableRel["WAIdRelType"] == WA_REL_MULTI))
							$FormRel["WACurrentAction"] = "F";
	
						echo "<!--- Linked Table Start -->";
						$LocalChildUIDForm = $TableRel["WAUIDChild"];
						FormContentBuild($FormRel, $_POST, $aMessage, $iCurrentForm + 1, $TableRel, $LocalChildUIDForm);
						echo "<!--- Linked Table End -->";
						echo "</td></tr><tr><td>";
	//					break;
	//					ShowChildForms($FormRel, $_POST, $LocalChildUIDForm, $aMessage, $iCurrentForm + 1);
					}
				}
			}
		}
	}
	else
	{
		$aMessage[$Form["WAUID"]] .= "<span class='ErrorMsg'>".WA_MSG_ERROR_STD. "</span><br>";
	}
	if (!empty($LocalChildUIDForm))
		$ChildUIDForm = $LocalChildUIDForm;
//	echo "ChildUIDForm: " . $ChildUIDForm. "<br>";
}

function ChildActionsHandle(&$Form, &$_POST, &$aMessage, $iCurrentForm)
{
//	echo "ChildActionsHandle ".$Form["WAUID"]."<br>";
//	$bSummary = False;

	if ((!empty($Form["WAUIDChild"])) ||
		((!empty($Form["WAKeyValue"])) && (!empty($Form["WATableKeyField"]))) )
	{
		$TableRel = "";
		$TablesRel = &$Form["WATablesRel"];
//		echo "<pre>"; print_r($TablesRel); echo "</pre>";

		reset($TablesRel);
//		foreach ($TablesRel as $TableRel)
		while (list($Key, $TableRel) = each ($TablesRel))
		{
			$WAIdFormChild = $TableRel["WAIdFormChild"];
//			echo "ChildActionsHandle ".$Form["WAUID"]." ".$Form["WAUIDChild"] ." ".$Key."<br>";
			if ($TableRel["WAUIDChild"] = BuildForm($WAIdFormChild, $iCurrentForm + 1))
			{
				// Memorizza il riferimento
				$TablesRel[$Key]["WAUIDChild"] = $TableRel["WAUIDChild"];
				if (($TableRel["WAUIDChild"] == $Form["WAUIDChild"] ) &&
					((($TableRel["WAFieldChild"] == $Form["WAChildKeyField"]) &&
						($TableRel["WAIdRelType"] == WA_REL_MULTI )) ||
					 (($TableRel["WAField"] == $Form["WAChildKeyField"]) &&
						($TableRel["WAIdRelType"] == WA_REL_ONE || $TableRel["WAIdRelType"] == WA_REL_LIST ) ) ) )
				{
					$aForms = &$_SESSION["gaForms"];
					$FormRel = &$aForms[$TableRel["WAUIDChild"]];
					$FormRel["WAUIDParent"] = $Form["WAUID"];

					if (!isset($aMessage[$TableRel["WAUIDChild"]]))
						$aMessage[$TableRel["WAUIDChild"]] = "";

					if ((empty($FormRel["WACurrentAction"])) &&
						($TableRel["WAIdRelType"] == WA_REL_MULTI))
						$FormRel["WACurrentAction"] = "F";

					FormActionsHandle($FormRel, $_POST, $aMessage, $iCurrentForm + 1, $TableRel);
					ChildActionsHandle($FormRel, $_POST, $aMessage, $iCurrentForm + 1);
				}
			}
 		}
	}
}

?>
Return current item: WebArchive