private function _getWhereClause($table)
{
// Columns to select
$allColumns = $GLOBALS['dbi']->getColumns($GLOBALS['db'], $table);
$likeClauses = array();
// Based on search type, decide like/regex & '%'/''
$like_or_regex = $this->_criteriaSearchType == 4 ? 'REGEXP' : 'LIKE';
$automatic_wildcard = $this->_criteriaSearchType < 3 ? '%' : '';
// For "as regular expression" (search option 4), LIKE won't be used
// Usage example: If user is searching for a literal $ in a regexp search,
// he should enter \$ as the value.
$criteriaSearchStringEscaped = $GLOBALS['dbi']->escapeString($this->_criteriaSearchString);
// Extract search words or pattern
$search_words = $this->_criteriaSearchType > 2 ? array($criteriaSearchStringEscaped) : explode(' ', $criteriaSearchStringEscaped);
foreach ($search_words as $search_word) {
// Eliminates empty values
if (strlen($search_word) === 0) {
continue;
}
$likeClausesPerColumn = array();
// for each column in the table
foreach ($allColumns as $column) {
if (!isset($this->_criteriaColumnName) || strlen($this->_criteriaColumnName) === 0 || $column['Field'] == $this->_criteriaColumnName) {
$column = 'CONVERT(' . Util::backquote($column['Field']) . ' USING utf8)';
$likeClausesPerColumn[] = $column . ' ' . $like_or_regex . ' ' . "'" . $automatic_wildcard . $search_word . $automatic_wildcard . "'";
}
}
// end for
if (count($likeClausesPerColumn) > 0) {
$likeClauses[] = implode(' OR ', $likeClausesPerColumn);
}
}
// end for
// Use 'OR' if 'at least one word' is to be searched, else use 'AND'
$implode_str = $this->_criteriaSearchType == 1 ? ' OR ' : ' AND ';
if (empty($likeClauses)) {
// this could happen when the "inside column" does not exist
// in any selected tables
$where_clause = ' WHERE FALSE';
} else {
$where_clause = ' WHERE (' . implode(') ' . $implode_str . ' (', $likeClauses) . ')';
}
return $where_clause;
}