Fix regression using confirm as POST (pb with cursor and download file)

This commit is contained in:
Laurent Destailleur 2022-09-21 10:57:30 +02:00
parent 71a9cda8a2
commit 45c4a6ce1c
4 changed files with 56 additions and 17 deletions

View File

@ -653,21 +653,28 @@ if (!empty($sortfield)) {
// Export into a file with format defined into setup (FEC, CSV, ...)
// Must be after definition of $sql
if ($action == 'export_fileconfirm' && $user->rights->accounting->mouvements->export) {
// TODO Replace the fetchAll to get all ->line followed by call to ->export(). It consumew too much memory on large export. Replace this with the query($sql) and loop on each line to export them.
// TODO Replace the fetchAll to get all ->line followed by call to ->export(). It consumes too much memory on large export.
// Replace this with the query($sql) and loop on each line to export them.
$result = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter, 'AND', (empty($conf->global->ACCOUNTING_REEXPORT) ? 0 : 1));
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
} else {
// Export files
// Export files then exit
$accountancyexport = new AccountancyExport($db);
$mimetype = $accountancyexport->getMimeType($formatexportset);
top_httphead($mimetype, 1);
// Output data on screen
$accountancyexport->export($object->lines, $formatexportset);
$notifiedexportdate = GETPOST('notifiedexportdate', 'alpha');
$notifiedvalidationdate = GETPOST('notifiedvalidationdate', 'alpha');
if (!empty($accountancyexport->errors)) {
setEventMessages('', $accountancyexport->errors, 'errors');
dol_print_error('', '', $accountancyexport->errors);
} elseif (!empty($notifiedexportdate) || !empty($notifiedvalidationdate)) {
// Specify as export : update field date_export or date_validated
$error = 0;
@ -701,11 +708,10 @@ if ($action == 'export_fileconfirm' && $user->rights->accounting->mouvements->ex
if (!$error) {
$db->commit();
// setEventMessages($langs->trans("AllExportedMovementsWereRecordedAsExportedOrValidated"), null, 'mesgs');
} else {
$error++;
$db->rollback();
setEventMessages($langs->trans("NotAllExportedMovementsCouldBeRecordedAsExportedOrValidated"), null, 'errors');
dol_print_error('', $langs->trans("NotAllExportedMovementsCouldBeRecordedAsExportedOrValidated"));
}
}
exit;

View File

@ -286,6 +286,28 @@ class AccountancyExport
}
/**
* Return the MIME type of a file
*
* @param int $formatexportset Id of export format
* @return string MIME type.
*/
public function getMimeType($formatexportset)
{
$mime = 'text/csv';
switch ($formatexportset) {
case self::$EXPORT_TYPE_FEC:
$mime = 'text/tab-separated-values';
break;
default:
$mime = 'text/csv';
break;
}
return $mime;
}
/**
* Function who chose which export to use with the default config, and make the export into a file
*

View File

@ -5156,6 +5156,8 @@ class Form
$jsforcursor .= 'jQuery("html,body,#id-container").addClass("cursorwait");'."\n";
}
$postconfirmas = 'GET';
$formconfirm .= '
resizable: false,
height: "'.$height.'",
@ -5184,15 +5186,19 @@ class Form
options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
});
}
var urljump = pageyes + (pageyes.indexOf("?") < 0 ? "?" : "") + options;
if (pageyes.length > 0) {
'.$jsforcursor.'
var post = $.post(
var urljump = pageyes + (pageyes.indexOf("?") < 0 ? "?" : "&") + options;
if (pageyes.length > 0) {';
if ($postconfirmas == 'GET') {
$formconfirm .= 'location.href = urljump;';
} else {
$formconfirm .= $jsforcursor;
$formconfirm .= 'var post = $.post(
pageyes,
options,
function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
);
);';
}
$formconfirm .= '
console.log("after post ok");
}
$(this).dialog("close");
@ -5211,15 +5217,20 @@ class Form
options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
});
}
var urljump=pageno + (pageno.indexOf("?") < 0 ? "?" : "") + options;
var urljump=pageno + (pageno.indexOf("?") < 0 ? "?" : "&") + options;
//alert(urljump);
if (pageno.length > 0) {
'.$jsforcursor.'
var post = $.post(
if (pageno.length > 0) {';
if ($postconfirmas == 'GET') {
$formconfirm .= 'location.href = urljump;';
} else {
$formconfirm .= $jsforcursor;
$formconfirm .= 'var post = $.post(
pageno,
options,
function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
);
);';
}
$formconfirm .= '
console.log("after post ko");
}
$(this).dialog("close");

View File

@ -286,7 +286,7 @@ DescClosure=Consult here the number of movements by month not yet validated & lo
OverviewOfMovementsNotValidated=Overview of movements not validated and locked
AllMovementsWereRecordedAsValidated=All movements were recorded as validated and locked
NotAllMovementsCouldBeRecordedAsValidated=Not all movements could be recorded as validated and locked
ValidateMovements=Validate and lock record...
ValidateMovements=Validate and lock movements...
DescValidateMovements=Any modification or deletion of writing, lettering and deletes will be prohibited. All entries for an exercise must be validated otherwise closing will not be possible
ValidateHistory=Bind Automatically