From dfe1ee7e7d26dbb5d73a8fff685d5d8223309a95 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Fri, 13 Mar 2015 14:11:59 +0100
Subject: [PATCH] Fix: count of notification emails was wrong

---
 htdocs/langs/en_US/other.lang  |  2 +-
 htdocs/societe/notify/card.php | 32 +++++++++++++++++++++++---------
 2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang
index f5b39b3f704..1e3a7f038ff 100644
--- a/htdocs/langs/en_US/other.lang
+++ b/htdocs/langs/en_US/other.lang
@@ -54,7 +54,7 @@ MaxSize=Maximum size
 AttachANewFile=Attach a new file/document
 LinkedObject=Linked object
 Miscellaneous=Miscellaneous
-NbOfActiveNotifications=Number of notifications
+NbOfActiveNotifications=Number of notifications (nb of recipient emails)
 PredefinedMailTest=This is a test mail.\nThe two lines are separated by a carriage return.\n\n__SIGNATURE__
 PredefinedMailTestHtml=This is a <b>test</b> mail (the word test must be in bold).<br>The two lines are separated by a carriage return.<br><br>__SIGNATURE__
 PredefinedMailContentSendInvoice=__CONTACTCIVNAME__\n\nYou will find here the invoice __FACREF__\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
diff --git a/htdocs/societe/notify/card.php b/htdocs/societe/notify/card.php
index 1845669dcfc..388a271cd8c 100644
--- a/htdocs/societe/notify/card.php
+++ b/htdocs/societe/notify/card.php
@@ -169,6 +169,8 @@ if ($result > 0)
 
     print '<tr><td>'.$langs->trans("NbOfActiveNotifications").'</td>';
     print '<td colspan="3">';
+    $nb=0;
+    // List of per contact notifications
     $sql = "SELECT COUNT(n.rowid) as nb";
     $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n";
     $sql.= " WHERE fk_soc = ".$object->id;
@@ -187,6 +189,13 @@ if ($result > 0)
     else {
         dol_print_error($db);
     }
+    // List of notifications enabled for fixed email
+    foreach($conf->global as $key => $val)
+    {
+    	if (! preg_match('/^NOTIFICATION_FIXEDEMAIL_(.*)/', $key, $reg)) continue;
+    	$listtmp=explode(',',$val);
+    	$nb+=count($listtmp);
+    }
     print $nb;
     print '</td></tr>';
     print '</table>';
@@ -273,16 +282,21 @@ if ($result > 0)
     foreach($conf->global as $key => $val)
     {
     	if (! preg_match('/^NOTIFICATION_FIXEDEMAIL_(.*)/', $key, $reg)) continue;
-    	//print $key.' - '.$val.' - '.$reg[1].'<br>';
-		print '<tr '.$bc[$var].'><td>'.$val;
-		if (isValidEmail($val))
+		print '<tr '.$bc[$var].'><td>';
+		$listtmp=explode(',',$val);
+		foreach($listtmp as $keyemail => $valemail)
 		{
-			print ' &lt;'.$val.'&gt;';
-		}
-		else
-		{
-			$langs->load("errors");
-			print ' &nbsp; '.img_warning().' '.$langs->trans("ErrorBadEMail",$val);
+			$valemail=trim($valemail);
+    		//print $keyemail.' - '.$valemail.' - '.$reg[1].'<br>';
+			if (isValidEmail($valemail))
+			{
+				print ' &lt;'.$valemail.'&gt;';
+			}
+			else
+			{
+				$langs->load("errors");
+				print ' &nbsp; '.img_warning().' '.$langs->trans("ErrorBadEMail",$valemail);
+			}
 		}
 		print '</td>';
 		print '<td>';
-- 
GitLab