#12687 Changes to the export name

This commit is contained in:
Daniel Maya 2024-02-07 15:49:20 +01:00
parent 5bc20f9768
commit 8675e60c9b
2 changed files with 33 additions and 25 deletions

View File

@ -222,6 +222,7 @@ html_print_table($table);
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "ajax.php", url: "ajax.php",
dataType: 'json',
data: { data: {
page: 'include/ajax/resources.ajax', page: 'include/ajax/resources.ajax',
exportPrd: 1, exportPrd: 1,
@ -230,29 +231,34 @@ html_print_table($table);
name: $("#select_value option:selected").text(), name: $("#select_value option:selected").text(),
}, },
success: function(data) { success: function(data) {
let a = document.createElement('a'); if (data.error === -1 || data.error === -2) {
const url = '<?php echo $config['homeurl'].'/attachment/'; ?>' + data; console.error("Failed to create file");
a.href = url;
a.download = data;
a.click();
setTimeout(() => {
$.ajax({
type: "DELETE",
url: "ajax.php",
data: {
page: 'include/ajax/resources.ajax',
deleteFile: 1,
filename: data,
},
});
$("#confirm_downloadDialog").dialog("close"); $("#confirm_downloadDialog").dialog("close");
}, 3000); } else {
let a = document.createElement('a');
const url = '<?php echo $config['homeurl'].'/attachment/'; ?>' + data.name;
a.href = url;
a.download = data.name_download;
a.click();
setTimeout(() => {
$.ajax({
type: "DELETE",
url: "ajax.php",
data: {
page: 'include/ajax/resources.ajax',
deleteFile: 1,
filename: data,
},
});
$("#confirm_downloadDialog").dialog("close");
}, 3000);
}
}, },
error: function(data) { error: function(data) {
console.error("Fatal error in AJAX call to interpreter order", data) console.error("Fatal error in AJAX call to interpreter order", data);
} }
}); });
} }
}); });
</script> </script>

View File

@ -69,10 +69,11 @@ if ((bool) is_ajax() === true) {
$data = $prd->exportPrd($type, $value, $name); $data = $prd->exportPrd($type, $value, $name);
$return = ''; $return = [];
if (empty($data) === false) { if (empty($data) === false) {
$filename = $type.'-'.date('Ymd').'-'.date('His').'.prd'; $filename = uniqid().'.prd';
$filename_download = date('YmdHis').'-'.$type.'-'.$name.'.prd';
$file = $config['attachment_store'].'/'.$filename; $file = $config['attachment_store'].'/'.$filename;
$file_pointer = fopen($file, 'a'); $file_pointer = fopen($file, 'a');
@ -80,18 +81,19 @@ if ((bool) is_ajax() === true) {
$write = fwrite($file_pointer, $data); $write = fwrite($file_pointer, $data);
if ($write === false) { if ($write === false) {
$return = -2; $return['error'] = -2;
} else { } else {
$return = $filename; $return['name'] = $filename;
$return['name_download'] = $filename_download;
} }
fclose($file_pointer); fclose($file_pointer);
} else { } else {
$return = -1; $return['error'] = -1;
} }
} }
echo $return; echo json_encode($return);
return; return;
} }