From 9051e411d074a300686868724831f150e099c2c1 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Mon, 18 Dec 2023 12:00:41 +0100 Subject: [PATCH 01/56] FIX Multilangs : PDF lines description --- htdocs/comm/propal/class/propal.class.php | 2 +- htdocs/core/lib/pdf.lib.php | 26 ++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 2dbaeaf056e..536e7fb59e0 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1680,7 +1680,7 @@ class Propal extends CommonObject $this->lines = array(); // Lines - $result = $this->fetch_lines(); + $result = $this->fetch_lines(0, (!empty(getDolGlobalInt('MAIN_MULTILANGS')) ? 1 : 0)); if ($result < 0) { return -3; } diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index d6a22f64de5..d5da41777ab 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1410,12 +1410,28 @@ function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, { global $db, $conf, $langs; + $multilangsactive = getDolGlobalInt('MAIN_MULTILANGS'); + + //id $idprod = (!empty($object->lines[$i]->fk_product) ? $object->lines[$i]->fk_product : false); - $label = (!empty($object->lines[$i]->label) ? $object->lines[$i]->label : (!empty($object->lines[$i]->product_label) ? $object->lines[$i]->product_label : '')); - $desc = (!empty($object->lines[$i]->desc) ? $object->lines[$i]->desc : (!empty($object->lines[$i]->description) ? $object->lines[$i]->description : '')); + //label + if(!empty($object->lines[$i]->label)){ + $label = $object->lines[$i]->label; + } else { + $label = (!empty($object->lines[$i]->multilangs[$langs->defaultlang]['label'] && $multilangsactive) ? $object->lines[$i]->multilangs[$langs->defaultlang]['label'] : (!empty($object->lines[$i]->product_label) ? $object->lines[$i]->product_label : '')); + } + //description + if(!empty($object->lines[$i]->desc)){ + $desc = $object->lines[$i]->desc; + } else { + $desc = (!empty($object->lines[$i]->multilangs[$langs->defaultlang]['description'] && $multilangsactive) ? $object->lines[$i]->multilangs[$langs->defaultlang]['description'] : (!empty($object->lines[$i]->description) ? $object->lines[$i]->description : '')); + } + //ref supplier $ref_supplier = (!empty($object->lines[$i]->ref_supplier) ? $object->lines[$i]->ref_supplier : (!empty($object->lines[$i]->ref_fourn) ? $object->lines[$i]->ref_fourn : '')); // TODO Not yet saved for supplier invoices, only supplier orders - $note = (!empty($object->lines[$i]->note) ? $object->lines[$i]->note : ''); - $dbatch = (!empty($object->lines[$i]->detail_batch) ? $object->lines[$i]->detail_batch : false); + //note + $note = (!empty($object->lines[$i]->note) ? $object->lines[$i]->note : ''); + //dbatch + $dbatch = (!empty($object->lines[$i]->detail_batch) ? $object->lines[$i]->detail_batch : false); if ($issupplierline) { include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; @@ -1432,7 +1448,7 @@ function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, if ($idprod) { $prodser->fetch($idprod); // If a predefined product and multilang and on other lang, we renamed label with label translated - if (getDolGlobalInt('MAIN_MULTILANGS') && ($outputlangs->defaultlang != $langs->defaultlang)) { + if ($multilangsactive && ($outputlangs->defaultlang != $langs->defaultlang)) { $translatealsoifmodified = (!empty($conf->global->MAIN_MULTILANG_TRANSLATE_EVEN_IF_MODIFIED)); // By default if value was modified manually, we keep it (no translation because we don't have it) // TODO Instead of making a compare to see if param was modified, check that content contains reference translation. If yes, add the added part to the new translation From ec19dcc8f85afab59a816a4bdba6103fa875e810 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Mon, 18 Dec 2023 13:34:50 +0100 Subject: [PATCH 02/56] Invoice --- htdocs/compta/facture/class/facture.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 7232137ae1c..faa54322c49 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2076,7 +2076,7 @@ class Facture extends CommonInvoice // Lines $this->lines = array(); - $result = $this->fetch_lines(); + $result = $this->fetch_lines(0, (!empty(getDolGlobalInt('MAIN_MULTILANGS')) ? 1 : 0)); if ($result < 0) { $this->error = $this->db->error(); return -3; From abc9eb7bdc21dff0608c12bd6ee0ec075c4d7251 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Mon, 18 Dec 2023 13:44:19 +0100 Subject: [PATCH 03/56] Clean Code --- htdocs/core/lib/pdf.lib.php | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index d5da41777ab..cb242fdf1f4 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1410,28 +1410,27 @@ function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, { global $db, $conf, $langs; - $multilangsactive = getDolGlobalInt('MAIN_MULTILANGS'); - - //id + $multilangsactive = getDolGlobalInt('MAIN_MULTILANGS'); + //id $idprod = (!empty($object->lines[$i]->fk_product) ? $object->lines[$i]->fk_product : false); - //label - if(!empty($object->lines[$i]->label)){ - $label = $object->lines[$i]->label; - } else { - $label = (!empty($object->lines[$i]->multilangs[$langs->defaultlang]['label'] && $multilangsactive) ? $object->lines[$i]->multilangs[$langs->defaultlang]['label'] : (!empty($object->lines[$i]->product_label) ? $object->lines[$i]->product_label : '')); - } - //description - if(!empty($object->lines[$i]->desc)){ - $desc = $object->lines[$i]->desc; - } else { - $desc = (!empty($object->lines[$i]->multilangs[$langs->defaultlang]['description'] && $multilangsactive) ? $object->lines[$i]->multilangs[$langs->defaultlang]['description'] : (!empty($object->lines[$i]->description) ? $object->lines[$i]->description : '')); - } - //ref supplier + //label + if (!empty($object->lines[$i]->label)) { + $label = $object->lines[$i]->label; + } else { + $label = (!empty($object->lines[$i]->multilangs[$langs->defaultlang]['label'] && $multilangsactive) ? $object->lines[$i]->multilangs[$langs->defaultlang]['label'] : (!empty($object->lines[$i]->product_label) ? $object->lines[$i]->product_label : '')); + } + //description + if (!empty($object->lines[$i]->desc)) { + $desc = $object->lines[$i]->desc; + } else { + $desc = (!empty($object->lines[$i]->multilangs[$langs->defaultlang]['description'] && $multilangsactive) ? $object->lines[$i]->multilangs[$langs->defaultlang]['description'] : (!empty($object->lines[$i]->description) ? $object->lines[$i]->description : '')); + } + //ref supplier $ref_supplier = (!empty($object->lines[$i]->ref_supplier) ? $object->lines[$i]->ref_supplier : (!empty($object->lines[$i]->ref_fourn) ? $object->lines[$i]->ref_fourn : '')); // TODO Not yet saved for supplier invoices, only supplier orders //note - $note = (!empty($object->lines[$i]->note) ? $object->lines[$i]->note : ''); + $note = (!empty($object->lines[$i]->note) ? $object->lines[$i]->note : ''); //dbatch - $dbatch = (!empty($object->lines[$i]->detail_batch) ? $object->lines[$i]->detail_batch : false); + $dbatch = (!empty($object->lines[$i]->detail_batch) ? $object->lines[$i]->detail_batch : false); if ($issupplierline) { include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; From 4d32d93ee2c065e5db590bb64796939e8074d8d9 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Mon, 18 Dec 2023 17:28:41 +0100 Subject: [PATCH 04/56] Clean Travis --- htdocs/comm/propal/class/propal.class.php | 2 +- htdocs/compta/facture/class/facture.class.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 536e7fb59e0..bdc3ee4d7f1 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1680,7 +1680,7 @@ class Propal extends CommonObject $this->lines = array(); // Lines - $result = $this->fetch_lines(0, (!empty(getDolGlobalInt('MAIN_MULTILANGS')) ? 1 : 0)); + $result = $this->fetch_lines(0, (getDolGlobalInt('MAIN_MULTILANGS') ? 1 : 0)); if ($result < 0) { return -3; } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index faa54322c49..f3466a73eba 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2076,7 +2076,7 @@ class Facture extends CommonInvoice // Lines $this->lines = array(); - $result = $this->fetch_lines(0, (!empty(getDolGlobalInt('MAIN_MULTILANGS')) ? 1 : 0)); + $result = $this->fetch_lines(0, (getDolGlobalInt('MAIN_MULTILANGS') ? 1 : 0)); if ($result < 0) { $this->error = $this->db->error(); return -3; From 86971c7b863c1b891c30f901b5ed3751eeaa720d Mon Sep 17 00:00:00 2001 From: atm-lena Date: Fri, 22 Dec 2023 09:30:35 +0100 Subject: [PATCH 05/56] Clean Conditions --- htdocs/core/lib/pdf.lib.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index cb242fdf1f4..4b9fdb6e7c3 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1417,13 +1417,29 @@ function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, if (!empty($object->lines[$i]->label)) { $label = $object->lines[$i]->label; } else { - $label = (!empty($object->lines[$i]->multilangs[$langs->defaultlang]['label'] && $multilangsactive) ? $object->lines[$i]->multilangs[$langs->defaultlang]['label'] : (!empty($object->lines[$i]->product_label) ? $object->lines[$i]->product_label : '')); + if (!empty($object->lines[$i]->multilangs[$langs->defaultlang]['label']) && $multilangsactive) { + $label = $object->lines[$i]->multilangs[$langs->defaultlang]['label']; + } else { + if (!empty($object->lines[$i]->product_label)) { + $label = $object->lines[$i]->product_label; + } else { + $label = ''; + } + } } //description if (!empty($object->lines[$i]->desc)) { $desc = $object->lines[$i]->desc; } else { - $desc = (!empty($object->lines[$i]->multilangs[$langs->defaultlang]['description'] && $multilangsactive) ? $object->lines[$i]->multilangs[$langs->defaultlang]['description'] : (!empty($object->lines[$i]->description) ? $object->lines[$i]->description : '')); + if (!empty($object->lines[$i]->multilangs[$langs->defaultlang]['description']) && $multilangsactive) { + $desc = $object->lines[$i]->multilangs[$langs->defaultlang]['description']; + } else { + if (!empty($object->lines[$i]->description)) { + $desc = $object->lines[$i]->description; + } else { + $desc = ''; + } + } } //ref supplier $ref_supplier = (!empty($object->lines[$i]->ref_supplier) ? $object->lines[$i]->ref_supplier : (!empty($object->lines[$i]->ref_fourn) ? $object->lines[$i]->ref_fourn : '')); // TODO Not yet saved for supplier invoices, only supplier orders From e24da3242440e88a840accf45bd6c805a47001e7 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Tue, 16 Jan 2024 14:13:28 +0100 Subject: [PATCH 06/56] Load multilangs in function pdf_getlinedesc() --- htdocs/comm/propal/class/propal.class.php | 2 +- htdocs/compta/facture/class/facture.class.php | 2 +- htdocs/core/lib/pdf.lib.php | 34 ++++++++++++------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index bdc3ee4d7f1..2dbaeaf056e 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1680,7 +1680,7 @@ class Propal extends CommonObject $this->lines = array(); // Lines - $result = $this->fetch_lines(0, (getDolGlobalInt('MAIN_MULTILANGS') ? 1 : 0)); + $result = $this->fetch_lines(); if ($result < 0) { return -3; } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index a4ba1d4896f..9d96dce5088 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2076,7 +2076,7 @@ class Facture extends CommonInvoice // Lines $this->lines = array(); - $result = $this->fetch_lines(0, (getDolGlobalInt('MAIN_MULTILANGS') ? 1 : 0)); + $result = $this->fetch_lines(); if ($result < 0) { $this->error = $this->db->error(); return -3; diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 4b9fdb6e7c3..3cd9a055bac 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1411,8 +1411,29 @@ function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, global $db, $conf, $langs; $multilangsactive = getDolGlobalInt('MAIN_MULTILANGS'); + + if ($issupplierline) { + include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; + $prodser = new ProductFournisseur($db); + } else { + include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + $prodser = new Product($db); + + if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { + include_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php'; + } + } + //id $idprod = (!empty($object->lines[$i]->fk_product) ? $object->lines[$i]->fk_product : false); + if($idprod) { + $prodser->fetch($idprod); + //load multilangs + if($multilangsactive){ + $prodser->getMultiLangs(); + $object->lines[$i]->multilangs = $prodser->multilangs; + } + } //label if (!empty($object->lines[$i]->label)) { $label = $object->lines[$i]->label; @@ -1448,20 +1469,7 @@ function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, //dbatch $dbatch = (!empty($object->lines[$i]->detail_batch) ? $object->lines[$i]->detail_batch : false); - if ($issupplierline) { - include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; - $prodser = new ProductFournisseur($db); - } else { - include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; - $prodser = new Product($db); - - if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { - include_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php'; - } - } - if ($idprod) { - $prodser->fetch($idprod); // If a predefined product and multilang and on other lang, we renamed label with label translated if ($multilangsactive && ($outputlangs->defaultlang != $langs->defaultlang)) { $translatealsoifmodified = (!empty($conf->global->MAIN_MULTILANG_TRANSLATE_EVEN_IF_MODIFIED)); // By default if value was modified manually, we keep it (no translation because we don't have it) From 66a175e48d975e9239cf4874d9864fae6aee80b8 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Mon, 22 Jan 2024 14:52:51 +0100 Subject: [PATCH 07/56] langs of recipient --- htdocs/core/lib/pdf.lib.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 3cd9a055bac..6dd5345be66 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1438,8 +1438,8 @@ function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, if (!empty($object->lines[$i]->label)) { $label = $object->lines[$i]->label; } else { - if (!empty($object->lines[$i]->multilangs[$langs->defaultlang]['label']) && $multilangsactive) { - $label = $object->lines[$i]->multilangs[$langs->defaultlang]['label']; + if (!empty($object->lines[$i]->multilangs[$outputlangs->defaultlang]['label']) && $multilangsactive) { + $label = $object->lines[$i]->multilangs[$outputlangs->defaultlang]['label']; } else { if (!empty($object->lines[$i]->product_label)) { $label = $object->lines[$i]->product_label; @@ -1452,8 +1452,8 @@ function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, if (!empty($object->lines[$i]->desc)) { $desc = $object->lines[$i]->desc; } else { - if (!empty($object->lines[$i]->multilangs[$langs->defaultlang]['description']) && $multilangsactive) { - $desc = $object->lines[$i]->multilangs[$langs->defaultlang]['description']; + if (!empty($object->lines[$i]->multilangs[$outputlangs->defaultlang]['description']) && $multilangsactive) { + $desc = $object->lines[$i]->multilangs[$outputlangs->defaultlang]['description']; } else { if (!empty($object->lines[$i]->description)) { $desc = $object->lines[$i]->description; From 87c16498ca4d93db7ed69f9738182f7b88c33070 Mon Sep 17 00:00:00 2001 From: Kamel Khelifa Date: Fri, 18 Oct 2024 14:26:04 +0200 Subject: [PATCH 08/56] FIX: Fix return value of hook sendMail when hook return -1 who must be return false in sendfile() function --- htdocs/core/class/CMailFile.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index db8b30ed249..34b7c2757e5 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -687,7 +687,7 @@ class CMailFile $this->error = "Error in hook maildao sendMail ".$reshook; dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); - return $reshook; + return false; } if ($reshook == 1) { // Hook replace standard code return true; From a4785adb3df9cf7162b21814c4e4204a67ce7ad6 Mon Sep 17 00:00:00 2001 From: tnegre Date: Thu, 12 Dec 2024 15:28:19 +0100 Subject: [PATCH 09/56] FIX : display error when loan can't be deleted --- htdocs/loan/card.php | 4 ++-- htdocs/loan/class/loan.class.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/loan/card.php b/htdocs/loan/card.php index 8c4cc3810b8..45e8fe0fd8a 100644 --- a/htdocs/loan/card.php +++ b/htdocs/loan/card.php @@ -82,7 +82,7 @@ if (empty($reshook)) { if ($result > 0) { setEventMessages($langs->trans('LoanPaid'), null, 'mesgs'); } else { - setEventMessages($loan->error, null, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } @@ -95,7 +95,7 @@ if (empty($reshook)) { header("Location: list.php"); exit; } else { - setEventMessages($loan->error, null, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } diff --git a/htdocs/loan/class/loan.class.php b/htdocs/loan/class/loan.class.php index 98051a0d2b6..0f077d0d9ed 100644 --- a/htdocs/loan/class/loan.class.php +++ b/htdocs/loan/class/loan.class.php @@ -308,6 +308,7 @@ class Loan extends CommonObject $accountline->fetch($line_url['fk_bank']); $result = $accountline->delete_urls($user); if ($result < 0) { + $this->errors = array_merge($this->errors, [$accountline->error], $accountline->errors); $error++; } } From d9be3efa90a081f6b5c3c64c1e3a36d3432cb2f4 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Fri, 13 Dec 2024 06:18:45 +0100 Subject: [PATCH 10/56] FIX #32339 Delete a loan settlement is partial --- htdocs/loan/class/paymentloan.class.php | 44 +++++++++---------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/htdocs/loan/class/paymentloan.class.php b/htdocs/loan/class/paymentloan.class.php index bd02374a24c..77c8b183b87 100644 --- a/htdocs/loan/class/paymentloan.class.php +++ b/htdocs/loan/class/paymentloan.class.php @@ -1,7 +1,7 @@ - * Copyright (C) 2015-2018 Frederic France - * Copyright (C) 2020 Maxime DEMAREST +/* Copyright (C) 2014-2024 Alexandre Spangaro + * Copyright (C) 2015-2018 Frederic France + * Copyright (C) 2020 Maxime DEMAREST * * 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 @@ -99,6 +99,11 @@ class PaymentLoan extends CommonObject public $type_code; public $type_label; + /** + * @var int + */ + public $bank_line; + /** * Constructor @@ -364,6 +369,7 @@ class PaymentLoan extends CommonObject } $this->db->rollback(); return -1 * $error; + } else { $this->db->commit(); return 1; @@ -380,19 +386,17 @@ class PaymentLoan extends CommonObject */ public function delete($user, $notrigger = 0) { - global $conf, $langs; $error = 0; $this->db->begin(); - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url"; - $sql .= " WHERE type='payment_loan' AND url_id=".((int) $this->id); - - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) { - $error++; $this->errors[] = "Error ".$this->db->lasterror(); + if ($this->bank_line > 0) { + $accline = new AccountLine($this->db); + $accline->fetch($this->bank_line); + $result = $accline->delete($user); + if ($result < 0) { + $this->errors[] = $accline->error; + $error++; } } @@ -422,22 +426,6 @@ class PaymentLoan extends CommonObject } } - //if (! $error) - //{ - // if (! $notrigger) - // { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action call a trigger. - - //// Call triggers - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - //$interface=new Interfaces($this->db); - //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); - //if ($result < 0) { $error++; $this->errors=$interface->errors; } - //// End call triggers - // } - //} - // Commit or rollback if ($error) { foreach ($this->errors as $errmsg) { From ef090aa895dc7d33482f4bd6d4b1ef9bb8d1d395 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Fri, 13 Dec 2024 06:22:44 +0100 Subject: [PATCH 11/56] CI --- htdocs/loan/class/paymentloan.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/loan/class/paymentloan.class.php b/htdocs/loan/class/paymentloan.class.php index 77c8b183b87..1604383b700 100644 --- a/htdocs/loan/class/paymentloan.class.php +++ b/htdocs/loan/class/paymentloan.class.php @@ -369,7 +369,6 @@ class PaymentLoan extends CommonObject } $this->db->rollback(); return -1 * $error; - } else { $this->db->commit(); return 1; From f60f34cdf8cd3c5f67afb7facd8391e389cfde09 Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 2 Jan 2025 14:07:46 +0100 Subject: [PATCH 12/56] Backport fix for send email to assigned user on ticket create --- ...terface_50_modTicket_TicketEmail.class.php | 170 ++++++++++++++---- 1 file changed, 137 insertions(+), 33 deletions(-) diff --git a/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php b/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php index 58eeaf18dc3..bead2d3faf6 100644 --- a/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php +++ b/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php @@ -77,45 +77,48 @@ class InterfaceTicketEmail extends DolibarrTriggers if ($res > 0) { // Send email to notification email if (empty($conf->global->TICKET_DISABLE_ALL_MAILS)) { - // Init to avoid errors - $filepath = array(); - $filename = array(); - $mimetype = array(); +// Init to avoid errors +// $filepath = array(); +// $filename = array(); +// $mimetype = array(); // Send email to assigned user - $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketAssignedToYou'); - $message = '

