diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php
index 85725b16547..72279faf16b 100644
--- a/htdocs/core/actions_massactions.inc.php
+++ b/htdocs/core/actions_massactions.inc.php
@@ -593,8 +593,10 @@ if (!$error && $massaction == 'confirm_presend') {
if ($mailfile->error) {
$resaction .= $langs->trans('ErrorFailedToSendMail', $from, $sendto);
$resaction .= '
'.$mailfile->error.'
';
- } else {
+ } elseif (!empty($conf->global->MAIN_DISABLE_ALL_MAILS)) {
$resaction .= 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS
';
+ } else {
+ $resaction .= $langs->trans('ErrorFailedToSendMail', $from, $sendto) . '
(unhandled error)
';
}
}
}
diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php
index 863bb9a6794..5683c8e6a07 100644
--- a/htdocs/core/class/CMailFile.class.php
+++ b/htdocs/core/class/CMailFile.class.php
@@ -926,7 +926,7 @@ class CMailFile
}
// send mail
try {
- $result = $this->mailer->send($this->message);
+ $result = $this->mailer->send($this->message, $failedRecipients);
} catch (Exception $e) {
$this->error = $e->getMessage();
}
@@ -936,6 +936,9 @@ class CMailFile
$res = true;
if (!empty($this->error) || !$result) {
+ if (!empty($failedRecipients)) {
+ $this->error = 'Transport failed for the following addresses: "' . join('", "', $failedRecipients) . '".';
+ }
dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
$res = false;
} else {
diff --git a/htdocs/product/price.php b/htdocs/product/price.php
index 7dfb94be79f..9548643166a 100644
--- a/htdocs/product/price.php
+++ b/htdocs/product/price.php
@@ -1470,7 +1470,6 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action == 'showlog_defaul
}
print ''.$langs->trans("PriceBase").' | ';
- print $conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL;
if (empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
print ''.$langs->trans("DefaultTaxRate").' | ';
}
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index e53675d8bb6..cb0f91851f2 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -3332,17 +3332,58 @@ class Societe extends CommonObject
{
// phpcs:enable
if ($this->id) {
- $sql = "UPDATE ".MAIN_DB_PREFIX."societe";
- $sql .= " SET parent = ".($id > 0 ? $id : "null");
- $sql .= " WHERE rowid = ".$this->id;
- dol_syslog(get_class($this).'::set_parent', LOG_DEBUG);
- $resql = $this->db->query($sql);
- if ($resql) {
- $this->parent = $id;
+ // Check if the id we want to add as parent has not already one parent that is the current id we try to update
+ $sameparent = $this->validateFamilyTree($id, $this->id, 0);
+ if ($sameparent < 0) {
+ return -1;
+ } elseif ($sameparent == 1) {
+ setEventMessages('ParentCompanyToAddIsAlreadyAChildOfModifiedCompany', null, 'warnings');
+ return -1;
+ } else {
+ $sql = 'UPDATE '.MAIN_DB_PREFIX.'societe SET parent = '.($id > 0 ? $id : 'null').' WHERE rowid = '.((int) $this->id);
+ dol_syslog(get_class($this).'::set_parent', LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $this->parent = $id;
+ return 1;
+ } else {
+ return -1;
+ }
+ }
+ } else {
+ return -1;
+ }
+ }
+
+ /**
+ * Check if a thirdparty $idchild is or not inside the parents (or grand parents) of another thirdparty id $idparent.
+ *
+ * @param int $idparent Id of thirdparty to check
+ * @param int $idchild Id of thirdparty to compare to
+ * @param int $counter Counter to protect against infinite loops
+ * @return int <0 if KO, 0 if OK or 1 if at some level a parent company was the child to compare to
+ */
+ public function validateFamilyTree($idparent, $idchild, $counter = 0)
+ {
+ if ($counter > 100) {
+ dol_syslog("Too high level of parent - child for company. May be an infinite loop ?", LOG_WARNING);
+ }
+
+ $sql = 'SELECT s.parent';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
+ $sql .= ' WHERE rowid = '.$idparent;
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $obj = $this->db->fetch_object($resql);
+
+ if ($obj->parent == '') {
+ return 0;
+ } elseif ($obj->parent == $idchild) {
return 1;
} else {
- return -1;
+ $sameparent = $this->validateFamilyTree($obj->parent, $idchild, ($counter + 1));
}
+ return $sameparent;
} else {
return -1;
}