From 0c101f3d1bed33c555035497f852c0fd3773878a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 Mar 2019 11:21:51 +0100 Subject: [PATCH 1/7] Fix translation --- htdocs/user/class/user.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index a5527186ebd..f83d991fccd 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2290,7 +2290,7 @@ class User extends CommonObject if ($infologin > 0) { $label.= '
'; - $label.= '
'.$langs->trans("Connection").''; + $label.= '
'.$langs->trans("Session").''; $label.= '
'.$langs->trans("IPAddress").': '.$_SERVER["REMOTE_ADDR"]; if (! empty($conf->global->MAIN_MODULE_MULTICOMPANY)) $label.= '
'.$langs->trans("ConnectedOnMultiCompany").': '.$conf->entity.' (user entity '.$this->entity.')'; $label.= '
'.$langs->trans("AuthenticationMode").': '.$_SESSION["dol_authmode"].(empty($dolibarr_main_demo)?'':' (demo)'); From 1cf42726ffa9e3a5399dee749aa277cf1e525744 Mon Sep 17 00:00:00 2001 From: ATM-Nicolas Date: Mon, 18 Mar 2019 15:19:39 +0100 Subject: [PATCH 2/7] FIX : Duplicate executeHook function --- htdocs/product/price.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/htdocs/product/price.php b/htdocs/product/price.php index e02ec3f82c7..c636deab22b 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -1277,9 +1277,6 @@ if ($action == 'edit_price' && $object->getRights()->creer) $parameters=array('colspan' => 2); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - $parameters=array('colspan' => 2); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - print ''; dol_fiche_end(); From aa013ff75302c393ac92bd6c3dfcdbdecd28bdf1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 Mar 2019 20:09:09 +0100 Subject: [PATCH 3/7] Fix do we really must copy notes when creating an object from another source object? Add a hack with hidden option to be able to change this. --- htdocs/commande/class/commande.class.php | 8 ++++++-- htdocs/compta/facture/class/facture.class.php | 14 +++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index d8aed383905..b1503f540d8 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1212,8 +1212,12 @@ class Commande extends CommonOrder $this->fk_delivery_address = $object->fk_delivery_address; $this->contact_id = $object->contactid; $this->ref_client = $object->ref_client; - $this->note_private = $object->note_private; - $this->note_public = $object->note_public; + + if (! empty($conf->global->MAIN_DISABLE_PROPAGATE_NOTES_FROM_ORIGIN)) + { + $this->note_private = $object->note_private; + $this->note_public = $object->note_public; + } $this->origin = $object->element; $this->origin_id = $object->id; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 86ee5482261..77f3bd4450a 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1081,7 +1081,7 @@ class Facture extends CommonInvoice */ function createFromOrder($object, User $user) { - global $hookmanager; + global $conf, $hookmanager; $error=0; @@ -1142,8 +1142,12 @@ class Facture extends CommonInvoice $this->fk_delivery_address = $object->fk_delivery_address; $this->contact_id = $object->contactid; $this->ref_client = $object->ref_client; - $this->note_private = $object->note_private; - $this->note_public = $object->note_public; + + if (! empty($conf->global->MAIN_DISABLE_PROPAGATE_NOTES_FROM_ORIGIN)) + { + $this->note_private = $object->note_private; + $this->note_public = $object->note_public; + } $this->origin = $object->element; $this->origin_id = $object->id; @@ -4402,10 +4406,6 @@ class FactureLigne extends CommonInvoiceLine public $date_start; public $date_end; - // Ne plus utiliser - //var $price; // P.U. HT apres remise % de ligne (exemple 80) - //var $remise; // Montant calcule de la remise % sur PU HT (exemple 20) - // From llx_product /** * @deprecated From 41c737a213577e425dd42516c8ba660fa50d1b4e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 Mar 2019 20:16:19 +0100 Subject: [PATCH 4/7] Fix, Oops, test was inverted --- htdocs/commande/class/commande.class.php | 2 +- htdocs/compta/facture/class/facture.class.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index b1503f540d8..f8b10935f83 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1213,7 +1213,7 @@ class Commande extends CommonOrder $this->contact_id = $object->contactid; $this->ref_client = $object->ref_client; - if (! empty($conf->global->MAIN_DISABLE_PROPAGATE_NOTES_FROM_ORIGIN)) + if (empty($conf->global->MAIN_DISABLE_PROPAGATE_NOTES_FROM_ORIGIN)) { $this->note_private = $object->note_private; $this->note_public = $object->note_public; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 77f3bd4450a..62dba82fc54 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1143,7 +1143,7 @@ class Facture extends CommonInvoice $this->contact_id = $object->contactid; $this->ref_client = $object->ref_client; - if (! empty($conf->global->MAIN_DISABLE_PROPAGATE_NOTES_FROM_ORIGIN)) + if (empty($conf->global->MAIN_DISABLE_PROPAGATE_NOTES_FROM_ORIGIN)) { $this->note_private = $object->note_private; $this->note_public = $object->note_public; From 3c1d7bfbf02634e0711a9ce6e5c749199e4725d1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Mar 2019 16:30:40 +0100 Subject: [PATCH 5/7] FIX counter of permissions in badge was wrong --- htdocs/user/class/user.class.php | 1 + htdocs/user/perms.php | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index f83d991fccd..a5a81b48869 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -749,6 +749,7 @@ class User extends CommonObject { dol_syslog(get_class($this)."::clearrights reset user->rights"); $this->rights=''; + $this->nb_rights=0; $this->all_permissions_are_loaded=false; $this->_tab_loaded=array(); } diff --git a/htdocs/user/perms.php b/htdocs/user/perms.php index 17666183319..340b42aa1ac 100644 --- a/htdocs/user/perms.php +++ b/htdocs/user/perms.php @@ -97,6 +97,9 @@ if (empty($reshook)) { $user->getrights(); $menumanager->loadMenu(); } + + $object->clearrights(); + $object->getrights(); } if ($action == 'delrights' && $caneditperms) { @@ -110,6 +113,9 @@ if (empty($reshook)) { $user->getrights(); $menumanager->loadMenu(); } + + $object->clearrights(); + $object->getrights(); } } @@ -266,9 +272,9 @@ if (($caneditperms && empty($objMod->rights_admin_allowed)) || empty($object->ad if ($caneditperms) { print ''; - print ''.$langs->trans("All").""; + print ''.$langs->trans("All").""; print '/'; - print ''.$langs->trans("None").""; + print ''.$langs->trans("None").""; print ''; } print ' '; From 4c85068a85e533e333c45c814c647346cf33aa29 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2019 11:53:04 +0100 Subject: [PATCH 6/7] FIX Can't insert if there is extrafields mandatory on another entity. --- htdocs/core/class/commonobject.class.php | 17 +++++++++++++++-- htdocs/core/class/extrafields.class.php | 16 +++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index d8d27a0378a..77e0a557c5d 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4979,8 +4979,9 @@ abstract class CommonObject $table_element = $this->table_element; if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility + dol_syslog(get_class($this)."::insertExtraFields delete then insert", LOG_DEBUG); + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; - dol_syslog(get_class($this)."::insertExtraFields delete", LOG_DEBUG); $this->db->query($sql_del); $sql = "INSERT INTO ".MAIN_DB_PREFIX.$table_element."_extrafields (fk_object"; @@ -4991,6 +4992,11 @@ abstract class CommonObject if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator $sql.=",".$attributeKey; } + // We must insert a default value for fields for other entities that are mandatory to avoid not null error + foreach($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) + { + $sql.=",".$tmpkey; + } $sql .= ") VALUES (".$this->id; foreach($new_array_options as $key => $value) @@ -5009,10 +5015,17 @@ abstract class CommonObject } } } + // We must insert a default value for fields for other entities that are mandatory to avoid not null error + foreach($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) + { + if (in_array($tmpval, array('int', 'double'))) $sql.=", 0"; + else $sql.=", ''"; + } + $sql.=")"; - dol_syslog(get_class($this)."::insertExtraFields insert", LOG_DEBUG); $resql = $this->db->query($sql); + if (! $resql) { $this->error=$this->db->lasterror(); diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 48eabbefe9e..679352dde06 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -747,7 +747,7 @@ class ExtraFields * @param boolean $forceload Force load of extra fields whatever is option MAIN_EXTRAFIELDS_DISABLED. Deprecated. Should not be required. * @return array Array of attributes keys+label for all extra fields. */ - function fetch_name_optionals_label($elementtype,$forceload=false) + function fetch_name_optionals_label($elementtype, $forceload=false) { global $conf; @@ -783,8 +783,8 @@ class ExtraFields $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,fielddefault,fieldcomputed,entity,enabled"; $sql.= " FROM ".MAIN_DB_PREFIX."extrafields"; - $sql.= " WHERE entity IN (0,".$conf->entity.")"; - if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'"; // Filed with object->table_element + //$sql.= " WHERE entity IN (0,".$conf->entity.")"; // Filter is done later + if ($elementtype) $sql.= " WHERE elementtype = '".$elementtype."'"; // Filed with object->table_element $sql.= " ORDER BY pos"; $resql=$this->db->query($sql); @@ -794,6 +794,16 @@ class ExtraFields { while ($tab = $this->db->fetch_object($resql)) { + if ($tab->entity != 0 && $tab->entity != $conf->entity) + { + // This field is not in current entity. We discard but before we save it into the array of mandatory fields if it is a mandatory field + if ($tab->fieldrequired) + { + $this->attributes[$tab->elementtype]['mandatoryfieldsofotherentities'][$tab->name]=$tab->type; + } + continue; + } + // We can add this attribute to object. TODO Remove this and return $this->attributes[$elementtype]['label'] if ($tab->type != 'separate') { From 032aa869e4124a4bee4752303690ba4090f0f82d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Mar 2019 11:54:14 +0100 Subject: [PATCH 7/7] FIX Can't insert if there is extrafields mandatory on another entity. FIX Can't set default value of extrafield of type varchar --- htdocs/core/class/commonobject.class.php | 16 +++++++++++----- htdocs/core/class/extrafields.class.php | 2 +- htdocs/core/db/mysqli.class.php | 2 +- htdocs/core/db/pgsql.class.php | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 77e0a557c5d..90bd03513fe 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4993,9 +4993,12 @@ abstract class CommonObject $sql.=",".$attributeKey; } // We must insert a default value for fields for other entities that are mandatory to avoid not null error - foreach($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) + if (is_array($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'])) { - $sql.=",".$tmpkey; + foreach($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) + { + $sql.=",".$tmpkey; + } } $sql .= ") VALUES (".$this->id; @@ -5016,10 +5019,13 @@ abstract class CommonObject } } // We must insert a default value for fields for other entities that are mandatory to avoid not null error - foreach($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) + if (is_array($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'])) { - if (in_array($tmpval, array('int', 'double'))) $sql.=", 0"; - else $sql.=", ''"; + foreach($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) + { + if (in_array($tmpval, array('int', 'double'))) $sql.=", 0"; + else $sql.=", ''"; + } } $sql.=")"; diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 679352dde06..6e92509756f 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -797,7 +797,7 @@ class ExtraFields if ($tab->entity != 0 && $tab->entity != $conf->entity) { // This field is not in current entity. We discard but before we save it into the array of mandatory fields if it is a mandatory field - if ($tab->fieldrequired) + if ($tab->fieldrequired && is_null($tab->fielddefault)) { $this->attributes[$tab->elementtype]['mandatoryfieldsofotherentities'][$tab->name]=$tab->type; } diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 23c19542ae6..738be0b2d86 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -835,7 +835,7 @@ class DoliDBMysqli extends DoliDB if ($field_desc['default'] != '') { if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']); - elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields + elseif ($field_desc['type'] != 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields } dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG); diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 3d365142a0a..ffbabc24d79 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -1138,7 +1138,7 @@ class DoliDBPgsql extends DoliDB if ($field_desc['default'] != '') { if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']); - elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields + elseif ($field_desc['type'] != 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields } dol_syslog($sql,LOG_DEBUG);