Skip to content

Commit

Permalink
Exportable select
Browse files Browse the repository at this point in the history
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@446 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information
jakubvrana committed Aug 16, 2008
1 parent 7afa763 commit ec23248
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
5 changes: 1 addition & 4 deletions dump.inc.php
Expand Up @@ -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>";
Expand Down
7 changes: 5 additions & 2 deletions export.inc.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
31 changes: 23 additions & 8 deletions select.inc.php
@@ -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");
Expand Down Expand Up @@ -61,22 +63,31 @@
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()) {
Expand All @@ -90,6 +101,9 @@
$result1->free();
}
}
if ($_POST["export"] || $_POST["export_result"]) {
exit;
}
if ($result) {
redirect(remove_from_uri("page"), lang('%d item(s) have been deleted.', $deleted));
}
Expand Down Expand Up @@ -264,7 +278,8 @@ function where_change(op) {
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);
Expand Down

0 comments on commit ec23248

Please sign in to comment.