mirror of
https://github.com/vrana/adminer.git
synced 2025-08-17 12:00:41 +02:00
Exportable select
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@446 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
@@ -163,10 +163,7 @@ function check(td, name, value) {
|
||||
</script>
|
||||
|
||||
<form action="" method="post">
|
||||
<p>
|
||||
<?php echo lang('Output'); ?>: <select name="output"><option value="text"><?php echo lang('open'); ?></option><option value="file"><?php echo lang('save'); ?></option></select>
|
||||
<?php echo lang('Format'); ?>: <select name="format"><option value="sql"><?php echo lang('SQL'); ?></option><option value="csv"><?php echo lang('CSV'); ?></option></select>
|
||||
</p>
|
||||
<p><?php echo lang('Output') . ": <select name='output'><option value='text'>" . lang('open') . "</option><option value='file'>" . lang('save') . "</option></select> " . $dump_options; ?></p>
|
||||
|
||||
<?php
|
||||
echo "<table border='1' cellspacing='0' cellpadding='2'>\n<thead><tr><th>" . lang('Database') . "</th>";
|
||||
|
@@ -8,13 +8,13 @@ function dump_csv($row) {
|
||||
echo implode(",", $row) . "\n";
|
||||
}
|
||||
|
||||
function dump_data($table, $style) {
|
||||
function dump_data($table, $style, $from = "") {
|
||||
global $mysql, $max_packet;
|
||||
if ($style) {
|
||||
if ($_POST["format"] != "csv" && $style == "TRUNCATE, INSERT") {
|
||||
echo "TRUNCATE " . idf_escape($table) . ";\n";
|
||||
}
|
||||
$result = $mysql->query("SELECT * FROM " . idf_escape($table)); //! enum and set as numbers, binary as _binary, microtime
|
||||
$result = $mysql->query("SELECT * " . ($from ? $from : "FROM " . idf_escape($table))); //! enum and set as numbers, binary as _binary, microtime
|
||||
if ($result) {
|
||||
$insert = "INSERT INTO " . idf_escape($table) . " VALUES ";
|
||||
$length = 0;
|
||||
@@ -55,3 +55,6 @@ function dump_data($table, $style) {
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
|
||||
$dump_options = lang('Format') . ": <select name='format'><option value='sql'>" . lang('SQL') . "</option><option value='csv'>" . lang('CSV') . "</option></select>";
|
||||
$max_packet = 0;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
include "./export.inc.php";
|
||||
|
||||
$table_status = table_status($_GET["select"]);
|
||||
$indexes = indexes($_GET["select"]);
|
||||
$operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "REGEXP", "IN", "IS NULL");
|
||||
@@ -61,22 +63,31 @@ $from = "FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode("
|
||||
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"));
|
||||
}
|
||||
if (isset($_POST["truncate"])) {
|
||||
$result = $mysql->query($where ? "DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : "TRUNCATE " . idf_escape($_GET["select"]));
|
||||
$deleted = $mysql->affected_rows;
|
||||
} elseif ($_POST["export_result"]) {
|
||||
dump_data($_GET["select"], "INSERT", ($where ? "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : ""));
|
||||
} elseif (is_array($_POST["delete"])) {
|
||||
foreach ($_POST["delete"] as $val) {
|
||||
parse_str($val, $delete);
|
||||
$result = $mysql->query("DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($delete)) . " LIMIT 1");
|
||||
if (!$result) {
|
||||
break;
|
||||
if ($_POST["export"]) {
|
||||
dump_data($_GET["select"], "INSERT", "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($delete)) . " LIMIT 1");
|
||||
} else {
|
||||
$result = $mysql->query("DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($delete)) . " LIMIT 1");
|
||||
if (!$result) {
|
||||
break;
|
||||
}
|
||||
$deleted += $mysql->affected_rows;
|
||||
}
|
||||
$deleted += $mysql->affected_rows;
|
||||
}
|
||||
} elseif ($_POST["delete_selected"]) {
|
||||
if (!$_GET["page"]) {
|
||||
$result = $mysql->query("DELETE $from");
|
||||
$deleted = $mysql->affected_rows;
|
||||
if ($_POST["export"]) {
|
||||
dump_data($_GET["select"], "INSERT", $from);
|
||||
} else {
|
||||
$result1 = $mysql->query("SELECT * $from");
|
||||
while ($row1 = $result1->fetch_assoc()) {
|
||||
@@ -90,6 +101,9 @@ if ($_POST && !$error) {
|
||||
$result1->free();
|
||||
}
|
||||
}
|
||||
if ($_POST["export"] || $_POST["export_result"]) {
|
||||
exit;
|
||||
}
|
||||
if ($result) {
|
||||
redirect(remove_from_uri("page"), lang('%d item(s) have been deleted.', $deleted));
|
||||
}
|
||||
@@ -264,7 +278,8 @@ for (var i=0; <?php echo $i; ?> > i; i++) {
|
||||
echo "</tr>\n";
|
||||
}
|
||||
echo "</table>\n";
|
||||
echo "<p><input type='hidden' name='token' value='$token' />" . (count($group) == count($select) ? "<input type='submit' value='" . lang('Delete selected') . "' /> " : "") . "<input type='submit' name='truncate' value='" . lang('Truncate result') . "' onclick=\"return confirm('" . lang('Are you sure?') . "');\" /></p>\n";
|
||||
echo "<fieldset><legend>" . lang('Delete') . "</legend><input type='hidden' name='token' value='$token' />" . (count($group) == count($select) ? "<input type='submit' value='" . lang('Delete selected') . "' /> " : "") . "<input type='submit' name='truncate' value='" . lang('Truncate result') . "' onclick=\"return confirm('" . lang('Are you sure?') . "');\" /></fieldset>\n";
|
||||
echo "<fieldset><legend>" . lang('Export') . "</legend>$dump_options " . (count($group) == count($select) ? "<input type='submit' name='export' value='" . lang('Export selected') . "' /> " : "") . "<input type='submit' name='export_result' value='" . lang('Export result') . "' /></fieldset>\n"; //! output, format
|
||||
echo "</form>\n";
|
||||
if (intval($limit) && ($found_rows = $mysql->result($mysql->query(count($group) < count($select) ? " SELECT FOUND_ROWS()" : "SELECT COUNT(*) FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "")))) > $limit) {
|
||||
$max_page = floor(($found_rows - 1) / $limit);
|
||||
|
Reference in New Issue
Block a user