From dcc197eb6be63a5ab5fdb9cb5fd4a2ac651e51b9 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Fri, 22 May 2015 17:13:32 +0200
Subject: [PATCH] Fix bug debian 786479

---
 htdocs/comm/propal.php    | 22 +++++++++++++++++++++-
 htdocs/compta/facture.php | 28 ++++++++++++++++++++++++----
 2 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index beaa24be32e..39bd54a21ac 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -494,6 +494,27 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
 			}
 		}
 
+		if ($_POST['sendtocc'])
+		{
+			// Le destinataire a ete fourni via le champ libre
+			$sendtocc = $_POST['sendtocc'];
+			$sendtoccid = 0;
+		}
+		elseif ($_POST['receivercc'] != '-1')
+		{
+			// Recipient was provided from combo list
+			if ($_POST['receivercc'] == 'thirdparty') // Id of third party
+			{
+				$sendtocc = $object->client->email;
+				$sendtoccid = 0;
+			}
+			else    // Id du contact
+			{
+				$sendtocc = $object->client->contact_get_property($_POST['receivercc'],'email');
+				$sendtoccid = $_POST['receivercc'];
+			}
+		}
+
 		if (dol_strlen($sendto))
 		{
 			$langs->load("commercial");
@@ -501,7 +522,6 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
 			$from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
 			$replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
 			$message = $_POST['message'];
-			$sendtocc = $_POST['sendtocc'];
 			$deliveryreceipt = $_POST['deliveryreceipt'];
 
 			if (dol_strlen($_POST['subject'])) $subject = $_POST['subject'];
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 11a920877cd..6aa81ff4270 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -283,12 +283,12 @@ else if ($action == 'setinvoicedate' && $user->rights->facture->creer)
 	$object->fetch($id);
 	$old_date_lim_reglement=$object->date_lim_reglement;
 	$date=dol_mktime(12,0,0,$_POST['invoicedatemonth'],$_POST['invoicedateday'],$_POST['invoicedateyear']);
-	if (empty($date)) 
+	if (empty($date))
 	{
 	    setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")),'errors');
 	    header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id.'&action=editinvoicedate');
 	    exit;
-	     
+
 	}
     $object->date=$date;
 	$new_date_lim_reglement=$object->calculate_date_lim_reglement();
@@ -1712,6 +1712,27 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
 			}
 		}
 
+		if ($_POST['sendtocc'])
+		{
+		        // Le destinataire a ete fourni via le champ libre
+		        $sendtocc = $_POST['sendtocc'];
+		        $sendtoccid = 0;
+		}
+		elseif ($_POST['receivercc'] != '-1')
+		{
+		        // Recipient was provided from combo list
+		        if ($_POST['receivercc'] == 'thirdparty') // Id of third party
+		        {
+		                $sendtocc = $object->client->email;
+		                $sendtoccid = 0;
+		        }
+		        else    // Id du contact
+		        {
+		                $sendtocc = $object->client->contact_get_property($_POST['receivercc'],'email');
+		                $sendtoccid = $_POST['receivercc'];
+		        }
+		}
+
 		if (dol_strlen($sendto))
 		{
 			$langs->load("commercial");
@@ -1719,7 +1740,6 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
 			$from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
 			$replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
 			$message = $_POST['message'];
-			$sendtocc = $_POST['sendtocc'];
 			$deliveryreceipt = $_POST['deliveryreceipt'];
 
 			if ($action == 'send')
@@ -3810,7 +3830,7 @@ else if ($id > 0 || ! empty($ref))
 		// Linked object block
 		$somethingshown=$object->showLinkedObjectBlock();
 
-		if (empty($somethingshown) && ! empty($conf->commande->enabled)) 
+		if (empty($somethingshown) && ! empty($conf->commande->enabled))
 		{
 			print '<br><a href="#" id="linktoorder">' . $langs->trans('LinkedOrder') . '</a>';
 
-- 
GitLab