Fix filtering

This commit is contained in:
Laurent Destailleur 2015-08-24 16:32:43 +02:00
parent 8061ec9084
commit 2cf10ac05d
2 changed files with 29 additions and 12 deletions

View File

@ -160,6 +160,7 @@ $extrafields = new ExtraFields($db);
// fetch optionals attributes and labels // fetch optionals attributes and labels
$extralabels = $extrafields->fetch_name_optionals_label('thirdparty'); $extralabels = $extrafields->fetch_name_optionals_label('thirdparty');
$search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
// Do we click on purge search criteria ? // Do we click on purge search criteria ?
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
@ -174,6 +175,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both
$search_datec=""; $search_datec="";
$search_categ=""; $search_categ="";
$search_status=""; $search_status="";
$search_array_options=array();
} }
if ($search_status=='') $search_status=1; // always display active customer first if ($search_status=='') $search_status=1; // always display active customer first
@ -256,6 +258,18 @@ if ($socname)
$sortfield = "s.nom"; $sortfield = "s.nom";
$sortorder = "ASC"; $sortorder = "ASC";
} }
// Extra fields
if (is_array($extrafields->attribute_list) && count($extrafields->attribute_list))
{
foreach($extrafields->attribute_list as $key => $val)
{
$crit=GETPOST('search_options_'.$key);
if ($val && $crit != '')
{
$sql .= natural_search('ef.'.$key, $crit);
}
}
}
// Add where from hooks // Add where from hooks
$parameters=array(); $parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
@ -269,6 +283,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
} }
$sql.= " ORDER BY $sortfield $sortorder, s.nom ASC"; $sql.= " ORDER BY $sortfield $sortorder, s.nom ASC";
$sql.= $db->plimit($conf->liste_limit+1, $offset); $sql.= $db->plimit($conf->liste_limit+1, $offset);
//print $sql;
dol_syslog('comm/prospect/list.php', LOG_DEBUG); dol_syslog('comm/prospect/list.php', LOG_DEBUG);
$resql = $db->query($sql); $resql = $db->query($sql);
@ -434,9 +449,10 @@ if ($resql)
{ {
if ($val) if ($val)
{ {
print '<td class="liste_titre">'; $crit=$search_array_options['search_options_'.$key];
//print $extrafields->showInputField($key, $array_options[$key], '', '', 'search_', 4); print '<td class="liste_titre">';
print '</td>'; print $extrafields->showInputField($key, $crit, '', '', 'search_', 4);
print '</td>';
} }
} }
} }

View File

@ -1425,11 +1425,12 @@ class ExtraFields
/** /**
* return array_options array for object by extrafields value (using for data send by forms) * return array_options array for object by extrafields value (using for data send by forms)
* *
* @param array $extralabels $array of extrafields * @param array $extralabels $array of extrafields
* @param string $keyprefix Prefix string to add into name and id of field (can be used to avoid duplicate names) * @param string $keyprefix Prefix string to add into name and id of field (can be used to avoid duplicate names)
* @return int 1 if array_options set / 0 if no value * @param string $keysuffix Suffix string to add into name and id of field (can be used to avoid duplicate names)
* @return int 1 if array_options set / 0 if no value
*/ */
function getOptionalsFromPost($extralabels,$keyprefix='') function getOptionalsFromPost($extralabels,$keyprefix='',$keysuffix='')
{ {
global $_POST; global $_POST;
@ -1444,24 +1445,24 @@ class ExtraFields
if (in_array($key_type,array('date','datetime'))) if (in_array($key_type,array('date','datetime')))
{ {
// Clean parameters // Clean parameters
$value_key=dol_mktime($_POST["options_".$key.$keyprefix."hour"], $_POST["options_".$key.$keyprefix."min"], 0, $_POST["options_".$key.$keyprefix."month"], $_POST["options_".$key.$keyprefix."day"], $_POST["options_".$key.$keyprefix."year"]); $value_key=dol_mktime($_POST[$keysuffix."options_".$key.$keyprefix."hour"], $_POST[$keysuffix."options_".$key.$keyprefix."min"], 0, $_POST[$keysuffix."options_".$key.$keyprefix."month"], $_POST[$keysuffix."options_".$key.$keyprefix."day"], $_POST[$keysuffix."options_".$key.$keyprefix."year"]);
} }
else if (in_array($key_type,array('checkbox'))) else if (in_array($key_type,array('checkbox')))
{ {
$value_arr=GETPOST("options_".$key.$keyprefix); $value_arr=GETPOST($keysuffix."options_".$key.$keyprefix);
$value_key=implode($value_arr,','); $value_key=implode($value_arr,',');
} }
else if (in_array($key_type,array('price','double'))) else if (in_array($key_type,array('price','double')))
{ {
$value_arr=GETPOST("options_".$key.$keyprefix); $value_arr=GETPOST($keysuffix."options_".$key.$keyprefix);
$value_key=price2num($value_arr); $value_key=price2num($value_arr);
} }
else else
{ {
$value_key=GETPOST("options_".$key.$keyprefix); $value_key=GETPOST($keysuffix."options_".$key.$keyprefix);
} }
$array_options["options_".$key]=$value_key; // No keyprefix here. keyprefix is used only for read. $array_options[$keysuffix."options_".$key]=$value_key; // No keyprefix here. keyprefix is used only for read.
} }
return $array_options; return $array_options;