Merge branch 'ent-11537-bug-en-cuadros-de-busqueda-con-los-caracteres-2-y-0' into 'develop'

Ent 11537 bug en cuadros de busqueda con los caracteres 2 y 0

See merge request artica/pandorafms!6410
This commit is contained in:
Rafael Ameijeiras 2023-12-11 14:30:51 +00:00
commit 7f75445d75
16 changed files with 84 additions and 74 deletions

View File

@ -566,10 +566,10 @@ if ($search != '') {
if ($id != '') {
$aux = $id[0]['id_agent'];
$search_sql = sprintf(
' AND ( nombre LIKE "%%%s%%"
OR alias LIKE "%%%s%%"
OR comentarios LIKE "%%%s%%"
OR EXISTS (SELECT * FROM tagent_custom_data WHERE id_agent = id_agente AND description LIKE "%%%s%%")
' AND ( REPLACE(nombre, " ", " ") LIKE "%%%s%%"
OR REPLACE(alias, " ", " ") LIKE "%%%s%%"
OR REPLACE(comentarios, " ", " ") LIKE "%%%s%%"
OR EXISTS (SELECT * FROM tagent_custom_data WHERE id_agent = id_agente AND REPLACE(description, " ", " ") LIKE "%%%s%%")
OR tagente.id_agente = %d',
$search,
$search,
@ -591,10 +591,10 @@ if ($search != '') {
$search_sql .= ')';
} else {
$search_sql = sprintf(
' AND ( nombre
LIKE "%%%s%%" OR alias
LIKE "%%%s%%" OR comentarios LIKE "%%%s%%"
OR EXISTS (SELECT * FROM tagent_custom_data WHERE id_agent = id_agente AND description LIKE "%%%s%%"))',
' AND ( REPLACE(nombre, " ", " ")
LIKE "%%%s%%" OR REPLACE(alias, " ", " ")
LIKE "%%%s%%" OR REPLACE(comentarios, " ", " ") LIKE "%%%s%%"
OR EXISTS (SELECT * FROM tagent_custom_data WHERE id_agent = id_agente AND REPLACE(description, " ", " ") LIKE "%%%s%%"))',
$search,
$search,
$search,

View File

@ -575,7 +575,7 @@ $where = sprintf('delete_pending = 0 AND id_agente = %s', $id_agente);
$search_string_entities = io_safe_input($search_string);
$basic_where = sprintf(
"(nombre LIKE '%%%s%%' OR nombre LIKE '%%%s%%' OR descripcion LIKE '%%%s%%' OR descripcion LIKE '%%%s%%') AND",
"(REPLACE(nombre, ' ', ' ') LIKE '%%%s%%' OR REPLACE(nombre, ' ', ' ') LIKE '%%%s%%' OR REPLACE(descripcion, ' ', ' ') LIKE '%%%s%%' OR REPLACE(descripcion, ' ', ' ') LIKE '%%%s%%') AND",
$search_string,
$search_string_entities,
$search_string,

View File

@ -729,7 +729,7 @@ if ($search_id_group) {
}
if ($search_string != '') {
$filter[] = '(name LIKE '."'%".$search_string."%'".'OR description LIKE '."'%".$search_string."%'".'OR tcp_send LIKE '."'%".$search_string."%'".'OR tcp_rcv LIKE '."'%".$search_string."%'".')';
$filter[] = '(REPLACE(name, " ", " ") LIKE '."'%".$search_string."%'".' OR REPLACE(REPLACE(description, " ", " "), "&#x20", " ")LIKE '."'%".$search_string."%'".' OR REPLACE(tcp_send, " ", " ") LIKE '."'%".$search_string."%'".'OR REPLACE(tcp_rcv, " ", " ") LIKE '."'%".$search_string."%'".')';
}
$total_components = network_components_get_network_components(

View File

@ -118,7 +118,7 @@ class ConfigPEN extends HTML
if (is_array($filter)) {
if (!empty($filter['free_search'])) {
$sql_filters[] = vsprintf(
' AND (lower(`manufacturer`) like lower("%%%s%%")
' AND (lower(REPLACE(manufacturer, " ", " ")) like lower("%%%s%%")
OR pen = "%s") ',
array_fill(0, 2, $filter['free_search'])
);

View File

@ -194,11 +194,11 @@ function custom_graphs_get_user($id_user=0, $only_names=false, $returnAllGroup=t
function custom_graphs_search($id_group, $search)
{
if ($id_group != '' && $search != '') {
$all_graphs = db_get_all_rows_sql('select * from tgraph where id_group = '.$id_group.' AND (name LIKE "%'.$search.'%" OR description LIKE "'.$search.'")');
$all_graphs = db_get_all_rows_sql('select * from tgraph where id_group = '.$id_group.' AND (REPLACE(name, " ", " ") LIKE "%'.$search.'%" OR REPLACE(description, " ", " ") LIKE "'.$search.'")');
} else if ($id_group != '') {
$all_graphs = db_get_all_rows_sql('select * from tgraph where id_group = '.$id_group.'');
} else {
$all_graphs = db_get_all_rows_sql('select * from tgraph where name LIKE "%'.$search.'%" OR description LIKE "'.$search.'"');
$all_graphs = db_get_all_rows_sql('select * from tgraph where REPLACE(name, " ", " ") LIKE "%'.$search.'%" OR REPLACE(description, " ", " ") LIKE "'.$search.'"');
}
if ($all_graphs === false) {

View File

@ -77,7 +77,7 @@ function inventory_get_data(
}
if ($inventory_search_string != '') {
array_push($where, "tagent_module_inventory.data LIKE '%".$inventory_search_string."%'");
array_push($where, "REPLACE(tagent_module_inventory.data, ' ', ' ') LIKE '%".$inventory_search_string."%'");
}
$offset = (int) get_parameter('offset');
@ -746,7 +746,7 @@ function inventory_get_datatable(
}
if ($inventory_search_string != '') {
array_push($where, "tagent_module_inventory.data LIKE '%".$inventory_search_string."%'");
array_push($where, "REPLACE(tagente_datos_inventory.data, ' ', ' ') LIKE '%".$inventory_search_string."%'");
}
if ($utimestamp > 0) {
@ -786,7 +786,6 @@ function inventory_get_datatable(
}
$rows = db_get_all_rows_sql($sql);
if ($order_by_agent === false) {
$modules = [];
foreach ($rows as $row) {
@ -796,7 +795,13 @@ function inventory_get_datatable(
$data_rows = explode(PHP_EOL, $row['data_inventory']);
foreach ($data_rows as $data_key => $data_value) {
if (empty($data_value) === false) {
if (empty($inventory_search_string) !== true) {
$search_check = strpos(str_replace(' ', ' ', $data_value), $inventory_search_string);
} else {
$search_check = true;
}
if (empty($data_value) === false && $search_check !== false) {
$row['data'] = $data_value;
$modules[$row['name']][$row['name_agent'].'-'.$data_key.'-'.$data_value] = $row;
}
@ -889,7 +894,7 @@ function get_data_basic_info_sql($params, $count=false)
if ($params['search'] > 0) {
$where .= sprintf(
' AND ( alias LIKE "%%%s%%" )',
' AND ( REPLACE(alias, " ", " ") LIKE "%%%s%%" )',
$params['search']
);
}

View File

@ -1289,6 +1289,10 @@ if ($inventory_module !== 'basic') {
$style = 'width: 100%';
$ordering = true;
$searching = false;
$search = [];
if (strlen($inventory_search_string) > 0) {
$search['value'] = $inventory_search_string;
}
$columns = [
'alias',
@ -1338,6 +1342,7 @@ if ($inventory_module !== 'basic') {
'get_data_basic_info' => 1,
'id_agent' => $id_agente,
'id_group' => $inventory_id_group,
'search' => $search,
],
'zeroRecords' => __('Agent info not found'),
'emptyTable' => __('Agent info not found'),

View File

@ -76,15 +76,15 @@ if ($searchAgents) {
$sql = "SELECT DISTINCT taddress_agent.id_agent FROM taddress
INNER JOIN taddress_agent ON
taddress.id_a = taddress_agent.id_a
WHERE taddress.ip LIKE '$stringSearchSQL'";
WHERE LOWER(REPLACE(taddress.ip, ' ', ' ')) LIKE LOWER('$stringSearchSQL')";
$id = db_get_all_rows_sql($sql);
if ($id != '') {
$aux = $id[0]['id_agent'];
$search_sql = " t1.nombre LIKE '".$stringSearchSQL."' OR
t2.nombre LIKE '".$stringSearchSQL."' OR
t1.alias LIKE '".$stringSearchSQL."' OR
t1.comentarios LIKE '".$stringSearchSQL."' OR
$search_sql = " LOWER(REPLACE(t1.nombre, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR
LOWER(REPLACE(t2.nombre, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR
LOWER(REPLACE(t1.alias, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR
LOWER(REPLACE(t1.comentarios, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR
t1.id_agente =".$aux;
$idCount = count($id);
@ -96,16 +96,16 @@ if ($searchAgents) {
}
}
} else {
$search_sql = " t1.nombre LIKE '".$stringSearchSQL."' OR
t2.nombre LIKE '".$stringSearchSQL."' OR
t1.direccion LIKE '".$stringSearchSQL."' OR
t1.comentarios LIKE '".$stringSearchSQL."' OR
t1.alias LIKE '".$stringSearchSQL."'";
$search_sql = " LOWER(REPLACE(t1.nombre, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR
LOWER(REPLACE(t2.nombre, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR
LOWER(REPLACE(t1.direccion, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR
LOWER(REPLACE(t1.comentarios, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR
LOWER(REPLACE(t1.alias, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."')";
}
if ($has_secondary === true) {
$search_sql .= " OR (tasg.id_group IS NOT NULL AND
tasg.id_group IN (SELECT id_grupo FROM tgrupo WHERE nombre LIKE '".$stringSearchSQL."'))";
tasg.id_group IN (SELECT id_grupo FROM tgrupo WHERE LOWER(REPLACE(nombre, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."')))";
}
$sql = "

View File

@ -139,64 +139,64 @@ if ($searchAlerts) {
switch ($config['dbtype']) {
case 'mysql':
$whereAlerts = 'AND (
id_alert_template IN (SELECT id FROM talert_templates WHERE name LIKE "%'.$stringSearchSQL.'%") OR
id_alert_template IN (SELECT id FROM talert_templates WHERE REPLACE(name, " ", " ") LIKE "%'.$stringSearchSQL.'%") OR
id_alert_template IN (
SELECT id
FROM talert_templates
WHERE id_alert_action IN (
SELECT id
FROM talert_actions
WHERE name LIKE "%'.$stringSearchSQL.'%")) OR
WHERE REPLACE(name, " ", " ") LIKE "%'.$stringSearchSQL.'%")) OR
talert_template_modules.id IN (
SELECT id_alert_template_module
FROM talert_template_module_actions
WHERE id_alert_action IN (
SELECT id
FROM talert_actions
WHERE name LIKE "%'.$stringSearchSQL.'%")) OR
WHERE REPLACE(name, " ", " ") LIKE "%'.$stringSearchSQL.'%")) OR
id_agent_module IN (
SELECT id_agente_modulo
FROM tagente_modulo
WHERE nombre LIKE "%'.$stringSearchSQL.'%") OR
WHERE REPLACE(nombre, " ", " ") LIKE "%'.$stringSearchSQL.'%") OR
id_agent_module IN (
SELECT id_agente_modulo
FROM tagente_modulo
WHERE id_agente IN (
SELECT id_agente
FROM tagente
WHERE nombre LIKE "%'.$stringSearchSQL.'%" '.$extra_sql.'))
WHERE REPLACE(nombre, " ", " ") LIKE "%'.$stringSearchSQL.'%" '.$extra_sql.'))
)';
break;
case 'postgresql':
case 'oracle':
$whereAlerts = 'AND (
id_alert_template IN (SELECT id FROM talert_templates WHERE upper(name) LIKE \'%'.strtolower($stringSearchSQL).'%\') OR
id_alert_template IN (SELECT id FROM talert_templates WHERE upper(REPLACE(name, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\') OR
id_alert_template IN (
SELECT id
FROM talert_templates
WHERE id_alert_action IN (
SELECT id
FROM talert_actions
WHERE upper(name) LIKE \'%'.strtolower($stringSearchSQL).'%\')) OR
WHERE upper(REPLACE(name, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\')) OR
talert_template_modules.id IN (
SELECT id_alert_template_module
FROM talert_template_module_actions
WHERE id_alert_action IN (
SELECT id
FROM talert_actions
WHERE upper(name) LIKE \'%'.strtolower($stringSearchSQL).'%\')) OR
WHERE upper(REPLACE(name, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\')) OR
id_agent_module IN (
SELECT id_agente_modulo
FROM tagente_modulo
WHERE upper(nombre) LIKE \'%'.strtolower($stringSearchSQL).'%\') OR
WHERE upper(REPLACE(nombre, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\') OR
id_agent_module IN (
SELECT id_agente_modulo
FROM tagente_modulo
WHERE id_agente IN (
SELECT id_agente
FROM tagente
WHERE upper(nombre) LIKE \'%'.strtolower($stringSearchSQL).'%\' '.$extra_sql.'))
WHERE upper(REPLACE(nombre, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\' '.$extra_sql.'))
)';
$agents = false;
break;

View File

@ -31,7 +31,7 @@ if ($searchGraphs) {
}
$filter = [];
$filter[] = "(upper(name) LIKE '%".strtolower($stringSearchSQL)."%' OR upper(description) LIKE '%$".strtolower($stringSearchSQL)."%')";
$filter[] = "(upper(REPLACE(name, ' ', ' ')) LIKE '%".strtolower($stringSearchSQL)."%' OR upper(REPLACE(description, ' ', ' ')) LIKE '%$".strtolower($stringSearchSQL)."%')";
$filter['id_graph'] = $usergraphs_id;
$columns = [

View File

@ -62,10 +62,10 @@ $sql = "SELECT DISTINCT taddress_agent.id_agent FROM taddress
$id = db_get_all_rows_sql($sql);
if ($id != '') {
$aux = $id[0]['id_agent'];
$search_sql = " t1.nombre LIKE '".$stringSearchSQL."' OR
t2.nombre LIKE '".$stringSearchSQL."' OR
t1.alias LIKE '".$stringSearchSQL."' OR
t1.comentarios LIKE '".$stringSearchSQL."' OR
$search_sql = " REPLACE(t1.nombre, ' ', ' ') LIKE '".$stringSearchSQL."' OR
REPLACE(t2.nombre, ' ', ' ') LIKE '".$stringSearchSQL."' OR
REPLACE(t1.alias, ' ', ' ') LIKE '".$stringSearchSQL."' OR
REPLACE(t1.comentarios, ' ', ' ') LIKE '".$stringSearchSQL."' OR
t1.id_agente =".$aux;
$idCount = count($id);
@ -77,16 +77,16 @@ if ($id != '') {
}
}
} else {
$search_sql = " t1.nombre LIKE '".$stringSearchSQL."' OR
t2.nombre LIKE '".$stringSearchSQL."' OR
t1.direccion LIKE '".$stringSearchSQL."' OR
t1.comentarios LIKE '".$stringSearchSQL."' OR
t1.alias LIKE '".$stringSearchSQL."'";
$search_sql = " REPLACE(t1.nombre, ' ', ' ') LIKE '".$stringSearchSQL."' OR
REPLACE(t2.nombre, ' ', ' ') LIKE '".$stringSearchSQL."' OR
REPLACE(t1.direccion, ' ', ' ') LIKE '".$stringSearchSQL."' OR
REPLACE(t1.comentarios, ' ', ' ') LIKE '".$stringSearchSQL."' OR
REPLACE(t1.alias, ' ', ' ') LIKE '".$stringSearchSQL."'";
}
if ($has_secondary === true) {
$search_sql .= " OR (tasg.id_group IS NOT NULL AND
tasg.id_group IN (SELECT id_grupo FROM tgrupo WHERE nombre LIKE '".$stringSearchSQL."'))";
tasg.id_group IN (SELECT id_grupo FROM tgrupo WHERE REPLACE(nombre, ' ', ' ') LIKE '".$stringSearchSQL."'))";
}
$sql = "

View File

@ -32,7 +32,7 @@ if ((bool) $searchMaps === true) {
FROM tlayout tl
LEFT JOIN tlayout_data tld
ON tl.id = tld.id_layout
WHERE tl.name LIKE "%%%s%%"
WHERE REPLACE(tl.name, " ", " ") LIKE "%%%s%%"
AND tl.id_group IN (%s)
GROUP BY tl.id, tl.name, tl.id_group',
$stringSearchSQL,

View File

@ -142,8 +142,8 @@ if ($searchModules) {
)
)
AND
(t1.nombre LIKE "%'.$stringSearchSQL.'%" OR
t3.nombre LIKE "%'.$stringSearchSQL.'%")
(REPLACE(t1.nombre, " ", " ") LIKE "%'.$stringSearchSQL.'%" OR
REPLACE(t3.nombre, " ", " ") LIKE "%'.$stringSearchSQL.'%")
AND t1.disabled = 0';
break;
@ -172,8 +172,8 @@ if ($searchModules) {
)
)
) AND
(t1.nombre LIKE \'%'.$stringSearchSQL.'%\' OR
t3.nombre LIKE \'%'.$stringSearchSQL.'%\')';
(REPLACE(t1.nombre, " ", " ") LIKE \'%'.$stringSearchSQL.'%\' OR
REPLACE(t3.nombre, " ", " ") LIKE \'%'.$stringSearchSQL.'%\')';
break;
case 'oracle':
@ -201,8 +201,8 @@ if ($searchModules) {
)
)
) AND
(LOWER(t1.nombre) LIKE \'%'.strtolower($stringSearchSQL).'%\' OR
LOWER(t3.nombre) LIKE \'%'.strtolower($stringSearchSQL).'%\')';
(LOWER(REPLACE(t1.nombre, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\' OR
LOWER(REPLACE(t3.nombre, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\')';
break;
}

View File

@ -207,7 +207,7 @@ if ($searchpolicies === true) {
$sql = "SELECT id, name, description, id_group, status
FROM tpolicies
WHERE name LIKE '$stringSearchSQL'
WHERE REPLACE(name, ' ', ' ') LIKE '$stringSearchSQL'
AND id_group IN ($id_user_groups_str)
";
}

View File

@ -46,13 +46,13 @@ if ($searchReports) {
case 'postgresql':
$sql = "SELECT id_report, name, description
FROM treport
WHERE (name LIKE '%".$stringSearchSQL."%' OR description LIKE '%".$stringSearchSQL."%')".$reports_condition;
WHERE (REPLACE(name, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR REPLACE(description, ' ', ' ') LIKE '%".$stringSearchSQL."%')".$reports_condition;
break;
case 'oracle':
$sql = "SELECT id_report, name, description
FROM treport
WHERE (upper(name) LIKE '%".strtolower($stringSearchSQL)."%' OR description LIKE '%".strtolower($stringSearchSQL)."%')".$reports_condition;
WHERE (upper(REPLACE(name, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR REPLACE(description, ' ', ' ') LIKE '%".strtolower($stringSearchSQL)."%')".$reports_condition;
break;
}
@ -77,13 +77,13 @@ if ($searchReports) {
case 'postgresql':
$sql_count = "SELECT COUNT(id_report) AS count
FROM treport
WHERE (name LIKE '%".$stringSearchSQL."%' OR description LIKE '%".$stringSearchSQL."%')".$reports_condition;
WHERE (REPLACE(name, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR REPLACE(description, ' ', ' ') LIKE '%".$stringSearchSQL."%')".$reports_condition;
break;
case 'oracle':
$sql_count = "SELECT COUNT(id_report) AS count
FROM treport
WHERE (upper(name) LIKE '%".strtolower($stringSearchSQL)."%' OR upper(description) LIKE '%".strtolower($stringSearchSQL)."%')".$reports_condition;
WHERE (upper(REPLACE(name, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR upper(REPLACE(description, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%')".$reports_condition;
break;
}

View File

@ -179,23 +179,23 @@ if ($searchUsers) {
case 'mysql':
case 'postgresql':
$sql = "SELECT id_user, fullname, firstname, lastname, middlename, email, last_connect, is_admin, comments FROM tusuario
WHERE fullname LIKE '%".$stringSearchSQL."%' OR
id_user LIKE '%".$stringSearchSQL."%' OR
firstname LIKE '%".$stringSearchSQL."%' OR
lastname LIKE '%".$stringSearchSQL."%' OR
middlename LIKE '%".$stringSearchSQL."%' OR
email LIKE '%".$stringSearchSQL."%'
WHERE REPLACE(fullname, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR
REPLACE(id_user, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR
REPLACE(firstname, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR
REPLACE(lastname, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR
REPLACE(middlename, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR
REPLACE(email, ' ', ' ') LIKE '%".$stringSearchSQL."%'
ORDER BY ".$order['field'].' '.$order['order'];
break;
case 'oracle':
$sql = "SELECT id_user, fullname, firstname, lastname, middlename, email, last_connect, is_admin, comments FROM tusuario
WHERE upper(fullname) LIKE '%".strtolower($stringSearchSQL)."%' OR
upper(id_user) LIKE '%".strtolower($stringSearchSQL)."%' OR
upper(firstname) LIKE '%".strtolower($stringSearchSQL)."%' OR
upper(lastname) LIKE '%".strtolower($stringSearchSQL)."%' OR
upper(middlename) LIKE '%".strtolower($stringSearchSQL)."%' OR
upper(email) LIKE '%".strtolower($stringSearchSQL)."%'
WHERE upper(REPLACE(fullname, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR
upper(REPLACE(id_user, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR
upper(REPLACE(firstname, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR
upper(REPLACE(lastname, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR
upper(REPLACE(middlename, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR
upper(REPLACE(email, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%'
ORDER BY ".$order['field'].' '.$order['order'];
break;
}