Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 832 lines (781 sloc) 29.976 kb
2c445a8 Extensibility basics
jakubvrana authored
1 <?php
e641e5c @vrana Limit commands and import in customization (bug #3194432)
authored
2 // any method change in this file should be transferred to editor/include/adminer.inc.php and plugins/plugin.php
3
c64c4fd Adminer class
jakubvrana authored
4 class Adminer {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
5 /** @var array operators used in select, null for all operators */
6 var $operators;
c64c4fd Adminer class
jakubvrana authored
7
8 /** Name in title and navigation
3ebfdd3 @vrana Simpler customization of name() link
authored
9 * @return string HTML code
c64c4fd Adminer class
jakubvrana authored
10 */
11 function name() {
3ebfdd3 @vrana Simpler customization of name() link
authored
12 return "<a href='http://www.adminer.org/' id='h1'>Adminer</a>";
c64c4fd Adminer class
jakubvrana authored
13 }
14
15 /** Connection parameters
16 * @return array ($server, $username, $password)
17 */
18 function credentials() {
49565e0 @vrana Rename variables to avoid conflict with Adminer 2 sessions and enable…
authored
19 return array(SERVER, $_GET["username"], get_session("pwds"));
c64c4fd Adminer class
jakubvrana authored
20 }
21
95b4ea4 Permanent login
jakubvrana authored
22 /** Get key used for permanent login
23 * @return string cryptic string which gets combined with password
24 */
25 function permanentLogin() {
4ba2d85 @vrana Allow permanent login without customization
authored
26 return password_file();
95b4ea4 Permanent login
jakubvrana authored
27 }
28
c64c4fd Adminer class
jakubvrana authored
29 /** Identifier of selected database
30 * @return string
31 */
32 function database() {
3022dcb Define DB
jakubvrana authored
33 // should be used everywhere instead of DB
34 return DB;
c64c4fd Adminer class
jakubvrana authored
35 }
36
9db4259 @vrana Introduce Adminer::headers method
authored
37 /** Headers to send before HTML output
0f00277 @vrana Easier sending of default headers (customization)
authored
38 * @return bool true to send security headers
9db4259 @vrana Introduce Adminer::headers method
authored
39 */
40 function headers() {
0f00277 @vrana Easier sending of default headers (customization)
authored
41 return true;
9db4259 @vrana Introduce Adminer::headers method
authored
42 }
43
d8cba0e @vrana Allow own code in <head> (thanks to Nikolaj Vasilcuk)
authored
44 /** Print HTML code inside <head>
45 * @return bool true to link adminer.css if exists
46 */
47 function head() {
48 return true;
49 }
50
c64c4fd Adminer class
jakubvrana authored
51 /** Print login form
52 * @return null
53 */
3f5b683 Reintegrate sqlite branch
jakubvrana authored
54 function loginForm() {
b0d637b @vrana Avoid fatal errors
authored
55 global $drivers;
2faa08c Customize login and login form
jakubvrana authored
56 ?>
0205440 HTML whitespace
jakubvrana authored
57 <table cellspacing="0">
1d47454 @vrana Hide credentials for SQLite
authored
58 <tr><th><?php echo lang('System'); ?><td><?php echo html_select("driver", $drivers, DRIVER, "loginDriver(this);"); ?>
67e5cbd @vrana Port hint in login form
authored
59 <tr><th><?php echo lang('Server'); ?><td><input name="server" value="<?php echo h(SERVER); ?>" title="hostname[:port]">
4269b7b Auto-focus user-name in login form
jakubvrana authored
60 <tr><th><?php echo lang('Username'); ?><td><input id="username" name="username" value="<?php echo h($_GET["username"]); ?>">
0205440 HTML whitespace
jakubvrana authored
61 <tr><th><?php echo lang('Password'); ?><td><input type="password" name="password">
62 </table>
4269b7b Auto-focus user-name in login form
jakubvrana authored
63 <script type="text/javascript">
1d47454 @vrana Hide credentials for SQLite
authored
64 var username = document.getElementById('username');
65 username.focus();
66 username.form['driver'].onchange();
4269b7b Auto-focus user-name in login form
jakubvrana authored
67 </script>
2faa08c Customize login and login form
jakubvrana authored
68 <?php
8474399 Move Login button to customization
jakubvrana authored
69 echo "<p><input type='submit' value='" . lang('Login') . "'>\n";
4ba2d85 @vrana Allow permanent login without customization
authored
70 echo checkbox("permanent", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n";
2faa08c Customize login and login form
jakubvrana authored
71 }
c64c4fd Adminer class
jakubvrana authored
72
73 /** Authorize the user
74 * @param string
75 * @param string
76 * @return bool
77 */
78 function login($login, $password) {
79 return true;
97b8c7b Display images in Editor
jakubvrana authored
80 }
c64c4fd Adminer class
jakubvrana authored
81
82 /** Table caption used in navigation and headings
83 * @param array result of SHOW TABLE STATUS
5ee1407 @vrana Avoid double escaping
authored
84 * @return string HTML code, "" to ignore table
c64c4fd Adminer class
jakubvrana authored
85 */
86 function tableName($tableStatus) {
689699a Shortcut for htmlspecialchars
jakubvrana authored
87 return h($tableStatus["Name"]);
c64c4fd Adminer class
jakubvrana authored
88 }
89
90 /** Field caption used in select and edit
91 * @param array single field returned from fields()
6c97b80 Display only first five columns in Editor example
jakubvrana authored
92 * @param int order of column in select
5ee1407 @vrana Avoid double escaping
authored
93 * @return string HTML code, "" to ignore field
c64c4fd Adminer class
jakubvrana authored
94 */
6c97b80 Display only first five columns in Editor example
jakubvrana authored
95 function fieldName($field, $order = 0) {
689699a Shortcut for htmlspecialchars
jakubvrana authored
96 return '<span title="' . h($field["full_type"]) . '">' . h($field["field"]) . '</span>';
c64c4fd Adminer class
jakubvrana authored
97 }
98
f2ed237 Display table links above table structure
jakubvrana authored
99 /** Print links after select heading
c64c4fd Adminer class
jakubvrana authored
100 * @param array result of SHOW TABLE STATUS
294b10b Highlight current link
jakubvrana authored
101 * @param string new item options, NULL for no new item
f2ed237 Display table links above table structure
jakubvrana authored
102 * @return null
c64c4fd Adminer class
jakubvrana authored
103 */
f2ed237 Display table links above table structure
jakubvrana authored
104 function selectLinks($tableStatus, $set = "") {
294b10b Highlight current link
jakubvrana authored
105 echo '<p class="tabs">';
2d8a2de Change table operations descriptions
jakubvrana authored
106 $links = array("select" => lang('Select data'), "table" => lang('Show structure'));
da6f1f8 @vrana Driver specific view detection
authored
107 if (is_view($tableStatus)) {
294b10b Highlight current link
jakubvrana authored
108 $links["view"] = lang('Alter view');
3f5b683 Reintegrate sqlite branch
jakubvrana authored
109 } else {
110 $links["create"] = lang('Alter table');
f2ed237 Display table links above table structure
jakubvrana authored
111 }
112 if (isset($set)) {
294b10b Highlight current link
jakubvrana authored
113 $links["edit"] = lang('New item');
114 }
115 foreach ($links as $key => $val) {
8ad4809 @vrana Use class="active" instead of <b>
authored
116 echo " <a href='" . h(ME) . "$key=" . urlencode($tableStatus["Name"]) . ($key == "edit" ? $set : "") . "'" . bold(isset($_GET[$key])) . ">$val</a>";
f2ed237 Display table links above table structure
jakubvrana authored
117 }
118 echo "\n";
c64c4fd Adminer class
jakubvrana authored
119 }
120
753909e @vrana Support for virtual foreign keys
authored
121 /** Get foreign keys for table
122 * @param string
123 * @return array same format as foreign_keys()
124 */
125 function foreignKeys($table) {
126 return foreign_keys($table);
127 }
128
c64c4fd Adminer class
jakubvrana authored
129 /** Find backward keys for table
130 * @param string
09e93de Move backward keys to Editor
jakubvrana authored
131 * @param string
132 * @return array $return[$target_table]["keys"][$key_name][$target_column] = $source_column; $return[$target_table]["name"] = $this->tableName($target_table);
c64c4fd Adminer class
jakubvrana authored
133 */
09e93de Move backward keys to Editor
jakubvrana authored
134 function backwardKeys($table, $tableName) {
c64c4fd Adminer class
jakubvrana authored
135 return array();
136 }
137
09e93de Move backward keys to Editor
jakubvrana authored
138 /** Print backward keys for row
139 * @param array result of $this->backwardKeys()
140 * @param array
141 * @return null
142 */
143 function backwardKeysPrint($backwardKeys, $row) {
144 }
145
c64c4fd Adminer class
jakubvrana authored
146 /** Query printed in select before execution
147 * @param string query to be executed
148 * @return string
149 */
150 function selectQuery($query) {
e672694 @vrana Rename $driver to $jush
authored
151 global $jush;
931f7ef @vrana Fix inline edit in IE9
authored
152 return "<p><a href='" . h(remove_from_uri("page")) . "&amp;page=last' title='" . lang('Last page') . "'>&gt;&gt;</a> <code class='jush-$jush'>" . h(str_replace("\n", " ", $query)) . "</code> <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a></p>\n"; // </p> - required for IE9 inline edit
c64c4fd Adminer class
jakubvrana authored
153 }
154
155 /** Description of a row in a table
156 * @param string
157 * @return string SQL expression, empty string for no description
158 */
159 function rowDescription($table) {
160 return "";
161 }
162
163 /** Get descriptions of selected data
164 * @param array all data to print
165 * @param array
166 * @return array
167 */
168 function rowDescriptions($rows, $foreignKeys) {
169 return $rows;
170 }
171
172 /** Value printed in select table
a0def47 Date localization
jakubvrana authored
173 * @param string HTML-escaped value to print
c64c4fd Adminer class
jakubvrana authored
174 * @param string link to foreign key
175 * @param array single field returned from fields()
176 * @return string
177 */
178 function selectVal($val, $link, $field) {
c64557a @vrana Support 'character varying'
authored
179 $return = ($val != "<i>NULL</i>" && ereg("char|binary", $field["type"]) && !ereg("var", $field["type"]) ? "<code>$val</code>" : $val);
5a73c01 @vrana Treat binary type as hex
authored
180 if (ereg('blob|bytea|raw|file', $field["type"]) && !is_utf8($val)) {
7197ab1 @vrana Report correct length of blob (bug #3070569)
authored
181 $return = lang('%d byte(s)', strlen(html_entity_decode($val, ENT_QUOTES)));
4921235 Hide edit functions in Editor
jakubvrana authored
182 }
12c042c Function htmlspecialchars now uses ENT_QUOTES
jakubvrana authored
183 return ($link ? "<a href='$link'>$return</a>" : $return);
c64c4fd Adminer class
jakubvrana authored
184 }
185
a0def47 Date localization
jakubvrana authored
186 /** Value conversion used in select and edit
187 * @param string
188 * @param array single field returned from fields()
2011428 Use LIKE operator in Editor
jakubvrana authored
189 * @return string
a0def47 Date localization
jakubvrana authored
190 */
191 function editVal($val, $field) {
5a73c01 @vrana Treat binary type as hex
authored
192 return (ereg("binary", $field["type"]) ? reset(unpack("H*", $val)) : $val);
a0def47 Date localization
jakubvrana authored
193 }
194
d24ad78 Select boxes customization
jakubvrana authored
195 /** Print columns box in select
d2c513d @vrana Column names customization (bug #3194500)
authored
196 * @param array result of selectColumnsProcess()[0]
d24ad78 Select boxes customization
jakubvrana authored
197 * @param array selectable columns
198 * @return null
199 */
200 function selectColumnsPrint($select, $columns) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
201 global $functions, $grouping;
dc667ea Hide select export and import
jakubvrana authored
202 print_fieldset("select", lang('Select'), $select);
d24ad78 Select boxes customization
jakubvrana authored
203 $i = 0;
3f5b683 Reintegrate sqlite branch
jakubvrana authored
204 $fun_group = array(lang('Functions') => $functions, lang('Aggregation') => $grouping);
d24ad78 Select boxes customization
jakubvrana authored
205 foreach ($select as $key => $val) {
206 $val = $_GET["columns"][$key];
0698409 Utilize html_select
jakubvrana authored
207 echo "<div>" . html_select("columns[$i][fun]", array(-1 => "") + $fun_group, $val["fun"]);
3f5b683 Reintegrate sqlite branch
jakubvrana authored
208 echo "(<select name='columns[$i][col]'><option>" . optionlist($columns, $val["col"], true) . "</select>)</div>\n";
d24ad78 Select boxes customization
jakubvrana authored
209 $i++;
210 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored
211 echo "<div>" . html_select("columns[$i][fun]", array(-1 => "") + $fun_group, "", "this.nextSibling.nextSibling.onchange();");
212 echo "(<select name='columns[$i][col]' onchange='selectAddRow(this);'><option>" . optionlist($columns, null, true) . "</select>)</div>\n";
d24ad78 Select boxes customization
jakubvrana authored
213 echo "</div></fieldset>\n";
214 }
215
216 /** Print search box in select
217 * @param array result of selectSearchProcess()
218 * @param array selectable columns
219 * @param array
220 * @return null
221 */
222 function selectSearchPrint($where, $columns, $indexes) {
dc667ea Hide select export and import
jakubvrana authored
223 print_fieldset("search", lang('Search'), $where);
d24ad78 Select boxes customization
jakubvrana authored
224 foreach ($indexes as $i => $index) {
225 if ($index["type"] == "FULLTEXT") {
689699a Shortcut for htmlspecialchars
jakubvrana authored
226 echo "(<i>" . implode("</i>, <i>", array_map('h', $index["columns"])) . "</i>) AGAINST";
227 echo " <input name='fulltext[$i]' value='" . h($_GET["fulltext"][$i]) . "'>";
6b30cfa Separate checkbox
jakubvrana authored
228 echo checkbox("boolean[$i]", 1, isset($_GET["boolean"][$i]), "BOOL");
d24ad78 Select boxes customization
jakubvrana authored
229 echo "<br>\n";
230 }
231 }
232 $i = 0;
233 foreach ((array) $_GET["where"] as $val) {
7352c28 Replace strlen() by != ""
jakubvrana authored
234 if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
235 echo "<div><select name='where[$i][col]'><option value=''>(" . lang('anywhere') . ")" . optionlist($columns, $val["col"], true) . "</select>";
0698409 Utilize html_select
jakubvrana authored
236 echo html_select("where[$i][op]", $this->operators, $val["op"]);
689699a Shortcut for htmlspecialchars
jakubvrana authored
237 echo "<input name='where[$i][val]' value='" . h($val["val"]) . "'></div>\n";
d24ad78 Select boxes customization
jakubvrana authored
238 $i++;
239 }
240 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored
241 echo "<div><select name='where[$i][col]' onchange='selectAddRow(this);'><option value=''>(" . lang('anywhere') . ")" . optionlist($columns, null, true) . "</select>";
675ac01 @vrana Ability to search by expression in select (bug #3158017)
authored
242 echo html_select("where[$i][op]", $this->operators, "=");
d24ad78 Select boxes customization
jakubvrana authored
243 echo "<input name='where[$i][val]'></div>\n";
244 echo "</div></fieldset>\n";
245 }
246
247 /** Print order box in select
248 * @param array result of selectOrderProcess()
249 * @param array selectable columns
250 * @param array
251 * @return null
252 */
253 function selectOrderPrint($order, $columns, $indexes) {
dc667ea Hide select export and import
jakubvrana authored
254 print_fieldset("sort", lang('Sort'), $order);
d24ad78 Select boxes customization
jakubvrana authored
255 $i = 0;
256 foreach ((array) $_GET["order"] as $key => $val) {
257 if (isset($columns[$val])) {
258 echo "<div><select name='order[$i]'><option>" . optionlist($columns, $val, true) . "</select>";
6b30cfa Separate checkbox
jakubvrana authored
259 echo checkbox("desc[$i]", 1, isset($_GET["desc"][$key]), lang('descending')) . "</div>\n";
d24ad78 Select boxes customization
jakubvrana authored
260 $i++;
261 }
262 }
3c5c0f0 Use camelCase in JavaScript
jakubvrana authored
263 echo "<div><select name='order[$i]' onchange='selectAddRow(this);'><option>" . optionlist($columns, null, true) . "</select>";
e25e780 @vrana DESC labels (bug #3192356)
authored
264 echo "<label><input type='checkbox' name='desc[$i]' value='1'>" . lang('descending') . "</label></div>\n"; // not checkbox() to allow selectAddRow()
d24ad78 Select boxes customization
jakubvrana authored
265 echo "</div></fieldset>\n";
266 }
267
268 /** Print limit box in select
269 * @param string result of selectLimitProcess()
270 * @return null
271 */
272 function selectLimitPrint($limit) {
273 echo "<fieldset><legend>" . lang('Limit') . "</legend><div>"; // <div> for easy styling
689699a Shortcut for htmlspecialchars
jakubvrana authored
274 echo "<input name='limit' size='3' value='" . h($limit) . "'>";
d24ad78 Select boxes customization
jakubvrana authored
275 echo "</div></fieldset>\n";
276 }
277
278 /** Print text length box in select
279 * @param string result of selectLengthProcess()
280 * @return null
281 */
282 function selectLengthPrint($text_length) {
283 if (isset($text_length)) {
284 echo "<fieldset><legend>" . lang('Text length') . "</legend><div>";
689699a Shortcut for htmlspecialchars
jakubvrana authored
285 echo '<input name="text_length" size="3" value="' . h($text_length) . '">';
d24ad78 Select boxes customization
jakubvrana authored
286 echo "</div></fieldset>\n";
287 }
288 }
289
290 /** Print action box in select
291 * @return null
292 */
293 function selectActionPrint() {
294 echo "<fieldset><legend>" . lang('Action') . "</legend><div>";
295 echo "<input type='submit' value='" . lang('Select') . "'>";
296 echo "</div></fieldset>\n";
297 }
298
e641e5c @vrana Limit commands and import in customization (bug #3194432)
authored
299 /** Print command box in select
300 * @return bool whether to print default commands
301 */
302 function selectCommandPrint() {
303 return !information_schema(DB);
304 }
305
306 /** Print import box in select
307 * @return bool whether to print default import
308 */
309 function selectImportPrint() {
310 return true;
311 }
312
1a6a73a Rename selectExtra to selectEmail
jakubvrana authored
313 /** Print extra text in the end of a select form
314 * @param array fields holding e-mails
1e55d47 User interface for e-mail {$name}
jakubvrana authored
315 * @param array selectable columns
1a6a73a Rename selectExtra to selectEmail
jakubvrana authored
316 * @return null
317 */
1e55d47 User interface for e-mail {$name}
jakubvrana authored
318 function selectEmailPrint($emailFields, $columns) {
1a6a73a Rename selectExtra to selectEmail
jakubvrana authored
319 }
320
d24ad78 Select boxes customization
jakubvrana authored
321 /** Process columns box in select
322 * @param array selectable columns
1e55d47 User interface for e-mail {$name}
jakubvrana authored
323 * @param array
d24ad78 Select boxes customization
jakubvrana authored
324 * @return array (array(select_expressions), array(group_expressions))
325 */
326 function selectColumnsProcess($columns, $indexes) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
327 global $functions, $grouping;
d24ad78 Select boxes customization
jakubvrana authored
328 $select = array(); // select expressions, empty for *
329 $group = array(); // expressions without aggregation - will be used for GROUP BY if an aggregation function is used
330 foreach ((array) $_GET["columns"] as $key => $val) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
331 if ($val["fun"] == "count" || (isset($columns[$val["col"]]) && (!$val["fun"] || in_array($val["fun"], $functions) || in_array($val["fun"], $grouping)))) {
d24ad78 Select boxes customization
jakubvrana authored
332 $select[$key] = apply_sql_function($val["fun"], (isset($columns[$val["col"]]) ? idf_escape($val["col"]) : "*"));
3f5b683 Reintegrate sqlite branch
jakubvrana authored
333 if (!in_array($val["fun"], $grouping)) {
d24ad78 Select boxes customization
jakubvrana authored
334 $group[] = $select[$key];
335 }
336 }
337 }
338 return array($select, $group);
339 }
340
341 /** Process search box in select
342 * @param array
343 * @param array
344 * @return array expressions to join by AND
345 */
07e1ae1 FOUND_ROWS only with GROUP BY
jakubvrana authored
346 function selectSearchProcess($fields, $indexes) {
7e644b4 @vrana Save bytes ($connection->quote shortcut)
authored
347 global $jush;
d24ad78 Select boxes customization
jakubvrana authored
348 $return = array();
349 foreach ($indexes as $i => $index) {
7352c28 Replace strlen() by != ""
jakubvrana authored
350 if ($index["type"] == "FULLTEXT" && $_GET["fulltext"][$i] != "") {
7e644b4 @vrana Save bytes ($connection->quote shortcut)
authored
351 $return[] = "MATCH (" . implode(", ", array_map('idf_escape', $index["columns"])) . ") AGAINST (" . q($_GET["fulltext"][$i]) . (isset($_GET["boolean"][$i]) ? " IN BOOLEAN MODE" : "") . ")";
d24ad78 Select boxes customization
jakubvrana authored
352 }
353 }
354 foreach ((array) $_GET["where"] as $val) {
7352c28 Replace strlen() by != ""
jakubvrana authored
355 if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
356 $cond = " $val[op]";
357 if (ereg('IN$', $val["op"])) {
358 $in = process_length($val["val"]);
359 $cond .= " (" . ($in != "" ? $in : "NULL") . ")";
675ac01 @vrana Ability to search by expression in select (bug #3158017)
authored
360 } elseif (!$val["op"]) {
361 $cond .= $val["val"]; // SQL injection
3f5b683 Reintegrate sqlite branch
jakubvrana authored
362 } elseif ($val["op"] == "LIKE %%") {
363 $cond = " LIKE " . $this->processInput($fields[$val["col"]], "%$val[val]%");
364 } elseif (!ereg('NULL$', $val["op"])) {
365 $cond .= " " . $this->processInput($fields[$val["col"]], $val["val"]);
366 }
7352c28 Replace strlen() by != ""
jakubvrana authored
367 if ($val["col"] != "") {
98b88eb Remove fulltext search without index
jakubvrana authored
368 $return[] = idf_escape($val["col"]) . $cond;
d24ad78 Select boxes customization
jakubvrana authored
369 } else {
98b88eb Remove fulltext search without index
jakubvrana authored
370 // find anywhere
371 $cols = array();
372 foreach ($fields as $name => $field) {
373 if (is_numeric($val["val"]) || !ereg('int|float|double|decimal', $field["type"])) {
d79b160 Illegal mix of collations
jakubvrana authored
374 $name = idf_escape($name);
782921b @vrana Finish SQLite
authored
375 $cols[] = ($jush == "sql" && ereg('char|text|enum|set', $field["type"]) && !ereg('^utf8', $field["collation"]) ? "CONVERT($name USING utf8)" : $name);
d24ad78 Select boxes customization
jakubvrana authored
376 }
377 }
d79b160 Illegal mix of collations
jakubvrana authored
378 $return[] = ($cols ? "(" . implode("$cond OR ", $cols) . "$cond)" : "0");
d24ad78 Select boxes customization
jakubvrana authored
379 }
380 }
381 }
382 return $return;
383 }
384
385 /** Process order box in select
386 * @param array
387 * @param array
388 * @return array expressions to join by comma
389 */
07e1ae1 FOUND_ROWS only with GROUP BY
jakubvrana authored
390 function selectOrderProcess($fields, $indexes) {
d24ad78 Select boxes customization
jakubvrana authored
391 $return = array();
392 foreach ((array) $_GET["order"] as $key => $val) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
393 if (isset($fields[$val]) || preg_match('~^((COUNT\\(DISTINCT |[A-Z0-9_]+\\()(`(?:[^`]|``)+`|"(?:[^"]|"")+")\\)|COUNT\\(\\*\\))$~', $val)) { //! MS SQL uses []
394 $return[] = (isset($fields[$val]) ? idf_escape($val) : $val) . (isset($_GET["desc"][$key]) ? " DESC" : "");
d24ad78 Select boxes customization
jakubvrana authored
395 }
396 }
397 return $return;
398 }
399
400 /** Process limit box in select
401 * @return string expression to use in LIMIT, will be escaped
402 */
403 function selectLimitProcess() {
404 return (isset($_GET["limit"]) ? $_GET["limit"] : "30");
405 }
406
407 /** Process length box in select
408 * @return string number of characters to shorten texts, will be escaped
409 */
410 function selectLengthProcess() {
411 return (isset($_GET["text_length"]) ? $_GET["text_length"] : "100");
412 }
413
c64c4fd Adminer class
jakubvrana authored
414 /** Process extras in select form
415 * @param array AND conditions
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored
416 * @param array
c64c4fd Adminer class
jakubvrana authored
417 * @return bool true if processed, false to process other parts of form
418 */
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored
419 function selectEmailProcess($where, $foreignKeys) {
c64c4fd Adminer class
jakubvrana authored
420 return false;
421 }
422
423 /** Query printed after execution in the message
424 * @param string executed query
425 * @return string
426 */
427 function messageQuery($query) {
e672694 @vrana Rename $driver to $jush
authored
428 global $jush;
79fa7da @vrana Minimize the chance of displaying message on different page (thanks t…
authored
429 static $count = 0;
be49e08 Improve session restarting
jakubvrana authored
430 restart_session();
79fa7da @vrana Minimize the chance of displaying message on different page (thanks t…
authored
431 $id = "sql-" . ($count++);
49565e0 @vrana Rename variables to avoid conflict with Adminer 2 sessions and enable…
authored
432 $history = &get_session("queries");
0bc930c @vrana Avoid big ternary (save memory)
authored
433 if (strlen($query) > 1e6) { // not DB - reset in drop database
434 $query = ereg_replace('[\x80-\xFF]+$', '', substr($query, 0, 1e6)) . "\n..."; // [\x80-\xFF] - valid UTF-8, \n - can end by one-line comment
435 }
8372913 @vrana Save bytes
authored
436 $history[$_GET["db"]][] = $query; // not DB - $_GET["db"] is changed in database.inc.php //! respect $_GET["ns"]
d8c7ea9 @vrana Highlighting only inside <code>
authored
437 return " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><div id='$id' class='hidden'><pre><code class='jush-$jush'>" . shorten_utf8($query, 1000) . '</code></pre><p><a href="' . h(str_replace("db=" . urlencode(DB), "db=" . urlencode($_GET["db"]), ME) . 'sql=&history=' . (count($history[$_GET["db"]]) - 1)) . '">' . lang('Edit') . '</a></div>';
c64c4fd Adminer class
jakubvrana authored
438 }
439
440 /** Functions displayed in edit form
441 * @param array single field from fields()
442 * @return array
443 */
444 function editFunctions($field) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
445 global $edit_functions;
02f7521 Fix input onchange
jakubvrana authored
446 $return = ($field["null"] ? "NULL/" : "");
3f5b683 Reintegrate sqlite branch
jakubvrana authored
447 foreach ($edit_functions as $key => $functions) {
448 if (!$key || (!isset($_GET["call"]) && (isset($_GET["select"]) || where($_GET)))) { // relative functions
449 foreach ($functions as $pattern => $val) {
450 if (!$pattern || ereg($pattern, $field["type"])) {
451 $return .= "/$val";
452 }
453 }
2671a47 @vrana No edit expression with set and binary
authored
454 if ($key && !ereg('set|blob|bytea|raw|file', $field["type"])) {
327b56b @vrana Ability to save expression in edit
authored
455 $return .= "/=";
456 }
309f681 Relative function concat
jakubvrana authored
457 }
4921235 Hide edit functions in Editor
jakubvrana authored
458 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored
459 return explode("/", $return);
4921235 Hide edit functions in Editor
jakubvrana authored
460 }
c64c4fd Adminer class
jakubvrana authored
461
462 /** Get options to display edit field
463 * @param string table name
464 * @param array single field from fields()
e1abcda Treat tinyint(1) as boolean
jakubvrana authored
465 * @param string attributes to use inside the tag
466 * @param string
467 * @return string custom input field or empty string for default
c64c4fd Adminer class
jakubvrana authored
468 */
e1abcda Treat tinyint(1) as boolean
jakubvrana authored
469 function editInput($table, $field, $attrs, $value) {
ec0282b Enum editing
jakubvrana authored
470 if ($field["type"] == "enum") {
fe06908 @vrana Allow redefining editInput for enum (bug #3048711)
authored
471 return (isset($_GET["select"]) ? "<label><input type='radio'$attrs value='-1' checked><i>" . lang('original') . "</i></label> " : "")
472 . ($field["null"] ? "<label><input type='radio'$attrs value=''" . (isset($value) || isset($_GET["select"]) ? "" : " checked") . "><i>NULL</i></label> " : "")
684e70d @vrana Search for empty enum
authored
473 . enum_input("radio", $attrs, $field, $value, 0) // 0 - empty
ec0282b Enum editing
jakubvrana authored
474 ;
475 }
476 return "";
4921235 Hide edit functions in Editor
jakubvrana authored
477 }
c64c4fd Adminer class
jakubvrana authored
478
479 /** Process sent input
480 * @param array single field from fields()
a0def47 Date localization
jakubvrana authored
481 * @param string
482 * @param string
c64c4fd Adminer class
jakubvrana authored
483 * @return string expression to use in a query
484 */
a0def47 Date localization
jakubvrana authored
485 function processInput($field, $value, $function = "") {
327b56b @vrana Ability to save expression in edit
authored
486 if ($function == "=") {
487 return $value; // SQL injection
488 }
a0def47 Date localization
jakubvrana authored
489 $name = $field["field"];
4ff2f03 @vrana Alter bit type default value
authored
490 $return = ($field["type"] == "bit" && ereg("^([0-9]+|b'[0-1]+')\$", $value) ? $value : q($value));
3f5b683 Reintegrate sqlite branch
jakubvrana authored
491 if (ereg('^(now|getdate|uuid)$', $function)) {
c64c4fd Adminer class
jakubvrana authored
492 $return = "$function()";
e4df0c6 @vrana MS SQL functions
authored
493 } elseif (ereg('^current_(date|timestamp)$', $function)) {
494 $return = $function;
3f5b683 Reintegrate sqlite branch
jakubvrana authored
495 } elseif (ereg('^([+-]|\\|\\|)$', $function)) {
c64c4fd Adminer class
jakubvrana authored
496 $return = idf_escape($name) . " $function $return";
497 } elseif (ereg('^[+-] interval$', $function)) {
5002b89 @vrana Big numbers without E
authored
498 $return = idf_escape($name) . " $function " . (preg_match("~^(\\d+|'[0-9.: -]') [A-Z_]+$~i", $value) ? $value : $return);
309f681 Relative function concat
jakubvrana authored
499 } elseif (ereg('^(addtime|subtime|concat)$', $function)) {
c64c4fd Adminer class
jakubvrana authored
500 $return = "$function(" . idf_escape($name) . ", $return)";
5a73c01 @vrana Treat binary type as hex
authored
501 } elseif (ereg('^(md5|sha1|password|encrypt|hex)$', $function)) {
c64c4fd Adminer class
jakubvrana authored
502 $return = "$function($return)";
503 }
5a73c01 @vrana Treat binary type as hex
authored
504 if (ereg("binary", $field["type"])) {
505 $return = "unhex($return)";
506 }
c64c4fd Adminer class
jakubvrana authored
507 return $return;
a78c941 Empty value in Editor as NULL
jakubvrana authored
508 }
c64c4fd Adminer class
jakubvrana authored
509
e40612a Use radio in export
jakubvrana authored
510 /** Returns export output options
be3410f @vrana Simplify dumpOutput, dumpFormat and dumpData methods
authored
511 * @return array
e40612a Use radio in export
jakubvrana authored
512 */
be3410f @vrana Simplify dumpOutput, dumpFormat and dumpData methods
authored
513 function dumpOutput() {
e40612a Use radio in export
jakubvrana authored
514 $return = array('text' => lang('open'), 'file' => lang('save'));
515 if (function_exists('gzencode')) {
516 $return['gz'] = 'gzip';
517 }
518 if (function_exists('bzcompress')) {
519 $return['bz2'] = 'bzip2';
520 }
521 // ZipArchive requires temporary file, ZIP can be created by gzcompress - see PEAR File_Archive
be3410f @vrana Simplify dumpOutput, dumpFormat and dumpData methods
authored
522 return $return;
e40612a Use radio in export
jakubvrana authored
523 }
524
525 /** Returns export format options
be3410f @vrana Simplify dumpOutput, dumpFormat and dumpData methods
authored
526 * @return array
e40612a Use radio in export
jakubvrana authored
527 */
be3410f @vrana Simplify dumpOutput, dumpFormat and dumpData methods
authored
528 function dumpFormat() {
e225d22 @vrana TSV export and import (bug #3097657)
authored
529 return array('sql' => 'SQL', 'csv' => 'CSV,', 'csv;' => 'CSV;', 'tsv' => 'TSV');
e40612a Use radio in export
jakubvrana authored
530 }
531
095d472 @vrana Customizable export
authored
532 /** Export table structure
533 * @param string
534 * @param string
535 * @param bool
536 * @return null prints data
537 */
538 function dumpTable($table, $style, $is_view = false) {
539 if ($_POST["format"] != "sql") {
540 echo "\xef\xbb\xbf"; // UTF-8 byte order mark
541 if ($style) {
542 dump_csv(array_keys(fields($table)));
543 }
544 } elseif ($style) {
545 $create = create_sql($table, $_POST["auto_increment"]);
546 if ($create) {
547 if ($style == "DROP+CREATE") {
548 echo "DROP " . ($is_view ? "VIEW" : "TABLE") . " IF EXISTS " . table($table) . ";\n";
549 }
550 if ($is_view) {
551 // remove DEFINER with current user
021e1e3 @vrana Allow % in view definer (thanks to Tomas Votruba)
authored
552 $create = preg_replace('~^([A-Z =]+) DEFINER=`' . preg_replace('~@(.*)~', '`@`(%|\\1)', logged_user()) . '`~', '\\1', $create); //! proper escaping of user
095d472 @vrana Customizable export
authored
553 }
554 echo ($style != "CREATE+ALTER" ? $create : ($is_view ? substr_replace($create, " OR REPLACE", 6, 0) : substr_replace($create, " IF NOT EXISTS", 12, 0))) . ";\n\n";
555 }
556 if ($style == "CREATE+ALTER" && !$is_view) {
557 // create procedure which iterates over original columns and adds new and removes old
558 $query = "SELECT COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE, COLLATION_NAME, COLUMN_TYPE, EXTRA, COLUMN_COMMENT FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = " . q($table) . " ORDER BY ORDINAL_POSITION";
559 echo "DELIMITER ;;
560 CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN
561 DECLARE _column_name, _collation_name, after varchar(64) DEFAULT '';
562 DECLARE _column_type, _column_default text;
563 DECLARE _is_nullable char(3);
564 DECLARE _extra varchar(30);
565 DECLARE _column_comment varchar(255);
566 DECLARE done, set_after bool DEFAULT 0;
567 DECLARE add_columns text DEFAULT '";
568 $fields = array();
569 $after = "";
570 foreach (get_rows($query) as $row) {
571 $default = $row["COLUMN_DEFAULT"];
572 $row["default"] = (isset($default) ? q($default) : "NULL");
573 $row["after"] = q($after); //! rgt AFTER lft, lft AFTER id doesn't work
574 $row["alter"] = escape_string(idf_escape($row["COLUMN_NAME"])
575 . " $row[COLUMN_TYPE]"
576 . ($row["COLLATION_NAME"] ? " COLLATE $row[COLLATION_NAME]" : "")
577 . (isset($default) ? " DEFAULT " . ($default == "CURRENT_TIMESTAMP" ? $default : $row["default"]) : "")
578 . ($row["IS_NULLABLE"] == "YES" ? "" : " NOT NULL")
579 . ($row["EXTRA"] ? " $row[EXTRA]" : "")
580 . ($row["COLUMN_COMMENT"] ? " COMMENT " . q($row["COLUMN_COMMENT"]) : "")
581 . ($after ? " AFTER " . idf_escape($after) : " FIRST")
582 );
583 echo ", ADD $row[alter]";
584 $fields[] = $row;
585 $after = $row["COLUMN_NAME"];
586 }
587 echo "';
588 DECLARE columns CURSOR FOR $query;
589 DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
590 SET @alter_table = '';
591 OPEN columns;
592 REPEAT
593 FETCH columns INTO _column_name, _column_default, _is_nullable, _collation_name, _column_type, _extra, _column_comment;
594 IF NOT done THEN
595 SET set_after = 1;
596 CASE _column_name";
597 foreach ($fields as $row) {
598 echo "
599 WHEN " . q($row["COLUMN_NAME"]) . " THEN
1c1537b @vrana Fix ALTER export: add columns together with modify
authored
600 SET add_columns = REPLACE(add_columns, ', ADD $row[alter]', IF(
601 _column_default <=> $row[default] AND _is_nullable = '$row[IS_NULLABLE]' AND _collation_name <=> " . (isset($row["COLLATION_NAME"]) ? "'$row[COLLATION_NAME]'" : "NULL") . " AND _column_type = " . q($row["COLUMN_TYPE"]) . " AND _extra = '$row[EXTRA]' AND _column_comment = " . q($row["COLUMN_COMMENT"]) . " AND after = $row[after]
602 , '', ', MODIFY $row[alter]'));"
603 ; //! don't replace in comment
095d472 @vrana Customizable export
authored
604 }
605 echo "
606 ELSE
607 SET @alter_table = CONCAT(@alter_table, ', DROP ', _column_name);
608 SET set_after = 0;
609 END CASE;
610 IF set_after THEN
611 SET after = _column_name;
612 END IF;
613 END IF;
614 UNTIL done END REPEAT;
615 CLOSE columns;
616 IF @alter_table != '' OR add_columns != '' THEN
617 SET alter_command = CONCAT(alter_command, 'ALTER TABLE " . table($table) . "', SUBSTR(CONCAT(add_columns, @alter_table), 2), ';\\n');
618 END IF;
619 END;;
620 DELIMITER ;
621 CALL adminer_alter(@adminer_alter);
622 DROP PROCEDURE adminer_alter;
623
624 ";
625 //! indexes
626 }
627 }
628 }
629
630 /** Export table data
631 * @param string
632 * @param string
be3410f @vrana Simplify dumpOutput, dumpFormat and dumpData methods
authored
633 * @param string
095d472 @vrana Customizable export
authored
634 * @return null prints data
635 */
be3410f @vrana Simplify dumpOutput, dumpFormat and dumpData methods
authored
636 function dumpData($table, $style, $query) {
095d472 @vrana Customizable export
authored
637 global $connection, $jush;
638 $max_packet = ($jush == "sqlite" ? 0 : 1048576); // default, minimum is 1024
639 if ($style) {
640 if ($_POST["format"] == "sql" && $style == "TRUNCATE+INSERT") {
641 echo truncate_sql($table) . ";\n";
642 }
15715b3 @vrana Export SQL command result (bug #3116854)
authored
643 if ($_POST["format"] == "sql") {
644 $fields = fields($table);
645 }
be3410f @vrana Simplify dumpOutput, dumpFormat and dumpData methods
authored
646 $result = $connection->query($query, 1); // 1 - MYSQLI_USE_RESULT //! enum and set as numbers
095d472 @vrana Customizable export
authored
647 if ($result) {
648 $insert = "";
649 $buffer = "";
650 while ($row = $result->fetch_assoc()) {
651 if ($_POST["format"] != "sql") {
15715b3 @vrana Export SQL command result (bug #3116854)
authored
652 if ($style == "table") {
653 dump_csv(array_keys($row));
654 $style = "INSERT";
655 }
095d472 @vrana Customizable export
authored
656 dump_csv($row);
657 } else {
658 if (!$insert) {
659 $insert = "INSERT INTO " . table($table) . " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ") VALUES";
660 }
661 foreach ($row as $key => $val) {
662 $row[$key] = (isset($val) ? (ereg('int|float|double|decimal', $fields[$key]["type"]) ? $val : q($val)) : "NULL"); //! columns looking like functions
663 }
664 $s = implode(",\t", $row);
665 if ($style == "INSERT+UPDATE") {
666 $set = array();
667 foreach ($row as $key => $val) {
668 $set[] = idf_escape($key) . " = $val";
669 }
670 echo "$insert ($s) ON DUPLICATE KEY UPDATE " . implode(", ", $set) . ";\n";
671 } else {
672 $s = ($max_packet ? "\n" : " ") . "($s)";
673 if (!$buffer) {
674 $buffer = $insert . $s;
baf2172 @vrana MySQL allows only (max_allow_packet - 3)-bytes queries (thanks to kluvi)
authored
675 } elseif (strlen($buffer) + 4 + strlen($s) < $max_packet) { // 4 - length specification
095d472 @vrana Customizable export
authored
676 $buffer .= ",$s";
677 } else {
baf2172 @vrana MySQL allows only (max_allow_packet - 3)-bytes queries (thanks to kluvi)
authored
678 echo "$buffer;\n";
095d472 @vrana Customizable export
authored
679 $buffer = $insert . $s;
680 }
681 }
682 }
683 }
684 if ($_POST["format"] == "sql" && $style != "INSERT+UPDATE" && $buffer) {
685 $buffer .= ";\n";
686 echo $buffer;
687 }
164cd3b @vrana Report errors in data export
authored
688 } elseif ($_POST["format"] == "sql") {
689 echo "-- " . str_replace("\n", " ", $connection->error) . "\n";
095d472 @vrana Customizable export
authored
690 }
691 }
692 }
693
694 /** Send headers for export
695 * @param string
696 * @param bool
697 * @return string extension
698 */
699 function dumpHeaders($identifier, $multi_table = false) {
700 $output = $_POST["output"];
701 $ext = ($_POST["format"] == "sql" ? "sql" : ($multi_table ? "tar" : "csv")); // multiple CSV packed to TAR
702 header("Content-Type: " .
703 ($output == "bz2" ? "application/x-bzip" :
704 ($output == "gz" ? "application/x-gzip" :
705 ($ext == "tar" ? "application/x-tar" :
706 ($ext == "sql" || $output != "file" ? "text/plain" : "text/csv") . "; charset=utf-8"
707 ))));
8ab6fff @vrana Centralize dump_headers
authored
708 if ($output == "bz2") {
095d472 @vrana Customizable export
authored
709 ob_start('bzcompress', 1e6);
710 }
8ab6fff @vrana Centralize dump_headers
authored
711 if ($output == "gz") {
095d472 @vrana Customizable export
authored
712 ob_start('gzencode', 1e6);
713 }
714 return $ext;
e40612a Use radio in export
jakubvrana authored
715 }
716
7416164 @vrana Homepage customization
authored
717 /** Print homepage
718 * @return bool whether to print default homepage
719 */
720 function homepage() {
721 echo '<p>' . ($_GET["ns"] == "" ? '<a href="' . h(ME) . 'database=">' . lang('Alter database') . "</a>\n" : "");
98e410f @vrana Move schema link to Adminer::homepage method
authored
722 echo (support("scheme") ? "<a href='" . h(ME) . "scheme='>" . ($_GET["ns"] != "" ? lang('Alter schema') : lang('Create schema')) . "</a>\n" : "");
33c4623 @vrana Hide schema link in homepage with no schema
authored
723 echo ($_GET["ns"] !== "" ? '<a href="' . h(ME) . 'schema=">' . lang('Database schema') . "</a>\n" : "");
16a72b4 @vrana Shortcut for database privileges
authored
724 echo (support("privileges") ? "<a href='" . h(ME) . "privileges='>" . lang('Privileges') . "</a>\n" : "");
7416164 @vrana Homepage customization
authored
725 return true;
726 }
727
c64c4fd Adminer class
jakubvrana authored
728 /** Prints navigation after Adminer title
d49903b @vrana Report invalid schema
authored
729 * @param string can be "auth" if there is no database connection, "db" if there is no database selected, "ns" with invalid schema
c64c4fd Adminer class
jakubvrana authored
730 * @return null
731 */
732 function navigation($missing) {
e672694 @vrana Rename $driver to $jush
authored
733 global $VERSION, $connection, $token, $jush, $drivers;
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored
734 ?>
735 <h1>
3ebfdd3 @vrana Simpler customization of name() link
authored
736 <?php echo $this->name(); ?> <span class="version"><?php echo $VERSION; ?></span>
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored
737 <a href="http://www.adminer.org/#download" id="version"><?php echo (version_compare($VERSION, $_COOKIE["adminer_version"]) < 0 ? h($_COOKIE["adminer_version"]) : ""); ?></a>
738 </h1>
739 <?php
605b093 @vrana List authentications
authored
740 if ($missing == "auth") {
741 $first = true;
49565e0 @vrana Rename variables to avoid conflict with Adminer 2 sessions and enable…
authored
742 foreach ((array) $_SESSION["pwds"] as $driver => $servers) {
605b093 @vrana List authentications
authored
743 foreach ($servers as $server => $usernames) {
744 foreach ($usernames as $username => $password) {
745 if (isset($password)) {
746 if ($first) {
9bb0fdc @vrana Display login in auth form (regression)
authored
747 echo "<p onclick='eventStop(event);'>\n";
605b093 @vrana List authentications
authored
748 $first = false;
749 }
e672694 @vrana Rename $driver to $jush
authored
750 echo "<a href='" . h(auth_url($driver, $server, $username)) . "'>($drivers[$driver]) " . h($username . ($server != "" ? "@$server" : "")) . "</a><br>\n";
605b093 @vrana List authentications
authored
751 }
752 }
753 }
754 }
755 } else {
c64c4fd Adminer class
jakubvrana authored
756 $databases = get_databases();
757 ?>
b95f24e Editor: User friendly data editor
jakubvrana authored
758 <form action="" method="post">
fde1171 Add CSS classes (thanks to cvicebni ubor)
jakubvrana authored
759 <p class="logout">
f7d4587 @vrana Hide SQL command link in case of an error
authored
760 <?php
9d47d1e @vrana Whitespace
authored
761 if (DB == "" || !$missing) {
8ad4809 @vrana Use class="active" instead of <b>
authored
762 echo "<a href='" . h(ME) . "sql='" . bold(isset($_GET["sql"])) . ">" . lang('SQL command') . "</a>\n";
9d47d1e @vrana Whitespace
authored
763 if (support("dump")) {
29d7d6c @vrana Modify dump link in AJAX
authored
764 echo "<a href='" . h(ME) . "dump=" . urlencode(isset($_GET["table"]) ? $_GET["table"] : $_GET["select"]) . "' id='dump'" . bold(isset($_GET["dump"])) . ">" . lang('Dump') . "</a>\n";
9d47d1e @vrana Whitespace
authored
765 }
766 }
767 ?>
fbc668c @vrana Simplify JavaScript
authored
768 <input type="submit" name="logout" value="<?php echo lang('Logout'); ?>" onclick="eventStop(event);">
740ae10 @vrana Don't send incomplete forms
authored
769 <input type="hidden" name="token" value="<?php echo $token; ?>">
d2ba593 Browsers interpret <form><p></form> as <form><p></form></p>
jakubvrana authored
770 </p>
b95f24e Editor: User friendly data editor
jakubvrana authored
771 </form>
772 <form action="">
25cef1f Disable session.use_trans_sid to preserve export result
jakubvrana authored
773 <p>
3f5b683 Reintegrate sqlite branch
jakubvrana authored
774 <?php hidden_fields_get(); ?>
0698409 Utilize html_select
jakubvrana authored
775 <?php echo ($databases ? html_select("db", array("" => "(" . lang('database') . ")") + $databases, DB, "this.form.submit();") : '<input name="db" value="' . h(DB) . '">'); ?>
fbc668c @vrana Simplify JavaScript
authored
776 <input type="submit" value="<?php echo lang('Use'); ?>"<?php echo ($databases ? " class='hidden'" : ""); ?> onclick="eventStop(event);">
b95f24e Editor: User friendly data editor
jakubvrana authored
777 <?php
7352c28 Replace strlen() by != ""
jakubvrana authored
778 if ($missing != "db" && DB != "" && $connection->select_db(DB)) {
6420c58 Schema support for PostgreSQL
jakubvrana authored
779 if (support("scheme")) {
780 echo "<br>" . html_select("ns", array("" => "(" . lang('schema') . ")") + schemas(), $_GET["ns"], "this.form.submit();");
781 if ($_GET["ns"] != "") {
782 set_schema($_GET["ns"]);
8e81039 Link table names in SQL queries
jakubvrana authored
783 }
6420c58 Schema support for PostgreSQL
jakubvrana authored
784 }
f7d4587 @vrana Hide SQL command link in case of an error
authored
785 if ($_GET["ns"] !== "" && !$missing) {
8ad4809 @vrana Use class="active" instead of <b>
authored
786 echo '<p><a href="' . h(ME) . 'create="' . bold($_GET["create"] === "") . ">" . lang('Create new table') . "</a>\n";
6420c58 Schema support for PostgreSQL
jakubvrana authored
787 $tables = tables_list();
788 if (!$tables) {
789 echo "<p class='message'>" . lang('No tables.') . "\n";
790 } else {
791 $this->tablesPrint($tables);
792 $links = array();
793 foreach ($tables as $table => $type) {
794 $links[] = preg_quote($table, '/');
795 }
796 echo "<script type='text/javascript'>\n";
28f21aa @vrana Escape JavaScript strings (bug #3093243)
authored
797 echo "var jushLinks = { $jush: [ '" . js_escape(ME) . "table=\$&', /\\b(" . implode("|", $links) . ")\\b/g ] };\n";
6420c58 Schema support for PostgreSQL
jakubvrana authored
798 foreach (array("bac", "bra", "sqlite_quo", "mssql_bra") as $val) {
e672694 @vrana Rename $driver to $jush
authored
799 echo "jushLinks.$val = jushLinks.$jush;\n";
6420c58 Schema support for PostgreSQL
jakubvrana authored
800 }
4ff2f03 @vrana Alter bit type default value
authored
801 echo "var cmComplete = [ '" . implode("', '", array_map('js_escape', array_keys($tables))) . "' ];\n";
6420c58 Schema support for PostgreSQL
jakubvrana authored
802 echo "</script>\n";
e5969d4 Shorten code
jakubvrana authored
803 }
df0c4bb Simplify tablesPrint
jakubvrana authored
804 }
805 }
6420c58 Schema support for PostgreSQL
jakubvrana authored
806 echo (isset($_GET["sql"]) ? '<input type="hidden" name="sql" value="">'
807 : (isset($_GET["schema"]) ? '<input type="hidden" name="schema" value="">'
808 : (isset($_GET["dump"]) ? '<input type="hidden" name="dump" value="">'
809 : "")));
60c7ed9 @vrana MS SQL schema support
authored
810 echo "</p></form>\n";
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored
811 }
812 }
813
814 /** Prints table list in menu
df0c4bb Simplify tablesPrint
jakubvrana authored
815 * @param array
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored
816 * @return null
817 */
df0c4bb Simplify tablesPrint
jakubvrana authored
818 function tablesPrint($tables) {
819 echo "<p id='tables'>\n";
3f5b683 Reintegrate sqlite branch
jakubvrana authored
820 foreach ($tables as $table => $type) {
8ad4809 @vrana Use class="active" instead of <b>
authored
821 echo '<a href="' . h(ME) . 'select=' . urlencode($table) . '"' . bold($_GET["select"] == $table) . ">" . lang('select') . "</a> ";
822 echo '<a href="' . h(ME) . 'table=' . urlencode($table) . '"' . bold($_GET["table"] == $table) . ">" . $this->tableName(array("Name" => $table)) . "</a><br>\n"; //! Adminer::tableName may work with full table status
b95f24e Editor: User friendly data editor
jakubvrana authored
823 }
824 }
c64c4fd Adminer class
jakubvrana authored
825
2c445a8 Extensibility basics
jakubvrana authored
826 }
464d84a Define functions unconditionally
jakubvrana authored
827
828 $adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer);
3f5b683 Reintegrate sqlite branch
jakubvrana authored
829 if (!isset($adminer->operators)) {
830 $adminer->operators = $operators;
831 }
Something went wrong with that request. Please try again.