From 9567e5cb1a1abe30c9ec12086a73f73b6f77caac Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Mon, 24 Feb 2014 23:44:24 -0800 Subject: [PATCH] Prepare for using edit form in select --- adminer/edit.inc.php | 72 +------------------------- adminer/include/functions.inc.php | 86 +++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 71 deletions(-) diff --git a/adminer/edit.inc.php b/adminer/edit.inc.php index b5da115e..0a56f962 100644 --- a/adminer/edit.inc.php +++ b/adminer/edit.inc.php @@ -125,75 +125,5 @@ if ($row === false) {
-
" . lang('You have no privileges to update this table.') . "\n"; -} else { - echo "\n"; - - foreach ($fields as $name => $field) { - echo "" - . "
" . $adminer->fieldName($field); - $default = $_GET["set"][bracket_escape($name)]; - if ($default === null) { - $default = $field["default"]; - if ($field["type"] == "bit" && preg_match("~^b'([01]*)'\$~", $default, $regs)) { - $default = $regs[1]; - } - } - $value = ($row !== null - ? ($row[$name] != "" && $jush == "sql" && preg_match("~enum|set~", $field["type"]) - ? (is_array($row[$name]) ? array_sum($row[$name]) : +$row[$name]) - : $row[$name] - ) - : (!$update && $field["auto_increment"] - ? "" - : (isset($_GET["select"]) ? false : $default) - ) - ); - if (!$_POST["save"] && is_string($value)) { - $value = $adminer->editVal($value, $field); - } - $function = ($_POST["save"] ? (string) $_POST["function"][$name] : ($update && $field["on_update"] == "CURRENT_TIMESTAMP" ? "now" : ($value === false ? null : ($value !== null ? '' : 'NULL')))); - if (preg_match("~time~", $field["type"]) && $value == "CURRENT_TIMESTAMP") { - $value = ""; - $function = "now"; - } - input($field, $value, $function); - echo "\n"; - } - - if (!support("table")) { - echo "
" // needs empty value for keyupChange() - . "" . html_select("field_funs[]", $adminer->editFunctions(array("null" => isset($_GET["select"])))) - . "" - . "\n" - ; - } - - echo "
\n"; -} -?> -

-\n"; - if (!isset($_GET["select"])) { - echo "\n"; - } -} -echo ($update ? "\n" - : ($_POST || !$fields ? "" : "\n") -); -if (isset($_GET["select"])) { - hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"])); -} -?> -"> - - -

+edit_form($fields, $row, $update); diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 9d46b2d6..cbb62948 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -1247,3 +1247,89 @@ function lzw_decompress($binary) { function on_help($command, $side = 0) { return " onmouseover='helpMouseover(this, event, " . h($command) . ", $side);' onmouseout='helpMouseout(this, event);'"; } + +/** Print edit data form +* @param array +* @param mixed +* @param bool +* @return null +*/ +function edit_form($fields, $row, $update) { + global $adminer, $jush, $token; + ?> +
+" . lang('You have no privileges to update this table.') . "\n"; + } else { + echo "\n"; + + foreach ($fields as $name => $field) { + echo "" + . "
" . $adminer->fieldName($field); + $default = $_GET["set"][bracket_escape($name)]; + if ($default === null) { + $default = $field["default"]; + if ($field["type"] == "bit" && preg_match("~^b'([01]*)'\$~", $default, $regs)) { + $default = $regs[1]; + } + } + $value = ($row !== null + ? ($row[$name] != "" && $jush == "sql" && preg_match("~enum|set~", $field["type"]) + ? (is_array($row[$name]) ? array_sum($row[$name]) : +$row[$name]) + : $row[$name] + ) + : (!$update && $field["auto_increment"] + ? "" + : (isset($_GET["select"]) ? false : $default) + ) + ); + if (!$_POST["save"] && is_string($value)) { + $value = $adminer->editVal($value, $field); + } + $function = ($_POST["save"] + ? (string) $_POST["function"][$name] + : ($update && $field["on_update"] == "CURRENT_TIMESTAMP" + ? "now" + : ($value === false ? null : ($value !== null ? '' : 'NULL')) + ) + ); + if (preg_match("~time~", $field["type"]) && $value == "CURRENT_TIMESTAMP") { + $value = ""; + $function = "now"; + } + input($field, $value, $function); + echo "\n"; + } + if (!support("table")) { + echo "
" // needs empty value for keyupChange() + . "" . html_select("field_funs[]", $adminer->editFunctions(array("null" => isset($_GET["select"])))) + . "" + . "\n" + ; + } + echo "
\n"; + } + echo "

\n"; + if ($fields) { + echo "\n"; + if (!isset($_GET["select"])) { + echo "\n"; + } + } + echo ($update ? "\n" + : ($_POST || !$fields ? "" : "\n") + ); + if (isset($_GET["select"])) { + hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"])); + } + ?> +"> + + +

+