]> git.joonet.de Git - adminer.git/commitdiff
Order of columns in table
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 7 May 2008 11:22:08 +0000 (11:22 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 7 May 2008 11:22:08 +0000 (11:22 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@397 7c3ca157-0c34-0410-bff1-cbf682f78f5c

create.inc.php
editing.inc.php
procedure.inc.php
todo.txt

index 005bec3667381105d2d48a4ae9cc93d5b650a721..73f378cac6ed88e2a2c16f4091314cc5160e6f0d 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"]) {
+if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] && !$_POST["down"]) {
        if ($_POST["drop"]) {
                if ($mysql->query("DROP TABLE " . idf_escape($_GET["create"]))) {
                        redirect(substr($SELF, 0, -1), lang('Table has been dropped.'));
@@ -29,7 +29,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"]) {
                                        . ($field["null"] ? " NULL" : " NOT NULL") // NULL for timestamp
                                        . ($key == $_POST["auto_increment_col"] ? " AUTO_INCREMENT$auto_increment_index" : "")
                                        . " COMMENT '" . $mysql->escape_string($field["comment"]) . "'"
-                                       . (strlen($_GET["create"]) && !strlen($field["orig"]) ? $after : "")
+                                       . (strlen($_GET["create"]) ? " $after" : "")
                                ;
                                $after = "AFTER " . idf_escape($field["field"]);
                        } elseif (strlen($field["orig"])) {
@@ -67,11 +67,7 @@ $result->free();
 
 if ($_POST) {
        $row = $_POST;
-       ksort($row["fields"]);
-       $row["fields"] = array_values($row["fields"]);
-       if ($_POST["add"]) {
-               array_splice($row["fields"], key($_POST["add"]), 0, array(array()));
-       }
+       process_fields($row["fields"]);
        if ($row["auto_increment_col"]) {
                $row["fields"][$row["auto_increment_col"] - 1]["auto_increment"] = true;
        }
index 904212b2fdeb4e66a4b44b6d0daf90f51a315b87..e7f4d048975e0bfea2ee129451415ec3826b7e57 100644 (file)
@@ -94,7 +94,7 @@ function edit_fields($fields, $collations, $type = "TABLE") {
 <td><input type="radio" name="auto_increment_col" value="" /><?php echo lang('Auto Increment'); ?></td>
 <td><?php echo lang('Comment'); ?></td>
 <?php } ?>
-<td><input type="submit" name="add[0]" value="<?php echo lang('Add next'); ?>" /></td>
+<td><input type="submit" name="add[0]" value="+" title="<?php echo lang('Add next'); ?>" /></td>
 </tr></thead>
 <?php
        $column_comments = false;
@@ -111,7 +111,7 @@ function edit_fields($fields, $collations, $type = "TABLE") {
 <td><input type="radio" name="auto_increment_col" value="<?php echo $i; ?>"<?php if ($field["auto_increment"]) { ?> checked="checked"<?php } ?> /></td>
 <td><input name="fields[<?php echo $i; ?>][comment]" value="<?php echo htmlspecialchars($field["comment"]); ?>" maxlength="255" /></td>
 <?php } ?>
-<td><input type="submit" name="add[<?php echo $i; ?>]" value="<?php echo lang('Add next'); ?>" onclick="return !add_row(this);" /> <input type="submit" name="drop_col[<?php echo $i; ?>]" value="<?php echo lang('Remove'); ?>" onclick="return !remove_row(this);" /></td>
+<td style="white-space: nowrap;"><input type="submit" name="add[<?php echo $i; ?>]" value="+" title="<?php echo lang('Add next'); ?>" onclick="return !add_row(this);" /> <input type="submit" name="drop_col[<?php echo $i; ?>]" value="-" title="<?php echo lang('Remove'); ?>" onclick="return !remove_row(this);" /> <input type="submit" name="up[<?php echo $i; ?>]" value="↑" title="<?php echo lang('Move up'); ?>" /> <input type="submit" name="down[<?php echo $i; ?>]" value="↓" title="<?php echo lang('Move down'); ?>" /></td>
 </tr>
 <?php
                if (strlen($field["comment"])) {
@@ -121,6 +121,43 @@ function edit_fields($fields, $collations, $type = "TABLE") {
        return $column_comments;
 }
 
+function process_fields(&$fields) {
+       ksort($fields);
+       $offset = 0;
+       if ($_POST["up"]) {
+               $last = 0;
+               foreach ($fields as $key => $field) {
+                       if (key($_POST["up"]) == $key) {
+                               unset($fields[$key]);
+                               array_splice($fields, $last, 0, array($field));
+                               break;
+                       }
+                       if (isset($field["field"])) {
+                               $last = $offset;
+                       }
+                       $offset++;
+               }
+       }
+       if ($_POST["down"]) {
+               $found = false;
+               foreach ($fields as $key => $field) {
+                       if (isset($field["field"]) && $found) {
+                               unset($fields[key($_POST["down"])]);
+                               array_splice($fields, $offset, 0, array($found));
+                               break;
+                       }
+                       if (key($_POST["down"]) == $key) {
+                               $found = $field;
+                       }
+                       $offset++;
+               }
+       }
+       $fields = array_values($fields);
+       if ($_POST["add"]) {
+               array_splice($fields, key($_POST["add"]), 0, array(array()));
+       }
+}
+
 function type_change($count) {
        ?>
 <script type="text/javascript">
index 82735ee44350feb700c96248ef01985b06865668..352fe6d8a5553bcf760a7a6aaad5c54119b9e98b 100644 (file)
@@ -2,7 +2,7 @@
 $routine = (isset($_GET["function"]) ? "FUNCTION" : "PROCEDURE");
 
 $dropped = false;
-if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"]) {
+if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] && !$_POST["down"]) {
        if (strlen($_GET["procedure"]) && ($_POST["dropped"] || $mysql->query("DROP $routine " . idf_escape($_GET["procedure"])))) {
                if ($_POST["drop"]) {
                        redirect(substr($SELF, 0, -1), lang('Routine has been dropped.'));
@@ -35,11 +35,7 @@ $collations = get_vals("SHOW CHARACTER SET");
 if ($_POST) {
        $row = $_POST;
        $row["fields"] = (array) $row["fields"];
-       ksort($row["fields"]);
-       $row["fields"] = array_values($row["fields"]);
-       if ($_POST["add"]) {
-               array_splice($row["fields"], key($_POST["add"]), 0, array(array()));
-       }
+       process_fields($row["fields"]);
 } elseif (strlen($_GET["procedure"])) {
        $row = routine($_GET["procedure"], $routine);
        $row["name"] = $_GET["procedure"];
index db4ca651934478a6524d177dfdc0cfc5e0ae2e1b..c56f6447779030104cffc1fe14f85e9f70fb9194 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -1,6 +1,5 @@
 Edit of fields with foreign key as <select> (optional)
 Highlight found fields
-Order of columns in table
 MySQL 5 BIT data type
 Check MySQL server version
 Rename table to other database