예제 #1
0
 function readWebValue(&$avalues, &$blobfields, $legacy1, $legacy2, &$filename_values)
 {
     $this->getPostValueAndType();
     $this->formStamp = postvalue("formStamp_" . $this->goodFieldName . "_" . $this->id);
     if (FieldSubmitted($this->goodFieldName . "_" . $this->id) && $this->formStamp != "") {
         $filesArray = my_json_decode($this->webValue);
         if (!is_array($filesArray) || count($filesArray) == 0) {
             $this->webValue = "";
         } else {
             if (count($_SESSION["mupload_" . $this->formStamp]) > 0) {
                 foreach ($_SESSION["mupload_" . $this->formStamp] as $fileArray) {
                     $fileArray["deleted"] = true;
                 }
             }
             $result = array();
             $uploadDir = $this->pageObject->pSetEdit->getLinkPrefix($this->field);
             $searchStr = "";
             foreach ($filesArray as $file) {
                 if (isset($_SESSION["mupload_" . $this->formStamp][$file["name"]])) {
                     $sessionFile = $_SESSION["mupload_" . $this->formStamp][$file["name"]]["file"];
                     $searchStr .= $file["name"] . ",!";
                     $result[] = array("name" => $sessionFile["name"], "usrName" => $file["name"], "size" => $sessionFile["size"], "type" => $sessionFile["type"]);
                     if ($this->pageObject->pSetEdit->getCreateThumbnail($this->field) && $sessionFile["thumbnail"] != "") {
                         $lastIndex = count($result) - 1;
                         $result[$lastIndex]["thumbnail"] = $sessionFile["thumbnail"];
                         $result[$lastIndex]["thumbnail_type"] = $sessionFile["thumbnail_type"];
                         $result[$lastIndex]["thumbnail_size"] = $sessionFile["thumbnail_size"];
                     }
                     $_SESSION["mupload_" . $this->formStamp][$file["name"]]["deleted"] = false;
                 }
             }
             if (count($result) > 0) {
                 $result[0]["searchStr"] = $searchStr . ":sStrEnd";
                 $this->webValue = my_json_encode_unescaped_unicode($result);
             } else {
                 $this->webValue = "";
             }
         }
     } else {
         $this->webValue = false;
     }
     if (!($this->webValue === false)) {
         if ($this->connection->dbType == nDATABASE_Informix) {
             if (IsTextType($this->pageObject->pSetEdit->getFieldType($this->field))) {
                 $blobfields[] = $this->field;
             }
         }
         $avalues[$this->field] = $this->webValue;
     }
 }
