<?php
class mySearch
{
var $fldList = array();
var $dateFld = array();
function __construct($fList,$dateFld=NULL)
{
$this -> fldList = $fList;
$this -> dateFld = $dateFld;
}
function getSearch($dbfld,$dbval,$oper,$sTo)
{
$sqlAdd = "";
for($x=0; $x < count($dbfld); $x++)
{
$sIn = $dbfld[$x];
$sFor = $dbval[$x];
$sToV = $sTo[$x];
$operator = $oper[$x];
if(in_array($this -> fldList[$sIn], $this -> dateFld))
{
$sFor = date('Y-m-d H:i:s',strtotime($sFor));
$sToV = date('Y-m-d H:i:s',strtotime($sToV));
}
if($sIn != "" && $sFor != "" && $operator != "")
{
if(is_array($this -> fldList[$sIn]))
{
$sqlAdd .= "and ( ";
for($x=0; $x<count($this -> fldList[$sIn]); $x++)
{
$con = ($x==0) ? "" : "or";
$sqlAdd .= $this -> getSearchC($sIn, $sFor,$sToV, $operator,$this -> fldList[$sIn][$x],$con);
}
$sqlAdd .= ")";
}
else
{
$sqlAdd .= $this -> getSearchC($sIn, $sFor,$sToV, $operator,$this -> fldList[$sIn],'and');
}
}
}
return $sqlAdd;
}
function getTotWidth($widthVal,$display)
{
$totWidth = 0;
for($i=0; $i < count($display); $i++)
{
$totWidth += $widthVal[$display[$i]];
}
//$totWidth = $totWidth + (8*count($display)) + (1*count($display));
return $totWidth;
}
function getSearchC($sIn, $sFor,$sToV, $operator,$cfldList,$cond)
{
if($sIn != "" && $sFor != "" && $operator != "")
{
switch ($operator)
{
case "e":
$sqlAdd .= " $cond ". $cfldList."= '$sFor'";
break;
case "n":
$sqlAdd .= " $cond ". $cfldList."<> '$sFor'";
break;
case "s":
$sqlAdd .= " $cond ". $cfldList. " like ('$sFor%')";
break;
case "c":
$sqlAdd .= " $cond ". $cfldList. " like ('%$sFor%')";
break;
case "k":
$sqlAdd .= " $cond ". $cfldList. " not like ('%$sFor%')";
break;
case "l":
$sqlAdd .= " $cond ". $cfldList. " < '$sFor' ";
break;
case "g":
$sqlAdd .= " $cond ". $cfldList. " > '$sFor' ";
break;
case "m":
$sqlAdd .= " $cond ". $cfldList. " <= '$sFor' ";
break;
case "h":
$sqlAdd .= " $cond ". $cfldList. " >= '$sFor' ";
break;
case "btw":
$sqlAdd .= " $cond ". $cfldList. " >= '$sFor' $cond ". $cfldList. " <='$sToV'";
break;
case "u":
$var = explode(',',$sFor);
$newVar = "";
for($i=0;$i<count($var);$i++)
{
$newVar.=($i > 0) ? "," : "";
$newVar.= "'".trim($var[$i])."'";
}
$sqlAdd .= " $cond ". $cfldList. " in ($newVar) ";
break;
case "x":
$var = explode(',',$sFor);
$newVar = "";
for($i=0;$i<count($var);$i++)
{
$newVar.=($i > 0) ? "," : "";
$newVar.= "'".trim($var[$i])."'";
}
$sqlAdd .= " $cond ". $cfldList. " not in ($newVar) ";
break;
}
}
return $sqlAdd;
}
}
?>
|