2
0
forked from Wavyzz/dolibarr

Merge branch '14.0_fix_regression_selct_extrafield_search' of github.com:atm-john/dolibarr into new_fix_regression_select_extrafield_search

This commit is contained in:
ATM john
2022-03-30 11:09:29 +02:00
3 changed files with 61 additions and 29 deletions

View File

@@ -139,7 +139,6 @@ $search_btn = GETPOST('button_search', 'alpha');
$search_remove_btn = GETPOST('button_removefilter', 'alpha');
$optioncss = GETPOST('optioncss', 'alpha');
$option = GETPOST('search_option');
if ($option == 'late') {
$search_status = '1';

View File

@@ -1065,35 +1065,56 @@ class ExtraFields
$out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'> ';
} elseif ($type == 'select') {
$out = '';
if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2)) {
include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
$out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
}
if ($mode) {
$options = array();
foreach ($param['options'] as $okey => $val) {
if ((string) $okey == '') {
continue;
}
$out .= '<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : '').'>';
$out .= '<option value="0">&nbsp;</option>';
foreach ($param['options'] as $key => $val) {
if ((string) $key == '') {
continue;
if ($langfile && $val) {
$options[$okey] = $langs->trans($val);
} else {
$options[$okey] = $val;
}
}
$valarray = explode('|', $val);
$val = $valarray[0];
$parent = '';
if (!empty($valarray[1])) {
$parent = $valarray[1];
$selected = array();
if (!is_array($value)) {
$selected = explode(',', $value);
}
$out .= '<option value="'.$key.'"';
$out .= (((string) $value == (string) $key) ? ' selected' : '');
$out .= (!empty($parent) ? ' parent="'.$parent.'"' : '');
$out .= '>';
if ($langfile && $val) {
$out .= $langs->trans($val);
} else {
$out .= $val;
$out .= $form->multiselectarray($keyprefix.$key.$keysuffix, $options, $selected, 0, 0, $morecss, 0, 0, '', '', '', !empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2));
} else {
if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2)) {
include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
$out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
}
$out .= '</option>';
$out .= '<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : '').'>';
$out .= '<option value="0">&nbsp;</option>';
foreach ($param['options'] as $key => $val) {
if ((string) $key == '') {
continue;
}
$valarray = explode('|', $val);
$val = $valarray[0];
$parent = '';
if (!empty($valarray[1])) {
$parent = $valarray[1];
}
$out .= '<option value="'.$key.'"';
$out .= (((string) $value == (string) $key) ? ' selected' : '');
$out .= (!empty($parent) ? ' parent="'.$parent.'"' : '');
$out .= '>';
if ($langfile && $val) {
$out .= $langs->trans($val);
} else {
$out .= $val;
}
$out .= '</option>';
}
$out .= '</select>';
}
$out .= '</select>';
} elseif ($type == 'sellist') {
$out = '';
if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2)) {
@@ -2108,6 +2129,17 @@ class ExtraFields
} else {
continue; // Value was not provided, we should not set it.
}
} elseif ($key_type == 'select') {
// to detect if we are in search context
$value_arr_test = GETPOST($keysuffix."options_".$key.$keyprefix, 'none');
if (is_array($value_arr_test)) {
$value_arr = GETPOST($keysuffix."options_".$key.$keyprefix, 'array:aZ09');
// Make sure we get an array even if there's only one selected
$value_arr = (array) $value_arr;
$value_key = implode(',', $value_arr);
} else {
$value_key = GETPOST($keysuffix."options_".$key.$keyprefix);
}
} elseif (in_array($key_type, array('checkbox', 'chkbxlst'))) {
if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) {
continue; // Value was not provided, we should not set it.

View File

@@ -48,7 +48,7 @@ if (!empty($extrafieldsobjectkey) && !empty($search_array_options) && is_array($
}
$sql .= ")";
}
} elseif ($crit != '' && (!in_array($typ, array('select', 'sellist')) || $crit != '0') && (!in_array($typ, array('link')) || $crit != '-1')) {
} elseif ($crit != '' && (!in_array($typ, array('select', 'sellist', 'select')) || $crit != '0') && (!in_array($typ, array('link')) || $crit != '-1')) {
$mode_search = 0;
if (in_array($typ, array('int', 'double', 'real', 'price'))) {
$mode_search = 1; // Search on a numeric
@@ -59,13 +59,14 @@ if (!empty($extrafieldsobjectkey) && !empty($search_array_options) && is_array($
if (in_array($typ, array('sellist')) && !is_numeric($crit)) {
$mode_search = 0;// Search on a foreign key string
}
if (in_array($typ, array('chkbxlst', 'checkbox'))) {
if (in_array($typ, array('chkbxlst', 'checkbox', 'select'))) {
$mode_search = 4; // Search on a multiselect field with sql type = text
}
if (is_array($crit)) {
$crit = implode(' ', $crit); // natural_search() expects a string
} elseif ($typ === 'select' and is_string($crit) and strpos($crit, ' ') === false) {
$sql .= " AND (".$extrafieldsobjectprefix.$tmpkey." = '".$db->escape($crit)."')";
} elseif ($typ === 'select' and is_string($crit) and strpos($crit, ',') === false) {
$critSelect = implode("','", array_map(array($db, 'escape'), explode(',', $crit)));
$sql .= " AND (".$extrafieldsobjectprefix.$tmpkey." IN ('".$critSelect."') )";
continue;
}
$sql .= natural_search($extrafieldsobjectprefix.$tmpkey, $crit, $mode_search);