From 45c4a6ce1c2ec863c06d560bbd4963b4b73b08d4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 21 Sep 2022 10:57:30 +0200 Subject: [PATCH] Fix regression using confirm as POST (pb with cursor and download file) --- htdocs/accountancy/bookkeeping/list.php | 16 ++++++--- .../class/accountancyexport.class.php | 22 +++++++++++++ htdocs/core/class/html.form.class.php | 33 ++++++++++++------- htdocs/langs/en_US/accountancy.lang | 2 +- 4 files changed, 56 insertions(+), 17 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 3ebda931c52..24c08b57574 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -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; diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index e4af034b1f4..390aaa9ed4a 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -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 * diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index a65c4a03108..a241aa367cf 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -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"); diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index d95791111cd..6e64f1c6e48 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -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