public function buildWhereClause($pString) { if ($pString == '' and $_POST['search'] == '') { $this->pageWhereClause = $this->SQL->where; } else { $dq = '"'; // add querystring search ('s') + user entry (POST) $string = str_replace('\\"', '"', $_POST['search']) . ' ' . $pString; $searchFor = array(); $explode = array(); // put strings that are in quotes into an array $strings = getArrayFromString($string, '"'); for ($i = 0; $i < count($strings); $i++) { $searchFor[] = $strings[$i]; } // remove strings that are in quotes from the original string for ($i = 0; $i < count($searchFor); $i++) { $string = str_replace('"' . $searchFor[$i] . '"', ' ', $string); } // put individual words or strings into an array $explode = explode(' ', $string); for ($i = 0; $i < count($explode); $i++) { if ($explode[$i] != '') { $searchFor[] = $explode[$i]; } } // build the start of the where clause $whereClause = iif($this->SQL->where == '', ' WHERE (', $this->SQL->where . ' AND ('); $AND = ''; //loop through all the words or phrases for ($i = 0; $i < count($searchFor); $i++) { if (substr_count($searchFor[$i], ' ') == 0 and substr($searchFor[$i], 0, 1) == '-') { $LIKE = ' NOT LIKE '; $ANDOR = ' AND '; $searchFor[$i] = substr($searchFor[$i], 1); } else { $LIKE = ' LIKE '; $ANDOR = ' OR '; } $columnWhere = ''; // loop through all the searchable fields for ($ii = 0; $ii < count($this->Column); $ii++) { if ($this->Column[$ii]->sbr_searchable == '1') { if ($columnWhere == '') { $columnWhere = $columnWhere . " \n{$AND} (\n(" . $this->Column[$ii]->sbr_display . " {$LIKE} {$dq}%" . $searchFor[$i] . '%") '; $AND = ') AND'; } else { $columnWhere = $columnWhere . "\n" . " {$ANDOR} (" . $this->Column[$ii]->sbr_display . " {$LIKE} {$dq}%" . $searchFor[$i] . '%") '; } } } $whereClause = $whereClause . $columnWhere; } $this->pageWhereClause = $whereClause . '))'; } }
function displayCondition_old($string, $recordID, $recordValues) { if ($string == '') { return true; } //--- replace variables in string with GLOBAL variables and/or $id $string = replaceVariablesInString('', $string, $recordID); //--- get array of other values that need replacing $hash = getArrayFromString($string, '#'); //--- loop through array replacing variables in string with values for ($i = 0; $i < count($hash); $i++) { $fieldname = $hash[$i]; $string = str_replace('#' . $hash[$i] . '#', $recordValues[$fieldname], $string); } //--- Run string as a select statement // $t = nuRunQuery('SELECT '.$string); $t = nuRunQuery($string); $answer = db_fetch_row($t); return $answer[0] == '1'; //---if answer = 1 then return True }