Fix: Use of other field in mailing-send
This commit is contained in:
parent
db74ace61c
commit
372ecf4e2a
@ -14,32 +14,14 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*
|
|
||||||
* $Id$
|
|
||||||
* $Source$
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* Export simple des contacts
|
|
||||||
*
|
|
||||||
* L'utilisation d'adresses de courriers électroniques dans les opérations
|
|
||||||
* de prospection commerciale est subordonnée au recueil du consentement
|
|
||||||
* préalable des personnes concernées.
|
|
||||||
*
|
|
||||||
* Le dispositif juridique applicable a été introduit par l'article 22 de
|
|
||||||
* la loi du 21 juin 2004 pour la confiance dans l'économie numérique.
|
|
||||||
*
|
|
||||||
* Les dispositions applicables sont définies par les articles L. 34-5 du
|
|
||||||
* code des postes et des télécommunications et L. 121-20-5 du code de la
|
|
||||||
* consommation. L'application du principe du consentement préalable en
|
|
||||||
* droit français résulte de la transposition de l'article 13 de la Directive
|
|
||||||
* européenne du 12 juillet 2002 « Vie privée et communications électroniques ».
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\file scripts/mailing/mailing-prepare.php
|
* \file scripts/emailing/mailing-prepare.php
|
||||||
\ingroup mailing
|
* \ingroup mailing
|
||||||
\brief Script pour préparer les destinataires d'un mailing
|
* \brief Script pour preparer les destinataires d'un mailing
|
||||||
*/
|
* \version $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
require_once("../../htdocs/master.inc.php");
|
require_once("../../htdocs/master.inc.php");
|
||||||
|
|
||||||
@ -49,28 +31,28 @@ $sql = "SELECT m.rowid, m.cible";
|
|||||||
$sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
|
$sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
|
||||||
$sql .= " WHERE m.statut in (0,1)";
|
$sql .= " WHERE m.statut in (0,1)";
|
||||||
|
|
||||||
if ( $db->query($sql) )
|
if ( $db->query($sql) )
|
||||||
{
|
{
|
||||||
$num = $db->num_rows();
|
$num = $db->num_rows();
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
while ($i < $num)
|
|
||||||
{
|
|
||||||
$row = $db->fetch_row();
|
|
||||||
|
|
||||||
dol_syslog("mailing-prepare: mailing $row[0]");
|
while ($i < $num)
|
||||||
dol_syslog("mailing-prepare: mailing module $row[1]");
|
{
|
||||||
|
$row = $db->fetch_row();
|
||||||
|
|
||||||
require_once(DOL_DOCUMENT_ROOT.'/includes/modules/mailings/'.$row[1].'.modules.php');
|
dol_syslog("mailing-prepare: mailing $row[0]");
|
||||||
|
dol_syslog("mailing-prepare: mailing module $row[1]");
|
||||||
|
|
||||||
$classname = "mailing_".$row[1];
|
require_once(DOL_DOCUMENT_ROOT.'/includes/modules/mailings/'.$row[1].'.modules.php');
|
||||||
|
|
||||||
$obj = new $classname($db);
|
$classname = "mailing_".$row[1];
|
||||||
$obj->add_to_target($row[0]);
|
|
||||||
|
|
||||||
$i++;
|
$obj = new $classname($db);
|
||||||
|
$obj->add_to_target($row[0]);
|
||||||
}
|
|
||||||
|
$i++;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file scripts/mailing/mailing-send.php
|
* \file scripts/emailings/mailing-send.php
|
||||||
* \ingroup mailing
|
* \ingroup mailing
|
||||||
* \brief Script d'envoi d'un mailing prepare et valide
|
* \brief Script d'envoi d'un mailing prepare et valide
|
||||||
* \version $Id$
|
* \version $Id$
|
||||||
@ -30,13 +30,13 @@
|
|||||||
// Test if CLI mode
|
// Test if CLI mode
|
||||||
$sapi_type = php_sapi_name();
|
$sapi_type = php_sapi_name();
|
||||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||||
echo "Error: You are using PH for CGI/Web. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
echo "Error: You are using PH for CGI/Web. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isset($argv[1]) || ! $argv[1]) {
|
if (! isset($argv[1]) || ! $argv[1]) {
|
||||||
print "Usage: mailing-send.php ID_MAILING\n";
|
print "Usage: mailing-send.php ID_MAILING\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
$id=$argv[1];
|
$id=$argv[1];
|
||||||
|
|
||||||
@ -91,37 +91,37 @@ $nbok=0; $nbko=0;
|
|||||||
|
|
||||||
// On choisit les mails non deja envoyes pour ce mailing (statut=0)
|
// On choisit les mails non deja envoyes pour ce mailing (statut=0)
|
||||||
// ou envoyes en erreur (statut=-1)
|
// ou envoyes en erreur (statut=-1)
|
||||||
$sql = "SELECT mc.rowid, mc.nom, mc.prenom, mc.email";
|
$sql = "SELECT mc.rowid, mc.nom, mc.prenom, mc.email, mc.other";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
|
$sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
|
||||||
$sql .= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$id;
|
$sql .= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$id;
|
||||||
|
|
||||||
$resql=$db->query($sql);
|
$resql=$db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
|
|
||||||
if ($num)
|
if ($num)
|
||||||
{
|
{
|
||||||
dol_syslog("mailing-send: nb of targets = ".$num, LOG_DEBUG);
|
dol_syslog("mailing-send: nb of targets = ".$num, LOG_DEBUG);
|
||||||
|
|
||||||
// Positionne date debut envoi
|
// Positionne date debut envoi
|
||||||
$sql="UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi=SYSDATE() WHERE rowid=".$id;
|
$sql="UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi=SYSDATE() WHERE rowid=".$id;
|
||||||
$resql2=$db->query($sql);
|
$resql2=$db->query($sql);
|
||||||
if (! $resql2)
|
if (! $resql2)
|
||||||
{
|
{
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Boucle sur chaque adresse et envoie le mail
|
// Boucle sur chaque adresse et envoie le mail
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while ($i < $num)
|
while ($i < $num)
|
||||||
{
|
{
|
||||||
$res=1;
|
$res=1;
|
||||||
|
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
|
|
||||||
// sendto en RFC2822
|
// sendto en RFC2822
|
||||||
$sendto = eregi_replace(',',' ',$obj->prenom." ".$obj->nom) ." <".$obj->email.">";
|
$sendto = eregi_replace(',',' ',$obj->prenom." ".$obj->nom) ." <".$obj->email.">";
|
||||||
|
|
||||||
// Make subtsitutions on topic and body
|
// Make subtsitutions on topic and body
|
||||||
$other=split(';',$obj->other);
|
$other=split(';',$obj->other);
|
||||||
@ -146,9 +146,9 @@ if ($resql)
|
|||||||
$newsubject=make_substitutions($subject,$substitutionarray);
|
$newsubject=make_substitutions($subject,$substitutionarray);
|
||||||
$newmessage=make_substitutions($message,$substitutionarray);
|
$newmessage=make_substitutions($message,$substitutionarray);
|
||||||
|
|
||||||
// Fabrication du mail
|
// Fabrication du mail
|
||||||
$mail = new CMailFile($newsubject, $sendto, $from, $newmessage,
|
$mail = new CMailFile($newsubject, $sendto, $from, $newmessage,
|
||||||
array(), array(), array(),
|
array(), array(), array(),
|
||||||
'', '', 0, $msgishtml, $errorsto);
|
'', '', 0, $msgishtml, $errorsto);
|
||||||
|
|
||||||
if ($mail->error)
|
if ($mail->error)
|
||||||
@ -161,63 +161,63 @@ if ($resql)
|
|||||||
$res=0;
|
$res=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send Email
|
// Send Email
|
||||||
if ($res)
|
if ($res)
|
||||||
{
|
{
|
||||||
$res=$mail->sendfile();
|
$res=$mail->sendfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($res)
|
if ($res)
|
||||||
{
|
{
|
||||||
// Mail successful
|
// Mail successful
|
||||||
$nbok++;
|
$nbok++;
|
||||||
|
|
||||||
dol_syslog("mailing-send: ok for #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
|
dol_syslog("mailing-send: ok for #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
|
||||||
|
|
||||||
$sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
|
$sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
|
||||||
$sql.=" SET statut=1, date_envoi=SYSDATE() WHERE rowid=".$obj->rowid;
|
$sql.=" SET statut=1, date_envoi=SYSDATE() WHERE rowid=".$obj->rowid;
|
||||||
$resql2=$db->query($sql);
|
$resql2=$db->query($sql);
|
||||||
if (! $resql2)
|
if (! $resql2)
|
||||||
{
|
{
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Mail failed
|
// Mail failed
|
||||||
$nbko++;
|
$nbko++;
|
||||||
|
|
||||||
dol_syslog("mailing-send: error for #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
|
dol_syslog("mailing-send: error for #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
|
||||||
|
|
||||||
$sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
|
$sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
|
||||||
$sql.=" SET statut=-1, date_envoi=SYSDATE() WHERE rowid=".$obj->rowid;
|
$sql.=" SET statut=-1, date_envoi=SYSDATE() WHERE rowid=".$obj->rowid;
|
||||||
$resql2=$db->query($sql);
|
$resql2=$db->query($sql);
|
||||||
if (! $resql2)
|
if (! $resql2)
|
||||||
{
|
{
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop finished, set global statut of mail
|
// Loop finished, set global statut of mail
|
||||||
$statut=2;
|
$statut=2;
|
||||||
if (! $nbko) $statut=3;
|
if (! $nbko) $statut=3;
|
||||||
|
|
||||||
$sql="UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$id;
|
$sql="UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$id;
|
||||||
dol_syslog("mailing-send: update global status sql=".$sql, LOG_DEBUG);
|
dol_syslog("mailing-send: update global status sql=".$sql, LOG_DEBUG);
|
||||||
$resql2=$db->query($sql);
|
$resql2=$db->query($sql);
|
||||||
if (! $resql2)
|
if (! $resql2)
|
||||||
{
|
{
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dol_syslog($db->error());
|
dol_syslog($db->error());
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user