Location: PHPKode > projects > Phparchive > phparchive.0.1.86.beta/includes/searchform.inc.php
<?php
/**
 *
 * @version $Id: searchform.inc.php,v 1.17 2004/02/21 17:11:06 freedev Exp $
 * @author Vincenzo D'Amore <hide@address.com>
 * @package wa_includes
 *
 */

/**
 * Split a string into an array using strtok,
 * for me this function work better than builtin split function
 * @param string Match string (like: ',;:')
 * @param string Source string
 * @return array of strings
 */

function WASplit($sMatch, $sString)
{
//	$aRet = array();
	$token = strtok($sString, $sMatch);
	while ($token)
	{
		$aRet[] = $token;
		$token = strtok($sMatch);
	}
	return $aRet;
}

/**
 * Create sql to search contents
 *
 *
 */

function CreateSearchSql(&$Form, $sOrderField = "", $AscDesc, &$sSql, &$sMessage)
{
	$bRC = True;
	$sFields = "";
	$bJoins = FALSE;
	$sWhere = "";
	$sWhereUsers = "";
	$sOrderBy = "";
	$formUID = $Form["WAUID"];
	$Fields = &$Form["WAFields"];
//	$FormDBInfo = &$Form["WADBInfo"];
	$FormDBInfo = &$GLOBALS["WADBInfo"];
	$sTableNames = $Form["WATableName"];

//	echo "<pre>"; print_r($Fields); echo "</pre>";
//	echo "<pre>"; print_r($FormDBInfo); echo "</pre>";

	$iRefCounter = 0;
	foreach ($Fields as $Field)
	{

		if (($Form["WATableName"].".".$Field["WAField"]) == $sOrderField)
			$sOrderBy = $sOrderField;

		// se il campo e' stato impostato
		if ( (!empty($Field["WATag"])) &&
			 (!is_array($Field["WATag"])) )
		{
			// controlla il tipo
			if (($Field["WAIdType"] == WA_STRING) ||
				($Field["WAIdType"] == WA_FILE)	||
				($Field["WAIdType"] == WA_IMAGE))
			{
				if (!empty($sWhere))
					$sWhere .= " AND ";
				// se e' presente il carattere % nella search presuppone che ci sia
				// una ricerca di tipo like...
//				$pos = strstr($Field["WATag"], "%");
//				if ($pos == FALSE)
//					$sWhere .=  $Form["WATableName"].".".$Field["WAField"] . "='" . str_replace("'", "''", stripslashes($Field["WATag"])) . "'";
//				else
					$sWhere .=  $Form["WATableName"].".".$Field["WAField"] . " LIKE '" . str_replace("'", "''", stripslashes($Field["WATag"])) . $GLOBALS[$FormDBInfo["WADBType"]]["WAWildcard"] ."'";
			}
			elseif ($Field["WAIdType"] == WA_NUMERIC)
			{
				if (is_numeric($Field["WATag"]))
				{
					if (!empty($sWhere)) $sWhere .= " AND ";
					$sWhere .=  $Form["WATableName"].".".$Field["WAField"] . "=" . $Field["WATag"];
				}
				else
				{
					$bRC = False;
					$sMessage .= "| il campo ".$Field["WAField"]." non e' un numero.";
				}
			}
			elseif (($Field["WAIdType"] == WA_USERID) ||
					($Field["WAIdType"] == WA_GROUPID))
			{
				if (is_numeric($Field["WATag"]))
				{
					if (!empty($sWhere)) $sWhere .= " AND ";
					$sWhere .=  $Form["WATableName"].".".$Field["WAField"] . "=" . $Field["WATag"];
				}
				else
				{
//					$bRC = False;
//					$sMessage .= "| il campo ".$Field["WAField"]." non e' un numero.";
				}
			}
			elseif ($Field["WAIdType"] == WA_BOOLEAN)
			{
				if (!empty($Field["WATag"]))
				{
					if (!empty($sWhere)) { $sWhere .= " AND "; }
					$sWhere .=  $Form["WATableName"].".".$Field["WAField"] . "=";
					if ($Field["WATag"] == "TRUE")
						$sWhere .= "-1";
					else
						$sWhere .= "0";
				}
				else
				{
					if (!empty($sWhere)) $sWhere .= " AND ";
					$sWhere .=  "NOT " . $Form["WATableName"].".".$Field["WAField"] . "=";
					if ($Field["WATag"] == "TRUE")
						$sWhere .= "-1";
					else
						$sWhere .= "0";
				}
			}
			elseif ($Field["WAIdType"] == WA_KEYNUM)
			{
				if (is_numeric($Field["WATag"]))
				{
					if (!empty($sWhere)) $sWhere .= " AND ";
					$sWhere .=  $Form["WATableName"].".".$Field["WAField"] . "=" . $Field["WATag"];
				}
				else
				{
					$bRC = False;
					$sMessage .= "| il campo ".$Field["WAField"]." non e' un numero.";
				}
			}
			elseif ($Field["WAIdType"] == WA_KEYUSEROWNER)
			{
				if (!empty($sWhereUsers)) $sWhereUsers .= " OR ";
				if (!$_SESSION["giAdmin"])
					$sWhereUsers .=  $Form["WATableName"].".".$Field["WAField"] . "=" . $_SESSION["giIdUser"];
				else
					$sWhereUsers .=  $Form["WATableName"].".".$Field["WAField"] . "=" . $Field["WATag"];
			}
			elseif ($Field["WAIdType"] == WA_KEYGROUPOWNER)
			{
				if (!empty($sWhereUsers)) $sWhere .= " OR ";
				if (!$_SESSION["giAdmin"])
				{
//					$sWhere .=  $Form["WATableName"].".".$Field["WAField"] . "=" . $_SESSION["giIdGroup"];
					if (!empty($_SESSION["gsOtherGroups"]))
						$sWhereUsers .=  $Form["WATableName"].".".$Field["WAField"] . " in (" . $_SESSION["giIdGroup"].", ".$_SESSION["gsOtherGroups"].") ";
					else
						$sWhereUsers .=  $Form["WATableName"].".".$Field["WAField"] . " = " . $_SESSION["giIdGroup"];
				}
				else
					$sWhereUsers .=  $Form["WATableName"].".".$Field["WAField"] . "=" . $Field["WATag"];
			}
			elseif ($Field["WAIdType"] == WA_PASSWORD)
			{
				if (!empty($sWhere))
					$sWhere .= " AND ";
				$sWhere .=  $Form["WATableName"].".".$Field["WAField"] . "='" . md5(stripslashes($Field["WATag"][0])) . "'";
			}
			elseif ($Field["WAIdType"] == WA_LIST)
			{
				$sRefTable = $Field["WAField"] . "_REF" . $iRefCounter;
				if (!empty($sWhere))
					$sWhere .= " AND ";
				$sWhere .=  $sRefTable.".".$Field["WARefFieldValue"];
				$sWhere .= " IN ( ".$Field["WATag"]." )";
				if ($bJoins)
					$sTableNames = "(".$sTableNames.")";
				$sTableNames .= " LEFT JOIN ".$Field["WAField"];
				$sTableNames .= " ".$sRefTable;
				$sTableNames .= " ON ";
				$sTableNames .= $Form["WATableName"].".".$Form["WATableKeyField"];
				$sTableNames .= " = ".$sRefTable.".".$Form["WATableKeyField"];
				$bJoins = TRUE;
			}
			else
			{
				$bRC = False;
				$sMessage .= "| Campo ".$Field["WAField"]." di tipo " . $Field["WAIdType"] . " non gestito";
			}
		}
		elseif (($Field["WAIdType"] == WA_DATE) &&
				@checkdate($Field["WATag"]["seleMonth"],
						  $Field["WATag"]["seleDay"],
						  $Field["WATag"]["seleYear"]) )
		{
			if (!empty($sWhere)) $sWhere .= " AND ";
			$sWhere .=  $Form["WATableName"].".".$Field["WAField"] . "= ". $GLOBALS[$FormDBInfo["WADBType"]]["WADateS"] . $Field["WATag"]["seleYear"] . "/";
			$sWhere .=  $Field["WATag"]["seleMonth"] . "/";
			$sWhere .=  $Field["WATag"]["seleDay"] . $GLOBALS[$FormDBInfo["WADBType"]]["WADateE"];
		}
		elseif ((($Field["WAIdType"] == WA_DATE) || ($Field["WAIdType"] == WA_DATETIME)) &&
				( !empty($Field["WATag"]["seleMonth"]) ||
				  !empty($Field["WATag"]["seleYear"]) ) &&
				empty($Field["WATag"]["seleDay"]) )
		{
			if (!empty($sWhere)) $sWhere .= " AND ";
			if (empty($Field["WATag"]["seleMonth"]))
				$Field["WATag"]["seleMonth"] = date("m");
			if (empty($Field["WATag"]["seleYear"]))
				$Field["WATag"]["seleYear"] = date("Y");
			$nextYear = intval($Field["WATag"]["seleYear"]);
			$nextMonth = intval($Field["WATag"]["seleMonth"]) + 1;
			if ($nextMonth > 12)
			{
				$nextMonth = 1;
				$nextYear += 1;
			}
			$sWhere .=  $Form["WATableName"].".".$Field["WAField"] . ">= ". $GLOBALS[$FormDBInfo["WADBType"]]["WADateS"] . $Field["WATag"]["seleYear"] . "/";
			$sWhere .=  $Field["WATag"]["seleMonth"] . "/1" . $GLOBALS[$FormDBInfo["WADBType"]]["WADateE"];
			$sWhere .=  " AND " . $Form["WATableName"].".".$Field["WAField"] . "< ". $GLOBALS[$FormDBInfo["WADBType"]]["WADateS"] . $nextYear . "/";
			$sWhere .=  $nextMonth . "/1";
			$sWhere .=  $Field["WATag"]["seleDay"] . $GLOBALS[$FormDBInfo["WADBType"]]["WADateE"];
//			echo "<pre>"; print_r($Field); echo "</pre>";
		}
		elseif (($Field["WAIdType"] == WA_DATETIME) &&
				checkdate($Field["WATag"]["seleMonth"],
						  $Field["WATag"]["seleDay"],
						  $Field["WATag"]["seleYear"]) &&
				( (!isset($Field["WATag"]["seleHour"])) ||
				(!isset($Field["WATag"]["seleMin"])) ||
				(!isset($Field["WATag"]["seleSec"])) ) )
		{
			if (!empty($sWhere)) $sWhere .= " AND ";
			$sWhere .=  $Form["WATableName"].".".$Field["WAField"] . "= ". $GLOBALS[$FormDBInfo["WADBType"]]["WADateTimeS"] . $Field["WATag"]["seleYear"] . "/";
			$sWhere .=  $Field["WATag"]["seleMonth"] . "/";
			$sWhere .=  $Field["WATag"]["seleDay"] . " ";
			$sWhere .=  str_pad($Field["WATag"]["seleHour"], 2, "0",  STR_PAD_LEFT) . ":";
			$sWhere .=  str_pad($Field["WATag"]["seleMin"], 2, "0",  STR_PAD_LEFT) . ":";
			$sWhere .=  str_pad($Field["WATag"]["seleSec"], 2, "0",  STR_PAD_LEFT);
			$sWhere .=  $GLOBALS[$FormDBInfo["WADBType"]]["WADateTimeE"];
		}
		elseif (($Field["WAIdType"] == WA_TIME) &&
				(!empty($Field["WATag"]["seleHour"])) &&
				(!empty($Field["WATag"]["seleMin"])) &&
				(!empty($Field["WATag"]["seleSec"])) )
		{
			if (!empty($sWhere)) $sWhere .= " AND ";
			$sWhere .=  $Form["WATableName"].".".$Field["WAField"] . "= ". $GLOBALS[$FormDBInfo["WADBType"]]["WATimeS"] ;
			$sWhere .=  str_pad($Field["WATag"]["seleHour"], 2, "0",  STR_PAD_LEFT) . ":";
			$sWhere .=  str_pad($Field["WATag"]["seleMin"], 2, "0",  STR_PAD_LEFT) . ":";
			$sWhere .=  str_pad($Field["WATag"]["seleSec"], 2, "0",  STR_PAD_LEFT);
			$sWhere .=  $GLOBALS[$FormDBInfo["WADBType"]]["WATimeE"];
		}
		elseif (($Field["WAIdType"] == WA_KEYUSEROWNER) && (!$_SESSION["giAdmin"]))
		{
			if (!empty($sWhereUsers)) $sWhereUsers .= " OR ";
			$sWhereUsers .=  $Form["WATableName"].".".$Field["WAField"] . "=" . $_SESSION["giIdUser"];
		}
		elseif (($Field["WAIdType"] == WA_KEYGROUPOWNER) && (!$_SESSION["giAdmin"]))
		{
			if (!empty($sWhereUsers)) $sWhereUsers .= " OR ";
			if (!empty($_SESSION["gsOtherGroups"]))
				$sWhereUsers .=  $Form["WATableName"].".".$Field["WAField"] . " in (" . $_SESSION["giIdGroup"].", ".$_SESSION["gsOtherGroups"].") ";
			else
				$sWhereUsers .=  $Form["WATableName"].".".$Field["WAField"] . " = " . $_SESSION["giIdGroup"];
		}
		
		// Handle join to tables
		if ((strlen($Field["WARefTable"]) > 0) &&
			($Field["WAIdType"] != WA_LIST))
		{
			$aFieldDescList = array();
			$sFieldsList = "";
			$lCount = 0;

			$sRefTable = $Field["WARefTable"] . "_REF" . $iRefCounter;
			if (!empty($Field["WARefFieldDesc"]))
			{
				$aFieldDescList = WASplit(', ', $Field["WARefFieldDesc"]);
//				echo "<pre>"; print_r($aFieldDescList); echo "</pre>";
				$lCount = count($aFieldDescList);
				for ($i = 0; $i < $lCount; $i++)
				{
					$sFieldsList .= " (".$sRefTable.".".$aFieldDescList[$i].") as ".$aFieldDescList[$i]."_".$Field["WAId"];
					if ($i < ($lCount - 1))
						$sFieldsList .= ", ";
				}
				if (!empty($sFields ))
					$sFields  .= ", ";
				$sFields .= $sFieldsList;
				if ($sOrderField == ($Form["WATableName"].".".$Field["WAField"]))
				{
					$sFieldsList = "";
	//				echo "<pre>"; print_r($aFieldDescList); echo "</pre>";
					for ($i = 0; $i < $lCount; $i++)
					{
						$sFieldsList .= $sRefTable.".".$aFieldDescList[$i]." ".$AscDesc;
						if ($i < ($lCount - 1))
							$sFieldsList .= ", ";
					}
					$sOrderBy = $sFieldsList;
					$AscDesc = "";
				}
			}

			if ($Field["WAIdRefType"] == 0)
			{
				$sTableNames .= ", ".$Field["WARefTable"];
				$sTableNames .= " ".$sRefTable;

				if (!empty($sWhere)) $sWhere .= " AND ";
				$sWhere .= $Form["WATableName"].".".$Field["WAField"];
				$sWhere .= "=".$sRefTable.".".$Field["WARefFieldValue"];
			}
			else
			{
				if ($bJoins)
					$sTableNames = "(".$sTableNames.")";
				if ($Field["WAIdRefType"] == WA_JOIN_EQUIV)
				{
					$sTableNames .= " INNER JOIN ".$Field["WARefTable"];
				}
				else if ($Field["WAIdRefType"] == WA_JOIN_LEFT)
				{
					$sTableNames .= " LEFT JOIN ".$Field["WARefTable"];
				}
				else if ($Field["WAIdRefType"] == WA_JOIN_RIGHT)
				{
					$sTableNames .= " RIGHT JOIN ".$Field["WARefTable"];
				}
				$sTableNames .= " ".$sRefTable;
				$sTableNames .= " ON ";
				$sTableNames .= $Form["WATableName"].".".$Field["WAField"];
				$sTableNames .= " = ".$sRefTable.".".$Field["WARefFieldValue"];
				$bJoins = TRUE;
			}
		}
		elseif ((strlen($Field["WARefTable"]) > 0) &&
			($Field["WAIdType"] == WA_LIST))
		{
		}
		elseif ($Field["WAIdType"] != WA_LIST)
		{
			if (!empty($sFields ))
				$sFields  .= ", ";
			$sFields .= $Form["WATableName"].".".$Field["WAField"];
		}
		$iRefCounter++;
	}
	$sSql = ("SELECT " . $sFields . " FROM " . $sTableNames);
	if (!empty($sWhere))
		$sSql .= " WHERE " . $sWhere;
	
	if (!empty($sWhereUsers))
	{
		if (empty($sWhere))
			$sSql .= " WHERE ";
		else
			$sSql .= " AND ";
		$sSql .= " ( " . $sWhereUsers ." )";
	}	
	if (!empty($sOrderBy))
		$sSql .= " ORDER BY " . $sOrderBy . " " . $AscDesc;
//	echo $sSql . "<BR>" . $bRC . "<BR>" . $sMessage . "<BR>";
	return $bRC;
}

