From 150b7377379e535d0e98ebde1c177d7c3bc7ea57 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 25 Jun 2005 13:02:17 +0000 Subject: [PATCH] Fix: Corrige pb envoi propal par mail. --- htdocs/comm/propal.php | 252 ++++++++++++++++++++++++++--------------- 1 file changed, 160 insertions(+), 92 deletions(-) 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='
'.$langs->trans("MailSuccessfulySent",$from,$sendto).'.
'; + + // Insertion action + include_once("../contact.class.php"); + $actioncomm = new ActionComm($db); + $actioncomm->type_code = $actioncode; + $actioncomm->label = $actionmsg2; + $actioncomm->note = $actionmsg; + $actioncomm->date = $db->idate(time()); + $actioncomm->percent = 100; + $actioncomm->contact = new Contact($db,$sendtoid); + $actioncomm->societe = new Societe($db,$propal->socidp); + $actioncomm->user = $user; // User qui a fait l'action + $actioncomm->propalrowid = $propal->id; + + $ret=$actioncomm->add($user); // User qui saisi l'action + + if ($ret < 0) + { + dolibarr_print_error($db); + } + else + { + // Renvoie sur la fiche + Header("Location: propal.php?propalid=".$propal->id."&msg=".urlencode($msg)); + exit; + } + } + else + { + $msg='
'.$langs->trans("ErrorFailedToSendMail",$from,$sendto).' !
'; + } + } + else + { + $msg='
'.$langs->trans("ErrorMailRecipientIsEmpty").' !
'; + dolibarr_syslog("Le mail du destinataire est vide"); + } + + } + else + { + dolibarr_syslog("Impossible de lire :".$file); + } + } + else + { + dolibarr_syslog("Impossible de lire les données de la propale. Le fichier propal n'a peut-être pas été généré."); + } +} + if ($_GET["action"] == 'commande') { /* @@ -240,6 +360,8 @@ llxHeader(); */ if ($_GET["propalid"]) { + if ($msg) print "$msg
"; + $html = new Form($db); $propal = new Propal($db); @@ -296,7 +418,9 @@ if ($_GET["propalid"]) { $obj = $db->fetch_object($result); - $color1 = "#e0e0e0"; + + $soc = new Societe($db); + $soc->fetch($obj->idp); if ($propal->brouillon == 1 && $user->rights->propale->creer) { @@ -354,7 +478,7 @@ if ($_GET["propalid"]) print ''.$langs->trans("GlobalDiscount").''; if ($propal->brouillon == 1 && $user->rights->propale->creer) { - print '
'; + print ''; print '% '; print ''; print ' ?'; @@ -626,54 +750,6 @@ if ($_GET["propalid"]) } - - /* - * Envoi de la propale par mail - * - */ - if ($_GET["action"] == 'send') - { - $forbidden_chars=array("/","\\",":","*","?","\"","<",">","|","[","]",",",";","="); - $propref = str_replace($forbidden_chars,"_",$propal->ref); - $file = $conf->propal->dir_output . "/$propref/$propref.pdf"; - if (file_exists($file)) - { - - $subject = "Notre proposition commerciale $propal->ref"; - $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']; - $from = $_POST["fromname"] . " <".$_POST["frommail"] .">"; - $replyto = $_POST["replytoname"]. " <".$_POST["replytomail"].">"; - - $mailfile = new CMailFile($subject,$_POST["sendto"],$from,$_POST["message"],$filepath,$mimetype,$filename,$sendtocc); - - if (! $mailfile->sendfile() ) - { - print "!! erreur d'envoi"; - } - } - /* - * Enregistre l'action - * - */ - - $actioncomm = new ActionComm($db); - $actioncomm->priority = 2; - $actioncomm->type = 3; - $actioncomm->date = $db->idate(time()); - $actioncomm->percent = 100; - $actioncomm->contact = $propal->contactid; - $actioncomm->user = $user; - $actioncomm->societe = $propal->socidp; - $actioncomm->propalrowid = $propal->id; - $actioncomm->note = "Envoyée à ".$_POST["sendto"]; - $actioncomm->add($user); - } - /* * */ @@ -746,7 +822,7 @@ if ($_GET["propalid"]) /* * Liste des actions propres à la propal */ - $sql = "SELECT id, ".$db->pdate("a.datea"). " as da, note, fk_user_author" ; + $sql = "SELECT id, ".$db->pdate("a.datea"). " as da, label, note, fk_user_author" ; $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a"; $sql .= " WHERE a.fk_soc = $obj->idp AND a.propalrowid = $propal->id "; @@ -771,7 +847,7 @@ if ($_GET["propalid"]) print ""; print ''.img_object($langs->trans("ShowTask"),"task").' '.$objp->id.''; print ''.dolibarr_print_date($objp->da)."\n"; - print ''.stripslashes($objp->note).''; + print ''.stripslashes($objp->label).''; $authoract = new User($db); $authoract->id = $objp->fk_user_author; $authoract->fetch(''); @@ -800,42 +876,34 @@ if ($_GET["propalid"]) */ if ($_GET["action"] == 'presend') { - $replytoname = $user->fullname; - $replytomail = $user->email; - - $from_name = $user->fullname ; //$conf->propal->fromtoname; - $from_mail = $user->email; //conf->propal->fromtomail; - - $message = "Veuillez trouver ci-joint notre proposition commerciale $propal->ref\n\nCordialement\n\n"; + print '
'; + print_titre("SendPropalByMail"); + $liste[0]=" "; + foreach ($soc->contact_email_array() as $key=>$value) { + $liste[$key]=$value; + } - print "id&action=send\">\n"; - print ''; - print ''; - print ''; - - print_titre("Envoyer la propale par mail"); - - // Créé l'objet formulaire mail - include_once("../html.formmail.class.php"); - $formmail = new FormMail($db); - $formmail->fromname = $user->fullname; - $formmail->frommail = $user->email; - $formmail->withfrom=1; - $formmail->withto=ucfirst(strtolower($obj->firstname)) . " " . ucfirst(strtolower($obj->name)) . " <$obj->email>"; - $formmail->withcc=1; - $formmail->withtopic=$langs->trans("SendPropalRef","__PROPREF__"); - $formmail->withfile=1; - $formmail->withbody=1; - // Tableau des substitutions - $formmail->substit["__PROPREF__"]=$propal->ref; - // Tableau des paramètres complémentaires - $formmail->param["action"]="send"; - $formmail->param["models"]="propal_send"; - $formmail->param["propalid"]=$propal->id; - $formmail->param["returnurl"]=DOL_URL_ROOT."/comm/propal.php?propalid=$propal->id"; - - $formmail->show_form(); + // Créé l'objet formulaire mail + include_once("../html.formmail.class.php"); + $formmail = new FormMail($db); + $formmail->fromname = $user->fullname; + $formmail->frommail = $user->email; + $formmail->withfrom=1; + $formmail->withto=$liste; + $formmail->withcc=1; + $formmail->withtopic=$langs->trans("SendPropalRef","__PROPREF__"); + $formmail->withfile=1; + $formmail->withbody=1; + // Tableau des substitutions + $formmail->substit["__PROPREF__"]=$propal->ref; + // Tableau des paramètres complémentaires + $formmail->param["action"]="send"; + $formmail->param["models"]="propal_send"; + $formmail->param["propalid"]=$propal->id; + $formmail->param["returnurl"]=DOL_URL_ROOT."/comm/propal.php?propalid=$propal->id"; + + $formmail->show_form(); } }