diff --git a/htdocs/comm/mailing/fiche.php b/htdocs/comm/mailing/fiche.php index 870e5833782..71777209198 100644 --- a/htdocs/comm/mailing/fiche.php +++ b/htdocs/comm/mailing/fiche.php @@ -426,24 +426,38 @@ if ($_REQUEST["action"] == 'setdesc' || $_REQUEST["action"] == 'setfrom' || $_RE $_GET["id"]=$_REQUEST["id"]; } +/* + * Add file in email form + */ +if (! empty($_POST['addfile'])) +{ + $mil = new Mailing($db); + $mil->fetch($_POST["id"]); + + $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($mil->id,2,0,1); + + require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); + + // Set tmp user directory + $mesg=dol_add_file_process($upload_dir,0,0); + + $_POST["action"]=$_GET["action"]="edit"; + $_GET["id"]=$_POST["id"]; +} + // Action update emailing -if (! empty($_POST["removedfileid"])) +if (! empty($_POST["removedfile"])) { $mil = new Mailing($db); $mil->fetch($_POST["id"]); $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($mil->id,2,0,1); - $listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0); + require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); - // Remove file - $filenb=($_POST["removedfileid"]-1); - if (isset($listofpaths[$filenb])) - { - $result=dol_delete_file($listofpaths[$filenb]['fullname'],1); - } + $mesg=dol_remove_file_process($_POST['removedfile'],0); - $_GET["action"]="edit"; + $_POST["action"]=$_GET["action"]="edit"; $_GET["id"]=$_POST["id"]; } @@ -457,15 +471,6 @@ if ($_POST["action"] == 'update' && empty($_POST["removedfile"]) && empty($_POST $isupload=0; - // If upload file - if (! empty($_POST["addfile"]) && ! empty($conf->global->MAIN_UPLOAD_DOC)) - { - $isupload=1; - $upload_dir = $conf->mailing->dir_output."/".get_exdir($mil->id,2,0,1); - - $mesg=dol_add_file_process($upload_dir,0,1); - } - if (! $isupload) { $mil->sujet = trim($_POST["sujet"]); @@ -653,7 +658,7 @@ else dol_fiche_head($head, 'card', $langs->trans("Mailing"), 0, 'email'); - if ($message) print $message."
"; + dol_htmloutput_mesg($message); // Confirmation de la validation du mailing if ($_GET["action"] == 'valid') @@ -743,7 +748,7 @@ else print ''; print $langs->trans("TotalNbOfDistinctRecipients"); print ''; - $nbemail = ($mil->nbemail?$mil->nbemail:''.$langs->trans("NoTargetYet").''); + $nbemail = ($mil->nbemail?$mil->nbemail:img_warning('').' '.$langs->trans("NoTargetYet").''); if (!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && is_numeric($nbemail) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) { if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0) @@ -809,11 +814,11 @@ else { if ($mil->nbemail <= 0) { - print ''.$langs->trans("ValidMailing").''; + print ''.$langs->trans("ValidMailing").''; } else if (empty($user->rights->mailing->valider)) { - print ''.$langs->trans("ValidMailing").''; + print ''.$langs->trans("ValidMailing").''; } else { @@ -825,7 +830,7 @@ else { if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0) { - print ''.$langs->trans("SendMailing").''; + print ''.$langs->trans("SendMailing").''; } else { @@ -881,12 +886,6 @@ else $formmail->param["mailid"]=$mil->id; $formmail->param["returnurl"]=DOL_URL_ROOT."/comm/mailing/fiche.php?id=".$mil->id; - // Init list of files - if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') - { - $formmail->clear_attached_files(); - } - $formmail->show_form(); print '
'; @@ -900,29 +899,22 @@ else print ''.$langs->trans("MailTopic").''.$mil->sujet.''; // Joined files - $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,0); - if (count($listofpaths)) + print ''.$langs->trans("MailFile").''; + // List of files + $listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0); + if (count($listofpaths)) + { + foreach($listofpaths as $key => $val) { - foreach($listofpaths as $key => $val) - { - print img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name']; - print '
'; - } + print img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name']; + print '
'; } - else - { - print $langs->trans("NoAttachedFiles").'
'; - } - print ''; - //} + } + else + { + print $langs->trans("NoAttachedFiles").'
'; + } + print ''; // Background color /*print ''.$langs->trans("BackgroundColorByDefault").''; @@ -990,40 +982,43 @@ else // Subject print ''.$langs->trans("MailTopic").''; + dol_init_file_process($upload_dir); + // Joined files - $i=''; - //$i=0; - //while ($i < 4) - //{ - // $i++; - //$property='joined_file'.$i; - print ''.$langs->trans("MailFile").' '.$i.''; - print ''; - // List of files - $listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0); - if (count($listofpaths)) + $addfileaction='addfile'; + print ''.$langs->trans("MailFile").''; + print ''; + // List of files + $listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0); + // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript + $out.= ''."\n"; + $out.= ''."\n"; + if (count($listofpaths)) + { + foreach($listofpaths as $key => $val) { - foreach($listofpaths as $key => $val) - { - print img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name']; - print ' '; - print ''; - print '
'; - } + $out.= '
'; + $out.= img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name']; + $out.= ' '; + $out.= '
'; } - else - { - print $langs->trans("NoAttachedFiles").'
'; - } - // Add link to add file - print ''; - print ' '; - print ''; - //print $mil->$property?'
'.$mil->$property:''; - - - print ''; - //} + } + else + { + $out.= $langs->trans("NoAttachedFiles").'
'; + } + // Add link to add file + $out.= ''; + $out.= ' '; + $out.= ''; + print $out; + print ''; // Background color print ''.$langs->trans("BackgroundColorByDefault").''; diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 94872285ddc..bad2bc75e70 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -831,6 +831,36 @@ function dol_meta_create($object) } } + + +/** + * Init $_SESSION with uploaded files + * + * @param string $pathtoscan Path to scan + * @return void + */ +function dol_init_file_process($pathtoscan='') +{ + $listofpaths=array(); + $listofnames=array(); + $listofmimes=array(); + + if ($pathtoscan) + { + $listoffiles=dol_dir_list($pathtoscan,'files'); + foreach($listoffiles as $key => $val) + { + $listofpaths[]=$val['fullname']; + $listofnames[]=$val['name']; + $listofmimes[]=dol_mimetype($val['name']); + } + } + $_SESSION["listofpaths"]=join(';',$listofpaths); + $_SESSION["listofnames"]=join(';',$listofnames); + $_SESSION["listofmimes"]=join(';',$listofmimes); +} + + /** * Get and save an upload file (for example after submitting a new file a mail form). * All information used are in db, conf, langs, user and _FILES.