diff --git a/dump.inc.php b/dump.inc.php index c9da9986..c90d1804 100644 --- a/dump.inc.php +++ b/dump.inc.php @@ -75,22 +75,24 @@ function dump($db, $style) { echo ($_POST["format"] != "csv" ? "USE " . idf_escape($db) . ";\n" : ""); if (!strlen($_GET["db"])) { $views = array(); - $result = $mysql->query("SHOW TABLE STATUS"); - while ($row = $result->fetch_assoc()) { - if (isset($row["Engine"])) { - if ($_POST["format"] == "csv") { - ob_start(); + if ($_POST["tables"][0] || $_POST["data"][0]) { + $result = $mysql->query("SHOW TABLE STATUS"); + while ($row = $result->fetch_assoc()) { + if (isset($row["Engine"])) { + if ($_POST["format"] == "csv") { + ob_start(); + } + dump_table($row["Name"], $_POST["tables"][0]); + dump_data($row["Name"], $_POST["data"][0]); + if ($_POST["format"] == "csv") { + echo tar_file("$db/$row[Name].csv", ob_get_clean()); + } + } else { + $views[] = $row["Name"]; } - dump_table($row["Name"], $_POST["tables"][0]); - dump_data($row["Name"], $_POST["data"][0]); - if ($_POST["format"] == "csv") { - echo tar_file("$db/$row[Name].csv", ob_get_clean()); - } - } else { - $views[] = $row["Name"]; } + $result->free(); } - $result->free(); if ($_POST["format"] != "csv") { foreach ($views as $view) { dump_table($view, $_POST["tables"][0]); @@ -112,10 +114,7 @@ function tar_file($filename, $contents) { } if ($_POST) { - $filename = (strlen($_GET["db"]) ? preg_replace('~[^a-z0-9_]~i', '-', (strlen($_GET["dump"]) ? $_GET["dump"] : $_GET["db"])) : "dump"); - $ext = ($_POST["format"] == "sql" ? "sql" : (!strlen($_GET["db"]) || count(array_filter($_POST["tables"]) + array_filter($_POST["data"])) > 1 ? "tar" : "csv")); - header("Content-Type: " . ($ext == "tar" ? "application/x-tar" : ($ext == "sql" || $_POST["output"] != "file" ? "text/plain" : "text/csv")) . "; charset=utf-8"); - header("Content-Disposition: " . ($_POST["output"] == "file" ? "attachment" : "inline") . "; filename=$filename.$ext"); + $ext = dump_headers((strlen($_GET["dump"]) ? $_GET["dump"] : $_GET["db"]), (!strlen($_GET["db"]) || count(array_filter($_POST["tables"]) + array_filter($_POST["data"])) > 1)); if ($_POST["format"] != "csv") { $max_packet = 16777216; echo "SET NAMES utf8;\n"; @@ -133,14 +132,16 @@ if ($_POST) { } if (strlen($_GET["db"])) { foreach ($_POST["tables"] as $key => $style) { - $table = bracket_escape($key, "back"); - if ($ext == "tar") { - ob_start(); - } - dump_table($table, $style); - dump_data($table, $_POST["data"][$key]); - if ($ext == "tar") { - echo tar_file("$table.csv", ob_get_clean()); + if ($style || $_POST["data"][$key]) { + $table = bracket_escape($key, "back"); + if ($ext == "tar") { + ob_start(); + } + dump_table($table, $style); + dump_data($table, $_POST["data"][$key]); + if ($ext == "tar") { + echo tar_file("$table.csv", ob_get_clean()); + } } } dump_routines($_GET["db"]); @@ -163,7 +164,7 @@ function check(td, name, value) {
-

" . $dump_options; ?>

+

\n" . lang('Database') . ""; diff --git a/export.inc.php b/export.inc.php index 070f0132..1f6c3bd6 100644 --- a/export.inc.php +++ b/export.inc.php @@ -56,5 +56,13 @@ function dump_data($table, $style, $from = "") { } } -$dump_options = lang('Format') . ": "; +function dump_headers($identifier, $multi_table = false) { + $filename = (strlen($identifier) ? preg_replace('~[^a-z0-9_]~i', '-', $identifier) : "dump"); + $ext = ($_POST["format"] == "sql" ? "sql" : ($multi_table ? "tar" : "csv")); + header("Content-Type: " . ($ext == "tar" ? "application/x-tar" : ($ext == "sql" || $_POST["output"] != "file" ? "text/plain" : "text/csv")) . "; charset=utf-8"); + header("Content-Disposition: " . ($_POST["output"] == "file" ? "attachment" : "inline") . "; filename=$filename.$ext"); + return $ext; +} + +$dump_options = lang('Output') . ": " . lang('Format') . ": "; $max_packet = 0; diff --git a/lang/cs.inc.php b/lang/cs.inc.php index 313065db..68fbdd5e 100644 --- a/lang/cs.inc.php +++ b/lang/cs.inc.php @@ -172,4 +172,6 @@ $translations = array( 'Tables' => 'Tabulky', 'Structure' => 'Struktura', 'Data' => 'Data', + 'Export selected' => 'Exportovat označené', + 'Export result' => 'Exportovat výsledek', ); diff --git a/select.inc.php b/select.inc.php index 4353c1bd..5fe586b4 100644 --- a/select.inc.php +++ b/select.inc.php @@ -64,8 +64,7 @@ if ($_POST && !$error) { $result = true; $deleted = 0; if ($_POST["export"] || $_POST["export_result"]) { - header("Content-Type: text/plain; charset=utf-8"); - header("Content-Disposition: inline; filename=" . preg_replace('~[^a-z0-9_]~i', '-', $_GET["select"]) . "." . ($_POST["format"] == "sql" ? "sql" : "csv")); + dump_headers($_GET["select"]); } if (isset($_POST["truncate"])) { $result = $mysql->query($where ? "DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : "TRUNCATE " . idf_escape($_GET["select"]));