diff --git a/htdocs/adherents/cartes/carte.php b/htdocs/adherents/cartes/carte.php
index 59713e20573..2c1db41ed00 100644
--- a/htdocs/adherents/cartes/carte.php
+++ b/htdocs/adherents/cartes/carte.php
@@ -45,6 +45,7 @@ $modellabel=GETPOST("modellabel"); // Doc template to use for address sheet
$mesg='';
$adherentstatic=new Adherent($db);
+$object=new Adherent($db);
$extrafields = new ExtraFields($db);
// fetch optionals attributes and labels
@@ -70,11 +71,11 @@ if ((! empty($foruserid) || ! empty($foruserlogin) || ! empty($mode)) && ! $mesg
$sql.= " t.libelle as type,";
$sql.= " c.code as country_code, c.label as country";
// Add fields from extrafields
- foreach ($extrafields->attribute_label as $key => $val)
- $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
+ if (! empty($extrafields->attributes[$object->table_element]['label']))
+ foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.country = c.rowid";
- if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."adherent_extrafields as ef on (d.rowid = ef.fk_object)";
+ if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."adherent_extrafields as ef on (d.rowid = ef.fk_object)";
$sql.= " WHERE d.fk_adherent_type = t.rowid AND d.statut = 1";
$sql.= " AND d.entity IN (".getEntity('adherent').")";
if (is_numeric($foruserid)) $sql.=" AND d.rowid=".$foruserid;
@@ -98,10 +99,10 @@ if ((! empty($foruserid) || ! empty($foruserlogin) || ! empty($mode)) && ! $mesg
$adherentstatic->firstname=$objp->firstname;
// format extrafiled so they can be parsed in function complete_substitutions_array
- if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
+ if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']))
{
$adherentstatic->array_options = array();
- foreach($extrafields->attribute_label as $key => $val)
+ foreach($extrafields->attributes[$object->table_element]['label'] as $key => $val)
{
$tmpkey='options_'.$key;
if (!empty($objp->$tmpkey))
diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php
index 929dc706042..d942038b0bc 100644
--- a/htdocs/adherents/type.php
+++ b/htdocs/adherents/type.php
@@ -338,7 +338,7 @@ if ($action == 'create')
$parameters=array();
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
- if (empty($reshook) && ! empty($extrafields->attribute_label))
+ if (empty($reshook))
{
print $object->showOptionals($extrafields,'edit');
}
@@ -736,7 +736,7 @@ if ($rowid > 0)
$parameters=array();
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
- if (empty($reshook) && ! empty($extrafields->attribute_label))
+ if (empty($reshook))
{
print $object->showOptionals($extrafields,'edit');
}
@@ -744,7 +744,7 @@ if ($rowid > 0)
print '';
// Extra field
- if (empty($reshook) && ! empty($extrafields->attribute_label))
+ if (empty($reshook))
{
print '
';
foreach($extrafields->attribute_label as $key=>$label)
diff --git a/htdocs/admin/system/perf.php b/htdocs/admin/system/perf.php
index 55584df6445..1e757b72f63 100644
--- a/htdocs/admin/system/perf.php
+++ b/htdocs/admin/system/perf.php
@@ -50,7 +50,7 @@ llxHeader();
print load_fiche_titre($langs->trans("PerfDolibarr"),'','title_setup');
-print $langs->trans("YouMayFindPerfAdviceHere",'http://wiki.dolibarr.org/index.php/FAQ_Increase_Performance').' ('.$langs->trans("Reload").') ';
+print $langs->trans("YouMayFindPerfAdviceHere",'https://wiki.dolibarr.org/index.php/FAQ_Increase_Performance').' ('.$langs->trans("Reload").') ';
// Recupere la version de PHP
$phpversion=version_php();
diff --git a/htdocs/assets/type.php b/htdocs/assets/type.php
index 51445f86254..f9e725acafa 100644
--- a/htdocs/assets/type.php
+++ b/htdocs/assets/type.php
@@ -317,7 +317,7 @@ if ($action == 'create')
$parameters=array();
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
- if (empty($reshook) && ! empty($extrafields->attribute_label))
+ if (empty($reshook))
{
print $object->showOptionals($extrafields,'edit');
}
@@ -715,7 +715,7 @@ if ($rowid > 0)
$parameters=array();
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
- if (empty($reshook) && ! empty($extrafields->attribute_label))
+ if (empty($reshook))
{
print $object->showOptionals($extrafields,'edit');
}
@@ -723,7 +723,7 @@ if ($rowid > 0)
print '
';
// Extra field
- if (empty($reshook) && ! empty($extrafields->attribute_label))
+ if (empty($reshook))
{
print '
';
foreach($extrafields->attribute_label as $key=>$label)
diff --git a/htdocs/categories/card.php b/htdocs/categories/card.php
index 9f49e42f060..60689dd37aa 100644
--- a/htdocs/categories/card.php
+++ b/htdocs/categories/card.php
@@ -268,7 +268,7 @@ if ($user->rights->categorie->creer)
$parameters=array();
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
- if (empty($reshook) && ! empty($extrafields->attribute_label))
+ if (empty($reshook))
{
print $object->showOptionals($extrafields,'edit');
}
diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php
index 4ccd9116d74..67190aee2e2 100644
--- a/htdocs/categories/edit.php
+++ b/htdocs/categories/edit.php
@@ -176,7 +176,7 @@ print '';
$parameters=array();
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
-if (empty($reshook) && ! empty($extrafields->attribute_label))
+if (empty($reshook))
{
print $object->showOptionals($extrafields,'edit');
}
diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php
index d0d97f83435..fb9c5944baf 100644
--- a/htdocs/comm/action/card.php
+++ b/htdocs/comm/action/card.php
@@ -908,7 +908,7 @@ if ($action == 'create')
$parameters=array();
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
- if (empty($reshook) && ! empty($extrafields->attribute_label))
+ if (empty($reshook))
{
print $object->showOptionals($extrafields,'edit');
}
@@ -1260,7 +1260,7 @@ if ($id > 0)
$parameters=array();
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
- if (empty($reshook) && ! empty($extrafields->attribute_label))
+ if (empty($reshook))
{
print $object->showOptionals($extrafields,'edit');
}
diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php
index a8bbb05fb84..5ded0c16b5e 100644
--- a/htdocs/comm/mailing/card.php
+++ b/htdocs/comm/mailing/card.php
@@ -754,7 +754,7 @@ if ($action == 'create')
$parameters=array();
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
- if (empty($reshook) && ! empty($extrafields->attribute_label))
+ if (empty($reshook))
{
print $object->showOptionals($extrafields,'edit');
}
@@ -1235,7 +1235,7 @@ else
$parameters=array();
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
- if (empty($reshook) && ! empty($extrafields->attribute_label))
+ if (empty($reshook))
{
print $object->showOptionals($extrafields,'edit');
}
diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php
index b3757021ee8..76a290a79cd 100644
--- a/htdocs/commande/card.php
+++ b/htdocs/commande/card.php
@@ -1646,7 +1646,7 @@ if ($action == 'create' && $user->rights->commande->creer)
$parameters = array('objectsrc' => $objectsrc, 'socid'=>$socid);
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by
print $hookmanager->resPrint;
- if (empty($reshook) && ! empty($extrafields->attribute_label)) {
+ if (empty($reshook)) {
print $object->showOptionals($extrafields, 'edit');
}
diff --git a/htdocs/commande/orderstoinvoice.php b/htdocs/commande/orderstoinvoice.php
index bebcaa93097..c9acc111dc4 100644
--- a/htdocs/commande/orderstoinvoice.php
+++ b/htdocs/commande/orderstoinvoice.php
@@ -472,7 +472,7 @@ if ($action == 'create' && !$error)
$parameters=array('objectsrc' => $objectsrc, 'idsrc' => $listoforders);
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
- if (empty($reshook) && ! empty($extrafields->attribute_label))
+ if (empty($reshook))
{
$object=new Facture($db);
print $object->showOptionals($extrafields,'edit');
diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php
index 78c5defed30..6a9ce1d2ba1 100644
--- a/htdocs/compta/bank/card.php
+++ b/htdocs/compta/bank/card.php
@@ -413,7 +413,7 @@ if ($action == 'create')
$parameters=array();
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
- if (empty($reshook) && ! empty($extrafields->attribute_label))
+ if (empty($reshook))
{
print $object->showOptionals($extrafields,'edit',$parameters);
}
@@ -914,7 +914,7 @@ else
$parameters=array();
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
- if (empty($reshook) && ! empty($extrafields->attribute_label))
+ if (empty($reshook))
{
print $object->showOptionals($extrafields,'edit');
}
diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php
index 044ca7da392..ec14ec3da14 100644
--- a/htdocs/compta/facture/card.php
+++ b/htdocs/compta/facture/card.php
@@ -2857,7 +2857,7 @@ if ($action == 'create')
$parameters = array('objectsrc' => $objectsrc,'colspan' => ' colspan="2"', 'cols'=>2);
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
- if (empty($reshook) && ! empty($extrafields->attribute_label)) {
+ if (empty($reshook)) {
print $object->showOptionals($extrafields, 'edit');
}
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 343bbbe6414..a06c1ccfa20 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -2730,14 +2730,15 @@ class Facture extends CommonInvoice
// Mise a jour informations denormalisees au niveau de la facture meme
$result=$this->update_price(1,'auto',0,$mysoc); // The addline method is designed to add line from user input so total calculation with update_price must be done using 'auto' mode.
+
if ($result > 0)
{
$this->db->commit();
- return $this->line->rowid;
+ return $this->line->id;
}
else
{
- $this->error=$this->db->error();
+ $this->error=$this->db->lasterror();
$this->db->rollback();
return -1;
}
@@ -4482,11 +4483,11 @@ class FactureLigne extends CommonInvoiceLine
$resql=$this->db->query($sql);
if ($resql)
{
- $this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'facturedet');
+ $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX.'facturedet');
+ $this->rowid=$this->id; // For backward compatibility
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
- $this->id=$this->rowid;
$result=$this->insertExtraFields();
if ($result < 0)
{
@@ -4558,12 +4559,12 @@ class FactureLigne extends CommonInvoiceLine
}
$this->db->commit();
- return $this->rowid;
+ return $this->id;
}
else
{
- $this->error=$this->db->error();
+ $this->error=$this->db->lasterror();
$this->db->rollback();
return -2;
}
diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php
index 713cab1dc13..e04f4d83ee8 100644
--- a/htdocs/compta/tva/quadri_detail.php
+++ b/htdocs/compta/tva/quadri_detail.php
@@ -369,7 +369,8 @@ if (! is_array($x_coll) || ! is_array($x_paye))
foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
// Define type
- $type=($fields['dtype']?$fields['dtype']:$fields['ptype']);
+ // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
+ $type=(isset($fields['dtype'])?$fields['dtype']:$fields['ptype']);
// Try to enhance type detection using date_start and date_end for free lines where type
// was not saved.
if (!empty($fields['ddate_start'])) {
@@ -401,10 +402,10 @@ if (! is_array($x_coll) || ! is_array($x_paye))
{
$product_static->id=$fields['pid'];
$product_static->ref=$fields['pref'];
- $product_static->type=$fields['ptype'];
+ $product_static->type=$fields['dtype']; // We force with the type of line to have type how line is registered
print $product_static->getNomUrl(1);
if (dol_string_nohtmltag($fields['descr'])) {
- print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
+ print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),24);
}
}
else
@@ -423,7 +424,7 @@ if (! is_array($x_coll) || ! is_array($x_paye))
$fields['descr']=$langs->transnoentitiesnoconv($reg[1]);
}
}
- print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
+ print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),24);
// Show range
print_date_range($fields['ddate_start'],$fields['ddate_end']);
@@ -550,7 +551,8 @@ if (! is_array($x_coll) || ! is_array($x_paye))
foreach ($x_both[$rate]['paye']['detail'] as $index=>$fields) {
// Define type
- $type=($fields['dtype']?$fields['dtype']:$fields['ptype']);
+ // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
+ $type=(isset($fields['dtype'])?$fields['dtype']:$fields['ptype']);
// Try to enhance type detection using date_start and date_end for free lines where type
// was not saved.
if (!empty($fields['ddate_start'])) {
@@ -582,10 +584,10 @@ if (! is_array($x_coll) || ! is_array($x_paye))
{
$product_static->id=$fields['pid'];
$product_static->ref=$fields['pref'];
- $product_static->type=$fields['ptype'];
+ $product_static->type=$fields['dtype']; // We force with the type of line to have type how line is registered
print $product_static->getNomUrl(1);
if (dol_string_nohtmltag($fields['descr'])) {
- print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
+ print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),24);
}
}
else
@@ -595,7 +597,16 @@ if (! is_array($x_coll) || ! is_array($x_paye))
} else {
$text = img_object($langs->trans('Product'),'product');
}
- print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
+ if (preg_match('/^\((.*)\)$/',$fields['descr'],$reg)) {
+ if ($reg[1]=='DEPOSIT') {
+ $fields['descr']=$langs->transnoentitiesnoconv('Deposit');
+ } elseif ($reg[1]=='CREDIT_NOTE') {
+ $fields['descr']=$langs->transnoentitiesnoconv('CreditNote');
+ } else {
+ $fields['descr']=$langs->transnoentitiesnoconv($reg[1]);
+ }
+ }
+ print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),24);
// Show range
print_date_range($fields['ddate_start'],$fields['ddate_end']);
diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php
index 560acabaee9..bb67f0f183d 100644
--- a/htdocs/contact/card.php
+++ b/htdocs/contact/card.php
@@ -686,7 +686,7 @@ else
$parameters=array('socid' => $socid, 'objsoc' => $objsoc, 'colspan' => ' colspan="3"', 'cols' => 3);
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
- if (empty($reshook) && ! empty($extrafields->attribute_label))
+ if (empty($reshook))
{
print $object->showOptionals($extrafields,'edit');
}
@@ -963,7 +963,7 @@ else
$parameters=array('colspan' => ' colspan="3"', 'cols'=>3);
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
- if (empty($reshook) && ! empty($extrafields->attribute_label))
+ if (empty($reshook))
{
print $object->showOptionals($extrafields,'edit');
}
diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php
index 41cf0c12f3e..17beae4be46 100644
--- a/htdocs/contrat/card.php
+++ b/htdocs/contrat/card.php
@@ -1287,7 +1287,7 @@ if ($action == 'create')
print $hookmanager->resPrint;
// Other attributes
- if (empty($reshook) && ! empty($extrafields->attribute_label)) {
+ if (empty($reshook)) {
print $object->showOptionals($extrafields, 'edit');
}
diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php
index 3e045140cb5..ff723866b74 100644
--- a/htdocs/core/actions_addupdatedelete.inc.php
+++ b/htdocs/core/actions_addupdatedelete.inc.php
@@ -153,7 +153,7 @@ if ($action == "update_extras" && ! empty($permissiontoadd))
$attributekeylong = 'options_'.$attributekey;
$object->array_options['options_'.$attributekey] = GETPOST($attributekeylong,' alpha');
- $result = $object->updateExtraField($attributekey, empty($triggermodname)?'':$triggermodname, $user);
+ $result = $object->insertExtraFields(empty($triggermodname)?'':$triggermodname, $user);
if ($result > 0)
{
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 8e92715cf76..d662fa98820 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -4903,14 +4903,14 @@ abstract class CommonObject
}
/**
- * Update an exta field value for the current object.
+ * Update an extra field value for the current object.
* Data to describe values to update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...)
*
* @param string $key Key of the extrafield (without starting 'options_')
* @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY)
* @param User $userused Object user
* @return int -1=error, O=did nothing, 1=OK
- * @see setValueFrom
+ * @see setValueFrom, insertExtraFields
*/
function updateExtraField($key, $trigger, $userused)
{
@@ -5054,7 +5054,6 @@ abstract class CommonObject
if (is_array($val['arrayofkeyval'])) $type='select';
if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link';
- //$elementtype=$this->attribute_elementtype[$key]; // seems to not be used
$default=$val['default'];
$computed=$val['computed'];
$unique=$val['unique'];
@@ -5597,7 +5596,6 @@ abstract class CommonObject
if (is_array($val['arrayofkeyval'])) $type='select';
if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link';
- //$elementtype=$this->attribute_elementtype[$key]; // seems to not be used
$default=$val['default'];
$computed=$val['computed'];
$unique=$val['unique'];
@@ -5996,7 +5994,7 @@ abstract class CommonObject
if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate')
{
- $out .= $extrafields->showSeparator($key);
+ $out .= $extrafields->showSeparator($key, $this);
}
else
{
diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php
index 09b73ab03c3..c6dab1241f8 100644
--- a/htdocs/core/class/extrafields.class.php
+++ b/htdocs/core/class/extrafields.class.php
@@ -1384,7 +1384,6 @@ class ExtraFields
if (! empty($extrafieldsobjectkey))
{
- $elementtype=$this->attributes[$extrafieldsobjectkey]['elementtype'][$key]; // seems not used
$label=$this->attributes[$extrafieldsobjectkey]['label'][$key];
$type=$this->attributes[$extrafieldsobjectkey]['type'][$key];
$size=$this->attributes[$extrafieldsobjectkey]['size'][$key];
@@ -1400,7 +1399,6 @@ class ExtraFields
}
else // Old usage
{
- $elementtype=$this->attribute_elementtype[$key]; // seems not used
$label=$this->attribute_label[$key];
$type=$this->attribute_type[$key];
$size=$this->attribute_size[$key];
@@ -1743,11 +1741,16 @@ class ExtraFields
* Return HTML string to print separator extrafield
*
* @param string $key Key of attribute
- * @return string
+ * @param string $object Object
+ * @return string HTML code with line for separator
*/
- function showSeparator($key)
+ function showSeparator($key, $object)
{
- $out = '