Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 117 lines (113 sloc) 5.177 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);'>";
f8d378f Prepare schema
jakubvrana authored
63 echo '<a href="' . htmlspecialchars($SELF) . 'table=' . urlencode($name) . '"><strong>' . htmlspecialchars($name) . "</strong></a><br />\n";
6636a61 Draggable tables in schema
jakubvrana authored
64 foreach ($table["fields"] as $field) {
f8d378f Prepare schema
jakubvrana authored
65 $val = htmlspecialchars($field["field"]);
b57f0de Remove confusion between type and Type
jakubvrana authored
66 $title = ' title="' . htmlspecialchars($field["full_type"] . ($field["null"] ? " " . lang('NULL') : '')) . '"';
f8d378f Prepare schema
jakubvrana authored
67 if (preg_match('~char|text~', $field["type"])) {
1f733b0 Display type in schema
jakubvrana authored
68 $val = "<span class='char'$title>$val</span>";
f8d378f Prepare schema
jakubvrana authored
69 } elseif (preg_match('~date|time|year~', $field["type"])) {
1f733b0 Display type in schema
jakubvrana authored
70 $val = "<span class='date'$title>$val</span>";
f8d378f Prepare schema
jakubvrana authored
71 } elseif (preg_match('~binary|blob~', $field["type"])) {
1f733b0 Display type in schema
jakubvrana authored
72 $val = "<span class='binary'$title>$val</span>";
f8d378f Prepare schema
jakubvrana authored
73 } elseif (preg_match('~enum|set~', $field["type"])) {
1f733b0 Display type in schema
jakubvrana authored
74 $val = "<span class='enum'$title>$val</span>";
75 } else {
76 $val = "<span$title>$val</span>";
f8d378f Prepare schema
jakubvrana authored
77 }
78 echo ($field["primary"] ? "<em>$val</em>" : $val) . "<br />\n";
6636a61 Draggable tables in schema
jakubvrana authored
79 }
80 foreach ((array) $table["references"] as $target_name => $refs) {
a055d87 Don't use PHP 5 only function (bug #2214423)
jakubvrana authored
81 foreach ($refs as $left => $ref) {
256438e Set vertical lines only once
jakubvrana authored
82 $left1 = $left - $table_pos[$name][1];
81dbdda Move references lines
jakubvrana authored
83 $i = 0;
a055d87 Don't use PHP 5 only function (bug #2214423)
jakubvrana authored
84 foreach ($ref[0] as $source) {
81dbdda Move references lines
jakubvrana authored
85 echo '<div class="references" title="' . htmlspecialchars($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
86 }
87 }
88 }
1eee0a1 Test $_COOKIE instead of SID (PHP bug #42135)
jakubvrana authored
89 foreach ((array) $referenced[$name] as $target_name => $refs) {
90 foreach ($refs as $left => $columns) {
256438e Set vertical lines only once
jakubvrana authored
91 $left1 = $left - $table_pos[$name][1];
81dbdda Move references lines
jakubvrana authored
92 $i = 0;
1eee0a1 Test $_COOKIE instead of SID (PHP bug #42135)
jakubvrana authored
93 foreach ($columns as $target) {
ed22950 More separation
jakubvrana authored
94 echo '<div class="references" title="' . htmlspecialchars($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
95 }
6636a61 Draggable tables in schema
jakubvrana authored
96 }
f8d378f Prepare schema
jakubvrana authored
97 }
98 echo "</div>\n";
99 }
100 foreach ($schema as $name => $table) {
d7d9c59 Change referenced to references
jakubvrana authored
101 foreach ((array) $table["references"] as $target_name => $refs) {
6636a61 Draggable tables in schema
jakubvrana authored
102 foreach ($refs as $left => $ref) {
38cb78a Show references in schema
jakubvrana authored
103 $min_pos = $top;
6636a61 Draggable tables in schema
jakubvrana authored
104 $max_pos = -10;
a055d87 Don't use PHP 5 only function (bug #2214423)
jakubvrana authored
105 foreach ($ref[0] as $key => $source) {
7c22767 Position lines
jakubvrana authored
106 $pos1 = $table["pos"][0] + $table["fields"][$source]["pos"];
a055d87 Don't use PHP 5 only function (bug #2214423)
jakubvrana authored
107 $pos2 = $schema[$target_name]["pos"][0] + $schema[$target_name]["fields"][$ref[1][$key]]["pos"];
38cb78a Show references in schema
jakubvrana authored
108 $min_pos = min($min_pos, $pos1, $pos2);
109 $max_pos = max($max_pos, $pos1, $pos2);
110 }
f203092 Typo
jakubvrana authored
111 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
112 }
113 }
f8d378f Prepare schema
jakubvrana authored
114 }
115 ?>
116 </div>
Something went wrong with that request. Please try again.