Skip to content
Newer
Older
100644 137 lines (126 sloc) 5.53 KB
2c445a8 Extensibility basics
jakubvrana authored Jul 3, 2009
1 <?php
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
2 /** Name in title and navigation
3 * @return string
4 */
5 function adminer_name() {
6 return call_adminer('name', lang('Adminer'));
7 }
8
9 /** Connection parameters
10 * @return array ($server, $username, $password)
11 */
12 function adminer_credentials() {
13 return call_adminer('credentials', array($_GET["server"], $_SESSION["usernames"][$_GET["server"]], $_SESSION["passwords"][$_GET["server"]]));
14 }
15
16 /** Identifier of selected database
17 * @return string
18 */
19 function adminer_database() {
20 // should be used everywhere instead of $_GET["db"]
21 return call_adminer('database', $_GET["db"]);
22 }
23
24 /** Table caption used in navigation and headings
25 * @param array result of SHOW TABLE STATUS
26 * @return string
27 */
28 function adminer_table_name($row) {
29 return call_adminer('table_name', htmlspecialchars($row["Name"]), $row);
30 }
31
32 /** Field caption used in select and edit
33 * @param array all fields in table, result of fields()
34 * @param string column identifier, function calls are not contained in $fields
35 * @return string
36 */
37 function adminer_field_name($fields, $key) {
cb2c957 Show type by field name (thanks to Jakub Sochor)
jakubvrana authored Jul 13, 2009
38 return call_adminer('field_name', '<span title="' . htmlspecialchars($fields[$key]["full_type"]) . '">' . htmlspecialchars($key) . '</span>', $fields, $key);
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
39 }
40
41 /** Links after select heading
42 * @param array result of SHOW TABLE STATUS
43 * @return string
44 */
45 function adminer_select_links($table_status) {
46 global $SELF;
47 return call_adminer('select_links', '<a href="' . htmlspecialchars($SELF) . (isset($table_status["Engine"]) ? 'table=' : 'view=') . urlencode($_GET['select']) . '">' . lang('Table structure') . '</a>', $table_status);
48 }
49
c74c06a Don't modify $query by adminer_select_query
jakubvrana authored Jul 11, 2009
50 /** Query printed in select before execution
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
51 * @param string query to be executed
52 * @return string
53 */
54 function adminer_select_query($query) {
55 global $SELF;
56 // it would be nice if $query can be passed by reference and printed value would be returned but call_user() doesn't allow reference parameters
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
57 return call_adminer('select_query', "<p><code class='jush-sql'>" . htmlspecialchars($query) . "</code> <a href='" . htmlspecialchars($SELF) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>\n", $query);
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
58 }
59
228e43a Row descriptions in select
jakubvrana authored Jul 20, 2009
60 /** Descriptions of selected data
61 * @param array all data to print
62 * @param array foreign keys
63 * @return array
64 */
65 function adminer_row_descriptions($rows, $foreign_keys) {
66 return call_adminer('row_descriptions', $rows, $rows, $foreign_keys);
67 }
68
ba90d60 Introduce adminer_select_val
jakubvrana authored Jul 14, 2009
69 /** Value printed in select table
70 * @param string escaped value to print
791ea4f Comment
jakubvrana authored Jul 15, 2009
71 * @param string link to foreign key
72 * @return string
ba90d60 Introduce adminer_select_val
jakubvrana authored Jul 14, 2009
73 */
74 function adminer_select_val($val, $link) {
75 return call_adminer('select_val', ($link ? '<a href="' . $link . '">' . $val . '</a>' : $val), $val, $link);
76 }
77
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
78 /** Query printed after execution in the message
79 * @param string executed query
80 * @return string
81 */
82 function adminer_message_query($query) {
83 global $SELF;
84 $id = "sql-" . count($_SESSION["messages"]);
04a3f5b Save history in adminer_message_query
jakubvrana authored Jul 16, 2009
85 $_SESSION["history"][$_GET["server"]][$_GET["db"]][] = $query;
86 return call_adminer('message_query', " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><div id='$id' class='hidden'><pre class='jush-sql'>" . htmlspecialchars($query) . '</pre><a href="' . htmlspecialchars($SELF . 'sql=&history=' . (count($_SESSION["history"][$_GET["server"]][$_GET["db"]]) - 1)) . '">' . lang('Edit') . '</a></div>', $query);
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
87 }
88
89 /** Prints navigation after Adminer title
90 * @param string can be "auth" if there is no database connection or "db" if there is no database selected
91 * @return bool true if default navigation should be printed
92 */
93 function adminer_navigation($missing) {
94 global $SELF;
95 if (call_adminer('navigation', true, $missing) && $missing != "auth") {
4a014a6 Always flush in navigation because table_status can take long
jakubvrana authored Jul 16, 2009
96 ob_flush();
97 flush();
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
98 $databases = get_databases();
99 ?>
b95f24e Editor: User friendly data editor
jakubvrana authored Jul 3, 2009
100 <form action="" method="post">
101 <p>
102 <a href="<?php echo htmlspecialchars($SELF); ?>sql="><?php echo lang('SQL command'); ?></a>
103 <a href="<?php echo htmlspecialchars($SELF); ?>dump=<?php echo urlencode(isset($_GET["table"]) ? $_GET["table"] : $_GET["select"]); ?>"><?php echo lang('Dump'); ?></a>
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
104 <input type="hidden" name="token" value="<?php echo $_SESSION["tokens"][$_GET["server"]]; ?>">
105 <input type="submit" name="logout" value="<?php echo lang('Logout'); ?>">
d2ba593 Browsers interpret <form><p></form> as <form><p></form></p>
jakubvrana authored Jul 14, 2009
106 </p>
b95f24e Editor: User friendly data editor
jakubvrana authored Jul 3, 2009
107 </form>
108 <form action="">
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
109 <p><?php if (strlen($_GET["server"])) { ?><input type="hidden" name="server" value="<?php echo htmlspecialchars($_GET["server"]); ?>"><?php } ?>
b95f24e Editor: User friendly data editor
jakubvrana authored Jul 3, 2009
110 <?php if ($databases) { ?>
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
111 <select name="db" onchange="this.form.submit();"><option value="">(<?php echo lang('database'); ?>)<?php echo optionlist($databases, $_GET["db"]); ?></select>
b95f24e Editor: User friendly data editor
jakubvrana authored Jul 3, 2009
112 <?php } else { ?>
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
113 <input name="db" value="<?php echo htmlspecialchars($_GET["db"]); ?>">
b95f24e Editor: User friendly data editor
jakubvrana authored Jul 3, 2009
114 <?php } ?>
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
115 <?php if (isset($_GET["sql"])) { ?><input type="hidden" name="sql" value=""><?php } ?>
116 <?php if (isset($_GET["schema"])) { ?><input type="hidden" name="schema" value=""><?php } ?>
117 <?php if (isset($_GET["dump"])) { ?><input type="hidden" name="dump" value=""><?php } ?>
118 <input type="submit" value="<?php echo lang('Use'); ?>"<?php echo ($databases ? " class='hidden'" : ""); ?>>
d2ba593 Browsers interpret <form><p></form> as <form><p></form></p>
jakubvrana authored Jul 14, 2009
119 </p>
b95f24e Editor: User friendly data editor
jakubvrana authored Jul 3, 2009
120 </form>
121 <?php
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
122 if ($missing != "db" && strlen($_GET["db"])) {
123 $table_status = table_status();
124 if (!$table_status) {
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
125 echo "<p class='message'>" . lang('No tables.') . "\n";
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
126 } else {
127 echo "<p>\n";
128 foreach ($table_status as $row) {
129 echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row["Name"]) . '">' . lang('select') . '</a> ';
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
130 echo '<a href="' . htmlspecialchars($SELF) . (isset($row["Rows"]) ? 'table' : 'view') . '=' . urlencode($row["Name"]) . '">' . adminer_table_name($row) . "</a><br>\n";
b95f24e Editor: User friendly data editor
jakubvrana authored Jul 3, 2009
131 }
132 }
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
133 echo '<p><a href="' . htmlspecialchars($SELF) . 'create=">' . lang('Create new table') . "</a>\n";
b95f24e Editor: User friendly data editor
jakubvrana authored Jul 3, 2009
134 }
135 }
2c445a8 Extensibility basics
jakubvrana authored Jul 3, 2009
136 }
Something went wrong with that request. Please try again.