NEW feature hidden extrafields

This commit is contained in:
phf 2016-02-03 22:49:43 +01:00
parent 47e2e33fb7
commit 75c4888364
10 changed files with 37 additions and 13 deletions

View File

@ -162,6 +162,7 @@ if ($action == 'add')
(GETPOST('alwayseditable')?1:0), (GETPOST('alwayseditable')?1:0),
(GETPOST('perms')?GETPOST('perms'):''), (GETPOST('perms')?GETPOST('perms'):''),
(GETPOST('list')?1:0) (GETPOST('list')?1:0)
,(GETPOST('ishidden')?1:0)
); );
if ($result > 0) if ($result > 0)
{ {
@ -312,6 +313,7 @@ if ($action == 'update')
(GETPOST('alwayseditable')?1:0), (GETPOST('alwayseditable')?1:0),
(GETPOST('perms')?GETPOST('perms'):''), (GETPOST('perms')?GETPOST('perms'):''),
(GETPOST('list')?1:0) (GETPOST('list')?1:0)
,(GETPOST('ishidden')?1:0)
); );
if ($result > 0) if ($result > 0)
{ {

View File

@ -4085,6 +4085,7 @@ abstract class CommonObject
else else
{ {
$csstyle=''; $csstyle='';
$class=(!empty($extrafields->attribute_hidden[$key]) ? 'class="hideobject" ' : '');
if (is_array($params) && count($params)>0) { if (is_array($params) && count($params)>0) {
if (array_key_exists('style',$params)) { if (array_key_exists('style',$params)) {
$csstyle=$params['style']; $csstyle=$params['style'];
@ -4092,12 +4093,12 @@ abstract class CommonObject
} }
if ( !empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) if ( !empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0)
{ {
$out .= '<tr '.$csstyle.'>'; $out .= '<tr '.$class.$csstyle.'>';
$colspan='0'; $colspan='0';
} }
else else
{ {
$out .= '<tr '.$csstyle.'>'; $out .= '<tr '.$class.$csstyle.'>';
} }
// Convert date into timestamp format // Convert date into timestamp format
if (in_array($extrafields->attribute_type[$key],array('date','datetime'))) if (in_array($extrafields->attribute_type[$key],array('date','datetime')))

View File

@ -61,6 +61,8 @@ class ExtraFields
var $error; var $error;
var $errno; var $errno;
var $attribute_hidden;
public static $type2label=array( public static $type2label=array(
'varchar'=>'String', 'varchar'=>'String',
'text'=>'TextLong', 'text'=>'TextLong',
@ -98,6 +100,7 @@ class ExtraFields
$this->attribute_required = array(); $this->attribute_required = array();
$this->attribute_perms = array(); $this->attribute_perms = array();
$this->attribute_list = array(); $this->attribute_list = array();
$this->attribute_hidden = array();
} }
/** /**
@ -116,9 +119,10 @@ class ExtraFields
* @param int $alwayseditable Is attribute always editable regardless of the document status * @param int $alwayseditable Is attribute always editable regardless of the document status
* @param string $perms Permission to check * @param string $perms Permission to check
* @param int $list Into list view by default * @param int $list Into list view by default
* @param int $ishidden Is hidden extrafield
* @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) function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0, $default_value='', $param=0, $alwayseditable=0, $perms='', $list=0, $ishidden=0)
{ {
if (empty($attrname)) return -1; if (empty($attrname)) return -1;
if (empty($label)) return -1; if (empty($label)) return -1;
@ -135,7 +139,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); $result2=$this->create_label($attrname,$label,$type,$pos,$size,$elementtype, $unique, $required, $param, $alwayseditable, $perms, $list, $ishidden);
$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'))
{ {
@ -243,9 +247,10 @@ class ExtraFields
* @param int $alwayseditable Is attribute always editable regardless of the document status * @param int $alwayseditable Is attribute always editable regardless of the document status
* @param string $perms Permission to check * @param string $perms Permission to check
* @param int $list Into list view by default * @param int $list Into list view by default
* @param int $ishidden Is hidden extrafield
* @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) 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)
{ {
global $conf; global $conf;
@ -271,7 +276,7 @@ class ExtraFields
$params=''; $params='';
} }
$sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields(name, label, type, pos, size, entity, elementtype, fieldunique, fieldrequired, param, alwayseditable, perms, list)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields(name, label, type, pos, size, entity, elementtype, fieldunique, fieldrequired, param, alwayseditable, perms, list, ishidden)";
$sql.= " VALUES('".$attrname."',"; $sql.= " VALUES('".$attrname."',";
$sql.= " '".$this->db->escape($label)."',"; $sql.= " '".$this->db->escape($label)."',";
$sql.= " '".$type."',"; $sql.= " '".$type."',";
@ -285,6 +290,7 @@ class ExtraFields
$sql.= " '".$alwayseditable."',"; $sql.= " '".$alwayseditable."',";
$sql.= " ".($perms?"'".$this->db->escape($perms)."'":"null").","; $sql.= " ".($perms?"'".$this->db->escape($perms)."'":"null").",";
$sql.= " ".$list; $sql.= " ".$list;
$sql.= ", ".$ishidden;
$sql.=')'; $sql.=')';
dol_syslog(get_class($this)."::create_label", LOG_DEBUG); dol_syslog(get_class($this)."::create_label", LOG_DEBUG);
@ -389,9 +395,10 @@ class ExtraFields
* @param int $alwayseditable Is attribute always editable regardless of the document status * @param int $alwayseditable Is attribute always editable regardless of the document status
* @param string $perms Permission to check * @param string $perms Permission to check
* @param int $list Into list view by default * @param int $list Into list view by default
* @param int $ishidden Is hidden extrafield
* @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='') function update($attrname,$label,$type,$length,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0, $perms='',$list='',$ishidden=0)
{ {
if ($elementtype == 'thirdparty') $elementtype='societe'; if ($elementtype == 'thirdparty') $elementtype='societe';
if ($elementtype == 'contact') $elementtype='socpeople'; if ($elementtype == 'contact') $elementtype='socpeople';
@ -432,7 +439,7 @@ class ExtraFields
{ {
if ($label) if ($label)
{ {
$result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param,$alwayseditable,$perms,$list); $result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param,$alwayseditable,$perms,$list,$ishidden);
} }
if ($result > 0) if ($result > 0)
{ {
@ -483,12 +490,13 @@ class ExtraFields
* @param int $alwayseditable Is attribute always editable regardless of the document status * @param int $alwayseditable Is attribute always editable regardless of the document status
* @param string $perms Permission to check * @param string $perms Permission to check
* @param int $list Into list view by default * @param int $list Into list view by default
* @param int $ishidden Is hidden extrafield
* @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) private function update_label($attrname,$label,$type,$size,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0,$perms='',$list=0,$ishidden=0)
{ {
global $conf; global $conf;
dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list); dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$ishidden);
// Clean parameters // Clean parameters
if ($elementtype == 'thirdparty') $elementtype='societe'; if ($elementtype == 'thirdparty') $elementtype='societe';
@ -526,6 +534,7 @@ class ExtraFields
$sql.= " alwayseditable,"; $sql.= " alwayseditable,";
$sql.= " param,"; $sql.= " param,";
$sql.= " list"; $sql.= " list";
$sql.= ", ishidden";
$sql.= ") VALUES ("; $sql.= ") VALUES (";
$sql.= "'".$attrname."',"; $sql.= "'".$attrname."',";
$sql.= " ".$conf->entity.","; $sql.= " ".$conf->entity.",";
@ -540,6 +549,7 @@ class ExtraFields
$sql.= " '".$alwayseditable."',"; $sql.= " '".$alwayseditable."',";
$sql.= " '".$param."',"; $sql.= " '".$param."',";
$sql.= " ".$list; $sql.= " ".$list;
$sql.= ", ".$ishidden;
$sql.= ")"; $sql.= ")";
dol_syslog(get_class($this)."::update_label", LOG_DEBUG); dol_syslog(get_class($this)."::update_label", LOG_DEBUG);
$resql2=$this->db->query($sql); $resql2=$this->db->query($sql);
@ -585,7 +595,7 @@ class ExtraFields
// For avoid conflicts with external modules // For avoid conflicts with external modules
if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return $array_name_label; if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return $array_name_label;
$sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,list"; $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,list,ishidden";
$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."'";
@ -616,6 +626,7 @@ class ExtraFields
$this->attribute_alwayseditable[$tab->name]=$tab->alwayseditable; $this->attribute_alwayseditable[$tab->name]=$tab->alwayseditable;
$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;
} }
} }
} }

View File

@ -118,6 +118,8 @@
<tr><td><?php echo $langs->trans("Required"); ?></td><td class="valeur"><input id="required" type="checkbox" name="required" <?php echo (GETPOST('required')?' checked':''); ?>></td></tr> <tr><td><?php echo $langs->trans("Required"); ?></td><td class="valeur"><input id="required" type="checkbox" name="required" <?php echo (GETPOST('required')?' checked':''); ?>></td></tr>
<!-- Always editable --> <!-- Always editable -->
<tr><td><?php echo $langs->trans("AlwaysEditable"); ?></td><td class="valeur"><input id="alwayseditable" type="checkbox" name="alwayseditable" <?php echo (GETPOST('alwayseditable')?' checked':''); ?>></td></tr> <tr><td><?php echo $langs->trans("AlwaysEditable"); ?></td><td class="valeur"><input id="alwayseditable" type="checkbox" name="alwayseditable" <?php echo (GETPOST('alwayseditable')?' checked':''); ?>></td></tr>
<!-- Is visible or not -->
<tr><td><?php echo $langs->trans("IsHidden"); ?></td><td class="valeur"><input id="ishidden" type="checkbox" name="ishidden" <?php echo (GETPOST('ishidden') ?' checked':''); ?>></td></tr>
<?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"); ?>

View File

@ -60,6 +60,7 @@ $alwayseditable=$extrafields->attribute_alwayseditable[$attrname];
$param=$extrafields->attribute_param[$attrname]; $param=$extrafields->attribute_param[$attrname];
$perms=$extrafields->attribute_perms[$attrname]; $perms=$extrafields->attribute_perms[$attrname];
$list=$extrafields->attribute_list[$attrname]; $list=$extrafields->attribute_list[$attrname];
$ishidden=$extrafields->attribute_hidden[$attrname];
if((($type == 'select') || ($type == 'checkbox') || ($type == 'radio')) && is_array($param)) if((($type == 'select') || ($type == 'checkbox') || ($type == 'radio')) && is_array($param))
{ {
@ -117,6 +118,8 @@ if(($type == 'select') || ($type == 'sellist') || ($type == 'checkbox') || ($typ
<tr><td><?php echo $langs->trans("Required"); ?></td><td class="valeur"><input id="required" type="checkbox" name="required" <?php echo ($required?' checked':''); ?>></td></tr> <tr><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 --> <!-- Always editable -->
<tr><td><?php echo $langs->trans("AlwaysEditable"); ?></td><td class="valeur"><input id="alwayseditable" type="checkbox" name="alwayseditable" <?php echo ($alwayseditable?' checked':''); ?>></td></tr> <tr><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 -->
<tr><td><?php echo $langs->trans("IsHidden"); ?></td><td class="valeur"><input id="ishidden" type="checkbox" name="ishidden" <?php echo ($ishidden ?' checked':''); ?>></td></tr>
<!-- 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"); ?>

View File

@ -44,6 +44,7 @@ print '<td align="right">'.$langs->trans("Size").'</td>';
print '<td align="center">'.$langs->trans("Unique").'</td>'; print '<td align="center">'.$langs->trans("Unique").'</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>';
print '<td align="center">'.$langs->trans("IsHidden").'</td>';
print '<td width="80">&nbsp;</td>'; print '<td width="80">&nbsp;</td>';
print "</tr>\n"; print "</tr>\n";
@ -60,6 +61,7 @@ foreach($extrafields->attribute_type as $key => $value)
print '<td align="center">'.yn($extrafields->attribute_unique[$key])."</td>\n"; print '<td align="center">'.yn($extrafields->attribute_unique[$key])."</td>\n";
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";
print '<td align="center">'.yn($extrafields->attribute_hidden[$key])."</td>\n";
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 "&nbsp; <a href=\"".$_SERVER["PHP_SELF"]."?action=delete&attrname=$key\">".img_delete()."</a></td>\n"; print "&nbsp; <a href=\"".$_SERVER["PHP_SELF"]."?action=delete&attrname=$key\">".img_delete()."</a></td>\n";
print "</tr>"; print "</tr>";

View File

@ -45,7 +45,8 @@ if (empty($reshook) && ! empty($extrafields->attribute_label))
} }
else else
{ {
print '<tr><td>'; if (!empty($extrafields->attribute_hidden[$key])) print '<tr class="hideobject"><td>';
else print '<tr><td>';
print '<table width="100%" class="nobordernopadding"><tr><td'; print '<table width="100%" class="nobordernopadding"><tr><td';
//var_dump($action);exit; //var_dump($action);exit;
if ((! empty($action) && ($action == 'create' || $action == 'edit')) && ! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"'; if ((! empty($action) && ($action == 'create' || $action == 'edit')) && ! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';

View File

@ -76,7 +76,7 @@ ALTER TABLE llx_website_page ADD UNIQUE INDEX uk_website_page_url (fk_website,pa
ALTER TABLE llx_website_page ADD CONSTRAINT fk_website_page_website FOREIGN KEY (fk_website) REFERENCES llx_website (rowid); ALTER TABLE llx_website_page ADD CONSTRAINT fk_website_page_website FOREIGN KEY (fk_website) REFERENCES llx_website (rowid);
ALTER TABLE llx_extrafields ADD COLUMN ishidden integer DEFAULT 0;

View File

@ -34,4 +34,5 @@ create table llx_extrafields
alwayseditable integer DEFAULT 0, -- 1 if field can be edited whatever is element status alwayseditable integer DEFAULT 0, -- 1 if field can be edited whatever is element status
param text, -- extra parameters to define possible values of field param text, -- extra parameters to define possible values of field
list integer DEFAULT 0 -- list of values for field that are combo lists list integer DEFAULT 0 -- list of values for field that are combo lists
,ishidden integer DEFAULT 0
)ENGINE=innodb; )ENGINE=innodb;

View File

@ -1641,6 +1641,7 @@ CloseFiscalYear=Close fiscal year
DeleteFiscalYear=Delete fiscal year DeleteFiscalYear=Delete fiscal year
ConfirmDeleteFiscalYear=Are you sure to delete this fiscal year ? ConfirmDeleteFiscalYear=Are you sure to delete this fiscal year ?
AlwaysEditable=Can always be edited AlwaysEditable=Can always be edited
IsHidden=Is not visible
MAIN_APPLICATION_TITLE=Force visible name of application (warning: setting your own name here may break autofill login feature when using DoliDroid mobile application) MAIN_APPLICATION_TITLE=Force visible name of application (warning: setting your own name here may break autofill login feature when using DoliDroid mobile application)
NbMajMin=Minimum number of uppercase characters NbMajMin=Minimum number of uppercase characters
NbNumMin=Minimum number of numeric characters NbNumMin=Minimum number of numeric characters