diff --git a/pandora_console/godmode/resources/resources_export_import.php b/pandora_console/godmode/resources/resources_export_import.php index 9fe4eb2852..5127094753 100644 --- a/pandora_console/godmode/resources/resources_export_import.php +++ b/pandora_console/godmode/resources/resources_export_import.php @@ -222,6 +222,7 @@ html_print_table($table); $.ajax({ type: "GET", url: "ajax.php", + dataType: 'json', data: { page: 'include/ajax/resources.ajax', exportPrd: 1, @@ -230,29 +231,34 @@ html_print_table($table); name: $("#select_value option:selected").text(), }, success: function(data) { - let a = document.createElement('a'); - const url = '' + data; - 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, - }, - }); + if (data.error === -1 || data.error === -2) { + console.error("Failed to create file"); $("#confirm_downloadDialog").dialog("close"); - }, 3000); + } else { + let a = document.createElement('a'); + const url = '' + 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) { - console.error("Fatal error in AJAX call to interpreter order", data) + console.error("Fatal error in AJAX call to interpreter order", data); } }); } }); - \ No newline at end of file + diff --git a/pandora_console/include/ajax/resources.ajax.php b/pandora_console/include/ajax/resources.ajax.php index 379a499407..7035655620 100644 --- a/pandora_console/include/ajax/resources.ajax.php +++ b/pandora_console/include/ajax/resources.ajax.php @@ -69,10 +69,11 @@ if ((bool) is_ajax() === true) { $data = $prd->exportPrd($type, $value, $name); - $return = ''; + $return = []; 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_pointer = fopen($file, 'a'); @@ -80,18 +81,19 @@ if ((bool) is_ajax() === true) { $write = fwrite($file_pointer, $data); if ($write === false) { - $return = -2; + $return['error'] = -2; } else { - $return = $filename; + $return['name'] = $filename; + $return['name_download'] = $filename_download; } fclose($file_pointer); } else { - $return = -1; + $return['error'] = -1; } } - echo $return; + echo json_encode($return); return; }