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
This commit is contained in:
jakubvrana 2009-06-07 23:53:51 +00:00
parent 0abe5a5060
commit 0cd2afbb6b
5 changed files with 19 additions and 20 deletions

View file

@ -1,6 +1,6 @@
<?php
$where = (isset($_GET["select"]) ? array() : where($_GET));
$update = ($where && !$_GET["clone"]);
$where = (isset($_GET["select"]) ? (count($_POST["check"]) == 1 ? where_check($_POST["check"][0]) : array()) : where($_GET));
$update = ($where && !$_POST["clone"]);
$fields = fields($_GET["edit"]);
foreach ($fields as $name => $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 "<table cellspacing='0'>\n";
foreach ($fields as $name => $field) {
echo "<tr><th>" . htmlspecialchars($name) . "</th>";
$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) {
?>
<p>
<input type="hidden" name="token" value="<?php echo $token; ?>" />
<input type="hidden" name="save" value="1" />
<?php
if (isset($_GET["select"])) {
hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
echo "<input type='hidden' name='save' value='1' />\n";
}
if ($fields) {
echo '<input type="submit" value="' . lang('Save') . '" />';

View file

@ -25,7 +25,7 @@ function input($name, $field, $value, $separator = "</td><td>") { //! 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("", "+", "-");
}

View file

@ -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));

View file

@ -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"])) {

View file

@ -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 "</tr></thead>\n";
}
$unique_idf = implode('&amp;', unique_idf($row, $indexes));
echo '<tr' . odd() . '><td><input type="checkbox" name="check[]" value="' . $unique_idf . '" onclick="this.form[\'all\'].checked = false; form_uncheck(\'all-page\');" />' . (count($select) == count($group) && $_GET["db"] != "information_schema" ? ' <a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '&amp;' . $unique_idf . '">' . lang('edit') . '</a> <a href="' . htmlspecialchars($SELF) . 'clone=' . urlencode($_GET['select']) . '&amp;' . $unique_idf . '">' . lang('clone') . '</a></td>' : '');
echo '<tr' . odd() . '><td><input type="checkbox" name="check[]" value="' . $unique_idf . '" onclick="this.form[\'all\'].checked = false; form_uncheck(\'all-page\');" />' . (count($select) == count($group) && $_GET["db"] != "information_schema" ? ' <a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '&amp;' . $unique_idf . '">' . lang('edit') . '</a></td>' : '');
foreach ($row as $key => $val) {
if (!isset($val)) {
$val = "<i>NULL</i>";