NEW Can set language on extrafields

This commit is contained in:
Laurent Destailleur 2017-08-27 12:06:46 +02:00
parent f10e89aa9f
commit 3f7eea2e0a
7 changed files with 57 additions and 74 deletions

View File

@ -560,11 +560,7 @@ else
$_GET["id"]=$object->id;
}
/*
* Affichage onglets
*/
// Onglets
// Show tabs
$head=bank_prepare_head($object);
dol_fiche_head($head, 'bankname', $langs->trans("FinancialAccount"), -1, 'account');
@ -592,18 +588,6 @@ else
print '<table class="border" width="100%">';
// Ref
/*
print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td>';
print '<td>';
print $form->showrefnav($object, 'ref', $linkback, 1, 'ref');
print '</td></tr>';*/
// Label
/*print '<tr><td class="titlefield">'.$langs->trans("Label").'</td>';
print '<td>'.$object->label.'</td></tr>';*/
// Type
print '<tr><td class="titlefield">'.$langs->trans("AccountType").'</td>';
print '<td>'.$object->type_lib[$object->type].'</td></tr>';
@ -616,26 +600,6 @@ else
print $langs->trans("Currency".$selectedcode);
print '</td></tr>';
// Status
/*print '<tr><td>'.$langs->trans("Status").'</td>';
print '<td>'.$object->getLibStatut(4).'</td></tr>';*/
// Country
/*
print '<tr><td>'.$langs->trans("BankAccountCountry").'</td><td>';
if ($object->country_id > 0)
{
$img=picto_from_langcode($object->country_code);
print $img?$img.' ':'';
print getCountry($object->getCountryCode(),0,$db);
}
print '</td></tr>';
// State
print '<tr><td>'.$langs->trans('State').'</td><td>';
if ($object->state_id > 0) print getState($object->state_id);
print '</td></tr>';*/
// Conciliate
print '<tr><td>'.$langs->trans("Conciliable").'</td>';
print '<td>';

View File

@ -4565,6 +4565,9 @@ abstract class CommonObject
$e = 0;
foreach($extrafields->attribute_label as $key=>$label)
{
// Load language if required
if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]);
if (is_array($params) && count($params)>0) {
if (array_key_exists('colspan',$params)) {
$colspan=$params['colspan'];

View File

@ -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.

View File

@ -37,10 +37,14 @@ $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object,
print $hookmanager->resPrint;
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
//var_dump($extrafields->attributes);
if (empty($reshook) && ! empty($extrafields->attributes[$object->table_element]['label']))
{
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label)
{
// Load language if required
if (! empty($extrafields->attributes[$object->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$object->table_element]['langfile'][$key]);
if ($action == 'edit_extras')
{
$value = (isset($_POST["options_" . $key]) ? $_POST["options_" . $key] : $object->array_options["options_" . $key]);

View File

@ -25,6 +25,8 @@
-- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup);
ALTER TABLE llx_extrafields MODIFY COLUMN langs varchar(64);
ALTER TABLE llx_facture_fourn ADD COLUMN date_pointoftax date DEFAULT NULL;
ALTER TABLE llx_facture_fourn ADD COLUMN date_valid date;

View File

@ -35,7 +35,7 @@ create table llx_extrafields
alwayseditable integer DEFAULT 0, -- 1 if field can be edited whatever is element status
param text, -- extra parameters to define possible values of field
list integer DEFAULT 0, -- list of values for field that are combo lists
langs varchar(24), -- example: fileofmymodule@mymodule
langs varchar(64), -- example: fileofmymodule@mymodule
ishidden integer DEFAULT 0, -- Can be foreign key of external system
fk_user_author integer, -- user making creation
fk_user_modif integer, -- user making last change

View File

@ -311,11 +311,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');
//$result2=$extrafields->addExtraField('myattr2', "New Attr 2 label", 'varchar', 1, 10, 'project');
//$result3=$extrafields->addExtraField('myattr3', "New Attr 3 label", 'varchar', 1, 10, 'bank_account');
//$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');
//$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');
$sql = array();