Merge pull request #7238 from atm-florian/dev_manageextrafieldswithmultientity
NEW : manageme extrafields with multientity
This commit is contained in:
commit
1bd992dae9
@ -174,7 +174,9 @@ if ($action == 'add')
|
|||||||
(GETPOST('perms', 'alpha')?GETPOST('perms', 'alpha'):''),
|
(GETPOST('perms', 'alpha')?GETPOST('perms', 'alpha'):''),
|
||||||
(GETPOST('list', 'alpha')?1:0),
|
(GETPOST('list', 'alpha')?1:0),
|
||||||
(GETPOST('ishidden', 'alpha')?1:0),
|
(GETPOST('ishidden', 'alpha')?1:0),
|
||||||
GETPOST('computed_value','alpha')
|
GETPOST('computed_value','alpha'),
|
||||||
|
(GETPOST('entitycurrentorall', 'alpha')?0:'')
|
||||||
|
|
||||||
);
|
);
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -139,9 +139,10 @@ class ExtraFields
|
|||||||
* @param int $list Into list view by default
|
* @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 $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 $computed Computed value
|
||||||
|
* @param string $entity Entity of extrafields
|
||||||
* @return int <=0 if KO, >0 if OK
|
* @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='')
|
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='')
|
||||||
{
|
{
|
||||||
if (empty($attrname)) return -1;
|
if (empty($attrname)) return -1;
|
||||||
if (empty($label)) return -1;
|
if (empty($label)) return -1;
|
||||||
@ -158,7 +159,7 @@ class ExtraFields
|
|||||||
if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate')
|
if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate')
|
||||||
{
|
{
|
||||||
// Add declaration of field into table
|
// 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);
|
$result2=$this->create_label($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $param, $alwayseditable, $perms, $list, $ishidden, $default, $computed, $entity);
|
||||||
$err2=$this->errno;
|
$err2=$this->errno;
|
||||||
if ($result2 > 0 || ($err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS'))
|
if ($result2 > 0 || ($err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS'))
|
||||||
{
|
{
|
||||||
@ -277,9 +278,10 @@ class ExtraFields
|
|||||||
* @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 $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 $default Default value (in database. use the default_value feature for default value on screen).
|
* @param string $default Default value (in database. use the default_value feature for default value on screen).
|
||||||
* @param string $computed Computed value
|
* @param string $computed Computed value
|
||||||
|
* @param string $entity Entity of extrafields
|
||||||
* @return int <=0 if KO, >0 if OK
|
* @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='')
|
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='')
|
||||||
{
|
{
|
||||||
global $conf,$user;
|
global $conf,$user;
|
||||||
|
|
||||||
@ -331,7 +333,7 @@ class ExtraFields
|
|||||||
$sql.= " '".$type."',";
|
$sql.= " '".$type."',";
|
||||||
$sql.= " '".$pos."',";
|
$sql.= " '".$pos."',";
|
||||||
$sql.= " '".$size."',";
|
$sql.= " '".$size."',";
|
||||||
$sql.= " ".$conf->entity.",";
|
$sql.= " ".($entity===''?$conf->entity:$entity).",";
|
||||||
$sql.= " '".$elementtype."',";
|
$sql.= " '".$elementtype."',";
|
||||||
$sql.= " '".$unique."',";
|
$sql.= " '".$unique."',";
|
||||||
$sql.= " '".$required."',";
|
$sql.= " '".$required."',";
|
||||||
@ -477,9 +479,10 @@ class ExtraFields
|
|||||||
* @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 $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 $default Default value (in database. use the default_value feature for default value on screen).
|
* @param string $default Default value (in database. use the default_value feature for default value on screen).
|
||||||
* @param string $computed Computed value
|
* @param string $computed Computed value
|
||||||
|
* @param string $entity Entity of extrafields
|
||||||
* @return int >0 if OK, <=0 if KO
|
* @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='')
|
function update($attrname,$label,$type,$length,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0, $perms='',$list='',$ishidden=0,$default='',$computed='',$entity='')
|
||||||
{
|
{
|
||||||
if ($elementtype == 'thirdparty') $elementtype='societe';
|
if ($elementtype == 'thirdparty') $elementtype='societe';
|
||||||
if ($elementtype == 'contact') $elementtype='socpeople';
|
if ($elementtype == 'contact') $elementtype='socpeople';
|
||||||
@ -527,7 +530,7 @@ class ExtraFields
|
|||||||
{
|
{
|
||||||
if ($label)
|
if ($label)
|
||||||
{
|
{
|
||||||
$result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param,$alwayseditable,$perms,$list,$ishidden,$default,$computed);
|
$result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param,$alwayseditable,$perms,$list,$ishidden,$default,$computed,$entity);
|
||||||
}
|
}
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
@ -581,12 +584,13 @@ class ExtraFields
|
|||||||
* @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 $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 $default Default value (in database. use the default_value feature for default value on screen).
|
* @param string $default Default value (in database. use the default_value feature for default value on screen).
|
||||||
* @param string $computed Computed value
|
* @param string $computed Computed value
|
||||||
|
* @param string $entity Entity of extrafields
|
||||||
* @return int <=0 if KO, >0 if OK
|
* @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='')
|
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='')
|
||||||
{
|
{
|
||||||
global $conf, $user;
|
global $conf, $user;
|
||||||
dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$ishidden.", ".$default.", ".$computed);
|
dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$ishidden.", ".$default.", ".$computed.", ".$entity);
|
||||||
|
|
||||||
// Clean parameters
|
// Clean parameters
|
||||||
if ($elementtype == 'thirdparty') $elementtype='societe';
|
if ($elementtype == 'thirdparty') $elementtype='societe';
|
||||||
@ -605,7 +609,7 @@ class ExtraFields
|
|||||||
|
|
||||||
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields";
|
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields";
|
||||||
$sql_del.= " WHERE name = '".$attrname."'";
|
$sql_del.= " WHERE name = '".$attrname."'";
|
||||||
$sql_del.= " AND entity = ".$conf->entity;
|
$sql_del.= " AND entity = ".($entity===''?$conf->entity:$entity);
|
||||||
$sql_del.= " AND elementtype = '".$elementtype."'";
|
$sql_del.= " AND elementtype = '".$elementtype."'";
|
||||||
|
|
||||||
$resql1=$this->db->query($sql_del);
|
$resql1=$this->db->query($sql_del);
|
||||||
@ -632,7 +636,7 @@ class ExtraFields
|
|||||||
$sql.= " datec";
|
$sql.= " datec";
|
||||||
$sql.= ") VALUES (";
|
$sql.= ") VALUES (";
|
||||||
$sql.= "'".$attrname."',";
|
$sql.= "'".$attrname."',";
|
||||||
$sql.= " ".$conf->entity.",";
|
$sql.= " ".($entity===''?$conf->entity:$entity).",";
|
||||||
$sql.= " '".$this->db->escape($label)."',";
|
$sql.= " '".$this->db->escape($label)."',";
|
||||||
$sql.= " '".$type."',";
|
$sql.= " '".$type."',";
|
||||||
$sql.= " '".$size."',";
|
$sql.= " '".$size."',";
|
||||||
@ -699,6 +703,7 @@ class ExtraFields
|
|||||||
dol_syslog("fetch_name_optionals_label elementtype=".$elementtype);
|
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,list,ishidden,fielddefault,fieldcomputed";
|
||||||
|
$sql .= ",entity";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."extrafields";
|
$sql.= " FROM ".MAIN_DB_PREFIX."extrafields";
|
||||||
$sql.= " WHERE entity IN (0,".$conf->entity.")";
|
$sql.= " WHERE entity IN (0,".$conf->entity.")";
|
||||||
if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'";
|
if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'";
|
||||||
@ -732,6 +737,7 @@ class ExtraFields
|
|||||||
$this->attribute_perms[$tab->name]=$tab->perms;
|
$this->attribute_perms[$tab->name]=$tab->perms;
|
||||||
$this->attribute_list[$tab->name]=$tab->list;
|
$this->attribute_list[$tab->name]=$tab->list;
|
||||||
$this->attribute_hidden[$tab->name]=$tab->ishidden;
|
$this->attribute_hidden[$tab->name]=$tab->ishidden;
|
||||||
|
$this->attribute_entity[$tab->name]=$tab->entity;
|
||||||
|
|
||||||
// New usage
|
// New usage
|
||||||
$this->attributes[$tab->elementtype]['type'][$tab->name]=$tab->type;
|
$this->attributes[$tab->elementtype]['type'][$tab->name]=$tab->type;
|
||||||
@ -748,6 +754,7 @@ class ExtraFields
|
|||||||
$this->attributes[$tab->elementtype]['perms'][$tab->name]=$tab->perms;
|
$this->attributes[$tab->elementtype]['perms'][$tab->name]=$tab->perms;
|
||||||
$this->attributes[$tab->elementtype]['list'][$tab->name]=$tab->list;
|
$this->attributes[$tab->elementtype]['list'][$tab->name]=$tab->list;
|
||||||
$this->attributes[$tab->elementtype]['ishidden'][$tab->name]=$tab->ishidden;
|
$this->attributes[$tab->elementtype]['ishidden'][$tab->name]=$tab->ishidden;
|
||||||
|
$this->attributes[$tab->elementtype]['entity'][$tab->name]=$tab->entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($elementtype) $this->attributes[$elementtype]['loaded']=1;
|
if ($elementtype) $this->attributes[$elementtype]['loaded']=1;
|
||||||
|
|||||||
@ -173,6 +173,9 @@
|
|||||||
<?php if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) { ?>
|
<?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') ?' checked' : ''); ?>></td></tr>
|
<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') ?' checked' : ''); ?>></td></tr>
|
||||||
<?php } ?>
|
<?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') ? '':' checked'); ?>></td></tr>
|
||||||
|
<?php } ?>
|
||||||
<?php if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { ?>
|
<?php if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { ?>
|
||||||
<!-- By default visible into list -->
|
<!-- By default visible into list -->
|
||||||
<tr><td><?php echo $langs->trans("ByDefaultInList"); ?>
|
<tr><td><?php echo $langs->trans("ByDefaultInList"); ?>
|
||||||
|
|||||||
@ -143,6 +143,9 @@ $list=$extrafields->attribute_list[$attrname];
|
|||||||
if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) {
|
if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) {
|
||||||
$ishidden=$extrafields->attribute_hidden[$attrname];
|
$ishidden=$extrafields->attribute_hidden[$attrname];
|
||||||
}
|
}
|
||||||
|
if ($conf->multicompany->enabled) {
|
||||||
|
$entitycurrentorall=$extrafields->attribute_entity[$attrname];
|
||||||
|
}
|
||||||
|
|
||||||
if((($type == 'select') || ($type == 'checkbox') || ($type == 'radio')) && is_array($param))
|
if((($type == 'select') || ($type == 'checkbox') || ($type == 'radio')) && is_array($param))
|
||||||
{
|
{
|
||||||
@ -232,6 +235,9 @@ else
|
|||||||
<?php if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) { ?>
|
<?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>
|
<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 } ?>
|
||||||
|
<?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 -->
|
<!-- By default visible into list -->
|
||||||
<?php if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { ?>
|
<?php if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { ?>
|
||||||
<tr><td><?php echo $langs->trans("ByDefaultInList"); ?>
|
<tr><td><?php echo $langs->trans("ByDefaultInList"); ?>
|
||||||
|
|||||||
@ -49,6 +49,9 @@ print '<td>'.$langs->trans("ComputedFormula").'</td>';
|
|||||||
print '<td align="center">'.$langs->trans("Required").'</td>';
|
print '<td align="center">'.$langs->trans("Required").'</td>';
|
||||||
print '<td align="center">'.$langs->trans("AlwaysEditable").'</td>';
|
print '<td align="center">'.$langs->trans("AlwaysEditable").'</td>';
|
||||||
if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) print '<td align="center">'.$langs->trans("Hidden").'</td>';
|
if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) print '<td align="center">'.$langs->trans("Hidden").'</td>';
|
||||||
|
if ($conf->multicompany->enabled) {
|
||||||
|
print '<td align="center">'.$langs->trans("AllEntities").'</td>';
|
||||||
|
}
|
||||||
print '<td width="80"> </td>';
|
print '<td width="80"> </td>';
|
||||||
print "</tr>\n";
|
print "</tr>\n";
|
||||||
|
|
||||||
@ -68,6 +71,9 @@ if (count($extrafields->attribute_type))
|
|||||||
print '<td align="center">'.yn($extrafields->attribute_required[$key])."</td>\n";
|
print '<td align="center">'.yn($extrafields->attribute_required[$key])."</td>\n";
|
||||||
print '<td align="center">'.yn($extrafields->attribute_alwayseditable[$key])."</td>\n";
|
print '<td align="center">'.yn($extrafields->attribute_alwayseditable[$key])."</td>\n";
|
||||||
if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) print '<td align="center">'.yn($extrafields->attribute_hidden[$key])."</td>\n"; // Add hidden option on not working feature. Why hide if user can't see it.
|
if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) print '<td align="center">'.yn($extrafields->attribute_hidden[$key])."</td>\n"; // Add hidden option on not working feature. Why hide if user can't see it.
|
||||||
|
if ($conf->multicompany->enabled) {
|
||||||
|
print '<td align="center">'.($extrafields->attribute_entity[$key]==0?$langs->trans("All"):$langs->trans("Current")).'</td>';
|
||||||
|
}
|
||||||
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit&attrname='.$key.'">'.img_edit().'</a>';
|
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit&attrname='.$key.'">'.img_edit().'</a>';
|
||||||
print " <a href=\"".$_SERVER["PHP_SELF"]."?action=delete&attrname=$key\">".img_delete()."</a></td>\n";
|
print " <a href=\"".$_SERVER["PHP_SELF"]."?action=delete&attrname=$key\">".img_delete()."</a></td>\n";
|
||||||
print "</tr>";
|
print "</tr>";
|
||||||
|
|||||||
@ -183,3 +183,8 @@ ALTER TABLE llx_expensereport_det ADD COLUMN fk_c_exp_tax_cat integer;
|
|||||||
|
|
||||||
ALTER TABLE llx_user ADD COLUMN default_range integer;
|
ALTER TABLE llx_user ADD COLUMN default_range integer;
|
||||||
ALTER TABLE llx_user ADD COLUMN default_c_exp_tax_cat integer;
|
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 tms timestamp;
|
||||||
Loading…
Reference in New Issue
Block a user