function CreateSearchResults(&$Form, $queryResults, $iCurrentPage, $iRowsPerPage, $sDeleteList = "")
{
//	echo "Entering... CreateSearchResults";
	$bRC = False;
	$formUID = $Form["WAUID"];
	$Fields = &$Form["WAFields"];

	$bDelete  = strstr($Form["WAActions"], "D");
	$bBrowse = strstr($Form["WAActions"], "V") || strstr($Form["WAActions"], "M");

	$search = new WARecordset();
	$search->SetConnection($Form);
	$search->WAOpenRecordset($queryResults);
	$aDeleteList = array();

	echo "<table border='0' cellpadding='0' cellspacing='0' width='100%' class='FormTableE'><tr><td>";
	if ($search->WAFetchRow())
	{
		$bRC = True;
		if ($iCurrentPage < 1)
			$iCurrentPage = 1;
		$KeyField = "";
		$sCurrentPage = "getFormElementByName(document.forms['formSearch_".$formUID."'], 'PageN').value";
		$sRowsPerPage = "getFormElementByName(document.forms['formSearch_".$formUID."'], 'RowsPerPage').value";

		echo "<form name='formSearch_".$formUID."' method='post' class='Form' onsubmit='return setSubmitFired();' action=''>";
		if ($GLOBALS['WA_PRIVATE_SESSIONS'])
			echo '<INPUT type="hidden" name="'. WA_SESSION_NAME.'" value="'.session_id().'" >';
		if (!empty($Form["WAActions"]))
		{
			echo "<table border='0' cellpadding='1' cellspacing='3'><tr>";
			echo "<td>&nbsp;<span class='FieldStd'>".WA_MSG_SEARCH_PAGE."</span>&nbsp;<input class='Inputs' type='text' name='PageN' value='".$iCurrentPage."' Size='4'></td>";
			echo "<td>&nbsp;<span class='FieldStd'>".WA_MSG_ROW_PER_PAGE."</span>&nbsp;<input class='Inputs' type='text' name='RowsPerPage' value='".$iRowsPerPage."' Size='4'></td>";
			echo "<td class='ButtonsSmall'>";
			echo "<a class='ButtonsSmall' href=\"javascript:PageNumber('" . $formUID . "', ".$sCurrentPage.",".$sRowsPerPage.")\">&nbsp;".WA_CMD_GO."&nbsp;</a></td>";
			echo "<td>&nbsp;</td>";
			echo "<td class='ButtonsSmall'>";
			echo "<a class='ButtonsSmall' href=\"javascript:PageNumber('" . $formUID . "', " . ($iCurrentPage-1) .",".$sRowsPerPage. ")\">&nbsp;".WA_MSG_SEARCH_PREV_PAGE."&nbsp;</a></td>";
			echo "<td class='ButtonsSmall'>";
			echo "<a class='ButtonsSmall' href=\"javascript:PageNumber('" . $formUID . "', " . ($iCurrentPage+1) .",".$sRowsPerPage. ")\">&nbsp;".WA_MSG_SEARCH_NEXT_PAGE."&nbsp;</a></td>";
			echo "</tr></table>";
		}
		if (!empty($sDeleteList))
		{
			$aDeleteList = WASplit(",", $sDeleteList);
		}

		echo "<table border='0' cellpadding='2' cellspacing='2'><tr>";
		if (($bBrowse) && (count($aDeleteList) == 0))
		{
			echo "<td></td>";
		}
		if ($bDelete)
		{
			if (count($aDeleteList) == 0)
				echo "<td class='ColumnTitle' valign='top'><input type=\"checkbox\" name='" . $formUID . "_checkall' onclick=\"javascript:CheckAllDelete('" . $formUID . "')\">";
			else
				echo "<td>";
			echo "</td>";
		}
		reset($Fields);
		foreach ($Fields as $Field)
		{
			if ($Field["WAIdType"] == WA_KEYNUM)
			{
				$KeyField = $Field["WAField"];
			}
			elseif ($Field["WAField"] == $Form['WAHiddenKeyField'])
			{
				// do nothing...
			}
			elseif ((($Field["WAIdType"] == WA_KEYUSEROWNER) ||
					 ($Field["WAIdType"] == WA_KEYGROUPOWNER) ||
					 ($Field["WAIdType"] == WA_GROUPID) ||
					 ($Field["WAIdType"] == WA_USERID) ||
					(!$_SESSION["giAdmin"]) ) || ($Field["WAHidden"])) 
			{
			}
			else
			{
				echo "<td class='ColumnTitle' valign=top>";
//				echo "<td class='ColumnTitle' valign=top onclick=\"javascript:ReorderBy('".$formUID."', ";
//				echo (count($aDeleteList) == 0) ? "'F'" : "'VD'";
//				echo ", '".$Form["WATableName"].".".$Field["WAField"]."')\">";
				if ($Field["WAIdType"] != WA_LIST)
				{
					echo "<a class='ColumnTitle' href=\"javascript:ReorderBy('".$formUID."', ";
					echo (count($aDeleteList) == 0) ? "'F'" : "'VD'";
					echo ", '".$Form["WATableName"].".".$Field["WAField"]."')\">";
					echo $Field["WADescription"];
					echo "</a>";
				}
				else
					echo $Field["WADescription"];
				echo "</td>";
			}
		}
		echo "</tr>\n";
		$i = 1;
		$iRow = 0;
		do
		{
			if ($iRow >= ((int)(($iCurrentPage - 1) * $iRowsPerPage)))
			{
				if ($bDelete || $bBrowse)
					$KeyValue = $search->WAResult($KeyField);
				if ((count($aDeleteList) == 0) ||
					(in_array($KeyValue, $aDeleteList)))
				{
					echo "<tr>";
					echo "<td class='ButtonsSmall'>";
					if (($bBrowse) && (count($aDeleteList) == 0))
					{
//						echo "<td class='ButtonsSmall' onclick=\"javascript:ModifyRecord('".$formUID."', ".$i.")\">";
						echo "<a class='ButtonsSmall' href=\"javascript:ModifyRecord('".$formUID."', $i)\">".WA_CMD_BROWSE."</a>";
						echo "<input type=hidden name=\"".$formUID."_KeyValue".$i."\" value=\"". $KeyValue."\">";
					}
					echo "<input type=hidden name=\"".$formUID."_KeyField$i\" value=\"$KeyField\"></td>";
					if ($bDelete)
					{
						echo "<td class='ButtonsSmall'>";
						echo "<input type=checkbox name=\"".$formUID."_chkDelete$i\"";
						if (in_array($KeyValue, $aDeleteList))
							echo " checked ";
						if (count($aDeleteList) > 0)
							echo " disabled ";
						echo " value=\"$KeyValue\"></td>";
					}

					reset ($Fields);
					foreach ($Fields as $Field)
					{
						if (($Field["WAIdType"] != WA_KEYNUM) &&
							($Field["WAIdType"] != WA_KEYUSEROWNER) &&
							($Field["WAIdType"] != WA_KEYGROUPOWNER) &&
							($Field["WAIdType"] != WA_GROUPID) &&
							($Field["WAIdType"] != WA_USERID) &&
							(!$Field["WAHidden"]) && 
							($Field["WAField"] != $Form['WAHiddenKeyField']))
						{
							$class = (($i % 2) ? "TableRow" : "TableRowE");
							echo "<td class='".$class."'>";
							if (($Field["WAIdType"] == WA_DATE) ||
								($Field["WAIdType"] == WA_DATETIME) ||
								($Field["WAIdType"] == WA_TIME) )
							{
								if ($Field["WAIdType"] == WA_DATE)
								    $sDate = substr($search->WAResult($Field["WAField"]), 0, 10);
								else
								    $sDate = $search->WAResult($Field["WAField"]);
							    echo ereg_replace ("-", "/", $sDate);
							}
							elseif ($Field["WAIdType"] == WA_BOOLEAN)
							{
							    echo ($search->WAResult($Field["WAField"]) == 0 ? WA_LBL_FALSE : WA_LBL_TRUE );
							}
							elseif ($Field["WAIdType"] == WA_FILE)
							{
//							    echo basename($search->WAResult($Field["WAField"]));
								$sFile = htmlentities(stripcslashes($search->WAResult($Field["WAField"])), ENT_QUOTES);
								$sFileName = basename($sFile);
								echo "&nbsp;<a ";
								echo (!empty($sFileName)) ? " href='javascript:doNothing();' onclick='javascript:ShowAttachment(\"".$GLOBALS['WA_DOWNLOAD_URI'].$sFile."\")'" : "";
								echo ">\n".$sFileName."</a>&nbsp;\n";
							}
							elseif ($Field["WAIdType"] == WA_IMAGE)
							{
//							    echo basename($search->WAResult($Field["WAField"]));
								$sFile = htmlentities(stripcslashes($search->WAResult($Field["WAField"])), ENT_QUOTES);
								$sFileName = basename($sFile);
								echo "&nbsp;<a class='Buttons' ";
								echo (!empty($sFileName)) ? " href='javascript:doNothing();' onclick='javascript:ShowAttachment(\"".$GLOBALS['WA_DOWNLOAD_URI'].$sFile."\")'" : "";
								echo ">\n";
								echo "><img src='".$sFile."' border='0'";
								if (!empty($Field["WASize"]))
									echo " width='".$Field["WASize"]."'";
								if (!empty($Field["WASize"]))
									echo " height='".$Field["WAMaxLength"]."'";
								echo " alt='".$sFileName."'";
								echo ">\n".$sFileName."</a>&nbsp;\n";

							}
							elseif ($Field["WAIdType"] == WA_LONGTEXT)
							{
							    echo substr($search->WAResult($Field["WAField"]), 0, $Field["WASize"]);
							}
							elseif ($Field["WAIdType"] == WA_LIST)
							{
								$aFieldDescList = WASplit(', ', $Field["WARefFieldDesc"]);
								$lCount = count($aFieldDescList);

								$sSqlFields2 = "";
								CreateFieldSearchSql($Field, $sSqlFields2, $iRow);
								$sSqlFields2 .= ", ".$Field["WAField"];
								$sSqlFields2 .= " WHERE ".$Field["WAField"].".".$KeyField." = ".$search->WAResult($KeyField);
								$sSqlFields2 .= " AND ".$Field["WARefTable"].".".$Field["WARefFieldValue"];
								$sSqlFields2 .= " = ".$Field["WAField"].".".$Field["WARefFieldValue"];
								$sSqlFields2 .=" ORDER BY ".$Field["WARefFieldDesc"];
//								echo $sSqlFields2;
								
								$valueList = new WARecordset();
								$valueList->SetConnection($Form);
								$valueList->WAOpenRecordset($sSqlFields2);
								$optValue = "";
								while ($valueList->WAFetchRow())
								{
									if (!empty($optValue))
										echo ",&nbsp;";
									$optValue = "1";
									// echo $valueList->WAResult($Field["WARefFieldDesc"]);
									for ($j = 0; $j < $lCount; $j++)
									{
										if ($j > 0)
											echo "&nbsp;";
										echo htmlentities($valueList->WAResult($aFieldDescList[$j]."_".$Field["WAId"]), ENT_QUOTES);
									}
								}
								$valueList->WACloseRecordset() ;
							}
							elseif ((!$_SESSION["giAdmin"]) && 
									(($Field["WAIdType"] == WA_USERID) ||
									 ($Field["WAIdType"] == WA_GROUPID) ||
									 ($Field["WAIdType"] == WA_KEYUSEROWNER) ||
									 ($Field["WAIdType"] == WA_KEYGROUPOWNER)))
							{
								// Do nothing
							}
							elseif (!empty($Field["WARefFieldDesc"]))
							{
								$aFieldDescList = WASplit(', ', $Field["WARefFieldDesc"]);
			//					echo "<pre>"; print_r($aFieldDescList); echo "</pre>";
								$lCount = count($aFieldDescList);
								for ($iRefFields = 0; $iRefFields < $lCount; $iRefFields++)
								{
									if ($iRefFields > 0)
										echo "&nbsp;";
								    echo htmlentities($search->WAResult($aFieldDescList[$iRefFields]."_".$Field["WAId"]));
								}
							}
							else
							    echo htmlentities($search->WAResult($Field["WAField"]));
							echo "</td>";
						}
						elseif ((($_SESSION["giAdmin"]) && (($Field["WAIdType"] == WA_USERID) ||
								($Field["WAIdType"] == WA_KEYUSEROWNER)) ) && (!$Field["WAHidden"])) 
						{
							$class = (($i % 2) ? "TableRow" : "TableRowE");
							echo "<td class='".$class."'>";
						    $IdUser = $search->WAResult($Field["WAField"]);
							$sUser = "";
							$sUserName = "";
							$sUserSurname = "";
							GetUserInfo($IdUser, $sUser, $sUserName, $sUserSurname);
							echo htmlentities($sUser, ENT_QUOTES);
							echo "</td>";
						}
						elseif (((($_SESSION["giAdmin"]) && ($Field["WAIdType"] == WA_GROUPID) ||
								($Field["WAIdType"] == WA_KEYGROUPOWNER)) ) && (!$Field["WAHidden"])) 
						{
							$class = (($i % 2) ? "TableRow" : "TableRowE");
							echo "<td class='".$class."'>";
						    $IdGroup = $search->WAResult($Field["WAField"]);
							$sGroupName = "";
							$bAdmin = "";
							GetGroupInfo($IdGroup, $sGroupName, $bAdmin);
							echo htmlentities($sGroupName, ENT_QUOTES);
							echo "</td>";
						}
						else
						{
//							echo htmlentities($search->WAResult($Field["WAField"]));
//							echo "</td>";
						}
					}
					$i++;
					echo "</tr>\n";
				}
			}
			$iRow++;
			if ($iRow >= (($iCurrentPage - 1) * $iRowsPerPage + $iRowsPerPage))
				break;
		}
		while ($search->WAFetchRow());
		echo "</table>";
		echo "</form>";
		$search->WACloseRecordset() ;
	}
	else
		echo "<span class='NotifyMsg'>".WA_MSG_WARNING_NOTFOUND."</span>";
	echo "</td></tr></table>";
	return $bRC;
}

?>
Return current item: Phparchive