mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-05 09:08:09 +01:00
Fix: [ bug #236 ] Can't attach a file to e-mailings
This commit is contained in:
@@ -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."<br>";
|
||||
dol_htmloutput_mesg($message);
|
||||
|
||||
// Confirmation de la validation du mailing
|
||||
if ($_GET["action"] == 'valid')
|
||||
@@ -743,7 +748,7 @@ else
|
||||
print '<tr><td width="25%">';
|
||||
print $langs->trans("TotalNbOfDistinctRecipients");
|
||||
print '</td><td colspan="3">';
|
||||
$nbemail = ($mil->nbemail?$mil->nbemail:'<font class="error">'.$langs->trans("NoTargetYet").'</font>');
|
||||
$nbemail = ($mil->nbemail?$mil->nbemail:img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>');
|
||||
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 '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NoTargetYet")).'">'.$langs->trans("ValidMailing").'</a>';
|
||||
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NoTargetYet")).'">'.$langs->trans("ValidMailing").'</a>';
|
||||
}
|
||||
else if (empty($user->rights->mailing->valider))
|
||||
{
|
||||
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("ValidMailing").'</a>';
|
||||
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("ValidMailing").'</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -825,7 +830,7 @@ else
|
||||
{
|
||||
if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
|
||||
{
|
||||
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("SendMailing").'</a>';
|
||||
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("SendMailing").'</a>';
|
||||
}
|
||||
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 '<br>';
|
||||
@@ -900,29 +899,22 @@ else
|
||||
print '<tr><td width="25%">'.$langs->trans("MailTopic").'</td><td colspan="3">'.$mil->sujet.'</td></tr>';
|
||||
|
||||
// Joined files
|
||||
$i='';
|
||||
//$i=0;
|
||||
//while ($i < 4)
|
||||
//{
|
||||
// $i++;
|
||||
//$property='joined_file'.$i;
|
||||
print '<tr><td>'.$langs->trans("MailFile").' '.$i.'</td><td colspan="3">';
|
||||
// List of files
|
||||
$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
|
||||
if (count($listofpaths))
|
||||
print '<tr><td>'.$langs->trans("MailFile").'</td><td colspan="3">';
|
||||
// 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 '<br>';
|
||||
}
|
||||
print img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
|
||||
print '<br>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("NoAttachedFiles").'<br>';
|
||||
}
|
||||
print '</td></tr>';
|
||||
//}
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("NoAttachedFiles").'<br>';
|
||||
}
|
||||
print '</td></tr>';
|
||||
|
||||
// Background color
|
||||
/*print '<tr><td width="25%">'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
|
||||
@@ -990,40 +982,43 @@ else
|
||||
// Subject
|
||||
print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("MailTopic").'</td><td colspan="3"><input class="flat" type="text" size=60 name="sujet" value="'.$mil->sujet.'"></td></tr>';
|
||||
|
||||
dol_init_file_process($upload_dir);
|
||||
|
||||
// Joined files
|
||||
$i='';
|
||||
//$i=0;
|
||||
//while ($i < 4)
|
||||
//{
|
||||
// $i++;
|
||||
//$property='joined_file'.$i;
|
||||
print '<tr><td>'.$langs->trans("MailFile").' '.$i.'</td>';
|
||||
print '<td colspan="3">';
|
||||
// List of files
|
||||
$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
|
||||
if (count($listofpaths))
|
||||
$addfileaction='addfile';
|
||||
print '<tr><td>'.$langs->trans("MailFile").'</td>';
|
||||
print '<td colspan="3">';
|
||||
// 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.= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
|
||||
$out.= '<script type="text/javascript" language="javascript">';
|
||||
$out.= 'jQuery(document).ready(function () {';
|
||||
$out.= ' jQuery(".removedfile").click(function() {';
|
||||
$out.= ' jQuery(".removedfilehidden").val(jQuery(this).val());';
|
||||
$out.= ' });';
|
||||
$out.= '})';
|
||||
$out.= '</script>'."\n";
|
||||
if (count($listofpaths))
|
||||
{
|
||||
foreach($listofpaths as $key => $val)
|
||||
{
|
||||
foreach($listofpaths as $key => $val)
|
||||
{
|
||||
print img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
|
||||
print ' <input type="image" style="border: 0px;" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/delete.png" value="removedfile" name="removedfile" />';
|
||||
print '<input type="hidden" name="removedfileid" value="'.($key+1).'" />';
|
||||
print '<br>';
|
||||
}
|
||||
$out.= '<div id="attachfile_'.$key.'">';
|
||||
$out.= img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
|
||||
$out.= ' <input type="image" style="border: 0px;" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/delete.png" value="'.($key+1).'" class="removedfile" id="removedfile_'.$key.'" name="removedfile_'.$key.'" />';
|
||||
$out.= '<br></div>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("NoAttachedFiles").'<br>';
|
||||
}
|
||||
// Add link to add file
|
||||
print '<input type="file" class="flat" name="addedfile'.$i.'" value="'.$langs->trans("Upload").'"/>';
|
||||
print ' ';
|
||||
print '<input type="submit" class="button" name="addfile'.$i.'" value="'.$langs->trans("MailingAddFile").'">';
|
||||
//print $mil->$property?'<br>'.$mil->$property:'';
|
||||
|
||||
|
||||
print '</td></tr>';
|
||||
//}
|
||||
}
|
||||
else
|
||||
{
|
||||
$out.= $langs->trans("NoAttachedFiles").'<br>';
|
||||
}
|
||||
// Add link to add file
|
||||
$out.= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
|
||||
$out.= ' ';
|
||||
$out.= '<input type="submit" class="button" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />';
|
||||
print $out;
|
||||
print '</td></tr>';
|
||||
|
||||
// Background color
|
||||
print '<tr><td width="25%">'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user