Merge branch 'ent-7995-unificar-criterios-de-busqueda-que-no-sean-case-sensitive' into 'develop'

Unify search criteria case insensitive

See merge request artica/pandorafms!4496
This commit is contained in:
Daniel Rodriguez 2021-11-29 11:08:00 +00:00
commit 198959f6cb
5 changed files with 30 additions and 11 deletions

View File

@ -760,9 +760,13 @@ function mysql_db_format_array_where_clause_sql($values, $join='AND', $prefix=fa
if ($field[0] != '`') { if ($field[0] != '`') {
// If the field is as <table>.<field>, don't scape. // If the field is as <table>.<field>, don't scape.
if (strstr($field, '.') === false) { if (strstr($field, '.') === false) {
if (preg_match('/(UPPER|LOWER)(.+)/mi', $field)) {
$field = preg_replace('/(UPPER|LOWER])\((.+)\)/mi', '$1(`$2`)', $field);
} else {
$field = '`'.$field.'`'; $field = '`'.$field.'`';
} }
} }
}
if ($value === null) { if ($value === null) {
$not = (($negative === true) ? 'NOT' : ''); $not = (($negative === true) ? 'NOT' : '');

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;