NEW : manageme extrafields with multientity
This commit is contained in:
parent
f058fa1938
commit
8fd45383e2
@ -174,7 +174,9 @@ if ($action == 'add')
|
||||
(GETPOST('perms', 'alpha')?GETPOST('perms', 'alpha'):''),
|
||||
(GETPOST('list', 'alpha')?1:0),
|
||||
(GETPOST('ishidden', 'alpha')?1:0),
|
||||
GETPOST('computed_value','alpha')
|
||||
GETPOST('computed_value','alpha'),
|
||||
(GETPOST('entitycurrentorall', 'alpha')?0:'')
|
||||
|
||||
);
|
||||
if ($result > 0)
|
||||
{
|
||||
|
||||
@ -139,9 +139,10 @@ class ExtraFields
|
||||
* @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
|
||||
* @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($label)) return -1;
|
||||
@ -158,7 +159,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);
|
||||
$result2=$this->create_label($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $param, $alwayseditable, $perms, $list, $ishidden, $default, $computed, $entity);
|
||||
$err2=$this->errno;
|
||||
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 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
|
||||
* @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;
|
||||
|
||||
@ -331,7 +333,7 @@ class ExtraFields
|
||||
$sql.= " '".$type."',";
|
||||
$sql.= " '".$pos."',";
|
||||
$sql.= " '".$size."',";
|
||||
$sql.= " ".$conf->entity.",";
|
||||
$sql.= " ".($entity===''?$conf->entity:$entity).",";
|
||||
$sql.= " '".$elementtype."',";
|
||||
$sql.= " '".$unique."',";
|
||||
$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 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
|
||||
* @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 == 'contact') $elementtype='socpeople';
|
||||
@ -527,7 +530,7 @@ class ExtraFields
|
||||
{
|
||||
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)
|
||||
{
|
||||
@ -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 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
|
||||
* @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;
|
||||
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
|
||||
if ($elementtype == 'thirdparty') $elementtype='societe';
|
||||
@ -605,7 +609,7 @@ class ExtraFields
|
||||
|
||||
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields";
|
||||
$sql_del.= " WHERE name = '".$attrname."'";
|
||||
$sql_del.= " AND entity = ".$conf->entity;
|
||||
$sql_del.= " AND entity = ".($entity===''?$conf->entity:$entity);
|
||||
$sql_del.= " AND elementtype = '".$elementtype."'";
|
||||
|
||||
$resql1=$this->db->query($sql_del);
|
||||
@ -632,7 +636,7 @@ class ExtraFields
|
||||
$sql.= " datec";
|
||||
$sql.= ") VALUES (";
|
||||
$sql.= "'".$attrname."',";
|
||||
$sql.= " ".$conf->entity.",";
|
||||
$sql.= " ".($entity===''?$conf->entity:$entity).",";
|
||||
$sql.= " '".$this->db->escape($label)."',";
|
||||
$sql.= " '".$type."',";
|
||||
$sql.= " '".$size."',";
|
||||
@ -699,6 +703,7 @@ class ExtraFields
|
||||
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 .= ",entity";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."extrafields";
|
||||
$sql.= " WHERE entity IN (0,".$conf->entity.")";
|
||||
if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'";
|
||||
@ -732,6 +737,7 @@ class ExtraFields
|
||||
$this->attribute_perms[$tab->name]=$tab->perms;
|
||||
$this->attribute_list[$tab->name]=$tab->list;
|
||||
$this->attribute_hidden[$tab->name]=$tab->ishidden;
|
||||
$this->attribute_entity[$tab->name]=$tab->entity;
|
||||
|
||||
// New usage
|
||||
$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]['list'][$tab->name]=$tab->list;
|
||||
$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;
|
||||
|
||||
@ -173,6 +173,9 @@
|
||||
<?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>
|
||||
<?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) { ?>
|
||||
<!-- By default visible into list -->
|
||||
<tr><td><?php echo $langs->trans("ByDefaultInList"); ?>
|
||||
|
||||
@ -143,6 +143,9 @@ $list=$extrafields->attribute_list[$attrname];
|
||||
if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) {
|
||||
$ishidden=$extrafields->attribute_hidden[$attrname];
|
||||
}
|
||||
if ($conf->multicompany->enabled) {
|
||||
$entitycurrentorall=$extrafields->attribute_entity[$attrname];
|
||||
}
|
||||
|
||||
if((($type == 'select') || ($type == 'checkbox') || ($type == 'radio')) && is_array($param))
|
||||
{
|
||||
@ -232,6 +235,9 @@ else
|
||||
<?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 -->
|
||||
<?php if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { ?>
|
||||
<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("AlwaysEditable").'</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 "</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_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 ($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 " <a href=\"".$_SERVER["PHP_SELF"]."?action=delete&attrname=$key\">".img_delete()."</a></td>\n";
|
||||
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_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