diff --git a/htdocs/api/class/api_dictionary.class.php b/htdocs/api/class/api_dictionary.class.php
index b0d5bb00b0a..d551f3d866f 100644
--- a/htdocs/api/class/api_dictionary.class.php
+++ b/htdocs/api/class/api_dictionary.class.php
@@ -33,7 +33,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/ccountry.class.php';
class Dictionary extends DolibarrApi
{
private $translations = null;
-
+
/**
* Constructor
*/
@@ -52,11 +52,11 @@ class Dictionary extends DolibarrApi
* @param int $page Page number {@min 0}
* @param int $active Payment type is active or not {@min 0} {@max 1}
* @param string $sqlfilters SQL criteria to filter with. Syntax example "(t.code:=:'CHQ')"
- *
+ *
* @url GET payment/types
*
* @return array [List of payment types]
- *
+ *
* @throws 400 RestException
* @throws 200 OK
*/
@@ -104,7 +104,7 @@ class Dictionary extends DolibarrApi
return $list;
}
-
+
/**
* Get the list of countries.
*
@@ -121,9 +121,9 @@ class Dictionary extends DolibarrApi
* @param string $lang Code of the language the label of the countries must be translated to
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return List of countries
- *
+ *
* @url GET countries
- *
+ *
* @throws RestException
*/
function getListOfCountries($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $filter = '', $lang = '', $sqlfilters = '')
@@ -135,7 +135,7 @@ class Dictionary extends DolibarrApi
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_country as t";
$sql.=" WHERE 1 = 1";
// Add sql filters
- if ($sqlfilters)
+ if ($sqlfilters)
{
if (! DolibarrApi::_checkFilters($sqlfilters))
{
@@ -144,7 +144,7 @@ class Dictionary extends DolibarrApi
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
}
-
+
$sql.= $this->db->order($sortfield, $sortorder);
if ($limit) {
@@ -152,7 +152,7 @@ class Dictionary extends DolibarrApi
$page = 0;
}
$offset = $limit * $page;
-
+
$sql .= $this->db->plimit($limit, $offset);
}
@@ -177,7 +177,7 @@ class Dictionary extends DolibarrApi
} else {
throw new RestException(503, 'Error when retrieving list of countries : '.$country->error);
}
-
+
return $list;
}
@@ -187,9 +187,9 @@ class Dictionary extends DolibarrApi
* @param int $id ID of country
* @param string $lang Code of the language the name of the
* country must be translated to
- *
+ *
* @url GET countries/{id}
- *
+ *
* @throws RestException
*/
function getCountryByID($id, $lang = '')
@@ -217,16 +217,16 @@ class Dictionary extends DolibarrApi
function _cleanObjectDatas($object)
{
$object = parent::_cleanObjectDatas($object);
-
+
unset($object->error);
unset($object->errors);
-
+
return $object;
}
/**
* Translate the name of the country to the given language.
- *
+ *
* @param Ccountry $country Country
* @param string $lang Code of the language the name of the
* country must be translated to
@@ -249,8 +249,8 @@ class Dictionary extends DolibarrApi
}
}
}
- }
-
+ }
+
/**
* Get the list of events types.
*
@@ -262,7 +262,7 @@ class Dictionary extends DolibarrApi
* @param string $module To filter on module events
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return List of events types
- *
+ *
* @url GET events
*
* @throws RestException
@@ -312,9 +312,9 @@ class Dictionary extends DolibarrApi
}
return $list;
- }
-
-
+ }
+
+
/**
* Get the list of extra fields.
*
@@ -323,7 +323,7 @@ class Dictionary extends DolibarrApi
* @param string $type Type of element ('adherent', 'commande', 'thirdparty', 'facture', 'propal', 'product', ...)
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.label:like:'SO-%')"
* @return List of events types
- *
+ *
* @url GET extrafields
*
* @throws RestException
@@ -335,7 +335,7 @@ class Dictionary extends DolibarrApi
if ($type == 'thirdparty') $type='societe';
if ($type == 'contact') $type='socpeople';
- $sql = "SELECT t.rowid, t.name, t.label, t.type, t.size, t.elementtype, t.fieldunique, t.fieldrequired, t.param, t.pos, t.alwayseditable, t.perms, t.list, t.ishidden, t.fielddefault, t.fieldcomputed";
+ $sql = "SELECT t.rowid, t.name, t.label, t.type, t.size, t.elementtype, t.fieldunique, t.fieldrequired, t.param, t.pos, t.alwayseditable, t.perms, t.list, t.fielddefault, t.fieldcomputed";
$sql.= " FROM ".MAIN_DB_PREFIX."extrafields as t";
$sql.= " WHERE t.entity IN (".getEntity('extrafields').")";
if (! empty($type)) $sql.= " AND t.elementtype = '".$this->db->escape($type)."'";
@@ -373,7 +373,6 @@ class Dictionary extends DolibarrApi
$list[$tab->elementtype][$tab->name]['alwayseditable']=$tab->alwayseditable;
$list[$tab->elementtype][$tab->name]['perms']=$tab->perms;
$list[$tab->elementtype][$tab->name]['list']=$tab->list;
- $list[$tab->elementtype][$tab->name]['ishidden']=$tab->ishidden;
}
}
}
@@ -388,9 +387,9 @@ class Dictionary extends DolibarrApi
}
return $list;
- }
-
-
+ }
+
+
/**
* Get the list of towns.
*
@@ -402,9 +401,9 @@ class Dictionary extends DolibarrApi
* @param string $town To filter on city name
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return List of towns
- *
+ *
* @url GET towns
- *
+ *
* @throws RestException
*/
function getListOfTowns($sortfield = "zip,town", $sortorder = 'ASC', $limit = 100, $page = 0, $zipcode = '', $town = '', $sqlfilters = '')
@@ -426,8 +425,8 @@ class Dictionary extends DolibarrApi
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
}
-
-
+
+
$sql.= $this->db->order($sortfield, $sortorder);
if ($limit) {
@@ -435,10 +434,10 @@ class Dictionary extends DolibarrApi
$page = 0;
}
$offset = $limit * $page;
-
+
$sql .= $this->db->plimit($limit, $offset);
}
-
+
$result = $this->db->query($sql);
if ($result) {
@@ -450,9 +449,9 @@ class Dictionary extends DolibarrApi
} else {
throw new RestException(503, 'Error when retrieving list of towns : '.$this->db->lasterror());
}
-
+
return $list;
- }
+ }
/**
* Get the list of payments terms.
diff --git a/htdocs/core/actions_extrafields.inc.php b/htdocs/core/actions_extrafields.inc.php
index b6e70059da3..798a43b8d96 100644
--- a/htdocs/core/actions_extrafields.inc.php
+++ b/htdocs/core/actions_extrafields.inc.php
@@ -174,7 +174,7 @@ if ($action == 'add')
(GETPOST('alwayseditable', 'alpha')?1:0),
(GETPOST('perms', 'alpha')?GETPOST('perms', 'alpha'):''),
GETPOST('list', 'alpha'), // Same as visible -1=not visible by default in list, 1=visible, 0=not visible in list
- (GETPOST('ishidden', 'alpha')?1:0),
+ 0,
GETPOST('computed_value','alpha'),
(GETPOST('entitycurrentorall', 'alpha')?0:''),
GETPOST('langfile', 'alpha')
@@ -336,7 +336,7 @@ if ($action == 'update')
(GETPOST('alwayseditable', 'alpha')?1:0),
(GETPOST('perms', 'alpha')?GETPOST('perms', 'alpha'):''),
GETPOST('list', 'alpha'), // Same as visible -1=not visible by default in list, 1=visible, 0=not visible in list
- (GETPOST('ishidden', 'alpha')?1:0),
+ 0,
GETPOST('default_value','alpha'),
GETPOST('computed_value','alpha'),
(GETPOST('entitycurrentorall', 'alpha')?0:''),
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index a2c756c9d2a..fb42e1bfbde 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -4651,14 +4651,572 @@ abstract class CommonObject
else return 0;
}
+
+ /**
+ * Return HTML string to put an input field into a page
+ * Code very similar with showInputField of extra fields
+ *
+ * @param array $val Array of properties for field to show
+ * @param string $key Key of attribute
+ * @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value)
+ * @param string $moreparam To add more parametes on html input tag
+ * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names)
+ * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names)
+ * @param mixed $showsize Value for css to define size. May also be a numeric.
+ * @param int $objectid Current object id
+ * @return string
+ */
+ function showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0, $objectid=0)
+ {
+ global $conf,$langs;
+
+ $label=$val['label'];
+ $type =$val['type'];
+ $size =$val['css'];
+
+ // Convert var to be able to share same code than showInputField of extrafields
+ if (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar
+ if (is_array($val['arrayofkeyval'])) $type='select';
+ if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link';
+
+ //$elementtype=$this->attribute_elementtype[$key]; // seems to not be used
+ $default=$val['default'];
+ $computed=$val['computed'];
+ $unique=$val['unique'];
+ $required=$val['required'];
+ $param=$val['param'];
+ if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval'];
+ if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg))
+ {
+ $type='link';
+ $param['options']=array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]);
+ }
+ $langfile=$val['langfile'];
+ $list=$val['list'];
+ $hidden=(abs($val['visible'])!=1 ? 1 : 0);
+ $help=$val['help'];
+
+
+ if ($computed)
+ {
+ if (! preg_match('/^search_/', $keyprefix)) return ''.$langs->trans("AutomaticallyCalculated").'';
+ else return '';
+ }
+
+ if (empty($showsize))
+ {
+ if ($type == 'date')
+ {
+ //$showsize=10;
+ $showsize = 'minwidth100imp';
+ }
+ elseif ($type == 'datetime')
+ {
+ //$showsize=19;
+ $showsize = 'minwidth200imp';
+ }
+ elseif (in_array($type,array('int','double','price')))
+ {
+ //$showsize=10;
+ $showsize = 'maxwidth75';
+ }
+ elseif ($type == 'url')
+ {
+ $showsize='minwidth400';
+ }
+ elseif ($type == 'boolean')
+ {
+ $showsize='';
+ }
+ else
+ {
+ if (round($size) < 12)
+ {
+ $showsize = 'minwidth100';
+ }
+ else if (round($size) <= 48)
+ {
+ $showsize = 'minwidth200';
+ }
+ else
+ {
+ //$showsize=48;
+ $showsize = 'minwidth400';
+ }
+ }
+ }
+
+ if (in_array($type,array('date','datetime')))
+ {
+ $tmp=explode(',',$size);
+ $newsize=$tmp[0];
+
+ $showtime = in_array($type,array('datetime')) ? 1 : 0;
+
+ // Do not show current date when field not required (see select_date() method)
+ if (!$required && $value == '') $value = '-1';
+
+ require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
+ global $form;
+ if (! is_object($form)) $form=new Form($this->db);
+
+ // TODO Must also support $moreparam
+ $out = $form->select_date($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, ($keyprefix != 'search_' ? 1 : 0), 1, 0, 1);
+ }
+ elseif (in_array($type,array('int','integer')))
+ {
+ $tmp=explode(',',$size);
+ $newsize=$tmp[0];
+ $out='';
+ }
+ elseif (preg_match('/varchar/', $type))
+ {
+ $out='';
+ }
+ elseif (in_array($type, array('mail', 'phone', 'url')))
+ {
+ $out='';
+ }
+ elseif ($type == 'text')
+ {
+ require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
+ $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,! empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_5,'90%');
+ $out=$doleditor->Create(1);
+ }
+ elseif ($type == 'boolean')
+ {
+ $checked='';
+ if (!empty($value)) {
+ $checked=' checked value="1" ';
+ } else {
+ $checked=' value="1" ';
+ }
+ $out='';
+ }
+ elseif ($type == 'price')
+ {
+ if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
+ $value=price($value);
+ }
+ $out=' '.$langs->getCurrencySymbol($conf->currency);
+ }
+ elseif ($type == 'double')
+ {
+ if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
+ $value=price($value);
+ }
+ $out=' ';
+ }
+ elseif ($type == 'select')
+ {
+ $out = '';
+ if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2))
+ {
+ include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
+ $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
+ }
+
+ $out.='';
+ }
+ elseif ($type == 'sellist')
+ {
+ $out = '';
+ if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2))
+ {
+ include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
+ $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
+ }
+
+ $out.='';
+ }
+ elseif ($type == 'checkbox')
+ {
+ require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
+ $form = new Form($db);
+
+ $value_arr=explode(',',$value);
+ $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%');
+
+ }
+ elseif ($type == 'radio')
+ {
+ $out='';
+ foreach ($param['options'] as $keyopt => $val)
+ {
+ $out.=' ';
+ }
+ }
+ elseif ($type == 'chkbxlst')
+ {
+ if (is_array($value)) {
+ $value_arr = $value;
+ }
+ else {
+ $value_arr = explode(',', $value);
+ }
+
+ if (is_array($param['options'])) {
+ $param_list = array_keys($param['options']);
+ $InfoFieldList = explode(":", $param_list[0]);
+ // 0 : tableName
+ // 1 : label field name
+ // 2 : key fields name (if differ of rowid)
+ // 3 : key field parent (for dependent lists)
+ // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
+ $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid');
+
+ if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) {
+ list ( $parentName, $parentField ) = explode('|', $InfoFieldList[3]);
+ $keyList .= ', ' . $parentField;
+ }
+ if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) {
+ if (strpos($InfoFieldList[4], 'extra.') !== false) {
+ $keyList = 'main.' . $InfoFieldList[2] . ' as rowid';
+ } else {
+ $keyList = $InfoFieldList[2] . ' as rowid';
+ }
+ }
+
+ $fields_label = explode('|', $InfoFieldList[1]);
+ if (is_array($fields_label)) {
+ $keyList .= ', ';
+ $keyList .= implode(', ', $fields_label);
+ }
+
+ $sqlwhere = '';
+ $sql = 'SELECT ' . $keyList;
+ $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0];
+ if (! empty($InfoFieldList[4])) {
+
+ // can use SELECT request
+ if (strpos($InfoFieldList[4], '$SEL$')!==false) {
+ $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]);
+ }
+
+ // current object id can be use into filter
+ if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) {
+ $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]);
+ } else {
+ $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]);
+ }
+
+ // We have to join on extrafield table
+ if (strpos($InfoFieldList[4], 'extra') !== false) {
+ $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra';
+ $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4];
+ } else {
+ $sqlwhere .= ' WHERE ' . $InfoFieldList[4];
+ }
+ } else {
+ $sqlwhere .= ' WHERE 1=1';
+ }
+ // Some tables may have field, some other not. For the moment we disable it.
+ if (in_array($InfoFieldList[0], array ('tablewithentity')))
+ {
+ $sqlwhere .= ' AND entity = ' . $conf->entity;
+ }
+ // $sql.=preg_replace('/^ AND /','',$sqlwhere);
+ // print $sql;
+
+ $sql .= $sqlwhere;
+ dol_syslog(get_class($this) . '::showInputField type=chkbxlst',LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+
+ $data=array();
+
+ while ( $i < $num ) {
+ $labeltoshow = '';
+ $obj = $this->db->fetch_object($resql);
+
+ // Several field into label (eq table:code|libelle:rowid)
+ $fields_label = explode('|', $InfoFieldList[1]);
+ if (is_array($fields_label)) {
+ $notrans = true;
+ foreach ( $fields_label as $field_toshow ) {
+ $labeltoshow .= $obj->$field_toshow . ' ';
+ }
+ } else {
+ $labeltoshow = $obj->{$InfoFieldList[1]};
+ }
+ $labeltoshow = dol_trunc($labeltoshow, 45);
+
+ if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
+ foreach ( $fields_label as $field_toshow ) {
+ $translabel = $langs->trans($obj->$field_toshow);
+ if ($translabel != $obj->$field_toshow) {
+ $labeltoshow = dol_trunc($translabel, 18) . ' ';
+ } else {
+ $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' ';
+ }
+ }
+
+ $data[$obj->rowid]=$labeltoshow;
+
+ } else {
+ if (! $notrans) {
+ $translabel = $langs->trans($obj->{$InfoFieldList[1]});
+ if ($translabel != $obj->{$InfoFieldList[1]}) {
+ $labeltoshow = dol_trunc($translabel, 18);
+ } else {
+ $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
+ }
+ }
+ if (empty($labeltoshow))
+ $labeltoshow = '(not defined)';
+
+ if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
+ $data[$obj->rowid]=$labeltoshow;
+ }
+
+ if (! empty($InfoFieldList[3])) {
+ $parent = $parentName . ':' . $obj->{$parentField};
+ }
+
+ $data[$obj->rowid]=$labeltoshow;
+ }
+
+ $i ++;
+ }
+ $this->db->free($resql);
+
+ require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
+ $form = new Form($db);
+
+ $out=$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%');
+
+ } else {
+ print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters. ';
+ }
+ }
+ $out .= '';
+ }
+ elseif ($type == 'link')
+ {
+ $out='';
+
+ $param_list=array_keys($param['options']);
+ // 0 : ObjectName
+ // 1 : classPath
+ $InfoFieldList = explode(":", $param_list[0]);
+ dol_include_once($InfoFieldList[1]);
+ if ($InfoFieldList[0] && class_exists($InfoFieldList[0]))
+ {
+ $valuetoshow=$value;
+ if (!empty($value))
+ {
+ $object = new $InfoFieldList[0]($this->db);
+ $resfetch=$object->fetch($value);
+ if ($resfetch > 0)
+ {
+ $valuetoshow=$object->ref;
+ if ($object->element == 'societe') $valuetoshow=$object->name; // Special case for thirdparty because ->ref is not name but id (because name is not unique)
+ }
+ }
+ $out.='';
+ }
+ else
+ {
+ dol_syslog('Error bad setup of type for field '.$InfoFieldList, LOG_WARNING);
+ $out.='Error bad setup of type for field '.join(',', $InfoFieldList);
+ }
+ }
+ elseif ($type == 'password')
+ {
+ // If prefix is 'search_', field is used as a filter, we use a common text field.
+ $out='';
+ }
+ if (!empty($hidden)) {
+ $out='';
+ }
+ /* Add comments
+ if ($type == 'date') $out.=' (YYYY-MM-DD)';
+ elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)';
+ */
+ return $out;
+ }
+
+
+
/**
* Function to show lines of extrafields with output datas
*
* @param Extrafields $extrafields Extrafield Object
* @param string $mode Show output (view) or input (edit) for extrafield
* @param array $params Optional parameters
- * @param string $keysuffix Suffix 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)
+ * @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names)
+ * @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names)
*
* @return string
*/
@@ -4677,6 +5235,9 @@ abstract class CommonObject
$e = 0;
foreach($extrafields->attribute_label as $key=>$label)
{
+ if (empty($extrafields->attribute_list[$key])) continue; // 0 = Never visible field
+ if (($mode == 'create' || $mode == 'edit') && abs($extrafields->attribute_list[$key]) != 1) continue; // <> -1 and <> 1 = not visible on forms, only on list
+
// Load language if required
if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]);
diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php
index 7130287b6bd..012a3ce7acc 100644
--- a/htdocs/core/class/extrafields.class.php
+++ b/htdocs/core/class/extrafields.class.php
@@ -140,8 +140,8 @@ class ExtraFields
* @param array|string $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) )
* @param int $alwayseditable Is attribute always editable regardless of the document status
* @param string $perms Permission to check
- * @param int $list Into list view by default (-1, 0 or 1)
- * @param int $ishidden Is hidden extrafield (warning, do not rely on this. If your module need a hidden data, it must use its own table)
+ * @param int $list Visibilty
+ * @param int $ishidden Deprecated. Us visibility instead.
* @param string $computed Computed value
* @param string $entity Entity of extrafields
* @param string $langfile Language file
@@ -279,8 +279,8 @@ class ExtraFields
* @param array|string $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) )
* @param int $alwayseditable Is attribute always editable regardless of the document status
* @param string $perms Permission to check
- * @param int $list Into list view by default (-1, 0 or 1)
- * @param int $ishidden Is hidden extrafield (warning, do not rely on this. If your module need a hidden data, it must use its own table)
+ * @param int $list Visibily
+ * @param int $ishidden Deprecated. Use visibility instead.
* @param string $default Default value (in database. use the default_value feature for default value on screen).
* @param string $computed Computed value
* @param string $entity Entity of extrafields
@@ -328,7 +328,6 @@ class ExtraFields
$sql.= " perms,";
$sql.= " langs,";
$sql.= " list,";
- $sql.= " ishidden,";
$sql.= " fielddefault,";
$sql.= " fieldcomputed,";
$sql.= " fk_user_author,";
@@ -349,7 +348,6 @@ class ExtraFields
$sql.= " ".($perms?"'".$this->db->escape($perms)."'":"null").",";
$sql.= " ".($langfile?"'".$this->db->escape($langfile)."'":"null").",";
$sql.= " ".$list.",";
- $sql.= " ".$ishidden.",";
$sql.= " ".($default?"'".$this->db->escape($default)."'":"null").",";
$sql.= " ".($computed?"'".$this->db->escape($computed)."'":"null").",";
$sql .= " " . $user->id . ",";
@@ -483,8 +481,8 @@ class ExtraFields
* @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) )
* @param int $alwayseditable Is attribute always editable regardless of the document status
* @param string $perms Permission to check
- * @param int $list Into list view by default
- * @param int $ishidden Is hidden extrafield (warning, do not rely on this. If your module need a hidden data, it must use its own table)
+ * @param int $list Visibility
+ * @param int $ishidden Deprecated. Use visiblity instead.
* @param string $default Default value (in database. use the default_value feature for default value on screen).
* @param string $computed Computed value
* @param string $entity Entity of extrafields
@@ -589,8 +587,8 @@ class ExtraFields
* @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) )
* @param int $alwayseditable Is attribute always editable regardless of the document status
* @param string $perms Permission to check
- * @param int $list Into list view by default
- * @param int $ishidden Is hidden extrafield (warning, do not rely on this. If your module need a hidden data, it must use its own table)
+ * @param int $list Visiblity
+ * @param int $ishidden Deprecated. Use visility instead.
* @param string $default Default value (in database. use the default_value feature for default value on screen).
* @param string $computed Computed value
* @param string $entity Entity of extrafields
@@ -639,7 +637,6 @@ class ExtraFields
$sql.= " alwayseditable,";
$sql.= " param,";
$sql.= " list,";
- $sql.= " ishidden,";
$sql.= " fielddefault,";
$sql.= " fieldcomputed,";
$sql.= " fk_user_author,";
@@ -660,7 +657,6 @@ class ExtraFields
$sql.= " '".$alwayseditable."',";
$sql.= " '".$param."',";
$sql.= " ".$list.", ";
- $sql.= " ".$ishidden.", ";
$sql.= " ".(($default!='')?"'".$this->db->escape($default)."'":"null").",";
$sql.= " ".($computed?"'".$this->db->escape($computed)."'":"null").",";
$sql .= " " . $user->id . ",";
@@ -714,7 +710,7 @@ class ExtraFields
// We should not have several time this log. If we have, there is some optimization to do by calling a simple $object->fetch_optionals() that include cache management.
dol_syslog("fetch_name_optionals_label elementtype=".$elementtype);
- $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,ishidden,fielddefault,fieldcomputed";
+ $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,fielddefault,fieldcomputed";
$sql .= ",entity";
$sql.= " FROM ".MAIN_DB_PREFIX."extrafields";
$sql.= " WHERE entity IN (0,".$conf->entity.")";
@@ -749,7 +745,6 @@ class ExtraFields
$this->attribute_perms[$tab->name]=$tab->perms;
$this->attribute_langfile[$tab->name]=$tab->langs;
$this->attribute_list[$tab->name]=$tab->list;
- $this->attribute_hidden[$tab->name]=$tab->ishidden;
$this->attribute_entityid[$tab->name]=$tab->entity;
// New usage
@@ -767,7 +762,6 @@ class ExtraFields
$this->attributes[$tab->elementtype]['perms'][$tab->name]=$tab->perms;
$this->attributes[$tab->elementtype]['langfile'][$tab->name]=$tab->langs;
$this->attributes[$tab->elementtype]['list'][$tab->name]=$tab->list;
- $this->attributes[$tab->elementtype]['ishidden'][$tab->name]=$tab->ishidden;
$this->attributes[$tab->elementtype]['entityid'][$tab->name]=$tab->entity;
if (!empty($conf->multicompany->enabled))
@@ -802,12 +796,13 @@ class ExtraFields
/**
* Return HTML string to put an input field into a page
+ * Code very similar with showInputField of common object
*
* @param string $key Key of attribute
* @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value)
* @param string $moreparam To add more parametes on html input tag
- * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names)
- * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names)
+ * @param string $keysuffix Prefix string to add after name and id of field (can be used to avoid duplicate names)
+ * @param string $keyprefix Suffix string to add before name and id of field (can be used to avoid duplicate names)
* @param mixed $showsize Value for css to define size. May also be a numeric.
* @param int $objectid Current object id
* @return string
@@ -816,10 +811,12 @@ class ExtraFields
{
global $conf,$langs;
+ $keyprefix = $keyprefix.'options_'; // Because we work on extrafields
+
$label=$this->attribute_label[$key];
$type =$this->attribute_type[$key];
$size =$this->attribute_size[$key];
- $elementtype=$this->attribute_elementtype[$key];
+ $elementtype=$this->attribute_elementtype[$key]; // Seems not used
$default=$this->attribute_default[$key];
$computed=$this->attribute_computed[$key];
$unique=$this->attribute_unique[$key];
@@ -831,7 +828,7 @@ class ExtraFields
if ($computed)
{
- if ($keyprefix != 'search_') return ''.$langs->trans("AutomaticallyCalculated").'';
+ if (! preg_match('/^search_/', $keyprefix)) return ''.$langs->trans("AutomaticallyCalculated").'';
else return '';
}
@@ -847,7 +844,7 @@ class ExtraFields
//$showsize=19;
$showsize = 'minwidth200imp';
}
- elseif (in_array($type,array('int','double','price')))
+ elseif (in_array($type,array('int','integer','double','price')))
{
//$showsize=10;
$showsize = 'maxwidth75';
@@ -893,26 +890,26 @@ class ExtraFields
if (! is_object($form)) $form=new Form($this->db);
// TODO Must also support $moreparam
- $out = $form->select_date($value, $keyprefix.'options_'.$key.$keysuffix, $showtime, $showtime, $required, '', 1, ($keyprefix != 'search_' ? 1 : 0), 1, 0, 1);
+ $out = $form->select_date($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, ($keyprefix != 'search_' ? 1 : 0), 1, 0, 1);
}
- elseif (in_array($type,array('int')))
+ elseif (in_array($type,array('int','integer')))
{
$tmp=explode(',',$size);
$newsize=$tmp[0];
- $out='';
+ $out='';
}
- elseif ($type == 'varchar')
+ elseif (preg_match('/varchar/', $type))
{
- $out='';
+ $out='';
}
elseif (in_array($type, array('mail', 'phone', 'url')))
{
- $out='';
+ $out='';
}
elseif ($type == 'text')
{
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
- $doleditor=new DolEditor($keyprefix.'options_'.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,! empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_5,'90%');
+ $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,! empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_5,'90%');
$out=$doleditor->Create(1);
}
elseif ($type == 'boolean')
@@ -923,21 +920,21 @@ class ExtraFields
} else {
$checked=' value="1" ';
}
- $out='';
+ $out='';
}
elseif ($type == 'price')
{
if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
$value=price($value);
}
- $out=' '.$langs->getCurrencySymbol($conf->currency);
+ $out=' '.$langs->getCurrencySymbol($conf->currency);
}
elseif ($type == 'double')
{
if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
$value=price($value);
}
- $out=' ';
+ $out=' ';
}
elseif ($type == 'select')
{
@@ -945,10 +942,10 @@ class ExtraFields
if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2))
{
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
- $out.= ajax_combobox($keyprefix.'options_'.$key.$keysuffix, array(), 0);
+ $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
}
- $out.='