diff --git a/ChangeLog b/ChangeLog
index afcfca98710..c05e9a929d1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@ English Dolibarr ChangeLog
***** ChangeLog for 2.9 compared to 2.8 *****
For users:
+- New: Can join files on emailing campaigns.
- New: Add statistics on trips and expenses module.
- New: Can reopen a closed customer order.
- New: Add module externalsite to add a web site/tools inside
diff --git a/htdocs/comm/mailing/fiche.php b/htdocs/comm/mailing/fiche.php
index d31b8ea3808..8eb4c13381f 100644
--- a/htdocs/comm/mailing/fiche.php
+++ b/htdocs/comm/mailing/fiche.php
@@ -26,6 +26,7 @@
require("../../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/emailing.lib.php");
+require_once(DOL_DOCUMENT_ROOT.'/lib/files.lib.php');
require_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
require_once(DOL_DOCUMENT_ROOT."/comm/mailing/mailing.class.php");
@@ -105,6 +106,8 @@ if ($_REQUEST["action"] == 'sendallconfirmed' && $_REQUEST['confirm'] == 'yes')
$mil=new Mailing($db);
$result=$mil->fetch($_REQUEST['id']);
+ $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($mil->id,2,0,1);
+
if ($mil->statut == 0)
{
dol_print_error('','ErrorMailIsNotValidated');
@@ -186,10 +189,26 @@ if ($_REQUEST["action"] == 'sendallconfirmed' && $_REQUEST['confirm'] == 'yes')
$newsubject=make_substitutions($subject,$substitutionarray,$langs);
$newmessage=make_substitutions($message,$substitutionarray,$langs);
+ $arr_file = array();
+ $arr_mime = array();
+ $arr_name = array();
+ $arr_css = array();
+
+ $listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,1);
+ if (sizeof($listofpaths))
+ {
+ foreach($listofpaths as $key => $val)
+ {
+ $arr_file[]=$listofpaths[$key]['fullname'];
+ $arr_mime[]=dol_mimetype($listofpaths[$key]['name']);
+ $arr_name[]=$listofpaths[$key]['name'];
+ }
+ }
+
// Fabrication du mail
$mail = new CMailFile($newsubject, $sendto, $from, $newmessage,
- array(), array(), array(),
- '', '', 0, $msgishtml, $errorsto);
+ $arr_file, $arr_mime, $arr_name,
+ '', '', 0, $msgishtml, $errorsto, $arr_css);
if ($mail->error)
{
@@ -278,6 +297,8 @@ if ($_POST["action"] == 'send' && empty($_POST["cancel"]))
$mil = new Mailing($db);
$result=$mil->fetch($_POST["mailid"]);
+ $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($mil->id,2,0,1);
+
$mil->sendto = $_POST["sendto"];
if (! $mil->sendto)
{
@@ -285,11 +306,6 @@ if ($_POST["action"] == 'send' && empty($_POST["cancel"]))
}
if ($mil->sendto)
{
- $arr_file = array();
- $arr_mime = array();
- $arr_name = array();
- $arr_css = array();
-
// Ajout CSS
if (!empty($mil->bgcolor)) $arr_css['bgcolor'] = $mil->bgcolor;
if (!empty($mil->bgimage)) $arr_css['bgimage'] = $mil->bgimage;
@@ -302,6 +318,23 @@ if ($_POST["action"] == 'send' && empty($_POST["cancel"]))
$mil->sujet=make_substitutions($mil->sujet,$substitutionarrayfortest,$langs);
$mil->body=make_substitutions($mil->body,$substitutionarrayfortest,$langs);
+ $arr_file = array();
+ $arr_mime = array();
+ $arr_name = array();
+ $arr_css = array();
+
+ // Attached files
+ $listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,1);
+ if (sizeof($listofpaths))
+ {
+ foreach($listofpaths as $key => $val)
+ {
+ $arr_file[]=$listofpaths[$key]['fullname'];
+ $arr_mime[]=dol_mimetype($listofpaths[$key]['name']);
+ $arr_name[]=$listofpaths[$key]['name'];
+ }
+ }
+
$mailfile = new CMailFile($mil->sujet,$mil->sendto,$mil->email_from,$mil->body,
$arr_file,$arr_mime,$arr_name,'', '', 0, $msgishtml,$mil->email_errorsto,$arr_css);
@@ -360,6 +393,8 @@ if ($_REQUEST["action"] == 'setdesc' || $_REQUEST["action"] == 'setfrom' || $_RE
$mil = new Mailing($db);
$mil->fetch($_POST["id"]);
+ $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($mil->id,2,0,1);
+
if ($_REQUEST["action"] == 'setdesc') $mil->titre = trim($_REQUEST["desc"]);
if ($_REQUEST["action"] == 'setfrom') $mil->email_from = trim($_REQUEST["from"]);
if ($_REQUEST["action"] == 'setreplyto') $mil->email_replyto = trim($_REQUEST["replyto"]);
@@ -384,34 +419,103 @@ if ($_REQUEST["action"] == 'setdesc' || $_REQUEST["action"] == 'setfrom' || $_RE
}
// Action update emailing
-if ($_POST["action"] == 'update' && empty($_POST["cancel"]))
+if (! empty($_POST["removedfile"]))
{
$mil = new Mailing($db);
$mil->fetch($_POST["id"]);
- $mil->sujet = trim($_POST["sujet"]);
- $mil->body = trim($_POST["body"]);
- $mil->bgcolor = trim($_POST["bgcolor"]);
- $mil->bgimage = trim($_POST["bgimage"]);
+ $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($mil->id,2,0,1);
- if (! $mil->sujet) $message.=($message?'
':'').$langs->trans("ErrorFieldRequired",$langs->trans("MailTopic"));
- if (! $mil->body) $message.=($message?'
':'').$langs->trans("ErrorFieldRequired",$langs->trans("MailBody"));
+ $listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,1);
- if (! $message)
+ // Remove file
+ $filenb=($_POST["removedfile"]-1);
+ if (isset($listofpaths[$filenb]))
{
- if ($mil->update($user) >= 0)
- {
- Header("Location: fiche.php?id=".$mil->id);
- exit;
- }
- $message=$mil->error;
+ $result=dol_delete_file($listofpaths[$filenb]['fullname'],1);
}
- $message='