Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Order of columns in table

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@397 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
commit fd8948ffa0dac6aeca652ae16891f673bff5b405 1 parent 478e9c8
jakubvrana authored
Showing with 44 additions and 16 deletions.
  1. +3 −7 create.inc.php
  2. +39 −2 editing.inc.php
  3. +2 −6 procedure.inc.php
  4. +0 −1  todo.txt
View
10 create.inc.php
@@ -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 @@
. ($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 @@
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;
}
View
41 editing.inc.php
@@ -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">
View
8 procedure.inc.php
@@ -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 @@
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"];
View
1  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
Please sign in to comment.
Something went wrong with that request. Please try again.