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