Maintain insert prefill value

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@957 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2009-08-03 13:37:29 +00:00
parent 1589362522
commit db46fc24cb
3 changed files with 22 additions and 16 deletions

View file

@ -8,10 +8,16 @@ foreach ($fields as $name => $field) {
}
}
if ($_POST && !$error && !isset($_GET["select"])) {
$location = ($_POST["insert"] // continue edit or insert
? $_SERVER["REQUEST_URI"]
: ME . (isset($_GET["default"]) ? "table=" : "select=") . urlencode($_GET["edit"]) //! append &set converted to &where
);
$location = $_SERVER["REQUEST_URI"]; // continue edit or insert
if (!$_POST["insert"]) {
$location = ME . (isset($_GET["default"]) ? "table=" : "select=") . urlencode($_GET["edit"]);
$i = 0; // append &set converted to &where
foreach ((array) $_GET["set"] as $key => $val) {
if ($val == $_POST["fields"][$key]) {
$location .= where_link($i++, bracket_escape($key, "back"), $val);
}
}
}
$set = array();
foreach ($fields as $name => $field) {
$val = process_input($field);

View file

@ -94,7 +94,7 @@ function where_check($val) {
}
function where_link($i, $column, $value) {
return "&where%5B$i%5D%5Bcol%5D=" . urlencode($column) . "&where%5B$i%5D%5Bop%5D=%3D&where%5B$i%5D%5Bval%5D=" . urlencode($value);
return "&where%5B$i%5D%5Bcol%5D=" . urlencode($column) . "&where%5B$i%5D%5Bop%5D=%3D&where%5B$i%5D%5Bval%5D=" . urlencode($value);
}
function redirect($location, $message = null) {

View file

@ -220,14 +220,15 @@ if (!$columns) {
$val = nl2br(h($val));
}
// link related items
foreach ((array) $foreign_keys[$key] as $foreign_key) {
if (count($foreign_keys[$key]) == 1 || count($foreign_key["source"]) == 1) {
foreach ($foreign_key["source"] as $i => $source) {
$link .= where_link($i, $foreign_key["target"][$i], $rows[$n][$source]);
if (!$link) { // link related items
foreach ((array) $foreign_keys[$key] as $foreign_key) {
if (count($foreign_keys[$key]) == 1 || count($foreign_key["source"]) == 1) {
foreach ($foreign_key["source"] as $i => $source) {
$link .= where_link($i, $foreign_key["target"][$i], $rows[$n][$source]);
}
$link = h((strlen($foreign_key["db"]) ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($foreign_key["db"]), ME) : ME) . 'select=' . urlencode($foreign_key["table"]) . $link); // InnoDB supports non-UNIQUE keys
break;
}
$link = h((strlen($foreign_key["db"]) ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($foreign_key["db"]), ME) : ME) . 'select=' . urlencode($foreign_key["table"])) . $link; // InnoDB supports non-UNIQUE keys
break;
}
}
}
@ -242,13 +243,12 @@ if (!$columns) {
echo "<td>";
foreach ($table_names as $table => $name) {
foreach ($backward_keys[$table] as $columns) {
echo " <a href='" . h(ME) . 'select=' . urlencode($table);
$link = ME . 'select=' . urlencode($table);
$i = 0;
foreach ($columns as $column => $val) {
echo where_link($i, $column, $rows[$n][$val]);
$i++;
$link .= where_link($i++, $column, $rows[$n][$val]);
}
echo "'>$name</a>";
echo " <a href='" . h($link) . "'>$name</a>";
}
}
}