Skip to content
Snippets Groups Projects
Commit 70342c09 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Fix: Better management of using ajax for upload form (to solve problem

when enabling ajax jquery multifile upload in some cases).
New: Add option to use a specific mask for uploaded filename
parent 0a11bf17
No related branches found
No related tags found
No related merge requests found
......@@ -39,13 +39,11 @@ For users:
- New: [ task #165 ] Add import/export of multiprices.
- New: Add Maghreb regions and departments.
- New: A more responsive desgin for statistic box of home page.
- Qual: Implement same rule for return value of all command line scripts (0 when success, <>0 if error).
- New: [ task #1005 ] Adapting to Spanish legislation bill numbering
- New: [ task #1011 ] Now supplier order and invoice deal with payment terms and mode.
- New: [ task #1014 ] Add option to recursivly add parent category.
- New: [ task #1016 ] Can define a specific numbering for deposits.
- New: [ task #918 ] Stock replenishment.
- Fix: [ bug #992 ] Proforma invoices don't have a separated numeric count.
- New : Add pdf link into supplier invoice list and supplier order list.
- New : Genrate auto the PDF for supplier invoice.
- New : Add category into filter webservice thirdparty method getListOfThirdParties.
......@@ -60,12 +58,16 @@ For users:
- New: Add hidden option MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS.
- New: Can send an email from thirdparty card.
- New: Can cancel holidays that were previously validated.
- Fix: [bug #1022] correct margin calculation for credit notes.
- New: Can choose contact on event (action com) creation, and filtred by thirdparty.
- New: Add hidden option MAIN_FORCE_DEFAULT_STATE_ID.
- New: Add page to make mass stock movement.
- New: Add field oustanding limit into thirdparty properties.
- New: Can enter a vat payment of zero.
- New: Add option to use a specific mask for uploaded filename
- Qual: Implement same rule for return value of all command line scripts (0 when success, <>0 if error).
- Fix: [ bug #992 ] Proforma invoices don't have a separated numeric count.
- Fix: [ bug #1022 ] correct margin calculation for credit notes.
- Fix: Better management of using ajax for upload form (to solve problem when enabling ajax jquery multifile upload in some cases).
For translators:
- Qual: Normalized sort order of all languages files with english reference files.
......
......@@ -59,19 +59,23 @@ class FormFile
* @param int $size Length of input file area
* @param Object $object Object to use (when attachment is done on an element)
* @param string $options Options
* @param boolean $useajax Use ajax if enabled
* @param boolean $useajax Use fileupload ajax (0=never, 1=if enabled, 2=always whatever is option). 2 should never be used.
* @param string $savingdocmask Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__'
* @return int <0 if KO, >0 if OK
*/
function form_attach_new_file($url, $title='', $addcancel=0, $sectionid=0, $perm=1, $size=50, $object='', $options='', $useajax=true)
function form_attach_new_file($url, $title='', $addcancel=0, $sectionid=0, $perm=1, $size=50, $object='', $options='', $useajax=1, $savingdocmask='')
{
global $conf,$langs, $hookmanager;
$hookmanager->initHooks(array('formfile'));
if (! empty($conf->browser->phone)) return 0;
if (! empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD) && $useajax)
if ((! empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD) && $useajax) || ($useajax==2))
{
return $this->_formAjaxFileUpload($object);
// TODO: Cheeck this works with 2 forms on same page
// TODO: Cheeck this works with GED module, otherwise, force useajax to 0
// TODO: This does not support option savingdocmask
return $this->_formAjaxFileUpload($object);
}
else
{
......@@ -133,6 +137,17 @@ class FormFile
$out .= ' ('.$langs->trans("UploadDisabled").')';
}
$out .= "</td></tr>";
if ($savingdocmask)
{
$out .= '<tr>';
if (! empty($options)) $out .= '<td>'.$options.'</td>';
$out .= '<td valign="middle" class="nowrap">';
$out .= '<input type="checkbox" checked="checked" name="savingdocmask" value="'.dol_escape_js($savingdocmask).'"> '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/',$langs->transnoentitiesnoconv("OriginFileName"),$savingdocmask), $langs->transnoentitiesnoconv("OriginFileName"));
$out .= '</td>';
$out .= '</tr>';
}
$out .= "</table>";
$out .= '</form>';
......
......@@ -994,18 +994,28 @@ function dol_init_file_process($pathtoscan='')
* @param int $allowoverwrite 1=Allow overwrite existing file
* @param int $donotupdatesession 1=Do no edit _SESSION variable
* @param string $varfiles _FILES var name
* @param string $savingdocmask Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__'
* @return void
*/
function dol_add_file_process($upload_dir,$allowoverwrite=0,$donotupdatesession=0,$varfiles='addedfile')
function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=0, $varfiles='addedfile', $savingdocmask='')
{
global $db,$user,$conf,$langs;
if (! empty($_FILES[$varfiles])) // For view $_FILES[$varfiles]['error']
{
dol_syslog('dol_add_file_process upload_dir='.$upload_dir.' allowoverwrite='.$allowoverwrite.' donotupdatesession='.$donotupdatesession, 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)
{
$resupload = dol_move_uploaded_file($_FILES[$varfiles]['tmp_name'], $upload_dir . "/" . $_FILES[$varfiles]['name'], $allowoverwrite, 0, $_FILES[$varfiles]['error'], 0, $varfiles);
// Define $destpath (path to file including filename) and $destfile (only filename)
$destpath=$upload_dir . "/" . $_FILES[$varfiles]['name'];
$destfile=$_FILES[$varfiles]['name'];
if ($savingdocmask)
{
$destpath=$upload_dir . "/" . preg_replace('/__file__/',$_FILES[$varfiles]['name'],$savingdocmask);
$destfile=preg_replace('/__file__/',$_FILES[$varfiles]['name'],$savingdocmask);
}
$resupload = dol_move_uploaded_file($_FILES[$varfiles]['tmp_name'], $destpath, $allowoverwrite, 0, $_FILES[$varfiles]['error'], 0, $varfiles);
if (is_numeric($resupload) && $resupload > 0)
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
......@@ -1013,16 +1023,16 @@ function dol_add_file_process($upload_dir,$allowoverwrite=0,$donotupdatesession=
{
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
$formmail->add_attached_files($upload_dir . "/" . $_FILES[$varfiles]['name'],$_FILES[$varfiles]['name'],$_FILES[$varfiles]['type']);
$formmail->add_attached_files($destpath, $destfile, $_FILES[$varfiles]['type']);
}
if (image_format_supported($upload_dir . "/" . $_FILES[$varfiles]['name']) == 1)
if (image_format_supported($destpath) == 1)
{
// Create small thumbs for image (Ratio is near 16/9)
// Used on logon for example
$imgThumbSmall = vignette($upload_dir . "/" . $_FILES[$varfiles]['name'], 160, 120, '_small', 50, "thumbs");
$imgThumbSmall = vignette($destpath, 160, 120, '_small', 50, "thumbs");
// Create mini thumbs for image (Ratio is near 16/9)
// Used on menu or for setup page for example
$imgThumbMini = vignette($upload_dir . "/" . $_FILES[$varfiles]['name'], 160, 120, '_mini', 50, "thumbs");
$imgThumbMini = vignette($destpath, 160, 120, '_mini', 50, "thumbs");
}
setEventMessage($langs->trans("FileTransferComplete"));
......
......@@ -74,8 +74,9 @@ if ($object->fetch($id, $ref))
// Envoi fichier
if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
if ($object->id > 0) {
dol_add_file_process($upload_dir, 0, 1, 'userfile');
if ($object->id > 0)
{
dol_add_file_process($upload_dir, 0, 1, 'userfile', GETPOST('savingdocmask'));
}
}
......@@ -197,9 +198,10 @@ if ($object->id > 0)
print '</table>';
print '</div>';
// Affiche formulaire upload
$formfile=new FormFile($db);
$formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?facid='.$object->id,'',0,0,$user->rights->fournisseur->facture->creer, 50, $object);
$formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?facid='.$object->id, '', 0, 0, $user->rights->fournisseur->facture->creer, 50, $object, '', 0, dol_sanitizeFileName($object->ref.'_'.$object->ref_supplier.'___file__'));
// List of document
......
......@@ -658,6 +658,8 @@ from=from
toward=toward
Access=Access
HelpCopyToClipboard=Use Ctrl+C to copy to clipboard
SaveUploadedFileWithMask=Save file on server with name "<strong>%s</strong>" (otherwise "%s")
OriginFileName=Nom d'origine
# Week day
Monday=Monday
......
......@@ -658,6 +658,8 @@ from=de
toward=vers
Access=Accès
HelpCopyToClipboard=Utilisez Ctrl+C pour copier dans le presse-papier
SaveUploadedFileWithMask=Sauver le fichier sur le serveur sous le nom "<strong>%s</strong>" (sinon "%s")
OriginFileName=nom du fichier source
# Week day
Monday=Lundi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment