From a3fa8b82fa861afc023ceda406cd2edb37a2bb27 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Thu, 9 Nov 2023 17:04:13 +0100 Subject: [PATCH 01/49] FIX: more correctly parse the select part to be replaced in sql queries --- htdocs/comm/action/list.php | 2 +- htdocs/compta/facture/list.php | 4 ++-- htdocs/modulebuilder/template/myobject_list.php | 2 +- htdocs/product/stock/movement_list.php | 2 +- htdocs/product/stock/productlot_list.php | 2 +- htdocs/ticket/list.php | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/htdocs/comm/action/list.php b/htdocs/comm/action/list.php index e2b412e15db..74055477e78 100644 --- a/htdocs/comm/action/list.php +++ b/htdocs/comm/action/list.php @@ -563,7 +563,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords++; }*/ /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),=<>\:\-\'\+\*\/"`]+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $resql = $db->query($sqlforcount); $objforcount = $db->fetch_object($resql); $nbtotalofrecords = $objforcount->nbtotalofrecords; diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index da2599dcee2..e2ec217e4a8 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -851,9 +851,9 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { */ /* The fast and low memory method to get and count full list converts the sql into a sql count */ if ($sall || $search_product_category > 0 || $search_user > 0) { - $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(DISTINCT f.rowid) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),=<>\:\-\'\+\*\/"`]+\sFROM/Ui', 'SELECT COUNT(DISTINCT f.rowid) as nbtotalofrecords FROM', $sql); } else { - $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(f.rowid) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),=<>\:\-\'\+\*\/"`]+\sFROM/Ui', 'SELECT COUNT(f.rowid) as nbtotalofrecords FROM', $sql); $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid/', '', $sqlforcount); } $sqlforcount = preg_replace('/GROUP BY.*$/', '', $sqlforcount); diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 5d4ae896134..aba2e44976f 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -369,7 +369,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords++; }*/ /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),=<>\:\-\'\+\*\/"`]+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $resql = $db->query($sqlforcount); $objforcount = $db->fetch_object($resql); $nbtotalofrecords = $objforcount->nbtotalofrecords; diff --git a/htdocs/product/stock/movement_list.php b/htdocs/product/stock/movement_list.php index f5d74c47c8e..b230dba10b0 100644 --- a/htdocs/product/stock/movement_list.php +++ b/htdocs/product/stock/movement_list.php @@ -585,7 +585,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords++; }*/ /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),=<>\:\-\'\+\*\/"`]+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $resql = $db->query($sqlforcount); $objforcount = $db->fetch_object($resql); $nbtotalofrecords = $objforcount->nbtotalofrecords; diff --git a/htdocs/product/stock/productlot_list.php b/htdocs/product/stock/productlot_list.php index 74abbad9140..6df36351c53 100644 --- a/htdocs/product/stock/productlot_list.php +++ b/htdocs/product/stock/productlot_list.php @@ -294,7 +294,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords++; }*/ /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),=<>\:\-\'\+\*\/"`]+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $resql = $db->query($sqlforcount); $objforcount = $db->fetch_object($resql); $nbtotalofrecords = $objforcount->nbtotalofrecords; diff --git a/htdocs/ticket/list.php b/htdocs/ticket/list.php index d80d44813e0..fe7987f85b3 100644 --- a/htdocs/ticket/list.php +++ b/htdocs/ticket/list.php @@ -454,7 +454,7 @@ $sql .= $hookmanager->resPrint; $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),=<>\:\-\'\+\*\/"`]+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $resql = $db->query($sqlforcount); $objforcount = $db->fetch_object($resql); $nbtotalofrecords = $objforcount->nbtotalofrecords; From 786ea1029ed07170c3a360f7fc1a7796532282a0 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Sat, 18 Nov 2023 12:40:10 +0100 Subject: [PATCH 02/49] FIX: more correctly parse the select part to be replaced in sql queries, part 2 --- htdocs/comm/action/list.php | 23 ++++++++++++------ htdocs/compta/facture/list.php | 24 ++++++++++++------- .../modulebuilder/template/myobject_list.php | 23 ++++++++++++------ htdocs/product/stock/movement_list.php | 23 ++++++++++++------ htdocs/product/stock/productlot_list.php | 23 ++++++++++++------ htdocs/ticket/list.php | 23 ++++++++++++------ 6 files changed, 96 insertions(+), 43 deletions(-) diff --git a/htdocs/comm/action/list.php b/htdocs/comm/action/list.php index 74055477e78..1482412e3cd 100644 --- a/htdocs/comm/action/list.php +++ b/htdocs/comm/action/list.php @@ -417,6 +417,8 @@ $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; +$sqlfields = $sql; + $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."actioncomm_extrafields as ef ON (a.id = ef.fk_object)"; if (empty($user->rights->societe->client->voir) && !$socid) { @@ -563,15 +565,22 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords++; }*/ /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),=<>\:\-\'\+\*\/"`]+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql); + $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); + $resql = $db->query($sqlforcount); - $objforcount = $db->fetch_object($resql); - $nbtotalofrecords = $objforcount->nbtotalofrecords; - if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 - $page = 0; - $offset = 0; + + if (!$resql) { + dol_print_error($db); + } else { + $objforcount = $db->fetch_object($resql); + $nbtotalofrecords = $objforcount->nbtotalofrecords; + if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 + $page = 0; + $offset = 0; + } + $db->free($resql); } - $db->free($resql); } // Complete request and execute it with limit diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index e2ec217e4a8..3a814081554 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -586,6 +586,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) { $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; + +$sqlfields = $sql; + $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s'; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)"; @@ -851,22 +854,27 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { */ /* The fast and low memory method to get and count full list converts the sql into a sql count */ if ($sall || $search_product_category > 0 || $search_user > 0) { - $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),=<>\:\-\'\+\*\/"`]+\sFROM/Ui', 'SELECT COUNT(DISTINCT f.rowid) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(DISTINCT f.rowid) as nbtotalofrecords', $sql); } else { - $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),=<>\:\-\'\+\*\/"`]+\sFROM/Ui', 'SELECT COUNT(f.rowid) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT( f.rowid) as nbtotalofrecords', $sql); $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid/', '', $sqlforcount); } $sqlforcount = preg_replace('/GROUP BY.*$/', '', $sqlforcount); $resql = $db->query($sqlforcount); - $objforcount = $db->fetch_object($resql); - $nbtotalofrecords = $objforcount->nbtotalofrecords; - if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0 - $page = 0; - $offset = 0; + if (! $resql) { + dol_print_error($db); + } else { + $objforcount = $db->fetch_object($resql); + $nbtotalofrecords = $objforcount->nbtotalofrecords; + + if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0 + $page = 0; + $offset = 0; + } + $db->free($resql); } - $db->free($resql); } $sql .= $db->plimit($limit + 1, $offset); diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index aba2e44976f..a2ae5eab08c 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -278,6 +278,9 @@ $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook $sql .= preg_replace('/^,/', '', $hookmanager->resPrint); $sql = preg_replace('/,\s*$/', '', $sql); + +$sqlfields = $sql; + $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t"; if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)"; @@ -369,15 +372,21 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords++; }*/ /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),=<>\:\-\'\+\*\/"`]+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql); + $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); $resql = $db->query($sqlforcount); - $objforcount = $db->fetch_object($resql); - $nbtotalofrecords = $objforcount->nbtotalofrecords; - if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0 - $page = 0; - $offset = 0; + + if (!$resql) { + dol_print_error($db); + } else { + $objforcount = $db->fetch_object($resql); + $nbtotalofrecords = $objforcount->nbtotalofrecords; + if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0 + $page = 0; + $offset = 0; + } + $db->free($resql); } - $db->free($resql); } // Complete request and execute it with limit diff --git a/htdocs/product/stock/movement_list.php b/htdocs/product/stock/movement_list.php index b230dba10b0..2534b381655 100644 --- a/htdocs/product/stock/movement_list.php +++ b/htdocs/product/stock/movement_list.php @@ -500,6 +500,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) { $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; + +$sqlfields = $sql; + $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e,"; $sql .= " ".MAIN_DB_PREFIX."product as p,"; $sql .= " ".MAIN_DB_PREFIX."stock_mouvement as m"; @@ -585,15 +588,21 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords++; }*/ /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),=<>\:\-\'\+\*\/"`]+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql); + $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); $resql = $db->query($sqlforcount); - $objforcount = $db->fetch_object($resql); - $nbtotalofrecords = $objforcount->nbtotalofrecords; - if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 - $page = 0; - $offset = 0; + + if (! $resql) { + dol_print_error($db); + } else { + $objforcount = $db->fetch_object($resql); + $nbtotalofrecords = $objforcount->nbtotalofrecords; + if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 + $page = 0; + $offset = 0; + } + $db->free($resql); } - $db->free($resql); } $sql .= $db->order($sortfield, $sortorder); diff --git a/htdocs/product/stock/productlot_list.php b/htdocs/product/stock/productlot_list.php index 6df36351c53..d40feaa4436 100644 --- a/htdocs/product/stock/productlot_list.php +++ b/htdocs/product/stock/productlot_list.php @@ -215,6 +215,9 @@ $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook $sql .= preg_replace('/^,/', '', $hookmanager->resPrint); $sql = preg_replace('/,\s*$/', '', $sql); + +$sqlfields = $sql; + $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t"; if ( !empty($extrafields->attributes[$object->table_element]['label']) && ($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)"; @@ -294,15 +297,21 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords++; }*/ /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),=<>\:\-\'\+\*\/"`]+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql); + $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); $resql = $db->query($sqlforcount); - $objforcount = $db->fetch_object($resql); - $nbtotalofrecords = $objforcount->nbtotalofrecords; - if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0 - $page = 0; - $offset = 0; + + if (!$resql) { + dol_print_error($db); + } else { + $objforcount = $db->fetch_object($resql); + $nbtotalofrecords = $objforcount->nbtotalofrecords; + if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0 + $page = 0; + $offset = 0; + } + $db->free($resql); } - $db->free($resql); } // Complete request and execute it with limit diff --git a/htdocs/ticket/list.php b/htdocs/ticket/list.php index fe7987f85b3..8bd759928ae 100644 --- a/htdocs/ticket/list.php +++ b/htdocs/ticket/list.php @@ -355,6 +355,9 @@ $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook $sql .= preg_replace('/^,/', '', $hookmanager->resPrint); $sql = preg_replace('/,\s*$/', '', $sql); + +$sqlfields = $sql; + $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t"; if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)"; @@ -454,15 +457,21 @@ $sql .= $hookmanager->resPrint; $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { /* The fast and low memory method to get and count full list converts the sql into a sql count */ - $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),=<>\:\-\'\+\*\/"`]+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql); + $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); $resql = $db->query($sqlforcount); - $objforcount = $db->fetch_object($resql); - $nbtotalofrecords = $objforcount->nbtotalofrecords; - if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0 - $page = 0; - $offset = 0; + + if (! $resql) { + dol_print_error($db); + } else { + $objforcount = $db->fetch_object($resql); + $nbtotalofrecords = $objforcount->nbtotalofrecords; + if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0 + $page = 0; + $offset = 0; + } + $db->free($resql); } - $db->free($resql); } // Complete request and execute it with limit From 9a151ebe2cf52bb03779ec396d80505f8bd18680 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Tue, 5 Dec 2023 08:19:28 +0100 Subject: [PATCH 03/49] FIX v18 SQL error in llx_c_forme_juridique.sql when installing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit insert into llx_c_forme_juridique (fk_pays, code, libelle) values (0, ‹ 0 ›,‹ - ›); And insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,‹ 00 ›,‹ Organisme de placement collectif en valeurs mobilières sans personnalité morale ›); throws an error as the column 'code' is integer not varchar and value must be unique see : https://www.dolibarr.fr/forum/t/nouvelle-instalation-forme-juridiques-des-tiers-pratiquement-vide/44489/4 --- htdocs/install/mysql/data/llx_c_forme_juridique.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/mysql/data/llx_c_forme_juridique.sql b/htdocs/install/mysql/data/llx_c_forme_juridique.sql index 93dfa941189..9ba7bdc6fb7 100644 --- a/htdocs/install/mysql/data/llx_c_forme_juridique.sql +++ b/htdocs/install/mysql/data/llx_c_forme_juridique.sql @@ -110,7 +110,7 @@ insert into llx_c_forme_juridique (fk_pays, code, libelle) values (2, '229', 'VS -- France: Catégories niveau II - Extrait de https://www.insee.fr/fr/information/2028129 - Dernière mise à jour Septembre 2022 -insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'00','Organisme de placement collectif en valeurs mobilières sans personnalité morale'); +insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'09','Organisme de placement collectif en valeurs mobilières sans personnalité morale'); insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'10','Entrepreneur individuel'); insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'21','Indivision'); insert into llx_c_forme_juridique (fk_pays, code, libelle) values (1,'22','Société créée de fait'); From 5601fab14f9d3f98cb76b47ea4f1d83da143008a Mon Sep 17 00:00:00 2001 From: Eric Seigne Date: Tue, 5 Dec 2023 10:41:02 +0100 Subject: [PATCH 04/49] fix sql error in case of balance is empty --- htdocs/compta/bank/class/account.class.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 70f03bc21c8..752de8f077b 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -650,6 +650,14 @@ class Account extends CommonObject return -1; } + $balance = $this->balance; + if (empty($balance) && !empty($this->solde)) { + $balance = $this->solde; + } + if (empty($balance)) { + $balance = 0; + } + // Chargement librairie pour acces fonction controle RIB require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; @@ -721,7 +729,7 @@ class Account extends CommonObject $accline = new AccountLine($this->db); $accline->datec = $this->db->idate($now); $accline->label = '('.$langs->trans("InitialBankBalance").')'; - $accline->amount = price2num($this->solde); + $accline->amount = price2num($balance); $accline->fk_user_author = $user->id; $accline->fk_account = $this->id; $accline->datev = $this->db->idate($this->date_solde); From b53420e64e9846480eb035370981e166fb8d8cd3 Mon Sep 17 00:00:00 2001 From: William Mead Date: Wed, 6 Dec 2023 15:17:29 +0100 Subject: [PATCH 05/49] Refactored & adjusted page head width --- .../supplier_order/doc/pdf_cornas.modules.php | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php b/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php index 0d2a2f902da..c5d858c9f9e 100644 --- a/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php +++ b/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php @@ -1252,7 +1252,9 @@ class pdf_cornas extends ModelePDFSuppliersOrders $pdf->SetTextColor(0, 0, 60); $pdf->SetFont('', 'B', $default_font_size + 3); - $posx = $this->page_largeur - $this->marge_droite - 100; + $w = 110; + + $posx = $this->page_largeur - $this->marge_droite - $w; $posy = $this->marge_haute; $pdf->SetXY($this->marge_gauche, $posy); @@ -1275,12 +1277,12 @@ class pdf_cornas extends ModelePDFSuppliersOrders } else { $pdf->SetTextColor(200, 0, 0); $pdf->SetFont('', 'B', $default_font_size - 2); - $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L'); - $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L'); + $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L'); + $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L'); } } else { $text = $this->emetteur->name; - $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection); + $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection); } } @@ -1288,7 +1290,7 @@ class pdf_cornas extends ModelePDFSuppliersOrders $pdf->SetXY($posx, $posy); $pdf->SetTextColor(0, 0, 60); $title = $outputlangs->transnoentities("SupplierOrder")." ".$outputlangs->convToOutputCharset($object->ref); - $pdf->MultiCell(100, 3, $title, '', 'R'); + $pdf->MultiCell($w, 3, $title, '', 'R'); $posy += 1; if ($object->ref_supplier) { @@ -1296,7 +1298,7 @@ class pdf_cornas extends ModelePDFSuppliersOrders $pdf->SetFont('', 'B', $default_font_size); $pdf->SetXY($posx, $posy); $pdf->SetTextColor(0, 0, 60); - $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefSupplier")." : ".$outputlangs->convToOutputCharset($object->ref_supplier), '', 'R'); + $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefSupplier")." : ".$outputlangs->convToOutputCharset($object->ref_supplier), '', 'R'); $posy += 1; } @@ -1320,7 +1322,7 @@ class pdf_cornas extends ModelePDFSuppliersOrders $pdf->SetXY($posx, $posy); $langs->load("projects"); $pdf->SetTextColor(0, 0, 60); - $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R'); + $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R'); } } @@ -1328,12 +1330,12 @@ class pdf_cornas extends ModelePDFSuppliersOrders $posy += 5; $pdf->SetXY($posx, $posy); $pdf->SetTextColor(0, 0, 60); - $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($object->date_commande, "day", false, $outputlangs, true), '', 'R'); + $pdf->MultiCell($w, 3, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($object->date_commande, "day", false, $outputlangs, true), '', 'R'); } else { $posy += 5; $pdf->SetXY($posx, $posy); $pdf->SetTextColor(255, 0, 0); - $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderToProcess"), '', 'R'); + $pdf->MultiCell($w, 3, $outputlangs->transnoentities("OrderToProcess"), '', 'R'); } $pdf->SetTextColor(0, 0, 60); @@ -1351,7 +1353,7 @@ class pdf_cornas extends ModelePDFSuppliersOrders $posy += 4; $pdf->SetXY($posx, $posy); $pdf->SetTextColor(0, 0, 60); - $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R'); + $pdf->MultiCell($w, 3, $outputlangs->transnoentities("SupplierCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R'); } // Get contact @@ -1363,7 +1365,7 @@ class pdf_cornas extends ModelePDFSuppliersOrders $posy += 4; $pdf->SetXY($posx, $posy); $pdf->SetTextColor(0, 0, 60); - $pdf->MultiCell(100, 3, $langs->trans("BuyerName")." : ".$usertmp->getFullName($langs), '', 'R'); + $pdf->MultiCell($w, 3, $langs->trans("BuyerName")." : ".$usertmp->getFullName($langs), '', 'R'); } } From f74073f1a3baed7558038b48c43414a40917cca4 Mon Sep 17 00:00:00 2001 From: William Mead Date: Wed, 6 Dec 2023 15:18:25 +0100 Subject: [PATCH 06/49] Added contributor details --- htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php b/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php index c5d858c9f9e..81bcc4d824c 100644 --- a/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php +++ b/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php @@ -6,6 +6,7 @@ * Copyright (C) 2015 Marcos García * Copyright (C) 2017 Ferran Marcet * Copyright (C) 2018-2022 Frédéric France + * Copyright (C) 2023 William Mead * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by From bcdb567dd75a592483df6965481cdc5b86aef222 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 6 Dec 2023 16:47:44 +0100 Subject: [PATCH 07/49] Fix PHP7.0 incompatibility (void is introduced in 7.1) --- htdocs/bom/class/api_boms.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/bom/class/api_boms.class.php b/htdocs/bom/class/api_boms.class.php index 52e6fe90501..2147f7be1ba 100644 --- a/htdocs/bom/class/api_boms.class.php +++ b/htdocs/bom/class/api_boms.class.php @@ -546,7 +546,7 @@ class Boms extends DolibarrApi * * @return void */ - private function checkRefNumbering(): void + private function checkRefNumbering() { $ref = substr($this->bom->ref, 1, 4); if ($this->bom->status > 0 && $ref == 'PROV') { From 5ced139e3b97679b71db95913b6c298535aad077 Mon Sep 17 00:00:00 2001 From: atm-florian Date: Wed, 6 Dec 2023 17:51:43 +0100 Subject: [PATCH 08/49] FIX: $this->newref already exists and could have been modified by trigger but we still use a local variable for the filesystem-based renaming --- htdocs/fourn/class/fournisseur.facture.class.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index b60dc531325..75874fbb86a 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1872,19 +1872,18 @@ class FactureFournisseur extends CommonInvoice // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); - $newref = dol_sanitizeFileName($num); $dirsource = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$oldref; - $dirdest = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$newref; + $dirdest = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$this->newref; if (!$error && file_exists($dirsource)) { dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest); if (@rename($dirsource, $dirdest)) { dol_syslog("Rename ok"); - // Rename docs starting with $oldref with $newref - $listoffiles = dol_dir_list($conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$newref, 'files', 1, '^'.preg_quote($oldref, '/')); + // Rename docs starting with $oldref with $this->newref + $listoffiles = dol_dir_list($conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$this->newref, 'files', 1, '^'.preg_quote($oldref, '/')); foreach ($listoffiles as $fileentry) { $dirsource = $fileentry['name']; - $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); + $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $this->newref, $dirsource); $dirsource = $fileentry['path'].'/'.$dirsource; $dirdest = $fileentry['path'].'/'.$dirdest; @rename($dirsource, $dirdest); From c10c419bf6a6e77691301c2f7499a046bbfb6680 Mon Sep 17 00:00:00 2001 From: Joachim Kueter Date: Thu, 7 Dec 2023 09:08:33 +0100 Subject: [PATCH 09/49] fix output --- htdocs/bom/tpl/linkedobjectblock.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/bom/tpl/linkedobjectblock.tpl.php b/htdocs/bom/tpl/linkedobjectblock.tpl.php index 1765e9a84c1..a5fcfe30acb 100644 --- a/htdocs/bom/tpl/linkedobjectblock.tpl.php +++ b/htdocs/bom/tpl/linkedobjectblock.tpl.php @@ -62,7 +62,7 @@ foreach ($linkedObjectBlock as $key => $objectlink) { $product_static->getNomUrl(1); } print ''; - echo ''.dol_print_date($objectlink->date_creation, 'day').''; + echo ''.dol_print_date($objectlink->date_creation, 'day').''; echo ''; if ($user->rights->commande->lire) { $total = $total + $objectlink->total_ht; From ea7afeb00735b959d0e6fc1493afa20d7b17f2b1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 7 Dec 2023 16:16:22 +0100 Subject: [PATCH 10/49] Fix warning --- htdocs/compta/bank/class/account.class.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 70f03bc21c8..cf5cabdddf3 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -219,6 +219,20 @@ class Account extends CommonObject */ public $date_solde; + /** + * Balance. Used in Account::create + * @var float + * @deprecated + * @see $balance + */ + public $solde; + + /** + * Balance. Used in Account::create + * @var float + */ + public $balance; + /** * Creditor Identifier CI. Some banks use different ICS for direct debit and bank tranfer * @var string From 9aa1b32c07c0b933eecee950e66dbbebfdcb18dd Mon Sep 17 00:00:00 2001 From: tnegre Date: Mon, 11 Dec 2023 09:52:40 +0100 Subject: [PATCH 11/49] Manage ref_alias for fetch societe --- htdocs/societe/class/societe.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index c61d61b922d..fed0a7a4af0 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1729,7 +1729,7 @@ class Societe extends CommonObject global $langs; global $conf; - if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($barcode) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) { + if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($barcode) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email) && empty($ref_alias)) { return -1; } From 77a22ea78ef96418c0493632c7a37540f674bd25 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 12 Dec 2023 15:01:23 +0100 Subject: [PATCH 12/49] Fix table was renamed --- dev/initdata/purge-data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/initdata/purge-data.php b/dev/initdata/purge-data.php index d75c9fae8b2..a10ecad1a65 100755 --- a/dev/initdata/purge-data.php +++ b/dev/initdata/purge-data.php @@ -149,7 +149,7 @@ $sqls=array( ), 'project'=>array( // TODO set fk_project to null on object that refer to project - "DELETE FROM ".MAIN_DB_PREFIX."projet_task_time WHERE fk_task IN (select rowid FROM ".MAIN_DB_PREFIX."projet_task WHERE fk_projet IN (select rowid FROM ".MAIN_DB_PREFIX."projet where datec < '__DATE__'))", + "DELETE FROM ".MAIN_DB_PREFIX."llx_element_time WHERE elementtype = 'task' AND fk_element IN (select rowid FROM ".MAIN_DB_PREFIX."projet_task WHERE fk_projet IN (select rowid FROM ".MAIN_DB_PREFIX."projet where datec < '__DATE__'))", "DELETE FROM ".MAIN_DB_PREFIX."projet_task WHERE fk_projet IN (select rowid FROM ".MAIN_DB_PREFIX."projet where datec < '__DATE__')", "DELETE FROM ".MAIN_DB_PREFIX."projet where datec < '__DATE__'", ), From 2c23b8db036b87e5813ab9070b691da9bf879147 Mon Sep 17 00:00:00 2001 From: Jonathan Lescaut Date: Tue, 12 Dec 2023 15:11:04 +0100 Subject: [PATCH 13/49] add trad menu left recuitment --- htdocs/langs/en_US/recruitment.lang | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/langs/en_US/recruitment.lang b/htdocs/langs/en_US/recruitment.lang index 686722a48c5..6cdf6cf41b3 100644 --- a/htdocs/langs/en_US/recruitment.lang +++ b/htdocs/langs/en_US/recruitment.lang @@ -77,3 +77,4 @@ ExtrafieldsApplication=Complementary attributes (job applications) MakeOffer=Make an offer WeAreRecruiting=We are recruiting. This is a list of open positions to be filled... NoPositionOpen=No positions open at the moment +recruitment=Recruitment \ No newline at end of file From de7d7d8d665033547bfee626f674765fd59a0b5e Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Wed, 13 Dec 2023 08:50:33 +0100 Subject: [PATCH 14/49] FIX: backport SQL error on global search product --- htdocs/product/list.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 8507026d302..9530bfd3189 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -168,10 +168,10 @@ if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) // List of fields to search into when doing a "search in all" $fieldstosearchall = array( 'p.ref'=>"Ref", - 'pfp.ref_fourn'=>"RefSupplier", 'p.label'=>"ProductLabel", 'p.description'=>"Description", "p.note"=>"Note", + 'pfp.ref_fourn'=>"RefSupplier", ); // multilang @@ -457,7 +457,21 @@ if (!empty($conf->global->PRODUCT_USE_UNITS)) { $sql .= ' WHERE p.entity IN ('.getEntity('product').')'; if ($sall) { - $sql .= natural_search(array_keys($fieldstosearchall), $sall); + // Clean $fieldstosearchall + $newfieldstosearchall = $fieldstosearchall; + unset($newfieldstosearchall['pfp.ref_fourn']); + unset($newfieldstosearchall['pfp.barcode']); + + $sql .= ' AND ('; + $sql .= natural_search(array_keys($newfieldstosearchall), $sall, 0, 1); + // Search also into a supplier reference 'pfp.ref_fourn'="RefSupplier" + $sql .= ' OR EXISTS (SELECT rowid FROM '.MAIN_DB_PREFIX.'product_fournisseur_price as pfp WHERE pfp.fk_product = p.rowid'; + $sql .= ' AND ('.natural_search('pfp.ref_fourn', $sall, 0, 1); + if (isModEnabled('barcode')) { + // Search also into a supplier barcode 'pfp.barcode'='GencodBuyPrice'; + $sql .= ' OR '.natural_search('pfp.barcode', $sall, 0, 1); + } + $sql .= ')))'; } // if the type is not 1, we show all products (type = 0,2,3) if (dol_strlen($search_type) && $search_type != '-1') { From ab7b9820d4522d1a9285e77a42a993a8a6f51b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 13 Dec 2023 09:34:25 +0100 Subject: [PATCH 15/49] fix error message --- htdocs/fourn/class/api_supplier_invoices.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/class/api_supplier_invoices.class.php b/htdocs/fourn/class/api_supplier_invoices.class.php index a531667d0e5..2e0efede12c 100644 --- a/htdocs/fourn/class/api_supplier_invoices.class.php +++ b/htdocs/fourn/class/api_supplier_invoices.class.php @@ -228,7 +228,7 @@ class SupplierInvoices extends DolibarrApi } if ($this->invoice->create(DolibarrApiAccess::$user) < 0) { - throw new RestException(500, "Error creating order", array_merge(array($this->invoice->error), $this->invoice->errors)); + throw new RestException(500, "Error creating invoice ", array_merge(array($this->invoice->error), $this->invoice->errors)); } return $this->invoice->id; } From bc048cac660b3bdbfc855b209f84a8654fb3e667 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Wed, 13 Dec 2023 09:37:45 +0100 Subject: [PATCH 16/49] fix: MAIN_AGENDA_EXPORT_PAST_DELAY is defaulted to 0 to 'not isset' is always false --- htdocs/public/agenda/agendaexport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/public/agenda/agendaexport.php b/htdocs/public/agenda/agendaexport.php index e8d9f986f91..a65c9347fe3 100644 --- a/htdocs/public/agenda/agendaexport.php +++ b/htdocs/public/agenda/agendaexport.php @@ -89,7 +89,7 @@ if (empty($conf->agenda->enabled)) { } // Not older than -if (!isset($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) { +if (empty($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) { $conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY = 100; // default limit } From ddf960e1c4c5fac760acfeb92cebe9fb2fdd740b Mon Sep 17 00:00:00 2001 From: atm-lena Date: Wed, 13 Dec 2023 14:32:58 +0100 Subject: [PATCH 17/49] Add contact to project and tasks : formconfirm get url too long --- htdocs/projet/contact.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/htdocs/projet/contact.php b/htdocs/projet/contact.php index be130572704..e7b18c749ce 100644 --- a/htdocs/projet/contact.php +++ b/htdocs/projet/contact.php @@ -126,7 +126,7 @@ if ($action == 'addcontact') { $formquestion[] = array('type'=> 'other', 'name'=>'tasksavailable', 'label'=>'', 'value' => ''); } - $formconfirmtoaddtasks = $form->formconfirm($_SERVER['PHP_SELF'] . $url_redirect, $text, '', 'addcontact_confirm', $formquestion, '', 1, 300, 590); + $formconfirmtoaddtasks = $form->formconfirm($_SERVER['PHP_SELF'] . $url_redirect, $text, '', 'addcontact_confirm', $formquestion, '', ((count($formquestion) > 10) ? 0 : 1), 300, 590); $formconfirmtoaddtasks .='