From 0cd2afbb6b55134dd5002b62ef151232177317d7 Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Sun, 7 Jun 2009 23:53:51 +0000 Subject: [PATCH] Remove single item clone Load single row values in multi-edit git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@661 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- edit.inc.php | 20 +++++++++----------- include/editing.inc.php | 2 +- include/functions.inc.php | 5 +++++ index.php | 3 --- select.inc.php | 9 ++++----- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/edit.inc.php b/edit.inc.php index 367f017f..cbaf4749 100644 --- a/edit.inc.php +++ b/edit.inc.php @@ -1,6 +1,6 @@ $field) { if (isset($_GET["default"]) ? $field["auto_increment"] || preg_match('~text|blob~', $field["type"]) : !isset($field["privileges"][$update ? "update" : "insert"])) { @@ -39,15 +39,15 @@ if ($_POST && !$error && !isset($_GET["select"])) { } } } -page_header((isset($_GET["default"]) ? lang('Default values') : ($_GET["where"] || isset($_GET["select"]) ? lang('Edit') : lang('Insert'))), $error, array((isset($_GET["default"]) ? "table" : "select") => $_GET["edit"]), $_GET["edit"]); +page_header((isset($_GET["default"]) ? lang('Default values') : ($_GET["where"] || (isset($_GET["select"]) && !$_POST["clone"]) ? lang('Edit') : lang('Insert'))), $error, array((isset($_GET["default"]) ? "table" : "select") => $_GET["edit"]), $_GET["edit"]); unset($row); -if ($_POST) { +if ($_POST["save"]) { $row = (array) $_POST["fields"]; } elseif ($where) { $select = array(); foreach ($fields as $name => $field) { - if (isset($field["privileges"]["select"]) && (!$_GET["clone"] || !$field["auto_increment"])) { + if (isset($field["privileges"]["select"]) && (!$_POST["clone"] || !$field["auto_increment"])) { $select[] = ($field["type"] == "enum" || $field["type"] == "set" ? "1*" . idf_escape($name) . " AS " : "") . idf_escape($name); } } @@ -67,11 +67,9 @@ if ($fields) { echo "\n"; foreach ($fields as $name => $field) { echo ""; - $value = (!isset($row) ? $field["default"] : - (strlen($row[$name]) && ($field["type"] == "enum" || $field["type"] == "set") ? intval($row[$name]) : - ($_POST["clone"] && $field["auto_increment"] ? "" : - $row[$name] - ))); + $value = (!isset($row) ? ($_POST["clone"] && $field["auto_increment"] ? "" : $field["default"]) + : (strlen($row[$name]) && ($field["type"] == "enum" || $field["type"] == "set") ? intval($row[$name]) : $row[$name]) + ); input($name, $field, $value); if (isset($_GET["default"]) && $field["type"] == "timestamp") { if (!isset($create) && !$_POST) { @@ -88,10 +86,10 @@ if ($fields) { ?>

+ (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"])); - echo "\n"; } if ($fields) { echo ''; diff --git a/include/editing.inc.php b/include/editing.inc.php index 812dd23e..c3629132 100644 --- a/include/editing.inc.php +++ b/include/editing.inc.php @@ -25,7 +25,7 @@ function input($name, $field, $value, $separator = "

\n"; } $unique_idf = implode('&', unique_idf($row, $indexes)); - echo '' : ''); + echo '' : ''); foreach ($row as $key => $val) { if (!isset($val)) { $val = "NULL";
" . htmlspecialchars($name) . "") { //! pass empty if (preg_match('~char|date|time~', $field["type"])) { $options = (preg_match('~char~', $field["type"]) ? array("", "md5", "sha1", "password", "uuid") : array("", "now")); } - if (!isset($_GET["clone"]) && !isset($_GET["call"]) && (isset($_GET["select"]) || where($_GET))) { + if (!isset($_GET["call"]) && (isset($_GET["select"]) || where($_GET))) { if (preg_match('~int|float|double|decimal~', $field["type"])) { $options = array("", "+", "-"); } diff --git a/include/functions.inc.php b/include/functions.inc.php index a15e92c6..42df67d0 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -75,6 +75,11 @@ function where($where) { return $return; } +function where_check($val) { + parse_str($val, $check); + return where($check); +} + function process_length($length) { global $enum_length; return (preg_match("~^\\s*(?:$enum_length)(?:\\s*,\\s*(?:$enum_length))*\\s*\$~", $length) && preg_match_all("~$enum_length~", $length, $matches) ? implode(",", $matches[0]) : preg_replace('~[^0-9,+-]~', '', $length)); diff --git a/index.php b/index.php index f713479f..94a62ec6 100644 --- a/index.php +++ b/index.php @@ -98,9 +98,6 @@ 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/select.inc.php b/select.inc.php index 4da734a7..0fab31a4 100644 --- a/select.inc.php +++ b/select.inc.php @@ -74,8 +74,7 @@ if ($_POST && !$error) { dump_table($_GET["select"], ""); if (is_array($_POST["check"])) { foreach ($_POST["check"] as $val) { - parse_str($val, $check); - dump_data($_GET["select"], "INSERT", "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($check)) . " LIMIT 1"); + dump_data($_GET["select"], "INSERT", "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where_check($val)) . " LIMIT 1"); } } else { dump_data($_GET["select"], "INSERT", ($where ? "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : "")); @@ -93,10 +92,10 @@ if ($_POST && !$error) { if ($_POST["clone"]) { $set[] = ($val !== false ? $val : idf_escape($name)); } elseif ($val !== false) { - $set[] = idf_escape($name) . " = $val"; + $set[] = "\n" . idf_escape($name) . " = $val"; } } - $command .= ($_POST["clone"] ? " SELECT " . implode(", ", $set) . " FROM " . idf_escape($_GET["select"]) : " SET " . implode(", ", $set)); + $command .= ($_POST["clone"] ? "\nSELECT " . implode(", ", $set) . " FROM " . idf_escape($_GET["select"]) : " SET" . implode(",", $set)); } if (!$_POST["delete"] && !$set) { // nothing @@ -243,7 +242,7 @@ if (!$columns) { echo "
' . (count($select) == count($group) && $_GET["db"] != "information_schema" ? ' ' . lang('edit') . ' ' . lang('clone') . '' . (count($select) == count($group) && $_GET["db"] != "information_schema" ? ' ' . lang('edit') . '