]> git.joonet.de Git - adminer.git/commitdiff
Respect defaults and comments checkbox after post (bug #3311791)
authorJakub Vrana <jakub@vrana.cz>
Tue, 7 Jun 2011 13:00:18 +0000 (15:00 +0200)
committerJakub Vrana <jakub@vrana.cz>
Tue, 7 Jun 2011 13:00:18 +0000 (15:00 +0200)
adminer/create.inc.php
adminer/include/editing.inc.php
adminer/include/functions.inc.php

index acef23f7b674431879211d4ed969b8542f40aca5..68ef8746ad9f9d749bebe48b4acaa9b84c637d7f 100644 (file)
@@ -157,12 +157,23 @@ foreach ($engines as $engine) {
  <?php echo ($collations && !ereg("sqlite|mssql", $jush) ? html_select("Collation", array("" => "(" . lang('collation') . ")") + $collations, $row["Collation"]) : ""); ?>
  <input type="submit" value="<?php echo lang('Save'); ?>">
 <table cellspacing="0" id="edit-fields" class="nowrap">
-<?php $comments = edit_fields($row["fields"], $collations, "TABLE", $suhosin, $foreign_keys, $row["Comment"] != ""); ?>
+<?php
+$comments = ($_POST ? $_POST["comments"] : $row["Comment"] != "");
+if (!$_POST && !$comments) {
+       foreach ($row["fields"] as $field) {
+               if ($field["comment"] != "") {
+                       $comments = true;
+                       break;
+               }
+       }
+}
+edit_fields($row["fields"], $collations, "TABLE", $suhosin, $foreign_keys, $comments);
+?>
 </table>
 <p>
 <?php echo lang('Auto Increment'); ?>: <input name="Auto_increment" size="6" value="<?php echo h($row["Auto_increment"]); ?>">
-<label class="jsonly"><input type="checkbox" onclick="columnShow(this.checked, 5);"><?php echo lang('Default values'); ?></label>
-<?php echo (support("comment") ? checkbox("", "", $comments, lang('Comment'), "columnShow(this.checked, 6); toggle('Comment'); if (this.checked) this.form['Comment'].focus();") . ' <input id="Comment" name="Comment" value="' . h($row["Comment"]) . '" maxlength="60"' . ($comments ? '' : ' class="hidden"') . '>' : ''); ?>
+<label class="jsonly"><input type="checkbox" name="defaults" value="1"<?php echo ($_POST["defaults"] ? " checked" : ""); ?> onclick="columnShow(this.checked, 5);"><?php echo lang('Default values'); ?></label>
+<?php echo (support("comment") ? checkbox("comments", 1, $comments, lang('Comment'), "columnShow(this.checked, 6); toggle('Comment'); if (this.checked) this.form['Comment'].focus();", true) . ' <input id="Comment" name="Comment" value="' . h($row["Comment"]) . '" maxlength="60"' . ($comments ? '' : ' class="hidden"') . '>' : ''); ?>
 <p>
 <input type="submit" value="<?php echo lang('Save'); ?>">
 <?php if ($_GET["create"] != "") { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>"<?php echo confirm(); ?>><?php } ?>
index bb603b69afb2fcb2ed25b580fd96348634cbbc22..b0b1b5e28205511ac235b641c3539971c4fe759d 100644 (file)
@@ -206,16 +206,11 @@ function type_class($type) {
 * @param string TABLE or PROCEDURE
 * @param int number of fields allowed by Suhosin
 * @param array returned by referencable_primary()
-* @return bool column comments used
+* @param bool display comments column
+* @return null
 */
 function edit_fields($fields, $collations, $type = "TABLE", $allowed = 0, $foreign_keys = array(), $comments = false) {
        global $inout;
-       foreach ($fields as $field) {
-               if ($field["comment"] != "") {
-                       $comments = true;
-                       break;
-               }
-       }
        ?>
 <thead><tr class="wrap">
 <?php if ($type == "PROCEDURE") { ?><td>&nbsp;<?php } ?>
@@ -226,7 +221,7 @@ function edit_fields($fields, $collations, $type = "TABLE", $allowed = 0, $forei
 <?php if ($type == "TABLE") { ?>
 <td>NULL
 <td><input type="radio" name="auto_increment_col" value=""><acronym title="<?php echo lang('Auto Increment'); ?>">AI</acronym>
-<td class="hidden"><?php echo lang('Default values'); ?>
+<td<?php echo ($_POST["defaults"] ? "" : " class='hidden'"); ?>><?php echo lang('Default values'); ?>
 <?php echo (support("comment") ? "<td" . ($comments ? "" : " class='hidden'") . ">" . lang('Comment') : ""); ?>
 <?php } ?>
 <td><?php echo "<input type='image' name='add[" . (support("move_col") ? 0 : count($fields)) . "]' src='../adminer/static/plus.gif' alt='+' title='" . lang('Add next') . "'>"; ?><script type="text/javascript">row_count = <?php echo count($fields); ?>;</script>
@@ -245,7 +240,7 @@ function edit_fields($fields, $collations, $type = "TABLE", $allowed = 0, $forei
 <?php if ($type == "TABLE") { ?>
 <td><?php echo checkbox("fields[$i][null]", 1, $field["null"]); ?>
 <td><input type="radio" name="auto_increment_col" value="<?php echo $i; ?>"<?php if ($field["auto_increment"]) { ?> checked<?php } ?> onclick="var field = this.form['fields[' + this.value + '][field]']; if (!field.value) { field.value = 'id'; field.onchange(); }">
-<td class="hidden"><?php echo checkbox("fields[$i][has_default]", 1, $field["has_default"]); ?><input name="fields[<?php echo $i; ?>][default]" value="<?php echo h($field["default"]); ?>" onchange="this.previousSibling.checked = true;">
+<td<?php echo ($_POST["defaults"] ? "" : " class='hidden'"); ?>><?php echo checkbox("fields[$i][has_default]", 1, $field["has_default"]); ?><input name="fields[<?php echo $i; ?>][default]" value="<?php echo h($field["default"]); ?>" onchange="this.previousSibling.checked = true;">
 <?php echo (support("comment") ? "<td" . ($comments ? "" : " class='hidden'") . "><input name='fields[$i][comment]' value='" . h($field["comment"]) . "' maxlength='255'>" : ""); ?>
 <?php } ?>
 <?php
@@ -258,7 +253,6 @@ function edit_fields($fields, $collations, $type = "TABLE", $allowed = 0, $forei
                echo ($orig == "" || support("drop_col") ? "<input type='image' name='drop_col[$i]' src='../adminer/static/cross.gif' alt='x' title='" . lang('Remove') . "' onclick='return !editingRemoveRow(this);'>" : "");
                echo "\n";
        }
-       return $comments;
 }
 
 /** Move fields up and down or add field
index ea9b885c2c33932c88f672cb770ca09e4259dfd3..1c6f3d805d75d01049cff777adb29145fc796cd2 100644 (file)
@@ -86,12 +86,13 @@ function nl_br($string) {
 * @param bool
 * @param string
 * @param string
+* @param bool
 * @return string
 */
-function checkbox($name, $value, $checked, $label = "", $onclick = "") {
+function checkbox($name, $value, $checked, $label = "", $onclick = "", $jsonly = false) {
        static $id = 0;
        $id++;
-       $return = "<input type='checkbox'" . ($name ? " name='$name' value='" . h($value) . "'" : " class='jsonly'") . ($checked ? " checked" : "") . ($onclick ? " onclick=\"$onclick\"" : "") . " id='checkbox-$id'>";
+       $return = "<input type='checkbox' name='$name' value='" . h($value) . "'" . ($checked ? " checked" : "") . ($onclick ? " onclick=\"$onclick\"" : "") . ($jsonly ? " class='jsonly'" : "") . " id='checkbox-$id'>";
        return ($label != "" ? "<label for='checkbox-$id'>$return" . h($label) . "</label>" : $return);
 }