Export Output in select.inc.php
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@447 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
ec23248c51
commit
9890b6c22d
11
dump.inc.php
11
dump.inc.php
|
@ -75,6 +75,7 @@ function dump($db, $style) {
|
||||||
echo ($_POST["format"] != "csv" ? "USE " . idf_escape($db) . ";\n" : "");
|
echo ($_POST["format"] != "csv" ? "USE " . idf_escape($db) . ";\n" : "");
|
||||||
if (!strlen($_GET["db"])) {
|
if (!strlen($_GET["db"])) {
|
||||||
$views = array();
|
$views = array();
|
||||||
|
if ($_POST["tables"][0] || $_POST["data"][0]) {
|
||||||
$result = $mysql->query("SHOW TABLE STATUS");
|
$result = $mysql->query("SHOW TABLE STATUS");
|
||||||
while ($row = $result->fetch_assoc()) {
|
while ($row = $result->fetch_assoc()) {
|
||||||
if (isset($row["Engine"])) {
|
if (isset($row["Engine"])) {
|
||||||
|
@ -91,6 +92,7 @@ function dump($db, $style) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$result->free();
|
$result->free();
|
||||||
|
}
|
||||||
if ($_POST["format"] != "csv") {
|
if ($_POST["format"] != "csv") {
|
||||||
foreach ($views as $view) {
|
foreach ($views as $view) {
|
||||||
dump_table($view, $_POST["tables"][0]);
|
dump_table($view, $_POST["tables"][0]);
|
||||||
|
@ -112,10 +114,7 @@ function tar_file($filename, $contents) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_POST) {
|
if ($_POST) {
|
||||||
$filename = (strlen($_GET["db"]) ? preg_replace('~[^a-z0-9_]~i', '-', (strlen($_GET["dump"]) ? $_GET["dump"] : $_GET["db"])) : "dump");
|
$ext = dump_headers((strlen($_GET["dump"]) ? $_GET["dump"] : $_GET["db"]), (!strlen($_GET["db"]) || count(array_filter($_POST["tables"]) + array_filter($_POST["data"])) > 1));
|
||||||
$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");
|
|
||||||
if ($_POST["format"] != "csv") {
|
if ($_POST["format"] != "csv") {
|
||||||
$max_packet = 16777216;
|
$max_packet = 16777216;
|
||||||
echo "SET NAMES utf8;\n";
|
echo "SET NAMES utf8;\n";
|
||||||
|
@ -133,6 +132,7 @@ if ($_POST) {
|
||||||
}
|
}
|
||||||
if (strlen($_GET["db"])) {
|
if (strlen($_GET["db"])) {
|
||||||
foreach ($_POST["tables"] as $key => $style) {
|
foreach ($_POST["tables"] as $key => $style) {
|
||||||
|
if ($style || $_POST["data"][$key]) {
|
||||||
$table = bracket_escape($key, "back");
|
$table = bracket_escape($key, "back");
|
||||||
if ($ext == "tar") {
|
if ($ext == "tar") {
|
||||||
ob_start();
|
ob_start();
|
||||||
|
@ -143,6 +143,7 @@ if ($_POST) {
|
||||||
echo tar_file("$table.csv", ob_get_clean());
|
echo tar_file("$table.csv", ob_get_clean());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
dump_routines($_GET["db"]);
|
dump_routines($_GET["db"]);
|
||||||
}
|
}
|
||||||
exit;
|
exit;
|
||||||
|
@ -163,7 +164,7 @@ function check(td, name, value) {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
<p><?php echo lang('Output') . ": <select name='output'><option value='text'>" . lang('open') . "</option><option value='file'>" . lang('save') . "</option></select> " . $dump_options; ?></p>
|
<p><?php echo $dump_options; ?></p>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
echo "<table border='1' cellspacing='0' cellpadding='2'>\n<thead><tr><th>" . lang('Database') . "</th>";
|
echo "<table border='1' cellspacing='0' cellpadding='2'>\n<thead><tr><th>" . lang('Database') . "</th>";
|
||||||
|
|
|
@ -56,5 +56,13 @@ function dump_data($table, $style, $from = "") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$dump_options = lang('Format') . ": <select name='format'><option value='sql'>" . lang('SQL') . "</option><option value='csv'>" . lang('CSV') . "</option></select>";
|
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') . ": <select name='output'><option value='text'>" . lang('open') . "</option><option value='file'>" . lang('save') . "</option></select> " . lang('Format') . ": <select name='format'><option value='sql'>" . lang('SQL') . "</option><option value='csv'>" . lang('CSV') . "</option></select>";
|
||||||
$max_packet = 0;
|
$max_packet = 0;
|
||||||
|
|
|
@ -172,4 +172,6 @@ $translations = array(
|
||||||
'Tables' => 'Tabulky',
|
'Tables' => 'Tabulky',
|
||||||
'Structure' => 'Struktura',
|
'Structure' => 'Struktura',
|
||||||
'Data' => 'Data',
|
'Data' => 'Data',
|
||||||
|
'Export selected' => 'Exportovat označené',
|
||||||
|
'Export result' => 'Exportovat výsledek',
|
||||||
);
|
);
|
||||||
|
|
|
@ -64,8 +64,7 @@ if ($_POST && !$error) {
|
||||||
$result = true;
|
$result = true;
|
||||||
$deleted = 0;
|
$deleted = 0;
|
||||||
if ($_POST["export"] || $_POST["export_result"]) {
|
if ($_POST["export"] || $_POST["export_result"]) {
|
||||||
header("Content-Type: text/plain; charset=utf-8");
|
dump_headers($_GET["select"]);
|
||||||
header("Content-Disposition: inline; filename=" . preg_replace('~[^a-z0-9_]~i', '-', $_GET["select"]) . "." . ($_POST["format"] == "sql" ? "sql" : "csv"));
|
|
||||||
}
|
}
|
||||||
if (isset($_POST["truncate"])) {
|
if (isset($_POST["truncate"])) {
|
||||||
$result = $mysql->query($where ? "DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : "TRUNCATE " . idf_escape($_GET["select"]));
|
$result = $mysql->query($where ? "DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : "TRUNCATE " . idf_escape($_GET["select"]));
|
||||||
|
|
Loading…
Reference in a new issue