Unify search criteria case insensitive

This commit is contained in:
Calvo 2021-10-22 12:02:31 +02:00
parent 80c7f106ad
commit f1f984614f
4 changed files with 25 additions and 10 deletions

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) function custom_graphs_search($id_group, $search)
{ {
if ($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.'%"'); $all_graphs = db_get_all_rows_sql('select * from tgraph where id_group = '.$id_group.' AND (name LIKE "%'.$search.'%" OR description LIKE "'.$search.'")');
} else if ($id_group != '') { } else if ($id_group != '') {
$all_graphs = db_get_all_rows_sql('select * from tgraph where id_group = '.$id_group.''); $all_graphs = db_get_all_rows_sql('select * from tgraph where id_group = '.$id_group.'');
} else { } else {
$all_graphs = db_get_all_rows_sql('select * from tgraph where name LIKE "%'.$search.'%"'); $all_graphs = db_get_all_rows_sql('select * from tgraph where name LIKE "%'.$search.'%" OR description LIKE "'.$search.'"');
} }
if ($all_graphs === false) { if ($all_graphs === false) {

View File

@ -1,5 +1,19 @@
/* global $, jQuery*/ /* global $, jQuery*/
/**
* Custom selector for case instensitive contains.
*/
jQuery.expr[":"].iContains = jQuery.expr.createPseudo(function(arg) {
return function(elem) {
return (
jQuery(elem)
.text()
.toUpperCase()
.indexOf(arg.toUpperCase()) >= 0
);
};
});
/** /**
* Add modules from available to selected. * Add modules from available to selected.
*/ */
@ -58,14 +72,14 @@ function filterItems(id, str) {
$("#" + id + " option[value=0]").remove(); $("#" + id + " option[value=0]").remove();
// Move not matching elements filtered to tmp-id. // Move not matching elements filtered to tmp-id.
var tmp = $("#" + id + " option:not(:contains(" + str + "))").toArray(); var tmp = $("#" + id + " option:not(:iContains(" + str + "))").toArray();
tmp.forEach(function(item) { tmp.forEach(function(item) {
$("#tmp-" + id).append(item); $("#tmp-" + id).append(item);
$(this).remove(); $(this).remove();
}); });
// Move matching filter back to id. // Move matching filter back to id.
tmp = $("#tmp-" + id + " option:contains(" + str + ")").toArray(); tmp = $("#tmp-" + id + " option:iContains(" + str + ")").toArray();
tmp.forEach(function(item) { tmp.forEach(function(item) {
$("#" + id).append(item); $("#" + id).append(item);
$(this).remove(); $(this).remove();

View File

@ -239,7 +239,8 @@ if ($free_search != '') {
WHERE id_agente IN ( WHERE id_agente IN (
SELECT id_agente SELECT id_agente
FROM tagente FROM tagente
WHERE nombre LIKE "%'.$free_search.'%") OR alias LIKE "%'.$free_search.'%")'.')'; WHERE nombre COLLATE utf8_general_ci LIKE "%'.$free_search.'%")
OR alias COLLATE utf8_general_ci LIKE "%'.$free_search.'%")'.')';
} else { } else {
$whereAlertSimple = ''; $whereAlertSimple = '';
} }

View File

@ -139,32 +139,32 @@ if ($searchAlerts) {
switch ($config['dbtype']) { switch ($config['dbtype']) {
case 'mysql': case 'mysql':
$whereAlerts = 'AND ( $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 name COLLATE utf8_general_ci LIKE "%'.$stringSearchSQL.'%") OR
id_alert_template IN ( id_alert_template IN (
SELECT id SELECT id
FROM talert_templates FROM talert_templates
WHERE id_alert_action IN ( WHERE id_alert_action IN (
SELECT id SELECT id
FROM talert_actions FROM talert_actions
WHERE name LIKE "%'.$stringSearchSQL.'%")) OR WHERE name COLLATE utf8_general_ci LIKE "%'.$stringSearchSQL.'%")) OR
talert_template_modules.id IN ( talert_template_modules.id IN (
SELECT id_alert_template_module SELECT id_alert_template_module
FROM talert_template_module_actions FROM talert_template_module_actions
WHERE id_alert_action IN ( WHERE id_alert_action IN (
SELECT id SELECT id
FROM talert_actions FROM talert_actions
WHERE name LIKE "%'.$stringSearchSQL.'%")) OR WHERE name COLLATE utf8_general_ci LIKE "%'.$stringSearchSQL.'%")) OR
id_agent_module IN ( id_agent_module IN (
SELECT id_agente_modulo SELECT id_agente_modulo
FROM tagente_modulo FROM tagente_modulo
WHERE nombre LIKE "%'.$stringSearchSQL.'%") OR WHERE nombre COLLATE utf8_general_ci LIKE "%'.$stringSearchSQL.'%") OR
id_agent_module IN ( id_agent_module IN (
SELECT id_agente_modulo SELECT id_agente_modulo
FROM tagente_modulo FROM tagente_modulo
WHERE id_agente IN ( WHERE id_agente IN (
SELECT id_agente SELECT id_agente
FROM tagente FROM tagente
WHERE nombre LIKE "%'.$stringSearchSQL.'%" '.$extra_sql.')) WHERE nombre COLLATE utf8_general_ci LIKE "%'.$stringSearchSQL.'%" '.$extra_sql.'))
)'; )';
break; break;