Prepare for using edit form in select
This commit is contained in:
parent
052b019210
commit
9567e5cb1a
|
@ -125,75 +125,5 @@ if ($row === false) {
|
||||||
|
|
||||||
<div id="message"></div>
|
<div id="message"></div>
|
||||||
|
|
||||||
<form action="" method="post" enctype="multipart/form-data" id="form">
|
|
||||||
<?php
|
<?php
|
||||||
if (!$fields) {
|
edit_form($fields, $row, $update);
|
||||||
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>
|
|
||||||
|
|
|
@ -1247,3 +1247,89 @@ function lzw_decompress($binary) {
|
||||||
function on_help($command, $side = 0) {
|
function on_help($command, $side = 0) {
|
||||||
return " onmouseover='helpMouseover(this, event, " . h($command) . ", $side);' onmouseout='helpMouseout(this, event);'";
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue