Fix: [ bug #236 ] Can't attach a file to e-mailings
This commit is contained in:
parent
985c061e65
commit
311f013289
@ -426,24 +426,38 @@ if ($_REQUEST["action"] == 'setdesc' || $_REQUEST["action"] == 'setfrom' || $_RE
|
|||||||
$_GET["id"]=$_REQUEST["id"];
|
$_GET["id"]=$_REQUEST["id"];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Action update emailing
|
/*
|
||||||
if (! empty($_POST["removedfileid"]))
|
* Add file in email form
|
||||||
|
*/
|
||||||
|
if (! empty($_POST['addfile']))
|
||||||
{
|
{
|
||||||
$mil = new Mailing($db);
|
$mil = new Mailing($db);
|
||||||
$mil->fetch($_POST["id"]);
|
$mil->fetch($_POST["id"]);
|
||||||
|
|
||||||
$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($mil->id,2,0,1);
|
$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
|
// Set tmp user directory
|
||||||
$filenb=($_POST["removedfileid"]-1);
|
$mesg=dol_add_file_process($upload_dir,0,0);
|
||||||
if (isset($listofpaths[$filenb]))
|
|
||||||
{
|
|
||||||
$result=dol_delete_file($listofpaths[$filenb]['fullname'],1);
|
|
||||||
}
|
|
||||||
|
|
||||||
$_GET["action"]="edit";
|
$_POST["action"]=$_GET["action"]="edit";
|
||||||
|
$_GET["id"]=$_POST["id"];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Action update emailing
|
||||||
|
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);
|
||||||
|
|
||||||
|
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
|
||||||
|
|
||||||
|
$mesg=dol_remove_file_process($_POST['removedfile'],0);
|
||||||
|
|
||||||
|
$_POST["action"]=$_GET["action"]="edit";
|
||||||
$_GET["id"]=$_POST["id"];
|
$_GET["id"]=$_POST["id"];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,15 +471,6 @@ if ($_POST["action"] == 'update' && empty($_POST["removedfile"]) && empty($_POST
|
|||||||
|
|
||||||
$isupload=0;
|
$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)
|
if (! $isupload)
|
||||||
{
|
{
|
||||||
$mil->sujet = trim($_POST["sujet"]);
|
$mil->sujet = trim($_POST["sujet"]);
|
||||||
@ -653,7 +658,7 @@ else
|
|||||||
|
|
||||||
dol_fiche_head($head, 'card', $langs->trans("Mailing"), 0, 'email');
|
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
|
// Confirmation de la validation du mailing
|
||||||
if ($_GET["action"] == 'valid')
|
if ($_GET["action"] == 'valid')
|
||||||
@ -743,7 +748,7 @@ else
|
|||||||
print '<tr><td width="25%">';
|
print '<tr><td width="25%">';
|
||||||
print $langs->trans("TotalNbOfDistinctRecipients");
|
print $langs->trans("TotalNbOfDistinctRecipients");
|
||||||
print '</td><td colspan="3">';
|
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 (!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && is_numeric($nbemail) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail)
|
||||||
{
|
{
|
||||||
if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0)
|
if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0)
|
||||||
@ -809,11 +814,11 @@ else
|
|||||||
{
|
{
|
||||||
if ($mil->nbemail <= 0)
|
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))
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -825,7 +830,7 @@ else
|
|||||||
{
|
{
|
||||||
if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -881,12 +886,6 @@ else
|
|||||||
$formmail->param["mailid"]=$mil->id;
|
$formmail->param["mailid"]=$mil->id;
|
||||||
$formmail->param["returnurl"]=DOL_URL_ROOT."/comm/mailing/fiche.php?id=".$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();
|
$formmail->show_form();
|
||||||
|
|
||||||
print '<br>';
|
print '<br>';
|
||||||
@ -900,29 +899,22 @@ else
|
|||||||
print '<tr><td width="25%">'.$langs->trans("MailTopic").'</td><td colspan="3">'.$mil->sujet.'</td></tr>';
|
print '<tr><td width="25%">'.$langs->trans("MailTopic").'</td><td colspan="3">'.$mil->sujet.'</td></tr>';
|
||||||
|
|
||||||
// Joined files
|
// Joined files
|
||||||
$i='';
|
print '<tr><td>'.$langs->trans("MailFile").'</td><td colspan="3">';
|
||||||
//$i=0;
|
// List of files
|
||||||
//while ($i < 4)
|
$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
|
||||||
//{
|
if (count($listofpaths))
|
||||||
// $i++;
|
{
|
||||||
//$property='joined_file'.$i;
|
foreach($listofpaths as $key => $val)
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
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
|
}
|
||||||
{
|
else
|
||||||
print $langs->trans("NoAttachedFiles").'<br>';
|
{
|
||||||
}
|
print $langs->trans("NoAttachedFiles").'<br>';
|
||||||
print '</td></tr>';
|
}
|
||||||
//}
|
print '</td></tr>';
|
||||||
|
|
||||||
// Background color
|
// Background color
|
||||||
/*print '<tr><td width="25%">'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
|
/*print '<tr><td width="25%">'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
|
||||||
@ -990,40 +982,43 @@ else
|
|||||||
// Subject
|
// 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>';
|
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
|
// Joined files
|
||||||
$i='';
|
$addfileaction='addfile';
|
||||||
//$i=0;
|
print '<tr><td>'.$langs->trans("MailFile").'</td>';
|
||||||
//while ($i < 4)
|
print '<td colspan="3">';
|
||||||
//{
|
// List of files
|
||||||
// $i++;
|
$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
|
||||||
//$property='joined_file'.$i;
|
// TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
|
||||||
print '<tr><td>'.$langs->trans("MailFile").' '.$i.'</td>';
|
$out.= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
|
||||||
print '<td colspan="3">';
|
$out.= '<script type="text/javascript" language="javascript">';
|
||||||
// List of files
|
$out.= 'jQuery(document).ready(function () {';
|
||||||
$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
|
$out.= ' jQuery(".removedfile").click(function() {';
|
||||||
if (count($listofpaths))
|
$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)
|
$out.= '<div id="attachfile_'.$key.'">';
|
||||||
{
|
$out.= img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
|
||||||
print 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.'" />';
|
||||||
print ' <input type="image" style="border: 0px;" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/delete.png" value="removedfile" name="removedfile" />';
|
$out.= '<br></div>';
|
||||||
print '<input type="hidden" name="removedfileid" value="'.($key+1).'" />';
|
|
||||||
print '<br>';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
print $langs->trans("NoAttachedFiles").'<br>';
|
{
|
||||||
}
|
$out.= $langs->trans("NoAttachedFiles").'<br>';
|
||||||
// Add link to add file
|
}
|
||||||
print '<input type="file" class="flat" name="addedfile'.$i.'" value="'.$langs->trans("Upload").'"/>';
|
// Add link to add file
|
||||||
print ' ';
|
$out.= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
|
||||||
print '<input type="submit" class="button" name="addfile'.$i.'" value="'.$langs->trans("MailingAddFile").'">';
|
$out.= ' ';
|
||||||
//print $mil->$property?'<br>'.$mil->$property:'';
|
$out.= '<input type="submit" class="button" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />';
|
||||||
|
print $out;
|
||||||
|
print '</td></tr>';
|
||||||
print '</td></tr>';
|
|
||||||
//}
|
|
||||||
|
|
||||||
// Background color
|
// Background color
|
||||||
print '<tr><td width="25%">'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
|
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).
|
* 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.
|
* All information used are in db, conf, langs, user and _FILES.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user