';
diff --git a/htdocs/comm/mailing/fiche.php b/htdocs/comm/mailing/fiche.php
index cf232de04d3..967c79c7382 100644
--- a/htdocs/comm/mailing/fiche.php
+++ b/htdocs/comm/mailing/fiche.php
@@ -1,6 +1,6 @@
- * Copyright (C) 2005-2006 Laurent Destailleur
+ * Copyright (C) 2005-2008 Laurent Destailleur
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -15,19 +15,17 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Id$
- * $Source$
*/
/**
\file htdocs/comm/mailing/fiche.php
\ingroup mailing
\brief Fiche mailing, onglet général
- \version $Revision$
+ \version $Id$
*/
require("./pre.inc.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
$langs->load("mails");
@@ -52,13 +50,186 @@ $substitutionarrayfortest=array(
// Action envoi mailing pour tous
-if ($_GET["action"] == 'sendall')
+if ($_POST["action"] == 'sendallconfirmed')
{
- // Pour des raisons de sécurité, on ne permet pas cette fonction via l'IHM,
- // on affiche donc juste un message
- $message='
'.$langs->trans("MailingNeedCommand").'
';
- $message.=' ';
- $_GET["action"]='';
+ if (empty($conf->global->MAILING_LIMIT_SENDBYWEB))
+ {
+ // Pour des raisons de sécurité, on ne permet pas cette fonction via l'IHM,
+ // on affiche donc juste un message
+ $message='
'.$langs->trans("MailingNeedCommand").'
';
+ $message.=' ';
+ $message.='
'.$langs->trans("MailingNeedCommand2").'
';
+ $_GET["action"]='';
+ }
+ else
+ {
+ $id=$_GET['id'];
+
+ $error = 0;
+
+ // On récupére données du mail
+ $sql = "SELECT m.rowid, m.titre, m.sujet, m.body";
+ $sql .= " , m.email_from, m.email_replyto, m.email_errorsto";
+ $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
+ $sql .= " WHERE m.statut >= 1";
+ $sql .= " AND m.rowid= ".$id;
+ $sql .= " LIMIT 1";
+
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+ $i = 0;
+
+ if ($num == 1)
+ {
+ $obj = $db->fetch_object($resql);
+
+ dolibarr_syslog("mailing-send: mailing ".$id);
+
+ $id = $obj->rowid;
+ $subject = $obj->sujet;
+ $message = $obj->body;
+ $from = $obj->email_from;
+ $errorsto = $obj->email_errorsto;
+
+ // Le message est-il en html
+ $msgishtml=0; // Non par defaut
+ if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_MAILING) $msgishtml=1;
+ if (eregi('[ \t]*',$message)) $msgishtml=1;
+
+ $i++;
+ }
+ }
+
+ $nbok=0; $nbko=0;
+
+ // On choisit les mails non déjà envoyés pour ce mailing (statut=0)
+ // ou envoyés en erreur (statut=-1)
+ $sql = "SELECT mc.rowid, mc.nom, mc.prenom, mc.email";
+ $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
+ $sql .= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$id;
+
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+
+ if ($num)
+ {
+ dolibarr_syslog("mailing-send: target number = $num");
+ // Positionne date debut envoi
+ $sql="UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi=SYSDATE() WHERE rowid=".$id;
+ $resql2=$db->query($sql);
+ if (! $resql2)
+ {
+ dolibarr_print_error($db);
+ }
+
+ // Boucle sur chaque adresse et envoie le mail
+ $i = 0;
+
+ while ($i < $num && $i < $conf->global->MAILING_LIMIT_SENDBYWEB)
+ {
+
+ $res=1;
+
+ $obj = $db->fetch_object($resql);
+
+ // sendto en RFC2822
+ $sendto = $obj->prenom." ".$obj->nom." <".$obj->email.">";
+
+ // Pratique les substitutions sur le sujet et message
+ $substitutionarray=array(
+ '__ID__' => $obj->rowid,
+ '__EMAIL__' => $obj->email,
+ '__LASTNAME__' => $obj->nom,
+ '__FIRSTNAME__' => $obj->prenom
+ );
+
+ $substitutionisok=true;
+ $subject2=make_substitutions($subject,$substitutionarray);
+ $message2=make_substitutions($message,$substitutionarray);
+
+ // Fabrication du mail
+ $mail = new CMailFile($subject2, $sendto, $from, $message2,
+ array(), array(), array(),
+ '', '', 0, $msgishtml);
+ $mail->errors_to = $errorsto;
+
+
+ if ($mail->error)
+ {
+ $res=0;
+ }
+ if (! $substitutionisok)
+ {
+ $mail->error='Some substitution failed';
+ $res=0;
+ }
+
+ // Envoi du mail
+ if ($res)
+ {
+ $res=$mail->sendfile();
+ }
+
+ if ($res)
+ {
+ // Mail envoye avec succes
+ $nbok++;
+
+ dolibarr_syslog("mailing-send: ok for #".$i.' - '.$mail->error);
+
+ $sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
+ $sql.=" SET statut=1, date_envoi=SYSDATE() WHERE rowid=".$obj->rowid;
+ $resql2=$db->query($sql);
+ if (! $resql2)
+ {
+ dolibarr_print_error($db);
+ }
+ }
+ else
+ {
+ // Mail en echec
+ $nbko++;
+
+ dolibarr_syslog("mailing-send: error for #".$i.' - '.$mail->error);
+
+ $sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
+ $sql.=" SET statut=-1, date_envoi=SYSDATE() WHERE rowid=".$obj->rowid;
+ $resql2=$db->query($sql);
+ if (! $resql2)
+ {
+ dolibarr_print_error($db);
+ }
+ }
+
+ $i++;
+ }
+ }
+
+ // Loop finished, set global statut of mail
+ $statut=2; // By default status with error
+ if (! $nbko) $statut=3;
+
+ $sql="UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$id;
+ dolibarr_syslog("mailing-send: update global status sql=".$sql);
+ $resql2=$db->query($sql);
+ if (! $resql2)
+ {
+ dolibarr_print_error($db);
+ }
+ }
+ else
+ {
+ dolibarr_syslog($db->error());
+ dolibarr_print_error($db);
+ }
+ $message='';
+ $_GET["action"] = '';
+
+ }
}
// Action envoi test mailing
@@ -248,7 +419,7 @@ if ($_GET["action"] == 'create')
print '
';
- print '
'.$langs->trans("MailFrom").'
';
+ print '
'.$langs->trans("MailFrom").'
';
print '
'.$langs->trans("MailTitle").'
';
print '
'.$langs->trans("MailTopic").'
';
print '
'.$langs->trans("MailMessage").' ';
@@ -320,6 +491,24 @@ else
* Mailing en mode visu
*
*/
+ if ($_GET["action"] == 'sendall')
+ {
+ if (empty($conf->global->MAILING_LIMIT_SENDBYWEB))
+ {
+ // Pour des raisons de sécurité, on ne permet pas cette fonction via l'IHM,
+ // on affiche donc juste un message
+ $message='
';
@@ -365,6 +554,14 @@ else
print "";
+ if ($_GET["action"] == 'sendall')
+ {
+ // Pour des raisons de sécurité, on ne permet pas cette fonction via l'IHM,
+ // on affiche donc juste un message
+ $message='
'.$langs->trans("MailingNeedCommand").'
';
+ $message.=' ';
+ }
+
if ($message) print "$message ";
/*
@@ -388,7 +585,7 @@ else
print ''.$langs->trans("ValidMailing").'';
}
- if ($mil->statut == 1 && $mil->nbemail > 0 && $user->rights->mailing->valider)
+ if (($mil->statut == 1 || $mil->statut == 2) && $mil->nbemail > 0 && $user->rights->mailing->valider)
{
print ''.$langs->trans("SendMailing").'';
}
@@ -414,7 +611,7 @@ else
$formmail->withsubstit=1;
$formmail->withfrom=0;
$formmail->withto=$user->email?$user->email:1;
- $formmail->withcc=0;
+ $formmail->withtocc=0;
$formmail->withtopic=0;
$formmail->withtopicreadonly=1;
$formmail->withfile=0;
diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index 2486aa76cce..c5fba87c966 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -1771,7 +1771,7 @@ if ($_GET['propalid'] > 0)
$formmail->frommail = $user->email;
$formmail->withfrom=1;
$formmail->withto=$liste;
- $formmail->withcc=1;
+ $formmail->withtocc=1;
$formmail->withtopic=$langs->trans('SendPropalRef','__PROPREF__');
$formmail->withfile=1;
$formmail->withbody=1;
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index 32c18536425..da1d0f9469e 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -1942,7 +1942,7 @@ else
$formmail->frommail = $user->email;
$formmail->withfrom=1;
$formmail->withto=$liste;
- $formmail->withcc=1;
+ $formmail->withtocc=1;
$formmail->withtopic=$langs->trans('SendOrderRef','__ORDERREF__');
$formmail->withfile=1;
$formmail->withbody=1;
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 494eff4dbb5..c718b49f2b3 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -3055,7 +3055,8 @@ else
$formmail->frommail = $user->email;
$formmail->withfrom=1;
$formmail->withto=$liste;
- $formmail->withcc=1;
+ $formmail->withtocc=1;
+ $formmail->withtoccc=$conf->global->FACTURE_EMAIL_USECCC;
$formmail->withtopic=$langs->trans('SendBillRef','__FACREF__');
$formmail->withfile=1;
$formmail->withbody=1;
@@ -3111,7 +3112,7 @@ else
$formmail->frommail = $user->email;
$formmail->withfrom=1;
$formmail->withto=$liste;
- $formmail->withcc=1;
+ $formmail->withtocc=1;
$formmail->withtopic=$langs->trans('SendReminderBillRef','__FACREF__');
$formmail->withfile=1;
$formmail->withbody=1;
diff --git a/htdocs/html.formmail.class.php b/htdocs/html.formmail.class.php
index 7c2877e87d5..34ee99320a0 100644
--- a/htdocs/html.formmail.class.php
+++ b/htdocs/html.formmail.class.php
@@ -1,5 +1,5 @@
+/* Copyright (C) 2005-2008 Laurent Destailleur
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -14,14 +14,12 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Id$
*/
/**
\file htdocs/html.formmail.class.php
\brief Fichier de la classe permettant la génération du formulaire html d'envoi de mail unitaire
- \version $Revision$
+ \version $Id$
*/
require_once(DOL_DOCUMENT_ROOT ."/html.form.class.php");
@@ -79,6 +77,7 @@ class FormMail
$this->withfrom=1;
$this->withto=1;
$this->withtocc=1;
+ $this->withtoccc=0;
$this->witherrorsto=0;
$this->withtopic=1;
$this->withfile=0;
@@ -219,7 +218,7 @@ class FormMail
}
// CC
- if ($this->withcc)
+ if ($this->withtocc || is_array($this->withtocc))
{
print '
'.$langs->trans("MailCC").'
';
if ($this->withtoccreadonly)
@@ -238,6 +237,26 @@ class FormMail
print "
\n";
}
+ // CC
+ if ($this->withtoccc || is_array($this->withtoccc))
+ {
+ print '
\n";
+ }
+
// Accusé réception
if ($this->withdeliveryreceipt)
{
diff --git a/htdocs/langs/en_US/mails.lang b/htdocs/langs/en_US/mails.lang
index e6f54fb9f7c..b91680ce72b 100644
--- a/htdocs/langs/en_US/mails.lang
+++ b/htdocs/langs/en_US/mails.lang
@@ -48,7 +48,7 @@ NbOfRecipients=Number of recipients
NbOfUniqueEMails=Nb of unique emails
NbOfEMails=Nb of EMails
TotalNbOfDistinctRecipients=Number of distinct recipients
-NoTargetYet=No recipients defined yet
+NoTargetYet=No recipients defined yet (Go on tab 'Recipients')
AddRecipients=Add recipients
RemoveRecipient=Remove recipient
CommonSubstitutions=Common substitutions
@@ -72,6 +72,8 @@ SendMailing=Send emailing
SendMail=Send email
SentBy=Sent by
MailingNeedCommand=For securities reason, sending an emailing can only be performed from command line. Ask your administrator to launch the following command to send the emailing to all recipients:
+MailingNeedCommand2=You can however send them online by adding parameter MAILING_LIMIT_SENDBYWEB with value of max number of emails you want to send by session.
+ConfirmSendingEmailing=Are you sure you want to send mailing ? On line sending of emailings are limited for security reason to %s recipients by sending session.
TargetsReset=Clear list
ToClearAllRecipientsClickHere=To clear recipients' list for this emailing, click button
ToAddRecipientsChooseHere=To add recipients, choose in those lists
diff --git a/htdocs/langs/fr_FR/mails.lang b/htdocs/langs/fr_FR/mails.lang
index 180df79eefe..d01838cfa40 100644
--- a/htdocs/langs/fr_FR/mails.lang
+++ b/htdocs/langs/fr_FR/mails.lang
@@ -48,7 +48,7 @@ NbOfRecipients=Nombre de destinataires
NbOfUniqueEMails=Nb d'e-mails uniques
NbOfEMails=Nbre d'EMails
TotalNbOfDistinctRecipients=Nombre de destinataires uniques
-NoTargetYet=Aucun destinataire défini
+NoTargetYet=Aucun destinataire défini (Aller sur l'onglet Destinataires)
AddRecipients=Ajout de destinataires
RemoveRecipient=Supprime destinataire
CommonSubstitutions=Substitutions communes
@@ -68,10 +68,12 @@ TargetsStatistics=Statistiques destinataires
NbOfCompaniesContacts=Contacts uniques des sociétés
MailNoChangePossible=Destinataires d'un mailing validé non modifiables
SearchAMailing=Rechercher un mailing
-SendMailing=Envoi mailing
+SendMailing=Envoi emailing
SendMail=Envoi mail
SentBy=Envoyé par
-MailingNeedCommand=Pour des raisons de sécurité, l'envoi d'un mailing de masse ne peut être réalisé qu'en ligne de commande. Demandez à votre administrateur de lancer la commande suivante pour envoyer le mailing à tous les destinataires :
+MailingNeedCommand=Pour des raisons de sécurité, il est recommandé de faire les envois d'un mailing de masse depuis une ligne de commande. Demandez à votre administrateur de lancer la commande suivante pour envoyer le mailing à tous les destinataires :
+MailingNeedCommand2=Vous pouvez toutefois quand même les envoyer en ligne en ajoutant le parametre MAILING_LIMIT_SENDBYWEB avec la valeur du nombre max de mails envoyés par session d'envoi.
+ConfirmSendingEmailing=Confirmez-vous l'envoi de l'emailing ? L'envoi en ligne des mailings sont limités par sécurité à %s destinataires par session d'envoi.
TargetsReset=Vider liste
ToClearAllRecipientsClickHere=Pour vider la liste des destinataires de ce mailing, cliquer le bouton
ToAddRecipientsChooseHere=Pour ajouter des destinataires, choisir dans les listes ci-dessous
diff --git a/htdocs/telephonie/client/facture.php b/htdocs/telephonie/client/facture.php
index 8bb9a03b3f2..1034c928d35 100644
--- a/htdocs/telephonie/client/facture.php
+++ b/htdocs/telephonie/client/facture.php
@@ -675,7 +675,7 @@ if ($_GET["facid"] > 0)
$formmail->frommail = $user->email;
$formmail->withfrom=1;
$formmail->withto=$liste;
- $formmail->withcc=1;
+ $formmail->withtocc=1;
$formmail->withtopic=$langs->trans("SendBillRef","__FACREF__");
$formmail->withfile=1;
$formmail->withbody=1;
@@ -710,7 +710,7 @@ if ($_GET["facid"] > 0)
$formmail->frommail = $user->email;
$formmail->withfrom=1;
$formmail->withto=$liste;
- $formmail->withcc=1;
+ $formmail->withtocc=1;
$formmail->withtopic=$langs->trans("SendReminderBillRef","__FACREF__");
$formmail->withfile=1;
$formmail->withbody=1;