Location: PHPKode > projects > Phparchive > phparchive.0.1.86.beta/includes/wafields.inc.php
<?php

/**
*
* @version $Id: wafields.inc.php,v 1.7 2004/02/08 18:27:40 freedev Exp $
* @author Vincenzo D'Amore <hide@address.com>
* @package wa_includes
*/

/**
 *
 */

/**
 *
 * @package wa_includes
 */
class WAFields
{
	var $m_Fields = 0;

	function WAFields()
	{
	}

	function Attach(&$Fields)
	{
		$bRC = FALSE;
		if (is_array($Fields))
		{
			$this->m_Fields = &$Fields;
			$bRC = TRUE;
		}
		return $bRC;
	}

	function IsBuild()
	{
		$bRC = FALSE;
		if (!empty($this->m_Fields))
			$bRC = TRUE;
		return $bRC;
	}

	function GetField($FieldName)
	{
		return $this->m_Fields[$FieldName];
	}

}

/**
 *
 * @package wa_includes
 */
class WAField
{
	var $m_Field = 0;
	var $m_Form = 0;

	function WAField()
	{
	}

	function Attach(&$Field)
	{
		$bRC = FALSE;
		if (is_array($Field))
		{
			$this->m_Field = &$Field;
			$bRC = TRUE;
		}
		return $bRC;
	}

	function AttachForm(&$Form)
	{
		$bRC = FALSE;
		if (is_array($Form))
		{
			$this->m_Form = &$Form;
			$bRC = TRUE;
		}
		return $bRC;
	}

	function IsBuild()
	{
		$bRC = FALSE;
		if (!empty($this->m_Field))
			$bRC = TRUE;
		return $bRC;
	}

	function GetName()
	{
		return $this->m_Field["WAField"];
	}

	function GetDescription()
	{
		return $this->m_Field["WADescription"];
	}

	function Field2Str($Field, $sData)
	{
		if (($sData != "WAValue") &&
			($sData != "WATag"))
			return -1;

		if (($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 (!empty($Field[$sData]) )
			{
				$sSqlFields2 .= " WHERE ".$Field["WARefTable"].".".$Field["WARefFieldValue"];
				$sSqlFields2 .= " IN ( ".$Field[$sData]." )";
//				$sSqlFields2 .=" ORDER BY ".( (strlen($Field["WARefFieldExpr"]) > 0) ? $Field["WARefFieldExpr"] : $Field["WARefFieldDesc"]);
				$sSqlFields2 .=" ORDER BY ".$Field["WARefFieldDesc"];
				$valueList = new WARecordset();
				$valueList->SetConnection($this->m_Form);
				$valueList->WAOpenRecordset($sSqlFields2);
				$optValue = "";
				while ($valueList->WAFetchRow())
				{
					if (!empty($optValue))
					echo ",&nbsp;";
					$optValue = "1";
					// echo $valueList->WAResult($Field["WARefFieldDesc"]);
					for ($i = 0; $i < $lCount; $i++)
					{
						if ($i > 0)
							echo "&nbsp;";
						echo htmlentities($valueList->WAResult($aFieldDescList[$i]."_".$Field["WAId"]), ENT_QUOTES);
					}
				}
				$valueList->WACloseRecordset() ;
			}
		}
		elseif (!empty($Field["WARefTable"]) )
		{
			$aFieldDescList = WASplit(', ', $Field["WARefFieldDesc"]);
			$lCount = count($aFieldDescList);

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

			if (!empty($Field[$sData]))
			{
				$sSqlFields2 .= " WHERE " . $Field["WARefFieldValue"] . " = ";
				if ($Field["WAIdType"] == WA_NUMERIC)
					$sSqlFields2 .= $Field[$sData];
				if ($Field["WAIdType"] == WA_STRING)
					$sSqlFields2 .= "'".htmlentities(stripcslashes($Field[$sData]), ENT_QUOTES)."'";

				$valueList = new WARecordset();
				$valueList->SetConnection($this->m_Form);
				$valueList->WAOpenRecordset($sSqlFields2);
				if ($valueList->WAFetchRow())
				{
					for ($i = 0; $i < $lCount; $i++)
					{
						if ($i)
							echo "&nbsp;";
						echo htmlentities($valueList->WAResult($aFieldDescList[$i]."_".$Field["WAId"]), ENT_QUOTES);
					}
				}
				$valueList->WACloseRecordset() ;
			}
		}
		elseif ((($Field["WAIdType"] == WA_USERID) ||
				 ($Field["WAIdType"] == WA_KEYUSEROWNER) ))
		{
			$sUser = "";
			$sUserName = ""; $sUserSurname = "";
			GetUserInfo($Field[$sData], $sUser, $sUserName, $sUserSurname);
			$sUserInfo = $sUser;
			return $sUserInfo;
		}
		elseif (($Field["WAIdType"] == WA_GROUPID) ||
				($Field["WAIdType"] == WA_KEYGROUPOWNER))
		{
			$sGroupName = ""; $bAdmin = 0;
			GetGroupInfo($Field[$sData], $sGroupName, $bAdmin);
			return $sGroupName;
		}
		elseif ($Field["WAIdType"] == WA_DATETIME)
		{
			if ((!empty($Field["WATag"]["seleDay"])) ||
				(!empty($Field["WATag"]["seleMonth"])) ||
				(!empty($Field["WATag"]["seleYear"])) )
			{
				return str_pad($Field["WATag"]["seleDay"], 2, "0",  STR_PAD_LEFT) . "/".
				 	str_pad($Field["WATag"]["seleMonth"], 2, "0",  STR_PAD_LEFT) . "/".
					str_pad($Field["WATag"]["seleYear"], 2, "0",  STR_PAD_LEFT) . " ".
					str_pad($Field["WATag"]["seleHour"], 2, "0",  STR_PAD_LEFT).":".
					str_pad($Field["WATag"]["seleMin"], 2, "0",  STR_PAD_LEFT).":".
					str_pad($Field["WATag"]["seleSec"], 2, "0",  STR_PAD_LEFT);
			}
		}
		elseif ($Field["WAIdType"] == WA_DATE)
		{
			if ((!empty($Field["WATag"]["seleDay"])) ||
				(!empty($Field["WATag"]["seleMonth"])) ||
				(!empty($Field["WATag"]["seleYear"])) )
			{
				return str_pad($Field["WATag"]["seleDay"], 2, "0",  STR_PAD_LEFT) . "/".
				 	str_pad($Field["WATag"]["seleMonth"], 2, "0",  STR_PAD_LEFT) . "/".
					str_pad($Field["WATag"]["seleYear"], 2, "0",  STR_PAD_LEFT);
			}
		}
		elseif ($Field["WAIdType"] == WA_TIME)
		{
				return str_pad($Field["WATag"]["seleHour"], 2, "0",  STR_PAD_LEFT).":".
					str_pad($Field["WATag"]["seleMin"], 2, "0",  STR_PAD_LEFT).":".
					str_pad($Field["WATag"]["seleSec"], 2, "0",  STR_PAD_LEFT);
		}
		elseif ($Field["WAIdType"] == WA_BOOLEAN)
		{
			if ($Field[$sData] == "TRUE")
				return WA_LBL_TRUE;
			return WA_LBL_FALSE;
		}
		else
			return $Field[$sData];
	}

	function GetValue()
	{
		return $this->Field2Str($this->m_Field, "WAValue");
	}

	function GetTag()
	{
		return $this->Field2Str($this->m_Field, "WATag");
	}
}

?>
Return current item: Phparchive