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, ...) // Export into a file with format defined into setup (FEC, CSV, ...)
// Must be after definition of $sql // Must be after definition of $sql
if ($action == 'export_fileconfirm' && $user->rights->accounting->mouvements->export) { 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)); $result = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter, 'AND', (empty($conf->global->ACCOUNTING_REEXPORT) ? 0 : 1));
if ($result < 0) { if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} else { } else {
// Export files // Export files then exit
$accountancyexport = new AccountancyExport($db); $accountancyexport = new AccountancyExport($db);
$mimetype = $accountancyexport->getMimeType($formatexportset);
top_httphead($mimetype, 1);
// Output data on screen
$accountancyexport->export($object->lines, $formatexportset); $accountancyexport->export($object->lines, $formatexportset);
$notifiedexportdate = GETPOST('notifiedexportdate', 'alpha'); $notifiedexportdate = GETPOST('notifiedexportdate', 'alpha');
$notifiedvalidationdate = GETPOST('notifiedvalidationdate', 'alpha'); $notifiedvalidationdate = GETPOST('notifiedvalidationdate', 'alpha');
if (!empty($accountancyexport->errors)) { if (!empty($accountancyexport->errors)) {
setEventMessages('', $accountancyexport->errors, 'errors'); dol_print_error('', '', $accountancyexport->errors);
} elseif (!empty($notifiedexportdate) || !empty($notifiedvalidationdate)) { } elseif (!empty($notifiedexportdate) || !empty($notifiedvalidationdate)) {
// Specify as export : update field date_export or date_validated // Specify as export : update field date_export or date_validated
$error = 0; $error = 0;
@ -701,11 +708,10 @@ if ($action == 'export_fileconfirm' && $user->rights->accounting->mouvements->ex
if (!$error) { if (!$error) {
$db->commit(); $db->commit();
// setEventMessages($langs->trans("AllExportedMovementsWereRecordedAsExportedOrValidated"), null, 'mesgs');
} else { } else {
$error++; $error++;
$db->rollback(); $db->rollback();
setEventMessages($langs->trans("NotAllExportedMovementsCouldBeRecordedAsExportedOrValidated"), null, 'errors'); dol_print_error('', $langs->trans("NotAllExportedMovementsCouldBeRecordedAsExportedOrValidated"));
} }
} }
exit; 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 * 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"; $jsforcursor .= 'jQuery("html,body,#id-container").addClass("cursorwait");'."\n";
} }
$postconfirmas = 'GET';
$formconfirm .= ' $formconfirm .= '
resizable: false, resizable: false,
height: "'.$height.'", height: "'.$height.'",
@ -5184,15 +5186,19 @@ class Form
options += "&" + inputname + "=" + encodeURIComponent(inputvalue); options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
}); });
} }
var urljump = pageyes + (pageyes.indexOf("?") < 0 ? "?" : "") + options; var urljump = pageyes + (pageyes.indexOf("?") < 0 ? "?" : "&") + options;
if (pageyes.length > 0) { if (pageyes.length > 0) {';
'.$jsforcursor.' if ($postconfirmas == 'GET') {
var post = $.post( $formconfirm .= 'location.href = urljump;';
} else {
$formconfirm .= $jsforcursor;
$formconfirm .= 'var post = $.post(
pageyes, pageyes,
options, options,
function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); } function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
); );';
}
$formconfirm .= '
console.log("after post ok"); console.log("after post ok");
} }
$(this).dialog("close"); $(this).dialog("close");
@ -5211,15 +5217,20 @@ class Form
options += "&" + inputname + "=" + encodeURIComponent(inputvalue); options += "&" + inputname + "=" + encodeURIComponent(inputvalue);
}); });
} }
var urljump=pageno + (pageno.indexOf("?") < 0 ? "?" : "") + options; var urljump=pageno + (pageno.indexOf("?") < 0 ? "?" : "&") + options;
//alert(urljump); //alert(urljump);
if (pageno.length > 0) { if (pageno.length > 0) {';
'.$jsforcursor.' if ($postconfirmas == 'GET') {
var post = $.post( $formconfirm .= 'location.href = urljump;';
} else {
$formconfirm .= $jsforcursor;
$formconfirm .= 'var post = $.post(
pageno, pageno,
options, options,
function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); } function(data) { $("body").html(data); jQuery("html,body,#id-container").removeClass("cursorwait"); }
); );';
}
$formconfirm .= '
console.log("after post ko"); console.log("after post ko");
} }
$(this).dialog("close"); $(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 OverviewOfMovementsNotValidated=Overview of movements not validated and locked
AllMovementsWereRecordedAsValidated=All movements were recorded as validated and locked AllMovementsWereRecordedAsValidated=All movements were recorded as validated and locked
NotAllMovementsCouldBeRecordedAsValidated=Not all movements could be 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 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 ValidateHistory=Bind Automatically