diff --git a/htdocs/comm/mailing/cibles.php b/htdocs/comm/mailing/cibles.php index 03d3295fe23..283a86fa9fc 100644 --- a/htdocs/comm/mailing/cibles.php +++ b/htdocs/comm/mailing/cibles.php @@ -30,92 +30,165 @@ require("./pre.inc.php"); $langs->load("mails"); +$dir=DOL_DOCUMENT_ROOT."/includes/modules/mailings"; + $mesg = ''; -llxHeader("","",$langs->trans("MailCard")); - -if ($_POST["cancel"] == $langs->trans("Cancel")) +/* + * Actions + */ +if ($_GET["action"] == 'add') { - $action = ''; + $modulename=$_GET["module"]; + + // Chargement de la classe + $file = $dir."/".$modulename.".modules.php"; + $classname = "mailing_".$modulename; + require_once($file); + + $obj = new $classname($db); + $obj->add_to_target($_GET["rowid"]); + + Header("Location: cibles.php?id=".$_GET["rowid"]); } + /* - * Fiche mailing en mode création - * + * Liste des destinataires */ -$mil = new Mailing($db); +llxHeader("","",$langs->trans("MailCard")); +$mil = new Mailing($db); $html = new Form($db); if ($mil->fetch($_GET["id"]) == 0) { - - $h=0; - $head[$h][0] = DOL_URL_ROOT."/comm/mailing/fiche.php?id=".$mil->id; - $head[$h][1] = $langs->trans("MailCard"); - $h++; - - $head[$h][0] = DOL_URL_ROOT."/comm/mailing/cibles.php?id=".$mil->id; - $head[$h][1] = $langs->trans("MailTargets"); - $hselected = $h; - $h++; - - dolibarr_fiche_head($head, $hselected, substr($mil->titre,0,20)); - - - print ''; - - print ''; - print '
'.$langs->trans("MailTitle").''.$mil->titre.'
'; - - /* - * - * - * - */ - $sql = "SELECT mc.nom, mc.prenom, mc.email"; - $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc"; - $sql .= " WHERE mc.fk_mailing=".$mil->id; - - if ( $db->query($sql) ) + + $h=0; + $head[$h][0] = DOL_URL_ROOT."/comm/mailing/fiche.php?id=".$mil->id; + $head[$h][1] = $langs->trans("MailCard"); + $h++; + + $head[$h][0] = DOL_URL_ROOT."/comm/mailing/cibles.php?id=".$mil->id; + $head[$h][1] = $langs->trans("MailRecipients"); + $hselected = $h; + $h++; + + /* + $head[$h][0] = DOL_URL_ROOT."/comm/mailing/history.php?id=".$mil->id; + $head[$h][1] = $langs->trans("MailHistory"); + $h++; + */ + dolibarr_fiche_head($head, $hselected, $langs->trans("Mailing").": ".substr($mil->titre,0,20)); + + + print ''; + + print ''; + print ''; + print ''; + print '
'.$langs->trans("MailTitle").''.$mil->titre.'
'.$langs->trans("MailFrom").''.htmlentities($mil->email_from).'
'.$langs->trans("TotalNbOfDistinctRecipients").''.($mil->nbemail?$mil->nbemail:''.$langs->trans("NoTargetYet").'').'

'; + + // Ajout d'une liste de sélection + print ''; + print ''; + print ''; + //print ''; + print ''; + print ''; + print "\n"; + + clearstatcache(); + + $handle=opendir($dir); + + $var=True; + while (($file = readdir($handle))!==false) { - $num = $db->num_rows(); - - print '
'.$langs->trans("RecipientSelectionModules").''.$langs->trans("Name").''.$langs->trans("NbOfRecipients").' 
'; - print ''; - $var = true; - $i = 0; - - while ($i < $num ) - { - $obj = $db->fetch_object(); - $var=!$var; - - print ""; - print ''; - print ''; - print ''; - - $i++; - } - - print "
'.$langs->trans("MailTargets").'
'.stripslashes($obj->prenom).''.stripslashes($obj->nom).''.$obj->email.'

"; - - $db->free(); - } - else + if (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') + { + $var = !$var; + if (eregi("(.*)\.(.*)\.(.*)",$file,$reg)) { + $modulename=$reg[1]; + + // Chargement de la classe + $file = $dir."/".$modulename.".modules.php"; + $classname = "mailing_".$modulename; + require_once($file); + + print ''; + + print ''; + $obj = new $classname($db); + print $obj->getDesc(); + print ''; + + /* + print ''; + print $modulename; + print ""; + */ + print ''.$obj->getNbOfRecipients().''; + print ''.img_edit_add($langs->trans("AddRecipients")).''; + } + print "\n"; + } + } + closedir($handle); + + print '
'; + + + print ""; + + $NBMAX=100; + + $sql = "SELECT mc.nom, mc.prenom, mc.email"; + $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc"; + $sql .= " WHERE mc.fk_mailing=".$mil->id; + $sql .= " limit ".($NBMAX+1); + + if ( $db->query($sql) ) { - dolibarr_print_error($db); + $num = $db->num_rows(); + + print_titre($langs->trans("MailSelectedRecipients")); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $var = true; + $i = 0; + + while ($i < $num ) + { + $obj = $db->fetch_object(); + $var=!$var; + + print ""; + print ''; + print ''; + print ''; + + $i++; + } + + print "
'.$langs->trans("Firstname").''.$langs->trans("Lastname").''.$langs->trans("EMail").'
'.stripslashes($obj->prenom).''.stripslashes($obj->nom).''.$obj->email.'

"; + + $db->free(); + } + else + { + dolibarr_print_error($db); } } - - - $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); diff --git a/htdocs/comm/mailing/fiche.php b/htdocs/comm/mailing/fiche.php index 32ff9388016..fab545d9d28 100644 --- a/htdocs/comm/mailing/fiche.php +++ b/htdocs/comm/mailing/fiche.php @@ -33,33 +33,41 @@ $langs->load("mails"); $mesg = ''; +llxHeader("","","Fiche Mailing"); + + + if ($_POST["action"] == 'add') { $mil = new Mailing($db); + $mil->from = $_POST["from"]; $mil->titre = $_POST["titre"]; $mil->sujet = $_POST["sujet"]; $mil->body = $_POST["body"]; - - if ( $mil->create($user) == 0) + if ($mil->create($user)) { Header("Location: fiche.php?id=".$mil->id); } + else + { + $message='
'.$mil->error.'
'; + $_GET["action"]="create"; + } } - if ($_POST["action"] == 'update') { $mil = new Mailing($db); - $mil->id = $_GET["id"]; + $mil->id = $_POST["id"]; + $mil->from = $_POST["from"]; $mil->titre = $_POST["titre"]; $mil->sujet = $_POST["sujet"]; $mil->body = $_POST["body"]; - - if ( $mil->update() == 0) + if ($mil->update()) { Header("Location: fiche.php?id=".$mil->id); } @@ -114,19 +122,29 @@ if ($_POST["action"] == 'confirm_approve') } } - - - - -llxHeader("","","Fiche Mailing"); +if ($_POST["action"] == 'confirm_delete') +{ + if ($_POST["confirm"] == 'yes') + { + $mil = new Mailing($db); + $mil->id = $_GET["id"]; + + if ($mil->delete($mil->id)) + { + Header("Location: index.php"); + } + } +} if ($_POST["cancel"] == $langs->trans("Cancel")) { $action = ''; } + + /* - * Création + * Mailing en mode création * */ @@ -134,149 +152,205 @@ $mil = new Mailing($db); if ($_GET["action"] == 'create') { - print '
'."\n"; - print ''; + print ''."\n"; + print ''; - print_titre($langs->trans("NewMailing")); - - print ''; + print_titre($langs->trans("NewMailing")); - print ''; + if ($message) print "$message
"; - print ''; + print '
'.$langs->trans("MailTitle").'
'.$langs->trans("MailTopic").'
'; - print ''; + print ''; - print ''; - print '
'.$langs->trans("MailMessage").'
'.$langs->trans("MailFrom").'
'; - print '
'; + print ''.$langs->trans("MailTitle").''; + + print ''.$langs->trans("MailTopic").''; + + print ''.$langs->trans("MailMessage").''; + + print ''; + print ''; + print ''; } else { - $html = new Form($db); - if ($mil->fetch($_GET["id"]) == 0) + $html = new Form($db); + if ($mil->fetch($_GET["id"]) == 0) { - $h=0; - $head[$h][0] = DOL_URL_ROOT."/comm/mailing/fiche.php?id=".$mil->id; - $head[$h][1] = $langs->trans("MailCard"); - $hselected = $h; - $h++; - - $head[$h][0] = DOL_URL_ROOT."/comm/mailing/cibles.php?id=".$mil->id; - $head[$h][1] = $langs->trans('MailTargets'); - $h++; - - dolibarr_fiche_head($head, $hselected, substr($mil->titre,0,20)); - - - /* - * Confirmation de la validation du mailing - * - */ - if ($_GET["action"] == 'valide') - { - $html->form_confirm("fiche.php?id=".$mil->id, - "Valider le mailing", - "Confirmez-vous la validation du mailing ?", - "confirm_valide"); - } - - /* - * Confirmation de l'approbation du mailing - * - */ - if ($_GET["action"] == 'approve') - { - $html->form_confirm("fiche.php?id=".$mil->id, - "Approuver le mailing", - "Confirmez-vous l'approbation du mailing ?", - "confirm_approve"); - } - - print ''; - - print ''; - - print ''; - print ''; - - //print ''; - //print ''; + $h=0; + $head[$h][0] = DOL_URL_ROOT."/comm/mailing/fiche.php?id=".$mil->id; + $head[$h][1] = $langs->trans("MailCard"); + $hselected = $h; + $h++; - if ($mil->statut > 0) - { - print ''; - } + $head[$h][0] = DOL_URL_ROOT."/comm/mailing/cibles.php?id=".$mil->id; + $head[$h][1] = $langs->trans('MailRecipients'); + $h++; - print ''; +/* + $head[$h][0] = DOL_URL_ROOT."/comm/mailing/history.php?id=".$mil->id; + $head[$h][1] = $langs->trans("MailHistory"); + $h++; +*/ + dolibarr_fiche_head($head, $hselected, $langs->trans("Mailing").": ".substr($mil->titre,0,20)); - $uc = new User($db, $mil->user_creat); - $uc->fetch(); - print ''; - print ''; - print ''; + // Confirmation de la validation du mailing + if ($_GET["action"] == 'valide') + { + $html->form_confirm("fiche.php?id=".$mil->id,$langs->trans("ValidMailing"),$langs->trans("ConfirmValidMailing"),"confirm_valide"); + } - if ($mil->statut > 0) - { - $uv = new User($db, $mil->user_valid); - $uv->fetch(); - print ''; - print ''; - print ''; - } + // Confirmation de l'approbation du mailing + if ($_GET["action"] == 'approve') + { + $html->form_confirm("fiche.php?id=".$mil->id,"Approuver le mailing","Confirmez-vous l'approbation du mailing ?","confirm_approve"); + } - if ($mil->statut > 1) - { - $ua = new User($db, $mil->user_appro); - $ua->fetch(); - print ''; - print ''; - print ''; - } - - // Contenu du mail - print ''; - - print ''; + // Confirmation de la suppression + if ($_GET["action"] == 'delete') + { + $html->form_confirm("fiche.php?id=".$mil->id,$langs->trans("DeleteAMailing"),$langs->trans("ConfirmDeleteMailing"),"confirm_delete"); + } - print '
'.$langs->trans("MailTitle").''.$mil->titre.'
'.$langs->trans("MailFrom").''.htmlentities($mil->email_from).''.$langs->trans("EMail").''.htmlentities($mil->email_from).'
Réponse'.htmlentities($mil->email_replyto).'
Retour Erreur'.htmlentities($mil->email_errorsto).'
Nb destinataires'.$mil->nbemail.'
'.$langs->trans("Status").''.$mil->statuts[$mil->statut].'
'.$langs->trans("CreatedBy").''.$uc->fullname.''.$langs->trans("DateCreation").''.strftime("%d %b %Y %H:%M", $mil->date_creat).'
'.$langs->trans("ValidatedBy").''.$uv->fullname.''.$langs->trans("Date").''.strftime("%d %b %Y %H:%M", $mil->date_valid).'
'.$langs->trans("ApprovedBy").''.$ua->fullname.''.$langs->trans("Date").''.strftime("%d %b %Y %H:%M", $mil->date_appro).'
'.$langs->trans("MailTopic").''.$mil->sujet.'
'.$langs->trans("MailMessage").''; - print nl2br($mil->body).'

'; - - print ""; - - - /* - * Boutons d'action - */ - - print "\n\n
\n"; - - if ($_GET["action"] == '') - { - - print ''.$langs->trans("TestMailing").''; - - if ($mil->statut == 0) - { - print ''.$langs->trans("ValidMailing").''; - } - - if ($mil->statut == 1 && $mil->nbemail > 0) - { - print ''.$langs->trans("ApproveMailing").''; - } - + if ($_GET["action"] != 'edit') + { + /* + * Mailing en mode visu + * + */ - } - print '

'; + print ''; + + print ''; + print ''; + print ''; + print ''; + + $uc = new User($db, $mil->user_creat); + $uc->fetch(); + print ''; + print ''; + print ''; + + if ($mil->statut > 0) + { + $uv = new User($db, $mil->user_valid); + $uv->fetch(); + print ''; + print ''; + print ''; + } + + if ($mil->statut > 1) + { + $ua = new User($db, $mil->user_appro); + $ua->fetch(); + print ''; + print ''; + print ''; + } + + // Contenu du mail + print ''; + print ''; + + print '
'.$langs->trans("MailTitle").''.$mil->titre.'
'.$langs->trans("MailFrom").''.htmlentities($mil->email_from).'
'.$langs->trans("TotalNbOfDistinctRecipients").''.($mil->nbemail?$mil->nbemail:''.$langs->trans("NoTargetYet").'').'
'.$langs->trans("Status").''.$mil->statuts[$mil->statut].'
'.$langs->trans("CreatedBy").''.$uc->fullname.''.$langs->trans("DateCreation").''.strftime("%d %b %Y %H:%M", $mil->date_creat).'
'.$langs->trans("ValidatedBy").''.$uv->fullname.''.$langs->trans("Date").''.strftime("%d %b %Y %H:%M", $mil->date_valid).'
'.$langs->trans("ApprovedBy").''.$ua->fullname.''.$langs->trans("Date").''.strftime("%d %b %Y %H:%M", $mil->date_appro).'
'.$langs->trans("MailTopic").''.$mil->sujet.'
'.$langs->trans("MailMessage").''; + print nl2br($mil->body).'

'; + + print ""; + + + /* + * Boutons d'action + */ + if ($_GET["action"] == '') + { + print "\n\n
\n"; + + if ($mil->statut == 0) + { + print ''.$langs->trans("EditMailing").''; + } + + //print ''.$langs->trans("PreviewMailing").''; + + print ''.$langs->trans("TestMailing").''; + + if ($mil->statut == 0 && $mil->nbemail > 0) + { + print ''.$langs->trans("ValidMailing").''; + } + +/* if ($mil->statut == 1 && $mil->nbemail > 0) + { + print ''.$langs->trans("ApproveMailing").''; + } +*/ + if ($mil->statut <= 1) + { + print ''.$langs->trans("DeleteMailing").''; + } + + print '

'; + } + + + 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 '
'."\n"; + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + print ''; + + print ''; + print '
'.$langs->trans("MailTitle").'
'.$langs->trans("MailFrom").'
'.$langs->trans("MailTopic").'
'.$langs->trans("MailMessage").'

'; + 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++;