From cb758fb86d04ea5231a9394bdd043e8b47d650b8 Mon Sep 17 00:00:00 2001 From: Lainow Date: Wed, 5 Mar 2025 11:19:53 +0100 Subject: [PATCH 01/15] Fix number search option --- inc/container.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/container.class.php b/inc/container.class.php index eb6712ec..cd925024 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -1962,7 +1962,7 @@ public static function getAddSearchOptions($itemtype, $containers_id = false) $opt[$i]['datatype'] = 'text'; break; case 'number': - $opt[$i]['datatype'] = 'decimal'; + $opt[$i]['datatype'] = 'float'; break; case 'date': case 'datetime': From acb0b07b3e67a44282692a085d25a453fc63989b Mon Sep 17 00:00:00 2001 From: Lainow Date: Wed, 5 Mar 2025 11:21:10 +0100 Subject: [PATCH 02/15] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index acb543d6..a4f8afe2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +- Force float `datatype` of `numeric` fields for fix the search option - Fix container update from other context (like plugins) ## [1.21.19] - 2025-02-03 From 77eb9a06ef5c2ade377e6aadd1b61573a3f00acd Mon Sep 17 00:00:00 2001 From: Lainow Date: Wed, 12 Mar 2025 17:26:24 +0100 Subject: [PATCH 03/15] Fix search option --- hook.php | 31 ++++++++++++++++++++++++++++--- inc/container.class.php | 4 +++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/hook.php b/hook.php index 2ee27aa7..f950b7eb 100644 --- a/hook.php +++ b/hook.php @@ -341,12 +341,37 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) /** @var \DBmysql $DB */ global $DB; - $searchopt = &Search::getOptions($itemtype); - $table = $searchopt[$ID]['table']; - $field = $searchopt[$ID]['field']; + $searchopt = &Search::getOptions($itemtype); + $table = $searchopt[$ID]['table']; + $field = $searchopt[$ID]['field']; + $pfields_type = $searchopt[$ID]['pfields_type']; $field_field = new PluginFieldsField(); + if ( + $field_field->getFromDBByCrit( + [ + 'name' => $field + ], + ) + && $pfields_type == 'number' + ) { + // if 'number' field with name is found with searchtype 'equals' or 'notequals' + // update WHERE clause with `$table_$field.$field` because without `$table_$field.id` is used + if ($searchtype == 'equals' || $searchtype == 'notequals') { + $operator = ($searchtype == 'equals') ? '=' : '!='; + return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . $operator . ' ' . $DB->quoteValue($val) ; + } else { + // if 'number' field with name is found with <= or >= or < or > search + $val = html_entity_decode($val); + if (preg_match('/(<=|>=|>|<)/', $val, $matches)) { + $operator = $matches[1]; + $val = trim(str_replace($operator, '', $val)); + return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . $operator . ' ' . $DB->quoteValue($val); + } + } + } + // if 'multiple' field with name is found -> 'Dropdown-XXXX' case // update WHERE clause with LIKE statement if ( diff --git a/inc/container.class.php b/inc/container.class.php index cd925024..38102de1 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -1962,7 +1962,9 @@ public static function getAddSearchOptions($itemtype, $containers_id = false) $opt[$i]['datatype'] = 'text'; break; case 'number': - $opt[$i]['datatype'] = 'float'; + // change datatype to string because decimal + $opt[$i]['datatype'] = 'string'; + $opt[$i]['searchtype'] = ['contains', 'notcontains', 'equals', 'notequals']; break; case 'date': case 'datetime': From a93d5957e89a7956930f64c341112154754d4d42 Mon Sep 17 00:00:00 2001 From: Lainow Date: Thu, 13 Mar 2025 09:15:16 +0100 Subject: [PATCH 04/15] Fix comment --- inc/container.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/container.class.php b/inc/container.class.php index 38102de1..d7e33e08 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -1962,7 +1962,7 @@ public static function getAddSearchOptions($itemtype, $containers_id = false) $opt[$i]['datatype'] = 'text'; break; case 'number': - // change datatype to string because decimal + // change datatype to string because SO does not work correctly with decimal numbers $opt[$i]['datatype'] = 'string'; $opt[$i]['searchtype'] = ['contains', 'notcontains', 'equals', 'notequals']; break; From 8500e3d37d19a3ac3c6af631b86c865cd9a2bf61 Mon Sep 17 00:00:00 2001 From: Lainow Date: Thu, 13 Mar 2025 09:19:12 +0100 Subject: [PATCH 05/15] Fix comment --- hook.php | 1 + 1 file changed, 1 insertion(+) diff --git a/hook.php b/hook.php index f950b7eb..989f284d 100644 --- a/hook.php +++ b/hook.php @@ -363,6 +363,7 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . $operator . ' ' . $DB->quoteValue($val) ; } else { // if 'number' field with name is found with <= or >= or < or > search + // update WHERE clause with the correct operator $val = html_entity_decode($val); if (preg_match('/(<=|>=|>|<)/', $val, $matches)) { $operator = $matches[1]; From e6521dbe3e7edbfff1fad20b96df78d01b5bf579 Mon Sep 17 00:00:00 2001 From: Lainow Date: Thu, 13 Mar 2025 09:21:36 +0100 Subject: [PATCH 06/15] Fix comment --- hook.php | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/hook.php b/hook.php index 989f284d..aa689390 100644 --- a/hook.php +++ b/hook.php @@ -348,31 +348,6 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) $field_field = new PluginFieldsField(); - if ( - $field_field->getFromDBByCrit( - [ - 'name' => $field - ], - ) - && $pfields_type == 'number' - ) { - // if 'number' field with name is found with searchtype 'equals' or 'notequals' - // update WHERE clause with `$table_$field.$field` because without `$table_$field.id` is used - if ($searchtype == 'equals' || $searchtype == 'notequals') { - $operator = ($searchtype == 'equals') ? '=' : '!='; - return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . $operator . ' ' . $DB->quoteValue($val) ; - } else { - // if 'number' field with name is found with <= or >= or < or > search - // update WHERE clause with the correct operator - $val = html_entity_decode($val); - if (preg_match('/(<=|>=|>|<)/', $val, $matches)) { - $operator = $matches[1]; - $val = trim(str_replace($operator, '', $val)); - return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . $operator . ' ' . $DB->quoteValue($val); - } - } - } - // if 'multiple' field with name is found -> 'Dropdown-XXXX' case // update WHERE clause with LIKE statement if ( From e75ea4961e4218cac8489c6615cc055b73797559 Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Thu, 13 Mar 2025 09:49:28 +0100 Subject: [PATCH 07/15] Update hook.php Co-authored-by: Stanislas --- hook.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hook.php b/hook.php index aa689390..d22e6fdf 100644 --- a/hook.php +++ b/hook.php @@ -344,7 +344,7 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) $searchopt = &Search::getOptions($itemtype); $table = $searchopt[$ID]['table']; $field = $searchopt[$ID]['field']; - $pfields_type = $searchopt[$ID]['pfields_type']; + $pfields_type = $searchopt[$ID]['pfields_type'] ?? ''; $field_field = new PluginFieldsField(); From 97b51e8443f54ab7595692254a983ad72e463a04 Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Thu, 13 Mar 2025 09:49:41 +0100 Subject: [PATCH 08/15] Update CHANGELOG.md Co-authored-by: Stanislas --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4f8afe2..927b9c8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed -- Force float `datatype` of `numeric` fields for fix the search option +- Fix `numeric` field search - Fix container update from other context (like plugins) ## [1.21.19] - 2025-02-03 From 749aa0bd7c578abc48ac32154481caf5324c6116 Mon Sep 17 00:00:00 2001 From: Lainow Date: Thu, 13 Mar 2025 09:53:46 +0100 Subject: [PATCH 09/15] Add suggestions --- hook.php | 26 ++++++++++++++++++++++++++ inc/container.class.php | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/hook.php b/hook.php index d22e6fdf..0fc9c323 100644 --- a/hook.php +++ b/hook.php @@ -348,6 +348,32 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) $field_field = new PluginFieldsField(); + if ( + $field_field->getFromDBByCrit( + [ + 'name' => $field, + 'type' => 'number' + ], + ) + && $pfields_type == 'number' + ) { + // if 'number' field with name is found with searchtype 'equals' or 'notequals' + // update WHERE clause with `$table_$field.$field` because without `$table_$field.id` is used + if ($searchtype == 'equals' || $searchtype == 'notequals') { + $operator = ($searchtype == 'equals') ? '=' : '!='; + return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . $operator . ' ' . $DB->quoteValue($val) ; + } else { + // if 'number' field with name is found with <= or >= or < or > search + // update WHERE clause with the correct operator + $val = html_entity_decode($val); + if (preg_match('/(<=|>=|>|<)/', $val, $matches)) { + $operator = $matches[1]; + $val = trim(str_replace($operator, '', $val)); + return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . $operator . ' ' . $DB->quoteValue($val); + } + } + } + // if 'multiple' field with name is found -> 'Dropdown-XXXX' case // update WHERE clause with LIKE statement if ( diff --git a/inc/container.class.php b/inc/container.class.php index d7e33e08..5bfe2995 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -1962,7 +1962,7 @@ public static function getAddSearchOptions($itemtype, $containers_id = false) $opt[$i]['datatype'] = 'text'; break; case 'number': - // change datatype to string because SO does not work correctly with decimal numbers + // change datatype to string to get `is` / `is not` operator $opt[$i]['datatype'] = 'string'; $opt[$i]['searchtype'] = ['contains', 'notcontains', 'equals', 'notequals']; break; From d86b90a3fd377479896a530be538716b91e7200d Mon Sep 17 00:00:00 2001 From: Lainow Date: Thu, 13 Mar 2025 09:58:18 +0100 Subject: [PATCH 10/15] Fix php cs --- hook.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hook.php b/hook.php index 0fc9c323..dbc8a02b 100644 --- a/hook.php +++ b/hook.php @@ -352,7 +352,7 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) $field_field->getFromDBByCrit( [ 'name' => $field, - 'type' => 'number' + 'type' => 'number', ], ) && $pfields_type == 'number' From d07827a2637385f475e5454c5d3e1a1ad79e84ad Mon Sep 17 00:00:00 2001 From: Lainow Date: Tue, 18 Mar 2025 13:51:18 +0100 Subject: [PATCH 11/15] Fix AND NOT & OR NOT for equals --- hook.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hook.php b/hook.php index dbc8a02b..a0ed6af8 100644 --- a/hook.php +++ b/hook.php @@ -361,6 +361,9 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) // update WHERE clause with `$table_$field.$field` because without `$table_$field.id` is used if ($searchtype == 'equals' || $searchtype == 'notequals') { $operator = ($searchtype == 'equals') ? '=' : '!='; + if ($nott) { + $link = $link . ' NOT '; + } return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . $operator . ' ' . $DB->quoteValue($val) ; } else { // if 'number' field with name is found with <= or >= or < or > search From a24873631232d621fafb1f6b8723792e1527d56f Mon Sep 17 00:00:00 2001 From: Lainow Date: Tue, 18 Mar 2025 14:07:22 +0100 Subject: [PATCH 12/15] Add cast --- hook.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hook.php b/hook.php index a0ed6af8..6b2c779d 100644 --- a/hook.php +++ b/hook.php @@ -364,7 +364,7 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) if ($nott) { $link = $link . ' NOT '; } - return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . $operator . ' ' . $DB->quoteValue($val) ; + return $link . 'CAST(' . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . ' AS DECIMAL(10,2))' . $operator . ' ' . $DB->quoteValue($val) ; } else { // if 'number' field with name is found with <= or >= or < or > search // update WHERE clause with the correct operator From c851b5d4c576ad5abfc02b2f6b1baba19460ae9f Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Wed, 19 Mar 2025 11:05:10 +0100 Subject: [PATCH 13/15] Update hook.php Co-authored-by: Stanislas --- hook.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hook.php b/hook.php index 6b2c779d..906ddf2a 100644 --- a/hook.php +++ b/hook.php @@ -364,7 +364,7 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) if ($nott) { $link = $link . ' NOT '; } - return $link . 'CAST(' . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . ' AS DECIMAL(10,2))' . $operator . ' ' . $DB->quoteValue($val) ; + return $link . 'CAST(' . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . ' AS DECIMAL(10,9))' . $operator . ' ' . $DB->quoteValue($val) ; } else { // if 'number' field with name is found with <= or >= or < or > search // update WHERE clause with the correct operator From 8322dc176000be018171fdd1734f48dc04cf533c Mon Sep 17 00:00:00 2001 From: Lainow Date: Wed, 19 Mar 2025 11:13:48 +0100 Subject: [PATCH 14/15] Fix decimal cast --- hook.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hook.php b/hook.php index 906ddf2a..615be71a 100644 --- a/hook.php +++ b/hook.php @@ -364,7 +364,7 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) if ($nott) { $link = $link . ' NOT '; } - return $link . 'CAST(' . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . ' AS DECIMAL(10,9))' . $operator . ' ' . $DB->quoteValue($val) ; + return $link . 'CAST(' . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . ' AS DECIMAL(10,8))' . $operator . ' ' . $DB->quoteValue($val) ; } else { // if 'number' field with name is found with <= or >= or < or > search // update WHERE clause with the correct operator From 494a3b37f0ddfc08e0e5e95ec592e2faa8b748ad Mon Sep 17 00:00:00 2001 From: Lainow Date: Thu, 20 Mar 2025 09:56:59 +0100 Subject: [PATCH 15/15] Fix Out of range sql warning --- hook.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hook.php b/hook.php index 615be71a..2ea90e48 100644 --- a/hook.php +++ b/hook.php @@ -364,7 +364,7 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) if ($nott) { $link = $link . ' NOT '; } - return $link . 'CAST(' . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . ' AS DECIMAL(10,8))' . $operator . ' ' . $DB->quoteValue($val) ; + return $link . 'CAST(' . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . ' AS DECIMAL(10,7))' . $operator . ' ' . $DB->quoteValue($val) ; } else { // if 'number' field with name is found with <= or >= or < or > search // update WHERE clause with the correct operator