NEW Support visibility on extrafields

This commit is contained in:
Laurent Destailleur 2017-10-25 11:42:14 +02:00
parent f381361c8b
commit bb996019c2
13 changed files with 665 additions and 136 deletions

View File

@ -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.

View File

@ -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:''),

View File

@ -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 '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
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='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.$value.'"'.($moreparam?$moreparam:'').'>';
}
elseif (preg_match('/varchar/', $type))
{
$out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>';
}
elseif (in_array($type, array('mail', 'phone', 'url')))
{
$out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>';
}
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='<input type="checkbox" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>';
}
elseif ($type == 'price')
{
if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
$value=price($value);
}
$out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '.$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='<input type="text" class="flat '.$showsize.' 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_USE_SELECT2))
{
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
$out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
}
$out.='<select class="flat '.$showsize.' 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;
list($val, $parent) = explode('|', $val);
$out.='<option value="'.$key.'"';
$out.= (((string) $value == (string) $key)?' selected':'');
$out.= (!empty($parent)?' parent="'.$parent.'"':'');
$out.='>'.$val.'</option>';
}
$out.='</select>';
}
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.='<select class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>';
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) > 4 && ! empty($InfoFieldList[4]))
{
if (strpos($InfoFieldList[4], 'extra.') !== false)
{
$keyList='main.'.$InfoFieldList[2].' as rowid';
} else {
$keyList=$InfoFieldList[2].' as rowid';
}
}
if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3]))
{
list($parentName, $parentField) = explode('|', $InfoFieldList[3]);
$keyList.= ', '.$parentField;
}
$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.=$sqlwhere;
//print $sql;
$sql .= ' ORDER BY ' . implode(', ', $fields_label);
dol_syslog(get_class($this).'::showInputField type=sellist', LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$out.='<option value="0">&nbsp;</option>';
$num = $this->db->num_rows($resql);
$i = 0;
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 ($value==$obj->rowid)
{
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).' ';
}
}
$out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
}
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 ($value==$obj->rowid)
{
$out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
}
if (!empty($InfoFieldList[3]))
{
$parent = $parentName.':'.$obj->{$parentField};
}
$out.='<option value="'.$obj->rowid.'"';
$out.= ($value==$obj->rowid?' selected':'');
$out.= (!empty($parent)?' parent="'.$parent.'"':'');
$out.='>'.$labeltoshow.'</option>';
}
$i++;
}
$this->db->free($resql);
}
else {
print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>';
}
}
$out.='</select>';
}
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.='<input class="flat '.$showsize.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'');
$out.=' value="'.$keyopt.'"';
$out.=' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"';
$out.= ($value==$keyopt?'checked':'');
$out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>';
}
}
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.<br>';
}
}
$out .= '</select>';
}
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.='<input type="text" class="flat '.$showsize.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$valuetoshow.'" >';
}
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='<input type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$showsize.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>';
}
if (!empty($hidden)) {
$out='<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>';
}
/* 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]);

View File

@ -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 '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
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='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.'options_'.$key.$keysuffix.'" id="'.$keyprefix.'options_'.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.$value.'"'.($moreparam?$moreparam:'').'>';
$out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.$value.'"'.($moreparam?$moreparam:'').'>';
}
elseif ($type == 'varchar')
elseif (preg_match('/varchar/', $type))
{
$out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.'options_'.$key.$keysuffix.'" id="'.$keyprefix.'options_'.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>';
$out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>';
}
elseif (in_array($type, array('mail', 'phone', 'url')))
{
$out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.'options_'.$key.$keysuffix.'" id="'.$keyprefix.'options_'.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>';
$out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>';
}
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='<input type="checkbox" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.'options_'.$key.$keysuffix.'" id="'.$keyprefix.'options_'.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>';
$out='<input type="checkbox" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>';
}
elseif ($type == 'price')
{
if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
$value=price($value);
}
$out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.'options_'.$key.$keysuffix.'" id="'.$keyprefix.'options_'.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency);
$out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '.$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='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.'options_'.$key.$keysuffix.'" id="'.$keyprefix.'options_'.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> ';
$out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> ';
}
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.='<select class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.'options_'.$key.$keysuffix.'" id="'.$keyprefix.'options_'.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>';
$out.='<select class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>';
$out.='<option value="0">&nbsp;</option>';
foreach ($param['options'] as $key => $val)
{
@ -967,10 +964,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.='<select class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.'options_'.$key.$keysuffix.'" id="'.$keyprefix.'options_'.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>';
$out.='<select class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>';
if (is_array($param['options']))
{
$param_list=array_keys($param['options']);
@ -1132,7 +1129,7 @@ class ExtraFields
$form = new Form($db);
$value_arr=explode(',',$value);
$out=$form->multiselectarray($keyprefix.'options_'.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%');
$out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%');
}
elseif ($type == 'radio')
@ -1140,11 +1137,11 @@ class ExtraFields
$out='';
foreach ($param['options'] as $keyopt => $val)
{
$out.='<input class="flat '.$showsize.'" type="radio" name="'.$keyprefix.'options_'.$key.$keysuffix.'" id="'.$keyprefix.'options_'.$key.$keysuffix.'" '.($moreparam?$moreparam:'');
$out.='<input class="flat '.$showsize.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'');
$out.=' value="'.$keyopt.'"';
$out.=' id="'.$keyprefix.'options_'.$key.$keysuffix.'_'.$keyopt.'"';
$out.=' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"';
$out.= ($value==$keyopt?'checked':'');
$out.='/><label for="'.$keyprefix.'options_'.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>';
$out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>';
}
}
elseif ($type == 'chkbxlst')
@ -1286,7 +1283,7 @@ class ExtraFields
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
$form = new Form($db);
$out=$form->multiselectarray($keyprefix.'options_'.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%');
$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.<br>';
@ -1316,7 +1313,7 @@ class ExtraFields
if ($object->element == 'societe') $valuetoshow=$object->name; // Special case for thirdparty because ->ref is not name but id (because name is not unique)
}
}
$out.='<input type="text" class="flat '.$showsize.'" name="'.$keyprefix.'options_'.$key.$keysuffix.'" id="'.$keyprefix.'options_'.$key.$keysuffix.'" value="'.$valuetoshow.'" >';
$out.='<input type="text" class="flat '.$showsize.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$valuetoshow.'" >';
}
else
{
@ -1327,10 +1324,10 @@ class ExtraFields
elseif ($type == 'password')
{
// If prefix is 'search_', field is used as a filter, we use a common text field.
$out='<input type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$showsize.'" name="'.$keyprefix.'options_'.$key.$keysuffix.'" id="'.$keyprefix.'options_'.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>';
$out='<input type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$showsize.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>';
}
if (!empty($hidden)) {
$out='<input type="hidden" value="'.$value.'" name="'.$keyprefix.'options_'.$key.$keysuffix.'" id="'.$keyprefix.'options_'.$key.$keysuffix.'"/>';
$out='<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>';
}
/* Add comments
if ($type == 'date') $out.=' (YYYY-MM-DD)';
@ -1352,7 +1349,7 @@ class ExtraFields
{
global $conf,$langs;
$elementtype=$this->attribute_elementtype[$key];
$elementtype=$this->attribute_elementtype[$key]; // seems not used
$label=$this->attribute_label[$key];
$type=$this->attribute_type[$key];
$size=$this->attribute_size[$key];

View File

@ -67,15 +67,15 @@ $langs->load("modulebuilder");
{
console.log("We enter a computed formula");
jQuery("#default_value").val('');
/* jQuery("#unique, #required, #alwayseditable, #ishidden, #list").removeAttr('checked'); */
jQuery("#default_value, #unique, #required, #alwayseditable, #ishidden, #list").attr('disabled', true);
jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_ishidden, tr.extra_list").hide();
/* jQuery("#unique, #required, #alwayseditable, #list").removeAttr('checked'); */
jQuery("#default_value, #unique, #required, #alwayseditable, #list").attr('disabled', true);
jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_list").hide();
}
else
{
console.log("No computed formula");
jQuery("#default_value, #unique, #required, #alwayseditable, #ishidden, #list").attr('disabled', false);
jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_ishidden, tr.extra_list").show();
jQuery("#default_value, #unique, #required, #alwayseditable, #list").attr('disabled', false);
jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_list").show();
}
if (type == 'date') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
@ -173,15 +173,11 @@ $langs->load("modulebuilder");
<tr class="extra_required"><td><?php echo $langs->trans("Required"); ?></td><td class="valeur"><input id="required" type="checkbox" name="required"<?php echo (GETPOST('required','alpha')?' checked':''); ?>></td></tr>
<!-- Always editable -->
<tr class="extra_alwayseditable"><td><?php echo $langs->trans("AlwaysEditable"); ?></td><td class="valeur"><input id="alwayseditable" type="checkbox" name="alwayseditable"<?php echo ((GETPOST('alwayseditable','alpha') || ! GETPOST('button','alpha'))?' checked':''); ?>></td></tr>
<!-- Is visible or not -->
<?php if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) { ?>
<tr class="extra_ishidden"><td><?php echo $langs->trans("Hidden"); ?></td><td class="valeur"><input id="ishidden" type="checkbox" name="ishidden"<?php echo (GETPOST('ishidden','alpha') ?' checked' : ''); ?>></td></tr>
<?php } ?>
<?php if ($conf->multicompany->enabled) { ?>
<tr><td><?php echo $langs->trans("AllEntities"); ?></td><td class="valeur"><input id="entitycurrentorall" type="checkbox" name="entitycurrentorall"<?php echo (GETPOST('entitycurrentorall','alpha') ? '':' checked'); ?>></td></tr>
<?php } ?>
<!-- By default visible into list -->
<tr><td class="extra_list"><?php echo $form->textwithpicto($langs->trans("ByDefaultInList"), $langs->trans("VisibleDesc")); ?>
<!-- Visibility -->
<tr><td class="extra_list"><?php echo $form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc")); ?>
</td><td class="valeur"><input id="list" size="1" type="text" name="list" value="<?php echo GETPOST('list','int')!='' ? GETPOST('list','int') : '1'; ?>"></td></tr>
</table>

