diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index aad40d9000f..9b4d2755d79 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -39,12 +39,8 @@ $user->getrights('propale');
if (!$user->rights->propale->lire)
accessforbidden();
-if ($conf->projet->enabled) {
- require_once "../project.class.php";
-}
-if($conf->commande->enabled) {
- require_once "../commande/commande.class.php";
-}
+if ($conf->projet->enabled) require_once "../project.class.php";
+if($conf->commande->enabled) require_once "../commande/commande.class.php";
require("./propal_model_pdf.class.php");
require("../propal.class.php");
require("../actioncomm.class.php");
@@ -59,6 +55,10 @@ if ($user->societe_id > 0)
$socidp = $user->societe_id;
}
+if ($_GET["socidp"]) { $socidp=$_GET["socidp"]; }
+if (isset($_GET["msg"])) { $msg=urldecode($_GET["msg"]); }
+
+
// Nombre de ligne pour choix de produit/service prédéfinis
$NBLINES=4;
@@ -138,6 +138,126 @@ if ($_POST["action"] == 'setstatut' && $user->rights->propale->cloturer)
$propal->cloture($user, $_POST["statut"], $_POST["note"]);
}
+/*
+* Envoi de la propale par mail
+*
+*/
+if ($_POST["action"] == 'send')
+{
+ $langs->load("mails");
+
+ $propal= new Propal($db);
+ if ( $propal->fetch($_POST["propalid"]) )
+ {
+ $forbidden_chars=array("/","\\",":","*","?","\"","<",">","|","[","]",",",";","=");
+ $propalref = str_replace($forbidden_chars,"_",$propal->ref);
+ $file = $conf->propal->dir_output . "/" . $propalref . "/" . $propalref . ".pdf";
+
+ if (is_readable($file))
+ {
+ $soc = new Societe($db, $propal->socidp);
+
+ if ($_POST["sendto"]) {
+ // Le destinataire a été fourni via le champ libre
+ $sendto = $_POST["sendto"];
+ $sendtoid = 0;
+ }
+ elseif ($_POST["receiver"]) {
+ // Le destinataire a été fourni via la liste déroulante
+ $sendto = $soc->contact_get_email($_POST["receiver"]);
+ $sendtoid = $_POST["receiver"];
+ }
+
+ if (strlen($sendto))
+ {
+ $from = $_POST["fromname"] . " <" . $_POST["frommail"] .">";
+ $replyto = $_POST["replytoname"]. " <" . $_POST["replytomail"].">";
+ $message = $_POST["message"];
+ if ($_POST["action"] == 'send') {
+ $subject = $langs->trans("Propal")." $propal->ref";
+ $actioncode=3;
+ $actionmsg ="Mail envoyé par $from à $sendto.
";
+ if ($message) {
+ $actionmsg.="Texte utilisé dans le corps du message:
";
+ $actionmsg.="$message";
+ }
+ $actionmsg2="Envoi Propal par mail";
+ }
+ /*
+ if ($_POST["action"] == 'relance') {
+ $subject = "Relance facture $propal->ref";
+ $actioncode=10;
+ $actionmsg="Mail envoyé par $from à $sendto.
";
+ if ($message) {
+ $actionmsg.="Texte utilisé dans le corps du message:
";
+ $actionmsg.="$message";
+ }
+ $actionmsg2="Relance Facture par mail";
+ }
+ */
+ $filepath[0] = $file;
+ $filename[0] = $propal->ref.".pdf";
+ $mimetype[0] = "application/pdf";
+ $filepath[1] = $_FILES['addedfile']['tmp_name'];
+ $filename[1] = $_FILES['addedfile']['name'];
+ $mimetype[1] = $_FILES['addedfile']['type'];
+
+ // Envoi de la facture
+ $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc);
+
+ if (! $mailfile->sendfile())
+ {
+ $msg='