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='
'.$message.'
'; $_GET["action"]="edit"; $_GET["id"]=$_POST["id"]; } +// Action update emailing +if ($_POST["action"] == 'update' && empty($_POST["removedfile"]) && empty($_POST["cancel"])) +{ + $mil = new Mailing($db); + $mil->fetch($_POST["id"]); + + $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($mil->id,2,0,1); + + $isupload=0; + + // If upload file + $i=''; + //$i=0; + //while ($i < 4) + //{ + if (! empty($_POST["addfile".$i]) && ! empty($conf->global->MAIN_UPLOAD_DOC)) + { + $isupload=1; + + if (! is_dir($upload_dir)) create_exdir($upload_dir); + + if (is_dir($upload_dir)) + { + $result = dol_move_uploaded_file($_FILES['addedfile'.$i]['tmp_name'], $upload_dir . "/" . $_FILES['addedfile'.$i]['name'],1); + if ($result > 0) + { + $mesg = '
'.$langs->trans("FileTransferComplete").'
'; + //print_r($_FILES); + } + else if ($result == -99) + { + // Files infected by a virus + $langs->load("errors"); + $mesg = '
'.$langs->trans("ErrorFileIsInfectedWithAVirus").'
'; + } + else if ($result < 0) + { + // Echec transfert (fichier depassant la limite ?) + $mesg = '
'.$langs->trans("ErrorFileNotUploaded").'
'; + // print_r($_FILES); + } + } + } + // $i++; + //} + + if (! $isupload) + { + $mil->sujet = trim($_POST["sujet"]); + $mil->body = trim($_POST["body"]); + $mil->bgcolor = trim($_POST["bgcolor"]); + $mil->bgimage = trim($_POST["bgimage"]); + + if (! $mil->sujet) $message.=($message?'
':'').$langs->trans("ErrorFieldRequired",$langs->trans("MailTopic")); + if (! $mil->body) $message.=($message?'
':'').$langs->trans("ErrorFieldRequired",$langs->trans("MailBody")); + + if (! $message) + { + if ($mil->update($user) >= 0) + { + Header("Location: fiche.php?id=".$mil->id); + exit; + } + $message=$mil->error; + } + + $message='
'.$message.'
'; + $_GET["action"]="edit"; + $_GET["id"]=$_POST["id"]; + } + else + { + $_GET["action"]="edit"; + $_GET["id"]=$_POST["id"]; + } +} + // Action confirmation validation if ($_POST["action"] == 'confirm_valide') { @@ -568,6 +672,8 @@ else { if ($mil->fetch($_GET["id"]) >= 0) { + $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($mil->id,2,0,1); + $head = emailing_prepare_head($mil); dol_fiche_head($head, 'card', $langs->trans("Mailing"), 0, 'email'); @@ -787,15 +893,30 @@ else print ''.$langs->trans("MailTopic").''.$mil->sujet.''; // Mails -/* - $i=0; - while ($i < 4) - { - $i++; - $property='joined_file'.$i; - print ''.$langs->trans("MailFile").' '.$i.''.$mil->$property.''; - } -*/ + $i=''; + //$i=0; + //while ($i < 4) + //{ + // $i++; + //$property='joined_file'.$i; + print ''.$langs->trans("MailFile").' '.$i.''; + // List of files + $listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,1); + if (sizeof($listofpaths)) + { + foreach($listofpaths as $key => $val) + { + print img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name']; + //print ' '; + print '
'; + } + } + else + { + print $langs->trans("NoAttachedFiles").'
'; + } + print ''; + //} // Message print ''.$langs->trans("MailMessage").''; @@ -819,8 +940,8 @@ else print ''.$langs->trans("Ref").''.$mil->id.''; print ''.$langs->trans("MailTitle").''.$mil->titre.''; - print ''.$langs->trans("MailFrom").''.dol_print_email($mil->email_from,0,0,1).''; - print ''.$langs->trans("MailErrorsTo").''.dol_print_email($mil->email_errorsto,0,0,1).''; + print ''.$langs->trans("MailFrom").''.dol_print_email($mil->email_from,0,0,0,0,1).''; + print ''.$langs->trans("MailErrorsTo").''.dol_print_email($mil->email_errorsto,0,0,0,0,1).''; // Status print ''.$langs->trans("Status").''.$mil->getLibStatut(4).''; @@ -844,8 +965,8 @@ else print ''; print ""; - - print '
'."\n"; + print "\n"; + print ''."\n"; print ''; print ''; print ''; @@ -857,20 +978,38 @@ else print ''.$langs->trans("MailTopic").''; // Add joined files -/* $i=0; - while ($i < 4) - { - $i++; - $property='joined_file'.$i; + $i=''; + //$i=0; + //while ($i < 4) + //{ + // $i++; + //$property='joined_file'.$i; print ''.$langs->trans("MailFile").' '.$i.''; print ''; - print ''; + // List of files + $listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,1); + if (sizeof($listofpaths)) + { + foreach($listofpaths as $key => $val) + { + print img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name']; + print ' '; + print '
'; + } + } + else + { + print $langs->trans("NoAttachedFiles").'
'; + } + // Add link to add file + print ''; print ' '; - print ''; - print $mil->$property?'
'.$mil->$property:''; + print ''; + //print $mil->$property?'
'.$mil->$property:''; + + print ''; - } -*/ + //} print ''.$langs->trans("BackgroundColorByDefault").''; $htmlother->select_color($mil->bgcolor,'bgcolor','edit_mailing');