Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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