View File

@ -65,15 +65,15 @@ $langs->load("modulebuilder");
{
console.log("We enter a computed formula");
jQuery("#default_value").val('');
/* jQuery("#unique, #required, #alwayseditable, #ishidden, #list").removeAttr('checked'); */
jQuery("#default_value, #unique, #required, #alwayseditable, #ishidden, #list").attr('disabled', true);
jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_ishidden, tr.extra_list").hide();
/* jQuery("#unique, #required, #alwayseditable, #list").removeAttr('checked'); */
jQuery("#default_value, #unique, #required, #alwayseditable, #list").attr('disabled', true);
jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_list").hide();
}
else
{
console.log("No computed formula");
jQuery("#default_value, #unique, #required, #alwayseditable, #ishidden, #list").attr('disabled', false);
jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_ishidden, tr.extra_list").show();
jQuery("#default_value, #unique, #required, #alwayseditable, #list").attr('disabled', false);
jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_list").show();
}
if (type == 'date') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
@ -143,7 +143,6 @@ $param=$extrafields->attributes[$elementtype]['param'][$attrname];
$perms=$extrafields->attributes[$elementtype]['perms'][$attrname];
$langfile=$extrafields->attributes[$elementtype]['langfile'][$attrname];
$list=$extrafields->attributes[$elementtype]['list'][$attrname];
$ishidden=$extrafields->attributes[$elementtype]['hidden'][$attrname];
$entitycurrentorall=$extrafields->attributes[$elementtype]['entityid'][$attrname];
if((($type == 'select') || ($type == 'checkbox') || ($type == 'radio')) && is_array($param))
@ -232,15 +231,11 @@ else
<tr class="extra_required"><td><?php echo $langs->trans("Required"); ?></td><td class="valeur"><input id="required" type="checkbox" name="required"<?php echo ($required?' checked':''); ?>></td></tr>
<!-- Always editable -->
<tr class="extra_alwayseditable"><td><?php echo $langs->trans("AlwaysEditable"); ?></td><td class="valeur"><input id="alwayseditable" type="checkbox" name="alwayseditable"<?php echo ($alwayseditable?' checked':''); ?>></td></tr>
<!-- Is visible or not -->
<?php if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) { ?>
<tr><td><?php echo $langs->trans("Hidden"); ?></td><td class="valeur"><input id="ishidden" type="checkbox" name="ishidden"<?php echo ($ishidden ?' checked':''); ?>></td></tr>
<?php } ?>
<?php if ($conf->multicompany->enabled) { ?>
<tr><td><?php echo $langs->trans("AllEntities"); ?></td><td class="valeur"><input id="entitycurrentorall" type="checkbox" name="entitycurrentorall"<?php echo (empty($entitycurrentorall) ?' checked':''); ?>></td></tr>
<?php } ?>
<!-- By default visible into list -->
<tr><td class="extra_list"><?php echo $form->textwithpicto($langs->trans("ByDefaultInList"), $langs->trans("VisibleDesc")); ?>
<!-- Visibility -->
<tr><td class="extra_list"><?php echo $form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc")); ?>
</td><td class="valeur"><input id="list" size="1" type="text" name="list" value="<?php echo ($list!=''?$list:'1'); ?>"></td></tr>
</table>

