]> git.joonet.de Git - adminer.git/commitdiff
Exportable select
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Sat, 16 Aug 2008 21:15:46 +0000 (21:15 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Sat, 16 Aug 2008 21:15:46 +0000 (21:15 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@446 7c3ca157-0c34-0410-bff1-cbf682f78f5c

dump.inc.php
export.inc.php
select.inc.php

index e469e9da959e7b48afc097c597d06159d86834e6..c9da9986baee8662e3fc3512537dccac506b4e22 100644 (file)
@@ -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>";
index 840266938aa62827d18a5c3a3d8a69820b283eb5..070f013214277fcc45db829dc8d4441b2db82dbc 100644 (file)
@@ -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;
index f5075103b2b9b038ece7b8ae0900e4ecb822c539..4353c1bd45e1658302c3e9d408ae2ea2e4eb765e 100644 (file)
@@ -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);