|
|
|
|
@ -64,7 +64,9 @@ class ExtraFields
|
|
|
|
|
var $attribute_alwayseditable;
|
|
|
|
|
// Array to store permission to check
|
|
|
|
|
var $attribute_perms;
|
|
|
|
|
// Array to store permission to check
|
|
|
|
|
// Array to store language file to translate label of values
|
|
|
|
|
var $attribute_langfile;
|
|
|
|
|
// Array to store if field is visible by default on list
|
|
|
|
|
var $attribute_list;
|
|
|
|
|
// Array to store if extra field is hidden
|
|
|
|
|
var $attribute_hidden; // warning, do not rely on this. If your module need a hidden data, it must use its own table.
|
|
|
|
|
@ -117,6 +119,7 @@ class ExtraFields
|
|
|
|
|
$this->attribute_unique = array();
|
|
|
|
|
$this->attribute_required = array();
|
|
|
|
|
$this->attribute_perms = array();
|
|
|
|
|
$this->attribute_langfile = array();
|
|
|
|
|
$this->attribute_list = array();
|
|
|
|
|
$this->attribute_hidden = array();
|
|
|
|
|
}
|
|
|
|
|
@ -124,25 +127,26 @@ class ExtraFields
|
|
|
|
|
/**
|
|
|
|
|
* Add a new extra field parameter
|
|
|
|
|
*
|
|
|
|
|
* @param string $attrname Code of attribute
|
|
|
|
|
* @param string $label label of attribute
|
|
|
|
|
* @param int $type Type of attribute ('boolean', 'int', 'text', 'varchar', 'date', 'datehour','price','phone','mail','password','url','select','checkbox', ...)
|
|
|
|
|
* @param int $pos Position of attribute
|
|
|
|
|
* @param string $size Size/length of attribute
|
|
|
|
|
* @param string $elementtype Element type ('member', 'product', 'thirdparty', ...)
|
|
|
|
|
* @param int $unique Is field unique or not
|
|
|
|
|
* @param int $required Is field required or not
|
|
|
|
|
* @param string $default_value Defaulted value (In database. use the default_value feature for default value on screen. Example: '', '0', 'null', 'avalue')
|
|
|
|
|
* @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 string $computed Computed value
|
|
|
|
|
* @param string $entity Entity of extrafields
|
|
|
|
|
* @param string $attrname Code of attribute
|
|
|
|
|
* @param string $label label of attribute
|
|
|
|
|
* @param int $type Type of attribute ('boolean', 'int', 'text', 'varchar', 'date', 'datehour','price','phone','mail','password','url','select','checkbox', ...)
|
|
|
|
|
* @param int $pos Position of attribute
|
|
|
|
|
* @param string $size Size/length of attribute
|
|
|
|
|
* @param string $elementtype Element type ('member', 'product', 'thirdparty', ...)
|
|
|
|
|
* @param int $unique Is field unique or not
|
|
|
|
|
* @param int $required Is field required or not
|
|
|
|
|
* @param string $default_value Defaulted value (In database. use the default_value feature for default value on screen. Example: '', '0', 'null', 'avalue')
|
|
|
|
|
* @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
|
|
|
|
|
* @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 string $computed Computed value
|
|
|
|
|
* @param string $entity Entity of extrafields
|
|
|
|
|
* @param string $langfile Language file
|
|
|
|
|
* @return int <=0 if KO, >0 if OK
|
|
|
|
|
*/
|
|
|
|
|
function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0, $default_value='', $param=0, $alwayseditable=0, $perms='', $list=0, $ishidden=0, $computed='', $entity='')
|
|
|
|
|
function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0, $default_value='', $param='', $alwayseditable=0, $perms='', $list=0, $ishidden=0, $computed='', $entity='', $langfile='')
|
|
|
|
|
{
|
|
|
|
|
if (empty($attrname)) return -1;
|
|
|
|
|
if (empty($label)) return -1;
|
|
|
|
|
@ -159,7 +163,7 @@ class ExtraFields
|
|
|
|
|
if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate')
|
|
|
|
|
{
|
|
|
|
|
// Add declaration of field into table
|
|
|
|
|
$result2=$this->create_label($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $param, $alwayseditable, $perms, $list, $ishidden, $default, $computed, $entity);
|
|
|
|
|
$result2=$this->create_label($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $param, $alwayseditable, $perms, $list, $ishidden, $default, $computed, $entity, $langfile);
|
|
|
|
|
$err2=$this->errno;
|
|
|
|
|
if ($result2 > 0 || ($err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS'))
|
|
|
|
|
{
|
|
|
|
|
@ -271,7 +275,7 @@ class ExtraFields
|
|
|
|
|
* @param string $elementtype Element type ('member', 'product', 'thirdparty', ...)
|
|
|
|
|
* @param int $unique Is field unique or not
|
|
|
|
|
* @param int $required Is field required or not
|
|
|
|
|
* @param array||string $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) )
|
|
|
|
|
* @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
|
|
|
|
|
@ -279,9 +283,10 @@ class ExtraFields
|
|
|
|
|
* @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
|
|
|
|
|
* @param string $langfile Language file
|
|
|
|
|
* @return int <=0 if KO, >0 if OK
|
|
|
|
|
*/
|
|
|
|
|
private function create_label($attrname, $label='', $type='', $pos=0, $size=0, $elementtype='member', $unique=0, $required=0, $param='', $alwayseditable=0, $perms='', $list=0, $ishidden=0, $default='', $computed='',$entity='')
|
|
|
|
|
private function create_label($attrname, $label='', $type='', $pos=0, $size=0, $elementtype='member', $unique=0, $required=0, $param='', $alwayseditable=0, $perms='', $list=0, $ishidden=0, $default='', $computed='',$entity='', $langfile='')
|
|
|
|
|
{
|
|
|
|
|
global $conf,$user;
|
|
|
|
|
|
|
|
|
|
@ -320,6 +325,7 @@ class ExtraFields
|
|
|
|
|
$sql.= " param,";
|
|
|
|
|
$sql.= " alwayseditable,";
|
|
|
|
|
$sql.= " perms,";
|
|
|
|
|
$sql.= " langs,";
|
|
|
|
|
$sql.= " list,";
|
|
|
|
|
$sql.= " ishidden,";
|
|
|
|
|
$sql.= " fielddefault,";
|
|
|
|
|
@ -340,6 +346,7 @@ class ExtraFields
|
|
|
|
|
$sql.= " '".$params."',";
|
|
|
|
|
$sql.= " '".$alwayseditable."',";
|
|
|
|
|
$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").",";
|
|
|
|
|
@ -480,9 +487,10 @@ class ExtraFields
|
|
|
|
|
* @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
|
|
|
|
|
* @param string $langfile Language file
|
|
|
|
|
* @return int >0 if OK, <=0 if KO
|
|
|
|
|
*/
|
|
|
|
|
function update($attrname,$label,$type,$length,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0, $perms='',$list='',$ishidden=0,$default='',$computed='',$entity='')
|
|
|
|
|
function update($attrname, $label, $type, $length, $elementtype, $unique=0, $required=0, $pos=0, $param='', $alwayseditable=0, $perms='', $list='', $ishidden=0, $default='', $computed='', $entity='', $langfile='')
|
|
|
|
|
{
|
|
|
|
|
if ($elementtype == 'thirdparty') $elementtype='societe';
|
|
|
|
|
if ($elementtype == 'contact') $elementtype='socpeople';
|
|
|
|
|
@ -530,7 +538,7 @@ class ExtraFields
|
|
|
|
|
{
|
|
|
|
|
if ($label)
|
|
|
|
|
{
|
|
|
|
|
$result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param,$alwayseditable,$perms,$list,$ishidden,$default,$computed,$entity);
|
|
|
|
|
$result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param,$alwayseditable,$perms,$list,$ishidden,$default,$computed,$entity,$langfile);
|
|
|
|
|
}
|
|
|
|
|
if ($result > 0)
|
|
|
|
|
{
|
|
|
|
|
@ -585,12 +593,13 @@ class ExtraFields
|
|
|
|
|
* @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
|
|
|
|
|
* @param string $langfile Language file
|
|
|
|
|
* @return int <=0 if KO, >0 if OK
|
|
|
|
|
*/
|
|
|
|
|
private function update_label($attrname,$label,$type,$size,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0,$perms='',$list=0,$ishidden=0,$default='',$computed='',$entity='')
|
|
|
|
|
private function update_label($attrname,$label,$type,$size,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0,$perms='',$list=0,$ishidden=0,$default='',$computed='',$entity='',$langfile='')
|
|
|
|
|
{
|
|
|
|
|
global $conf, $user;
|
|
|
|
|
dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$ishidden.", ".$default.", ".$computed.", ".$entity);
|
|
|
|
|
dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$ishidden.", ".$default.", ".$computed.", ".$entity.", ".$langfile);
|
|
|
|
|
|
|
|
|
|
// Clean parameters
|
|
|
|
|
if ($elementtype == 'thirdparty') $elementtype='societe';
|
|
|
|
|
@ -624,6 +633,7 @@ class ExtraFields
|
|
|
|
|
$sql.= " fieldunique,";
|
|
|
|
|
$sql.= " fieldrequired,";
|
|
|
|
|
$sql.= " perms,";
|
|
|
|
|
$sql.= " langs,";
|
|
|
|
|
$sql.= " pos,";
|
|
|
|
|
$sql.= " alwayseditable,";
|
|
|
|
|
$sql.= " param,";
|
|
|
|
|
@ -644,6 +654,7 @@ class ExtraFields
|
|
|
|
|
$sql.= " '".$unique."',";
|
|
|
|
|
$sql.= " '".$required."',";
|
|
|
|
|
$sql.= " ".($perms?"'".$this->db->escape($perms)."'":"null").",";
|
|
|
|
|
$sql.= " ".($langfile?"'".$this->db->escape($langfile)."'":"null").",";
|
|
|
|
|
$sql.= " '".$pos."',";
|
|
|
|
|
$sql.= " '".$alwayseditable."',";
|
|
|
|
|
$sql.= " '".$param."',";
|
|
|
|
|
@ -702,7 +713,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,list,ishidden,fielddefault,fieldcomputed";
|
|
|
|
|
$sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,ishidden,fielddefault,fieldcomputed";
|
|
|
|
|
$sql .= ",entity";
|
|
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."extrafields";
|
|
|
|
|
$sql.= " WHERE entity IN (0,".$conf->entity.")";
|
|
|
|
|
@ -722,8 +733,6 @@ class ExtraFields
|
|
|
|
|
$array_name_label[$tab->name]=$tab->label;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Old usage
|
|
|
|
|
$this->attribute_type[$tab->name]=$tab->type;
|
|
|
|
|
$this->attribute_label[$tab->name]=$tab->label;
|
|
|
|
|
@ -737,12 +746,11 @@ class ExtraFields
|
|
|
|
|
$this->attribute_pos[$tab->name]=$tab->pos;
|
|
|
|
|
$this->attribute_alwayseditable[$tab->name]=$tab->alwayseditable;
|
|
|
|
|
$this->attribute_perms[$tab->name]=$tab->perms;
|
|
|
|
|
$this->attribute_langfile[$tab->langs]=$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
|
|
|
|
|
$this->attributes[$tab->elementtype]['type'][$tab->name]=$tab->type;
|
|
|
|
|
$this->attributes[$tab->elementtype]['label'][$tab->name]=$tab->label;
|
|
|
|
|
@ -756,6 +764,7 @@ class ExtraFields
|
|
|
|
|
$this->attributes[$tab->elementtype]['pos'][$tab->name]=$tab->pos;
|
|
|
|
|
$this->attributes[$tab->elementtype]['alwayseditable'][$tab->name]=$tab->alwayseditable;
|
|
|
|
|
$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;
|
|
|
|
|
@ -820,7 +829,7 @@ class ExtraFields
|
|
|
|
|
$unique=$this->attribute_unique[$key];
|
|
|
|
|
$required=$this->attribute_required[$key];
|
|
|
|
|
$param=$this->attribute_param[$key];
|
|
|
|
|
$perms=$this->attribute_perms[$key];
|
|
|
|
|
$langfile=$this->attribute_langfile[$key];
|
|
|
|
|
$list=$this->attribute_list[$key];
|
|
|
|
|
$hidden=$this->attribute_hidden[$key];
|
|
|
|
|
|
|
|
|
|
@ -1352,6 +1361,7 @@ class ExtraFields
|
|
|
|
|
$required=$this->attribute_required[$key];
|
|
|
|
|
$params=$this->attribute_param[$key];
|
|
|
|
|
$perms=$this->attribute_perms[$key];
|
|
|
|
|
$langfile=$this->attribute_langfile[$key];
|
|
|
|
|
$list=$this->attribute_list[$key];
|
|
|
|
|
$hidden=$this->attribute_hidden[$key]; // warning, do not rely on this. If your module need a hidden data, it must use its own table.
|
|
|
|
|
|
|
|
|
|
|