View File

@ -81,7 +81,6 @@ if (count($extrafields->attributes[$elementtype]['type']))
print '<td align="center">'.yn($extrafields->attributes[$elementtype]['required'][$key])."</td>\n";
print '<td align="center">'.yn($extrafields->attributes[$elementtype]['alwayseditable'][$key])."</td>\n";
print '<td align="center">'.$extrafields->attributes[$elementtype]['list'][$key]."</td>\n";
if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) print '<td align="center">'.yn($extrafields->attributes[$elementtype]['ishidden'][$key])."</td>\n"; // Add hidden option on not working feature. Why hide if user can't see it.
if (! empty($conf->multicompany->enabled)) {
print '<td align="center">'.($extrafields->attributes[$elementtype]['entityid'][$key]==0?$langs->trans("All"):$extrafields->attributes[$elementtype]['entitylabel'][$key]).'</td>';
}

View File

@ -59,8 +59,7 @@ if (empty($reshook) && ! empty($extrafields->attributes[$object->table_element][
}
else
{
if (! empty($extrafields->attributes[$object->table_element]['ishidden'][$key])) print '<tr class="hideobject"><td>';
else print '<tr><td>';
print '<tr><td>';
print '<table width="100%" class="nobordernopadding">';
print '<tr>';
print '<td';

View File

@ -349,7 +349,7 @@ ALTER TABLE llx_extrafields ADD COLUMN fk_user_modif integer;
ALTER TABLE llx_extrafields ADD COLUMN datec datetime;
ALTER TABLE llx_extrafields ADD COLUMN tms timestamp;
-- We fix value of 'list' fro m0 to 1 for all extrafields created before this migration
-- We fix value of 'list' from 0 to 1 for all extrafields created before this migration
UPDATE llx_extrafields SET list = 1 WHERE list = 0 AND fk_user_author IS NULL and fk_user_modif IS NULL and datec IS NULL;
ALTER TABLE llx_extrafields MODIFY COLUMN list integer DEFAULT 1;

View File

@ -34,9 +34,8 @@ create table llx_extrafields
pos integer DEFAULT 0,
alwayseditable integer DEFAULT 0, -- 1 if field can be edited whatever is element status
param text, -- extra parameters to define possible values of field
list integer DEFAULT 1, -- list of values for field that are combo lists
list integer DEFAULT 1, -- visibility of field. 0=Never visible, 1=Visible on list and forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing
langs varchar(64), -- example: fileofmymodule@mymodule
ishidden integer DEFAULT 0, -- Can be foreign key of external system
fk_user_author integer, -- user making creation
fk_user_modif integer, -- user making last change
datec datetime, -- date de creation

View File

@ -71,7 +71,7 @@ NoWidget=No widget
GoToApiExplorer=Go to API explorer
ListOfPermissionsDefined=List of defined permissions
EnabledDesc=Condition to have this field active (Examples: 1 or $conf->global->MYMODULE_MYOPTION)
VisibleDesc=Is the field visible into list ? (Examples: 0=Not visible, 1=Visible on list and forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing)
VisibleDesc=Is the field visible ? (Examples: 0=Never visible, 1=Visible on list and forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing)
IsAMeasureDesc=Can the value of field be cumulated to get a total into list ? (Examples: 1 or 0)
SearchAllDesc=Is the field used to make a search from the quick search tool ? (Examples: 1 or 0)
SpecDefDesc=Enter here all documentation you want to provide with your module that is not already defined by other tabs. You can use .md or better, the rich .asciidoc syntax.

View File

@ -99,7 +99,7 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be inclu
/*
* ACTIONS
* Actions
*
* Put here all code to do according to value of "action" parameter
*/
@ -133,7 +133,7 @@ if (empty($reshook))
/*
* VIEW
* View
*
* Put here all code to build page
*/

View File

@ -100,9 +100,7 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be inclu
/*
* ACTIONS
*
* Put here all code to do according to value of "action" parameter
* Actions
*/
$parameters=array();
@ -132,9 +130,7 @@ if (empty($reshook))
/*
* VIEW
*
* Put here all code to build page
* View
*/
$form=new Form($db);
@ -188,22 +184,10 @@ if ($action == 'create')
print $langs->trans($val['label']);
print '</td>';
print '<td>';
$defaultcss='minwidth100';
if ($val['type'] == 'text')
{
print '<textarea class="flat quatrevingtpercent" rows="'.ROWS_4.'" name="'.$key.'">';
print GETPOST($key,'none');
print '</textarea>';
}
elseif (is_array($val['arrayofkeyval']))
{
print $form->selectarray($key, $val['arrayofkeyval'], GETPOST($key, 'int'));
}
else
{
$cssforinput = empty($val['css'])?$defaultcss:$val['css'];
print '<input class="flat'.($cssforinput?' '.$cssforinput:'').'" class="'.$cssforinput.'" type="text" name="'.$key.'" value="'.(GETPOST($key,'alpha')?GETPOST($key,'alpha'):'').'">';
}
if (in_array($val['type'], array('int', 'integer'))) $value = GETPOST($key, 'int');
elseif ($val['type'] == 'text') $value = GETPOST($key, 'none');
else $value = GETPOST($key, 'alpha');
print $object->showInputField($val, $key, $value, '', '', '', 0, 0);
print '</td>';
print '</tr>';
}