diff --git a/CHANGELOG.md b/CHANGELOG.md index 78c63ff3..63ee7d31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Link //domain.tld values - Improve print of nested tables - Hide sort links on unsortable columns +- Display uneditable fields in edit form - PostgreSQL: Offer foreign keys in create table - PostgreSQL: Add missing parentheses to CHECK export - PostgreSQL: Allow creating NOT DEFERRABLE foreign keys diff --git a/adminer/edit.inc.php b/adminer/edit.inc.php index 5e661f3e..b47f5e41 100644 --- a/adminer/edit.inc.php +++ b/adminer/edit.inc.php @@ -9,7 +9,7 @@ $where = (isset($_GET["select"]) ); $update = (isset($_GET["select"]) ? $_POST["edit"] : $where); foreach ($fields as $name => $field) { - if (!isset($field["privileges"][$update ? "update" : "insert"]) || adminer()->fieldName($field) == "" || $field["generated"]) { + if ((!$update && !isset($field["privileges"]["insert"])) || adminer()->fieldName($field) == "") { unset($fields[$name]); } } @@ -65,9 +65,7 @@ if ($_POST && !$error && !isset($_GET["select"])) { } $row = null; -if ($_POST["save"]) { - $row = (array) $_POST["fields"]; -} elseif ($where) { +if ($where) { $select = array(); foreach ($fields as $name => $field) { if (isset($field["privileges"]["select"])) { @@ -113,4 +111,8 @@ if (!support("table") && !$fields) { // used by Mongo and SimpleDB } } +if ($_POST["save"]) { + $row = (array) $_POST["fields"] + ($row ? $row : array()); +} + edit_form($TABLE, $fields, $row, $update, $error); diff --git a/adminer/include/html.inc.php b/adminer/include/html.inc.php index 496cfd9e..e9d51bff 100644 --- a/adminer/include/html.inc.php +++ b/adminer/include/html.inc.php @@ -232,8 +232,7 @@ function input(array $field, $value, ?string $function, ?bool $autofocus = false $field["type"] = "enum"; $field["length"] = $enums; } - $disabled = stripos($field["default"], "GENERATED ALWAYS AS ") === 0 ? " disabled" : ""; - $attrs = " name='fields[$name]" . ($field["type"] == "enum" || $field["type"] == "set" ? "[]" : "") . "'$disabled" . ($autofocus ? " autofocus" : ""); + $attrs = " name='fields[$name]" . ($field["type"] == "enum" || $field["type"] == "set" ? "[]" : "") . "'" . ($autofocus ? " autofocus" : ""); echo driver()->unconvertFunction($field) . " "; $table = $_GET["edit"] ?: $_GET["select"]; if ($field["type"] == "enum") { @@ -241,7 +240,7 @@ function input(array $field, $value, ?string $function, ?bool $autofocus = false } else { $has_function = (in_array($function, $functions) || isset($functions[$function])); echo (count($functions) > 1 - ? "" + ? "" . on_help("event.target.value.replace(/^SQL\$/, '')", 1) . script("qsl('select').onchange = functionChange;", "") : h(reset($functions)) @@ -304,12 +303,12 @@ function input(array $field, $value, ?string $function, ?bool $autofocus = false * @return mixed false to leave the original value */ function process_input(array $field) { - if (stripos($field["default"], "GENERATED ALWAYS AS ") === 0) { - return; - } $idf = bracket_escape($field["field"]); $function = idx($_POST["function"], $idf); $value = idx($_POST["fields"], $idf); + if ($value === null) { + return false; + } if ($field["type"] == "enum" || driver()->enumLength($field)) { $value = idx($value, 0); if ($value == "orig" || !$value) { @@ -427,30 +426,34 @@ function edit_form(string $table, array $fields, $row, ?bool $update, string $er if (!$_POST["save"] && is_string($value)) { $value = adminer()->editVal($value, $field); } - $function = ($_POST["save"] - ? idx($_POST["function"], $name, "") - : ($update && preg_match('~^CURRENT_TIMESTAMP~i', $field["on_update"]) - ? "now" - : ($value === false ? null : ($value !== null ? '' : 'NULL')) - ) - ); - if (!$_POST && !$update && $value == $field["default"] && preg_match('~^[\w.]+\(~', $value)) { - $function = "SQL"; - } - if (preg_match("~time~", $field["type"]) && preg_match('~^CURRENT_TIMESTAMP~i', $value)) { - $value = ""; - $function = "now"; - } - if ($field["type"] == "uuid" && $value == "uuid()") { - $value = ""; - $function = "uuid"; - } - if ($autofocus !== false) { - $autofocus = ($field["auto_increment"] || $function == "now" || $function == "uuid" ? null : true); // null - don't autofocus this input but check the next one - } - input($field, $value, $function, $autofocus); - if ($autofocus) { - $autofocus = false; + if (($update && !isset($field["privileges"]["update"])) || $field["generated"]) { + echo "