]> git.joonet.de Git - adminer.git/commitdiff
Separate JavaScript
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 29 May 2009 16:14:54 +0000 (16:14 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 29 May 2009 16:14:54 +0000 (16:14 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@618 7c3ca157-0c34-0410-bff1-cbf682f78f5c

15 files changed:
_compile.php
changes.txt
connect.inc.php
create.inc.php
design.inc.php
dump.inc.php
editing.inc.php
foreign.inc.php
functions.js [new file with mode: 0644]
index.php
indexes.inc.php
procedure.inc.php
schema.inc.php
select.inc.php
todo.txt

index a408abdf6aaa3f6a514567fa3f7d65a1f8c4718a..b60686893e4d7f6e06e592259f9dc217090d9665 100644 (file)
@@ -170,7 +170,7 @@ if ($_COOKIE["lang"]) {
        $file = preg_replace_callback("~lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])~s", 'lang_ids', $file);
 }
 $replace = 'preg_replace("~\\\\\\\\?.*~", "", $_SERVER["REQUEST_URI"]) . "?file=\\0&amp;version=' . $VERSION;
-$file = preg_replace('~default\\.css|favicon\\.ico|(up|down|plus|minus)\\.gif~', '<?php echo ' . $replace . '"; ?>', $file);
+$file = preg_replace('~default\\.css|functions\\.js|favicon\\.ico|(up|down|plus|minus)\\.gif~', '<?php echo ' . $replace . '"; ?>', $file);
 $file = preg_replace('~arrow\\.gif~', '" . ' . $replace, $file);
 $file = str_replace('error_reporting(E_ALL & ~E_NOTICE);', 'error_reporting(E_ALL & ~E_NOTICE);
 if (isset($_GET["file"])) {
@@ -181,6 +181,9 @@ if (isset($_GET["file"])) {
        } elseif ($_GET["file"] == "default.css") {
                header("Content-Type: text/css");
                ?>' . preg_replace('~\\s*([:;{},])\\s*~', '\\1', file_get_contents("default.css")) . '<?php
+       } elseif ($_GET["file"] == "functions.js") {
+               header("Content-Type: text/javascript");
+               ?>' . file_get_contents("functions.js") . '<?php
        } else {
                header("Content-Type: image/gif");
                switch ($_GET["file"]) {
index f85dc28fd7f1e73a2a2d83d58d648ccbcb463459..257ea30356c775642105d4bf66a50f267e849dd4 100644 (file)
@@ -2,6 +2,7 @@ phpMinAdmin 1.11.0:
 Connection through socket by server :/path/to/socket
 Display execution time in SQL query
 Version checker
+Separate JavaScript functions
 
 phpMinAdmin 1.10.1:
 Highlight odd and hover rows
index 767796f6685351b3a82db76df9093bb8a9d2e5e7..ca5d92eec8f3f037b6cb5f02ab464ed3dfdac2e2 100644 (file)
@@ -17,10 +17,7 @@ if (!(strlen($_GET["db"]) ? $dbh->select_db($_GET["db"]) : isset($_GET["sql"]) |
                        ?>
 <script type="text/javascript">
 onload = function () {
-       document.cookie = 'phpMinAdmin_version=0';
-       var script = document.createElement('script');
-       script.src = 'http://phpminadmin.sourceforge.net/version.php?version=<?php echo $VERSION; ?>';
-       document.body.appendChild(script);
+       check_version('<?php echo $VERSION; ?>');
 };
 </script>
 <?php
index 2718e9e771e8e1c7c6ddaee0feaee3f4c5651d0e..8d4f566f440a914d0b8749604cb8f2e34dd730bd 100644 (file)
@@ -122,22 +122,14 @@ if ($suhosin && count($row["fields"]) > $suhosin) {
 <select name="Collation"><option value="">(<?php echo lang('collation'); ?>)</option><?php echo optionlist($collations, $row["Collation"]); ?></select>
 <input type="submit" value="<?php echo lang('Save'); ?>" />
 </p>
-<table cellspacing="0">
-<?php $column_comments = edit_fields($row["fields"], $collations); ?>
+<table cellspacing="0" id="edit-fields">
+<?php $column_comments = edit_fields($row["fields"], $collations, "TABLE", $suhosin); ?>
 </table>
-<?php echo type_change(count($row["fields"]), $suhosin); ?>
 <p>
 <?php echo lang('Auto Increment'); ?>: <input name="Auto_increment" size="4" value="<?php echo intval($row["Auto_increment"]); ?>" />
 <?php echo lang('Comment'); ?>: <input name="Comment" value="<?php echo htmlspecialchars($row["Comment"]); ?>" maxlength="60" />
 <script type="text/javascript">// <![CDATA[
 document.write('<label><input type="checkbox"<?php if ($column_comments) { ?> checked="checked"<?php } ?> onclick="column_comments_click(this.checked);" /><?php echo lang('Show column comments'); ?></label>');
-function column_comments_click(checked) {
-       var trs = document.getElementsByTagName('tr');
-       for (var i=0; i < trs.length; i++) {
-               trs[i].getElementsByTagName('td')[5].style.display = (checked ? '' : 'none');
-       }
-}
-<?php if (!$column_comments) { ?>column_comments_click(false);<?php } ?>
 // ]]></script>
 </p>
 <p>
@@ -151,7 +143,7 @@ if ($dbh->server_info >= 5.1) {
        ?>
 <fieldset><legend><?php echo lang('Partition by'); ?></legend>
 <p>
-<select name="partition_by" onchange="var partition_table = /RANGE|LIST/.test(this.options[this.selectedIndex].text); this.form['partitions'].className = (partition_table || !this.selectedIndex ? 'hidden' : ''); document.getElementById('partition-table').className = (partition_table ? '' : 'hidden');"><option></option><?php echo optionlist($partition_by, $row["partition_by"]); ?></select>
+<select name="partition_by" onchange="partition_by_change(this);"><option></option><?php echo optionlist($partition_by, $row["partition_by"]); ?></select>
 (<input name="partition" value="<?php echo htmlspecialchars($row["partition"]); ?>" />)
 <?php echo lang('Partitions'); ?>: <input name="partitions" size="2" value="<?php echo htmlspecialchars($row["partitions"]); ?>"<?php echo ($partition_table || !$row["partition_by"] ? " class='hidden'" : ""); ?> />
 </p>
@@ -159,7 +151,7 @@ if ($dbh->server_info >= 5.1) {
 <thead><tr><th><?php echo lang('Partition name'); ?></th><th><?php echo lang('Values'); ?></th></tr></thead>
 <?php
 foreach ($row["partition_names"] as $key => $val) {
-       echo '<tr><td><input name="partition_names[]" value="' . htmlspecialchars($val) . '"' . ($key == count($row["partition_names"]) - 1 ? ' onchange="var row = this.parentNode.parentNode.cloneNode(true); row.firstChild.firstChild.value = \'\'; this.parentNode.parentNode.parentNode.appendChild(row); this.onchange = function () {};"' : '') . ' /></td><td><input name="partition_values[]" value="' . htmlspecialchars($row["partition_values"][$key]) . "\" /></td></tr>\n";
+       echo '<tr><td><input name="partition_names[]" value="' . htmlspecialchars($val) . '"' . ($key == count($row["partition_names"]) - 1 ? ' onchange="partition_name_change(this);"' : '') . ' /></td><td><input name="partition_values[]" value="' . htmlspecialchars($row["partition_values"][$key]) . "\" /></td></tr>\n";
 }
 ?>
 </table>
index 0f6454b5e12b1523f5357dab9b3a6d0ea482c330..8b69fe0dfab05858432f7d6ee956d99ee3438cf8 100644 (file)
@@ -18,14 +18,7 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
 </head>
 
 <body>
-<script type="text/javascript">
-document.body.className = 'js';
-function toggle(id) {
-       var el = document.getElementById(id);
-       el.className = (el.className == 'hidden' ? '' : 'hidden');
-       return true;
-}
-</script>
+<script type="text/javascript" src="functions.js"></script>
 
 <div id="content">
 <?php
index 160acc2960762f4e40cf37227b6032308ed2d72b..2d56bb5af59778c3574465bc6912cd54f833b156 100644 (file)
@@ -17,7 +17,7 @@ function dump_link($type, $name, $val, $attrs = "") {
                . (isset($check["db_check"]) ? "&amp;db_check=" . urlencode($check["db_check"]) : "")
                . (isset($check["table_check"]) ? "&amp;table_check=" . urlencode($check["table_check"]) : "")
                . (isset($check["data_check"]) ? "&amp;data_check=" . urlencode($check["data_check"]) : "")
-               . "\" onclick=\"return !check(this, /^$name/, '$val');\"$attrs>" . ($val ? $val : lang('skip')) . "</a>"
+               . "\" onclick=\"return !dump_check(this, /^$name/, '$val');\"$attrs>" . ($val ? $val : lang('skip')) . "</a>"
        ;
 }
 
@@ -142,18 +142,6 @@ DROP PROCEDURE phpminadmin_drop;
 page_header(lang('Export'), "", (strlen($_GET["export"]) ? array("table" => $_GET["export"]) : array()), $_GET["db"]);
 ?>
 
-<script type="text/javascript">
-function check(a, name, value) {
-       var inputs = a.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('input');
-       for (var i=0; inputs.length > i; i++) {
-               if (name.test(inputs[i].name)) {
-                       inputs[i].checked = (inputs[i].value == value);
-               }
-       }
-       return true;
-}
-</script>
-
 <form action="" method="post">
 <p><?php echo lang('Output') . ": $dump_output " . lang('Format') . ": $dump_format"; ?> <input type="submit" value="<?php echo lang('Export'); ?>" /></p>
 
index cf8d23166b6f78eec566cd5d35834a78be8cc5bc..df06613a22794fd19e9a7a2c2c72d51f8779d36d 100644 (file)
@@ -89,7 +89,7 @@ function process_input($name, $field) {
 function edit_type($key, $field, $collations) {
        global $types, $unsigned, $inout;
        ?>
-<td><select name="<?php echo $key; ?>[type]" onchange="type_change(this);"><?php echo optionlist(array_keys($types), $field["type"]); ?></select></td>
+<td><select name="<?php echo $key; ?>[type]" onchange="editing_type_change(this);"><?php echo optionlist(array_keys($types), $field["type"]); ?></select></td>
 <td><input name="<?php echo $key; ?>[length]" value="<?php echo htmlspecialchars($field["length"]); ?>" size="3" /></td>
 <td><?php echo "<select name=\"$key" . '[collation]"' . (preg_match('~char|text|enum|set~', $field["type"]) ? "" : " class='hidden'") . '><option value="">(' . lang('collation') . ')</option>' . optionlist($collations, $field["collation"]) . '</select>' . ($unsigned ? " <select name=\"$key" . '[unsigned]"' . (!$field["type"] || preg_match('~int|float|double|decimal~', $field["type"]) ? "" : " class='hidden'") . '>' . optionlist($unsigned, $field["unsigned"]) . '</select>' : ''); ?></td>
 <?php
@@ -104,8 +104,14 @@ function process_type($field, $collate = "COLLATE") {
        ;
 }
 
-function edit_fields($fields, $collations, $type = "TABLE") {
+function edit_fields($fields, $collations, $type = "TABLE", $allowed = 0) {
        global $inout;
+       $column_comments = false;
+       foreach ($fields as $field) {
+               if (strlen($field["comment"])) {
+                       $column_comments = true;
+               }
+       }
        ?>
 <thead><tr>
 <?php if ($type == "PROCEDURE") { ?><td><?php echo lang('IN-OUT'); ?></td><?php } ?>
@@ -116,12 +122,16 @@ function edit_fields($fields, $collations, $type = "TABLE") {
 <?php if ($type == "TABLE") { ?>
 <td><?php echo lang('NULL'); ?></td>
 <td><input type="radio" name="auto_increment_col" value="" /><?php echo lang('Auto Increment'); ?></td>
-<td><?php echo lang('Comment'); ?></td>
+<td<?php echo ($column_comments ? "" : " class='hidden'"); ?>><?php echo lang('Comment'); ?></td>
 <?php } ?>
-<td><input type="image" name="add[0]" src="plus.gif" title="<?php echo lang('Add next'); ?>" /></td>
+<td><input type="image" name="add[0]" src="plus.gif" title="<?php echo lang('Add next'); ?>" />
+<script type="text/javascript">
+var added = '.';
+var row_count = <?php echo count($fields); ?>;
+</script>
+</td>
 </tr></thead>
 <?php
-       $column_comments = false;
        foreach ($fields as $i => $field) {
                $i++;
                $display = (isset($_POST["add"][$i-1]) || (isset($field["field"]) && !$_POST["drop_col"][$i]));
@@ -133,19 +143,16 @@ function edit_fields($fields, $collations, $type = "TABLE") {
 <?php if ($type == "TABLE") { ?>
 <td><input type="checkbox" name="fields[<?php echo $i; ?>][null]" value="1"<?php if ($field["null"]) { ?> checked="checked"<?php } ?> /></td>
 <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>
+<td<?php echo ($column_comments ? "" : " class='hidden'"); ?>><input name="fields[<?php echo $i; ?>][comment]" value="<?php echo htmlspecialchars($field["comment"]); ?>" maxlength="255" /></td>
 <?php } ?>
 <td class="nowrap">
-<input type="image" name="add[<?php echo $i; ?>]" src="plus.gif" title="<?php echo lang('Add next'); ?>" onclick="return !add_row(this);" />
-<input type="image" name="drop_col[<?php echo $i; ?>]" src="minus.gif" title="<?php echo lang('Remove'); ?>" onclick="return !remove_row(this);" />
+<input type="image" name="add[<?php echo $i; ?>]" src="plus.gif" title="<?php echo lang('Add next'); ?>" onclick="return !editing_add_row(this, <?php echo $allowed; ?>);" />
+<input type="image" name="drop_col[<?php echo $i; ?>]" src="minus.gif" title="<?php echo lang('Remove'); ?>" onclick="return !editing_remove_row(this);" />
 <input type="image" name="up[<?php echo $i; ?>]" src="up.gif" title="<?php echo lang('Move up'); ?>" />
 <input type="image" name="down[<?php echo $i; ?>]" src="down.gif" title="<?php echo lang('Move down'); ?>" />
 </td>
 </tr>
 <?php
-               if (strlen($field["comment"])) {
-                       $column_comments = true;
-               }
        }
        return $column_comments;
 }
@@ -187,68 +194,6 @@ function process_fields(&$fields) {
        }
 }
 
-function type_change($count, $allowed = 0) {
-       ?>
-<script type="text/javascript">// <![CDATA[
-var added = '.';
-var row_count = <?php echo $count; ?>;
-
-function add_row(button) {
-       if (<?php echo $allowed; ?> && row_count >= <?php echo $allowed; ?>) {
-               return false;
-       }
-       var match = /([0-9]+)(\.[0-9]+)?/.exec(button.name)
-       var x = match[0] + (match[2] ? added.substr(match[2].length) : added) + '1';
-       var row = button.parentNode.parentNode;
-       var row2 = row.cloneNode(true);
-       var tags = row.getElementsByTagName('select');
-       var tags2 = row2.getElementsByTagName('select');
-       for (var i=0; tags.length > i; i++) {
-               tags[i].name = tags[i].name.replace(/([0-9.]+)/, x);
-               tags2[i].selectedIndex = tags[i].selectedIndex;
-       }
-       tags = row.getElementsByTagName('input');
-       for (var i=0; tags.length > i; i++) {
-               if (tags[i].name == 'auto_increment_col') {
-                       tags[i].value = x;
-                       tags[i].checked = false;
-               }
-               tags[i].name = tags[i].name.replace(/([0-9.]+)/, x);
-               if (/\[(orig|field|comment)/.test(tags[i].name)) {
-                       tags[i].value = '';
-               }
-       }
-       row.parentNode.insertBefore(row2, row);
-       tags[0].focus();
-       added += '0';
-       row_count++;
-       return true;
-}
-
-function remove_row(button) {
-       var field = button.form[button.name.replace(/drop_col(.+)/, 'fields$1[field]')];
-       field.parentNode.removeChild(field);
-       button.parentNode.parentNode.style.display = 'none';
-       //! should change class="odd" of next rows
-       return true;
-}
-
-function type_change(type) {
-       var name = type.name.substr(0, type.name.length - 6);
-       for (var i=0; i < type.form.elements.length; i++) {
-               var el = type.form.elements[i];
-               if (el.name == name + '[collation]') {
-                       el.className = (/char|text|enum|set/.test(type.options[type.selectedIndex].text) ? '' : 'hidden');
-               }
-               if (el.name == name + '[unsigned]') {
-                       el.className = (/int|float|double|decimal/.test(type.options[type.selectedIndex].text) ? '' : 'hidden');
-               }
-       }
-}
-// ]]></script>
-<?php
-}
-
 function normalize_enum($match) {
        return "'" . str_replace("'", "''", addcslashes(stripcslashes(str_replace($match[0]{0} . $match[0]{0}, $match[0]{0}, substr($match[0], 1, -1))), '\\')) . "'";
 }
index 8fb9c1d331995cc9bcd7c76e956013603f5889ef..8132cd6e630d13fabf13aa9d4c328fc6b3a3b5dc 100644 (file)
@@ -48,19 +48,6 @@ $source = get_vals("SHOW COLUMNS FROM " . idf_escape($_GET["foreign"])); //! no
 $target = ($_GET["foreign"] === $row["table"] ? $source : get_vals("SHOW COLUMNS FROM " . idf_escape($row["table"])));
 ?>
 
-<script type="text/javascript">// <![CDATA[
-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$&');
-               selects[i].selectedIndex = 0;
-       }
-       field.parentNode.parentNode.parentNode.appendChild(row);
-       field.onchange = function () { };
-}
-// ]]></script>
-
 <form action="" method="post">
 <p>
 <?php echo lang('Target table'); ?>:
@@ -74,7 +61,7 @@ function add_row(field) {
 $j = 0;
 foreach ($row["source"] as $key => $val) {
        echo "<tr>";
-       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='source[" . intval($key) . "]'" . ($j == count($row["source"]) - 1 ? " onchange='foreign_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++;
diff --git a/functions.js b/functions.js
new file mode 100644 (file)
index 0000000..bb3c242
--- /dev/null
@@ -0,0 +1,236 @@
+function toggle(id) {
+       var el = document.getElementById(id);
+       el.className = (el.className == 'hidden' ? '' : 'hidden');
+       return true;
+}
+
+function check_version(version) {
+       document.cookie = 'phpMinAdmin_version=0';
+       var script = document.createElement('script');
+       script.src = 'http://phpminadmin.sourceforge.net/version.php?version=' + version;
+       document.body.appendChild(script);
+}
+
+function tables_check(el) {
+       var elems = el.form.elements;
+       for (var i=0; i < elems.length; i++) {
+               if (elems[i].name == 'tables[]') {
+                       elems[i].checked = el.checked;
+               }
+       }
+}
+
+function where_change(op) {
+       for (var i=0; i < op.form.elements.length; i++) {
+               var el = op.form.elements[i];
+               if (el.name == op.name.substr(0, op.name.length - 4) + '[val]') {
+                       el.className = (/NULL$/.test(op.options[op.selectedIndex].text) ? 'hidden' : '');
+               }
+       }
+}
+
+function select_add_row(field) {
+       var row = field.parentNode.cloneNode(true);
+       var selects = row.getElementsByTagName('select');
+       for (var i=0; i < selects.length; i++) {
+               selects[i].name = selects[i].name.replace(/[a-z]\[[0-9]+/, '$&1');
+               selects[i].selectedIndex = 0;
+       }
+       var inputs = row.getElementsByTagName('input');
+       if (inputs.length) {
+               inputs[0].name = inputs[0].name.replace(/[a-z]\[[0-9]+/, '$&1');
+               inputs[0].value = '';
+               inputs[0].className = '';
+       }
+       field.parentNode.parentNode.appendChild(row);
+       field.onchange = function () { };
+}
+
+function editing_add_row(button, allowed) {
+       if (allowed && row_count >= allowed) {
+               return false;
+       }
+       var match = /([0-9]+)(\.[0-9]+)?/.exec(button.name)
+       var x = match[0] + (match[2] ? added.substr(match[2].length) : added) + '1';
+       var row = button.parentNode.parentNode;
+       var row2 = row.cloneNode(true);
+       var tags = row.getElementsByTagName('select');
+       var tags2 = row2.getElementsByTagName('select');
+       for (var i=0; i < tags.length; i++) {
+               tags[i].name = tags[i].name.replace(/([0-9.]+)/, x);
+               tags2[i].selectedIndex = tags[i].selectedIndex;
+       }
+       tags = row.getElementsByTagName('input');
+       for (var i=0; i < tags.length; i++) {
+               if (tags[i].name == 'auto_increment_col') {
+                       tags[i].value = x;
+                       tags[i].checked = false;
+               }
+               tags[i].name = tags[i].name.replace(/([0-9.]+)/, x);
+               if (/\[(orig|field|comment)/.test(tags[i].name)) {
+                       tags[i].value = '';
+               }
+       }
+       row.parentNode.insertBefore(row2, row);
+       tags[0].focus();
+       added += '0';
+       row_count++;
+       return true;
+}
+
+function editing_remove_row(button) {
+       var field = button.form[button.name.replace(/drop_col(.+)/, 'fields$1[field]')];
+       field.parentNode.removeChild(field);
+       button.parentNode.parentNode.style.display = 'none';
+       //! should change class="odd" of next rows
+       return true;
+}
+
+function editing_type_change(type) {
+       var name = type.name.substr(0, type.name.length - 6);
+       for (var i=0; i < type.form.elements.length; i++) {
+               var el = type.form.elements[i];
+               if (el.name == name + '[collation]') {
+                       el.className = (/char|text|enum|set/.test(type.options[type.selectedIndex].text) ? '' : 'hidden');
+               }
+               if (el.name == name + '[unsigned]') {
+                       el.className = (/int|float|double|decimal/.test(type.options[type.selectedIndex].text) ? '' : 'hidden');
+               }
+       }
+}
+
+function column_comments_click(checked) {
+       var trs = document.getElementById('edit-fields').getElementsByTagName('tr');
+       for (var i=0; i < trs.length; i++) {
+               trs[i].getElementsByTagName('td')[5].className = (checked ? '' : 'hidden');
+       }
+}
+
+function partition_by_change(el) {
+       var partition_table = /RANGE|LIST/.test(el.options[el.selectedIndex].text);
+       el.form['partitions'].className = (partition_table || !el.selectedIndex ? 'hidden' : '');
+       document.getElementById('partition-table').className = (partition_table ? '' : 'hidden');
+}
+
+function partition_name_change(el) {
+       var row = el.parentNode.parentNode.cloneNode(true);
+       row.firstChild.firstChild.value = '';
+       el.parentNode.parentNode.parentNode.appendChild(row);
+       el.onchange = function () {};
+}
+
+function foreign_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$&');
+               selects[i].selectedIndex = 0;
+       }
+       field.parentNode.parentNode.parentNode.appendChild(row);
+       field.onchange = function () { };
+}
+
+function indexes_add_row(field) {
+       var row = field.parentNode.parentNode.cloneNode(true);
+       var spans = row.getElementsByTagName('span');
+       row.getElementsByTagName('td')[1].innerHTML = '<span>' + spans[spans.length - 1].innerHTML + '</span>';
+       var selects = row.getElementsByTagName('select');
+       for (var i=0; i < selects.length; i++) {
+               selects[i].name = selects[i].name.replace(/indexes\[[0-9]+/, '$&1');
+               selects[i].selectedIndex = 0;
+       }
+       var input = row.getElementsByTagName('input')[0];
+       input.name = input.name.replace(/indexes\[[0-9]+/, '$&1');
+       input.value = '';
+       field.parentNode.parentNode.parentNode.appendChild(row);
+       field.onchange = function () { };
+}
+
+function indexes_add_column(field) {
+       var column = field.parentNode.cloneNode(true);
+       var select = column.getElementsByTagName('select')[0];
+       select.name = select.name.replace(/\]\[[0-9]+/, '$&1');
+       select.selectedIndex = 0;
+       var input = column.getElementsByTagName('input')[0];
+       input.name = input.name.replace(/\]\[[0-9]+/, '$&1');
+       input.value = '';
+       field.parentNode.parentNode.appendChild(column);
+       field.onchange = function () { };
+}
+
+function schema_mousedown(el, event, top) {
+       that = el;
+       em = document.getElementById('schema').offsetHeight / top;
+       x = event.clientX - el.offsetLeft;
+       y = event.clientY - el.offsetTop;
+}
+
+function schema_mousemove(ev) {
+       if (that !== undefined) {
+               ev = ev || event;
+               var left = (ev.clientX - x) / em;
+               var top = (ev.clientY - y) / em;
+               var divs = that.getElementsByTagName('div');
+               var line_set = { };
+               for (var i=0; i < divs.length; i++) {
+                       if (divs[i].className == 'references') {
+                               var div2 = document.getElementById((divs[i].id.substr(0, 4) == 'refs' ? 'refd' : 'refs') + divs[i].id.substr(4));
+                               var ref = (table_pos[divs[i].title] ? table_pos[divs[i].title] : [ div2.parentNode.offsetTop / em, 0 ]);
+                               var left1 = -1;
+                               var is_top = true;
+                               var id = divs[i].id.replace(/^ref.(.+)-.+/, '$1');
+                               if (divs[i].parentNode != div2.parentNode) {
+                                       left1 = Math.min(0, ref[1] - left) - 1;
+                                       divs[i].style.left = left1 + 'em';
+                                       divs[i].getElementsByTagName('div')[0].style.width = -left1 + 'em';
+                                       var left2 = Math.min(0, left - ref[1]) - 1;
+                                       div2.style.left = left2 + 'em';
+                                       div2.getElementsByTagName('div')[0].style.width = -left2 + 'em';
+                                       is_top = (div2.offsetTop + ref[0] * em > divs[i].offsetTop + top * em);
+                               }
+                               if (!line_set[id]) {
+                                       var line = document.getElementById(divs[i].id.replace(/^....(.+)-[0-9]+$/, 'refl$1'));
+                                       var shift = ev.clientY - y - that.offsetTop;
+                                       line.style.left = (left + left1) + 'em';
+                                       if (is_top) {
+                                               line.style.top = (line.offsetTop + shift) / em + 'em';
+                                       }
+                                       if (divs[i].parentNode != div2.parentNode) {
+                                               line = line.getElementsByTagName('div')[0];
+                                               line.style.height = (line.offsetHeight + (is_top ? -1 : 1) * shift) / em + 'em';
+                                       }
+                                       line_set[id] = true;
+                               }
+                       }
+               }
+               that.style.left = left + 'em';
+               that.style.top = top + 'em';
+       }
+}
+
+function schema_mouseup(ev) {
+       if (that !== undefined) {
+               ev = ev || event;
+               table_pos[that.firstChild.firstChild.firstChild.data] = [ (ev.clientY - y) / em, (ev.clientX - x) / em ];
+               that = undefined;
+               var date = new Date();
+               date.setMonth(date.getMonth() + 1);
+               var s = '';
+               for (var key in table_pos) {
+                       s += '_' + key + ':' + Math.round(table_pos[key][0] * 10000) / 10000 + 'x' + Math.round(table_pos[key][1] * 10000) / 10000;
+               }
+               document.cookie = 'schema=' + encodeURIComponent(s.substr(1)) + '; expires=' + date + '; path=' + location.pathname + location.search;
+       }
+}
+
+function dump_check(a, name, value) {
+       var inputs = a.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('input');
+       for (var i=0; i < inputs.length; i++) {
+               if (name.test(inputs[i].name)) {
+                       inputs[i].checked = (inputs[i].value == value);
+               }
+       }
+       return true;
+}
+
+document.body.className = 'js';
index 76f2795f8f6fdd339641c9f43078969183fd302b..4b7e846438c2c91e7bec916fb21e48a2328113a7 100644 (file)
--- a/index.php
+++ b/index.php
@@ -171,7 +171,7 @@ if (isset($_GET["download"])) {
                        } else {
                                echo "<form action='' method='post'>\n";
                                echo "<table cellspacing='0'>\n";
-                               echo '<thead><tr><td><input type="checkbox" onclick="var elems = this.form.elements; for (var i=0; elems.length > i; i++) if (elems[i].name == \'tables[]\') elems[i].checked = this.checked;" /></td><th>' . lang('Table') . '</th><td>' . lang('Engine') . '</td><td>' . lang('Comment') . '</td><td>' . lang('Collation') . '</td><td>' . lang('Data Length') . '</td><td>' . lang('Index Length') . '</td><td>' . lang('Data Free') . '</td><td>' . lang('Auto Increment') . '</td><td>' . lang('Rows') . "</td></tr></thead>\n";
+                               echo '<thead><tr><td><input type="checkbox" onclick="tables_check(this);" /></td><th>' . lang('Table') . '</th><td>' . lang('Engine') . '</td><td>' . lang('Comment') . '</td><td>' . lang('Collation') . '</td><td>' . lang('Data Length') . '</td><td>' . lang('Index Length') . '</td><td>' . lang('Data Free') . '</td><td>' . lang('Auto Increment') . '</td><td>' . lang('Rows') . "</td></tr></thead>\n";
                                while ($row = $result->fetch_assoc()) {
                                        table_comment($row);
                                        echo '<tr class="nowrap' . odd(' odd') . '"><td>' . (isset($row["Rows"]) ? '<input type="checkbox" name="tables[]" value="' . htmlspecialchars($row["Name"]) . '"' . (in_array($row["Name"], (array) $_POST["tables"], true) ? ' checked="checked"' : '') . ' /></td><th><a href="' . htmlspecialchars($SELF) . 'table=' . urlencode($row["Name"]) . '">' . htmlspecialchars($row["Name"]) . "</a></th><td>$row[Engine]</td><td>" . (strlen(trim($row["Comment"])) ? htmlspecialchars($row["Comment"]) : "&nbsp;") . "</td><td>$row[Collation]" : '&nbsp;</td><th><a href="' . htmlspecialchars($SELF) . 'view=' . urlencode($row["Name"]) . '">' . htmlspecialchars($row["Name"]) . '</a></th><td colspan="8"><a href="' . htmlspecialchars($SELF) . "select=" . urlencode($row["Name"]) . '">' . lang('View') . '</a>');
index 691d02fe5a65a0051bbc0429fa2a491c3441f8b8..7ede702b686e4295168eb8381f5dbe89fee05751 100644 (file)
@@ -63,46 +63,16 @@ if ($_POST) {
 }
 ?>
 
-<script type="text/javascript">// <![CDATA[
-function add_row(field) {
-       var row = field.parentNode.parentNode.cloneNode(true);
-       var spans = row.getElementsByTagName('span');
-       row.getElementsByTagName('td')[1].innerHTML = '<span>' + spans[spans.length - 1].innerHTML + '</span>';
-       var selects = row.getElementsByTagName('select');
-       for (var i=0; i < selects.length; i++) {
-               selects[i].name = selects[i].name.replace(/indexes\[[0-9]+/, '$&1');
-               selects[i].selectedIndex = 0;
-       }
-       var input = row.getElementsByTagName('input')[0];
-       input.name = input.name.replace(/indexes\[[0-9]+/, '$&1');
-       input.value = '';
-       field.parentNode.parentNode.parentNode.appendChild(row);
-       field.onchange = function () { };
-}
-
-function add_column(field) {
-       var column = field.parentNode.cloneNode(true);
-       var select = column.getElementsByTagName('select')[0];
-       select.name = select.name.replace(/\]\[[0-9]+/, '$&1');
-       select.selectedIndex = 0;
-       var input = column.getElementsByTagName('input')[0];
-       input.name = input.name.replace(/\]\[[0-9]+/, '$&1');
-       input.value = '';
-       field.parentNode.parentNode.appendChild(column);
-       field.onchange = function () { };
-}
-// ]]></script>
-
 <form action="" method="post">
 <table cellspacing="0">
 <thead><tr><th><?php echo lang('Index Type'); ?></th><th><?php echo lang('Column (length)'); ?></th></tr></thead>
 <?php
 $j = 0;
 foreach ($row["indexes"] as $index) {
-       echo "<tr><td><select name='indexes[$j][type]'" . ($j == count($row["indexes"]) - 1 ? " onchange='add_row(this);'" : "") . "><option></option>" . optionlist($index_types, $index["type"]) . "</select></td><td>\n";
+       echo "<tr><td><select name='indexes[$j][type]'" . ($j == count($row["indexes"]) - 1 ? " onchange='indexes_add_row(this);'" : "") . "><option></option>" . optionlist($index_types, $index["type"]) . "</select></td><td>\n";
        ksort($index["columns"]);
        foreach ($index["columns"] as $i => $column) {
-               echo "<span><select name='indexes[$j][columns][$i]'" . ($i == count($index["columns"]) ? " onchange='add_column(this);'" : "") . "><option></option>" . optionlist($fields, $column) . "</select>";
+               echo "<span><select name='indexes[$j][columns][$i]'" . ($i == count($index["columns"]) ? " onchange='indexes_add_column(this);'" : "") . "><option></option>" . optionlist($fields, $column) . "</select>";
                echo "<input name='indexes[$j][lengths][$i]' size='2' value=\"" . htmlspecialchars($index["lengths"][$i]) . "\" /></span>\n";
        }
        echo "</td></tr>\n";
index a74a00357804fde5c6e6109f14e046aed59862d6..15306eebcc298e90fe23e7fbe7ed2becca5771e3 100644 (file)
@@ -41,12 +41,6 @@ if ($_POST) {
 <?php edit_fields($row["fields"], $collations, $routine); ?>
 <?php if (isset($_GET["function"])) { ?><tr><td><?php echo lang('Return type'); ?></td><?php echo edit_type("returns", $row["returns"], $collations); ?></tr><?php } ?>
 </table>
-<?php echo type_change(count($row["fields"])); ?>
-<?php if (isset($_GET["function"])) { ?>
-<script type="text/javascript">
-document.getElementById('form')['returns[type]'].onchange();
-</script>
-<?php } ?>
 <p><textarea name="definition" rows="10" cols="80" style="width: 98%;"><?php echo htmlspecialchars($row["definition"]); ?></textarea></p>
 <p>
 <input type="hidden" name="token" value="<?php echo $token; ?>" />
index 0f2ef70332f47d68ce8d104484bf55266feea2b5..44e97bc07bfc22030fed12b0a669b1406c31718e 100644 (file)
@@ -53,75 +53,14 @@ $result->free();
 <script type="text/javascript">
 var that, x, y, em;
 var table_pos = {<?php echo implode(",", $table_pos_js) . "\n"; ?>};
-
-function mousedown(el, event) {
-       that = el;
-       em = document.getElementById('schema').offsetHeight / <?php echo $top; ?>;
-       x = event.clientX - el.offsetLeft;
-       y = event.clientY - el.offsetTop;
-}
-document.onmousemove = function (ev) {
-       if (that !== undefined) {
-               ev = ev || event;
-               var left = (ev.clientX - x) / em;
-               var top = (ev.clientY - y) / em;
-               var divs = that.getElementsByTagName('div');
-               var line_set = { };
-               for (var i=0; divs.length > i; i++) {
-                       if (divs[i].className == 'references') {
-                               var div2 = document.getElementById((divs[i].id.substr(0, 4) == 'refs' ? 'refd' : 'refs') + divs[i].id.substr(4));
-                               var ref = (table_pos[divs[i].title] ? table_pos[divs[i].title] : [ div2.parentNode.offsetTop / em, 0 ]);
-                               var left1 = -1;
-                               var is_top = true;
-                               var id = divs[i].id.replace(/^ref.(.+)-.+/, '$1');
-                               if (divs[i].parentNode != div2.parentNode) {
-                                       left1 = Math.min(0, ref[1] - left) - 1;
-                                       divs[i].style.left = left1 + 'em';
-                                       divs[i].getElementsByTagName('div')[0].style.width = -left1 + 'em';
-                                       var left2 = Math.min(0, left - ref[1]) - 1;
-                                       div2.style.left = left2 + 'em';
-                                       div2.getElementsByTagName('div')[0].style.width = -left2 + 'em';
-                                       is_top = (div2.offsetTop + ref[0] * em > divs[i].offsetTop + top * em);
-                               }
-                               if (!line_set[id]) {
-                                       var line = document.getElementById(divs[i].id.replace(/^....(.+)-[0-9]+$/, 'refl$1'));
-                                       var shift = ev.clientY - y - that.offsetTop;
-                                       line.style.left = (left + left1) + 'em';
-                                       if (is_top) {
-                                               line.style.top = (line.offsetTop + shift) / em + 'em';
-                                       }
-                                       if (divs[i].parentNode != div2.parentNode) {
-                                               line = line.getElementsByTagName('div')[0];
-                                               line.style.height = (line.offsetHeight + (is_top ? -1 : 1) * shift) / em + 'em';
-                                       }
-                                       line_set[id] = true;
-                               }
-                       }
-               }
-               that.style.left = left + 'em';
-               that.style.top = top + 'em';
-       }
-}
-document.onmouseup = function (ev) {
-       if (that !== undefined) {
-               ev = ev || event;
-               table_pos[that.firstChild.firstChild.firstChild.data] = [ (ev.clientY - y) / em, (ev.clientX - x) / em ];
-               that = undefined;
-               var date = new Date();
-               date.setMonth(date.getMonth() + 1);
-               var s = '';
-               for (var key in table_pos) {
-                       s += '_' + key + ':' + Math.round(table_pos[key][0] * 10000) / 10000 + 'x' + Math.round(table_pos[key][1] * 10000) / 10000;
-               }
-               document.cookie = 'schema=' + encodeURIComponent(s.substr(1)) + '; expires=' + date + '; path=' + location.pathname + location.search;
-       }
-}
+document.onmousemove = schema_mousemove;
+document.onmouseup = schema_mouseup;
 </script>
 
 <div id="schema" style="height: <?php echo $top; ?>em;">
 <?php
 foreach ($schema as $name => $table) {
-       echo "<div class='table' style='top: " . $table["pos"][0] . "em; left: " . $table["pos"][1] . "em;' onmousedown='mousedown(this, event);'>";
+       echo "<div class='table' style='top: " . $table["pos"][0] . "em; left: " . $table["pos"][1] . "em;' onmousedown='schema_mousedown(this, event, $top);'>";
        echo '<a href="' . htmlspecialchars($SELF) . 'table=' . urlencode($name) . '"><strong>' . htmlspecialchars($name) . "</strong></a><br />\n";
        foreach ($table["fields"] as $field) {
                $val = htmlspecialchars($field["field"]);
index 346480016b73f532ec748615016b48ba5ebad0e3..7ae7cc3605866a57fcf4a2fb2d3a1c74256d3263 100644 (file)
@@ -152,25 +152,6 @@ if (!$columns) {
        echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "" : ": " . htmlspecialchars($dbh->error)) . ".</p>\n";
 } else {
        echo "<form action='' id='form'>\n";
-       ?>
-<script type="text/javascript">// <![CDATA[
-function add_row(field) {
-       var row = field.parentNode.cloneNode(true);
-       var selects = row.getElementsByTagName('select');
-       for (var i=0; i < selects.length; i++) {
-               selects[i].name = selects[i].name.replace(/[a-z]\[[0-9]+/, '$&1');
-               selects[i].selectedIndex = 0;
-       }
-       var inputs = row.getElementsByTagName('input');
-       if (inputs.length) {
-               inputs[0].name = inputs[0].name.replace(/[a-z]\[[0-9]+/, '$&1');
-               inputs[0].value = '';
-       }
-       field.parentNode.parentNode.appendChild(row);
-       field.onchange = function () { };
-}
-// ]]></script>
-<?php
        echo "<fieldset><legend>" . lang('Select') . "</legend>\n";
        if (strlen($_GET["server"])) {
                echo '<input type="hidden" name="server" value="' . htmlspecialchars($_GET["server"]) . '" />';
@@ -187,7 +168,7 @@ function add_row(field) {
                $i++;
        }
        echo "<div><select name='columns[$i][fun]' onchange='this.nextSibling.onchange();'><option></option>" . optionlist($fun_group) . "</select>";
-       echo "<select name='columns[$i][col]' onchange='add_row(this);'><option></option>" . optionlist($columns) . "</select></div>\n";
+       echo "<select name='columns[$i][col]' onchange='select_add_row(this);'><option></option>" . optionlist($columns) . "</select></div>\n";
        echo "</fieldset>\n";
        
        echo "<fieldset><legend>" . lang('Search') . "</legend>\n";
@@ -204,28 +185,11 @@ function add_row(field) {
                if (strlen("$val[col]$val[val]") && in_array($val["op"], $operators)) {
                        echo "<div><select name='where[$i][col]'><option value=''>" . lang('(anywhere)') . "</option>" . optionlist($columns, $val["col"]) . "</select>";
                        echo "<select name='where[$i][op]' onchange='where_change(this);'>" . optionlist($operators, $val["op"]) . "</select>";
-                       echo "<input name='where[$i][val]' value=\"" . htmlspecialchars($val["val"]) . "\" /></div>\n";
+                       echo "<input name='where[$i][val]' value=\"" . htmlspecialchars($val["val"]) . '"' . (ereg('NULL$', $val["op"]) ? " class='hidden'" : "") . " /></div>\n";
                        $i++;
                }
        }
-       ?>
-<script type="text/javascript">
-function where_change(op) {
-       for (var i=0; i < op.form.elements.length; i++) {
-               var el = op.form.elements[i];
-               if (el.name == op.name.substr(0, op.name.length - 4) + '[val]') {
-                       el.style.display = (/NULL$/.test(op.options[op.selectedIndex].text) ? 'none' : '');
-               }
-       }
-}
-<?php if ($i) { ?>
-for (var i=0; <?php echo $i; ?> > i; i++) {
-       document.getElementById('form')['where[' + i + '][op]'].onchange();
-}
-<?php } ?>
-</script>
-<?php
-       echo "<div><select name='where[$i][col]' onchange='add_row(this);'><option value=''>" . lang('(anywhere)') . "</option>" . optionlist($columns) . "</select>";
+       echo "<div><select name='where[$i][col]' onchange='select_add_row(this);'><option value=''>" . lang('(anywhere)') . "</option>" . optionlist($columns) . "</select>";
        echo "<select name='where[$i][op]' onchange='where_change(this);'>" . optionlist($operators) . "</select>";
        echo "<input name='where[$i][val]' /></div>\n";
        echo "</fieldset>\n";
@@ -239,7 +203,7 @@ for (var i=0; <?php echo $i; ?> > i; i++) {
                        $i++;
                }
        }
-       echo "<div><select name='order[$i]' onchange='add_row(this);'><option></option>" . optionlist($columns) . "</select>";
+       echo "<div><select name='order[$i]' onchange='select_add_row(this);'><option></option>" . optionlist($columns) . "</select>";
        echo "<label><input type='checkbox' name='desc[$i]' value='1' />" . lang('DESC') . "</label></div>\n";
        echo "</fieldset>\n";
        
index 86ede04049a3c4da13488ebba4a39d85bde65b93..0691dccc9b2c080a4faf5a07119b35e32f101060 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -7,7 +7,6 @@ Compress export and import
 Create view and routine options
 SQL queries history - utilize in edit link in .message and .error
 Function to fix database encoding - http://php.vrana.cz/prevod-kodovani-mysql.php
-Separate JavaScript - load after login form
 ? Save token also to cookie - for session expiration and login in other window
 ? Save uploaded files after error to session variable instead of hidden field
 ? Aliasing of built-in functions can save 7 KB, substitution of $_GET and friends can save 2 KB, remove of base64_decode() + using chars 127-255 in minification can save 1 KB, JS shrink can save 1 KB