From 221b671636f5e960ecad95903f0ba799302121f0 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Thu, 6 Sep 2012 19:07:51 +0200
Subject: [PATCH] New: The signature feature is full ok now.

---
 ChangeLog                                 |  2 +-
 htdocs/admin/mails.php                    |  2 +-
 htdocs/comm/mailing/fiche.php             |  2 +-
 htdocs/core/class/html.formmail.class.php | 11 -----------
 htdocs/core/lib/functions.lib.php         |  4 ++++
 htdocs/langs/en_US/other.lang             |  4 ++--
 htdocs/langs/fr_FR/other.lang             |  4 ++--
 7 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cf059c60b7a..47daf5bc6ae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,7 +5,7 @@ English Dolibarr ChangeLog
 
 ***** ChangeLog for 3.3 compared to 3.2.2 *****
 For users:
-- New: If field "signature" is filled into user table, text is added 
+- New: Add field "signature" into thirdparty card. If filled, text is added 
   at end of predefined email texts. If option MAIL_DO_NOT_USE_SIGN is on, this
   feature is disabled.
 - New: Add link "Back to list" on all cards.
diff --git a/htdocs/admin/mails.php b/htdocs/admin/mails.php
index 4262616fef8..b2341019ead 100644
--- a/htdocs/admin/mails.php
+++ b/htdocs/admin/mails.php
@@ -40,7 +40,7 @@ $substitutionarrayfortest=array(
 '__EMAIL__' => 'TESTEMail',
 '__LASTNAME__' => 'TESTLastname',
 '__FIRSTNAME__' => 'TESTFirstname',
-'__SIGNATURE__' => 'TESTSignature',
+'__SIGNATURE__' => (($user->signature && empty($conf->global->MAIL_DO_NOT_USE_SIGN))?$user->signature:''),
 //'__PERSONALIZED__' => 'TESTPersonalized'	// Hiden because not used yet
 );
 complete_substitutions_array($substitutionarrayfortest, $langs);
diff --git a/htdocs/comm/mailing/fiche.php b/htdocs/comm/mailing/fiche.php
index c1b8628dca8..39bdc5f1ec7 100644
--- a/htdocs/comm/mailing/fiche.php
+++ b/htdocs/comm/mailing/fiche.php
@@ -88,7 +88,7 @@ $object->substitutionarrayfortest=array(
     '__OTHER3__' => 'TESTOther3',
     '__OTHER4__' => 'TESTOther4',
     '__OTHER5__' => 'TESTOther5',
-    '__SIGNATURE__' => 'TESTSignature',
+	'__SIGNATURE__' => (($user->signature && empty($conf->global->MAIL_DO_NOT_USE_SIGN))?$user->signature:''),
     //'__PERSONALIZED__' => 'TESTPersonalized'	// Not used yet
 );
 if (!empty($conf->global->MAILING_EMAIL_UNSUBSCRIBE))
diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php
index 5d408c47cbf..df775c55cd7 100644
--- a/htdocs/core/class/html.formmail.class.php
+++ b/htdocs/core/class/html.formmail.class.php
@@ -601,17 +601,6 @@ class FormMail
             {
             	if (! isset($this->ckeditortoolbar)) $this->ckeditortoolbar = 'dolibarr_notes';
 
-                if (empty($conf->global->MAIL_DO_NOT_USE_SIGN) && $this->fromid > 0)
-                {
-                    $fuser=new User($this->db);
-                    $fuser->fetch($this->fromid);
-
-                    if(! empty($fuser->signature)) 
-                    {
-                        $defaultmessage.=dol_htmlentitiesbr_decode($fuser->signature);
-                    }
-                }
-
                 // Editor wysiwyg
                 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
                 $doleditor=new DolEditor('message',$defaultmessage,'',280,$this->ckeditortoolbar,'In',true,true,$this->withfckeditor,8,72);
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index e7b608cfb0e..e746708d277 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -3406,13 +3406,17 @@ function dol_textishtml($msg,$option=0)
  */
 function make_substitutions($chaine,$substitutionarray)
 {
+	global $conf;
+
 	if (! is_array($substitutionarray)) return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
 
 	// Make substitition
 	foreach ($substitutionarray as $key => $value)
 	{
+		if ($key == '__SIGNATURE__' && (! empty($conf->global->MAIL_DO_NOT_USE_SIGN))) $value='';
 		$chaine=str_replace("$key","$value",$chaine);	// We must keep the " to work when value is 123.5 for example
 	}
+
 	return $chaine;
 }
 
diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang
index 7587bdc12d5..57e34e66146 100644
--- a/htdocs/langs/en_US/other.lang
+++ b/htdocs/langs/en_US/other.lang
@@ -46,8 +46,8 @@ AttachANewFile=Attach a new file/document
 LinkedObject=Linked object
 Miscellanous=Miscellaneous
 NbOfActiveNotifications=Number of notifications
-PredefinedMailTest=This is a test mail.\nThe two lines are separated by a carriage return.
-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.
+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=You will find here the invoice __FACREF__\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
 PredefinedMailContentSendInvoiceReminder=We would like to warn you that the invoice  __FACREF__ seems to not being payed. So this is the invoice in attachment again, as a reminder.\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
 PredefinedMailContentSendProposal=You will find here the commercial propoal __PROPREF__\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
diff --git a/htdocs/langs/fr_FR/other.lang b/htdocs/langs/fr_FR/other.lang
index bb43e302431..127e874a6df 100644
--- a/htdocs/langs/fr_FR/other.lang
+++ b/htdocs/langs/fr_FR/other.lang
@@ -45,8 +45,8 @@ AttachANewFile=Ajouter un nouveau fichier/document
 LinkedObject=Objet lié
 Miscellanous=Divers
 NbOfActiveNotifications=Nombre de notifications 
-PredefinedMailTest=Ceci est un mail de test.\nLes 2 lignes sont séparées par un retour à la ligne.
-PredefinedMailTestHtml=Ceci est un mail de <b>test</b> (le mot test doit être en gras).<br>Les 2 lignes sont séparées par un retour à la ligne.
+PredefinedMailTest=Ceci est un mail de test.\nLes 2 lignes sont séparées par un retour à la ligne.\n\n__SIGNATURE__
+PredefinedMailTestHtml=Ceci est un mail de <b>test</b> (le mot test doit être en gras).<br>Les 2 lignes sont séparées par un retour à la ligne.<br><br>__SIGNATURE__
 PredefinedMailContentSendInvoice=Veuillez trouver ci-joint la facture __FACREF__\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
 PredefinedMailContentSendInvoiceReminder=Nous apportons à votre connaissance que la facture  __FACREF__ ne semble pas avoir été réglée. La voici donc, pour rappel, en pièce jointe.\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
 PredefinedMailContentSendProposal=Veuillez trouver ci-joint la proposition commerciale __PROPREF__\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
-- 
GitLab