Skip to content
Browse files

Prepare for using edit form in select

  • Loading branch information...
1 parent 052b019 commit 9567e5cb1a1abe30c9ec12086a73f73b6f77caac @vrana committed Feb 24, 2014
Showing with 87 additions and 71 deletions.
  1. +1 −71 adminer/edit.inc.php
  2. +86 −0 adminer/include/functions.inc.php
View
72 adminer/edit.inc.php
@@ -125,75 +125,5 @@
<div id="message"></div>
-<form action="" method="post" enctype="multipart/form-data" id="form">
<?php
-if (!$fields) {
- echo "<p class='error'>" . lang('You have no privileges to update this table.') . "\n";
-} else {
- echo "<table cellspacing='0' onkeydown='return editingKeydown(event);'>\n";
-
- foreach ($fields as $name => $field) {
- echo "<tr><th>" . $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 "<tr>"
- . "<th><input name='field_keys[]' onkeyup='keyupChange.call(this);' onchange='fieldChange(this);' value=''>" // needs empty value for keyupChange()
- . "<td class='function'>" . html_select("field_funs[]", $adminer->editFunctions(array("null" => isset($_GET["select"]))))
- . "<td><input name='field_vals[]'>"
- . "\n"
- ;
- }
-
- echo "</table>\n";
-}
-?>
-<p>
-<?php
-if ($fields) {
- echo "<input type='submit' value='" . lang('Save') . "'>\n";
- if (!isset($_GET["select"])) {
- echo "<input type='submit' name='insert' value='" . ($update
- ? lang('Save and continue edit') . "' onclick='return !ajaxForm(this.form, \"" . lang('Saving') . '...", this)'
- : lang('Save and insert next')
- ) . "' title='Ctrl+Shift+Enter'>\n";
- }
-}
-echo ($update ? "<input type='submit' name='delete' value='" . lang('Delete') . "'" . confirm() . ">\n"
- : ($_POST || !$fields ? "" : "<script type='text/javascript'>focus(document.getElementById('form').getElementsByTagName('td')[1].firstChild);</script>\n")
-);
-if (isset($_GET["select"])) {
- hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
-}
-?>
-<input type="hidden" name="referer" value="<?php echo h(isset($_POST["referer"]) ? $_POST["referer"] : $_SERVER["HTTP_REFERER"]); ?>">
-<input type="hidden" name="save" value="1">
-<input type="hidden" name="token" value="<?php echo $token; ?>">
-</form>
+edit_form($fields, $row, $update);
View
86 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;
+ ?>
+<form action="" method="post" enctype="multipart/form-data" id="form">
+<?php
+ if (!$fields) {
+ echo "<p class='error'>" . lang('You have no privileges to update this table.') . "\n";
+ } else {
+ echo "<table cellspacing='0' onkeydown='return editingKeydown(event);'>\n";
+
+ foreach ($fields as $name => $field) {
+ echo "<tr><th>" . $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 "<tr>"
+ . "<th><input name='field_keys[]' onkeyup='keyupChange.call(this);' onchange='fieldChange(this);' value=''>" // needs empty value for keyupChange()
+ . "<td class='function'>" . html_select("field_funs[]", $adminer->editFunctions(array("null" => isset($_GET["select"]))))
+ . "<td><input name='field_vals[]'>"
+ . "\n"
+ ;
+ }
+ echo "</table>\n";
+ }
+ echo "<p>\n";
+ if ($fields) {
+ echo "<input type='submit' value='" . lang('Save') . "'>\n";
+ if (!isset($_GET["select"])) {
+ echo "<input type='submit' name='insert' value='" . ($update
+ ? lang('Save and continue edit') . "' onclick='return !ajaxForm(this.form, \"" . lang('Saving') . '...", this)'
+ : lang('Save and insert next')
+ ) . "' title='Ctrl+Shift+Enter'>\n";
+ }
+ }
+ echo ($update ? "<input type='submit' name='delete' value='" . lang('Delete') . "'" . confirm() . ">\n"
+ : ($_POST || !$fields ? "" : "<script type='text/javascript'>focus(document.getElementById('form').getElementsByTagName('td')[1].firstChild);</script>\n")
+ );
+ if (isset($_GET["select"])) {
+ hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
+ }
+ ?>
+<input type="hidden" name="referer" value="<?php echo h(isset($_POST["referer"]) ? $_POST["referer"] : $_SERVER["HTTP_REFERER"]); ?>">
+<input type="hidden" name="save" value="1">
+<input type="hidden" name="token" value="<?php echo $token; ?>">
+</form>
+<?php
+}

0 comments on commit 9567e5c

Please sign in to comment.
Something went wrong with that request. Please try again.