mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-26 08:03:51 +02:00
- Compress API filters to a loop
- Check for filters for valid fields
This commit is contained in:
+12
-8
@@ -69,17 +69,21 @@ class component {
|
||||
$COUNT = 0;
|
||||
if (isset($options['filter'])) {
|
||||
$COUNT++;
|
||||
$validFields = array('device_id','type','id','label','status','disabled','ignore','error');
|
||||
$SQL .= " ( ";
|
||||
foreach ($options['filter'] as $field => $array) {
|
||||
if ($array[0] == 'LIKE') {
|
||||
$SQL .= "`".$field."` LIKE ? AND ";
|
||||
$array[1] = "%".$array[1]."%";
|
||||
// Only add valid fields to the query
|
||||
if (in_array($field,$validFields)) {
|
||||
if ($array[0] == 'LIKE') {
|
||||
$SQL .= "`".$field."` LIKE ? AND ";
|
||||
$array[1] = "%".$array[1]."%";
|
||||
}
|
||||
else {
|
||||
// Equals operator is the default
|
||||
$SQL .= "`".$field."` = ? AND ";
|
||||
}
|
||||
array_push($PARAM,$array[1]);
|
||||
}
|
||||
else {
|
||||
// Equals operator is the default
|
||||
$SQL .= "`".$field."` = ? AND ";
|
||||
}
|
||||
array_push($PARAM,$array[1]);
|
||||
}
|
||||
// Strip the last " AND " before closing the bracket.
|
||||
$SQL = substr($SQL,0,-5)." )";
|
||||
|
||||
Reference in New Issue
Block a user