Fix extrafields
This commit is contained in:
parent
c5231112c5
commit
9a0b5fb599
@ -1941,24 +1941,36 @@ class ExtraFields
|
||||
/**
|
||||
* return array_options array of data of extrafields value of object sent by a search form
|
||||
*
|
||||
* @param array $extralabels $array of extrafields (@deprecated)
|
||||
* @param string $keyprefix Prefix string to add into name and id of field (can be used to avoid duplicate names)
|
||||
* @param string $keysuffix Suffix string to add into name and id of field (can be used to avoid duplicate names)
|
||||
* @return array|int array_options set or 0 if no value
|
||||
* @param array|string $extrafieldsobjectkey array of extrafields (old usage) or value of object->table_element (new usage)
|
||||
* @param string $keyprefix Prefix string to add into name and id of field (can be used to avoid duplicate names)
|
||||
* @param string $keysuffix Suffix string to add into name and id of field (can be used to avoid duplicate names)
|
||||
* @return array|int array_options set or 0 if no value
|
||||
*/
|
||||
function getOptionalsFromPost($extralabels,$keyprefix='',$keysuffix='')
|
||||
function getOptionalsFromPost($extrafieldsobjectkey, $keyprefix='', $keysuffix='')
|
||||
{
|
||||
global $_POST;
|
||||
|
||||
if (is_array($this->attributes[$object->table_element]['label'])) $extralabels=$this->attributes[$object->table_element]['label'];
|
||||
if (is_string($extrafieldsobjectkey) && is_array($this->attributes[$extrafieldsobjectkey]['label']))
|
||||
{
|
||||
$extralabels = $this->attributes[$extrafieldsobjectkey]['label'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$extralabels = $extrafieldsobjectkey;
|
||||
}
|
||||
|
||||
$array_options = array();
|
||||
if (is_array($extralabels))
|
||||
{
|
||||
$array_options = array();
|
||||
|
||||
// Get extra fields
|
||||
foreach ($extralabels as $key => $value)
|
||||
{
|
||||
$key_type = $this->attributes[$object->table_element]['type'][$key];
|
||||
$key_type = '';
|
||||
if (is_string($extrafieldsobjectkey))
|
||||
{
|
||||
$key_type = $this->attributes[$extrafieldsobjectkey]['type'][$key];
|
||||
}
|
||||
|
||||
if (in_array($key_type,array('date','datetime')))
|
||||
{
|
||||
@ -1987,8 +1999,7 @@ class ExtraFields
|
||||
|
||||
return $array_options;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -7288,7 +7288,8 @@ function dol_getmypid()
|
||||
* If param $mode is 1, can contains an operator <, > or = like "<10" or ">=100.5 < 1000"
|
||||
* If param $mode is 2, can contains a list of int id separated by comma like "1,3,4"
|
||||
* If param $mode is 3, can contains a list of string separated by comma like "a,b,c"
|
||||
* @param integer $mode 0=value is list of keyword strings, 1=value is a numeric test (Example ">5.5 <10"), 2=value is a list of id separated with comma (Example '1,3,4')
|
||||
* @param integer $mode 0=value is list of keyword strings, 1=value is a numeric test (Example ">5.5 <10"), 2=value is a list of ID separated with comma (Example '1,3,4')
|
||||
* 3=value is list of string separated with comma (Example 'text 1,text 2'), 4=value is a list of ID separated with comma (Example '1,3,4') for search into a multiselect string ('1,2')
|
||||
* @param integer $nofirstand 1=Do not output the first 'AND'
|
||||
* @return string $res The statement to append to the SQL query
|
||||
*/
|
||||
@ -7372,11 +7373,9 @@ function natural_search($fields, $value, $mode=0, $nofirstand=0)
|
||||
else if ($mode == 4)
|
||||
{
|
||||
$tmparray=explode(',',trim($crit));
|
||||
|
||||
if (count($tmparray))
|
||||
{
|
||||
$listofcodes='';
|
||||
|
||||
foreach($tmparray as $val)
|
||||
{
|
||||
if ($val)
|
||||
@ -7385,7 +7384,7 @@ function natural_search($fields, $value, $mode=0, $nofirstand=0)
|
||||
$newres .= ' OR '. $field . ' = \'' . $db->escape(trim($val)) . '\'';
|
||||
$newres .= ' OR '. $field . ' LIKE \'%,' . $db->escape(trim($val)) . '\'';
|
||||
$newres .= ' OR '. $field . ' LIKE \'%,' . $db->escape(trim($val)) . ',%\'';
|
||||
$newres .= ')';
|
||||
$newres .= ')';
|
||||
$i2++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,12 +18,17 @@ if (! empty($extrafieldsobjectkey)) // $extrafieldsobject is the $object->table_
|
||||
$tmpkey=preg_replace('/search_options_/','',$key);
|
||||
$typ=$extrafields->attributes[$extrafieldsobjectkey]['type'][$tmpkey];
|
||||
|
||||
$mode_search=0;
|
||||
if (in_array($typ, array('int','double','real'))) $mode_search=1; // Search on a numeric
|
||||
if (in_array($typ, array('sellist','link')) && $crit != '0' && $crit != '-1') $mode_search=2; // Search on a foreign key int
|
||||
if (in_array($typ, array('chkbxlst','checkbox'))) $mode_search=4; // Search on a multiselect field with sql type = text
|
||||
if ($crit != '' && (! in_array($typ, array('select','sellist')) || $crit != '0') && (! in_array($typ, array('link')) || $crit != '-1'))
|
||||
if ($crit != '' && in_array($typ, array('date', 'datetime', 'timestamp')))
|
||||
{
|
||||
$sql .= " AND ef.".$tmpkey." = '".$db->idate($crit)."'";
|
||||
}
|
||||
elseif ($crit != '' && (! in_array($typ, array('select','sellist')) || $crit != '0') && (! in_array($typ, array('link')) || $crit != '-1'))
|
||||
{
|
||||
$mode_search=0;
|
||||
if (in_array($typ, array('int','double','real'))) $mode_search=1; // Search on a numeric
|
||||
if (in_array($typ, array('sellist','link')) && $crit != '0' && $crit != '-1') $mode_search=2; // Search on a foreign key int
|
||||
if (in_array($typ, array('chkbxlst','checkbox'))) $mode_search=4; // Search on a multiselect field with sql type = text
|
||||
|
||||
$sql .= natural_search('ef.'.$tmpkey, $crit, $mode_search);
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,8 +93,8 @@ $extrafields = new ExtraFields($db);
|
||||
$diroutputmassaction=$conf->mymodule->dir_output . '/temp/massgeneration/'.$user->id;
|
||||
$hookmanager->initHooks(array('myobjectlist')); // Note that conf->hooks_modules contains array
|
||||
// Fetch optionals attributes and labels
|
||||
$extralabels = $extrafields->fetch_name_optionals_label('myobject');
|
||||
$search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
|
||||
$extralabels = $extrafields->fetch_name_optionals_label('myobject'); // Load $extrafields->attributes['myobject']
|
||||
$search_array_options=$extrafields->getOptionalsFromPost($object->table_element,'','search_');
|
||||
|
||||
// Default sort order (if not yet defined by previous GETPOST)
|
||||
if (! $sortfield) $sortfield="t.".key($object->fields); // Set here default search field. By default 1st field in definition.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user