From 820c88203d1d4c2e0f9103a290ef2a2f70eb5add Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Thu, 9 Oct 2008 13:23:54 +0000 Subject: [PATCH] Bulk clone git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@526 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- edit.inc.php | 21 ++++++++------------- functions.inc.php | 2 +- index.php | 5 ++++- lang/cs.inc.php | 4 +--- select.inc.php | 17 ++++++++++------- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/edit.inc.php b/edit.inc.php index 63e5ad30..09a92644 100644 --- a/edit.inc.php +++ b/edit.inc.php @@ -49,12 +49,11 @@ if ($_POST) { $select[] = ($field["type"] == "enum" || $field["type"] == "set" ? "1*" . idf_escape($name) . " AS " : "") . idf_escape($name); } } + $row = array(); if ($select) { $result = $mysql->query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1"); $row = $result->fetch_assoc(); $result->free(); - } else { - $row = array(); } } ?> @@ -66,13 +65,11 @@ if ($fields) { echo "\n"; foreach ($fields as $name => $field) { echo "
" . htmlspecialchars($name) . ""; - if (!isset($row)) { - $value = $field["default"]; - } elseif (strlen($row[$name]) && ($field["type"] == "enum" || $field["type"] == "set")) { - $value = intval($row[$name]); - } else { - $value = $row[$name]; - } + $value = (!isset($row) ? $field["default"] : + (strlen($row[$name]) && ($field["type"] == "enum" || $field["type"] == "set") ? intval($row[$name]) : + ($_POST["clone"] && $field["auto_increment"] ? "" : + $row[$name] + ))); input($name, $field, $value); if (isset($_GET["default"]) && $field["type"] == "timestamp") { if (!isset($create) && !$_POST) { @@ -91,10 +88,8 @@ if ($fields) { '; - } - echo ($_POST["all"] ? "\n" : "\n"); + hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"])); + echo "\n"; } if ($fields) { ?> diff --git a/functions.inc.php b/functions.inc.php index 061d49f1..e3f37fb4 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -341,7 +341,7 @@ function table_comment(&$row) { } } -function hidden_fields($process, $ignore) { +function hidden_fields($process, $ignore = array()) { while (list($key, $val) = each($process)) { if (is_array($val)) { foreach ($val as $k => $v) { diff --git a/index.php b/index.php index 9a45aeee..e9a06c40 100644 --- a/index.php +++ b/index.php @@ -99,7 +99,7 @@ if (isset($_GET["download"])) { if (isset($_GET["default"])) { $_GET["edit"] = $_GET["default"]; } - if (isset($_GET["select"]) && $_POST["edit"]) { + if (isset($_GET["select"]) && $_POST && (!$_POST["delete"] && !$_POST["export"] && !$_POST["save"])) { $_GET["edit"] = $_GET["select"]; } if (isset($_GET["callf"])) { @@ -108,6 +108,9 @@ if (isset($_GET["download"])) { if (isset($_GET["function"])) { $_GET["procedure"] = $_GET["function"]; } + if (isset($_GET["clone"])) { + $_GET["edit"] = $_GET["clone"]; + } if (isset($_GET["sql"])) { include "./sql.inc.php"; } elseif (isset($_GET["edit"])) { diff --git a/lang/cs.inc.php b/lang/cs.inc.php index 4404439b..31ab0484 100644 --- a/lang/cs.inc.php +++ b/lang/cs.inc.php @@ -149,7 +149,6 @@ $translations = array( 'Routine' => 'Procedura', 'Grant' => 'Povolit', 'Revoke' => 'Zakázat', - 'Error during deleting' => 'Chyba při mazání', 'Too big POST data. Reduce the data or increase the "post_max_size" configuration directive.' => 'Příliš velká POST data. Zmenšete data nebo zvyšte hodnotu konfigurační direktivy "post_max_size".', 'Logged as: %s' => 'Přihlášen jako: %s', 'Move up' => 'Přesunout nahoru', @@ -167,8 +166,6 @@ $translations = array( 'Tables' => 'Tabulky', 'Structure' => 'Struktura', 'Data' => 'Data', - // 'Export selected' => 'Exportovat označené', - // 'Export result' => 'Exportovat výsledek', 'Event has been dropped.' => 'Událost byla odstraněna.', 'Event has been altered.' => 'Událost byla změněna.', 'Event has been created.' => 'Událost byla vytvořena.', @@ -205,4 +202,5 @@ $translations = array( '%d item(s) have been affected.' => array('Byl ovlivněn %d záznam.', 'Byly ovlivněny %d záznamy.', 'Bylo ovlivněno %d záznamů.'), 'whole result' => 'celý výsledek', 'Tables have been dropped.' => 'Tabulky byla odstraněny.', + 'Clone' => 'Klonovat', ); diff --git a/select.inc.php b/select.inc.php index 8096f469..68951cbf 100644 --- a/select.inc.php +++ b/select.inc.php @@ -67,8 +67,6 @@ $limit = (isset($_GET["limit"]) ? $_GET["limit"] : "30"); $from = "FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . ($group && count($group) < count($select) ? " GROUP BY " . implode(", ", $group) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "") . (strlen($limit) ? " LIMIT " . intval($limit) . (intval($_GET["page"]) ? " OFFSET " . ($limit * $_GET["page"]) : "") : ""); if ($_POST && !$error) { - $result = true; - $affected = 0; if ($_POST["export"]) { dump_headers($_GET["select"]); dump_table($_GET["select"], ""); @@ -82,16 +80,20 @@ if ($_POST && !$error) { } exit; } - $command = ($_POST["delete"] ? ($_POST["all"] && !$where ? "TRUNCATE " : "DELETE FROM ") : "UPDATE ") . idf_escape($_GET["select"]); + $result = true; + $affected = 0; + $command = ($_POST["delete"] ? ($_POST["all"] && !$where ? "TRUNCATE " : "DELETE FROM ") : ($_POST["clone"] ? "INSERT INTO " : "UPDATE ")) . idf_escape($_GET["select"]); if (!$_POST["delete"]) { $set = array(); foreach ($fields as $name => $field) { $val = process_input($name, $field); - if ($val !== false) { + if ($_POST["clone"]) { + $set[] = ($val !== false ? $val : idf_escape($name)); + } elseif ($val !== false) { $set[] = idf_escape($name) . " = $val"; } } - $command .= " SET " . implode(", ", $set); + $command .= ($_POST["clone"] ? " SELECT " . implode(", ", $set) . " FROM " . idf_escape($_GET["select"]) : " SET " . implode(", ", $set)); } if (!$_POST["delete"] && !$set) { // nothing @@ -109,8 +111,9 @@ if ($_POST && !$error) { } } query_redirect(queries(), remove_from_uri("page"), lang('%d item(s) have been affected.', $affected), $result, false, !$result); + //! display edit page in case of an error } -page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]), ($error ? lang('Error during deleting') . ": $error" : "")); +page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]), $error); if (isset($rights["insert"])) { //! pass search values forth and back @@ -297,7 +300,7 @@ for (var i=0; > i; i++) { } echo " (" . lang('%d row(s)', $found_rows) . ")

\n"; - echo "
" . lang('Edit') . "
\n"; + echo "
" . lang('Edit') . "
\n"; echo "
" . lang('Export') . "$dump_options
\n"; echo "\n"; }