diff --git a/CHANGELOG.md b/CHANGELOG.md index 42d4784c..bb7b07b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fix incompatibility of `multiple` dropdowns with `massiveaction` - Fix default value properly applied in multiple dropdown search options +- Fix `search option` for default values in `multiple` dropdown ## [1.21.22] - 2025-05-28 diff --git a/hook.php b/hook.php index f6fadaa9..2835d88a 100644 --- a/hook.php +++ b/hook.php @@ -390,9 +390,9 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) $tablefield = "$table" . '_' . "$field"; switch ($searchtype) { case 'equals': - return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'notequals' : 'equals'); + return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'notequals' : 'equals', $itemtype, $field_field); case 'notequals': - return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'equals' : 'notequals'); + return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'equals' : 'notequals', $itemtype, $field_field); } } else { // if 'multiple' field with cleaned name is found -> 'dropdown' case @@ -410,9 +410,9 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) ) { switch ($searchtype) { case 'equals': - return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'notequals' : 'equals'); + return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'notequals' : 'equals', $itemtype, $field_field); case 'notequals': - return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'equals' : 'notequals'); + return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'equals' : 'notequals', $itemtype, $field_field); } } else { return false; diff --git a/inc/dropdown.class.php b/inc/dropdown.class.php index 727c6d09..926b670a 100644 --- a/inc/dropdown.class.php +++ b/inc/dropdown.class.php @@ -255,16 +255,32 @@ public static function getClassname($system_name) return 'PluginFields' . ucfirst($system_name) . 'Dropdown'; } - public static function multipleDropdownAddWhere($link, $tablefield, $field, $val, $searchtype) + public static function multipleDropdownAddWhere($link, $tablefield, $field, $val, $searchtype, $itemtype, $field_field) { /** @var \DBmysql $DB */ global $DB; + $default_value_request = ""; + + if ($field_field->fields['default_value'] === '["' . $val . '"]') { + switch ($searchtype) { + case 'equals': + $default_value_request = ' OR (' . $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName('itemtype') . ' IS NULL' . + ' AND ' . $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName('items_id') . ' IS NULL)'; + break; + case 'notequals': + $default_value_request = ' AND (' . $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName('itemtype') . '=' . $DB->quoteValue($itemtype) . + ' OR ' . $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName('items_id') . '=' . $itemtype::getTable() . '.id)'; + break; + } + } + switch ($searchtype) { case 'equals': - return $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ; + return $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . ' LIKE ' . $DB->quoteValue("%\"$val\"%") . $default_value_request; case 'notequals': - return $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . 'NOT LIKE ' . $DB->quoteValue("%\"$val\"%") . ' OR ' . $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . 'IS NULL '; + return $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . ' NOT LIKE ' . $DB->quoteValue("%\"$val\"%") . + ' OR ' . $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . ' IS NULL' . $default_value_request; } } }