From 24f77465ccede7b1e21541a16f0877cb44f0e786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 8 Mar 2023 21:16:37 +0100 Subject: [PATCH 1/6] use a fonction to get multidir output --- htdocs/commande/card.php | 2 +- htdocs/core/lib/functions.lib.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 97b3e017505..e36fa67b053 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -2987,7 +2987,7 @@ if ($action == 'create' && $usercancreate) { // Presend form $modelmail = 'order_send'; $defaulttopic = 'SendOrderRef'; - $diroutput = $conf->commande->multidir_output[$object->entity]; + $diroutput = getMultidirOutput($object); $trackid = 'ord'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index e0f3fb0a4bb..668c7636926 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -71,6 +71,18 @@ if (!function_exists('utf8_decode')) { } } +/** + * Return multidir output for an Dolibarr object + * + * @param CommonObject $object Dolibarr common object + * @return string + */ +function getMultiDirOutput($object) : string +{ + global $conf; + $module = $object->element; + return $conf->$module->multidir_output[$object->entity]; +} /** * Return dolibarr global constant string value From e4492da46f87c160ebb61b57193446ac45aa36b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 8 Mar 2023 21:20:56 +0100 Subject: [PATCH 2/6] use a fonction to get multidir output --- htdocs/core/lib/functions.lib.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 668c7636926..ee200fa1679 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -75,11 +75,15 @@ if (!function_exists('utf8_decode')) { * Return multidir output for an Dolibarr object * * @param CommonObject $object Dolibarr common object - * @return string + * @since Dolibarr V18 + * @return string|void */ -function getMultiDirOutput($object) : string +function getMultidirOutput($object) { global $conf; + if (!is_object($object)) { + return; + } $module = $object->element; return $conf->$module->multidir_output[$object->entity]; } From a9b9812b7e7ffdf4710ff9e87cede29bb190613a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 8 Mar 2023 21:39:05 +0100 Subject: [PATCH 3/6] try to use function --- htdocs/commande/class/commande.class.php | 1 + .../core/modules/commande/doc/pdf_eratosthene.modules.php | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 86fcfbea1ad..4a6a197aa79 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -3960,6 +3960,7 @@ class Commande extends CommonOrder $this->id = 0; $this->ref = 'SPECIMEN'; $this->specimen = 1; + $this->entity = $conf->entity; $this->socid = 1; $this->date = time(); $this->date_lim_reglement = $this->date + 3600 * 24 * 30; diff --git a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php index 78b3fa24a33..c035b190693 100644 --- a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php @@ -296,18 +296,18 @@ class pdf_eratosthene extends ModelePDFCommandes - if ($conf->commande->multidir_output[$conf->entity]) { + if (getMultidirOutput($object)) { $object->fetch_thirdparty(); $deja_regle = 0; // Definition of $dir and $file if ($object->specimen) { - $dir = $conf->commande->multidir_output[$conf->entity]; + $dir = getMultidirOutput($object); $file = $dir."/SPECIMEN.pdf"; } else { $objectref = dol_sanitizeFileName($object->ref); - $dir = $conf->commande->multidir_output[$object->entity]."/".$objectref; + $dir = getMultidirOutput($object)."/".$objectref; $file = $dir."/".$objectref.".pdf"; } From 145880bc92d67b71c26019322d63d6f1d1f8bb01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 8 Mar 2023 21:52:50 +0100 Subject: [PATCH 4/6] try to use function --- htdocs/core/lib/functions.lib.php | 9 +++++++-- .../modules/commande/doc/pdf_eratosthene.modules.php | 6 +++--- htdocs/societe/class/societe.class.php | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index ee200fa1679..77f4cc09b77 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -75,16 +75,21 @@ if (!function_exists('utf8_decode')) { * Return multidir output for an Dolibarr object * * @param CommonObject $object Dolibarr common object + * @param string $module override object element, by example mycompany instead societe * @since Dolibarr V18 * @return string|void */ -function getMultidirOutput($object) +function getMultidirOutput($object, $module = '') { global $conf; if (!is_object($object)) { return; } - $module = $object->element; + if (empty($module) && !empty($object->element)) { + $module = $object->element; + } else { + return; + } return $conf->$module->multidir_output[$object->entity]; } diff --git a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php index c035b190693..cb460cff14a 100644 --- a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php @@ -1447,7 +1447,7 @@ class pdf_eratosthene extends ModelePDFCommandes protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null, $titlekey = "PdfOrderTitle") { // phpcs:enable - global $conf, $langs, $hookmanager; + global $conf, $langs, $hookmanager, $mysoc; $ltrdirection = 'L'; if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R'; @@ -1473,8 +1473,8 @@ class pdf_eratosthene extends ModelePDFCommandes if (!getDolGlobalInt('PDF_DISABLE_MYCOMPANY_LOGO')) { if ($this->emetteur->logo) { $logodir = $conf->mycompany->dir_output; - if (!empty($conf->mycompany->multidir_output[$object->entity])) { - $logodir = $conf->mycompany->multidir_output[$object->entity]; + if (!empty(getMultidirOutput($mysoc, 'mycompany'))) { + $logodir = getMultidirOutput($mysoc, 'mycompany'); } if (!getDolGlobalInt('MAIN_PDF_USE_LARGE_LOGO')) { $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 1912bd74521..a56fad2c086 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -4358,7 +4358,9 @@ class Societe extends CommonObject global $langs; $this->id = 0; + $this->entity = $conf->entity; $this->name = getDolGlobalString('MAIN_INFO_SOCIETE_NOM'); + $this->nom = $this->name; // deprecated $this->address = getDolGlobalString('MAIN_INFO_SOCIETE_ADDRESS'); $this->zip = getDolGlobalString('MAIN_INFO_SOCIETE_ZIP'); $this->town = getDolGlobalString('MAIN_INFO_SOCIETE_TOWN'); @@ -4368,8 +4370,6 @@ class Societe extends CommonObject $this->note_private = getDolGlobalString('MAIN_INFO_SOCIETE_NOTE'); - $this->nom = $this->name; // deprecated - // We define country_id, country_code and country $country_id = $country_code = $country_label = ''; if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) { From bd4d06887cea9a24d09ca97755fb1dd43692a75a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 14 Mar 2023 22:05:16 +0100 Subject: [PATCH 5/6] return null instead void --- htdocs/core/lib/functions.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 77f4cc09b77..b7c028b65e8 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -83,12 +83,12 @@ function getMultidirOutput($object, $module = '') { global $conf; if (!is_object($object)) { - return; + return null; } if (empty($module) && !empty($object->element)) { $module = $object->element; } else { - return; + return null; } return $conf->$module->multidir_output[$object->entity]; } From dd885a8e29c882448d9a2d3c7e07903efe3b2714 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 18 Mar 2023 10:55:05 +0100 Subject: [PATCH 6/6] Update functions.lib.php --- htdocs/core/lib/functions.lib.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index b7c028b65e8..0c4a91e6259 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -72,12 +72,12 @@ if (!function_exists('utf8_decode')) { } /** - * Return multidir output for an Dolibarr object + * Return the full path of the directory where a module (or an object of a module) stores its files. Path may depends on the entity if a multicompany module is enabled. * - * @param CommonObject $object Dolibarr common object - * @param string $module override object element, by example mycompany instead societe + * @param CommonObject $object Dolibarr common object + * @param string $module Override object element, for example to use 'mycompany' instead of 'societe' + * @return string|void The path of the relative directory of the module * @since Dolibarr V18 - * @return string|void */ function getMultidirOutput($object, $module = '') {