1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-09 16:17:48 +02:00

Allow redefining editInput for enum (bug #3048711)

This commit is contained in:
Jakub Vrana
2010-10-23 00:28:48 +02:00
parent 677687fc1a
commit fe0690851f
3 changed files with 12 additions and 7 deletions

View File

@@ -430,8 +430,10 @@ document.getElementById('username').focus();
*/ */
function editInput($table, $field, $attrs, $value) { function editInput($table, $field, $attrs, $value) {
if ($field["type"] == "enum") { if ($field["type"] == "enum") {
return ($field["null"] ? "<label><input type='radio'$attrs value=''" . (isset($value) || isset($_GET["select"]) ? "" : " checked") . "><i>NULL</i></label> " : "") return (isset($_GET["select"]) ? "<label><input type='radio'$attrs value='-1' checked><i>" . lang('original') . "</i></label> " : "")
. ($field["null"] ? "<label><input type='radio'$attrs value=''" . (isset($value) || isset($_GET["select"]) ? "" : " checked") . "><i>NULL</i></label> " : "")
. "<label><input type='radio'$attrs value='0'" . ($value === 0 ? " checked" : "") . "><i>" . lang('empty') . "</i></label>" . "<label><input type='radio'$attrs value='0'" . ($value === 0 ? " checked" : "") . "><i>" . lang('empty') . "</i></label>"
. enum_input("radio", $attrs, $field, $value)
; ;
} }
return ""; return "";

View File

@@ -568,11 +568,13 @@ function column_foreign_keys($table) {
*/ */
function enum_input($type, $attrs, $field, $value) { function enum_input($type, $attrs, $field, $value) {
preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches); preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
$return = "";
foreach ($matches[1] as $i => $val) { foreach ($matches[1] as $i => $val) {
$val = stripcslashes(str_replace("''", "'", $val)); $val = stripcslashes(str_replace("''", "'", $val));
$checked = (is_int($value) ? $value == $i+1 : (is_array($value) ? in_array($i+1, $value) : $value === $val)); $checked = (is_int($value) ? $value == $i+1 : (is_array($value) ? in_array($i+1, $value) : $value === $val));
echo " <label><input type='$type'$attrs value='" . ($i+1) . "'" . ($checked ? ' checked' : '') . '>' . h($val) . '</label>'; $return .= " <label><input type='$type'$attrs value='" . ($i+1) . "'" . ($checked ? ' checked' : '') . '>' . h($val) . '</label>';
} }
return $return;
} }
/** Print edit input field /** Print edit input field
@@ -588,9 +590,7 @@ function input($field, $value, $function) {
$functions = (isset($_GET["select"]) ? array("orig" => lang('original')) : array()) + $adminer->editFunctions($field); $functions = (isset($_GET["select"]) ? array("orig" => lang('original')) : array()) + $adminer->editFunctions($field);
$attrs = " name='fields[$name]'"; $attrs = " name='fields[$name]'";
if ($field["type"] == "enum") { if ($field["type"] == "enum") {
echo nbsp($functions[""]) . "<td>" . ($functions["orig"] ? "<label><input type='radio'$attrs value='-1' checked><i>$functions[orig]</i></label> " : ""); echo nbsp($functions[""]) . "<td>" . $adminer->editInput($_GET["edit"], $field, $attrs, $value);
echo $adminer->editInput($_GET["edit"], $field, $attrs, $value);
enum_input("radio", $attrs, $field, $value);
} else { } else {
$first = 0; $first = 0;
foreach ($functions as $key => $val) { foreach ($functions as $key => $val) {

View File

@@ -202,7 +202,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
$key = $keys[$name]; $key = $keys[$name];
$i--; $i--;
echo "<div>" . h($desc) . "<input type='hidden' name='where[$i][col]' value='" . h($name) . "'>:"; echo "<div>" . h($desc) . "<input type='hidden' name='where[$i][col]' value='" . h($name) . "'>:";
enum_input("checkbox", " name='where[$i][val][]'", $field, (array) $where[$key]["val"]); //! impossible to search for NULL echo enum_input("checkbox", " name='where[$i][val][]'", $field, (array) $where[$key]["val"]); //! impossible to search for NULL
echo "</div>\n"; echo "</div>\n";
unset($columns[$name]); unset($columns[$name]);
} }
@@ -392,7 +392,10 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
function editInput($table, $field, $attrs, $value) { function editInput($table, $field, $attrs, $value) {
if ($field["type"] == "enum") { if ($field["type"] == "enum") {
return ($field["null"] ? "<input type='radio'$attrs value=''" . ($value || isset($_GET["select"]) ? "" : " checked") . ">" : ""); return (isset($_GET["select"]) ? "<label><input type='radio'$attrs value='-1' checked><i>" . lang('original') . "</i></label> " : "")
. ($field["null"] ? "<label><input type='radio'$attrs value=''" . ($value || isset($_GET["select"]) ? "" : " checked") . "><i>" . lang('empty') . "</i></label>" : "")
. enum_input("radio", $attrs, $field, $value)
;
} }
$options = $this->_foreignKeyOptions($table, $field["field"]); $options = $this->_foreignKeyOptions($table, $field["field"]);
if ($options) { if ($options) {