Skip to content
Snippets Groups Projects
Commit 9406e2f0 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

New: Gros avancements sur l'outil de mailing. Il est possible maintenant de...

New: Gros avancements sur l'outil de mailing. Il est possible maintenant de créer un mailing, le supprimer, editer, valider et de choisir les destinataires parmi des listes prédéfinis dans des modules.
Qual: Les modules poire et cerise de sélection de destinataire ont été revue pour respoecter la norme objet.
parent 93bf985b
No related branches found
No related tags found
No related merge requests found
......@@ -30,92 +30,165 @@ require("./pre.inc.php");
$langs->load("mails");
$mesg = '';
$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 cration
*
* 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 '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans("MailTitle").'</td><td>'.$mil->titre.'</td></tr>';
print '</table>';
/*
*
*
*
*/
$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 '<table class="border" width="100%">';
print '<tr><td width="25%">'.$langs->trans("MailTitle").'</td><td colspan="3">'.$mil->titre.'</td></tr>';
print '<tr><td width="25%">'.$langs->trans("MailFrom").'</td><td colspan="3">'.htmlentities($mil->email_from).'</td></tr>';
print '<tr><td width="25%">'.$langs->trans("TotalNbOfDistinctRecipients").'</td><td colspan="3">'.($mil->nbemail?$mil->nbemail:'<font class="error">'.$langs->trans("NoTargetYet").'</font>').'</td></tr>';
print '</table><br>';
// Ajout d'une liste de slection
print '<table class="noborder" width=\"100%\">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("RecipientSelectionModules").'</td>';
//print '<td>'.$langs->trans("Name").'</td>';
print '<td align="center">'.$langs->trans("NbOfRecipients").'</td>';
print '<td width="80">&nbsp;</td>';
print "</tr>\n";
clearstatcache();
$handle=opendir($dir);
$var=True;
while (($file = readdir($handle))!==false)
{
$num = $db->num_rows();
print '<br /><table class="noborder" width="100%">';
print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("MailTargets").'</td></tr>';
$var = true;
$i = 0;
while ($i < $num )
{
$obj = $db->fetch_object();
$var=!$var;
print "<tr $bc[$var]>";
print '<td>'.stripslashes($obj->prenom).'</a></td>';
print '<td>'.stripslashes($obj->nom).'</a></td>';
print '<td>'.$obj->email.'</td>';
$i++;
}
print "</table><br>";
$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 '<tr '.$bc[$var].'>';
print '<td>';
$obj = new $classname($db);
print $obj->getDesc();
print '</td>';
/*
print '<td width=\"100\">';
print $modulename;
print "</td>";
*/
print '<td align="center">'.$obj->getNbOfRecipients().'</td>';
print '<td><a href="cibles.php?action=add&amp;rowid='.$mil->id.'&amp;module='.$modulename.'">'.img_edit_add($langs->trans("AddRecipients")).'</a></td>';
}
print "</tr>\n";
}
}
closedir($handle);
print '</table><br>';
print "</div>";
$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 '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Firstname").'</td>';
print '<td>'.$langs->trans("Lastname").'</td>';
print '<td>'.$langs->trans("EMail").'</td>';
print '</tr>';
$var = true;
$i = 0;
while ($i < $num )
{
$obj = $db->fetch_object();
$var=!$var;
print "<tr $bc[$var]>";
print '<td>'.stripslashes($obj->prenom).'</a></td>';
print '<td>'.stripslashes($obj->nom).'</a></td>';
print '<td>'.$obj->email.'</td>';
$i++;
}
print "</table><br>";
$db->free();
}
else
{
dolibarr_print_error($db);
}
}
$db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>");
......
......@@ -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='<div class="error">'.$mil->error.'</div>';
$_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 = '';
}
/*
* Cration
* Mailing en mode cration
*
*/
......@@ -134,148 +152,204 @@ $mil = new Mailing($db);
if ($_GET["action"] == 'create')
{
print '<form action="fiche.php" method="post">'."\n";
print '<input type="hidden" name="action" value="add">';
print '<form action="fiche.php" method="post">'."\n";
print '<input type="hidden" name="action" value="add">';
print_titre($langs->trans("NewMailing"));
print_titre($langs->trans("NewMailing"));
print '<table class="border" width="100%">';
if ($message) print "$message<br>";
print '<tr><td width="20%">'.$langs->trans("MailTitle").'</td><td><input name="titre" size="30" value=""></td></tr>';
print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans("MailTopic").'</td><td><input name="sujet" size="40" value=""></td></tr>';
print '<tr><td width="20%">'.$langs->trans("MailFrom").'</td><td><input name="from" size="30" value="'.MAIN_MAIL_FROM.'"></td></tr>';
print '<tr><td width="20%" valign="top">'.$langs->trans("MailMessage").'</td><td><textarea cols="30" rows="8" name="body"></textarea></td></tr>';
print '<tr><td width="20%">'.$langs->trans("MailTitle").'</td><td><input name="titre" size="30" value=""></td></tr>';
print '<tr><td colspan="2" align="center"><input type="submit" value="'.$langs->trans("CreateMailing").'"></td></tr>';
print '</table>';
print '</form>';
print '<tr><td width="20%">'.$langs->trans("MailTopic").'</td><td><input name="sujet" size="40" value=""></td></tr>';
print '<tr><td width="20%" valign="top">'.$langs->trans("MailMessage").'</td><td><textarea cols="30" rows="8" name="body"></textarea></td></tr>';
print '<tr><td colspan="2" align="center"><input type="submit" value="'.$langs->trans("CreateMailing").'"></td></tr>';
print '</table>';
print '</form>';
}
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 '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans("MailTitle").'</td><td colspan="3">'.$mil->titre.'</td></tr>';
print '<tr><td width="20%">'.$langs->trans("MailFrom").'</td><td>'.htmlentities($mil->email_from).'</td>';
print '<td>'.$langs->trans("EMail").'</td><td>'.htmlentities($mil->email_from).'</td></tr>';
//print '<tr><td width="20%">Rponse</td><td>'.htmlentities($mil->email_replyto).'</td></tr>';
//print '<tr><td width="20%">Retour Erreur</td><td>'.htmlentities($mil->email_errorsto).'</td></tr>';
if ($mil->statut > 0)
{
print '<tr><td width="20%">Nb destinataires</td><td colspan="3">'.$mil->nbemail.'</td></tr>';
}
print '<tr><td width="20%">'.$langs->trans("Status").'</td><td colspan="3">'.$mil->statuts[$mil->statut].'</td></tr>';
$h=0;
$head[$h][0] = DOL_URL_ROOT."/comm/mailing/fiche.php?id=".$mil->id;
$head[$h][1] = $langs->trans("MailCard");
$hselected = $h;
$h++;
$uc = new User($db, $mil->user_creat);
$uc->fetch();
print '<tr><td width="20%">'.$langs->trans("CreatedBy").'</td><td>'.$uc->fullname.'</td>';
print '<td>'.$langs->trans("DateCreation").'</td>';
print '<td>'.strftime("%d %b %Y %H:%M", $mil->date_creat).'</td></tr>';
$head[$h][0] = DOL_URL_ROOT."/comm/mailing/cibles.php?id=".$mil->id;
$head[$h][1] = $langs->trans('MailRecipients');
$h++;
if ($mil->statut > 0)
{
$uv = new User($db, $mil->user_valid);
$uv->fetch();
print '<tr><td width="20%">'.$langs->trans("ValidatedBy").'</td><td>'.$uv->fullname.'</td>';
print '<td>'.$langs->trans("Date").'</td>';
print '<td>'.strftime("%d %b %Y %H:%M", $mil->date_valid).'</td></tr>';
}
if ($mil->statut > 1)
{
$ua = new User($db, $mil->user_appro);
$ua->fetch();
print '<tr><td width="20%">'.$langs->trans("ApprovedBy").'</td><td>'.$ua->fullname.'</td>';
print '<td>'.$langs->trans("Date").'</td>';
print '<td>'.strftime("%d %b %Y %H:%M", $mil->date_appro).'</td></tr>';
}
// Contenu du mail
print '<tr><td width="20%">'.$langs->trans("MailTopic").'</td><td colspan="3">'.$mil->sujet.'</td></tr>';
print '<tr><td width="20%" valign="top">'.$langs->trans("MailMessage").'</td><td colspan="3">';
print nl2br($mil->body).'</td></tr>';
print '</table><br>';
print "</div>";
/*
* Boutons d'action
*/
print "\n\n<div class=\"tabsAction\">\n";
if ($_GET["action"] == '')
{
print '<a class="tabAction" href="fiche.php?action=test&amp;id='.$mil->id.'">'.$langs->trans("TestMailing").'</a>';
if ($mil->statut == 0)
{
print '<a class="tabAction" href="fiche.php?action=valide&amp;id='.$mil->id.'">'.$langs->trans("ValidMailing").'</a>';
}
if ($mil->statut == 1 && $mil->nbemail > 0)
{
print '<a class="tabAction" href="fiche.php?action=approve&amp;id='.$mil->id.'">'.$langs->trans("ApproveMailing").'</a>';
}
}
print '<br /><br /></div>';
/*
$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));
// 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");
}
// 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");
}
// Confirmation de la suppression
if ($_GET["action"] == 'delete')
{
$html->form_confirm("fiche.php?id=".$mil->id,$langs->trans("DeleteAMailing"),$langs->trans("ConfirmDeleteMailing"),"confirm_delete");
}
if ($_GET["action"] != 'edit')
{
/*
* Mailing en mode visu
*
*/
print '<table class="border" width="100%">';
print '<tr><td width="25%">'.$langs->trans("MailTitle").'</td><td colspan="3">'.$mil->titre.'</td></tr>';
print '<tr><td width="25%">'.$langs->trans("MailFrom").'</td><td colspan="3">'.htmlentities($mil->email_from).'</td></tr>';
print '<tr><td width="25%">'.$langs->trans("TotalNbOfDistinctRecipients").'</td><td colspan="3">'.($mil->nbemail?$mil->nbemail:'<font class="error">'.$langs->trans("NoTargetYet").'</font>').'</td></tr>';
print '<tr><td width="25%">'.$langs->trans("Status").'</td><td colspan="3">'.$mil->statuts[$mil->statut].'</td></tr>';
$uc = new User($db, $mil->user_creat);
$uc->fetch();
print '<tr><td>'.$langs->trans("CreatedBy").'</td><td>'.$uc->fullname.'</td>';
print '<td>'.$langs->trans("DateCreation").'</td>';
print '<td>'.strftime("%d %b %Y %H:%M", $mil->date_creat).'</td></tr>';
if ($mil->statut > 0)
{
$uv = new User($db, $mil->user_valid);
$uv->fetch();
print '<tr><td>'.$langs->trans("ValidatedBy").'</td><td>'.$uv->fullname.'</td>';
print '<td>'.$langs->trans("Date").'</td>';
print '<td>'.strftime("%d %b %Y %H:%M", $mil->date_valid).'</td></tr>';
}
if ($mil->statut > 1)
{
$ua = new User($db, $mil->user_appro);
$ua->fetch();
print '<tr><td>'.$langs->trans("ApprovedBy").'</td><td>'.$ua->fullname.'</td>';
print '<td>'.$langs->trans("Date").'</td>';
print '<td>'.strftime("%d %b %Y %H:%M", $mil->date_appro).'</td></tr>';
}
// Contenu du mail
print '<tr><td>'.$langs->trans("MailTopic").'</td><td colspan="3">'.$mil->sujet.'</td></tr>';
print '<tr><td valign="top">'.$langs->trans("MailMessage").'</td><td colspan="3">';
print nl2br($mil->body).'</td></tr>';
print '</table><br>';
print "</div>";
/*
* Boutons d'action
*/
if ($_GET["action"] == '')
{
print "\n\n<div class=\"tabsAction\">\n";
if ($mil->statut == 0)
{
print '<a class="tabAction" href="fiche.php?action=edit&amp;id='.$mil->id.'">'.$langs->trans("EditMailing").'</a>';
}
//print '<a class="tabAction" href="fiche.php?action=test&amp;id='.$mil->id.'">'.$langs->trans("PreviewMailing").'</a>';
print '<a class="tabAction" href="fiche.php?action=test&amp;id='.$mil->id.'">'.$langs->trans("TestMailing").'</a>';
if ($mil->statut == 0 && $mil->nbemail > 0)
{
print '<a class="tabAction" href="fiche.php?action=valide&amp;id='.$mil->id.'">'.$langs->trans("ValidMailing").'</a>';
}
/* if ($mil->statut == 1 && $mil->nbemail > 0)
{
print '<a class="tabAction" href="fiche.php?action=approve&amp;id='.$mil->id.'">'.$langs->trans("ApproveMailing").'</a>';
}
*/
if ($mil->statut <= 1)
{
print '<a class="butDelete" href="fiche.php?action=delete&amp;id='.$mil->id.'">'.$langs->trans("DeleteMailing").'</a>';
}
print '<br /><br /></div>';
}
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 paramtres complmentaires 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 '<form action="fiche.php" method="post">'."\n";
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.$mil->id.'">';
print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans("MailTitle").'</td><td colspan="3"><input type="text" size=50 name="titre" value="'.$mil->titre.'"></td></tr>';
print '<tr><td width="20%">'.$langs->trans("MailFrom").'</td><td colspan="3"><input type="text" size=50 name="from" value="'.htmlentities($mil->email_from).'"></td></tr>';
print '<tr><td width="20%">'.$langs->trans("MailTopic").'</td><td colspan="3"><input type="text" size=50 name="sujet" value="'.$mil->sujet.'"></td></tr>';
print '<tr><td width="20%" valign="top">'.$langs->trans("MailMessage").'</td><td colspan="3"><textarea name="body" cols=50 rows=10>';
print nl2br($mil->body).'</textarea></td></tr>';
print '<tr><td colspan="4" align="center"><input type="submit" value="'.$langs->trans("Save").'"></td></tr>';
print '</table><br>';
print '</form>';
print "</div>";
}
}
}
}
$db->close();
......
......@@ -33,7 +33,8 @@
class Mailing
{
var $id;
var $error;
/**
* \brief Constructeur de la classe
* \param DB handler accs base de donnes
......@@ -55,49 +56,83 @@ class Mailing
/**
* \brief Cration du mailing
* \param user object utilisateur qui cre
* \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 succs
*/
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;
}
}
......
......@@ -134,7 +134,7 @@ class FormMail
if ($this->withtoreadonly) {
print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:"";
} else {
print "<input size=\"30\" name=\"sendto\" value=\"".(! is_array($this->withto)?$this->withto:"")."\">";
print "<input size=\"30\" name=\"sendto\" value=\"".(! is_array($this->withto) && ! is_numeric($this->withto)?$this->withto:"")."\">";
if (is_array($this->withto))
{
print " ".$langs->trans("or")." ";
......
......@@ -35,103 +35,129 @@
*
*/
/*!
\file
\ingroup mailing
\brief
\version $Revision$
/** \file htdocs/includes/modules/mailings/poire.modules.php
\ingroup mailing
\brief Fichier de la classe permettant de gnrer la liste de destinataires Cerise
\version $Revision$
*/
class mailing_poire
include_once DOL_DOCUMENT_ROOT.'/includes/modules/mailings/modules_mailings.php';
/** \class mailing_cerise
\brief Classe permettant de gnrer la liste des destinataires Cerise
*/
class mailing_cerise extends MailingTargets
{
function mailing_poire()
{
$this->desc = 'Tous les contacts assaocis 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 trouves");
$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 ajoutes");
$sql = "UPDATE ".MAIN_DB_PREFIX."mailing";
$sql .= " SET nbemail = ".$i." WHERE rowid = ".$mailing_id;
if (!$db->query($sql))
{
dolibarr_syslog($db->error());
}
var $name="ContactProspects";
var $desc='Tous les contacts associs aux prospects';
var $require_module=array("prospet");
return 0;
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 trouves");
$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 ajoutes");
$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;
}
}
?>
<?php
/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
*
* 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 mre des classes de liste de destinataires mailing
\version $Revision$
*/
/** \class MailingTargets
\brief Classe mre des classes de liste de destinataires mailing
*/
class MailingTargets
{
var $error='';
/** \brief Renvoi un exemple de numrotation
* \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 numrotation
* \return string Example
*/
function getNbOfRecords()
{
return 0;
}
}
?>
......@@ -35,103 +35,131 @@
*
*/
/*!
\file
\ingroup mailing
\brief
\version $Revision$
/** \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$
*/
class mailing_cerise
{
function mailing_cerise()
{
$this->desc = 'Tous les contacts assaocis 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 trouves");
$olde = '';
while ($i < $num)
{
$row = $db->fetch_row();
if ($olde <> $row[0])
{
$cibles[$j] = $row;
$olde = $row[0];
$j++;
}
include_once DOL_DOCUMENT_ROOT.'/includes/modules/mailings/modules_mailings.php';
$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);
/** \class mailing_poire
\brief Classe permettant de générer la liste des destinataires Poire
*/
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());
}
}
class mailing_poire extends MailingTargets
{
var $name='ContactCustomers';
var $desc='Tous les contacts associés aux clients';
var $require_module=array("customer");
var $db;
dolibarr_syslog("mailing-prepare: mailing $i cibles ajoutes");
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";
$sql = "UPDATE ".MAIN_DB_PREFIX."mailing";
$sql .= " SET nbemail = ".$i." WHERE rowid = ".$mailing_id;
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 = '';
if (!$db->query($sql))
{
dolibarr_syslog($db->error());
}
while ($i < $num)
{
$row = $this->db->fetch_row();
return 0;
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;
}
}
?>
......@@ -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
......@@ -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=Prvisualiser mailing
PrepareMailing=Preparer mailing
CreateMailing=Crer 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 succs (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 dfinis
AddRecipients=Ajout de destinataires
MailingModuleDescContactProspects=Tous les contacts de toutes les socits propsects
MailingModuleDescContactCustomers=Tous les contacts de toutes les socits clientes
RecipientSelectionModules=Modules actifs de slection de destinataires
MailSelectedRecipients=Destinataires slectionns
......@@ -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++;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment