Merge pull request #4197 from atm-ph/new_mail_input_file_multiple

NEW hidden conf to use input file multiple from mail form
This commit is contained in:
Juanjo Menent
2016-01-09 17:57:50 +01:00
2 changed files with 63 additions and 47 deletions

View File

@@ -630,7 +630,8 @@ class FormMail extends Form
} }
if ($this->withfile == 2) // Can add other files if ($this->withfile == 2) // Can add other files
{ {
$out.= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />'; if (!empty($conf->global->FROM_MAIL_USE_INPUT_FILE_MULTIPLE)) $out.= '<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans("Upload").'" multiple />';
else $out.= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
$out.= ' '; $out.= ' ';
$out.= '<input type="submit" class="button" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />'; $out.= '<input type="submit" class="button" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />';
} }

View File

@@ -1437,20 +1437,33 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio
{ {
dol_syslog('dol_add_file_process upload_dir='.$upload_dir.' allowoverwrite='.$allowoverwrite.' donotupdatesession='.$donotupdatesession.' savingdocmask='.$savingdocmask, LOG_DEBUG); dol_syslog('dol_add_file_process upload_dir='.$upload_dir.' allowoverwrite='.$allowoverwrite.' donotupdatesession='.$donotupdatesession.' savingdocmask='.$savingdocmask, LOG_DEBUG);
if (dol_mkdir($upload_dir) >= 0) if (dol_mkdir($upload_dir) >= 0)
{
$TFile = $_FILES[$varfiles];
if (!is_array($TFile['name']))
{
foreach ($TFile as $key => &$val)
{
$val = array($val);
}
}
$nbfile = count($TFile['name']);
for ($i = 0; $i < $nbfile; $i++)
{ {
// Define $destpath (path to file including filename) and $destfile (only filename) // Define $destpath (path to file including filename) and $destfile (only filename)
$destpath=$upload_dir . "/" . $_FILES[$varfiles]['name']; $destpath=$upload_dir . "/" . $TFile['name'][$i];
$destfile=$_FILES[$varfiles]['name']; $destfile=$TFile['name'][$i];
$savingdocmask = dol_sanitizeFileName($savingdocmask); $savingdocmask = dol_sanitizeFileName($savingdocmask);
if ($savingdocmask) if ($savingdocmask)
{ {
$destpath=$upload_dir . "/" . preg_replace('/__file__/',$_FILES[$varfiles]['name'],$savingdocmask); $destpath=$upload_dir . "/" . preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask);
$destfile=preg_replace('/__file__/',$_FILES[$varfiles]['name'],$savingdocmask); $destfile=preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask);
} }
$resupload = dol_move_uploaded_file($_FILES[$varfiles]['tmp_name'], $destpath, $allowoverwrite, 0, $_FILES[$varfiles]['error'], 0, $varfiles); $resupload = dol_move_uploaded_file($TFile['tmp_name'][$i], $destpath, $allowoverwrite, 0, $TFile['error'][$i], 0, $varfiles);
if (is_numeric($resupload) && $resupload > 0) if (is_numeric($resupload) && $resupload > 0)
{ {
include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
@@ -1458,7 +1471,7 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio
{ {
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
$formmail = new FormMail($db); $formmail = new FormMail($db);
$formmail->add_attached_files($destpath, $destfile, $_FILES[$varfiles]['type']); $formmail->add_attached_files($destpath, $destfile, $TFile['type'][$i]);
} }
if (image_format_supported($destpath) == 1) if (image_format_supported($destpath) == 1)
{ {
@@ -1489,6 +1502,8 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio
} }
} }
} }
}
} elseif ($link) { } elseif ($link) {
if (dol_mkdir($upload_dir) >= 0) { if (dol_mkdir($upload_dir) >= 0) {
require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';