diff --git a/htdocs/comm/mailing/cibles.php b/htdocs/comm/mailing/cibles.php
index 8f94ef2c643..3c62685d277 100644
--- a/htdocs/comm/mailing/cibles.php
+++ b/htdocs/comm/mailing/cibles.php
@@ -134,7 +134,7 @@ llxHeader("","",$langs->trans("MailCard"));
$mil = new Mailing($db);
$html = new Form($db);
-if ($mil->fetch($_REQUEST["id"]) == 0)
+if ($mil->fetch($_REQUEST["id"]) >= 0)
{
$h=0;
@@ -148,7 +148,7 @@ if ($mil->fetch($_REQUEST["id"]) == 0)
$h++;
/*
- $head[$h][0] = DOL_URL_ROOT."/comm/mailing/history.php?id=".$mil->id;
+ $head[$h][0] = DOL_URL_ROOT."/comm/mailing/info.php?id=".$mil->id;
$head[$h][1] = $langs->trans("MailHistory");
$h++;
*/
@@ -309,7 +309,8 @@ if ($mil->fetch($_REQUEST["id"]) == 0)
print_liste_field_titre($langs->trans("Firstname"),$_SERVER["PHP_SELF"],"mc.prenom",$addu,"","",$sortfield);
print_liste_field_titre($langs->trans("EMail"),$_SERVER["PHP_SELF"],"mc.email",$addu,"","",$sortfield);
print '
| ';
- print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"mc.statut",$addu,'','align="center"',$sortfield);
+
+ // Date
if ($mil->statut == 0)
{
print ' | ';
@@ -318,6 +319,10 @@ if ($mil->fetch($_REQUEST["id"]) == 0)
{
print ''.$langs->trans("Date").' | ';
}
+
+ // Statut
+ print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"mc.statut",$addu,'','align="right"',$sortfield);
+
print '';
// Ligne des champs de filtres
@@ -353,19 +358,19 @@ if ($mil->fetch($_REQUEST["id"]) == 0)
print ''.$obj->email.' | ';
print ''.$obj->url.' | ';
- // Statut
+ // Statut pour l'email destinataire (Attentioon != statut du mailing)
if ($mil->statut == 0)
{
- print ''.$langs->trans("MailingStatusNotSent").' | ';
- print ''.img_delete($langs->trans("RemoveRecipient")).' | ';
+ print ' | ';
+ print ''.$langs->trans("MailingStatusNotSent").' '.img_delete($langs->trans("RemoveRecipient")).' | ';
}
else
{
- print '';
- if ($obj->statut==-1) print $langs->trans("MailingStatusError").' '.img_error();
- if ($obj->statut==1) print $langs->trans("MailingStatusSent");
- print ' | ';
print ''.$obj->date_envoi.' | ';
+ print '';
+ if ($obj->statut==-1) print $langs->trans("MailingStatusError").' '.img_error();
+ if ($obj->statut==1) print $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
+ print ' | ';
}
print '';
diff --git a/htdocs/comm/mailing/fiche.php b/htdocs/comm/mailing/fiche.php
index 5fe8980c7ec..04bf39f5bc2 100644
--- a/htdocs/comm/mailing/fiche.php
+++ b/htdocs/comm/mailing/fiche.php
@@ -54,33 +54,17 @@ if ($_GET["action"] == 'sendall')
if ($_POST["action"] == 'send')
{
$mil = new Mailing($db);
-
- $mil->id = $_POST["mailid"];
- $mil->fromname = $_POST["fromname"];
- $mil->frommail = $_POST["frommail"];
+ $result=$mil->fetch($_POST["mailid"]);
+
$mil->sendto = $_POST["sendto"];
- $mil->titre = $_POST["titre"];
- $mil->sujet = $_POST["subject"];
- $mil->body = $_POST["message"];
-
if (! $mil->sendto)
{
$message=''.$langs->trans("ErrorFieldRequired",$langs->trans("MailTo")).'
';
}
- if (! $mil->sujet)
- {
- $message=''.$langs->trans("ErrorFieldRequired",$langs->trans("MailTopic")).'
';
- }
- if (! $mil->body)
- {
- $message=''.$langs->trans("ErrorFieldRequired",$langs->trans("MailMessage")).'
';
- }
- if ($mil->sendto && $mil->sujet && $mil->body)
+ if ($mil->sendto)
{
require_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
- $sendto = $mil->sendto;
- $from = $mil->fromname." <".$mil->frommail.">";
$arr_file = array();
$arr_mime = array();
$arr_name = array();
@@ -90,15 +74,14 @@ if ($_POST["action"] == 'send')
if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_MAILING) $msgishtml=1;
if (eregi('[ \t]*',$message)) $msgishtml=1;
- $mailfile = new CMailFile($mil->sujet,$sendto,$from,$mil->body,
+ $mailfile = new CMailFile($mil->sujet,$mil->sendto,$mil->email_from,$mil->body,
$arr_file,$arr_mime,$arr_name,
'', '', 0, $msgishtml);
$result=$mailfile->sendfile();
-
if ($result)
{
- $message=''.$langs->trans("MailSuccessfulySent",$from,$sendto).'
';
+ $message=''.$langs->trans("MailSuccessfulySent",$mil->email_from,$mil->sendto).'
';
}
else
{
@@ -159,50 +142,53 @@ if ($_POST["action"] == 'update')
// Action confirmation validation
if ($_POST["action"] == 'confirm_valide')
{
-
- if ($_POST["confirm"] == 'yes')
- {
- $mil = new Mailing($db);
- if ($mil->fetch($_GET["id"]) == 0)
+ if ($_POST["confirm"] == 'yes')
{
- $mil->valid($user);
-
- Header("Location: fiche.php?id=".$mil->id);
+ $mil = new Mailing($db);
+
+ if ($mil->fetch($_GET["id"]) >= 0)
+ {
+ $mil->valid($user);
+
+ Header("Location: fiche.php?id=".$mil->id);
+ exit;
+ }
+ else
+ {
+ dolibarr_print_error($db);
+ }
}
- else
+ else
{
- dolibarr_print_error($db);
+ Header("Location: fiche.php?id=".$_GET["id"]);
+ exit;
}
- }
- else
- {
- Header("Location: fiche.php?id=".$_GET["id"]);
- }
}
if ($_POST["action"] == 'confirm_approve')
{
-
- if ($_POST["confirm"] == 'yes')
- {
- $mil = new Mailing($db);
-
- if ($mil->fetch($_GET["id"]) == 0)
+ if ($_POST["confirm"] == 'yes')
{
- $mil->approve($user);
-
- Header("Location: fiche.php?id=".$mil->id);
+ $mil = new Mailing($db);
+
+ if ($mil->fetch($_GET["id"]) >= 0)
+ {
+ $mil->approve($user);
+
+ Header("Location: fiche.php?id=".$mil->id);
+ exit;
+ }
+ else
+ {
+ dolibarr_print_error($db);
+ }
}
- else
+ else
{
- dolibarr_print_error($db);
+ Header("Location: fiche.php?id=".$_GET["id"]);
+ exit;
}
- }
- else
- {
- Header("Location: fiche.php?id=".$_GET["id"]);
- }
}
// Action confirmation suppression
@@ -279,7 +265,7 @@ else
{
$html = new Form($db);
- if ($mil->fetch($_GET["id"]) == 0)
+ if ($mil->fetch($_GET["id"]) >= 0)
{
$h=0;
@@ -293,7 +279,7 @@ else
$h++;
/*
- $head[$h][0] = DOL_URL_ROOT."/comm/mailing/history.php?id=".$mil->id;
+ $head[$h][0] = DOL_URL_ROOT."/comm/mailing/info.php?id=".$mil->id;
$head[$h][1] = $langs->trans("MailHistory");
$h++;
*/
@@ -338,32 +324,35 @@ else
$uc = new User($db, $mil->user_creat);
$uc->fetch();
- print '| '.$langs->trans("CreatedBy").' | '.$uc->fullname.' | ';
+ print '
| '.$langs->trans("CreatedBy").' | '.$uc->getNomUrl(1).' | ';
print ''.$langs->trans("Date").' | ';
- print ''.strftime("%d %b %Y %H:%M", $mil->date_creat).' |
';
+ print ''.dolibarr_print_date($mil->date_creat,"%d %b %Y %H:%M").' | ';
if ($mil->statut > 0)
{
$uv = new User($db, $mil->user_valid);
$uv->fetch();
- print '| '.$langs->trans("ValidatedBy").' | '.$uv->fullname.' | ';
+ print '
| '.$langs->trans("ValidatedBy").' | '.$uv->getNomUrl(1).' | ';
print ''.$langs->trans("Date").' | ';
- print ''.strftime("%d %b %Y %H:%M", $mil->date_valid).' |
';
+ print ''.dolibarr_print_date($mil->date_valid,"%d %b %Y %H:%M").' | ';
}
if ($mil->statut > 1)
{
print '| '.$langs->trans("SentBy").' | '.$langs->trans("Unknown").' | ';
print ''.$langs->trans("Date").' | ';
- print ''.strftime("%d %b %Y %H:%M", $mil->date_envoi).' |
';
+ print ''.dolibarr_print_date($mil->date_envoi,"%d %b %Y %H:%M").' | ';
}
- // Contenu du mail
+ // Sujet
print '| '.$langs->trans("MailTopic").' | '.$mil->sujet.' |
';
- print '| '.$langs->trans("MailMessage").' | ';
+ // Message
+ print '
| '.$langs->trans("MailMessage").' | ';
print '';
- print nl2br($mil->body).' |
';
+ print nl2br($mil->body);
+ print '';
+ print '';
print '';
@@ -415,13 +404,13 @@ else
$formmail = new FormMail($db);
$formmail->fromname = $mil->email_from;
$formmail->frommail = $mil->email_from;
- $formmail->withfrom=1;
+ $formmail->withfrom=0;
$formmail->withto=$user->email?$user->email:1;
$formmail->withcc=0;
- $formmail->withtopic=$mil->sujet;
+ $formmail->withtopic=0;
$formmail->withtopicreadonly=1;
$formmail->withfile=0;
- $formmail->withbody=$mil->body;
+ $formmail->withbody=0;
$formmail->withbodyreadonly=1;
// Tableau des substitutions
$formmail->substit["__FACREF__"]=$fac->ref;
diff --git a/htdocs/comm/mailing/mailing.class.php b/htdocs/comm/mailing/mailing.class.php
index 4bed9c460d1..29966e8170d 100644
--- a/htdocs/comm/mailing/mailing.class.php
+++ b/htdocs/comm/mailing/mailing.class.php
@@ -69,10 +69,10 @@ class Mailing
$this->db = $DB ;
$this->db_table = MAIN_DB_PREFIX."mailing";
- $this->statuts[0] = $langs->trans("MailingStatusDraft");
- $this->statuts[1] = $langs->trans("MailingStatusValidated");
- $this->statuts[2] = $langs->trans("MailingStatusSentPartialy");
- $this->statuts[3] = $langs->trans("MailingStatusSentCompletely");
+ $this->statuts[0] = $langs->trans("MailingStatusDraft");
+ $this->statuts[1] = $langs->trans("MailingStatusValidated");
+ $this->statuts[2] = $langs->trans("MailingStatusSentPartialy");
+ $this->statuts[3] = $langs->trans("MailingStatusSentCompletely");
}
/**
@@ -163,62 +163,65 @@ class Mailing
}
}
- /**
- * \brief Recupére l'objet mailing
- * \param rowid id du mailing
- */
- function fetch($rowid)
- {
- $sql = "SELECT m.rowid, m.titre, m.sujet, m.body";
- $sql .= " , m.email_from, m.email_replyto, m.email_errorsto";
- $sql .= " , m.statut, m.nbemail";
- $sql .= ", m.fk_user_creat, m.fk_user_valid, m.fk_user_appro";
- $sql .= ", ".$this->db->pdate("m.date_creat") . " as date_creat";
- $sql .= ", ".$this->db->pdate("m.date_valid") . " as date_valid";
- $sql .= ", ".$this->db->pdate("m.date_envoi") . " as date_envoi";
- $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
- $sql .= " WHERE m.rowid = ".$rowid;
-
- if ($this->db->query($sql) )
+ /**
+ * \brief Recupére l'objet mailing
+ * \param rowid id du mailing
+ * \return int
+ */
+ function fetch($rowid)
{
- if ($this->db->num_rows())
- {
- $obj = $this->db->fetch_object();
-
- $this->id = $obj->rowid;
- $this->statut = $obj->statut;
- $this->nbemail = $obj->nbemail;
- $this->titre = stripslashes($obj->titre);
- $this->sujet = stripslashes($obj->sujet);
- $this->body = stripslashes($obj->body);
-
- $this->email_from = $obj->email_from;
- $this->email_replyto = $obj->email_replyto;
- $this->email_errorsto = $obj->email_errorsto;
-
- $this->user_creat = $obj->fk_user_creat;
- $this->user_valid = $obj->fk_user_valid;
- $this->user_appro = $obj->fk_user_appro;
-
- $this->date_creat = $obj->date_creat;
- $this->date_valid = $obj->date_valid;
- $this->date_appro = $obj->date_appro;
- $this->date_envoi = $obj->date_envoi;
-
- return 0;
- }
- else
- {
- dolibarr_syslog("Mailing::Fetch Erreur -1");
- return -1;
- }
+ $sql = "SELECT m.rowid, m.titre, m.sujet, m.body";
+ $sql .= ", m.email_from, m.email_replyto, m.email_errorsto";
+ $sql .= ", m.statut, m.nbemail";
+ $sql .= ", m.fk_user_creat, m.fk_user_valid, m.fk_user_appro";
+ $sql .= ", ".$this->db->pdate("m.date_creat") . " as date_creat";
+ $sql .= ", ".$this->db->pdate("m.date_valid") . " as date_valid";
+ $sql .= ", ".$this->db->pdate("m.date_envoi") . " as date_envoi";
+ $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
+ $sql .= " WHERE m.rowid = ".$rowid;
+
+ dolibarr_syslog("Mailing.class::fetch sql=".$sql);
+ $result=$this->db->query($sql);
+ if ($result)
+ {
+ if ($this->db->num_rows($result))
+ {
+ $obj = $this->db->fetch_object($result);
+
+ $this->id = $obj->rowid;
+ $this->statut = $obj->statut;
+ $this->nbemail = $obj->nbemail;
+ $this->titre = $obj->titre;
+ $this->sujet = $obj->sujet;
+ $this->body = $obj->body;
+
+ $this->email_from = $obj->email_from;
+ $this->email_replyto = $obj->email_replyto;
+ $this->email_errorsto = $obj->email_errorsto;
+
+ $this->user_creat = $obj->fk_user_creat;
+ $this->user_valid = $obj->fk_user_valid;
+ $this->user_appro = $obj->fk_user_appro;
+
+ $this->date_creat = $obj->date_creat;
+ $this->date_valid = $obj->date_valid;
+ $this->date_appro = $obj->date_appro;
+ $this->date_envoi = $obj->date_envoi;
+
+ return 1;
+ }
+ else
+ {
+ dolibarr_syslog("Mailing::Fetch Erreur -1");
+ return -1;
+ }
+ }
+ else
+ {
+ dolibarr_syslog("Mailing::Fetch Erreur -2");
+ return -2;
+ }
}
- else
- {
- dolibarr_syslog("Mailing::Fetch Erreur -2");
- return -2;
- }
- }
/**
@@ -335,10 +338,10 @@ class Mailing
}
if ($mode == 5)
{
- if ($statut == 0) return $this->statuts[$statut].' '.img_picto($langs->trans($this->statuts[$statut]),'statut0');
- if ($statut == 1) return $this->statuts[$statut].' '.img_picto($langs->trans($this->statuts[$statut]),'statut1');
- if ($statut == 2) return $this->statuts[$statut].' '.img_picto($langs->trans($this->statuts[$statut]),'statut3');
- if ($statut == 3) return $this->statuts[$statut].' '.img_picto($langs->trans($this->statuts[$statut]),'statut6');
+ if ($statut == 0) return $this->statuts[$statut].' '.img_picto($langs->trans($this->statuts[$statut]),'statut0');
+ if ($statut == 1) return $this->statuts[$statut].' '.img_picto($langs->trans($this->statuts[$statut]),'statut1');
+ if ($statut == 2) return $this->statuts[$statut].' '.img_picto($langs->trans($this->statuts[$statut]),'statut3');
+ if ($statut == 3) return $this->statuts[$statut].' '.img_picto($langs->trans($this->statuts[$statut]),'statut6');
}
}
diff --git a/mysql/tables/llx_mailing.sql b/mysql/tables/llx_mailing.sql
index c0facf50824..83caf15efcd 100644
--- a/mysql/tables/llx_mailing.sql
+++ b/mysql/tables/llx_mailing.sql
@@ -31,7 +31,6 @@ create table llx_mailing
statut smallint DEFAULT 0, --
- date_envoi datetime, -- date d'envoi
titre varchar(60), -- company name
sujet varchar(60), -- company name
body text,
@@ -44,8 +43,9 @@ create table llx_mailing
email_errorsto varchar(160), -- company name
date_creat datetime, -- creation date
- date_valid datetime, -- creation date
- date_appro datetime, -- creation date
+ date_valid datetime, --
+ date_appro datetime, --
+ date_envoi datetime, -- date d'envoi
fk_user_creat integer, -- utilisateur qui a créé l'info
fk_user_valid integer, -- utilisateur qui a créé l'info