Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 247 lines (229 sloc) 9.27 kb
2c445a8 Extensibility basics
jakubvrana authored
1 <?php
c16c57b E-mail sending
jakubvrana authored
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
2faa08c Customize login and login form
jakubvrana authored
24 /** Print login form
25 * @param string
26 * @return bool whether to display default login form
27 */
28 function adminer_login_form($username) {
29 if (call_adminer('login_form', true, $username)) {
30 ?>
0205440 HTML whitespace
jakubvrana authored
31 <table cellspacing="0">
32 <tr><th><?php echo lang('Server'); ?><td><input name="server" value="<?php echo htmlspecialchars($_GET["server"]); ?>">
33 <tr><th><?php echo lang('Username'); ?><td><input name="username" value="<?php echo htmlspecialchars($username); ?>">
34 <tr><th><?php echo lang('Password'); ?><td><input type="password" name="password">
35 </table>
2faa08c Customize login and login form
jakubvrana authored
36 <?php
37 }
38 }
39
40 /** Authorize the user
41 * @param string
42 * @param string
43 * @return bool
44 */
45 function adminer_login($login, $password) {
46 return call_adminer('login', true, $login, $password);
47 }
48
c16c57b E-mail sending
jakubvrana authored
49 /** Table caption used in navigation and headings
50 * @param array result of SHOW TABLE STATUS
51 * @return string
52 */
0ed4c1d Use SHOW TABLES in navigation for performance
jakubvrana authored
53 function adminer_table_name($table_status) {
54 return call_adminer('table_name', htmlspecialchars($table_status["Name"]), $table_status);
c16c57b E-mail sending
jakubvrana authored
55 }
56
57 /** Field caption used in select and edit
5034123 Apply field name with functions
jakubvrana authored
58 * @param array single field returned from fields()
c16c57b E-mail sending
jakubvrana authored
59 * @return string
60 */
5034123 Apply field name with functions
jakubvrana authored
61 function adminer_field_name($field) {
ba9c9a5 Display SQL function with braces in select heading
jakubvrana authored
62 return call_adminer('field_name', '<span title="' . htmlspecialchars($field["full_type"]) . '">' . htmlspecialchars($field["field"]) . '</span>', $field);
c16c57b E-mail sending
jakubvrana authored
63 }
64
65 /** Links after select heading
66 * @param array result of SHOW TABLE STATUS
67 * @return string
68 */
69 function adminer_select_links($table_status) {
70 global $SELF;
0ed4c1d Use SHOW TABLES in navigation for performance
jakubvrana authored
71 return call_adminer('select_links', '<a href="' . htmlspecialchars($SELF) . 'table=' . urlencode($_GET['select']) . '">' . lang('Table structure') . '</a>', $table_status);
c16c57b E-mail sending
jakubvrana authored
72 }
73
e5de7ef Separate backward keys
jakubvrana authored
74 /** Find backward keys for table
75 * @param string
76 * @return array $return[$target_table][$key_name][$target_column] = $source_column;
77 */
78 function adminer_backward_keys($table) {
79 return call_adminer('backward_keys', array(), $table);
80 }
81
c74c06a Don't modify $query by adminer_select_query
jakubvrana authored
82 /** Query printed in select before execution
c16c57b E-mail sending
jakubvrana authored
83 * @param string query to be executed
84 * @return string
85 */
86 function adminer_select_query($query) {
87 global $SELF;
88 // 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
89 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
90 }
91
1e4d11e Select from foreign keys in Editor
jakubvrana authored
92 /** Description of a row in a table
93 * @param string
94 * @return string SQL expression, empty string for no description
95 */
96 function adminer_row_description($table) {
97 return call_adminer('row_description', "", $table);
98 }
99
100 /** Get descriptions of selected data
228e43a Row descriptions in select
jakubvrana authored
101 * @param array all data to print
1e4d11e Select from foreign keys in Editor
jakubvrana authored
102 * @param array
228e43a Row descriptions in select
jakubvrana authored
103 * @return array
104 */
105 function adminer_row_descriptions($rows, $foreign_keys) {
106 return call_adminer('row_descriptions', $rows, $rows, $foreign_keys);
107 }
108
ba90d60 Introduce adminer_select_val
jakubvrana authored
109 /** Value printed in select table
110 * @param string escaped value to print
791ea4f Comment
jakubvrana authored
111 * @param string link to foreign key
78e49f0 Pass $field to select_val
jakubvrana authored
112 * @param array single field returned from fields()
791ea4f Comment
jakubvrana authored
113 * @return string
ba90d60 Introduce adminer_select_val
jakubvrana authored
114 */
78e49f0 Pass $field to select_val
jakubvrana authored
115 function adminer_select_val($val, $link, $field) {
116 $return = ($field["type"] == "char" ? "<code>$val</code>" : $val);
117 return call_adminer('select_val', ($link ? "<a href=\"$link\">$return</a>" : $return), $val, $link);
ba90d60 Introduce adminer_select_val
jakubvrana authored
118 }
119
c16c57b E-mail sending
jakubvrana authored
120 /** Query printed after execution in the message
121 * @param string executed query
122 * @return string
123 */
124 function adminer_message_query($query) {
125 global $SELF;
126 $id = "sql-" . count($_SESSION["messages"]);
04a3f5b Save history in adminer_message_query
jakubvrana authored
127 $_SESSION["history"][$_GET["server"]][$_GET["db"]][] = $query;
128 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
129 }
130
4921235 Hide edit functions in Editor
jakubvrana authored
131 /** Functions displayed in edit form
132 * @param array single field from fields()
133 * @return array
134 */
135 function adminer_edit_functions($field) {
136 $return = array("");
137 if (!isset($_GET["default"])) {
138 if (ereg('char|date|time', $field["type"])) {
139 $return = (ereg('char', $field["type"]) ? array("", "md5", "sha1", "password", "uuid") : array("", "now")); //! JavaScript for disabling maxlength
140 }
141 if (!isset($_GET["call"]) && (isset($_GET["select"]) || where($_GET))) {
142 // relative functions
143 if (ereg('int|float|double|decimal', $field["type"])) {
144 $return = array("", "+", "-");
145 }
146 if (ereg('date', $field["type"])) {
147 $return[] = "+ interval";
148 $return[] = "- interval";
149 }
150 if (ereg('time', $field["type"])) {
151 $return[] = "addtime";
152 $return[] = "subtime";
153 }
154 }
155 }
156 if ($field["null"] || isset($_GET["default"])) {
157 array_unshift($return, "NULL");
158 }
1e4d11e Select from foreign keys in Editor
jakubvrana authored
159 return call_adminer('edit_functions', (isset($_GET["select"]) ? array("orig" => lang('original')) : array()) + $return, $field);
160 }
161
162 /** Get options to display edit field
163 * @param string table name
164 * @param array single field from fields()
165 * @return array options for <select> or empty to display <input>
166 */
167 function adminer_edit_input($table, $field) {
168 return call_adminer('edit_input', false, $table, $field);
4921235 Hide edit functions in Editor
jakubvrana authored
169 }
170
a78c941 Empty value in Editor as NULL
jakubvrana authored
171 /** Process sent input
172 * @param string field name
173 * @param array single field from fields()
174 * @return string expression to use in a query
175 */
176 function adminer_process_input($name, $field) {
177 global $dbh;
178 $idf = bracket_escape($name);
179 $function = $_POST["function"][$idf];
180 $value = $_POST["fields"][$idf];
181 $return = $dbh->quote($value);
182 if (ereg('^(now|uuid)$', $function)) {
183 $return = "$function()";
184 } elseif (ereg('^[+-]$', $function)) {
185 $return = idf_escape($name) . " $function $return";
186 } elseif (ereg('^[+-] interval$', $function)) {
187 $return = idf_escape($name) . " $function " . (preg_match("~^([0-9]+|'[0-9.: -]') [A-Z_]+$~i", $value) ? $value : $return);
188 } elseif (ereg('^(addtime|subtime)$', $function)) {
189 $return = "$function(" . idf_escape($name) . ", $return)";
190 } elseif (ereg('^(md5|sha1|password)$', $function)) {
191 $return = "$function($return)";
192 } elseif (ereg('date|time', $field["type"]) && $value == "CURRENT_TIMESTAMP") {
193 $return = $value;
194 }
195 return call_adminer('process_input', $return, $name, $field);
196 }
197
c16c57b E-mail sending
jakubvrana authored
198 /** Prints navigation after Adminer title
199 * @param string can be "auth" if there is no database connection or "db" if there is no database selected
200 * @return bool true if default navigation should be printed
201 */
202 function adminer_navigation($missing) {
0ed4c1d Use SHOW TABLES in navigation for performance
jakubvrana authored
203 global $SELF, $dbh;
c16c57b E-mail sending
jakubvrana authored
204 if (call_adminer('navigation', true, $missing) && $missing != "auth") {
4a014a6 Always flush in navigation because table_status can take long
jakubvrana authored
205 ob_flush();
206 flush();
c16c57b E-mail sending
jakubvrana authored
207 $databases = get_databases();
208 ?>
b95f24e Editor: User friendly data editor
jakubvrana authored
209 <form action="" method="post">
210 <p>
211 <a href="<?php echo htmlspecialchars($SELF); ?>sql="><?php echo lang('SQL command'); ?></a>
212 <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
213 <input type="hidden" name="token" value="<?php echo $_SESSION["tokens"][$_GET["server"]]; ?>">
214 <input type="submit" name="logout" value="<?php echo lang('Logout'); ?>">
d2ba593 Browsers interpret <form><p></form> as <form><p></form></p>
jakubvrana authored
215 </p>
b95f24e Editor: User friendly data editor
jakubvrana authored
216 </form>
217 <form action="">
ace55ed HTML instead of XHTML
jakubvrana authored
218 <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
219 <?php if ($databases) { ?>
ace55ed HTML instead of XHTML
jakubvrana authored
220 <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
221 <?php } else { ?>
ace55ed HTML instead of XHTML
jakubvrana authored
222 <input name="db" value="<?php echo htmlspecialchars($_GET["db"]); ?>">
b95f24e Editor: User friendly data editor
jakubvrana authored
223 <?php } ?>
ace55ed HTML instead of XHTML
jakubvrana authored
224 <?php if (isset($_GET["sql"])) { ?><input type="hidden" name="sql" value=""><?php } ?>
225 <?php if (isset($_GET["schema"])) { ?><input type="hidden" name="schema" value=""><?php } ?>
226 <?php if (isset($_GET["dump"])) { ?><input type="hidden" name="dump" value=""><?php } ?>
227 <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
228 </p>
b95f24e Editor: User friendly data editor
jakubvrana authored
229 </form>
230 <?php
c16c57b E-mail sending
jakubvrana authored
231 if ($missing != "db" && strlen($_GET["db"])) {
0ed4c1d Use SHOW TABLES in navigation for performance
jakubvrana authored
232 $result = $dbh->query("SHOW TABLES");
233 if (!$result->num_rows) {
ace55ed HTML instead of XHTML
jakubvrana authored
234 echo "<p class='message'>" . lang('No tables.') . "\n";
c16c57b E-mail sending
jakubvrana authored
235 } else {
236 echo "<p>\n";
0ed4c1d Use SHOW TABLES in navigation for performance
jakubvrana authored
237 while ($row = $result->fetch_row()) {
238 echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row[0]) . '">' . lang('select') . '</a> ';
239 echo '<a href="' . htmlspecialchars($SELF) . 'table=' . urlencode($row[0]) . '">' . adminer_table_name(array("Name" => $row[0])) . "</a><br>\n"; //! Adminer::table_name may work with full table status
b95f24e Editor: User friendly data editor
jakubvrana authored
240 }
241 }
0ed4c1d Use SHOW TABLES in navigation for performance
jakubvrana authored
242 $result->free();
ace55ed HTML instead of XHTML
jakubvrana authored
243 echo '<p><a href="' . htmlspecialchars($SELF) . 'create=">' . lang('Create new table') . "</a>\n";
b95f24e Editor: User friendly data editor
jakubvrana authored
244 }
245 }
2c445a8 Extensibility basics
jakubvrana authored
246 }
Something went wrong with that request. Please try again.