Fix field enabled and perms must differs
This commit is contained in:
parent
3bcf1d9da6
commit
7a88afe962
@ -143,11 +143,12 @@ class ExtraFields
|
||||
* @param int $list Visibilty
|
||||
* @param int $ishidden Deprecated. Use visibility instead.
|
||||
* @param string $computed Computed value
|
||||
* @param string $entity Entity of extrafields
|
||||
* @param string $entity Entity of extrafields (for multicompany modules)
|
||||
* @param string $langfile Language file
|
||||
* @param string $enabled Condition to have the field enabled or not
|
||||
* @return int <=0 if KO, >0 if OK
|
||||
*/
|
||||
function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0, $default_value='', $param='', $alwayseditable=0, $perms='', $list=-1, $ishidden=0, $computed='', $entity='', $langfile='')
|
||||
function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0, $default_value='', $param='', $alwayseditable=0, $perms='', $list=-1, $ishidden=0, $computed='', $entity='', $langfile='', $enabled='1')
|
||||
{
|
||||
if (empty($attrname)) return -1;
|
||||
if (empty($label)) return -1;
|
||||
@ -286,9 +287,10 @@ class ExtraFields
|
||||
* @param string $computed Computed value
|
||||
* @param string $entity Entity of extrafields
|
||||
* @param string $langfile Language file
|
||||
* @param string $enabled Condition to have the field enabled or not
|
||||
* @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=-1, $ishidden=0, $default='', $computed='',$entity='', $langfile='')
|
||||
private function create_label($attrname, $label='', $type='', $pos=0, $size=0, $elementtype='member', $unique=0, $required=0, $param='', $alwayseditable=0, $perms='', $list=-1, $ishidden=0, $default='', $computed='',$entity='', $langfile='', $enabled='1')
|
||||
{
|
||||
global $conf,$user;
|
||||
|
||||
@ -298,6 +300,9 @@ class ExtraFields
|
||||
// Clean parameters
|
||||
if (empty($pos)) $pos=0;
|
||||
if (empty($list)) $list=0;
|
||||
if (empty($required)) $required=0;
|
||||
if (empty($unique)) $unique=0;
|
||||
if (empty($alwayseditable)) $alwayseditable=0;
|
||||
|
||||
if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname) && ! is_numeric($attrname))
|
||||
{
|
||||
@ -333,19 +338,20 @@ class ExtraFields
|
||||
$sql.= " fieldcomputed,";
|
||||
$sql.= " fk_user_author,";
|
||||
$sql.= " fk_user_modif,";
|
||||
$sql.= " datec";
|
||||
$sql.= " datec,";
|
||||
$sql.= " enabled";
|
||||
$sql.= " )";
|
||||
$sql.= " VALUES('".$attrname."',";
|
||||
$sql.= " '".$this->db->escape($label)."',";
|
||||
$sql.= " '".$type."',";
|
||||
$sql.= " '".$pos."',";
|
||||
$sql.= " '".$size."',";
|
||||
$sql.= " '".$this->db->escape($type)."',";
|
||||
$sql.= " ".$pos.",";
|
||||
$sql.= " '".$this->db->escape($size)."',";
|
||||
$sql.= " ".($entity===''?$conf->entity:$entity).",";
|
||||
$sql.= " '".$elementtype."',";
|
||||
$sql.= " '".$unique."',";
|
||||
$sql.= " '".$required."',";
|
||||
$sql.= " '".$params."',";
|
||||
$sql.= " '".$alwayseditable."',";
|
||||
$sql.= " '".$this->db->escape($elementtype)."',";
|
||||
$sql.= " ".$unique.",";
|
||||
$sql.= " ".$required.",";
|
||||
$sql.= " '".$this->db->escape($params)."',";
|
||||
$sql.= " ".$alwayseditable.",";
|
||||
$sql.= " ".($perms?"'".$this->db->escape($perms)."'":"null").",";
|
||||
$sql.= " ".($langfile?"'".$this->db->escape($langfile)."'":"null").",";
|
||||
$sql.= " ".$list.",";
|
||||
@ -353,7 +359,8 @@ class ExtraFields
|
||||
$sql.= " ".($computed?"'".$this->db->escape($computed)."'":"null").",";
|
||||
$sql .= " " . $user->id . ",";
|
||||
$sql .= " " . $user->id . ",";
|
||||
$sql .= "'" . $this->db->idate(dol_now()) . "'";
|
||||
$sql .= "'" . $this->db->idate(dol_now()) . "',";
|
||||
$sql.= " ".($enabled?"'".$this->db->escape($enabled)."'":"1");
|
||||
$sql.=')';
|
||||
|
||||
dol_syslog(get_class($this)."::create_label", LOG_DEBUG);
|
||||
@ -488,9 +495,10 @@ class ExtraFields
|
||||
* @param string $computed Computed value
|
||||
* @param string $entity Entity of extrafields
|
||||
* @param string $langfile Language file
|
||||
* @param string $enabled Condition to have the field enabled or not
|
||||
* @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='', $langfile='')
|
||||
function update($attrname, $label, $type, $length, $elementtype, $unique=0, $required=0, $pos=0, $param='', $alwayseditable=0, $perms='', $list='', $ishidden=0, $default='', $computed='', $entity='', $langfile='', $enabled='1')
|
||||
{
|
||||
if ($elementtype == 'thirdparty') $elementtype='societe';
|
||||
if ($elementtype == 'contact') $elementtype='socpeople';
|
||||
@ -538,7 +546,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,$langfile);
|
||||
$result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param,$alwayseditable,$perms,$list,$ishidden,$default,$computed,$entity,$langfile,$enabled);
|
||||
}
|
||||
if ($result > 0)
|
||||
{
|
||||
@ -594,18 +602,23 @@ class ExtraFields
|
||||
* @param string $computed Computed value
|
||||
* @param string $entity Entity of extrafields
|
||||
* @param string $langfile Language file
|
||||
* @param string $enabled Condition to have the field enabled or not
|
||||
* @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='',$langfile='')
|
||||
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='',$enabled='1')
|
||||
{
|
||||
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.", ".$langfile);
|
||||
dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$ishidden.", ".$default.", ".$computed.", ".$entity.", ".$langfile.", ".$enabled);
|
||||
|
||||
// Clean parameters
|
||||
if ($elementtype == 'thirdparty') $elementtype='societe';
|
||||
if ($elementtype == 'contact') $elementtype='socpeople';
|
||||
|
||||
if (empty($pos)) $pos=0;
|
||||
if (empty($list)) $list=0;
|
||||
if (empty($required)) $required=0;
|
||||
if (empty($unique)) $unique=0;
|
||||
if (empty($alwayseditable)) $alwayseditable=0;
|
||||
|
||||
if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
|
||||
{
|
||||
@ -642,27 +655,29 @@ class ExtraFields
|
||||
$sql.= " fieldcomputed,";
|
||||
$sql.= " fk_user_author,";
|
||||
$sql.= " fk_user_modif,";
|
||||
$sql.= " datec";
|
||||
$sql.= " datec,";
|
||||
$sql.= " enabled";
|
||||
$sql.= ") VALUES (";
|
||||
$sql.= "'".$attrname."',";
|
||||
$sql.= " ".($entity===''?$conf->entity:$entity).",";
|
||||
$sql.= " '".$this->db->escape($label)."',";
|
||||
$sql.= " '".$type."',";
|
||||
$sql.= " '".$size."',";
|
||||
$sql.= " '".$elementtype."',";
|
||||
$sql.= " '".$unique."',";
|
||||
$sql.= " '".$required."',";
|
||||
$sql.= " '".$this->db->escape($type)."',";
|
||||
$sql.= " '".$this->db->escape($size)."',";
|
||||
$sql.= " '".$this->db->escape($elementtype)."',";
|
||||
$sql.= " ".$unique.",";
|
||||
$sql.= " ".$required.",";
|
||||
$sql.= " ".($perms?"'".$this->db->escape($perms)."'":"null").",";
|
||||
$sql.= " ".($langfile?"'".$this->db->escape($langfile)."'":"null").",";
|
||||
$sql.= " '".$pos."',";
|
||||
$sql.= " '".$alwayseditable."',";
|
||||
$sql.= " '".$param."',";
|
||||
$sql.= " ".$pos.",";
|
||||
$sql.= " '".$this->db->escape($alwayseditable)."',";
|
||||
$sql.= " '".$this->db->escape($param)."',";
|
||||
$sql.= " ".$list.", ";
|
||||
$sql.= " ".(($default!='')?"'".$this->db->escape($default)."'":"null").",";
|
||||
$sql.= " ".($computed?"'".$this->db->escape($computed)."'":"null").",";
|
||||
$sql .= " " . $user->id . ",";
|
||||
$sql .= " " . $user->id . ",";
|
||||
$sql .= "'" . $this->db->idate(dol_now()) . "'";
|
||||
$sql .= "'" . $this->db->idate(dol_now()) . "',";
|
||||
$sql .= "'" . $this->db->escape($enabled). "'";
|
||||
$sql.= ")";
|
||||
|
||||
$resql2=$this->db->query($sql);
|
||||
|
||||
@ -429,6 +429,7 @@ ALTER TABLE llx_user ADD COLUMN default_c_exp_tax_cat integer;
|
||||
ALTER TABLE llx_extrafields ADD COLUMN fk_user_author integer;
|
||||
ALTER TABLE llx_extrafields ADD COLUMN fk_user_modif integer;
|
||||
ALTER TABLE llx_extrafields ADD COLUMN datec datetime;
|
||||
ALTER TABLE llx_extrafields ADD COLUMN enabled varchar(255) DEFAULT '1';
|
||||
ALTER TABLE llx_extrafields ADD COLUMN tms timestamp;
|
||||
|
||||
-- We fix value of 'list' from 0 to 1 for all extrafields created before this migration
|
||||
|
||||
@ -31,6 +31,7 @@ create table llx_extrafields
|
||||
fieldunique integer DEFAULT 0,
|
||||
fieldrequired integer DEFAULT 0,
|
||||
perms varchar(255), -- not used yet
|
||||
enabled varchar(255),
|
||||
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
|
||||
|
||||
@ -314,11 +314,11 @@ class modMyModule extends DolibarrModules
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
|
||||
$extrafields = new ExtraFields($this->db);
|
||||
|
||||
//$result1=$extrafields->addExtraField('myattr1', "New Attr 1 label", 'boolean', 1, 3, 'thirdparty', 0, 0, '', '', 1, '', 0, 0, '', '', 'mymodule@mymodule');
|
||||
//$result2=$extrafields->addExtraField('myattr2', "New Attr 2 label", 'varchar', 1, 10, 'project', 0, 0, '', '', 1, '', 0, 0, '', '', 'mymodule@mymodule');
|
||||
//$result3=$extrafields->addExtraField('myattr3', "New Attr 3 label", 'varchar', 1, 10, 'bank_account', 0, 0, '', '', 1, '', 0, 0, '', '', 'mymodule@mymodule');
|
||||
//$result4=$extrafields->addExtraField('myattr4', "New Attr 4 label", 'select', 1, 3, 'thirdparty', 0, 1, '', array('options'=>array('code1'=>'Val1','code2'=>'Val2','code3'=>'Val3')), 1);
|
||||
//$result5=$extrafields->addExtraField('myattr5', "New Attr 5 label", 'text', 1, 10, 'user', 0, 0, '', '', 1, '', 0, 0, '', '', 'mymodule@mymodule');
|
||||
//$result1=$extrafields->addExtraField('myattr1', "New Attr 1 label", 'boolean', 1, 3, 'thirdparty', 0, 0, '', '', 1, '', 0, 0, '', '', 'mymodule@mymodule', '$conf->mymodule->enabled');
|
||||
//$result2=$extrafields->addExtraField('myattr2', "New Attr 2 label", 'varchar', 1, 10, 'project', 0, 0, '', '', 1, '', 0, 0, '', '', 'mymodule@mymodule', '$conf->mymodule->enabled');
|
||||
//$result3=$extrafields->addExtraField('myattr3', "New Attr 3 label", 'varchar', 1, 10, 'bank_account', 0, 0, '', '', 1, '', 0, 0, '', '', 'mymodule@mymodule', '$conf->mymodule->enabled');
|
||||
//$result4=$extrafields->addExtraField('myattr4', "New Attr 4 label", 'select', 1, 3, 'thirdparty', 0, 1, '', array('options'=>array('code1'=>'Val1','code2'=>'Val2','code3'=>'Val3')), 1 '', 0, 0, '', '', 'mymodule@mymodule', '$conf->mymodule->enabled');
|
||||
//$result5=$extrafields->addExtraField('myattr5', "New Attr 5 label", 'text', 1, 10, 'user', 0, 0, '', '', 1, '', 0, 0, '', '', 'mymodule@mymodule', '$conf->mymodule->enabled');
|
||||
|
||||
$sql = array();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user