fixed search not calculating diskspace/traffic if no operator is used

Signed-off-by: Roman Schmerold (BNoiZe) <bnoize@froxlor.org>
This commit is contained in:
Roman Schmerold (BNoiZe)
2013-12-11 17:11:49 +01:00
parent 7eedf6e694
commit 911de0727f

View File

@@ -279,27 +279,40 @@ class paging {
} }
$searchfield = implode('.', $searchfield); $searchfield = implode('.', $searchfield);
// check for logical operators and whether searchtext is a number
// in any other case the logical-operators would make no sense
$ops = array('<', '>', '='); $ops = array('<', '>', '=');
if (in_array(substr($this->searchtext, 0, 1), $ops) && is_numeric(substr($this->searchtext, 1))) {
// if we're checking on traffic or diskspace, we need to adjust the search-value // check if we use an operator or not
if (strpos($searchfield, 'diskspace') > 0) { $useOper = 0;
// anything with diskspace is *1024 $oper = "=";
$searchtext = ((int)substr($this->searchtext, 1))*1024; if (in_array(substr($this->searchtext, 0, 1), $ops)) {
} elseif (strpos($searchfield, 'traffic') > 0) { $useOper = 1;
// anything with traffic is *1024*1024 $oper = substr($this->searchtext, 0, 1);
$searchtext = ((int)substr($this->searchtext, 1))*1024*1024; }
} else {
// any other field // check for diskspace and whether searchtext is a number
$searchtext = substr($this->searchtext, 1); // in any other case the logical-operators would make no sense
} if (strpos($searchfield, 'diskspace') > 0 && is_numeric(substr($this->searchtext, $useOper))) {
// anything with diskspace is *1024
$searchtext = ((int)substr($this->searchtext, $useOper))*1024;
$useOper = 1;
} elseif (strpos($searchfield, 'traffic') > 0 && is_numeric(substr($this->searchtext, $useOper))) {
// anything with traffic is *1024*1024
$searchtext = ((int)substr($this->searchtext, $useOper))*1024*1024;
$useOper = 1;
} else {
// any other field
$searchtext = substr($this->searchtext, $useOper);
}
if ($useOper == 1 && is_numeric(substr($this->searchtext, $useOper))) {
// now as we use >, < or = we use the given operator and not LIKE // now as we use >, < or = we use the given operator and not LIKE
$condition.= $searchfield . " ".substr($this->searchtext, 0, 1)." " . Database::quote($searchtext); $condition.= $searchfield . " ".$oper." " . Database::quote($searchtext);
} else { } else {
$searchtext = str_replace('*', '%', $this->searchtext); $searchtext = str_replace('*', '%', $this->searchtext);
$condition.= $searchfield . " LIKE " . Database::quote($searchtext); $condition.= $searchfield . " LIKE " . Database::quote($searchtext);
} }
} else { } else {
$condition = ''; $condition = '';
} }