]> git.joonet.de Git - adminer.git/commitdiff
Prepare for using edit form in select
authorJakub Vrana <jakub@vrana.cz>
Tue, 25 Feb 2014 07:44:24 +0000 (23:44 -0800)
committerJakub Vrana <jakub@vrana.cz>
Tue, 25 Feb 2014 07:44:24 +0000 (23:44 -0800)
adminer/edit.inc.php
adminer/include/functions.inc.php

index b5da115e533ab2a918dddfd5545d69bf3ad7a161..0a56f9626085a3a88509adc7096cfcca7cd19461 100644 (file)
@@ -125,75 +125,5 @@ if ($row === false) {
 
 <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);
index 9d46b2d66a7ed21a9ce039abc6da6937e4314da2..cbb6294825b4f671987e81276ad411499366c30f 100644 (file)
@@ -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
+}