@@ -338,12 +338,45 @@ function plugin_datainjection_populate_fields()
338338
339339function plugin_fields_addWhere ($ link , $ nott , $ itemtype , $ ID , $ val , $ searchtype )
340340{
341- $ searchopt = &Search::getOptions ($ itemtype );
342- $ table = $ searchopt [$ ID ]['table ' ];
343- $ field = $ searchopt [$ ID ]['field ' ];
341+ /** @var \DBmysql $DB */
342+ global $ DB ;
343+
344+ $ searchopt = &Search::getOptions ($ itemtype );
345+ $ table = $ searchopt [$ ID ]['table ' ];
346+ $ field = $ searchopt [$ ID ]['field ' ];
347+ $ pfields_type = $ searchopt [$ ID ]['pfields_type ' ] ?? '' ;
344348
345349 $ field_field = new PluginFieldsField ();
346350
351+ if (
352+ $ field_field ->getFromDBByCrit (
353+ [
354+ 'name ' => $ field ,
355+ 'type ' => 'number ' ,
356+ ],
357+ )
358+ && $ pfields_type == 'number '
359+ ) {
360+ // if 'number' field with name is found with searchtype 'equals' or 'notequals'
361+ // update WHERE clause with `$table_$field.$field` because without `$table_$field.id` is used
362+ if ($ searchtype == 'equals ' || $ searchtype == 'notequals ' ) {
363+ $ operator = ($ searchtype == 'equals ' ) ? '= ' : '!= ' ;
364+ if ($ nott ) {
365+ $ link = $ link . ' NOT ' ;
366+ }
367+ return $ link . 'CAST( ' . $ DB ->quoteName ("$ table " . '_ ' . "$ field " ) . '. ' . $ DB ->quoteName ($ field ) . ' AS DECIMAL(10,7)) ' . $ operator . ' ' . $ DB ->quoteValue ($ val ) ;
368+ } else {
369+ // if 'number' field with name is found with <= or >= or < or > search
370+ // update WHERE clause with the correct operator
371+ $ val = html_entity_decode ($ val );
372+ if (preg_match ('/(<=|>=|>|<)/ ' , $ val , $ matches )) {
373+ $ operator = $ matches [1 ];
374+ $ val = trim (str_replace ($ operator , '' , $ val ));
375+ return $ link . $ DB ->quoteName ("$ table " . '_ ' . "$ field " ) . '. ' . $ DB ->quoteName ($ field ) . $ operator . ' ' . $ DB ->quoteValue ($ val );
376+ }
377+ }
378+ }
379+
347380 // if 'multiple' field with name is found -> 'Dropdown-XXXX' case
348381 // update WHERE clause with LIKE statement
349382 if (
0 commit comments