Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 105 lines (101 sloc) 4.627 kb
f8d378f Prepare schema
jakubvrana authored
1 <?php
eff527b Move error output to page_header()
jakubvrana authored
2 page_header(lang('Database schema'), "", array(), $_GET["db"]);
f8d378f Prepare schema
jakubvrana authored
3
6636a61 Draggable tables in schema
jakubvrana authored
4 $table_pos = array();
5 $table_pos_js = array();
64ba924 Comments
jakubvrana authored
6 // saved in one cookie because there is a limit of 20 cookies per domain
b8ef9fb Use prefix for cookies
jakubvrana authored
7 preg_match_all('~([^:]+):([-0-9.]+)x([-0-9.]+)(_|$)~', $_COOKIE["adminer_schema"], $matches, PREG_SET_ORDER); //! ':' in table name
6636a61 Draggable tables in schema
jakubvrana authored
8 foreach ($matches as $i => $match) {
7c22767 Position lines
jakubvrana authored
9 $table_pos[$match[1]] = array($match[2], $match[3]);
6636a61 Draggable tables in schema
jakubvrana authored
10 $table_pos_js[] = "\n\t'" . addcslashes($match[1], "\r\n'\\") . "': [ $match[2], $match[3] ]";
11 }
12
13 $top = 0;
1eee0a1 Test $_COOKIE instead of SID (PHP bug #42135)
jakubvrana authored
14 $base_left = -1;
64ba924 Comments
jakubvrana authored
15 $schema = array(); // table => array("fields" => array(name => field), "pos" => array(top, left), "references" => array(table => array(left => array(source, target))))
16 $referenced = array(); // target_table => array(table => array(left => target_column))
17 $lefts = array(); // float => bool
caeb30f Separate table_status
jakubvrana authored
18 foreach (table_status() as $row) {
f8d378f Prepare schema
jakubvrana authored
19 if (!isset($row["Engine"])) { // view
20 continue;
21 }
6636a61 Draggable tables in schema
jakubvrana authored
22 $pos = 0;
23 $schema[$row["Name"]]["fields"] = array();
24 foreach (fields($row["Name"]) as $name => $field) {
25 $pos += 1.25;
26 $field["pos"] = $pos;
27 $schema[$row["Name"]]["fields"][$name] = $field;
28 }
7c22767 Position lines
jakubvrana authored
29 $schema[$row["Name"]]["pos"] = ($table_pos[$row["Name"]] ? $table_pos[$row["Name"]] : array($top, 0));
f8d378f Prepare schema
jakubvrana authored
30 if ($row["Engine"] == "InnoDB") {
31 foreach (foreign_keys($row["Name"]) as $val) {
32 if (!$val["db"]) {
d8df520 Initialize variables outside blocks
jakubvrana authored
33 $left = $base_left;
7c22767 Position lines
jakubvrana authored
34 if ($table_pos[$row["Name"]][1] || $table_pos[$row["Name"]][1]) {
1eee0a1 Test $_COOKIE instead of SID (PHP bug #42135)
jakubvrana authored
35 $left = min($table_pos[$row["Name"]][1], $table_pos[$val["table"]][1]) - 1;
7c22767 Position lines
jakubvrana authored
36 } else {
37 $base_left -= .1;
38 }
256438e Set vertical lines only once
jakubvrana authored
39 while ($lefts[(string) $left]) {
64ba924 Comments
jakubvrana authored
40 // find free $left
4c1bf36 Beware overlapped lines
jakubvrana authored
41 $left -= .0001;
42 }
a055d87 Don't use PHP 5 only function (bug #2214423)
jakubvrana authored
43 $schema[$row["Name"]]["references"][$val["table"]][(string) $left] = array($val["source"], $val["target"]);
256438e Set vertical lines only once
jakubvrana authored
44 $referenced[$val["table"]][$row["Name"]][(string) $left] = $val["target"];
45 $lefts[(string) $left] = true;
f8d378f Prepare schema
jakubvrana authored
46 }
47 }
48 }
7c22767 Position lines
jakubvrana authored
49 $top = max($top, $schema[$row["Name"]]["pos"][0] + 2.5 + $pos);
f8d378f Prepare schema
jakubvrana authored
50 }
6636a61 Draggable tables in schema
jakubvrana authored
51
f8d378f Prepare schema
jakubvrana authored
52 ?>
56e884f JSLint
jakubvrana authored
53 <div id="schema" style="height: <?php echo $top; ?>em;">
6636a61 Draggable tables in schema
jakubvrana authored
54 <script type="text/javascript">
56e884f JSLint
jakubvrana authored
55 table_pos = {<?php echo implode(",", $table_pos_js) . "\n"; ?>};
56 em = document.getElementById('schema').offsetHeight / <?php echo $top; ?>;
540e217 Separate JavaScript
jakubvrana authored
57 document.onmousemove = schema_mousemove;
58 document.onmouseup = schema_mouseup;
6636a61 Draggable tables in schema
jakubvrana authored
59 </script>
f8d378f Prepare schema
jakubvrana authored
60 <?php
38cb78a Show references in schema
jakubvrana authored
61 foreach ($schema as $name => $table) {
56e884f JSLint
jakubvrana authored
62 echo "<div class='table' style='top: " . $table["pos"][0] . "em; left: " . $table["pos"][1] . "em;' onmousedown='schema_mousedown(this, event);'>";
98507da Function verify_version doesn't use version parameter
jakubvrana authored
63 echo '<a href="' . h(ME) . 'table=' . urlencode($name) . '"><strong>' . h($name) . "</strong></a><br>\n";
6636a61 Draggable tables in schema
jakubvrana authored
64 foreach ($table["fields"] as $field) {
b349612 Remove useless translations
jakubvrana authored
65 $val = '<span' . type_class($field["type"]) . ' title="' . h($field["full_type"] . ($field["null"] ? " NULL" : '')) . '">' . h($field["field"]) . '</span>';
ace55ed HTML instead of XHTML
jakubvrana authored
66 echo ($field["primary"] ? "<em>$val</em>" : $val) . "<br>\n";
6636a61 Draggable tables in schema
jakubvrana authored
67 }
68 foreach ((array) $table["references"] as $target_name => $refs) {
a055d87 Don't use PHP 5 only function (bug #2214423)
jakubvrana authored
69 foreach ($refs as $left => $ref) {
256438e Set vertical lines only once
jakubvrana authored
70 $left1 = $left - $table_pos[$name][1];
81dbdda Move references lines
jakubvrana authored
71 $i = 0;
a055d87 Don't use PHP 5 only function (bug #2214423)
jakubvrana authored
72 foreach ($ref[0] as $source) {
689699a Shortcut for htmlspecialchars
jakubvrana authored
73 echo "<div class='references' title='" . h($target_name) . "' id='refs$left-" . ($i++) . "' style='left: $left1" . "em; top: " . $table["fields"][$source]["pos"] . "em; padding-top: .5em;'><div style='border-top: 1px solid Gray; width: " . (-$left1) . "em;'></div></div>\n";
6636a61 Draggable tables in schema
jakubvrana authored
74 }
75 }
76 }
1eee0a1 Test $_COOKIE instead of SID (PHP bug #42135)
jakubvrana authored
77 foreach ((array) $referenced[$name] as $target_name => $refs) {
78 foreach ($refs as $left => $columns) {
256438e Set vertical lines only once
jakubvrana authored
79 $left1 = $left - $table_pos[$name][1];
81dbdda Move references lines
jakubvrana authored
80 $i = 0;
1eee0a1 Test $_COOKIE instead of SID (PHP bug #42135)
jakubvrana authored
81 foreach ($columns as $target) {
689699a Shortcut for htmlspecialchars
jakubvrana authored
82 echo "<div class='references' title='" . h($target_name) . "' id='refd$left-" . ($i++) . "' style='left: $left1" . "em; top: " . $table["fields"][$target]["pos"] . "em; height: 1.25em; background: url(../adminer/arrow.gif) no-repeat right center;'><div style='height: .5em; border-bottom: 1px solid Gray; width: " . (-$left1) . "em;'></div></div>\n";
1eee0a1 Test $_COOKIE instead of SID (PHP bug #42135)
jakubvrana authored
83 }
6636a61 Draggable tables in schema
jakubvrana authored
84 }
f8d378f Prepare schema
jakubvrana authored
85 }
86 echo "</div>\n";
87 }
88 foreach ($schema as $name => $table) {
d7d9c59 Change referenced to references
jakubvrana authored
89 foreach ((array) $table["references"] as $target_name => $refs) {
6636a61 Draggable tables in schema
jakubvrana authored
90 foreach ($refs as $left => $ref) {
38cb78a Show references in schema
jakubvrana authored
91 $min_pos = $top;
6636a61 Draggable tables in schema
jakubvrana authored
92 $max_pos = -10;
a055d87 Don't use PHP 5 only function (bug #2214423)
jakubvrana authored
93 foreach ($ref[0] as $key => $source) {
7c22767 Position lines
jakubvrana authored
94 $pos1 = $table["pos"][0] + $table["fields"][$source]["pos"];
a055d87 Don't use PHP 5 only function (bug #2214423)
jakubvrana authored
95 $pos2 = $schema[$target_name]["pos"][0] + $schema[$target_name]["fields"][$ref[1][$key]]["pos"];
38cb78a Show references in schema
jakubvrana authored
96 $min_pos = min($min_pos, $pos1, $pos2);
97 $max_pos = max($max_pos, $pos1, $pos2);
98 }
f203092 Typo
jakubvrana authored
99 echo "<div class='references' id='refl$left' style='left: $left" . "em; top: $min_pos" . "em; padding: .5em 0;'><div style='border-right: 1px solid Gray; margin-top: 1px; height: " . ($max_pos - $min_pos) . "em;'></div></div>\n";
38cb78a Show references in schema
jakubvrana authored
100 }
101 }
f8d378f Prepare schema
jakubvrana authored
102 }
103 ?>
104 </div>
Something went wrong with that request. Please try again.