'.$langs->transnoentities('TicketAssignedEmailBody', $object->track_id, dolGetFirstLastname($user->firstname, $user->lastname))."

"; - $message .= '
  • '.$langs->trans('Title').' : '.$object->subject.'
  • '; - $message .= '
  • '.$langs->trans('Type').' : '.$object->type_label.'
  • '; - $message .= '
  • '.$langs->trans('Category').' : '.$object->category_label.'
  • '; - $message .= '
  • '.$langs->trans('Severity').' : '.$object->severity_label.'
  • '; - // Extrafields - if (is_array($object->array_options) && count($object->array_options) > 0) { - foreach ($object->array_options as $key => $value) { - $message .= '
  • '.$langs->trans($key).' : '.$value.'
  • '; - } - } - - $message .= '
'; - $message .= '

'.$langs->trans('Message').' :
'.$object->message.'

'; - $message .= '

'.$langs->trans('SeeThisTicketIntomanagementInterface').'

'; +// $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketAssignedToYou'); +// $message = '

'.$langs->transnoentities('TicketAssignedEmailBody', $object->track_id, dolGetFirstLastname($user->firstname, $user->lastname))."

"; +// $message .= '
  • '.$langs->trans('Title').' : '.$object->subject.'
  • '; +// $message .= '
  • '.$langs->trans('Type').' : '.$object->type_label.'
  • '; +// $message .= '
  • '.$langs->trans('Category').' : '.$object->category_label.'
  • '; +// $message .= '
  • '.$langs->trans('Severity').' : '.$object->severity_label.'
  • '; +// // Extrafields +// if (is_array($object->array_options) && count($object->array_options) > 0) { +// foreach ($object->array_options as $key => $value) { +// $message .= '
  • '.$langs->trans($key).' : '.$value.'
  • '; +// } +// } +// +// $message .= '
'; +// $message .= '

'.$langs->trans('Message').' :
'.$object->message.'

'; +// $message .= '

'.$langs->trans('SeeThisTicketIntomanagementInterface').'

'; $sendto = $userstat->email; - $from = dolGetFirstLastname($user->firstname, $user->lastname).'<'.$user->email.'>'; - - $message = dol_nl2br($message); + $subject_assignee = 'TicketAssignedToYou'; + $body_assignee = 'TicketAssignedEmailBody'; + $see_ticket_assignee = 'SeeThisTicketIntomanagementInterface'; +// $from = dolGetFirstLastname($user->firstname, $user->lastname).'<'.$user->email.'>'; +// +// $message = dol_nl2br($message); if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; } - include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, '', '', 0, -1); - if ($mailfile->error) { - setEventMessages($mailfile->error, $mailfile->errors, 'errors'); - } else { - $result = $mailfile->sendfile(); - } +// include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; +// $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, '', '', 0, -1); +// if ($mailfile->error) { +// setEventMessages($mailfile->error, $mailfile->errors, 'errors'); +// } else { +// $result = $mailfile->sendfile(); +// } if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; } @@ -173,10 +176,15 @@ class InterfaceTicketEmail extends DolibarrTriggers $subject_admin = 'TicketNewEmailSubjectAdmin'; $body_admin = 'TicketNewEmailBodyAdmin'; + $subject_customer = 'TicketNewEmailSubjectCustomer'; $body_customer = 'TicketNewEmailBodyCustomer'; $see_ticket_customer = 'TicketNewEmailBodyInfosTrackUrlCustomer'; + $subject_assignee = 'TicketAssignedToYou'; + $body_assignee = 'TicketAssignedEmailBody'; + $see_ticket_assignee = 'SeeThisTicketIntomanagementInterface'; + // Send email to notification email if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && empty($object->context['disableticketemail'])) { $sendto = empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) ? '' : $conf->global->TICKET_NOTIFICATION_EMAIL_TO; @@ -185,6 +193,34 @@ class InterfaceTicketEmail extends DolibarrTriggers } } + // Send email to assignee if an assignee was set at creation + if ($object->fk_user_assign > 0 && $object->fk_user_assign != $user->id && empty($object->context['disableticketemail'])) { + $userstat = new User($this->db); + $res = $userstat->fetch($object->fk_user_assign); + if ($res > 0) { + // Send email to notification email + if (!getDolGlobalString('TICKET_DISABLE_ALL_MAILS')) { + // Send email to assigned user + $sendto = $userstat->email; + if (!getDolGlobalString('TICKET_DISABLE_MAIL_AUTOCOPY_TO')) { + $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; + $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; + } + + if (!empty($sendto)) { + $this->composeAndSendAssigneeMessage($sendto, $subject_assignee, $body_assignee, $see_ticket_assignee, $object, $langs); + } + + if (!getDolUserString('TICKET_DISABLE_MAIL_AUTOCOPY_TO')) { + $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; + } + } + } else { + $this->error = $userstat->error; + $this->errors = $userstat->errors; + } + } + // Send email to customer if (empty($conf->global->TICKET_DISABLE_CUSTOMER_MAILS) && empty($object->context['disableticketemail']) && $object->notify_tiers_at_create) { $sendto = ''; @@ -428,9 +464,9 @@ class InterfaceTicketEmail extends DolibarrTriggers $trackid = 'tic'.$object->id; - $old_MAIN_MAIL_AUTOCOPY_TO = getDolGlobalString('MAIN_MAIL_AUTOCOPY_TO'); - - if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { + $old_MAIN_MAIL_AUTOCOPY_TO = null; + if (getDolGlobalString('TICKET_DISABLE_MAIL_AUTOCOPY_TO')) { + $old_MAIN_MAIL_AUTOCOPY_TO = getDolGlobalString('MAIN_MAIL_AUTOCOPY_TO'); $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; } @@ -451,4 +487,72 @@ class InterfaceTicketEmail extends DolibarrTriggers $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; } } + + /** + * Composes and sends a message concerning a ticket, to be sent to user assigned to the ticket + * + * @param string $sendto Addresses to send the mail, format "first@address.net, second@address.net, " etc. + * @param string $base_subject email subject. Non-translated string. + * @param string $body email body (first line). Non-translated string. + * @param string $see_ticket string indicating the ticket public address + * @param Ticket $object the ticket thet the email refers to + * @param Translate $langs the translation object + * @return void + */ + private function composeAndSendAssigneeMessage($sendto, $base_subject, $body, $see_ticket, Ticket $object, Translate $langs) + { + global $conf, $user, $mysoc; + + // Init to avoid errors + $filepath = array(); + $filename = array(); + $mimetype = array(); + + // Send email to assigned user + $appli = $mysoc->name; + + $subject = '['.$appli.'] '.$langs->transnoentities($base_subject); + $message = '

'.$langs->transnoentities($body, $object->track_id, dolGetFirstLastname($user->firstname, $user->lastname))."

"; + $message .= '
  • '.$langs->trans('Title').' : '.$object->subject.'
  • '; + $message .= '
  • '.$langs->trans('Type').' : '.$object->type_label.'
  • '; + $message .= '
  • '.$langs->trans('Category').' : '.$object->category_label.'
  • '; + $message .= '
  • '.$langs->trans('Severity').' : '.$object->severity_label.'
  • '; + // Extrafields + if (is_array($object->array_options) && count($object->array_options) > 0) { + foreach ($object->array_options as $key => $value) { + $message .= '
  • '.$langs->trans($key).' : '.$value.'
  • '; + } + } + + $message .= '
'; + $message .= '

'.$langs->trans('Message').' :
'.$object->message.'

'; + $message .= '

'.$langs->trans($see_ticket).'

'; + + $from = dolGetFirstLastname($user->firstname, $user->lastname).'<'.$user->email.'>'; + + $message = dol_nl2br($message); + + $old_MAIN_MAIL_AUTOCOPY_TO = null; + if (getDolGlobalString('TICKET_DISABLE_MAIL_AUTOCOPY_TO')) { + $old_MAIN_MAIL_AUTOCOPY_TO = getDolGlobalString('MAIN_MAIL_AUTOCOPY_TO'); + $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; + } + + include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; + $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, '', '', 0, -1); + if ($mailfile->error) { + setEventMessages($mailfile->error, $mailfile->errors, 'errors'); + } else { + $result = $mailfile->sendfile(); + if ($result) { + // update last_msg_sent date + $object->fetch($object->id); + $object->date_last_msg_sent = dol_now(); + $object->update($user); + } + } + if (!getDolUserString('TICKET_DISABLE_MAIL_AUTOCOPY_TO')) { + $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; + } + } } From 37a815af535a485b9865bbedd483eee99c7827a6 Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 2 Jan 2025 14:50:14 +0100 Subject: [PATCH 13/56] Cleaned code --- ...terface_50_modTicket_TicketEmail.class.php | 33 +------------------ 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php b/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php index bead2d3faf6..55f04a9d43e 100644 --- a/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php +++ b/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php @@ -77,48 +77,17 @@ class InterfaceTicketEmail extends DolibarrTriggers if ($res > 0) { // Send email to notification email if (empty($conf->global->TICKET_DISABLE_ALL_MAILS)) { -// Init to avoid errors -// $filepath = array(); -// $filename = array(); -// $mimetype = array(); - // Send email to assigned user -// $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketAssignedToYou'); -// $message = '

'.$langs->transnoentities('TicketAssignedEmailBody', $object->track_id, dolGetFirstLastname($user->firstname, $user->lastname))."

"; -// $message .= '
  • '.$langs->trans('Title').' : '.$object->subject.'
  • '; -// $message .= '
  • '.$langs->trans('Type').' : '.$object->type_label.'
  • '; -// $message .= '
  • '.$langs->trans('Category').' : '.$object->category_label.'
  • '; -// $message .= '
  • '.$langs->trans('Severity').' : '.$object->severity_label.'
  • '; -// // Extrafields -// if (is_array($object->array_options) && count($object->array_options) > 0) { -// foreach ($object->array_options as $key => $value) { -// $message .= '
  • '.$langs->trans($key).' : '.$value.'
  • '; -// } -// } -// -// $message .= '
'; -// $message .= '

'.$langs->trans('Message').' :
'.$object->message.'

'; -// $message .= '

'.$langs->trans('SeeThisTicketIntomanagementInterface').'

