]> git.joonet.de Git - adminer.git/commitdiff
Drop and re-create at once
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Sat, 4 Aug 2007 20:26:58 +0000 (20:26 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Sat, 4 Aug 2007 20:26:58 +0000 (20:26 +0000)
JavaScript for next field

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@301 7c3ca157-0c34-0410-bff1-cbf682f78f5c

foreign.inc.php

index 8094a2bea2c3f642683eae783f1e8d2c48467c7e..7fbfad8637627744148b907697cd1a748e827df4 100644 (file)
@@ -1,9 +1,10 @@
 <?php
 if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change-js"]) {
-       if (strlen($_GET["name"]) && $mysql->query("ALTER TABLE " . idf_escape($_GET["foreign"]) . " DROP FOREIGN KEY " . idf_escape($_GET["name"])) && $_POST["drop"]) {
-               redirect($SELF . "table=" . urlencode($_GET["foreign"]), lang('Foreign key has been dropped.'));
-       }
-       if (!$_POST["drop"]) {
+       if ($_POST["drop"]) {
+               if ($mysql->query("ALTER TABLE " . idf_escape($_GET["foreign"]) . " DROP FOREIGN KEY " . idf_escape($_GET["name"]))) {
+                       redirect($SELF . "table=" . urlencode($_GET["foreign"]), lang('Foreign key has been dropped.'));
+               }
+       } else {
                $source = array_filter($_POST["source"], 'strlen');
                ksort($source);
                $target = array();
@@ -11,14 +12,13 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change-
                        $target[$key] = $_POST["target"][$key];
                }
                if ($mysql->query("
-                       ALTER TABLE " . idf_escape($_GET["foreign"]) . " ADD FOREIGN KEY
-                       " . (strlen($_GET["name"]) ? idf_escape($_GET["name"]) : "") . "
-                       (" . implode(", ", array_map('idf_escape', $source)) . ")
-                       REFERENCES " . idf_escape($_POST["table"]) . "
-                       (" . implode(", ", array_map('idf_escape', $target)) . ")
-                       " . (in_array($_POST["on_delete"], $on_actions) ? "ON DELETE $_POST[on_delete]" : "") . "
-                       " . (in_array($_POST["on_update"], $on_actions) ? "ON UPDATE $_POST[on_update]" : "") . "
-               ")) {
+                       ALTER TABLE " . idf_escape($_GET["foreign"])
+                       . (strlen($_GET["name"]) ? " DROP FOREIGN KEY " . idf_escape($_GET["name"]) . "," : "") . "
+                       ADD FOREIGN KEY (" . implode(", ", array_map('idf_escape', $source)) . ")
+                       REFERENCES " . idf_escape($_POST["table"]) . " (" . implode(", ", array_map('idf_escape', $target)) . ")"
+                       . (in_array($_POST["on_delete"], $on_actions) ? " ON DELETE $_POST[on_delete]" : "")
+                       . (in_array($_POST["on_update"], $on_actions) ? " ON UPDATE $_POST[on_update]" : "")
+               )) {
                        redirect($SELF . "table=" . urlencode($_GET["foreign"]), (strlen($_GET["name"]) ? lang('Foreign key has been altered.') : lang('Foreign key has been created.')));
                }
        }
@@ -49,6 +49,7 @@ if ($_POST) {
 } elseif (strlen($_GET["name"])) {
        $foreign_keys = foreign_keys($_GET["foreign"]);
        $row = $foreign_keys[$_GET["name"]];
+       $row["source"][] = "";
 } else {
        $row = array("table" => $_GET["foreign"], "source" => array(""));
 }
@@ -56,6 +57,19 @@ if ($_POST) {
 $source = get_vals("SHOW COLUMNS FROM " . idf_escape($_GET["foreign"])); //! no text and blob
 $target = ($_GET["foreign"] === $row["table"] ? $source : get_vals("SHOW COLUMNS FROM " . idf_escape($row["table"])));
 ?>
+
+<script type="text/javascript">
+function add_row(field) {
+       var row = field.parentNode.parentNode.cloneNode(true);
+       var selects = row.getElementsByTagName('select');
+       for (var i=0; i < selects.length; i++) {
+               selects[i].name = selects[i].name.replace(/\]/, '1$&');
+       }
+       field.parentNode.parentNode.parentNode.appendChild(row);
+       field.onchange = function () { };
+}
+</script>
+
 <form action="" method="post">
 <p>
 <?php echo lang('Target table'); ?>:
@@ -66,11 +80,13 @@ $target = ($_GET["foreign"] === $row["table"] ? $source : get_vals("SHOW COLUMNS
 <table border="0" cellspacing="0" cellpadding="2">
 <thead><tr><th><?php echo lang('Source'); ?></th><th><?php echo lang('Target'); ?></th></tr></thead>
 <?php
+$j = 0;
 foreach ($row["source"] as $key => $val) {
        echo "<tr>";
-       echo "<td><select name='source[" . intval($key) . "]'><option></option>" . optionlist($source, $val) . "</select></td>";
+       echo "<td><select name='source[" . intval($key) . "]'" . ($j == count($row["source"]) - 1 ? " onchange='add_row(this);'" : "") . "><option></option>" . optionlist($source, $val) . "</select></td>";
        echo "<td><select name='target[" . intval($key) . "]'>" . optionlist($target, $row["target"][$key]) . "</select></td>";
        echo "</tr>\n";
+       $j++;
 }
 ?>
 </table>
@@ -81,7 +97,7 @@ foreach ($row["source"] as $key => $val) {
 <p>
 <input type="hidden" name="token" value="<?php echo $token; ?>" />
 <input type="submit" value="<?php echo lang('Save'); ?>" />
-<input type="submit" name="add" value="<?php echo lang('Add column'); ?>" />
 <?php if (strlen($_GET["name"])) { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>" onclick="return confirm('<?php echo lang('Are you sure?'); ?>');" /><?php } ?>
 </p>
+<noscript><p><input type="submit" name="add" value="<?php echo lang('Add column'); ?>" /></p></noscript>
 </form>