From 5ef2717027e2e22b830e4d293dce985445994a39 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 23 Oct 2004 14:25:59 +0000 Subject: [PATCH] =?UTF-8?q?Fix:=20Corrections=20diverses=20sur=20l'outil?= =?UTF-8?q?=20d'envoi=20des=20mailings=20New:=20Ajout=20de=20la=20possibil?= =?UTF-8?q?it=E9=20d'envoyer=20un=20mailing=20=E0=20tous=20les=20utilisate?= =?UTF-8?q?urs=20Dolibarr.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/comm/mailing.php | 143 +++++++++++++++++++++++++++++----------- 1 file changed, 105 insertions(+), 38 deletions(-) diff --git a/htdocs/comm/mailing.php b/htdocs/comm/mailing.php index 12904edac82..d9bff888a64 100644 --- a/htdocs/comm/mailing.php +++ b/htdocs/comm/mailing.php @@ -29,6 +29,11 @@ */ require("./pre.inc.php"); +$langs->load("admin"); +$langs->load("commercial"); +$langs->load("users"); +$langs->load("bills"); +$langs->load("companies"); /* * Modules optionnels @@ -49,82 +54,144 @@ if ($user->societe_id > 0) $socidp = $user->societe_id; } + +llxHeader(); + + /******************************************************************************/ /* Actions */ /******************************************************************************/ -llxHeader(); -print_fiche_titre ("Mailing"); + +print_fiche_titre($langs->trans("Mailing")); + + if ($_GET["action"] != 'mailing') { + print $langs->trans("MailingDesc")."

"; + + $form = new Form($db); + print "
"; + + // To + print ""; + print ""; + print ""; + print "
".$langs->trans("MailTo").""; print "

"; - print "

"; - print "

"; - print "

"; - print ""; - print ""; + print ""; + print ""; + print ""; + print ""; + print "
"; + + // Affiche la partie mail topic + message + file + $form->mail_topicmessagefile(1,1,1,$defaultmessage); + + print "
trans("Send")."\">
\n"; + + print "trans("MailingResult")."

"; + $cible=$_POST['receiver']; $subject=$_POST['subject']; - $body=$_POST['body']; + $body=$_POST['message']; + + // Definition de la requete qui donne les groupes d'email cibles if($cible=="prospects") - $all_soc_req="SELECT idp,nom FROM llx_societe WHERE client=2"; //prospect + $all_group_req="SELECT idp,nom FROM llx_societe WHERE client=2"; //prospect elseif($cible=="clients") - $all_soc_req="SELECT idp,nom FROM llx_societe WHERE client=1"; //client - $all_soc_res = @$db->query($all_soc_req); + $all_group_req="SELECT idp,nom FROM llx_societe WHERE client=1"; //client + elseif($cible=="dolusers") + $all_group_req="SELECT 0,'".$langs->trans("DolibarrUsers")."' nom"; + else { + dolibarr_print_error(0,$langs->trans("ErrorUnkownReceiver")); + exit; + } + + $all_group_res = $db->query($all_group_req); + if (! $all_group_res) { + dolibarr_print_error($db); + exit; + } + $num_soc = $db->num_rows(); $i=0; - while ($i < $num_soc) - { - $obj = $db->fetch_object($i); - $tab_soc[$i]=$obj->idp; - $tab_soc_nom[$i]=$obj->nom; - $i++; - } - print ""; - print ""; + if ($num_soc > 0) { + while ($i < $num_soc) + { + $obj = $db->fetch_object($all_group_res); + $tab_soc[$i]=$obj->idp; + $tab_soc_nom[$i]=$obj->nom; + $i++; + } + } + else { + print $langs->trans("ErrorNoGroupFound"); + } + + print '
SociétéE-MailNomPrénomStatus
'; + print ''; foreach($tab_soc as $idp) { $h=0; - $all_socpeop_req="SELECT * FROM llx_socpeople WHERE fk_soc=$idp"; - $all_socpeop_res = @$db->query($all_socpeop_req); + if($cible=="dolusers") { + $all_peop_req="SELECT rowid idp, name, firstname, email FROM llx_user"; + } + else { + $all_peop_req="SELECT idp, name, firstname, email FROM llx_socpeople WHERE fk_soc=$idp"; + } + + $all_peop_res = $db->query($all_peop_req); + if (! $all_peop_res) { + dolibarr_print_error($db); + exit; + } + $num_socpeop = $db->num_rows(); $j=0; while($j < $num_socpeop) { - $obj_soc = $db->fetch_object($j); - if($obj_soc->email!="") + + $obj_target = $db->fetch_object($all_peop_res); + + if($obj_target->email!="") { $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/plain; charset=iso-8859-1\n"; $headers .= "From: ".$user->fullname." <".MAILING_EMAIL.">\r\n"; $headers .= "Reply-to:".$user->fullname." <".MAILING_EMAIL.">\r\n"; $headers .= "X-Priority: 3\r\n"; - $headers .= "X-Mailer: Dolibarr V 1.2\r\n"; - $m=mail ($obj_soc->name." ".$obj_soc->firstname."<".$obj_soc->email.">", $subject, $body, $headers); - print ""; + $headers .= "X-Mailer: Dolibarr ".DOL_VERSION."\r\n"; + + $m=mail($obj_target->name." ".$obj_target->firstname."<".$obj_target->email.">", $subject, $body, $headers); + + print ""; if($m) { - print ""; - $sql="INSERT INTO llx_actioncomm (datea, fk_action, fk_soc, fk_user_author, fk_user_action, fk_contact, percent, note,priority,propalrowid) VALUES (NOW(),4, $idp,$user->id,$user->id,$obj_soc->idp, '100%', '', 0, 0)"; - $res= @$db->query($sql); - + if($cible!="dolusers") { + print ''; + $sql="INSERT INTO llx_actioncomm (datea, fk_action, fk_soc, fk_user_author, fk_user_action, fk_contact, percent, note,priority,propalrowid) VALUES (NOW(),4, $idp,$user->id,$user->id,$obj_target->idp, '100%', '', 0, 0)"; + $res= $db->query($sql); + } } else { - print ""; - $sql2="INSERT INTO llx_actioncomm (datea, fk_action, fk_soc, fk_user_author, fk_user_action, fk_contact, percent, note,priority,propalrowid) VALUES (NOW(),4, $idp,$user->id,$user->id,$obj_soc->idp, '0%', '', 0, 0)"; - $res2= @$db->query($sql2); + if($cible!="dolusers") { + print ''; + $sql="INSERT INTO llx_actioncomm (datea, fk_action, fk_soc, fk_user_author, fk_user_action, fk_contact, percent, note,priority,propalrowid) VALUES (NOW(),4, $idp,$user->id,$user->id,$obj_target->idp, '0%', '', 0, 0)"; + $res= $db->query($sql); + } } + print ''; } $j++; } $h++; - } + } + print '
'.$langs->trans("Group").' / '.$langs->trans("Company").''.$langs->trans("EMail").''.$langs->trans("Name").''.$langs->trans("Lastname").''.$langs->trans("Status").'
$h$tab_soc_nom[$h]$obj_soc->email$obj_soc->name$obj_soc->firstname
$h$tab_soc_nom[$h]$obj_target->email$obj_target->name$obj_target->firstnameréussi
'.$langs->trans("ResultOk").'raté
'.$langs->trans("ResultKo").'
'; } ?>