';
+ }
+
+
+ if ($_GET["action"] == 'test')
+ {
+ print_titre($langs->trans("TestMailing"));
+
+ // 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=$user->email;
+ $formmail->withcc=0;
+ $formmail->withtopic=0;
+ $formmail->withfile=0;
+ $formmail->withbody=1;
+ // Tableau des substitutions
+ $formmail->substit["__FACREF__"]=$fac->ref;
+ // Tableau des paramètres complémentaires du post
+ $formmail->param["action"]="send";
+ $formmail->param["models"]=$mil->body;
+ $formmail->param["mailid"]=$mil->id;
+ $formmail->param["returnurl"]=DOL_URL_ROOT."/comm/mailing.php?id=$mil->id";
+
+ $formmail->show_form();
+ }
+
+ }
+ else
+ {
+ /*
+ * Mailing en mode edition
+ */
+ print '';
+
+ print "";
+ }
}
-
+
}
-
-
$db->close();
llxFooter("Dernière modification $Date$ révision $Revision$");
diff --git a/htdocs/comm/mailing/mailing.class.php b/htdocs/comm/mailing/mailing.class.php
index ba4bbc34bc1..c481a33480d 100644
--- a/htdocs/comm/mailing/mailing.class.php
+++ b/htdocs/comm/mailing/mailing.class.php
@@ -33,7 +33,8 @@
class Mailing
{
var $id;
-
+ var $error;
+
/**
* \brief Constructeur de la classe
* \param DB handler accès base de données
@@ -55,49 +56,83 @@ class Mailing
/**
* \brief Création du mailing
* \param user object utilisateur qui crée
+ * \return -1 si erreur, >0 sinon
*
*/
function create($user)
{
+ global $langs;
+
dolibarr_syslog("Mailing::Create");
+
+ $this->db->begin();
+
+ $this->from=trim($this->from);
+ $this->titre=trim($this->titre);
+
+ if (! $this->from)
+ {
+ $this->error = $langs->trans("ErrorMailFromRequired");
+ return -1;
+ }
+
$sql = "INSERT INTO ".$this->db_table;
$sql .= " (date_creat, fk_user_creat)";
$sql .= " VALUES (now(), ".$user->id.")";
- if (strlen(trim($this->titre)) == 0)
+ if (! $this->titre)
{
- $this->titre = "Sans titre";
+ $this->titre = $langs->trans("NoTitle");
}
- if ( $this->db->query($sql) )
+ $result=$this->db->query($sql);
+ if ($result)
{
- $this->id = $this->db->last_insert_id();
-
- return $this->update();
+ $this->id = $this->db->last_insert_id($result);
+
+ if ($this->update() > 0)
+ {
+ $this->db->commit();
+ }
+ else
+ {
+ $this->db->rollback();
+ $this->error=$langs->trans("ErrorUnknown");
+ return -1;
+ }
+
+ return $this->id;
}
else
{
+ $this->db->rollback();
+
dolibarr_syslog("Mailing::Create Erreur -1");
+ $this->error=$langs->trans("UnknownError");
return -1;
}
+
}
/**
- * \brief Update les infos du mailing
+ * \brief Update les infos du mailing
+ * \return < 0 si erreur, > 0 si ok
*/
function update()
{
dolibarr_syslog("Mailing::Update");
$sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
- $sql .= " SET titre = '".$this->titre."'";
- $sql .= " , sujet = '".$this->sujet."'";
- $sql .= " , body = '".$this->body."'";
+ $sql .= " SET titre = '".addslashes($this->titre)."'";
+ $sql .= " , sujet = '".addslashes($this->sujet)."'";
+ $sql .= " , body = '".addslashes($this->body)."'";
+ $sql .= " , email_from = '".$this->from."'";
$sql .= " WHERE rowid = ".$this->id;
- if ($this->db->query($sql) )
+ $result=$this->db->query($sql);
+ if ($result)
{
- return 0;
+ return 1;
}
else
{
@@ -211,15 +246,17 @@ class Mailing
/**
- * \brief Supprime le mailing
- * \param rowid id du mailing à supprimer
+ * \brief Supprime le mailing
+ * \param rowid id du mailing à supprimer
+ * \return int 1 en cas de succès
*/
function delete($rowid)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing";
- $sql .= " WHERE fk_facture = ".$rowid;
+ $sql .= " WHERE rowid = ".$rowid;
$this->db->query($sql);
+ return 1;
}
}
diff --git a/htdocs/comm/mailing/modules/cerise.modules.php b/htdocs/comm/mailing/modules/cerise.modules.php
deleted file mode 100644
index 2f90bb0f69d..00000000000
--- a/htdocs/comm/mailing/modules/cerise.modules.php
+++ /dev/null
@@ -1,137 +0,0 @@
-
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * 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.
- * or see http://www.gnu.org/
- *
- * $Id$
- * $Source$
- *
- *
- * 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
- \ingroup mailing
- \brief
- \version $Revision$
-*/
-
-class mailing_cerise
-{
- function mailing_cerise()
- {
- $this->desc = 'Tous les contacts assaociés aux prospects';
- }
-
-
- function prepare_cible($db, $mailing_id)
- {
- $cibles = array();
-
- $sql = "SELECT distinct(c.email), c.idp, c.name, c.firstname, s.nom ";
- $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
- $sql .= ", ".MAIN_DB_PREFIX."societe as s";
- $sql .= " WHERE s.idp = c.fk_soc";
- $sql .= " AND s.client = 2";
- $sql .= " AND c.email IS NOT NULL";
- $sql .= " ORDER BY c.email ASC";
-
- if ( $db->query($sql) )
- {
- $num = $db->num_rows();
- $i = 0;
- $j = 0;
-
- dolibarr_syslog("mailing-prepare: mailing $num cibles trouvées");
-
- $olde = '';
-
- while ($i < $num)
- {
- $row = $db->fetch_row();
-
- if ($olde <> $row[0])
- {
- $cibles[$j] = $row;
- $olde = $row[0];
- $j++;
- }
-
- $i++;
- }
- }
- else
- {
- dolibarr_syslog($db->error());
- }
-
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles";
- $sql .= " WHERE fk_mailing = ".$mailing_id;
-
- if (!$db->query($sql))
- {
- dolibarr_syslog($db->error());
- }
-
- $num = sizeof($cibles);
-
- for ($i = 0 ; $i < $num ; $i++)
- {
-
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_cibles";
- $sql .= " (fk_mailing, fk_contact, nom, prenom, email)";
- $sql .= " VALUES (".$mailing_id.",";
- $sql .= $cibles[$i][1] .",";
- $sql .= "'".$cibles[$i][2] ."',";
- $sql .= "'".$cibles[$i][3] ."',";
- $sql .= "'".$cibles[$i][0] ."')";
-
- if (!$db->query($sql))
- {
- dolibarr_syslog($db->error());
- }
- }
-
- dolibarr_syslog("mailing-prepare: mailing $i cibles ajoutées");
-
- $sql = "UPDATE ".MAIN_DB_PREFIX."mailing";
- $sql .= " SET nbemail = ".$i." WHERE rowid = ".$mailing_id;
-
- if (!$db->query($sql))
- {
- dolibarr_syslog($db->error());
- }
-
- return 0;
-
- }
-
-}
-
-?>
diff --git a/htdocs/comm/mailing/modules/poire.modules.php b/htdocs/comm/mailing/modules/poire.modules.php
deleted file mode 100644
index 910b2aa83ca..00000000000
--- a/htdocs/comm/mailing/modules/poire.modules.php
+++ /dev/null
@@ -1,137 +0,0 @@
-
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * 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.
- * or see http://www.gnu.org/
- *
- * $Id$
- * $Source$
- *
- *
- * 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
- \ingroup mailing
- \brief
- \version $Revision$
-*/
-
-class mailing_poire
-{
- function mailing_poire()
- {
- $this->desc = 'Tous les contacts assaociés aux clients';
- }
-
-
- function prepare_cible($db, $mailing_id)
- {
- $cibles = array();
-
- $sql = "SELECT distinct(c.email), c.idp, c.name, c.firstname, s.nom ";
- $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
- $sql .= ", ".MAIN_DB_PREFIX."societe as s";
- $sql .= " WHERE s.idp = c.fk_soc";
- $sql .= " AND s.client = 1";
- $sql .= " AND c.email IS NOT NULL";
- $sql .= " ORDER BY c.email ASC";
-
- if ( $db->query($sql) )
- {
- $num = $db->num_rows();
- $i = 0;
- $j = 0;
-
- dolibarr_syslog("mailing-prepare: mailing $num cibles trouvées");
-
- $olde = '';
-
- while ($i < $num)
- {
- $row = $db->fetch_row();
-
- if ($olde <> $row[0])
- {
- $cibles[$j] = $row;
- $olde = $row[0];
- $j++;
- }
-
- $i++;
- }
- }
- else
- {
- dolibarr_syslog($db->error());
- }
-
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles";
- $sql .= " WHERE fk_mailing = ".$mailing_id;
-
- if (!$db->query($sql))
- {
- dolibarr_syslog($db->error());
- }
-
- $num = sizeof($cibles);
-
- for ($i = 0 ; $i < $num ; $i++)
- {
-
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_cibles";
- $sql .= " (fk_mailing, fk_contact, nom, prenom, email)";
- $sql .= " VALUES (".$mailing_id.",";
- $sql .= $cibles[$i][1] .",";
- $sql .= "'".$cibles[$i][2] ."',";
- $sql .= "'".$cibles[$i][3] ."',";
- $sql .= "'".$cibles[$i][0] ."')";
-
- if (!$db->query($sql))
- {
- dolibarr_syslog($db->error());
- }
- }
-
- dolibarr_syslog("mailing-prepare: mailing $i cibles ajoutées");
-
- $sql = "UPDATE ".MAIN_DB_PREFIX."mailing";
- $sql .= " SET nbemail = ".$i." WHERE rowid = ".$mailing_id;
-
- if (!$db->query($sql))
- {
- dolibarr_syslog($db->error());
- }
-
- return 0;
-
- }
-
-}
-
-?>
diff --git a/htdocs/html.formmail.class.php b/htdocs/html.formmail.class.php
index cb5b51992ab..4c8040251bb 100644
--- a/htdocs/html.formmail.class.php
+++ b/htdocs/html.formmail.class.php
@@ -134,7 +134,7 @@ class FormMail
if ($this->withtoreadonly) {
print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:"";
} else {
- print "withto)?$this->withto:"")."\">";
+ print "withto) && ! is_numeric($this->withto)?$this->withto:"")."\">";
if (is_array($this->withto))
{
print " ".$langs->trans("or")." ";
diff --git a/htdocs/includes/modules/mailings/cerise.modules.php b/htdocs/includes/modules/mailings/cerise.modules.php
new file mode 100644
index 00000000000..56b0e7f8aeb
--- /dev/null
+++ b/htdocs/includes/modules/mailings/cerise.modules.php
@@ -0,0 +1,163 @@
+
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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.
+ * or see http://www.gnu.org/
+ *
+ * $Id$
+ * $Source$
+ *
+ *
+ * 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 htdocs/includes/modules/mailings/poire.modules.php
+ \ingroup mailing
+ \brief Fichier de la classe permettant de générer la liste de destinataires Cerise
+ \version $Revision$
+*/
+
+include_once DOL_DOCUMENT_ROOT.'/includes/modules/mailings/modules_mailings.php';
+
+
+/** \class mailing_cerise
+ \brief Classe permettant de générer la liste des destinataires Cerise
+*/
+
+class mailing_cerise extends MailingTargets
+{
+ var $name="ContactProspects";
+ var $desc='Tous les contacts associés aux prospects';
+ var $require_module=array("prospet");
+
+ function mailing_cerise($DB)
+ {
+ $this->db=$DB;
+ }
+
+ function getNbOfRecipients()
+ {
+ $sql = "SELECT count(distinct(c.email)) nb";
+ $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
+ $sql .= ", ".MAIN_DB_PREFIX."societe as s";
+ $sql .= " WHERE s.idp = c.fk_soc";
+ $sql .= " AND s.client = 2";
+ $sql .= " AND c.email IS NOT NULL";
+
+ if ( $this->db->query($sql) )
+ {
+ $obj = $this->db->fetch_object();
+ return $obj->nb;
+ }
+ return 0;
+ }
+
+ function add_to_target($mailing_id)
+ {
+ $cibles = array();
+
+ $sql = "SELECT distinct(c.email), c.idp, c.name, c.firstname, s.nom ";
+ $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
+ $sql .= ", ".MAIN_DB_PREFIX."societe as s";
+ $sql .= " WHERE s.idp = c.fk_soc";
+ $sql .= " AND s.client = 2";
+ $sql .= " AND c.email IS NOT NULL";
+ $sql .= " ORDER BY c.email ASC";
+
+ if ( $this->db->query($sql) )
+ {
+ $num = $this->db->num_rows();
+ $i = 0;
+ $j = 0;
+
+ dolibarr_syslog("mailing-prepare: mailing $num cibles trouvées");
+
+ $olde = '';
+
+ while ($i < $num)
+ {
+ $row = $this->db->fetch_row();
+
+ if ($olde <> $row[0])
+ {
+ $cibles[$j] = $row;
+ $olde = $row[0];
+ $j++;
+ }
+
+ $i++;
+ }
+ }
+ else
+ {
+ dolibarr_syslog($this->db->error());
+ }
+
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles";
+ $sql .= " WHERE fk_mailing = ".$mailing_id;
+
+ if (!$this->db->query($sql))
+ {
+ dolibarr_syslog($this->db->error());
+ }
+
+ $num = sizeof($cibles);
+
+ for ($i = 0 ; $i < $num ; $i++)
+ {
+
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_cibles";
+ $sql .= " (fk_mailing, fk_contact, nom, prenom, email)";
+ $sql .= " VALUES (".$mailing_id.",";
+ $sql .= $cibles[$i][1] .",";
+ $sql .= "'".$cibles[$i][2] ."',";
+ $sql .= "'".$cibles[$i][3] ."',";
+ $sql .= "'".$cibles[$i][0] ."')";
+
+ if (!$this->db->query($sql))
+ {
+ dolibarr_syslog($this->db->error());
+ }
+ }
+
+ dolibarr_syslog("mailing-prepare: mailing $i cibles ajoutées");
+
+ $sql = "UPDATE ".MAIN_DB_PREFIX."mailing";
+ $sql .= " SET nbemail = ".$i." WHERE rowid = ".$mailing_id;
+
+ if (!$this->db->query($sql))
+ {
+ dolibarr_syslog($this->db->error());
+ }
+
+ return 0;
+
+ }
+
+}
+
+?>
diff --git a/htdocs/includes/modules/mailings/modules_mailings.php b/htdocs/includes/modules/mailings/modules_mailings.php
new file mode 100644
index 00000000000..e72e499f914
--- /dev/null
+++ b/htdocs/includes/modules/mailings/modules_mailings.php
@@ -0,0 +1,62 @@
+
+ * Copyright (C) 2004 Laurent Destailleur
+ * Copyright (C) 2004 Eric Seigne
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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.
+ * or see http://www.gnu.org/
+ *
+ * $Id$
+ * $Source$
+ *
+ */
+
+/** \file htdocs/includes/modules/mailings/modules_mailings.php
+ \ingroup mailing
+ \brief Fichier contenant la classe mère des classes de liste de destinataires mailing
+ \version $Revision$
+*/
+
+
+/** \class MailingTargets
+ \brief Classe mère des classes de liste de destinataires mailing
+*/
+
+class MailingTargets
+{
+ var $error='';
+
+ /** \brief Renvoi un exemple de numérotation
+ * \return string Retourne la traduction de la clé MailingModuleDescXXX ou XXX nom du module, ou $this->desc si non trouvé
+ */
+ function getDesc()
+ {
+ global $langs;
+ $langs->load("mails");
+ $transstring="MailingModuleDesc".$this->name;
+ if ($langs->trans($transstring) != $transstring) return $langs->trans($transstring);
+ else return $this->desc;
+ }
+
+ /** \brief Renvoi un exemple de numérotation
+ * \return string Example
+ */
+ function getNbOfRecords()
+ {
+ return 0;
+ }
+}
+
+?>
diff --git a/htdocs/includes/modules/mailings/poire.modules.php b/htdocs/includes/modules/mailings/poire.modules.php
new file mode 100644
index 00000000000..22bf2b0cb78
--- /dev/null
+++ b/htdocs/includes/modules/mailings/poire.modules.php
@@ -0,0 +1,165 @@
+
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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.
+ * or see http://www.gnu.org/
+ *
+ * $Id$
+ * $Source$
+ *
+ *
+ * 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 htdocs/includes/modules/mailings/poire.modules.php
+ \ingroup mailing
+ \brief Fichier de la classe permettant de générer la liste de destinataires Poire
+ \version $Revision$
+*/
+
+include_once DOL_DOCUMENT_ROOT.'/includes/modules/mailings/modules_mailings.php';
+
+
+/** \class mailing_poire
+ \brief Classe permettant de générer la liste des destinataires Poire
+*/
+
+class mailing_poire extends MailingTargets
+{
+ var $name='ContactCustomers';
+ var $desc='Tous les contacts associés aux clients';
+ var $require_module=array("customer");
+
+ var $db;
+
+ function mailing_poire($DB)
+ {
+ $this->db=$DB;
+ }
+
+ function getNbOfRecipients()
+ {
+ $sql = "SELECT count(distinct(c.email)) nb";
+ $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
+ $sql .= ", ".MAIN_DB_PREFIX."societe as s";
+ $sql .= " WHERE s.idp = c.fk_soc";
+ $sql .= " AND s.client = 1";
+ $sql .= " AND c.email IS NOT NULL";
+
+ if ( $this->db->query($sql) )
+ {
+ $obj = $this->db->fetch_object();
+ return $obj->nb;
+ }
+ return 0;
+ }
+
+ function add_to_target($mailing_id)
+ {
+ $cibles = array();
+
+ $sql = "SELECT distinct(c.email), c.idp, c.name, c.firstname, s.nom ";
+ $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
+ $sql .= ", ".MAIN_DB_PREFIX."societe as s";
+ $sql .= " WHERE s.idp = c.fk_soc";
+ $sql .= " AND s.client = 1";
+ $sql .= " AND c.email IS NOT NULL";
+ $sql .= " ORDER BY c.email ASC";
+
+ if ( $this->db->query($sql) )
+ {
+ $num = $this->db->num_rows();
+ $i = 0;
+ $j = 0;
+
+ dolibarr_syslog("mailing-prepare: mailing $num cibles trouvées");
+
+ $olde = '';
+
+ while ($i < $num)
+ {
+ $row = $this->db->fetch_row();
+
+ if ($olde <> $row[0])
+ {
+ $cibles[$j] = $row;
+ $olde = $row[0];
+ $j++;
+ }
+
+ $i++;
+ }
+ }
+ else
+ {
+ dolibarr_syslog($this->db->error());
+ }
+
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles";
+ $sql .= " WHERE fk_mailing = ".$mailing_id;
+
+ if (!$this->db->query($sql))
+ {
+ dolibarr_syslog($this->db->error());
+ }
+
+ $num = sizeof($cibles);
+
+ for ($i = 0 ; $i < $num ; $i++)
+ {
+
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_cibles";
+ $sql .= " (fk_mailing, fk_contact, nom, prenom, email)";
+ $sql .= " VALUES (".$mailing_id.",";
+ $sql .= $cibles[$i][1] .",";
+ $sql .= "'".$cibles[$i][2] ."',";
+ $sql .= "'".$cibles[$i][3] ."',";
+ $sql .= "'".$cibles[$i][0] ."')";
+
+ if (!$this->db->query($sql))
+ {
+ dolibarr_syslog($this->db->error());
+ }
+ }
+
+ dolibarr_syslog("mailing-prepare: mailing $i cibles ajoutées");
+
+ $sql = "UPDATE ".MAIN_DB_PREFIX."mailing";
+ $sql .= " SET nbemail = ".$i." WHERE rowid = ".$mailing_id;
+
+ if (!$this->db->query($sql))
+ {
+ dolibarr_syslog($this->db->error());
+ }
+
+ return 0;
+
+ }
+
+}
+
+?>
diff --git a/htdocs/langs/en_US/mails.lang b/htdocs/langs/en_US/mails.lang
index a4b82d3b731..8f633a2f09c 100644
--- a/htdocs/langs/en_US/mails.lang
+++ b/htdocs/langs/en_US/mails.lang
@@ -2,6 +2,7 @@
Mailing=Mailing
MailCard=Mailing card
MailTargets=Targets
+MailRecipients=Recipients
MailTitle=Title
MailTopic=Mail topic
MailFrom=Sender
@@ -13,6 +14,10 @@ MailText=Message
MailFile=Attach a file
MailMessage=Message
NewMailing=New mailing
+EditMailing=Edit mailing
+DeleteMailing=Delete mailing
+DeleteAMailing=Delete a mailing
+PreviewMailing=Preview mailing
PrepareMailing=Prepare mailing
CreateMailing=Create mailing
MailingDesc=This page allows you to send mailings to a group of people.
@@ -26,4 +31,14 @@ MailingStatusApproved=Approved
MailingStatusSent=Sent
MailSuccessfulySent=Mail successfuly sent (from %s to %s)
ErrorMailRecipientIsEmpty=Mail recipient is empty
+ConfirmValidMailing=Are you sure you want to validate this mailing ?
+ConfirmDeleteMailing=Are you sure you want to delete this mailling ?
+NbOfRecipients=Number of recipients
+TotalNbOfDistinctRecipients=Total number of distinct recipients
+NoTargetYet=No recipients defined yet
+AddRecipients=Add recipients
+MailingModuleDescContactProspects=All contacts for all prospect companies
+MailingModuleDescContactCustomers=All contacts for all customer companies
+RecipientSelectionModules=Active modules for recipients selection
+MailSelectedRecipients=Selected recipients
diff --git a/htdocs/langs/fr_FR/mails.lang b/htdocs/langs/fr_FR/mails.lang
index c39dacfc76f..ce40ab60fdf 100644
--- a/htdocs/langs/fr_FR/mails.lang
+++ b/htdocs/langs/fr_FR/mails.lang
@@ -2,6 +2,7 @@
Mailing=Mailing
MailCard=Fiche mailing
MailTargets=Destinataires
+MailRecipients=Destinataires
MailTitle=Titre
MailTopic=Sujet du mail
MailFrom=Emetteur
@@ -13,6 +14,10 @@ MailText=Message
MailFile=Joindre un fichier
MailMessage=Message
NewMailing=Nouveau mailing
+EditMailing=Editer mailing
+DeleteMailing=Supprimer mailing
+DeleteAMailing=Supprimer un mailing
+PreviewMailing=Prévisualiser mailing
PrepareMailing=Preparer mailing
CreateMailing=Créer mailing
MailingDesc=Cette page vous permet d'envoyer des mailings à un groupe de personnes.
@@ -26,3 +31,13 @@ MailingStatusApproved=Approv
MailingStatusSent=Envoyé
MailSuccessfulySent=Mail envoyé avec succès (de la part de %s pour %s)
ErrorMailRecipientIsEmpty=Le mail du destinataire est vide
+ConfirmValidMailing=Confirmez-vous la validation du mailing ?
+ConfirmDeleteMailing=Confirmez-vous la suppression du mailing ?
+NbOfRecipients=Nombre de destinataires
+TotalNbOfdistinctRecipients=Nombre total de destinataires uniques
+NoTargetYet=Pas de destinataire définis
+AddRecipients=Ajout de destinataires
+MailingModuleDescContactProspects=Tous les contacts de toutes les sociétés propsects
+MailingModuleDescContactCustomers=Tous les contacts de toutes les sociétés clientes
+RecipientSelectionModules=Modules actifs de sélection de destinataires
+MailSelectedRecipients=Destinataires sélectionnés
diff --git a/scripts/mailing-prepare.php b/scripts/mailing-prepare.php
index a520bec039f..3418f60f2b4 100644
--- a/scripts/mailing-prepare.php
+++ b/scripts/mailing-prepare.php
@@ -56,13 +56,12 @@ if ( $db->query($sql) )
dolibarr_syslog("mailing-prepare: mailing $row[0]");
dolibarr_syslog("mailing-prepare: mailing module $row[1]");
- require DOL_DOCUMENT_ROOT.'/comm/mailing/modules/'.$row[1].'.modules.php';
+ require DOL_DOCUMENT_ROOT.'/includes/modules/mailings/'.$row[1].'.modules.php';
$classname = "mailing_".$row[1];
- $obj = new $classname;
-
- $obj->prepare_cible($db, $row[0]);
+ $obj = new $classname($db);
+ $obj->add_to_target($row[0]);
$i++;