예제 #2
0
     continue;
 }
 $fieldControl = $controls->getControl($f);
 $isAggregateField = $pSet->isAggregateField($f);
 $where = $fieldControl->getSuggestWhere($searchOpt, $searchFor, $isAggregateField);
 $having = $fieldControl->getSuggestHaving($searchOpt, $searchFor, $isAggregateField);
 if (!strlen($where) && !strlen($having)) {
     continue;
 }
 $where = whereAdd($where . $masterWhere, $strSecuritySql);
 $clausesData = $fieldControl->getSelectColumnsAndJoinFromPart($searchFor, $searchOpt, true);
 $selectColumns = $clausesData["selectColumns"];
 $fromClause = $gQuery->FromToSql() . $clausesData["joinFromPart"];
 $distinct = "DISTINCT";
 if ($_connection->dbType == nDATABASE_MSSQLServer || $_connection->dbType == nDATABASE_Access) {
     if (IsTextType($fType)) {
         $distinct = "";
     }
 }
 $sqlHead = "SELECT " . $distinct . " " . $selectColumns . " as _srchfld_";
 if ($gQuery->HasGroupBy()) {
     $strSQL = $gQuery->gSQLWhere_having_fromQuery("", $where, $having);
     $strSQL = "SELECT DISTINCT st." . $_connection->addFieldWrappers($f) . " from (" . $strSQL . ") st";
 } else {
     $strSQL = SQLQuery::gSQLWhere_having($sqlHead, $fromClause, $gQuery->WhereToSql(), $gQuery->GroupByToSql(), $gQuery->Having()->toSql($gQuery), $where, $having);
 }
 if ($_connection->dbType == nDATABASE_MySQL || $_connection->dbType == nDATABASE_PostgreSQL) {
     $strSQL .= " LIMIT " . $numberOfSuggests;
 } elseif ($_connection->dbType == nDATABASE_MSSQLServer || $_connection->dbType == nDATABASE_Access) {
     $strSQL = "select top " . $numberOfSuggests . " * from (" . $strSQL . ") st";
 } elseif ($_connection->dbType == nDATABASE_Oracle) {
예제 #3
0
파일: Control.php 프로젝트: kcallow/MatchMe
 /**
  * @param String strSearchOption
  * @return String | Boolean
  */
 function baseSQLWhere($strSearchOption)
 {
     if (IsBinaryType($this->type)) {
         return false;
     }
     if ($this->connection->dbType != nDATABASE_MySQL) {
         $this->btexttype = IsTextType($this->type);
     }
     if ($this->connection->dbType == nDATABASE_MSSQLServer) {
         if ($this->btexttype && $strSearchOption != "Contains" && $strSearchOption != "Starts with") {
             return false;
         }
     }
     if ($strSearchOption != 'Empty') {
         return "";
     }
     $fullFieldName = $this->getFieldSQLDecrypt();
     if (IsCharType($this->type) && (!$this->ismssql || !$this->btexttype) && !$this->isOracle) {
         return "(" . $fullFieldName . " is null or " . $fullFieldName . "='')";
     }
     if ($this->ismssql && $this->btexttype) {
         return "(" . $fullFieldName . " is null or " . $fullFieldName . " LIKE '')";
     }
     return $fullFieldName . " is null";
 }
예제 #4
0
function GenericStrWhereAdv($strTable, $strField, $SearchFor, $strSearchOption, $SearchFor2, $etype)
{
    global $dal;
    $sfield = $strField;
    $stable = "";
    if (is_wr_db()) {
        WRSplitFieldName($strField, $stable, $sfield);
        $type = WRGetFieldType($strField);
    } else {
        $type = WRCustomGetFieldType($strTable, $strField);
    }
    if (GetDatabaseType() != nDATABASE_MSSQLServer) {
        $ismssql = false;
    } else {
        $ismssql = true;
    }
    $btexttype = IsTextType($type);
    if (GetDatabaseType() == nDATABASE_MySQL) {
        $btexttype = false;
    }
    if (IsBinaryType($type)) {
        return "";
    }
    if (GetDatabaseType() == nDATABASE_MSSQLServer) {
        if ($btexttype && $strSearchOption != "Contains" && $strSearchOption != "Starts with ...") {
            return "";
        }
    }
    if ($strSearchOption == 'Empty') {
        if (IsCharType($type) && (!$ismssql || !$btexttype)) {
            return "(" . WRAddFieldWrappers($strField) . " is null or " . WRAddFieldWrappers($strField) . "='')";
        } elseif ($ismssql && $btexttype) {
            return "(" . WRAddFieldWrappers($strField) . " is null or " . WRAddFieldWrappers($strField) . " LIKE '')";
        } else {
            return WRAddFieldWrappers($strField) . " is null";
        }
    }
    if (GetDatabaseType() == nDATABASE_PostgreSQL) {
        $like = "ilike";
    } else {
        $like = "like";
    }
    if (GetGenericEditFormat($strTable, $sfield) == EDIT_FORMAT_LOOKUP_WIZARD) {
        $pSet = new ProjectSettings($strTable);
        if ($pSet->multiSelect($sfield)) {
            $SearchFor = splitvalues($SearchFor);
        } else {
            $SearchFor = array($SearchFor);
        }
        $ret = "";
        foreach ($SearchFor as $searchItem) {
            $value = $searchItem;
            if (!($value == "null" || $value == "Null" || $value == "")) {
                if (strlen($ret)) {
                    $ret .= " or ";
                }
                if ($strSearchOption == "Equals") {
                    $value = WRmake_db_value($sfield, $value, $strTable);
                    if (!($value == "null" || $value == "Null")) {
                        $ret .= WRAddFieldWrappers($strField) . '=' . $value;
                    }
                } else {
                    $connection = getWebreportConnection();
                    if (strpos($value, ",") !== false || strpos($value, '"') !== false) {
                        $value = '"' . str_replace('"', '""', $value) . '"';
                    }
                    $ret .= WRAddFieldWrappers($strField) . " = " . $connection->prepareString($value);
                    $ret .= " or " . WRAddFieldWrappers($strField) . " " . $like . " " . $connection->prepareString("%," . $value . ",%");
                    $ret .= " or " . WRAddFieldWrappers($strField) . " " . $like . " " . $connection->prepareString("%," . $value);
                    $ret .= " or " . WRAddFieldWrappers($strField) . " " . $like . " " . $connection->prepareString($value . ",%");
                }
            }
        }
        if (strlen($ret)) {
            $ret = "(" . $ret . ")";
        }
        return $ret;
    }
    if (GetGenericEditFormat($strTable, $sfield) == EDIT_FORMAT_CHECKBOX) {
        if ($SearchFor == "none") {
            return "";
        }
        if (NeedQuotes($type)) {
            if ($SearchFor == "on") {
                return "(" . WRAddFieldWrappers($strField) . "<>'0' and " . WRAddFieldWrappers($strField) . "<>'' and " . WRAddFieldWrappers($strField) . " is not null)";
            } else {
                return "(" . WRAddFieldWrappers($strField) . "='0' or " . WRAddFieldWrappers($strField) . "='' or " . WRAddFieldWrappers($strField) . " is null)";
            }
        } else {
            if ($SearchFor == "on") {
                return "(" . WRAddFieldWrappers($strField) . "<>0 and " . WRAddFieldWrappers($strField) . " is not null)";
            } else {
                return "(" . WRAddFieldWrappers($strField) . "=0 or " . WRAddFieldWrappers($strField) . " is null)";
            }
        }
    }
    $value1 = WRmake_db_value($sfield, $SearchFor, $strTable);
    $value2 = false;
    if ($strSearchOption == "Between") {
        $value2 = WRmake_db_value($sfield, $SearchFor2, $strTable);
    }
    if ($strSearchOption != "Contains" && $strSearchOption != "Starts with ..." && ($value1 === "null" || $value2 === "null")) {
        return "";
    }
    $connection = getWebreportConnection();
    if (IsCharType($type) && !$btexttype) {
        $value1 = $connection->upper($value1);
        $value2 = $connection->upper($value2);
        $strField = $connection->upper(WRAddFieldWrappers($strField));
    } elseif ($ismssql && !$btexttype && ($strSearchOption == "Contains" || $strSearchOption == "Starts with ...")) {
        $strField = "convert(varchar," . WRAddFieldWrappers($strField) . ")";
    } elseif (GetDatabaseType() == nDATABASE_PostgreSQL && !$btexttype && ($strSearchOption == "Contains" || $strSearchOption == "Starts with ...")) {
        $strField = "CAST(" . WRAddFieldWrappers($strField) . " AS TEXT)";
    } else {
        $strField = WRAddFieldWrappers($strField);
    }
    $ret = "";
    if ($strSearchOption == "Contains") {
        if (IsCharType($type) && !$btexttype) {
            return $strField . " " . $like . " " . $connection->upper($connection->prepareString("%" . $SearchFor . "%"));
        } else {
            return $strField . " " . $like . " " . $connection->prepareString("%" . $SearchFor . "%");
        }
    } else {
        if ($strSearchOption == "Equals") {
            return $strField . "=" . $value1;
        } else {
            if ($strSearchOption == "Starts with ...") {
                if (IsCharType($type) && !$btexttype) {
                    return $strField . " " . $like . " " . $connection->upper($connection->prepareString($SearchFor . "%"));
                } else {
                    return $strField . " " . $like . " " . $connection->prepareString($SearchFor . "%");
                }
            } else {
                if ($strSearchOption == "More than ...") {
                    return $strField . ">" . $value1;
                } else {
                    if ($strSearchOption == "Less than ...") {
                        return $strField . "<" . $value1;
                    } else {
                        if ($strSearchOption == "Equal or more than ...") {
                            return $strField . ">=" . $value1;
                        } else {
                            if ($strSearchOption == "Equal or less than ...") {
                                return $strField . "<=" . $value1;
                            } else {
                                if ($strSearchOption == "Between") {
                                    $ret = $strField . ">=" . $value1;
                                    $ret .= " and " . $strField . "<=" . $value2;
                                    return $ret;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return "";
}
예제 #5
0
function IsCharType($type)
{
    if (IsTextType($type) || $type == 8 || $type == 129 || $type == 200 || $type == 202 || $type == 130) {
        return true;
    }
    return false;
}
예제 #6
0
파일: dal.php 프로젝트: kcallow/MatchMe
 /**
  * Update record in the table.
  * @intellisense
  */
 function Update()
 {
     global $dal_info;
     $tableinfo =& $dal_info[$this->m_TableName];
     $updateParam = "";
     $updateValue = "";
     $blobs = array();
     foreach ($tableinfo as $fieldname => $fld) {
         $command = 'if(isset($this->' . $fld['varname'] . ')) { ';
         if ($fld["key"]) {
             $command .= '$this->Param[\'' . escapesq($fieldname) . '\'] = $this->' . $fld['varname'] . ';';
         } else {
             $command .= '$this->Value[\'' . escapesq($fieldname) . '\'] = $this->' . $fld['varname'] . ';';
         }
         $command .= ' }';
         eval($command);
         if (!$fld["key"] && !array_key_exists(strtoupper($fieldname), array_change_key_case($this->Param, CASE_UPPER))) {
             foreach ($this->Value as $field => $value) {
                 if (strtoupper($field) != strtoupper($fieldname)) {
                     continue;
                 }
                 $updateValue .= $this->_connection->addFieldWrappers($fieldname) . "=" . $this->PrepareValue($value, $fld["type"]) . ", ";
                 if ($this->_connection->dbType == nDATABASE_Oracle || $this->_connection->dbType == nDATABASE_DB2 || $this->_connection->dbType == nDATABASE_Informix) {
                     if (IsBinaryType($fld["type"])) {
                         $blobs[$fieldname] = $value;
                     }
                     if ($this->_connection->dbType == nDATABASE_Informix && IsTextType($fld["type"])) {
                         $blobs[$fieldname] = $value;
                     }
                 }
                 break;
             }
         } else {
             foreach ($this->Param as $field => $value) {
                 if (strtoupper($field) != strtoupper($fieldname)) {
                     continue;
                 }
                 $updateParam .= $this->_connection->addFieldWrappers($fieldname) . "=" . $this->PrepareValue($value, $fld["type"]) . " and ";
                 break;
             }
         }
     }
     //	construct SQL and do update
     if ($updateParam) {
         $updateParam = substr($updateParam, 0, -5);
     }
     if ($updateValue) {
         $updateValue = substr($updateValue, 0, -2);
     }
     if ($updateValue && $updateParam) {
         $dalSQL = "update " . $this->_connection->addTableWrappers($this->m_TableName) . " set " . $updateValue . " where " . $updateParam;
         $this->Execute_Query($blobs, $dalSQL, $tableinfo);
     }
     //	cleanup
     $this->Reset();
 }
// array of vals
$response = array();
if (postvalue("start")) {
    $suggestAllContent = false;
}
$searchFor = postvalue('searchFor');
$searchField = GoodFieldName(postvalue('searchField'));
$strSecuritySql = SecuritySQL("Search", $strTableName);
if ($searchField == "") {
    $allSearchFields = GetTableData($strTableName, '.googleLikeFields', array());
}
// proccess fields and create sql
foreach ($allSearchFields as $f) {
    $fType = GetFieldType($f, $strTableName);
    // filter fields by type
    if (!IsCharType($fType) && !IsNumberType($fType) && !IsGuid($fType) || IsTextType($fType)) {
        continue;
    }
    // get suggest for field
    if (($searchField == '' || $searchField == GoodFieldName($f)) && CheckFieldPermissions($f)) {
        $where = "";
        $having = "";
        if (!$gQuery->IsAggrFuncField(GetFieldIndex($f) - 1)) {
            $where = $searchClauseObj->getSuggestWhere($f, $fType, $suggestAllContent, $searchFor);
        } elseif ($gQuery->IsAggrFuncField(GetFieldIndex($f) - 1)) {
            $having = $searchClauseObj->getSuggestWhere($f, $fType, $suggestAllContent, $searchFor);
        }
        // prepare common vals
        $sqlHead = "SELECT DISTINCT " . GetFullFieldName($f) . " ";
        $oHaving = $gQuery->Having();
        $sqlHaving = $oHaving->toSql($gQuery);
 /**
  * Execute an SQL query with blob fields processing
  * @param String sql
  * @param Array blobs
  * @param Array blobTypes
  * @return Boolean
  */
 public function execWithBlobProcessing($sql, $blobs, $blobTypes = array())
 {
     if (!count($blobs)) {
         $this->exec($sql);
         return;
     }
     $blobidarray = array();
     foreach ($blobs as $fname => $fvalue) {
         if (IsTextType($blobTypes[$fname])) {
             $blob_type = 1;
         } else {
             $blob_type = 0;
         }
         $blobidarray[] = ifx_create_blob($blob_type, 0, $fvalue);
     }
     return @ifx_query($sql, $this->conn, $blobidarray);
 }
예제 #9
0
 /**
  * Get the WHERE clause conditions string for the search or suggest SQL query
  * @param String SearchFor
  * @param String strSearchOption
  * @param String SearchFor2
  * @param String etype
  * @param Boolean isSuggest
  * @return String
  */
 function SQLWhere($SearchFor, $strSearchOption, $SearchFor2, $etype, $isSuggest)
 {
     if ($this->lookupType == LT_LISTOFVALUES) {
         return parent::SQLWhere($SearchFor, $strSearchOption, $SearchFor2, $etype, $isSuggest);
     }
     $baseResult = $this->baseSQLWhere($strSearchOption);
     if ($baseResult === false) {
         return "";
     }
     if ($baseResult !== "") {
         return $baseResult;
     }
     if ($this->connection->dbType != nDATABASE_MySQL) {
         $this->btexttype = IsTextType($this->type);
     }
     if ($this->multiselect && $strSearchOption != "Equals") {
         $SearchFor = splitvalues($SearchFor);
     } else {
         $SearchFor = array($SearchFor);
     }
     $gstrField = $this->getFieldSQLDecrypt();
     $gstrField = $this->getFieldSQLDecrypt();
     if (($strSearchOption == "Starts with" || $strSearchOption == "Contains") && (!IsCharType($this->type) || $this->btexttype)) {
         $gstrField = $this->connection->field2char($gstrField, $this->type);
     }
     $ret = "";
     foreach ($SearchFor as $searchItem) {
         $value = $searchItem;
         if ($value == "null" || $value == "Null" || $value == "") {
             continue;
         }
         if (strlen(trim($ret))) {
             $ret .= " or ";
         }
         if (($strSearchOption == "Starts with" || $strSearchOption == "Contains") && !$this->multiselect) {
             $value = $this->connection->escapeLIKEpattern($value);
             if ($strSearchOption == "Starts with") {
                 $value .= '%';
             }
             if ($strSearchOption == "Contains") {
                 $value = '%' . $value . '%';
             }
         }
         if ($strSearchOption != "Starts with" && $strSearchOption != "Contains") {
             $value = make_db_value($this->field, $value);
         }
         $searchIsCaseInsensitive = $this->pageObject->pSetEdit->getNCSearch();
         if ($strSearchOption == "Equals" && !($value == "null" || $value == "Null")) {
             $condition = $gstrField . '=' . $value;
         } else {
             if (($strSearchOption == "Starts with" || $strSearchOption == "Contains") && !$this->multiselect) {
                 $condition = $gstrField . " " . $this->like . " " . $this->connection->prepareString($value);
             } else {
                 if ($strSearchOption == "More than") {
                     $condition = $gstrField . " > " . $value;
                 } else {
                     if ($strSearchOption == "Less than") {
                         $condition = $gstrField . "<" . $value;
                     } else {
                         if ($strSearchOption == "Equal or more than") {
                             $condition = $gstrField . ">=" . $value1;
                         } else {
                             if ($strSearchOption == "Equal or less than") {
                                 $condition = $gstrField . "<=" . $value1;
                             } else {
                                 if ($strSearchOption == "Between") {
                                     $value2 = $this->connection->prepareString($SearchFor2);
                                     if ($this->lookupType == LT_QUERY && IsCharType($this->type) && !$this->btexttype && $searchIsCaseInsensitive) {
                                         $value2 = $this->connection->upper($value2);
                                     }
                                     $condition = $gstrField . ">=" . $value . " and ";
                                     if (IsDateFieldType($this->type)) {
                                         $timeArr = db2time($SearchFor2);
                                         // for dates without time, add one day
                                         if ($timeArr[3] == 0 && $timeArr[4] == 0 && $timeArr[5] == 0) {
                                             $timeArr = adddays($timeArr, 1);
                                             $SearchFor2 = $timeArr[0] . "-" . $timeArr[1] . "-" . $timeArr[2];
                                             $SearchFor2 = add_db_quotes($this->field, $SearchFor2, $this->tName);
                                             $condition .= $gstrField . "<" . $SearchFor2;
                                         } else {
                                             $condition .= $gstrField . "<=" . $value2;
                                         }
                                     } else {
                                         $condition .= $gstrField . "<=" . $value2;
                                     }
                                 } else {
                                     if ($this->multiselect) {
                                         if (strpos($value, ",") !== false || strpos($value, '"') !== false) {
                                             $value = '"' . str_replace('"', '""', $value) . '"';
                                         }
                                         $fullFieldName = $this->getFieldSQLDecrypt();
                                         $value = $this->connection->escapeLIKEpattern($value);
                                         //for search by multiply Lookup wizard field
                                         $ret .= $fullFieldName . " = " . $this->connection->prepareString($value);
                                         $ret .= " or " . $fullFieldName . " " . $this->like . " " . $this->connection->prepareString("%," . $value . ",%");
                                         $ret .= " or " . $fullFieldName . " " . $this->like . " " . $this->connection->prepareString("%," . $value);
                                         $ret .= " or " . $fullFieldName . " " . $this->like . " " . $this->connection->prepareString($value . ",%");
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if ($condition != "" && ($isSuggest || $strSearchOption == "Contains" || $strSearchOption == "Equals" || $strSearchOption == "Starts with" || $strSearchOption == "More than" || $strSearchOption == "Less than" || $strSearchOption == "Equal or more than" || $strSearchOption == "Equal or less than" || $strSearchOption == "Between")) {
             if ($this->linkAndDisplaySame || $strSearchOption != "Contains" && $strSearchOption != "Starts with") {
                 $ret .= " " . $condition;
             } else {
                 return "";
             }
         }
     }
     $ret = trim($ret);
     if (strlen($ret)) {
         $ret = "(" . $ret . ")";
     }
     return $ret;
 }
예제 #10
0
 function baseSQLWhere($strSearchOption)
 {
     $this->btexttype = IsTextType($this->type);
     if (IsBinaryType($this->type)) {
         return false;
     }
     if ($strSearchOption == 'Empty') {
         if (IsCharType($this->type) && (!$this->ismssql || !$this->btexttype) && !$this->isOracle) {
             return "(" . GetFullFieldNameForInsert($this->pageObject->pSetEdit, $this->field) . " is null or " . GetFullFieldNameForInsert($this->pageObject->pSetEdit, $this->field) . "='')";
         } elseif ($this->ismssql && $this->btexttype) {
             return "(" . GetFullFieldNameForInsert($this->pageObject->pSetEdit, $this->field) . " is null or " . GetFullFieldNameForInsert($this->pageObject->pSetEdit, $this->field) . " LIKE '')";
         } else {
             return GetFullFieldNameForInsert($this->pageObject->pSetEdit, $this->field) . " is null";
         }
     }
     return "";
 }
예제 #11
0
 function SQLWhere($SearchFor, $strSearchOption, $SearchFor2, $etype, $isSuggest)
 {
     if ($this->lookupType == LT_LISTOFVALUES) {
         return parent::SQLWhere($SearchFor, $strSearchOption, $SearchFor2, $etype, $isSuggest);
     }
     $baseResult = $this->baseSQLWhere($strSearchOption);
     if ($baseResult === false) {
         return "";
     }
     if ($baseResult != "") {
         return $baseResult;
     }
     $displayFieldType = $this->type;
     if ($this->lookupType == LT_QUERY) {
         $displayFieldType = $this->lookupPSet->getFieldType($this->field);
         $this->btexttype = IsTextType($displayFieldType);
     }
     if ($this->multiselect) {
         $SearchFor = splitvalues($SearchFor);
     } else {
         $SearchFor = array($SearchFor);
     }
     $ret = "";
     if ($this->linkAndDisplaySame) {
         $gstrField = GetFullFieldName($this->field, "", false);
     } else {
         $gstrField = GetFullFieldName($this->displayFieldName, $this->lookupTable, false);
     }
     if ($this->customDisplay) {
         $gstrField = $this->lwDisplayFieldWrapped;
     } else {
         if (!$this->linkAndDisplaySame && $this->lookupType == LT_QUERY && IsCharType($displayFieldType) && !$this->btexttype && !$this->ciphererDisplay->isFieldPHPEncrypted($this->displayFieldName)) {
             $gstrField = $this->lookupPSet->isEnableUpper(GetFullFieldName($this->displayFieldName, $this->lookupTable, false));
         }
     }
     foreach ($SearchFor as $value) {
         if (!($value == "null" || $value == "Null" || $value == "")) {
             if (strlen(trim($ret))) {
                 $ret .= " or ";
             }
             if (!$this->multiselect) {
                 if ($strSearchOption == "Starts with") {
                     $value .= '%';
                 }
                 if ($isSuggest || $strSearchOption == "Contains") {
                     $value = '%' . $value . '%';
                 }
                 if ($isSuggest || $strSearchOption == "Contains" || $strSearchOption == "Starts with" || $strSearchOption == "More than" || $strSearchOption == "Less than" || $strSearchOption == "Equal or more than" || $strSearchOption == "Equal or less than" || $strSearchOption == "Between" || $strSearchOption == "Equals" && $this->LCType == LCT_AJAX && !$this->linkAndDisplaySame) {
                     $value = $this->escapeSearchValForMySQL($value);
                     if ($this->lookupType == LT_QUERY && IsCharType($displayFieldType) && !$this->btexttype) {
                         $value = $this->lookupPSet->isEnableUpper(db_prepare_string($value));
                     } else {
                         $value = db_prepare_string($value);
                     }
                 } else {
                     if ($strSearchOption == "Equals") {
                         $value = make_db_value($this->field, $value);
                     }
                 }
             }
             if ($strSearchOption == "Equals") {
                 if (!($value == "null" || $value == "Null")) {
                     if ($this->LCType == LCT_AJAX && !$this->linkAndDisplaySame) {
                         $condition = $gstrField . '=' . $value;
                     } else {
                         $condition = GetFullFieldName($this->field, "", false) . '=' . $value;
                     }
                 }
             } else {
                 if ($strSearchOption == "Starts with" || $strSearchOption == "Contains" && !$this->multiselect) {
                     $condition = $gstrField . " " . $this->like . " " . $value;
                 } else {
                     if ($strSearchOption == "More than") {
                         $condition = $gstrField . " > " . $value;
                     } else {
                         if ($strSearchOption == "Less than") {
                             $condition = $gstrField . "<" . $value;
                         } else {
                             if ($strSearchOption == "Equal or more than") {
                                 $condition = $gstrField . ">=" . $value1;
                             } else {
                                 if ($strSearchOption == "Equal or less than") {
                                     $condition = $gstrField . "<=" . $value1;
                                 } else {
                                     if ($strSearchOption == "Between") {
                                         if ($this->lookupType == LT_QUERY && IsCharType($displayFieldType) && !$this->btexttype) {
                                             $value2 = $this->lookupPSet->isEnableUpper(db_prepare_string($SearchFor2));
                                         } else {
                                             $value2 = db_prepare_string($SearchFor2);
                                         }
                                         $condition = $gstrField . ">=" . $value . " and ";
                                         if (IsDateFieldType($this->type)) {
                                             $timeArr = db2time($SearchFor2);
                                             // for dates without time, add one day
                                             if ($timeArr[3] == 0 && $timeArr[4] == 0 && $timeArr[5] == 0) {
                                                 $timeArr = adddays($timeArr, 1);
                                                 $SearchFor2 = $timeArr[0] . "-" . $timeArr[1] . "-" . $timeArr[2];
                                                 $SearchFor2 = add_db_quotes($this->field, $SearchFor2, $this->pageObject->tName);
                                                 $condition .= $gstrField . "<" . $SearchFor2;
                                             } else {
                                                 $condition .= $gstrField . "<=" . $value2;
                                             }
                                         } else {
                                             $condition .= $gstrField . "<=" . $value2;
                                         }
                                     } else {
                                         if (strpos($value, ",") !== false || strpos($value, '"') !== false) {
                                             $value = '"' . str_replace('"', '""', $value) . '"';
                                         }
                                         $value = $this->escapeSearchValForMySQL($value);
                                         //for search by multiply Lookup wizard field
                                         $ret .= GetFullFieldName($this->field, "", false) . " = " . db_prepare_string($value);
                                         $ret .= " or " . GetFullFieldName($this->field, "", false) . " " . $this->like . " " . db_prepare_string("%," . $value . ",%");
                                         $ret .= " or " . GetFullFieldName($this->field, "", false) . " " . $this->like . " " . db_prepare_string("%," . $value);
                                         $ret .= " or " . GetFullFieldName($this->field, "", false) . " " . $this->like . " " . db_prepare_string($value . ",%");
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if ($condition != "" && ($isSuggest || $strSearchOption == "Contains" || $strSearchOption == "Equals" || $strSearchOption == "Starts with" || $strSearchOption == "More than" || $strSearchOption == "Less than" || $strSearchOption == "Equal or more than" || $strSearchOption == "Equal or less than" || $strSearchOption == "Between")) {
                 if ($this->linkAndDisplaySame || $strSearchOption == "Equals" && $this->LCType != LCT_AJAX) {
                     $ret .= " " . $condition;
                 } else {
                     if ($this->lookupType == LT_QUERY) {
                         $lookupQueryObj = $this->lookupPSet->getSQLQuery();
                         $ret .= " EXISTS (" . $lookupQueryObj->toSql($condition . " and " . GetFullFieldName($this->linkFieldName, $this->lookupTable, false) . " = " . AddTableWrappers($this->pageObject->pSetEdit->getStrOriginalTableName()) . "." . AddFieldWrappers($this->field), '', null, false) . ")";
                     } else {
                         $ret .= " EXISTS (SELECT 1 as fld from " . AddTableWrappers($this->lookupTable) . " where " . $condition . " and " . $this->lwLinkField . " = " . AddTableWrappers($this->pageObject->pSetEdit->getStrOriginalTableName()) . "." . AddFieldWrappers($this->field) . ")";
                     }
                 }
             }
         }
     }
     if (strlen(trim($ret))) {
         $ret = "(" . $ret . ")";
     } else {
         $ret = trim($ret);
     }
     return $ret;
 }