'; - $sendto = $userstat->email; $subject_assignee = 'TicketAssignedToYou'; $body_assignee = 'TicketAssignedEmailBody'; $see_ticket_assignee = 'SeeThisTicketIntomanagementInterface'; -// $from = dolGetFirstLastname($user->firstname, $user->lastname).'<'.$user->email.'>'; -// -// $message = dol_nl2br($message); if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; } -// include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; -// $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, '', '', 0, -1); -// if ($mailfile->error) { -// setEventMessages($mailfile->error, $mailfile->errors, 'errors'); -// } else { -// $result = $mailfile->sendfile(); -// } + if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; } From 4c4b773de5797e69e435dbbe89409cf2ca6220d9 Mon Sep 17 00:00:00 2001 From: William Mead Date: Thu, 2 Jan 2025 14:59:44 +0100 Subject: [PATCH 14/56] Fix send on assign --- .../triggers/interface_50_modTicket_TicketEmail.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php b/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php index 55f04a9d43e..00fce02d2c8 100644 --- a/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php +++ b/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php @@ -87,7 +87,9 @@ class InterfaceTicketEmail extends DolibarrTriggers $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; } - + if (!empty($sendto)) { + $this->composeAndSendAssigneeMessage($sendto, $subject_assignee, $body_assignee, $see_ticket_assignee, $object, $langs); + } if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; } From 112220da86222ba4cf9054ac53685c735cc4502d Mon Sep 17 00:00:00 2001 From: tnegre Date: Fri, 3 Jan 2025 10:08:56 +0100 Subject: [PATCH 15/56] BUG: when there are two identical HTML tags in a substitution string, everything is taken between first opening tag and last closing tag. Write test to reproduce. --- test/phpunit/ODFTest.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/test/phpunit/ODFTest.php b/test/phpunit/ODFTest.php index a7d972bf345..a019d5754e2 100644 --- a/test/phpunit/ODFTest.php +++ b/test/phpunit/ODFTest.php @@ -296,33 +296,39 @@ class ODFTest extends PHPUnit\Framework\TestCase 'charset' => null, 'expected' => utf8_encode('text with intricatedtags'), ], + 24 => [ + 'to_convert' => "text with two (strong) tags", + 'encode' => true, + 'charset' => null, + 'expected' => utf8_encode('text with two (strong) tags'), + ], // One can also pass html-encoded string to the method - 24 => [ + 25 => [ 'to_convert' => 'One&two', 'encode' => true, 'charset' => null, 'expected' => 'One&two', ], - 25 => [ + 26 => [ 'to_convert' => "text with <strong>strong, </strong><em>emphasis</em> and <u>underlined</u> words with <i>it@lic sp&ciàlchärs éè l'</i>", 'encode' => false, 'charset' => 'UTF-8', 'expected' => 'text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l\'', ], - 26 => [ + 27 => [ 'to_convert' => "text with <strong>strong, </strong><em>emphasis</em> and <u>underlined</u> words with <i>it@lic sp&ciàlchärs éè l'</i>", 'encode' => true, 'charset' => 'UTF-8', 'expected' => 'text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l'', ], - 27 => [ + 28 => [ 'to_convert' => "text with <strong>strong, </strong><em>emphasis</em> and <u>underlined</u> words with <i>it@lic sp&ciàlchärs éè l'</i>", 'encode' => false, 'charset' => null, 'expected' => utf8_encode('text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l\''), ], - 28 => [ + 29 => [ 'to_convert' => "text with <strong>strong, </strong><em>emphasis</em> and <u>underlined</u> words with <i>it@lic sp&ciàlchärs éè l'</i>", 'encode' => true, 'charset' => null, @@ -341,20 +347,20 @@ class ODFTest extends PHPUnit\Framework\TestCase // Following tests reflect the current behavior. They may evolve if the method behavior changes. // The method removes hyperlinks and tags that are not dealt with. - 29 => [ + 30 => [ 'to_convert' => '123 trucmachin > truc < troc > tracbla bla', 'encode' => true, 'charset' => null, 'expected' => "123 trucmachin > truc < troc > tracbla bla", ], - 30 => [ + 31 => [ 'to_convert' => '123

Title

bla', 'encode' => true, 'charset' => null, 'expected' => "123 Title bla", ], // HTML should not take \n into account, but only
. - 31 => [ + 32 => [ 'to_convert' => "text with strong text , a line\nbreak and underlined words with it@lic sp&ciàlchärs éè l'", 'encode' => false, 'charset' => 'UTF-8', From b31962f7e2835a294d3079985ba2fe3426152e59 Mon Sep 17 00:00:00 2001 From: tnegre Date: Fri, 3 Jan 2025 10:41:35 +0100 Subject: [PATCH 16/56] fix --- htdocs/includes/odtphp/odf.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/includes/odtphp/odf.php b/htdocs/includes/odtphp/odf.php index 5a832234686..17dc178b6a2 100644 --- a/htdocs/includes/odtphp/odf.php +++ b/htdocs/includes/odtphp/odf.php @@ -46,8 +46,8 @@ class Odf public $userdefined=array(); const PIXEL_TO_CM = 0.026458333; - const FIND_TAGS_REGEX = '/<([A-Za-z0-9]+)(?:\s([A-Za-z]+(?:\-[A-Za-z]+)?(?:=(?:".*?")|(?:[0-9]+))))*(?:(?:\s\/>)|(?:>(.*)<\/\1>))/s'; - const FIND_ENCODED_TAGS_REGEX = '/<([A-Za-z]+)(?:\s([A-Za-z]+(?:\-[A-Za-z]+)?(?:=(?:".*?")|(?:[0-9]+))))*(?:(?:\s\/>)|(?:>(.*)<\/\1>))/'; + const FIND_TAGS_REGEX = '/<([A-Za-z0-9]+)(?:\s([A-Za-z]+(?:\-[A-Za-z]+)?(?:=(?:".*?")|(?:[0-9]+))))*(?:(?:\s\/>)|(?:>([^(<\1>)]*)<\/\1>))/s'; + const FIND_ENCODED_TAGS_REGEX = '/<([A-Za-z]+)(?:\s([A-Za-z]+(?:\-[A-Za-z]+)?(?:=(?:".*?")|(?:[0-9]+))))*(?:(?:\s\/>)|(?:>([^(<\1>)]*)<\/\1>))/'; /** @@ -1017,4 +1017,4 @@ IMG; $this->contentXml = preg_replace($searchreg, "", $this->contentXml); return $matches[1]; } -} \ No newline at end of file +} From 61b03b0c0575456e098c2e7a2628ba385c1d179d Mon Sep 17 00:00:00 2001 From: tnegre Date: Fri, 3 Jan 2025 10:50:30 +0100 Subject: [PATCH 17/56] Testing ODF : revert parameters order for assertEquals() --- test/phpunit/ODFTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/phpunit/ODFTest.php b/test/phpunit/ODFTest.php index a019d5754e2..ab1a2c74d48 100644 --- a/test/phpunit/ODFTest.php +++ b/test/phpunit/ODFTest.php @@ -377,7 +377,7 @@ class ODFTest extends PHPUnit\Framework\TestCase } else { $res = $odf->convertVarToOdf($case['to_convert'], $case['encode']); } - $this->assertEquals($res, $case['expected']); + $this->assertEquals($case['expected'], $res); } print __METHOD__." result=".$result."\n"; From 78bf506790c18a227c8b9936919f92e4a0b46df4 Mon Sep 17 00:00:00 2001 From: tnegre Date: Fri, 3 Jan 2025 11:14:17 +0100 Subject: [PATCH 18/56] fix tests in error --- htdocs/includes/odtphp/odf.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/includes/odtphp/odf.php b/htdocs/includes/odtphp/odf.php index 17dc178b6a2..f5678d838a3 100644 --- a/htdocs/includes/odtphp/odf.php +++ b/htdocs/includes/odtphp/odf.php @@ -46,8 +46,8 @@ class Odf public $userdefined=array(); const PIXEL_TO_CM = 0.026458333; - const FIND_TAGS_REGEX = '/<([A-Za-z0-9]+)(?:\s([A-Za-z]+(?:\-[A-Za-z]+)?(?:=(?:".*?")|(?:[0-9]+))))*(?:(?:\s\/>)|(?:>([^(<\1>)]*)<\/\1>))/s'; - const FIND_ENCODED_TAGS_REGEX = '/<([A-Za-z]+)(?:\s([A-Za-z]+(?:\-[A-Za-z]+)?(?:=(?:".*?")|(?:[0-9]+))))*(?:(?:\s\/>)|(?:>([^(<\1>)]*)<\/\1>))/'; + const FIND_TAGS_REGEX = '/<([A-Za-z0-9]+)(?:\s([A-Za-z]+(?:\-[A-Za-z]+)?(?:=(?:".*?")|(?:[0-9]+))))*(?:(?:\s\/>)|(?:>(((?!<\1>).)*)<\/\1>))/s'; + const FIND_ENCODED_TAGS_REGEX = '/<([A-Za-z]+)(?:\s([A-Za-z]+(?:\-[A-Za-z]+)?(?:=(?:".*?")|(?:[0-9]+))))*(?:(?:\s\/>)|(?:>(((?!<\1>).)*)<\/\1>))/'; /** From c218eaa6ed6ca5e97ddbdaa6c68a8934bede5831 Mon Sep 17 00:00:00 2001 From: uvaldenaire-opendsi Date: Tue, 7 Jan 2025 12:10:40 +0100 Subject: [PATCH 19/56] fix join societe_commerciaux in societe list --- htdocs/societe/list.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/htdocs/societe/list.php b/htdocs/societe/list.php index 21e811c25c8..59c79e2ec95 100644 --- a/htdocs/societe/list.php +++ b/htdocs/societe/list.php @@ -516,7 +516,7 @@ if ($search_sale == -2) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid"; //elseif ($search_sale || (empty($user->rights->societe->client->voir) && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->societe->client->readallthirdparties_advance)) && !$socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } elseif (!empty($search_sale) && $search_sale != '-1' || (empty($user->rights->societe->client->voir) && !$socid)) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux AS sc ON s.rowid = sc.fk_soc"; } // Add table from hooks $parameters = array(); @@ -527,9 +527,6 @@ $sql .= " WHERE s.entity IN (".getEntity('societe').")"; if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } -if ($search_sale && $search_sale != '-1' && $search_sale != '-2') { - $sql .= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale -} if (empty($user->rights->fournisseur->lire)) { $sql .= " AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible } From ec58ee940a8de664875d826f2c9ac3eca4b612d5 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:09:48 +0100 Subject: [PATCH 20/56] FIX: product variants copy: also copy multiprice variations --- .../class/ProductCombination.class.php | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php index 42e3bdc1530..fa642dc2765 100644 --- a/htdocs/variants/class/ProductCombination.class.php +++ b/htdocs/variants/class/ProductCombination.class.php @@ -702,16 +702,16 @@ class ProductCombination * [...] * ) * - * @param User $user Object user - * @param Product $product Parent product - * @param array $combinations Attribute and value combinations. - * @param array $variations Price and weight variations - * @param bool|array $price_var_percent Is the price variation a relative variation? - * @param bool|float $forced_pricevar If the price variation is forced - * @param bool|float $forced_weightvar If the weight variation is forced - * @param bool|string $forced_refvar If the reference is forced - * @param string $ref_ext External reference - * @return int <0 KO, >0 OK + * @param User $user Object user + * @param Product $product Parent product + * @param array $combinations Attribute and value combinations. + * @param array $variations Price and weight variations + * @param bool|array $price_var_percent Is the price variation a relative variation? + * @param bool|float|array $forced_pricevar If the price variation is forced + * @param bool|float $forced_weightvar If the weight variation is forced + * @param bool|string $forced_refvar If the reference is forced + * @param string $ref_ext External reference + * @return int <0 KO, >0 OK */ public function createProductCombination(User $user, Product $product, array $combinations, array $variations, $price_var_percent = false, $forced_pricevar = false, $forced_weightvar = false, $forced_refvar = false, $ref_ext = '') { @@ -752,8 +752,8 @@ class ProductCombination $price_impact = $forced_pricevar; } - if (!array($price_var_percent)) { - $price_var_percent[1] = (float) $price_var_percent; + if (!is_array($price_var_percent)) { + $price_var_percent = array(1 => (float) $price_var_percent); } $newcomb = new ProductCombination($this->db); @@ -840,12 +840,7 @@ class ProductCombination $productCombinationLevel->fk_product_attribute_combination = $newcomb->id; $productCombinationLevel->fk_price_level = $i; $productCombinationLevel->variation_price = $price_impact[$i]; - - if (is_array($price_var_percent)) { - $productCombinationLevel->variation_price_percentage = (empty($price_var_percent[$i]) ? false : $price_var_percent[$i]); - } else { - $productCombinationLevel->variation_price_percentage = $price_var_percent; - } + $productCombinationLevel->variation_price_percentage = (empty($price_var_percent[$i]) ? false : $price_var_percent[$i]); $newcomb->combination_price_levels[$i] = $productCombinationLevel; } @@ -955,13 +950,26 @@ class ProductCombination $variations[$tmp_pc2v->fk_prod_attr] = $tmp_pc2v->fk_prod_attr_val; } + $variation_price_percentage = $combination->variation_price_percentage; + $variation_price = $combination->variation_price; + + if (getDolGlobalInt('PRODUIT_MULTIPRICES') && getDolGlobalInt('PRODUIT_MULTIPRICES_LIMIT') > 1) { + $variation_price_percentage = [ ]; + $variation_price = [ ]; + + foreach ($combination->combination_price_levels as $productCombinationLevel) { + $variation_price_percentage[$productCombinationLevel->fk_price_level] = $productCombinationLevel->variation_price_percentage; + $variation_price[$productCombinationLevel->fk_price_level] = $productCombinationLevel->variation_price; + } + } + if ($this->createProductCombination( $user, $destProduct, $variations, array(), - $combination->variation_price_percentage, - $combination->variation_price, + $variation_price_percentage, + $variation_price, $combination->variation_weight ) < 0) { return -1; From 3ef6299c839aa0e1ae473e65942a6ace54dc6644 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:20:57 +0100 Subject: [PATCH 21/56] FIX: phpcs --- htdocs/variants/class/ProductCombination.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php index fa642dc2765..e41325f6efb 100644 --- a/htdocs/variants/class/ProductCombination.class.php +++ b/htdocs/variants/class/ProductCombination.class.php @@ -950,8 +950,8 @@ class ProductCombination $variations[$tmp_pc2v->fk_prod_attr] = $tmp_pc2v->fk_prod_attr_val; } - $variation_price_percentage = $combination->variation_price_percentage; - $variation_price = $combination->variation_price; + $variation_price_percentage = $combination->variation_price_percentage; + $variation_price = $combination->variation_price; if (getDolGlobalInt('PRODUIT_MULTIPRICES') && getDolGlobalInt('PRODUIT_MULTIPRICES_LIMIT') > 1) { $variation_price_percentage = [ ]; From ef564caf28bafb827aec71697e58f2a0e4302fca Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:37:30 +0100 Subject: [PATCH 22/56] FIX: qual --- htdocs/variants/class/ProductCombination.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php index e41325f6efb..163ea7be5bd 100644 --- a/htdocs/variants/class/ProductCombination.class.php +++ b/htdocs/variants/class/ProductCombination.class.php @@ -753,7 +753,7 @@ class ProductCombination } if (!is_array($price_var_percent)) { - $price_var_percent = array(1 => (float) $price_var_percent); + $price_var_percent = array(1 => (bool) $price_var_percent); } $newcomb = new ProductCombination($this->db); @@ -840,7 +840,7 @@ class ProductCombination $productCombinationLevel->fk_product_attribute_combination = $newcomb->id; $productCombinationLevel->fk_price_level = $i; $productCombinationLevel->variation_price = $price_impact[$i]; - $productCombinationLevel->variation_price_percentage = (empty($price_var_percent[$i]) ? false : $price_var_percent[$i]); + $productCombinationLevel->variation_price_percentage = $price_var_percent[$i]; $newcomb->combination_price_levels[$i] = $productCombinationLevel; } From 7e82f70c77aa42718cb6009d72cb5d806ca7175e Mon Sep 17 00:00:00 2001 From: tnegre Date: Thu, 9 Jan 2025 11:05:45 +0100 Subject: [PATCH 23/56] add case when HTML tags contain attributes --- htdocs/includes/odtphp/odf.php | 4 ++-- test/phpunit/ODFTest.php | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/htdocs/includes/odtphp/odf.php b/htdocs/includes/odtphp/odf.php index f5678d838a3..39f595f4934 100644 --- a/htdocs/includes/odtphp/odf.php +++ b/htdocs/includes/odtphp/odf.php @@ -46,8 +46,8 @@ class Odf public $userdefined=array(); const PIXEL_TO_CM = 0.026458333; - const FIND_TAGS_REGEX = '/<([A-Za-z0-9]+)(?:\s([A-Za-z]+(?:\-[A-Za-z]+)?(?:=(?:".*?")|(?:[0-9]+))))*(?:(?:\s\/>)|(?:>(((?!<\1>).)*)<\/\1>))/s'; - const FIND_ENCODED_TAGS_REGEX = '/<([A-Za-z]+)(?:\s([A-Za-z]+(?:\-[A-Za-z]+)?(?:=(?:".*?")|(?:[0-9]+))))*(?:(?:\s\/>)|(?:>(((?!<\1>).)*)<\/\1>))/'; + const FIND_TAGS_REGEX = '/<([A-Za-z0-9]+)(?:\s([A-Za-z]+(?:\-[A-Za-z]+)?(?:=(?:".*?")|(?:[0-9]+))))*(?:(?:\s\/>)|(?:>(((?!<\1(\s.*)?>).)*)<\/\1>))/s'; + const FIND_ENCODED_TAGS_REGEX = '/<([A-Za-z]+)(?:\s([A-Za-z]+(?:\-[A-Za-z]+)?(?:=(?:".*?")|(?:[0-9]+))))*(?:(?:\s\/>)|(?:>(((?!<\1(\s.*)?>).)*)<\/\1>))/'; /** diff --git a/test/phpunit/ODFTest.php b/test/phpunit/ODFTest.php index ab1a2c74d48..2badd77baf6 100644 --- a/test/phpunit/ODFTest.php +++ b/test/phpunit/ODFTest.php @@ -302,33 +302,39 @@ class ODFTest extends PHPUnit\Framework\TestCase 'charset' => null, 'expected' => utf8_encode('text with two (strong) tags'), ], + 25 => [ + 'to_convert' => "text with two (strong) tags and intricated underline ", + 'encode' => true, + 'charset' => null, + 'expected' => utf8_encode('text with two (strong) tags and intricated underline '), + ], // One can also pass html-encoded string to the method - 25 => [ + 26 => [ 'to_convert' => 'One&two', 'encode' => true, 'charset' => null, 'expected' => 'One&two', ], - 26 => [ + 27 => [ 'to_convert' => "text with <strong>strong, </strong><em>emphasis</em> and <u>underlined</u> words with <i>it@lic sp&ciàlchärs éè l'</i>", 'encode' => false, 'charset' => 'UTF-8', 'expected' => 'text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l\'', ], - 27 => [ + 28 => [ 'to_convert' => "text with <strong>strong, </strong><em>emphasis</em> and <u>underlined</u> words with <i>it@lic sp&ciàlchärs éè l'</i>", 'encode' => true, 'charset' => 'UTF-8', 'expected' => 'text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l'', ], - 28 => [ + 29 => [ 'to_convert' => "text with <strong>strong, </strong><em>emphasis</em> and <u>underlined</u> words with <i>it@lic sp&ciàlchärs éè l'</i>", 'encode' => false, 'charset' => null, 'expected' => utf8_encode('text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l\''), ], - 29 => [ + 30 => [ 'to_convert' => "text with <strong>strong, </strong><em>emphasis</em> and <u>underlined</u> words with <i>it@lic sp&ciàlchärs éè l'</i>", 'encode' => true, 'charset' => null, @@ -347,20 +353,20 @@ class ODFTest extends PHPUnit\Framework\TestCase // Following tests reflect the current behavior. They may evolve if the method behavior changes. // The method removes hyperlinks and tags that are not dealt with. - 30 => [ + 31 => [ 'to_convert' => '123 trucmachin > truc < troc > tracbla bla', 'encode' => true, 'charset' => null, 'expected' => "123 trucmachin > truc < troc > tracbla bla", ], - 31 => [ + 32 => [ 'to_convert' => '123

Title

bla', 'encode' => true, 'charset' => null, 'expected' => "123 Title bla", ], // HTML should not take \n into account, but only
. - 32 => [ + 33 => [ 'to_convert' => "text with strong text , a line\nbreak and underlined words with it@lic sp&ciàlchärs éè l'", 'encode' => false, 'charset' => 'UTF-8', From 77f982d1a8c3fa490c40c95e06d39f51731da055 Mon Sep 17 00:00:00 2001 From: atm-florian Date: Fri, 10 Jan 2025 16:25:27 +0100 Subject: [PATCH 24/56] FIX 17.0 - collisions in cache for dol_getIdFromCode --- htdocs/core/lib/functions.lib.php | 49 ++++++++++++++++--------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 7fe94ff83c4..61bb1c78a2e 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -8876,12 +8876,13 @@ function dol_osencode($str) * @param string $fieldid Field to get * @param int $entityfilter Filter by entity * @param string $filters Filters to add. WARNING: string must be escaped for SQL and not coming from user input. + * @param bool $useCache If true (default), cache will be queried and updated. * @return int <0 if KO, Id of code if OK * @see $langs->getLabelFromKey */ -function dol_getIdFromCode($db, $key, $tablename, $fieldkey = 'code', $fieldid = 'id', $entityfilter = 0, $filters = '') +function dol_getIdFromCode($db, $key, $tablename, $fieldkey = 'code', $fieldid = 'id', $entityfilter = 0, $filters = '', $useCache = true) { - global $cache_codes; + static $cache_codes = array(); // If key empty if ($key == '') { @@ -8889,8 +8890,8 @@ function dol_getIdFromCode($db, $key, $tablename, $fieldkey = 'code', $fieldid = } // Check in cache - if (isset($cache_codes[$tablename][$key][$fieldid])) { // Can be defined to 0 or '' - return $cache_codes[$tablename][$key][$fieldid]; // Found in cache + if ($useCache && isset($cache_codes[$tablename][$fieldkey][$fieldid][$entityfilter][$filters][$key])) { // Can be defined to 0 or '' + return $cache_codes[$tablename][$fieldkey][$fieldid][$entityfilter][$filters][$key]; // Found in cache } dol_syslog('dol_getIdFromCode (value for field '.$fieldid.' from key '.$key.' not found into cache)', LOG_DEBUG); @@ -8908,13 +8909,15 @@ function dol_getIdFromCode($db, $key, $tablename, $fieldkey = 'code', $fieldid = $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); + $valuetoget = ''; if ($obj) { - $cache_codes[$tablename][$key][$fieldid] = $obj->valuetoget; - } else { - $cache_codes[$tablename][$key][$fieldid] = ''; + $valuetoget = $obj->valuetoget; } $db->free($resql); - return $cache_codes[$tablename][$key][$fieldid]; + if ($useCache) { + $cache_codes[$tablename][$fieldkey][$fieldid][$entityfilter][$filters][$key] = $valuetoget; + } + return $valuetoget; } else { return -1; } @@ -10839,21 +10842,21 @@ function dolGetStatus($statusLabel = '', $statusLabelShort = '', $html = '', $st * @param int|boolean $userRight User action right * // phpcs:disable * @param array $params = [ // Various params for future : recommended rather than adding more function arguments - * 'attr' => [ // to add or override button attributes - * 'xxxxx' => '', // your xxxxx attribute you want - * 'class' => 'reposition', // to add more css class to the button class attribute - * 'classOverride' => '' // to replace class attribute of the button - * ], - * 'confirm' => [ - * 'url' => 'http://', // Overide Url to go when user click on action btn, if empty default url is $url.?confirm=yes, for no js compatibility use $url for fallback confirm. - * 'title' => '', // Overide title of modal, if empty default title use "ConfirmBtnCommonTitle" lang key - * 'action-btn-label' => '', // Overide label of action button, if empty default label use "Confirm" lang key - * 'cancel-btn-label' => '', // Overide label of cancel button, if empty default label use "CloseDialog" lang key - * 'content' => '', // Overide text of content, if empty default content use "ConfirmBtnCommonContent" lang key - * 'modal' => true, // true|false to display dialog as a modal (with dark background) - * 'isDropDrown' => false, // true|false to display dialog as a dropdown (with dark background) - * ], - * ] + * 'attr' => [ // to add or override button attributes + * 'xxxxx' => '', // your xxxxx attribute you want + * 'class' => 'reposition', // to add more css class to the button class attribute + * 'classOverride' => '' // to replace class attribute of the button + * ], + * 'confirm' => [ + * 'url' => 'http://', // Overide Url to go when user click on action btn, if empty default url is $url.?confirm=yes, for no js compatibility use $url for fallback confirm. + * 'title' => '', // Overide title of modal, if empty default title use "ConfirmBtnCommonTitle" lang key + * 'action-btn-label' => '', // Overide label of action button, if empty default label use "Confirm" lang key + * 'cancel-btn-label' => '', // Overide label of cancel button, if empty default label use "CloseDialog" lang key + * 'content' => '', // Overide text of content, if empty default content use "ConfirmBtnCommonContent" lang key + * 'modal' => true, // true|false to display dialog as a modal (with dark background) + * 'isDropDrown' => false, // true|false to display dialog as a dropdown (with dark background) + * ], + * ] * // phpcs:enable * @return string html button */ From 762e4ec8d1c720785a4f4adb309798acd7f12959 Mon Sep 17 00:00:00 2001 From: atm-florian Date: Fri, 10 Jan 2025 17:01:59 +0100 Subject: [PATCH 25/56] updated local pre-commit hook -> fix typo --- htdocs/core/lib/functions.lib.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 61bb1c78a2e..610e19b293a 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -10848,11 +10848,11 @@ function dolGetStatus($statusLabel = '', $statusLabelShort = '', $html = '', $st * 'classOverride' => '' // to replace class attribute of the button * ], * 'confirm' => [ - * 'url' => 'http://', // Overide Url to go when user click on action btn, if empty default url is $url.?confirm=yes, for no js compatibility use $url for fallback confirm. - * 'title' => '', // Overide title of modal, if empty default title use "ConfirmBtnCommonTitle" lang key - * 'action-btn-label' => '', // Overide label of action button, if empty default label use "Confirm" lang key - * 'cancel-btn-label' => '', // Overide label of cancel button, if empty default label use "CloseDialog" lang key - * 'content' => '', // Overide text of content, if empty default content use "ConfirmBtnCommonContent" lang key + * 'url' => 'http://', // Override Url to go when user click on action btn, if empty default url is $url.?confirm=yes, for no js compatibility use $url for fallback confirm. + * 'title' => '', // Override title of modal, if empty default title use "ConfirmBtnCommonTitle" lang key + * 'action-btn-label' => '', // Override label of action button, if empty default label use "Confirm" lang key + * 'cancel-btn-label' => '', // Override label of cancel button, if empty default label use "CloseDialog" lang key + * 'content' => '', // Override text of content, if empty default content use "ConfirmBtnCommonContent" lang key * 'modal' => true, // true|false to display dialog as a modal (with dark background) * 'isDropDrown' => false, // true|false to display dialog as a dropdown (with dark background) * ], From e53260c00b129d5ad63c91eabf338bb48f570d7e Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 11 Jan 2025 07:55:52 +0100 Subject: [PATCH 26/56] VAT - Edit look --- htdocs/admin/dict.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 360488a2410..fdd05bfcb00 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -2786,12 +2786,11 @@ function dictFieldList($fieldlist, $obj = null, $tabname = '', $context = '') print ''; } elseif ($value == 'department_buyer') { if ($context == 'edit') { - print ''; + print ''; // show department buyer list $country_code = (!empty($obj->country_code) ? $obj->country_code : ''); $department_buyer_id = (!empty($obj->department_buyer_id) ? (int) $obj->department_buyer_id : 0); if ($country_code != '') { - print img_picto('', 'state', 'class="pictofixedwidth"'); print $formcompany->select_state($department_buyer_id, $country_code, 'department_buyer_id', 'minwidth100 maxwidth150 maxwidthonsmartphone'); } print ''; From 24eef4d54c38648b1df2c70051a8906a8aadba1e Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 12 Jan 2025 05:34:53 +0100 Subject: [PATCH 27/56] Fix phpstan & phan --- htdocs/core/lib/security.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index 6a0e5de24da..c5208330d5f 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -245,7 +245,7 @@ function dolDecrypt($chain, $key = '') * Use 'md5' if hash is not needed for security purpose. For security need, prefer 'auto'. * @param int $nosalt Do not include any salt * @param int $mode 0=Return encoded password, 1=Return array with encoding password + encoding algorithm - * @return string|array Hash of string or array with pass_encrypted and pass_encoding + * @return string|array{pass_encrypted:string,pass_encoding:string} Hash of string or array with pass_encrypted and pass_encoding * @see getRandomPassword(), dol_verifyHash() */ function dol_hash($chain, $type = '0', $nosalt = 0, $mode = 0) From ac1077bfe32712d293527f9b22dc4c8f2d934041 Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Tue, 14 Jan 2025 09:48:13 +0100 Subject: [PATCH 28/56] FIX : There were many status indicator in the invoice linked object block (propal card) --- htdocs/compta/facture/tpl/linkedobjectblock.tpl.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/htdocs/compta/facture/tpl/linkedobjectblock.tpl.php b/htdocs/compta/facture/tpl/linkedobjectblock.tpl.php index c002e5a7e5f..071403509dd 100644 --- a/htdocs/compta/facture/tpl/linkedobjectblock.tpl.php +++ b/htdocs/compta/facture/tpl/linkedobjectblock.tpl.php @@ -89,11 +89,8 @@ foreach ($linkedObjectBlock as $key => $objectlink) { $totalallpayments = 0; $totalcalculated = false; if (method_exists($objectlink, 'getSommePaiement')) { - print $objectlink->getLibStatut(3, $objectlink->getSommePaiement()); $totalcalculated = true; $totalallpayments += $objectlink->getSommePaiement(); - } else { - print $objectlink->getLibStatut(3); } if (method_exists($objectlink, 'getSumDepositsUsed')) { $totalcalculated = true; From 79c55149b2ffc99b7f7178087bb305f77b736cd7 Mon Sep 17 00:00:00 2001 From: Florian Mortgat <50440633+atm-florianm@users.noreply.github.com> Date: Tue, 14 Jan 2025 11:00:38 +0100 Subject: [PATCH 29/56] Update htdocs/core/lib/functions.lib.php --- htdocs/core/lib/functions.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 610e19b293a..621b0987b08 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -8882,7 +8882,7 @@ function dol_osencode($str) */ function dol_getIdFromCode($db, $key, $tablename, $fieldkey = 'code', $fieldid = 'id', $entityfilter = 0, $filters = '', $useCache = true) { - static $cache_codes = array(); + global $cache_codes; // If key empty if ($key == '') { From df992477be752c137e09a3ff9b5455292972c7fd Mon Sep 17 00:00:00 2001 From: atm-florian Date: Tue, 14 Jan 2025 14:34:09 +0100 Subject: [PATCH 30/56] Apply suggestion by @mdeweerd to ensure pre-commit will pass. --- .../DataCollector/PDO/TraceablePDO.php | 88 +++++++++++-------- 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/htdocs/includes/maximebf/debugbar/src/DebugBar/DataCollector/PDO/TraceablePDO.php b/htdocs/includes/maximebf/debugbar/src/DebugBar/DataCollector/PDO/TraceablePDO.php index e448a794ad3..753964a343c 100644 --- a/htdocs/includes/maximebf/debugbar/src/DebugBar/DataCollector/PDO/TraceablePDO.php +++ b/htdocs/includes/maximebf/debugbar/src/DebugBar/DataCollector/PDO/TraceablePDO.php @@ -23,13 +23,13 @@ class TraceablePDO extends PDO $this->pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, [TraceablePDOStatement::class, [$this]]); } - /** - * Initiates a transaction - * - * @link http://php.net/manual/en/pdo.begintransaction.php - * @return bool TRUE on success or FALSE on failure. - */ - public function beginTransaction() + /** + * Initiates a transaction + * + * @link http://php.net/manual/en/pdo.begintransaction.php + * @return bool TRUE on success or FALSE on failure. + */ + public function beginTransaction() : bool { return $this->pdo->beginTransaction(); } @@ -40,7 +40,7 @@ class TraceablePDO extends PDO * @link http://php.net/manual/en/pdo.commit.php * @return bool TRUE on success or FALSE on failure. */ - public function commit() + public function commit() : bool { return $this->pdo->commit(); } @@ -51,6 +51,7 @@ class TraceablePDO extends PDO * @link http://php.net/manual/en/pdo.errorinfo.php * @return array PDO::errorInfo returns an array of error information */ + #[\ReturnTypeWillChange] public function errorCode() { return $this->pdo->errorCode(); @@ -62,7 +63,7 @@ class TraceablePDO extends PDO * @link http://php.net/manual/en/pdo.errorinfo.php * @return array PDO::errorInfo returns an array of error information */ - public function errorInfo() + public function errorInfo() : array { return $this->pdo->errorInfo(); } @@ -77,6 +78,7 @@ class TraceablePDO extends PDO * return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. * Please read the section on Booleans for more information */ + #[\ReturnTypeWillChange] public function exec($statement) { return $this->profileCall('exec', $statement, func_get_args()); @@ -90,6 +92,7 @@ class TraceablePDO extends PDO * @return mixed A successful call returns the value of the requested PDO attribute. * An unsuccessful call returns null. */ + #[\ReturnTypeWillChange] public function getAttribute($attribute) { return $this->pdo->getAttribute($attribute); @@ -101,7 +104,7 @@ class TraceablePDO extends PDO * @link http://php.net/manual/en/pdo.intransaction.php * @return bool TRUE if a transaction is currently active, and FALSE if not. */ - public function inTransaction() + public function inTransaction() : bool { return $this->pdo->inTransaction(); } @@ -114,36 +117,41 @@ class TraceablePDO extends PDO * @return string If a sequence name was not specified for the name parameter, PDO::lastInsertId * returns a string representing the row ID of the last row that was inserted into the database. */ + #[\ReturnTypeWillChange] public function lastInsertId($name = null) { return $this->pdo->lastInsertId($name); } - /** - * Prepares a statement for execution and returns a statement object - * - * @link http://php.net/manual/en/pdo.prepare.php - * @param string $statement This must be a valid SQL statement template for the target DB server. - * @param array $driver_options [optional] This array holds one or more key=>value pairs to - * set attribute values for the PDOStatement object that this method returns. - * @return TraceablePDOStatement|bool If the database server successfully prepares the statement, - * PDO::prepare returns a PDOStatement object. If the database server cannot successfully prepare - * the statement, PDO::prepare returns FALSE or emits PDOException (depending on error handling). - */ + /** + * Prepares a statement for execution and returns a statement object + * + * @link http://php.net/manual/en/pdo.prepare.php + * @param string $statement This must be a valid SQL statement template for the target DB server. + * @param array $driver_options [optional] This array holds one or more key=>value pairs to + * set attribute values for the PDOStatement object that this method returns. + * @return TraceablePDOStatement|bool If the database server successfully prepares the statement, + * PDO::prepare returns a PDOStatement object. If the database server cannot successfully prepare + * the statement, PDO::prepare returns FALSE or emits PDOException (depending on error handling). + */ + #[\ReturnTypeWillChange] public function prepare($statement, $driver_options = []) { return $this->pdo->prepare($statement, $driver_options); } - /** - * Executes an SQL statement, returning a result set as a PDOStatement object - * - * @link http://php.net/manual/en/pdo.query.php - * @param string $statement - * @return TraceablePDOStatement|bool PDO::query returns a PDOStatement object, or FALSE on - * failure. - */ - public function query($statement) + /** + * Executes an SQL statement, returning a result set as a PDOStatement object + * + * @link http://php.net/manual/en/pdo.query.php + * @param string $statement + * @param int $fetchMode + * @param mixed ...$fetchModeArgs + * @return TraceablePDOStatement|bool PDO::query returns a PDOStatement object, or FALSE on + * failure. + */ + #[\ReturnTypeWillChange] + public function query($statement, $fetchMode = null, ...$fetchModeArgs) { return $this->profileCall('query', $statement, func_get_args()); } @@ -158,6 +166,7 @@ class TraceablePDO extends PDO * @return string|bool A quoted string that is theoretically safe to pass into an SQL statement. * Returns FALSE if the driver does not support quoting in this way. */ + #[\ReturnTypeWillChange] public function quote($string, $parameter_type = PDO::PARAM_STR) { return $this->pdo->quote($string, $parameter_type); @@ -169,7 +178,7 @@ class TraceablePDO extends PDO * @link http://php.net/manual/en/pdo.rollback.php * @return bool TRUE on success or FALSE on failure. */ - public function rollBack() + public function rollBack() : bool { return $this->pdo->rollBack(); } @@ -182,7 +191,7 @@ class TraceablePDO extends PDO * @param mixed $value * @return bool TRUE on success or FALSE on failure. */ - public function setAttribute($attribute, $value) + public function setAttribute($attribute, $value) : bool { return $this->pdo->setAttribute($attribute, $value); } @@ -195,6 +204,7 @@ class TraceablePDO extends PDO * @param array $args * @return mixed The result of the call */ + #[\ReturnTypeWillChange] protected function profileCall($method, $sql, array $args) { $trace = new TracedStatement($sql); @@ -226,7 +236,7 @@ class TraceablePDO extends PDO * * @param TracedStatement $stmt */ - public function addExecutedStatement(TracedStatement $stmt) + public function addExecutedStatement(TracedStatement $stmt) : void { $this->executedStatements[] = $stmt; } @@ -234,9 +244,9 @@ class TraceablePDO extends PDO /** * Returns the accumulated execution time of statements * - * @return int + * @return float */ - public function getAccumulatedStatementsDuration() + public function getAccumulatedStatementsDuration() : float { return array_reduce($this->executedStatements, function ($v, $s) { return $v + $s->getDuration(); }); } @@ -246,7 +256,7 @@ class TraceablePDO extends PDO * * @return int */ - public function getMemoryUsage() + public function getMemoryUsage() : int { return array_reduce($this->executedStatements, function ($v, $s) { return $v + $s->getMemoryUsage(); }); } @@ -256,7 +266,7 @@ class TraceablePDO extends PDO * * @return int */ - public function getPeakMemoryUsage() + public function getPeakMemoryUsage() : int { return array_reduce($this->executedStatements, function ($v, $s) { $m = $s->getEndMemory(); return $m > $v ? $m : $v; }); } @@ -266,7 +276,7 @@ class TraceablePDO extends PDO * * @return TracedStatement[] */ - public function getExecutedStatements() + public function getExecutedStatements() : array { return $this->executedStatements; } @@ -276,7 +286,7 @@ class TraceablePDO extends PDO * * @return TracedStatement[] */ - public function getFailedExecutedStatements() + public function getFailedExecutedStatements() : array { return array_filter($this->executedStatements, function ($s) { return !$s->isSuccess(); }); } From 79ed9c7e370cec7000434bcc7c6fdfccc4d55d40 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 14 Jan 2025 16:08:40 +0100 Subject: [PATCH 31/56] fix: add entity in where for fetch when fetch by ref --- htdocs/expensereport/class/expensereport.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 8af62d14736..32dc9b9a25b 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -619,6 +619,7 @@ class ExpenseReport extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as d"; if ($ref) { $sql .= " WHERE d.ref = '".$this->db->escape($ref)."'"; + $sql .= " WHERE d.entity IN (".getEntity('expensereport').")"; } else { $sql .= " WHERE d.rowid = ".((int) $id); } From a34eaa07ed7a7491c82ddb92246c429487ccdf85 Mon Sep 17 00:00:00 2001 From: Irvine Fleith Date: Tue, 14 Jan 2025 16:19:52 +0100 Subject: [PATCH 32/56] fix(services-list): search thirdparty by name --- htdocs/contrat/services_list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/contrat/services_list.php b/htdocs/contrat/services_list.php index 21f49ebc789..7b75c4aa9d3 100644 --- a/htdocs/contrat/services_list.php +++ b/htdocs/contrat/services_list.php @@ -281,7 +281,7 @@ if ($filter == "notexpired") { $sql .= " AND cd.date_fin_validite >= '".$db->idate($now)."'"; } if ($search_name) { - $sql .= natural_search("c.ref", $search_name); + $sql .= natural_search("s.nom", $search_name); } if ($search_contract) { $sql .= natural_search("c.ref", $search_contract); From 2d1d6f13c9b4fe4c0fe3fb705fd9e17a071b3f26 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Wed, 15 Jan 2025 09:10:11 +0100 Subject: [PATCH 33/56] chore: review --- htdocs/expensereport/class/expensereport.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 32dc9b9a25b..0a4e590ca79 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -619,7 +619,7 @@ class ExpenseReport extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as d"; if ($ref) { $sql .= " WHERE d.ref = '".$this->db->escape($ref)."'"; - $sql .= " WHERE d.entity IN (".getEntity('expensereport').")"; + $sql .= " AND d.entity IN (".getEntity('expensereport').")"; } else { $sql .= " WHERE d.rowid = ".((int) $id); } From 748dcd088136882906f855de955e1d4a882721d5 Mon Sep 17 00:00:00 2001 From: uvaldenaire-opendsi Date: Wed, 15 Jan 2025 10:12:16 +0100 Subject: [PATCH 34/56] FIX selectcontact is loading all contacts if socid is empty and MAIN_ACTIONCOM_CAN_ADD_ANY_CONTACT is not set --- htdocs/comm/action/card.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 0310ac0b225..681a977adb1 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -1670,7 +1670,12 @@ if ($id > 0) { // related contact print ''.$langs->trans("ActionOnContact").''; print '
'; - print img_picto('', 'contact', 'class="paddingrightonly"').$form->selectcontacts($object->socid, array_keys($object->socpeopleassigned), 'socpeopleassigned[]', 1, '', '', 1, 'quatrevingtpercent', false, 0, 0, array(), 'multiple', 'contactid'); + if (getDolGlobalInt('MAIN_ACTIONCOM_CAN_ADD_ANY_CONTACT')) { + $select_contact_default = 0; // select "all" contacts by default : avoid to use it if there is a lot of contacts + } else { + $select_contact_default = -1; // select "none" by default + } + print img_picto('', 'contact', 'class="paddingrightonly"').$form->selectcontacts(!empty($object->socid) ? $object->socid : $select_contact_default, array_keys($object->socpeopleassigned), 'socpeopleassigned[]', 1, '', '', 1, 'quatrevingtpercent', false, 0, 0, array(), 'multiple', 'contactid'); print '
'; print ''; print ''; From 628189f57f6ecdd89d27d29df65ee35d5a9fd627 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 23 May 2022 00:49:59 +0200 Subject: [PATCH 35/56] Backport of #00e65eb Fix bad management when inserting contacts of actioncomm --- htdocs/comm/action/class/actioncomm.class.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 9b006c83ab6..9e1e471bbd3 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1203,11 +1203,14 @@ class ActionComm extends CommonObject if (!empty($this->socpeopleassigned)) { $already_inserted = array(); - foreach (array_keys($this->socpeopleassigned) as $id) { + foreach (array_keys($this->socpeopleassigned) as $key => $val) { + if (!is_array($val)) { // For backward compatibility when val=id + $val = array('id'=>$val); + } if (!empty($already_inserted[$val['id']])) continue; $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)"; - $sql .= " VALUES(".$this->id.", 'socpeople', ".$id.", 0, 0, 0)"; + $sql .= " VALUES(".((int) $this->id).", 'socpeople', ".((int) $val['id']).", 0, 0, 0)"; $resql = $this->db->query($sql); if (!$resql) { From 351a7bd6bb81b07b058585e852cbce1bc386c5f2 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Wed, 15 Jan 2025 19:01:18 +0100 Subject: [PATCH 36/56] FIX: #26250 fatal error on kit --- htdocs/product/class/product.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index e289762d2a5..ea9c7f6b830 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -5016,7 +5016,8 @@ class Product extends CommonObject //$prods[$this->db->escape($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty'],2=>$rec['fk_product_type']); //$prods[$this->db->escape($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty']); if (empty($firstlevelonly)) { - $listofchilds = $this->getChildsArbo($rec['rowid'], 0, $level + 1, array_push($parents, $rec['rowid'])); + array_push($parents, $rec['rowid']); + $listofchilds = $this->getChildsArbo($rec['rowid'], 0, $level + 1, $parents); foreach ($listofchilds as $keyChild => $valueChild) { $prods[$rec['rowid']]['childs'][$keyChild] = $valueChild; } From bd35af136098dc6a6881110ee07b284c4945b233 Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Wed, 15 Jan 2025 20:07:31 +0100 Subject: [PATCH 37/56] Fix phpunit --- htdocs/core/lib/pdf.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index d6a22f64de5..44ff8a217c9 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -36,7 +36,7 @@ */ include_once DOL_DOCUMENT_ROOT.'/core/lib/signature.lib.php'; - + /** * Return array head with list of tabs to view object informations. From 8b7eaf360e58693a9365544cb1520f28ced7e626 Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Wed, 15 Jan 2025 20:08:13 +0100 Subject: [PATCH 38/56] Fix phpunit --- htdocs/core/lib/pdf.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 42fee8bfa7b..163fdefb2b0 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1426,7 +1426,7 @@ function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, //id $idprod = (!empty($object->lines[$i]->fk_product) ? $object->lines[$i]->fk_product : false); - if($idprod) { + if ($idprod) { $prodser->fetch($idprod); //load multilangs if($multilangsactive){ From c4529ed9869b59d4f34865e79dd5ad419a45c204 Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Thu, 16 Jan 2025 00:35:38 +0100 Subject: [PATCH 39/56] Clean file --- htdocs/core/lib/pdf.lib.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 163fdefb2b0..c2078f2c74a 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -36,7 +36,7 @@ */ include_once DOL_DOCUMENT_ROOT.'/core/lib/signature.lib.php'; - + /** * Return array head with list of tabs to view object informations. @@ -1412,8 +1412,8 @@ function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $multilangsactive = getDolGlobalInt('MAIN_MULTILANGS'); - if ($issupplierline) { - include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; + if ($issupplierline) { + include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; $prodser = new ProductFournisseur($db); } else { include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; @@ -1429,7 +1429,7 @@ function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, if ($idprod) { $prodser->fetch($idprod); //load multilangs - if($multilangsactive){ + if ($multilangsactive) { $prodser->getMultiLangs(); $object->lines[$i]->multilangs = $prodser->multilangs; } From c2c3879032ac2fe80e397835b2d784168b0f5d57 Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Thu, 16 Jan 2025 00:36:56 +0100 Subject: [PATCH 40/56] Clean php file --- htdocs/core/lib/pdf.lib.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index c2078f2c74a..7bb8e4d8a1e 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1414,26 +1414,26 @@ function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, if ($issupplierline) { include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; - $prodser = new ProductFournisseur($db); - } else { - include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; - $prodser = new Product($db); + $prodser = new ProductFournisseur($db); + } else { + include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + $prodser = new Product($db); - if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { - include_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php'; - } - } + if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { + include_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php'; + } + } //id $idprod = (!empty($object->lines[$i]->fk_product) ? $object->lines[$i]->fk_product : false); - if ($idprod) { - $prodser->fetch($idprod); - //load multilangs - if ($multilangsactive) { - $prodser->getMultiLangs(); - $object->lines[$i]->multilangs = $prodser->multilangs; - } - } + if ($idprod) { + $prodser->fetch($idprod); + //load multilangs + if ($multilangsactive) { + $prodser->getMultiLangs(); + $object->lines[$i]->multilangs = $prodser->multilangs; + } + } //label if (!empty($object->lines[$i]->label)) { $label = $object->lines[$i]->label; From ba4e97f07bb69031deefd9f5fffbb86869bcf609 Mon Sep 17 00:00:00 2001 From: atm-florian Date: Thu, 16 Jan 2025 10:37:29 +0100 Subject: [PATCH 41/56] FIX 17.0 API endpoints "PUT": prevent overwriting all extrafields if only some are supplied in the request cf. PR #29237 + security for Tickets API: disable updating rowid --- htdocs/adherents/class/api_members.class.php | 6 ++++++ htdocs/adherents/class/api_memberstypes.class.php | 6 ++++++ htdocs/adherents/class/api_subscriptions.class.php | 6 ++++++ htdocs/bom/class/api_boms.class.php | 6 ++++++ htdocs/categories/class/api_categories.class.php | 6 ++++++ htdocs/comm/action/class/api_agendaevents.class.php | 6 ++++++ htdocs/comm/propal/class/api_proposals.class.php | 6 ++++++ htdocs/commande/class/api_orders.class.php | 6 ++++++ htdocs/compta/bank/class/api_bankaccounts.class.php | 6 ++++++ htdocs/compta/facture/class/api_invoices.class.php | 6 ++++++ htdocs/contrat/class/api_contracts.class.php | 6 ++++++ htdocs/don/class/api_donations.class.php | 6 ++++++ htdocs/expedition/class/api_shipments.class.php | 6 ++++++ htdocs/expensereport/class/api_expensereports.class.php | 6 ++++++ htdocs/fourn/class/api_supplier_invoices.class.php | 6 ++++++ htdocs/fourn/class/api_supplier_orders.class.php | 6 ++++++ .../class/api_knowledgemanagement.class.php | 6 ++++++ .../modulebuilder/template/class/api_mymodule.class.php | 6 ++++++ htdocs/mrp/class/api_mos.class.php | 6 ++++++ htdocs/partnership/class/api_partnership.class.php | 6 ++++++ htdocs/product/class/api_products.class.php | 6 ++++++ htdocs/product/stock/class/api_warehouses.class.php | 6 ++++++ htdocs/projet/class/api_projects.class.php | 6 ++++++ htdocs/projet/class/api_tasks.class.php | 6 ++++++ htdocs/reception/class/api_receptions.class.php | 6 ++++++ htdocs/societe/class/api_contacts.class.php | 6 ++++++ htdocs/societe/class/api_thirdparties.class.php | 6 ++++++ htdocs/ticket/class/api_tickets.class.php | 9 +++++++++ htdocs/user/class/api_users.class.php | 6 ++++++ 29 files changed, 177 insertions(+) diff --git a/htdocs/adherents/class/api_members.class.php b/htdocs/adherents/class/api_members.class.php index 4ecf79d9079..a224bbdda44 100644 --- a/htdocs/adherents/class/api_members.class.php +++ b/htdocs/adherents/class/api_members.class.php @@ -348,6 +348,12 @@ class Members extends DolibarrApi } } } else { + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $member->array_options[$index] = $this->_checkValForAPI($field, $val, $member); + } + continue; + } $member->$field = $value; } } diff --git a/htdocs/adherents/class/api_memberstypes.class.php b/htdocs/adherents/class/api_memberstypes.class.php index 8179612d769..46443b7b063 100644 --- a/htdocs/adherents/class/api_memberstypes.class.php +++ b/htdocs/adherents/class/api_memberstypes.class.php @@ -193,6 +193,12 @@ class MembersTypes extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $membertype->array_options[$index] = $this->_checkValForAPI($field, $val, $membertype); + } + continue; + } // Process the status separately because it must be updated using // the validate(), resiliate() and exclude() methods of the class AdherentType. $membertype->$field = $value; diff --git a/htdocs/adherents/class/api_subscriptions.class.php b/htdocs/adherents/class/api_subscriptions.class.php index dfde21dc5a1..be97312280c 100644 --- a/htdocs/adherents/class/api_subscriptions.class.php +++ b/htdocs/adherents/class/api_subscriptions.class.php @@ -186,6 +186,12 @@ class Subscriptions extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $subscription->array_options[$index] = $this->_checkValForAPI($field, $val, $subscription); + } + continue; + } $subscription->$field = $value; } diff --git a/htdocs/bom/class/api_boms.class.php b/htdocs/bom/class/api_boms.class.php index 57b0d26e80a..255934368a8 100644 --- a/htdocs/bom/class/api_boms.class.php +++ b/htdocs/bom/class/api_boms.class.php @@ -237,6 +237,12 @@ class Boms extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->bom->array_options[$index] = $this->_checkValForAPI($field, $val, $this->bom); + } + continue; + } $this->bom->$field = $value; } diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php index 77356ba2a87..44aefd694ba 100644 --- a/htdocs/categories/class/api_categories.class.php +++ b/htdocs/categories/class/api_categories.class.php @@ -237,6 +237,12 @@ class Categories extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->category->array_options[$index] = $this->_checkValForAPI($field, $val, $this->category); + } + continue; + } $this->category->$field = $value; } diff --git a/htdocs/comm/action/class/api_agendaevents.class.php b/htdocs/comm/action/class/api_agendaevents.class.php index 058de48542d..cfb933ed695 100644 --- a/htdocs/comm/action/class/api_agendaevents.class.php +++ b/htdocs/comm/action/class/api_agendaevents.class.php @@ -270,6 +270,12 @@ class AgendaEvents extends DolibarrApi continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->actioncomm->array_options[$index] = $this->_checkValForAPI($field, $val, $this->actioncomm); + } + continue; + } $this->actioncomm->$field = $this->_checkValForAPI($field, $value, $this->actioncomm); } diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index bbdc3cab71d..14ba90aef18 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -696,6 +696,12 @@ class Proposals extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->propal->array_options[$index] = $this->_checkValForAPI($field, $val, $this->propal); + } + continue; + } $this->propal->$field = $value; } diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index af460b3b459..b1571052a2b 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -652,6 +652,12 @@ class Orders extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->commande->array_options[$index] = $this->_checkValForAPI($field, $val, $this->commande); + } + continue; + } $this->commande->$field = $value; } diff --git a/htdocs/compta/bank/class/api_bankaccounts.class.php b/htdocs/compta/bank/class/api_bankaccounts.class.php index 052c45fbc56..1da37b2c760 100644 --- a/htdocs/compta/bank/class/api_bankaccounts.class.php +++ b/htdocs/compta/bank/class/api_bankaccounts.class.php @@ -332,6 +332,12 @@ class BankAccounts extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $account->array_options[$index] = $this->_checkValForAPI($field, $val, $account); + } + continue; + } $account->$field = $this->_checkValForAPI($field, $value, $account); } diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 47fd0263d7e..4dfd1f023aa 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -627,6 +627,12 @@ class Invoices extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->invoice->array_options[$index] = $this->_checkValForAPI($field, $val, $this->invoice); + } + continue; + } $this->invoice->$field = $value; } diff --git a/htdocs/contrat/class/api_contracts.class.php b/htdocs/contrat/class/api_contracts.class.php index 2becf6fcfb7..5bbdf7d1525 100644 --- a/htdocs/contrat/class/api_contracts.class.php +++ b/htdocs/contrat/class/api_contracts.class.php @@ -510,6 +510,12 @@ class Contracts extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->contract->array_options[$index] = $this->_checkValForAPI($field, $val, $this->contract); + } + continue; + } $this->contract->$field = $value; } diff --git a/htdocs/don/class/api_donations.class.php b/htdocs/don/class/api_donations.class.php index fee513f2ed7..472c5f8d4b2 100644 --- a/htdocs/don/class/api_donations.class.php +++ b/htdocs/don/class/api_donations.class.php @@ -231,6 +231,12 @@ class Donations extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->don->array_options[$index] = $this->_checkValForAPI($field, $val, $this->don); + } + continue; + } $this->don->$field = $value; } diff --git a/htdocs/expedition/class/api_shipments.class.php b/htdocs/expedition/class/api_shipments.class.php index fea57fbea10..23e1b1d0c84 100644 --- a/htdocs/expedition/class/api_shipments.class.php +++ b/htdocs/expedition/class/api_shipments.class.php @@ -447,6 +447,12 @@ class Shipments extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->shipment->array_options[$index] = $this->_checkValForAPI($field, $val, $this->shipment); + } + continue; + } $this->shipment->$field = $value; } diff --git a/htdocs/expensereport/class/api_expensereports.class.php b/htdocs/expensereport/class/api_expensereports.class.php index c3bfeb2264d..c985c5fe813 100644 --- a/htdocs/expensereport/class/api_expensereports.class.php +++ b/htdocs/expensereport/class/api_expensereports.class.php @@ -420,6 +420,12 @@ class ExpenseReports extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->expensereport->array_options[$index] = $this->_checkValForAPI($field, $val, $this->expensereport); + } + continue; + } $this->expensereport->$field = $value; } diff --git a/htdocs/fourn/class/api_supplier_invoices.class.php b/htdocs/fourn/class/api_supplier_invoices.class.php index cb7072fdca1..84568f2b13c 100644 --- a/htdocs/fourn/class/api_supplier_invoices.class.php +++ b/htdocs/fourn/class/api_supplier_invoices.class.php @@ -263,6 +263,12 @@ class SupplierInvoices extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->invoice->array_options[$index] = $this->_checkValForAPI($field, $val, $this->invoice); + } + continue; + } $this->invoice->$field = $value; } diff --git a/htdocs/fourn/class/api_supplier_orders.class.php b/htdocs/fourn/class/api_supplier_orders.class.php index 4ad1f951883..b56c5195ee7 100644 --- a/htdocs/fourn/class/api_supplier_orders.class.php +++ b/htdocs/fourn/class/api_supplier_orders.class.php @@ -277,6 +277,12 @@ class SupplierOrders extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->order->array_options[$index] = $this->_checkValForAPI($field, $val, $this->order); + } + continue; + } $this->order->$field = $value; } diff --git a/htdocs/knowledgemanagement/class/api_knowledgemanagement.class.php b/htdocs/knowledgemanagement/class/api_knowledgemanagement.class.php index 6d5c15c0dc6..7d777530166 100644 --- a/htdocs/knowledgemanagement/class/api_knowledgemanagement.class.php +++ b/htdocs/knowledgemanagement/class/api_knowledgemanagement.class.php @@ -298,6 +298,12 @@ class KnowledgeManagement extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->knowledgerecord->array_options[$index] = $this->_checkValForAPI($field, $val, $this->knowledgerecord); + } + continue; + } $this->knowledgerecord->$field = $this->_checkValForAPI($field, $value, $this->knowledgerecord); } diff --git a/htdocs/modulebuilder/template/class/api_mymodule.class.php b/htdocs/modulebuilder/template/class/api_mymodule.class.php index fdb56ff3c67..19bb4f50781 100644 --- a/htdocs/modulebuilder/template/class/api_mymodule.class.php +++ b/htdocs/modulebuilder/template/class/api_mymodule.class.php @@ -255,6 +255,12 @@ class MyModuleApi extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->myobject->array_options[$index] = $this->_checkValForAPI($field, $val, $this->myobject); + } + continue; + } $this->myobject->$field = $this->_checkValForAPI($field, $value, $this->myobject); } diff --git a/htdocs/mrp/class/api_mos.class.php b/htdocs/mrp/class/api_mos.class.php index 2312f4bd636..c524d5533d6 100644 --- a/htdocs/mrp/class/api_mos.class.php +++ b/htdocs/mrp/class/api_mos.class.php @@ -238,6 +238,12 @@ class Mos extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->mo->array_options[$index] = $this->_checkValForAPI($field, $val, $this->mo); + } + continue; + } $this->mo->$field = $value; } diff --git a/htdocs/partnership/class/api_partnership.class.php b/htdocs/partnership/class/api_partnership.class.php index 13bc447c51d..f5cb7293081 100644 --- a/htdocs/partnership/class/api_partnership.class.php +++ b/htdocs/partnership/class/api_partnership.class.php @@ -255,6 +255,12 @@ class PartnershipApi extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->partnership->array_options[$index] = $this->_checkValForAPI($field, $val, $this->partnership); + } + continue; + } $this->partnership->$field = $this->_checkValForAPI($field, $value, $this->partnership); } diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index e95db77d0cc..eeb8427596a 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -361,6 +361,12 @@ class Products extends DolibarrApi if ($field == 'stock_reel') { throw new RestException(400, 'Stock reel cannot be updated here. Use the /stockmovements endpoint instead'); } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->product->array_options[$index] = $this->_checkValForAPI($field, $val, $this->product); + } + continue; + } $this->product->$field = $value; } diff --git a/htdocs/product/stock/class/api_warehouses.class.php b/htdocs/product/stock/class/api_warehouses.class.php index a0646598d96..f39a9fa88d8 100644 --- a/htdocs/product/stock/class/api_warehouses.class.php +++ b/htdocs/product/stock/class/api_warehouses.class.php @@ -206,6 +206,12 @@ class Warehouses extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->warehouse->array_options[$index] = $this->_checkValForAPI($field, $val, $this->warehouse); + } + continue; + } $this->warehouse->$field = $value; } diff --git a/htdocs/projet/class/api_projects.class.php b/htdocs/projet/class/api_projects.class.php index f5c23f4b040..9eed224e99a 100644 --- a/htdocs/projet/class/api_projects.class.php +++ b/htdocs/projet/class/api_projects.class.php @@ -462,6 +462,12 @@ class Projects extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->project->array_options[$index] = $this->_checkValForAPI($field, $val, $this->project); + } + continue; + } $this->project->$field = $value; } diff --git a/htdocs/projet/class/api_tasks.class.php b/htdocs/projet/class/api_tasks.class.php index 80fede57563..bb65cfa31e5 100644 --- a/htdocs/projet/class/api_tasks.class.php +++ b/htdocs/projet/class/api_tasks.class.php @@ -460,6 +460,12 @@ class Tasks extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->task->array_options[$index] = $this->_checkValForAPI($field, $val, $this->task); + } + continue; + } $this->task->$field = $value; } diff --git a/htdocs/reception/class/api_receptions.class.php b/htdocs/reception/class/api_receptions.class.php index 55e3fa59165..70088db3455 100644 --- a/htdocs/reception/class/api_receptions.class.php +++ b/htdocs/reception/class/api_receptions.class.php @@ -447,6 +447,12 @@ class Receptions extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->reception->array_options[$index] = $this->_checkValForAPI($field, $val, $this->reception); + } + continue; + } $this->reception->$field = $value; } diff --git a/htdocs/societe/class/api_contacts.class.php b/htdocs/societe/class/api_contacts.class.php index d8839c9a122..efbc1625ea0 100644 --- a/htdocs/societe/class/api_contacts.class.php +++ b/htdocs/societe/class/api_contacts.class.php @@ -330,6 +330,12 @@ class Contacts extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->contact->array_options[$index] = $this->_checkValForAPI($field, $val, $this->contact); + } + continue; + } $this->contact->$field = $value; } diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index ef54c3a2299..f35521689da 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -301,6 +301,12 @@ class Thirdparties extends DolibarrApi if ($field == 'id') { continue; } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->company->array_options[$index] = $this->_checkValForAPI($field, $val, $this->company); + } + continue; + } $this->company->$field = $value; } diff --git a/htdocs/ticket/class/api_tickets.class.php b/htdocs/ticket/class/api_tickets.class.php index c27d9195683..d07687ff192 100644 --- a/htdocs/ticket/class/api_tickets.class.php +++ b/htdocs/ticket/class/api_tickets.class.php @@ -381,6 +381,15 @@ class Tickets extends DolibarrApi } foreach ($request_data as $field => $value) { + if ($field == 'id') { + continue; + } + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->ticket->array_options[$index] = $this->_checkValForAPI($field, $val, $this->ticket); + } + continue; + } $this->ticket->$field = $value; } diff --git a/htdocs/user/class/api_users.class.php b/htdocs/user/class/api_users.class.php index 781de4d23cd..fadcde59d53 100644 --- a/htdocs/user/class/api_users.class.php +++ b/htdocs/user/class/api_users.class.php @@ -406,6 +406,12 @@ class Users extends DolibarrApi throw new RestException(500, 'Error when updating status of user: '.$this->useraccount->error); } } else { + if ($field == 'array_options' && is_array($value)) { + foreach ($value as $index => $val) { + $this->useraccount->array_options[$index] = $this->_checkValForAPI($field, $val, $this->useraccount); + } + continue; + } $this->useraccount->$field = $value; } } From a52a218ae42f0e8114ec44591780026855391f02 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Thu, 16 Jan 2025 19:17:47 +0100 Subject: [PATCH 42/56] Use same patch like in #26454 --- htdocs/product/class/product.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index ea9c7f6b830..4860fe9c34a 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -5016,7 +5016,7 @@ class Product extends CommonObject //$prods[$this->db->escape($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty'],2=>$rec['fk_product_type']); //$prods[$this->db->escape($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty']); if (empty($firstlevelonly)) { - array_push($parents, $rec['rowid']); + $parents[] = $rec['rowid']; $listofchilds = $this->getChildsArbo($rec['rowid'], 0, $level + 1, $parents); foreach ($listofchilds as $keyChild => $valueChild) { $prods[$rec['rowid']]['childs'][$keyChild] = $valueChild; From a9ff78528a5f9dbc9c5988028126eb0870d538da Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 17 Jan 2025 11:36:41 +0100 Subject: [PATCH 43/56] FIX missing default values if $objsrc or $soc fields are empty --- htdocs/compta/facture/card.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 4b60fdacff5..9f0301f3c06 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -3179,9 +3179,9 @@ if ($action == 'create') { $expesrc->fetch_optionals(); $object->array_options = $expesrc->array_options; } else { - $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0)); - $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0)); - $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0)); + $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : (!empty($cond_reglement_id) ? $cond_reglement_id : 0))); + $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : (!empty($mode_reglement_id) ? $mode_reglement_id : 0))); + $fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : (!empty($fk_account) ? $fk_account : 0))); //$remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0)); //$remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0)); From 74bfddeeab8eddd210db3e4b977ce5d58d4d5138 Mon Sep 17 00:00:00 2001 From: John BOTELLA <68917336+thersane-john@users.noreply.github.com> Date: Sun, 19 Jan 2025 14:59:35 +0100 Subject: [PATCH 44/56] Fix supplier ref search --- htdocs/core/class/html.form.class.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index a3787797c25..52ff50b6791 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2999,11 +2999,6 @@ class Form $sql .= ' AND e.statut IN (' . $this->db->sanitize($this->db->escape(implode(',', $warehouseStatusArray))) . ')'; // Return line if product is inside the selected stock. If not, an empty line will be returned so we will count 0. } - // include search in supplier ref - if (getDolGlobalString('MAIN_SEARCH_PRODUCT_BY_FOURN_REF')) { - $sql .= " LEFT JOIN " . $this->db->prefix() . "product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; - } - //Price by customer if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') && !empty($socid)) { $sql .= " LEFT JOIN " . $this->db->prefix() . "product_customer_price as pcp ON pcp.fk_soc=" . ((int) $socid) . " AND pcp.fk_product=p.rowid"; @@ -3064,6 +3059,8 @@ class Form $sql .= $hookmanager->resPrint; // Add criteria on ref/label if ($filterkey != '') { + $sqlSupplierSearch= ''; + $sql .= ' AND ('; $prefix = !getDolGlobalString('PRODUCT_DONOTSEARCH_ANYWHERE') ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on // For natural search @@ -3089,8 +3086,11 @@ class Form $sql .= " OR pl.description LIKE '" . $this->db->escape($prefix . $crit) . "%'"; } } + + // include search in supplier ref if (getDolGlobalString('MAIN_SEARCH_PRODUCT_BY_FOURN_REF')) { - $sql .= " OR pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) . "%'"; + $sqlSupplierSearch .= !empty($sqlSupplierSearch) ? ' OR ':''; + $sqlSupplierSearch .= " pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) . "%'"; } $sql .= ")"; $i++; @@ -3101,6 +3101,12 @@ class Form if (isModEnabled('barcode')) { $sql .= " OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) . "%'"; } + + // include search in supplier ref + if (getDolGlobalString('MAIN_SEARCH_PRODUCT_BY_FOURN_REF')) { + $sql .= ' OR EXISTS (SELECT pfp.fk_product FROM ' . $this->db->prefix() . 'product_fournisseur_price as pfp WHERE p.rowid = pfp.fk_product AND ('.$sqlSupplierSearch.') )'; + } + $sql .= ')'; } if (count($warehouseStatusArray)) { From 35a07af56bf88928f718a4282378997593f085fb Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 20 Jan 2025 03:14:47 +0100 Subject: [PATCH 45/56] Update html.form.class.php --- htdocs/core/class/html.form.class.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 52ff50b6791..a3b36ddd962 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3104,7 +3104,10 @@ class Form // include search in supplier ref if (getDolGlobalString('MAIN_SEARCH_PRODUCT_BY_FOURN_REF')) { - $sql .= ' OR EXISTS (SELECT pfp.fk_product FROM ' . $this->db->prefix() . 'product_fournisseur_price as pfp WHERE p.rowid = pfp.fk_product AND ('.$sqlSupplierSearch.') )'; + $sql .= " OR EXISTS (SELECT pfp.fk_product FROM " . $this->db->prefix() . "product_fournisseur_price as pfp WHERE p.rowid = pfp.fk_product"; + $sql .= " AND ("; + $sql .= $sqlSupplierSearch; + $sql .= "))"; } $sql .= ')'; From df861e76bceeae2226f310a8525f943aee57cb3d Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Mon, 20 Jan 2025 08:53:47 +0100 Subject: [PATCH 46/56] FIX code not visible correctly into view of dictionnary --- htdocs/admin/dict.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 320d8ca9e82..6218c894c62 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -2367,7 +2367,10 @@ if ($id > 0) { continue; } - if ($value == 'element') { + // Management of several special cases and exceptions + if ($value == 'code' && $id == DICT_PRODUCT_NATURE) { + $valuetoshow = (int) $valuetoshow; + } elseif ($value == 'element') { $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow; } elseif ($value == 'source') { $valuetoshow = isset($sourceList[$valuetoshow]) ? $sourceList[$valuetoshow] : $valuetoshow; @@ -2543,6 +2546,7 @@ if ($id > 0) { $valuetoshow = $TDurationTypes[$obj->{$value}]; } } + $class .= ($class ? ' ' : '').'tddict'; if ($value == 'name') { $class .= ' tdoverflowmax200'; From 5729995b21105eef0532294210fc32474d55d28b Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Mon, 20 Jan 2025 08:53:47 +0100 Subject: [PATCH 47/56] FIX code not visible correctly into view of dictionnary --- htdocs/admin/dict.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index d5492e16956..6d10c1de384 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -2286,7 +2286,10 @@ if ($id > 0) { continue; } - if ($value == 'element') { + // Management of several special cases and exceptions + if ($value == 'code' && $id == DICT_PRODUCT_NATURE) { + $valuetoshow = (int) $valuetoshow; + } elseif ($value == 'element') { $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow; } elseif ($value == 'source') { $valuetoshow = isset($sourceList[$valuetoshow]) ? $sourceList[$valuetoshow] : $valuetoshow; @@ -2460,6 +2463,7 @@ if ($id > 0) { $valuetoshow = $TDurationTypes[$obj->{$value}]; } } + $class .= ($class ? ' ' : '').'tddict'; if ($value == 'note' && $id == DICT_TVA) { $class .= ' tdoverflowmax200'; From 695b0e12a786ba94978f38f0b901339970a7b0c0 Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Mon, 20 Jan 2025 10:07:40 +0100 Subject: [PATCH 48/56] Fix sql --- htdocs/install/mysql/tables/llx_blockedlog.key.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/install/mysql/tables/llx_blockedlog.key.sql b/htdocs/install/mysql/tables/llx_blockedlog.key.sql index 065be82aba1..e1e2c956609 100644 --- a/htdocs/install/mysql/tables/llx_blockedlog.key.sql +++ b/htdocs/install/mysql/tables/llx_blockedlog.key.sql @@ -22,4 +22,5 @@ ALTER TABLE llx_blockedlog ADD INDEX entity (entity); ALTER TABLE llx_blockedlog ADD INDEX fk_user (fk_user); ALTER TABLE llx_blockedlog ADD INDEX entity_action_certified (entity,action,certified); -ALTER TABLE llx_blockedlog ADD INDEX entity_rowid (entity, rowid); -- for the "SELECT rowid, signature FROM llx_blockedlog FORCE INDEX entity_rowid WHERE entity = x AND rowid < z ORDER BY rowid DESC" +-- We add this index for the "SELECT rowid, signature FROM llx_blockedlog FORCE INDEX entity_rowid WHERE entity = x AND rowid < z ORDER BY rowid DESC" +ALTER TABLE llx_blockedlog ADD INDEX entity_rowid (entity, rowid); From 736890b244e3de3d6c397310cf339d8ced9604fe Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Mon, 20 Jan 2025 10:15:31 +0100 Subject: [PATCH 49/56] Merge --- htdocs/comm/action/class/actioncomm.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 68d17fe99f6..cf1898daa07 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -619,7 +619,7 @@ class ActionComm extends CommonObject foreach ($this->userassigned as $key => $val) { // Common value with new behavior is to have $val = array('id'=>iduser, 'transparency'=>0|1) and $this->userassigned is an array of iduser => $val. if (!is_array($val)) { // For backward compatibility when $val='id'. - $val = array('id'=>$val); + $val = array('id' => $val); } if ($val['id'] > 0) { From dcb0befcd45dacfe0c5f427aa30881c263545f77 Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Mon, 20 Jan 2025 12:51:00 +0100 Subject: [PATCH 50/56] Fix regression --- htdocs/adherents/class/api_subscriptions.class.php | 2 +- htdocs/expedition/class/api_shipments.class.php | 2 +- htdocs/projet/class/api_tasks.class.php | 2 +- htdocs/reception/class/api_receptions.class.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/adherents/class/api_subscriptions.class.php b/htdocs/adherents/class/api_subscriptions.class.php index 6d27ba72dea..a689a35a0a6 100644 --- a/htdocs/adherents/class/api_subscriptions.class.php +++ b/htdocs/adherents/class/api_subscriptions.class.php @@ -202,7 +202,7 @@ class Subscriptions extends DolibarrApi } continue; } - $subscription->$field = $this->_checkValForAPI($field, $val, $subscription); + $subscription->$field = $this->_checkValForAPI($field, $value, $subscription); } if ($subscription->update(DolibarrApiAccess::$user) > 0) { diff --git a/htdocs/expedition/class/api_shipments.class.php b/htdocs/expedition/class/api_shipments.class.php index b5995eed7ac..1cdd859004f 100644 --- a/htdocs/expedition/class/api_shipments.class.php +++ b/htdocs/expedition/class/api_shipments.class.php @@ -463,7 +463,7 @@ class Shipments extends DolibarrApi } continue; } - $this->shipment->$field = $this->_checkValForAPI($field, $val, $this->shipment);; + $this->shipment->$field = $this->_checkValForAPI($field, $value, $this->shipment);; } if ($this->shipment->update(DolibarrApiAccess::$user) > 0) { diff --git a/htdocs/projet/class/api_tasks.class.php b/htdocs/projet/class/api_tasks.class.php index 353615ba887..49382685edd 100644 --- a/htdocs/projet/class/api_tasks.class.php +++ b/htdocs/projet/class/api_tasks.class.php @@ -478,7 +478,7 @@ class Tasks extends DolibarrApi } continue; } - $this->task->$field = $this->_checkValForAPI($field, $val, $this->task); + $this->task->$field = $this->_checkValForAPI($field, $value, $this->task); } if ($this->task->update(DolibarrApiAccess::$user) > 0) { diff --git a/htdocs/reception/class/api_receptions.class.php b/htdocs/reception/class/api_receptions.class.php index 5eeece76d81..c05e5ca477e 100644 --- a/htdocs/reception/class/api_receptions.class.php +++ b/htdocs/reception/class/api_receptions.class.php @@ -464,7 +464,7 @@ class Receptions extends DolibarrApi } continue; } - $this->reception->$field = $this->_checkValForAPI($field, $val, $this->reception); + $this->reception->$field = $this->_checkValForAPI($field, $value, $this->reception); } if ($this->reception->update(DolibarrApiAccess::$user) > 0) { From 36b48a81ec231d882c962dd6a56ee227a835981d Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Mon, 20 Jan 2025 14:59:13 +0100 Subject: [PATCH 51/56] Fix double ; --- htdocs/expedition/class/api_shipments.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/expedition/class/api_shipments.class.php b/htdocs/expedition/class/api_shipments.class.php index 1cdd859004f..df30b70a141 100644 --- a/htdocs/expedition/class/api_shipments.class.php +++ b/htdocs/expedition/class/api_shipments.class.php @@ -463,7 +463,7 @@ class Shipments extends DolibarrApi } continue; } - $this->shipment->$field = $this->_checkValForAPI($field, $value, $this->shipment);; + $this->shipment->$field = $this->_checkValForAPI($field, $value, $this->shipment); } if ($this->shipment->update(DolibarrApiAccess::$user) > 0) { From 42c870ca629ff6419cc9ef4fd64ed9f64d57e19b Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Mon, 20 Jan 2025 15:41:20 +0100 Subject: [PATCH 52/56] FIX The email for admin must be in language of admin not of visitor --- htdocs/public/payment/paymentko.php | 10 +++++++++- htdocs/public/payment/paymentok.php | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/htdocs/public/payment/paymentko.php b/htdocs/public/payment/paymentko.php index 4e3cc764659..db16c74ab21 100644 --- a/htdocs/public/payment/paymentko.php +++ b/htdocs/public/payment/paymentko.php @@ -194,8 +194,16 @@ if (!empty($_SESSION['ipaddress'])) { // To avoid to make action twice // Send warning of error to administrator if ($sendemail) { + // Get default language to use for the company for supervision emails + $myCompanyDefaultLang = $mysoc->default_lang; + if (empty($myCompanyDefaultLang) || $myCompanyDefaultLang === 'auto') { + // We must guess the language from the company country. We must not use the language of the visitor. This is a technical email for supervision + // so it must always be into the same language. + $myCompanyDefaultLang = getLanguageCodeFromCountryCode($mysoc->country_code); + } + $companylangs = new Translate('', $conf); - $companylangs->setDefaultLang($mysoc->default_lang); + $companylangs->setDefaultLang($myCompanyDefaultLang); $companylangs->loadLangs(array('main', 'members', 'bills', 'paypal', 'paybox', 'stripe')); $from = getDolGlobalString("MAIN_MAIL_EMAIL_FROM"); diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index cbfaae76079..aa46e7ccf0b 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -1957,8 +1957,16 @@ if ($ispaymentok) { // Send an email to the admins if ($sendemail) { + // Get default language to use for the company for supervision emails + $myCompanyDefaultLang = $mysoc->default_lang; + if (empty($myCompanyDefaultLang) || $myCompanyDefaultLang === 'auto') { + // We must guess the language from the company country. We must not use the language of the visitor. This is a technical email for supervision + // so it must always be into the same language. + $myCompanyDefaultLang = getLanguageCodeFromCountryCode($mysoc->country_code); + } + $companylangs = new Translate('', $conf); - $companylangs->setDefaultLang($mysoc->default_lang); + $companylangs->setDefaultLang($myCompanyDefaultLang); $companylangs->loadLangs(array('main', 'members', 'bills', 'paypal', 'paybox', 'stripe')); $sendto = $sendemail; From ca9a1923e1c62b5c81546d299757543bed9b1acf Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Mon, 20 Jan 2025 16:13:40 +0100 Subject: [PATCH 53/56] Fix missing field in the select of country --- htdocs/core/class/ccountry.class.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/ccountry.class.php b/htdocs/core/class/ccountry.class.php index 1d798698e84..22a1d2d84d2 100644 --- a/htdocs/core/class/ccountry.class.php +++ b/htdocs/core/class/ccountry.class.php @@ -52,6 +52,21 @@ class Ccountry extends CommonDict 'label' => array('type' => 'varchar(250)', 'label' => 'Label', 'enabled' => 1, 'visible' => 1, 'position' => 15, 'notnull' => -1, 'showoncombobox' => 1) ); + /** + * @var int + */ + public $favorite; + + /** + * @var int + */ + public $eec; + + /** + * @var string + */ + public $numeric_code; + /** * Constructor @@ -150,7 +165,10 @@ class Ccountry extends CommonDict $sql .= " t.code,"; $sql .= " t.code_iso,"; $sql .= " t.label,"; - $sql .= " t.active"; + $sql .= " t.eec,"; + $sql .= " t.active,"; + $sql .= " t.favorite,"; + $sql .= " t.numeric_code"; $sql .= " FROM ".$this->db->prefix()."c_country as t"; if ($id) { $sql .= " WHERE t.rowid = ".((int) $id); @@ -161,6 +179,7 @@ class Ccountry extends CommonDict } dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + $resql = $this->db->query($sql); if ($resql) { if ($this->db->num_rows($resql)) { @@ -172,6 +191,9 @@ class Ccountry extends CommonDict $this->code_iso = $obj->code_iso; $this->label = $obj->label; $this->active = $obj->active; + $this->favorite = $obj->favorite; + $this->eec = $obj->eec; + $this->numeric_code = $obj->numeric_code; } $this->db->free($resql); From a6d8feefdc47670392b88adaa1ad640b7b819ca4 Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Tue, 21 Jan 2025 13:00:18 +0100 Subject: [PATCH 54/56] Fix warning --- htdocs/core/lib/files.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 08dd5e94151..a2795eda594 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -3162,7 +3162,7 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, $original_file = $conf->fckeditor->dir_output.'/'.$original_file; } elseif ($modulepart == 'user' && !empty($conf->user->dir_output)) { // Wrapping for users - $canreaduser = (!empty($fuser->admin) || $fuser->rights->user->user->{$lire}); + $canreaduser = (!empty($fuser->admin) || $fuser->hasRight('user', 'user', 'lire')); if ($fuser->id == (int) $refname) { $canreaduser = 1; } // A user can always read its own card From 7a8d4e2507ac3108cded12df449f0e2f23883a62 Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Tue, 21 Jan 2025 14:08:52 +0100 Subject: [PATCH 55/56] Debug v21 --- htdocs/comm/action/class/actioncomm.class.php | 4 +- .../comm/action/class/cactioncomm.class.php | 2 + htdocs/core/lib/company.lib.php | 64 +++++++++++++------ 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index a96ec4e0e82..6eb05106686 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1883,7 +1883,7 @@ class ActionComm extends CommonObject $color = 'style="color: #'.$this->type_color.' !important;"'; } if ($this->type_picto) { - $imgpicto = img_picto($titlealt, $this->type_picto, '', 0, 0, 0, '', ($morecss ? ' '.$morecss : '')); + $imgpicto = img_picto($titlealt.'rr', $this->type_picto, '', 0, 0, 0, '', ($morecss ? ' '.$morecss : '')); } else { if ($this->type_code == 'AC_RDV') { $imgpicto = img_picto($titlealt, 'meeting', $color, 0, 0, 0, '', ($morecss ? ' '.$morecss : '')); @@ -1891,7 +1891,7 @@ class ActionComm extends CommonObject $imgpicto = img_picto($titlealt, 'object_phoning', $color, 0, 0, 0, '', ($morecss ? ' '.$morecss : '')); } elseif ($this->type_code == 'AC_FAX') { $imgpicto = img_picto($titlealt, 'object_phoning_fax', $color, 0, 0, 0, '', ($morecss ? ' '.$morecss : '')); - } elseif ($this->type_code == 'AC_EMAIL' || $this->type_code == 'AC_EMAIL_IN' || (!empty($this->code) && preg_match('/_SENTBYMAIL/', $this->code))) { + } elseif ($this->type_code == 'AC_EMAIL' || $this->type_code == 'AC_EMAIL_IN' || $this->type_code == 'AC_EMAILING' || (!empty($this->code) && preg_match('/_SENTBYMAIL/', $this->code))) { $imgpicto = img_picto($titlealt, 'object_email', $color, 0, 0, 0, '', ($morecss ? ' '.$morecss : '')); } elseif ($this->type_code == 'AC_INT') { $imgpicto = img_picto($titlealt, 'object_intervention', $color, 0, 0, 0, '', ($morecss ? ' '.$morecss : '')); diff --git a/htdocs/comm/action/class/cactioncomm.class.php b/htdocs/comm/action/class/cactioncomm.class.php index 9c28468c1c7..db3fcfe1bbc 100644 --- a/htdocs/comm/action/class/cactioncomm.class.php +++ b/htdocs/comm/action/class/cactioncomm.class.php @@ -163,11 +163,13 @@ class CActionComm global $langs, $conf, $user; $langs->load("commercial"); + /* $actionstatic = new ActionComm($this->db); $rep_id = array(); $rep_code = array(); $rep_all = array(); + */ $sql = "SELECT id, code, libelle as label, module, type, color, picto"; $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm"; diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index dcaa104ee2c..6f6d25eecb8 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -1809,6 +1809,7 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = null, $nopr $sql .= " a.percent as percent, 'action' as type,"; $sql .= " a.fk_element, a.elementtype,"; $sql .= " a.fk_contact,"; + $sql .= " a.code,"; $sql .= " c.code as acode, c.libelle as alabel, c.picto as apicto,"; $sql .= " u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname"; if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) { @@ -2006,6 +2007,7 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = null, $nopr $sql .= $hookmanager->resPrint; } + // Now add events of emailing module if (is_array($actioncode)) { foreach ($actioncode as $code) { $sql2 = addMailingEventTypeSQL($code, $objcon, $filterobj); @@ -2087,6 +2089,9 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = null, $nopr 'firstname' => empty($obj->firstname) ? '' : $obj->firstname, 'fk_element' => (int) $obj->fk_element, 'elementtype' => $obj->elementtype, + + 'code' => $obj->code, + // Type of event 'acode' => $obj->acode, 'alabel' => $obj->alabel, @@ -2102,6 +2107,10 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = null, $nopr 'dateend' => $db->jdate($obj->dp2), 'note' => $obj->label, 'percent' => (int) $obj->percent, + + 'code' => $obj->code, + + // Type of event 'acode' => $obj->acode, 'userid' => (int) $obj->user_id, @@ -2238,11 +2247,14 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = null, $nopr require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php'; $caction = new CActionComm($db); - $arraylist = $caction->liste_array(1, 'code', '', (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? 1 : 0), '', 1); + $arraylist = $caction->liste_array(1, 'code', '', (getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? 0 : 1), '', 1); foreach ($histo as $key => $value) { $actionstatic->fetch($histo[$key]['id']); // TODO Do we need this, we already have a lot of data of line into $histo + if (empty($actionstatic->code)) { + $actionstatic->code = $histo[$key]['acode']; + } $actionstatic->type_picto = $histo[$key]['apicto'] ?? ''; $actionstatic->type_code = $histo[$key]['acode']; @@ -2314,25 +2326,38 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = null, $nopr } $out .= ''; + // type_code // column "acode" in the sql = code in type of actioncomm, example: AC_OTH_AUTO, AC_EMAILING + // code // columne code in the sql (not yet added), can be AC_CONTACT_SENTBYMAIL, ... + // Type - $labeltype = $actionstatic->type_code; - if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') && empty($arraylist[$labeltype])) { - $labeltype = 'AC_OTH'; + $labelOfTypeToShow = $actionstatic->type_code; + //$typelabel = $actionstatic->type_label; + $code = $actionstatic->code; + if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') && empty($arraylist[$labelOfTypeToShow])) { + $labelOfTypeToShow = 'AC_OTH'; } if (!empty($actionstatic->code) && preg_match('/^TICKET_MSG/', $actionstatic->code)) { - $labeltype = $langs->trans("Message"); + $labelOfTypeToShow = $langs->trans("Message"); } else { - if (!empty($arraylist[$labeltype])) { - $labeltype = $arraylist[$labeltype]; + if (!empty($arraylist[$labelOfTypeToShow])) { + $labelOfTypeToShow = $arraylist[$labelOfTypeToShow]; + } elseif ($actionstatic->type_code == 'AC_EMAILING') { + $labelOfTypeToShow = $langs->trans("Emailing"); } - if ($actionstatic->type_code == 'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labeltype && !empty($arraylist[$actionstatic->code])) { - $labeltype .= ' - '.$arraylist[$actionstatic->code]; // Use code in priority on type_code + if ($actionstatic->type_code == 'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labelOfTypeToShow && !empty($arraylist[$actionstatic->code])) { + $labelOfTypeToShow .= ' - '.$arraylist[$actionstatic->code]; // Show also detailed code } } - $out .= ''; + + $labelOfTypeToShowLong = $labelOfTypeToShow; + if ($actionstatic->type_code == 'AC_OTH_AUTO') { + $labelOfTypeToShowLong .= ' (auto)'; + } + + $out .= ''; $out .= $actionstatic->getTypePicto(); //if (empty($conf->dol_optimize_smallscreen)) { - $out .= $labeltype; + $out .= $labelOfTypeToShow; //} $out .= ''; @@ -2341,18 +2366,19 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = null, $nopr if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'action') { $transcode = $langs->trans("Action".$histo[$key]['acode']); //$libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : $histo[$key]['alabel']); - $libelle = $histo[$key]['note']; + $label = $histo[$key]['note']; $actionstatic->id = $histo[$key]['id']; - $out .= ' title="'.dol_escape_htmltag($libelle).'">'; - $out .= dol_trunc($libelle, 120); + $out .= ' title="'.dol_escape_htmltag($label).'">'; + $out .= dol_trunc($label, 120); } if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') { $transcode = $langs->trans("Action".$histo[$key]['acode']); - $libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : 'Send mass mailing'); + $label = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : 'Send mass mailing'); + $label .= ' - '.$histo[$key]['note']; $out .= ''; - $out .= img_object($langs->trans("ShowEMailing"), "email").' '; - $out .= dol_trunc($libelle, 120); + $out .= ' title="'.dol_escape_htmltag($label).'">'; + //$out .= img_object($langs->trans("EMailing").'
'.$histo[$key]['note'], "email").' '; + $out .= dol_trunc($label, 120); $out .= '
'; } $out .= ''; @@ -2606,7 +2632,7 @@ function addMailingEventTypeSQL($actioncode, $objcon, $filterobj) if (isModEnabled('mailing') && !empty($objcon->email) && (empty($actioncode) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING')) { $sql2 = "SELECT m.rowid as id, m.titre as label, mc.date_envoi as dp, mc.date_envoi as dp2, '100' as percent, 'mailing' as type"; $sql2 .= ", null as fk_element, '' as elementtype, null as contact_id"; - $sql2 .= ", 'AC_EMAILING' as acode, '' as alabel, '' as apicto"; + $sql2 .= ", 'AC_EMAILING' as code, 'AC_EMAILING' as acode, '' as alabel, '' as apicto"; $sql2 .= ", u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname"; // User that valid action if (is_object($filterobj) && get_class($filterobj) == 'Societe') { $sql2 .= ", '' as lastname, '' as firstname"; From 8f7881a8714d992e5cc404655ecf4ad609edb82d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 21 Jan 2025 17:51:01 +0100 Subject: [PATCH 56/56] Debug v21 --- htdocs/langs/en_US/stripe.lang | 1 + htdocs/public/stripe/ipn.php | 79 +++++++++++++++++++--------------- htdocs/stripe/admin/stripe.php | 24 ++++++++--- 3 files changed, 64 insertions(+), 40 deletions(-) diff --git a/htdocs/langs/en_US/stripe.lang b/htdocs/langs/en_US/stripe.lang index 2e244858d28..3d1e3925309 100644 --- a/htdocs/langs/en_US/stripe.lang +++ b/htdocs/langs/en_US/stripe.lang @@ -12,6 +12,7 @@ YourEMail=Email to receive payment confirmation STRIPE_PAYONLINE_SENDEMAIL=Email notification after a payment attempt (success or fail) Creditor=Creditor PaymentCode=Payment code +StripeAutoRecordPayout=Enable the auto recording of payout (when Stripe do a payout and call the webhook payout.create/payout.paid) StripeDoPayment=Pay with Stripe YouWillBeRedirectedOnStripe=You will be redirected on secured Stripe page to input you credit card information Continue=Next diff --git a/htdocs/public/stripe/ipn.php b/htdocs/public/stripe/ipn.php index 0a2c982258d..e04053634d7 100644 --- a/htdocs/public/stripe/ipn.php +++ b/htdocs/public/stripe/ipn.php @@ -178,14 +178,14 @@ top_httphead(); dol_syslog("***** Stripe IPN was called with event->type=".$event->type." service=".$service); -if ($event->type == 'payout.created') { - // When a payout is create by Stripe to transfer money to your account +if ($event->type == 'payout.created' && getDolGlobalString('STRIPE_AUTO_RECORD_PAYOUT')) { + // When a payout is created by Stripe to transfer money to your account $error = 0; $result = dolibarr_set_const($db, $service."_NEXTPAYOUT", date('Y-m-d H:i:s', $event->data->object->arrival_date), 'chaine', 0, '', $conf->entity); if ($result > 0) { - $subject = $societeName.' - [NOTIFICATION] Stripe payout scheduled'; + $subject = '['.$societeName.'] Notification - Stripe payout scheduled'; if (!empty($user->email)) { $sendto = dolGetFirstLastname($user->firstname, $user->lastname)." <".$user->email.">"; } else { @@ -221,7 +221,7 @@ if ($event->type == 'payout.created') { http_response_code(500); return -1; } -} elseif ($event->type == 'payout.paid') { +} elseif ($event->type == 'payout.paid' && getDolGlobalString('STRIPE_AUTO_RECORD_PAYOUT')) { // When a payout to transfer money to your account is completely done $error = 0; $result = dolibarr_set_const($db, $service."_NEXTPAYOUT", 0, 'chaine', 0, '', $conf->entity); @@ -249,6 +249,8 @@ if ($event->type == 'payout.created') { $typefrom = 'PRE'; $typeto = 'VIR'; + $db->begin(); + if (!$error) { $bank_line_id_from = $accountfrom->addline($dateo, $typefrom, $label, -1 * (float) price2num($amount), '', '', $user); } @@ -274,38 +276,47 @@ if ($event->type == 'payout.created') { if (!($result > 0)) { $error++; } + + if (!$error) { + $db->commit(); + } else { + $db->rollback(); + } + + // Send email + if (!$error) { + $subject = '['.$societeName.'] - NotificationOTIFICATION] Stripe payout done'; + if (!empty($user->email)) { + $sendto = dolGetFirstLastname($user->firstname, $user->lastname)." <".$user->email.">"; + } else { + $sendto = getDolGlobalString('MAIN_INFO_SOCIETE_MAIL') . '" <' . getDolGlobalString('MAIN_INFO_SOCIETE_MAIL').'>'; + } + $replyto = $sendto; + $sendtocc = ''; + if (getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL')) { + $sendtocc = getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL') . '" <' . getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL').'>'; + } + + $message = "A bank transfer of ".price2num($event->data->object->amount / 100)." ".$event->data->object->currency." has been done to your account the ".dol_print_date($event->data->object->arrival_date, 'dayhour'); + + $mailfile = new CMailFile( + $subject, + $sendto, + $replyto, + $message, + array(), + array(), + array(), + $sendtocc, + '', + 0, + -1 + ); + + $ret = $mailfile->sendfile(); + } } - $subject = $societeName.' - [NOTIFICATION] Stripe payout done'; - if (!empty($user->email)) { - $sendto = dolGetFirstLastname($user->firstname, $user->lastname)." <".$user->email.">"; - } else { - $sendto = getDolGlobalString('MAIN_INFO_SOCIETE_MAIL') . '" <' . getDolGlobalString('MAIN_INFO_SOCIETE_MAIL').'>'; - } - $replyto = $sendto; - $sendtocc = ''; - if (getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL')) { - $sendtocc = getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL') . '" <' . getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL').'>'; - } - - $message = "A bank transfer of ".price2num($event->data->object->amount / 100)." ".$event->data->object->currency." has been done to your account the ".dol_print_date($event->data->object->arrival_date, 'dayhour'); - - $mailfile = new CMailFile( - $subject, - $sendto, - $replyto, - $message, - array(), - array(), - array(), - $sendtocc, - '', - 0, - -1 - ); - - $ret = $mailfile->sendfile(); - return 1; } else { $error++; diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index a017742d722..eb08aac811d 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -379,18 +379,30 @@ print ''.$langs->trans("Example").': '.$mysoc->name.''; print ''; -print ''; -print $langs->trans("StripeUserAccountForActions").''; -print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers(getDolGlobalString('STRIPE_USER_ACCOUNT_FOR_ACTIONS'), 'STRIPE_USER_ACCOUNT_FOR_ACTIONS', 0); -print ''; - print ''; print $langs->trans("BankAccount").''; print img_picto('', 'bank_account', 'class="pictofixedwidth"'); $form->select_comptes(getDolGlobalString('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS'), 'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1); print ''; -if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // What is this for ? + +// Param to record automatically payouts (received from IPN payout.payed and payout.created) +print ''; +print $langs->trans("StripeAutoRecordPayout").''; +if ($conf->use_javascript_ajax) { + print ajax_constantonoff('STRIPE_AUTO_RECORD_PAYOUT', array(), null, 0, 0, 1); +} else { + $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); + print $form->selectarray("STRIPE_AUTO_RECORD_PAYOUT", $arrval, getDolGlobalInt('STRIPE_AUTO_RECORD_PAYOUT')); +} +print ''; + +if (getDolGlobalInt('STRIPE_AUTO_RECORD_PAYOUT')) { + print ''; + print $langs->trans("StripeUserAccountForActions").''; + print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers(getDolGlobalString('STRIPE_USER_ACCOUNT_FOR_ACTIONS'), 'STRIPE_USER_ACCOUNT_FOR_ACTIONS', 0); + print ''; + print ''; print $langs->trans("BankAccountForBankTransfer").''; print img_picto('', 'bank_account', 'class="pictofixedwidth"');