Skip to content
Newer
Older
100644 864 lines (811 sloc) 30.3 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]">
8be29af @vrana Allow specifying database in login form (bug #3499359)
authored May 14, 2012
70 <tr><th><?php echo lang('Database'); ?><td><input name="auth[db]" value="<?php echo h($_GET["db"]); ?>">
0205440 HTML whitespace
jakubvrana authored Jul 21, 2009
71 </table>
4269b7b Auto-focus user-name in login form
jakubvrana authored Apr 26, 2010
72 <script type="text/javascript">
1d47454 @vrana Hide credentials for SQLite
authored Jan 31, 2011
73 var username = document.getElementById('username');
74 username.focus();
f595f93 @vrana Use namespace in login form
authored May 14, 2012
75 username.form['auth[driver]'].onchange();
4269b7b Auto-focus user-name in login form
jakubvrana authored Apr 26, 2010
76 </script>
2faa08c Customize login and login form
jakubvrana authored Jul 21, 2009
77 <?php
8474399 Move Login button to customization
jakubvrana authored Dec 18, 2009
78 echo "<p><input type='submit' value='" . lang('Login') . "'>\n";
f595f93 @vrana Use namespace in login form
authored May 14, 2012
79 echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n";
2faa08c Customize login and login form
jakubvrana authored Jul 21, 2009
80 }
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
81
82 /** Authorize the user
83 * @param string
84 * @param string
85 * @return bool
86 */
87 function login($login, $password) {
88 return true;
97b8c7b Display images in Editor
jakubvrana authored Jul 24, 2009
89 }
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
90
91 /** Table caption used in navigation and headings
92 * @param array result of SHOW TABLE STATUS
5ee1407 @vrana Avoid double escaping
authored Mar 24, 2011
93 * @return string HTML code, "" to ignore table
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
94 */
95 function tableName($tableStatus) {
689699a Shortcut for htmlspecialchars
jakubvrana authored Jul 28, 2009
96 return h($tableStatus["Name"]);
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
97 }
98
99 /** Field caption used in select and edit
100 * @param array single field returned from fields()
6c97b80 Display only first five columns in Editor example
jakubvrana authored Jul 27, 2009
101 * @param int order of column in select
5ee1407 @vrana Avoid double escaping
authored Mar 24, 2011
102 * @return string HTML code, "" to ignore field
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
103 */
6c97b80 Display only first five columns in Editor example
jakubvrana authored Jul 27, 2009
104 function fieldName($field, $order = 0) {
689699a Shortcut for htmlspecialchars
jakubvrana authored Jul 28, 2009
105 return '<span title="' . h($field["full_type"]) . '">' . h($field["field"]) . '</span>';
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
106 }
107
f2ed237 Display table links above table structure
jakubvrana authored Sep 20, 2009
108 /** Print links after select heading
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
109 * @param array result of SHOW TABLE STATUS
294b10b Highlight current link
jakubvrana authored Nov 24, 2009
110 * @param string new item options, NULL for no new item
f2ed237 Display table links above table structure
jakubvrana authored Sep 20, 2009
111 * @return null
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
112 */
f2ed237 Display table links above table structure
jakubvrana authored Sep 20, 2009
113 function selectLinks($tableStatus, $set = "") {
294b10b Highlight current link
jakubvrana authored Nov 24, 2009
114 echo '<p class="tabs">';
2d8a2de Change table operations descriptions
jakubvrana authored Nov 27, 2009
115 $links = array("select" => lang('Select data'), "table" => lang('Show structure'));
da6f1f8 @vrana Driver specific view detection
authored May 27, 2010
116 if (is_view($tableStatus)) {
294b10b Highlight current link
jakubvrana authored Nov 24, 2009
117 $links["view"] = lang('Alter view');
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
118 } else {
119 $links["create"] = lang('Alter table');
f2ed237 Display table links above table structure
jakubvrana authored Sep 20, 2009
120 }
6591d48 @vrana Replace isset($var) by $var !== null
authored May 13, 2012
121 if ($set !== null) {
294b10b Highlight current link
jakubvrana authored Nov 24, 2009
122 $links["edit"] = lang('New item');
123 }
124 foreach ($links as $key => $val) {
8ad4809 @vrana Use class="active" instead of <b>
authored Nov 22, 2010
125 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
126 }
127 echo "\n";
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
128 }
129
753909e @vrana Support for virtual foreign keys
authored Oct 29, 2010
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
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
138 /** Find backward keys for table
139 * @param string
09e93de Move backward keys to Editor
jakubvrana authored Sep 23, 2009
140 * @param string
141 * @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
142 */
09e93de Move backward keys to Editor
jakubvrana authored Sep 23, 2009
143 function backwardKeys($table, $tableName) {
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
144 return array();
145 }
146
09e93de Move backward keys to Editor
jakubvrana authored Sep 23, 2009
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
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
155 /** Query printed in select before execution
156 * @param string query to be executed
157 * @return string
158 */
159 function selectQuery($query) {
e672694 @vrana Rename $driver to $jush
authored May 7, 2010
160 global $jush;
931f7ef @vrana Fix inline edit in IE9
authored Mar 23, 2011
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
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
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
a0def47 Date localization
jakubvrana authored Jul 27, 2009
182 * @param string HTML-escaped value to print
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
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) {
c4a5724 @vrana Simplify work with NULL values in select
authored May 13, 2012
188 $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
189 if (ereg('blob|bytea|raw|file', $field["type"]) && !is_utf8($val)) {
c4a5724 @vrana Simplify work with NULL values in select
authored May 14, 2012
190 $return = lang('%d byte(s)', strlen($val));
4921235 Hide edit functions in Editor
jakubvrana authored Jul 23, 2009
191 }
12c042c Function htmlspecialchars now uses ENT_QUOTES
jakubvrana authored Jul 30, 2009
192 return ($link ? "<a href='$link'>$return</a>" : $return);
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
193 }
194
a0def47 Date localization
jakubvrana authored Jul 27, 2009
195 /** Value conversion used in select and edit
196 * @param string
197 * @param array single field returned from fields()
2011428 Use LIKE operator in Editor
jakubvrana authored Jul 28, 2009
198 * @return string
a0def47 Date localization
jakubvrana authored Jul 27, 2009
199 */
200 function editVal($val, $field) {
5a73c01 @vrana Treat binary type as hex
authored Sep 28, 2010
201 return (ereg("binary", $field["type"]) ? reset(unpack("H*", $val)) : $val);
a0def47 Date localization
jakubvrana authored Jul 27, 2009
202 }
203
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
204 /** Print columns box in select
d2c513d @vrana Column names customization (bug #3194500)
authored May 24, 2011
205 * @param array result of selectColumnsProcess()[0]
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
206 * @param array selectable columns
207 * @return null
208 */
209 function selectColumnsPrint($select, $columns) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
210 global $functions, $grouping;
dc667ea Hide select export and import
jakubvrana authored Sep 11, 2009
211 print_fieldset("select", lang('Select'), $select);
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
212 $i = 0;
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
213 $fun_group = array(lang('Functions') => $functions, lang('Aggregation') => $grouping);
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
214 foreach ($select as $key => $val) {
215 $val = $_GET["columns"][$key];
0698409 Utilize html_select
jakubvrana authored Oct 2, 2009
216 echo "<div>" . html_select("columns[$i][fun]", array(-1 => "") + $fun_group, $val["fun"]);
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
217 echo "(<select name='columns[$i][col]'><option>" . optionlist($columns, $val["col"], true) . "</select>)</div>\n";
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
218 $i++;
219 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
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";
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
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) {
dc667ea Hide select export and import
jakubvrana authored Sep 11, 2009
232 print_fieldset("search", lang('Search'), $where);
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
233 foreach ($indexes as $i => $index) {
234 if ($index["type"] == "FULLTEXT") {
689699a Shortcut for htmlspecialchars
jakubvrana authored Jul 28, 2009
235 echo "(<i>" . implode("</i>, <i>", array_map('h', $index["columns"])) . "</i>) AGAINST";
739bcb0 @vrana Warn about selecting data without index
authored May 16, 2012
236 echo " <input name='fulltext[$i]' value='" . h($_GET["fulltext"][$i]) . "' onchange='selectFieldChange(this.form);'>";
6b30cfa Separate checkbox
jakubvrana authored Sep 25, 2009
237 echo checkbox("boolean[$i]", 1, isset($_GET["boolean"][$i]), "BOOL");
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
238 echo "<br>\n";
239 }
240 }
739bcb0 @vrana Warn about selecting data without index
authored May 17, 2012
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";
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
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) {
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])) {
739bcb0 @vrana Warn about selecting data without index
authored May 17, 2012
266 echo "<div><select name='order[$i]' onchange='selectFieldChange(this.form);'><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
739bcb0 @vrana Warn about selecting data without index
authored May 17, 2012
299 * @param array
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
300 * @return null
301 */
739bcb0 @vrana Warn about selecting data without index
authored May 17, 2012
302 function selectActionPrint($indexes) {
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
303 echo "<fieldset><legend>" . lang('Action') . "</legend><div>";
304 echo "<input type='submit' value='" . lang('Select') . "'>";
739bcb0 @vrana Warn about selecting data without index
authored May 17, 2012
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";
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
321 echo "</div></fieldset>\n";
322 }
323
e641e5c @vrana Limit commands and import in customization (bug #3194432)
authored May 24, 2011
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
1a6a73a Rename selectExtra to selectEmail
jakubvrana authored Jul 28, 2009
338 /** Print extra text in the end of a select form
339 * @param array fields holding e-mails
1e55d47 User interface for e-mail {$name}
jakubvrana authored Sep 9, 2009
340 * @param array selectable columns
1a6a73a Rename selectExtra to selectEmail
jakubvrana authored Jul 28, 2009
341 * @return null
342 */
1e55d47 User interface for e-mail {$name}
jakubvrana authored Sep 9, 2009
343 function selectEmailPrint($emailFields, $columns) {
1a6a73a Rename selectExtra to selectEmail
jakubvrana authored Jul 28, 2009
344 }
345
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
346 /** Process columns box in select
347 * @param array selectable columns
1e55d47 User interface for e-mail {$name}
jakubvrana authored Sep 9, 2009
348 * @param array
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
349 * @return array (array(select_expressions), array(group_expressions))
350 */
351 function selectColumnsProcess($columns, $indexes) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
352 global $functions, $grouping;
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
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) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
356 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
357 $select[$key] = apply_sql_function($val["fun"], (isset($columns[$val["col"]]) ? idf_escape($val["col"]) : "*"));
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
358 if (!in_array($val["fun"], $grouping)) {
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
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 */
07e1ae1 FOUND_ROWS only with GROUP BY
jakubvrana authored Jul 28, 2009
371 function selectSearchProcess($fields, $indexes) {
7e644b4 @vrana Save bytes ($connection->quote shortcut)
authored Oct 13, 2010
372 global $jush;
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
373 $return = array();
374 foreach ($indexes as $i => $index) {
7352c28 Replace strlen() by != ""
jakubvrana authored Jan 9, 2010
375 if ($index["type"] == "FULLTEXT" && $_GET["fulltext"][$i] != "") {
7e644b4 @vrana Save bytes ($connection->quote shortcut)
authored Oct 13, 2010
376 $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
377 }
378 }
379 foreach ((array) $_GET["where"] as $val) {
7352c28 Replace strlen() by != ""
jakubvrana authored Jan 9, 2010
380 if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
381 $cond = " $val[op]";
382 if (ereg('IN$', $val["op"])) {
383 $in = process_length($val["val"]);
384 $cond .= " (" . ($in != "" ? $in : "NULL") . ")";
675ac01 @vrana Ability to search by expression in select (bug #3158017)
authored Jan 30, 2011
385 } elseif (!$val["op"]) {
386 $cond .= $val["val"]; // SQL injection
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
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 }
7352c28 Replace strlen() by != ""
jakubvrana authored Jan 9, 2010
392 if ($val["col"] != "") {
98b88eb Remove fulltext search without index
jakubvrana authored Jul 28, 2009
393 $return[] = idf_escape($val["col"]) . $cond;
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
394 } else {
98b88eb Remove fulltext search without index
jakubvrana authored Jul 28, 2009
395 // find anywhere
396 $cols = array();
397 foreach ($fields as $name => $field) {
398 if (is_numeric($val["val"]) || !ereg('int|float|double|decimal', $field["type"])) {
d79b160 Illegal mix of collations
jakubvrana authored Jan 15, 2010
399 $name = idf_escape($name);
782921b @vrana Finish SQLite
authored May 27, 2010
400 $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
401 }
402 }
d79b160 Illegal mix of collations
jakubvrana authored Jan 15, 2010
403 $return[] = ($cols ? "(" . implode("$cond OR ", $cols) . "$cond)" : "0");
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
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 */
07e1ae1 FOUND_ROWS only with GROUP BY
jakubvrana authored Jul 28, 2009
415 function selectOrderProcess($fields, $indexes) {
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
416 $return = array();
417 foreach ((array) $_GET["order"] as $key => $val) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
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" : "");
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
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
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
439 /** Process extras in select form
440 * @param array AND conditions
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored Sep 9, 2009
441 * @param array
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
442 * @return bool true if processed, false to process other parts of form
443 */
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored Sep 9, 2009
444 function selectEmailProcess($where, $foreignKeys) {
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
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) {
e672694 @vrana Rename $driver to $jush
authored May 7, 2010
453 global $jush;
79fa7da @vrana Minimize the chance of displaying message on different page (thanks t…
authored Jan 30, 2011
454 static $count = 0;
be49e08 Improve session restarting
jakubvrana authored Nov 3, 2009
455 restart_session();
79fa7da @vrana Minimize the chance of displaying message on different page (thanks t…
authored Jan 30, 2011
456 $id = "sql-" . ($count++);
49565e0 @vrana Rename variables to avoid conflict with Adminer 2 sessions and enable…
authored Oct 15, 2010
457 $history = &get_session("queries");
24c51fe @vrana Print current time next to executed SQL queries
authored Mar 10, 2012
458 if (strlen($query) > 1e6) {
0bc930c @vrana Avoid big ternary (save memory)
authored Mar 22, 2011
459 $query = ereg_replace('[\x80-\xFF]+$', '', substr($query, 0, 1e6)) . "\n..."; // [\x80-\xFF] - valid UTF-8, \n - can end by one-line comment
460 }
24c51fe @vrana Print current time next to executed SQL queries
authored Mar 10, 2012
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
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
463 }
464
465 /** Functions displayed in edit form
466 * @param array single field from fields()
467 * @return array
468 */
469 function editFunctions($field) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
470 global $edit_functions;
02f7521 Fix input onchange
jakubvrana authored Apr 22, 2010
471 $return = ($field["null"] ? "NULL/" : "");
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
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 }
2671a47 @vrana No edit expression with set and binary
authored Mar 22, 2011
479 if ($key && !ereg('set|blob|bytea|raw|file', $field["type"])) {
327b56b @vrana Ability to save expression in edit
authored Mar 15, 2011
480 $return .= "/=";
481 }
309f681 Relative function concat
jakubvrana authored Aug 28, 2009
482 }
4921235 Hide edit functions in Editor
jakubvrana authored Jul 23, 2009
483 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
484 return explode("/", $return);
4921235 Hide edit functions in Editor
jakubvrana authored Jul 23, 2009
485 }
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
486
487 /** Get options to display edit field
488 * @param string table name
489 * @param array single field from fields()
e1abcda Treat tinyint(1) as boolean
jakubvrana authored Jul 28, 2009
490 * @param string attributes to use inside the tag
491 * @param string
492 * @return string custom input field or empty string for default
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
493 */
e1abcda Treat tinyint(1) as boolean
jakubvrana authored Jul 28, 2009
494 function editInput($table, $field, $attrs, $value) {
ec0282b Enum editing
jakubvrana authored Nov 12, 2009
495 if ($field["type"] == "enum") {
fe06908 @vrana Allow redefining editInput for enum (bug #3048711)
authored Oct 23, 2010
496 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
497 . ($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
498 . enum_input("radio", $attrs, $field, $value, 0) // 0 - empty
ec0282b Enum editing
jakubvrana authored Nov 12, 2009
499 ;
500 }
501 return "";
4921235 Hide edit functions in Editor
jakubvrana authored Jul 23, 2009
502 }
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
503
504 /** Process sent input
505 * @param array single field from fields()
a0def47 Date localization
jakubvrana authored Jul 27, 2009
506 * @param string
507 * @param string
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
508 * @return string expression to use in a query
509 */
a0def47 Date localization
jakubvrana authored Jul 27, 2009
510 function processInput($field, $value, $function = "") {
327b56b @vrana Ability to save expression in edit
authored Mar 15, 2011
511 if ($function == "=") {
512 return $value; // SQL injection
513 }
a0def47 Date localization
jakubvrana authored Jul 27, 2009
514 $name = $field["field"];
4ff2f03 @vrana Alter bit type default value
authored May 16, 2011
515 $return = ($field["type"] == "bit" && ereg("^([0-9]+|b'[0-1]+')\$", $value) ? $value : q($value));
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
516 if (ereg('^(now|getdate|uuid)$', $function)) {
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
517 $return = "$function()";
e4df0c6 @vrana MS SQL functions
authored May 18, 2010
518 } elseif (ereg('^current_(date|timestamp)$', $function)) {
519 $return = $function;
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
520 } elseif (ereg('^([+-]|\\|\\|)$', $function)) {
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
521 $return = idf_escape($name) . " $function $return";
522 } elseif (ereg('^[+-] interval$', $function)) {
5002b89 @vrana Big numbers without E
authored Oct 23, 2010
523 $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
524 } elseif (ereg('^(addtime|subtime|concat)$', $function)) {
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
525 $return = "$function(" . idf_escape($name) . ", $return)";
5a73c01 @vrana Treat binary type as hex
authored Sep 28, 2010
526 } elseif (ereg('^(md5|sha1|password|encrypt|hex)$', $function)) {
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
527 $return = "$function($return)";
528 }
5a73c01 @vrana Treat binary type as hex
authored Sep 28, 2010
529 if (ereg("binary", $field["type"])) {
530 $return = "unhex($return)";
531 }
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
532 return $return;
a78c941 Empty value in Editor as NULL
jakubvrana authored Jul 23, 2009
533 }
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
534
e40612a Use radio in export
jakubvrana authored Oct 2, 2009
535 /** Returns export output options
be3410f @vrana Simplify dumpOutput, dumpFormat and dumpData methods
authored Oct 29, 2010
536 * @return array
e40612a Use radio in export
jakubvrana authored Oct 2, 2009
537 */
be3410f @vrana Simplify dumpOutput, dumpFormat and dumpData methods
authored Oct 29, 2010
538 function dumpOutput() {
e40612a Use radio in export
jakubvrana authored Oct 2, 2009
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
be3410f @vrana Simplify dumpOutput, dumpFormat and dumpData methods
authored Oct 29, 2010
547 return $return;
e40612a Use radio in export
jakubvrana authored Oct 2, 2009
548 }
549
550 /** Returns export format options
1e70b74 @vrana Ability to disable export
authored Dec 21, 2011
551 * @return array empty to disable export
e40612a Use radio in export
jakubvrana authored Oct 2, 2009
552 */
be3410f @vrana Simplify dumpOutput, dumpFormat and dumpData methods
authored Oct 29, 2010
553 function dumpFormat() {
e225d22 @vrana TSV export and import (bug #3097657)
authored Oct 29, 2010
554 return array('sql' => 'SQL', 'csv' => 'CSV,', 'csv;' => 'CSV;', 'tsv' => 'TSV');
e40612a Use radio in export
jakubvrana authored Oct 2, 2009
555 }
556
095d472 @vrana Customizable export
authored Oct 29, 2010
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) {
576 // remove DEFINER with current user
021e1e3 @vrana Allow % in view definer (thanks to Tomas Votruba)
authored Mar 14, 2011
577 $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
578 }
579 echo ($style != "CREATE+ALTER" ? $create : ($is_view ? substr_replace($create, " OR REPLACE", 6, 0) : substr_replace($create, " IF NOT EXISTS", 12, 0))) . ";\n\n";
580 }
581 if ($style == "CREATE+ALTER" && !$is_view) {
582 // create procedure which iterates over original columns and adds new and removes old
583 $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";
584 echo "DELIMITER ;;
585 CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN
586 DECLARE _column_name, _collation_name, after varchar(64) DEFAULT '';
587 DECLARE _column_type, _column_default text;
588 DECLARE _is_nullable char(3);
589 DECLARE _extra varchar(30);
590 DECLARE _column_comment varchar(255);
591 DECLARE done, set_after bool DEFAULT 0;
592 DECLARE add_columns text DEFAULT '";
593 $fields = array();
594 $after = "";
595 foreach (get_rows($query) as $row) {
596 $default = $row["COLUMN_DEFAULT"];
6591d48 @vrana Replace isset($var) by $var !== null
authored May 14, 2012
597 $row["default"] = ($default !== null ? q($default) : "NULL");
095d472 @vrana Customizable export
authored Oct 29, 2010
598 $row["after"] = q($after); //! rgt AFTER lft, lft AFTER id doesn't work
599 $row["alter"] = escape_string(idf_escape($row["COLUMN_NAME"])
600 . " $row[COLUMN_TYPE]"
601 . ($row["COLLATION_NAME"] ? " COLLATE $row[COLLATION_NAME]" : "")
6591d48 @vrana Replace isset($var) by $var !== null
authored May 14, 2012
602 . ($default !== null ? " DEFAULT " . ($default == "CURRENT_TIMESTAMP" ? $default : $row["default"]) : "")
095d472 @vrana Customizable export
authored Oct 29, 2010
603 . ($row["IS_NULLABLE"] == "YES" ? "" : " NOT NULL")
604 . ($row["EXTRA"] ? " $row[EXTRA]" : "")
605 . ($row["COLUMN_COMMENT"] ? " COMMENT " . q($row["COLUMN_COMMENT"]) : "")
606 . ($after ? " AFTER " . idf_escape($after) : " FIRST")
607 );
608 echo ", ADD $row[alter]";
609 $fields[] = $row;
610 $after = $row["COLUMN_NAME"];
611 }
612 echo "';
613 DECLARE columns CURSOR FOR $query;
614 DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
615 SET @alter_table = '';
616 OPEN columns;
617 REPEAT
618 FETCH columns INTO _column_name, _column_default, _is_nullable, _collation_name, _column_type, _extra, _column_comment;
619 IF NOT done THEN
620 SET set_after = 1;
621 CASE _column_name";
622 foreach ($fields as $row) {
623 echo "
624 WHEN " . q($row["COLUMN_NAME"]) . " THEN
1c1537b @vrana Fix ALTER export: add columns together with modify
authored Apr 24, 2011
625 SET add_columns = REPLACE(add_columns, ', ADD $row[alter]', IF(
626 _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]
627 , '', ', MODIFY $row[alter]'));"
628 ; //! don't replace in comment
095d472 @vrana Customizable export
authored Oct 29, 2010
629 }
630 echo "
631 ELSE
632 SET @alter_table = CONCAT(@alter_table, ', DROP ', _column_name);
633 SET set_after = 0;
634 END CASE;
635 IF set_after THEN
636 SET after = _column_name;
637 END IF;
638 END IF;
639 UNTIL done END REPEAT;
640 CLOSE columns;
641 IF @alter_table != '' OR add_columns != '' THEN
642 SET alter_command = CONCAT(alter_command, 'ALTER TABLE " . table($table) . "', SUBSTR(CONCAT(add_columns, @alter_table), 2), ';\\n');
643 END IF;
644 END;;
645 DELIMITER ;
646 CALL adminer_alter(@adminer_alter);
647 DROP PROCEDURE adminer_alter;
648
649 ";
650 //! indexes
651 }
652 }
653 }
654
655 /** Export table data
656 * @param string
657 * @param string
be3410f @vrana Simplify dumpOutput, dumpFormat and dumpData methods
authored Oct 29, 2010
658 * @param string
095d472 @vrana Customizable export
authored Oct 29, 2010
659 * @return null prints data
660 */
be3410f @vrana Simplify dumpOutput, dumpFormat and dumpData methods
authored Oct 29, 2010
661 function dumpData($table, $style, $query) {
095d472 @vrana Customizable export
authored Oct 29, 2010
662 global $connection, $jush;
663 $max_packet = ($jush == "sqlite" ? 0 : 1048576); // default, minimum is 1024
664 if ($style) {
665 if ($_POST["format"] == "sql" && $style == "TRUNCATE+INSERT") {
666 echo truncate_sql($table) . ";\n";
667 }
15715b3 @vrana Export SQL command result (bug #3116854)
authored Feb 15, 2011
668 if ($_POST["format"] == "sql") {
669 $fields = fields($table);
670 }
be3410f @vrana Simplify dumpOutput, dumpFormat and dumpData methods
authored Oct 29, 2010
671 $result = $connection->query($query, 1); // 1 - MYSQLI_USE_RESULT //! enum and set as numbers
095d472 @vrana Customizable export
authored Oct 29, 2010
672 if ($result) {
673 $insert = "";
674 $buffer = "";
675 while ($row = $result->fetch_assoc()) {
676 if ($_POST["format"] != "sql") {
15715b3 @vrana Export SQL command result (bug #3116854)
authored Feb 15, 2011
677 if ($style == "table") {
678 dump_csv(array_keys($row));
679 $style = "INSERT";
680 }
095d472 @vrana Customizable export
authored Oct 29, 2010
681 dump_csv($row);
682 } else {
683 if (!$insert) {
684 $insert = "INSERT INTO " . table($table) . " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ") VALUES";
685 }
686 foreach ($row as $key => $val) {
6591d48 @vrana Replace isset($var) by $var !== null
authored May 14, 2012
687 $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
688 }
689 $s = implode(",\t", $row);
690 if ($style == "INSERT+UPDATE") {
691 $set = array();
692 foreach ($row as $key => $val) {
693 $set[] = idf_escape($key) . " = $val";
694 }
695 echo "$insert ($s) ON DUPLICATE KEY UPDATE " . implode(", ", $set) . ";\n";
696 } else {
697 $s = ($max_packet ? "\n" : " ") . "($s)";
698 if (!$buffer) {
699 $buffer = $insert . $s;
baf2172 @vrana MySQL allows only (max_allow_packet - 3)-bytes queries (thanks to kluvi)
authored May 20, 2011
700 } elseif (strlen($buffer) + 4 + strlen($s) < $max_packet) { // 4 - length specification
095d472 @vrana Customizable export
authored Oct 29, 2010
701 $buffer .= ",$s";
702 } else {
baf2172 @vrana MySQL allows only (max_allow_packet - 3)-bytes queries (thanks to kluvi)
authored May 20, 2011
703 echo "$buffer;\n";
095d472 @vrana Customizable export
authored Oct 29, 2010
704 $buffer = $insert . $s;
705 }
706 }
707 }
708 }
709 if ($_POST["format"] == "sql" && $style != "INSERT+UPDATE" && $buffer) {
710 $buffer .= ";\n";
711 echo $buffer;
712 }
164cd3b @vrana Report errors in data export
authored Oct 29, 2010
713 } elseif ($_POST["format"] == "sql") {
714 echo "-- " . str_replace("\n", " ", $connection->error) . "\n";
095d472 @vrana Customizable export
authored Oct 29, 2010
715 }
716 }
717 }
718
b78b0cd @vrana Plugin for including date in export filename
authored Jun 29, 2012
719 /** Set export filename
720 * @param string
721 * @return string filename without extension
722 */
723 function dumpFilename($identifier) {
724 return friendly_url($identifier != "" ? $identifier : (SERVER != "" ? SERVER : "localhost"));
725 }
726
095d472 @vrana Customizable export
authored Oct 29, 2010
727 /** Send headers for export
728 * @param string
729 * @param bool
730 * @return string extension
731 */
732 function dumpHeaders($identifier, $multi_table = false) {
733 $output = $_POST["output"];
734 $ext = ($_POST["format"] == "sql" ? "sql" : ($multi_table ? "tar" : "csv")); // multiple CSV packed to TAR
735 header("Content-Type: " .
736 ($output == "bz2" ? "application/x-bzip" :
737 ($output == "gz" ? "application/x-gzip" :
738 ($ext == "tar" ? "application/x-tar" :
739 ($ext == "sql" || $output != "file" ? "text/plain" : "text/csv") . "; charset=utf-8"
740 ))));
8ab6fff @vrana Centralize dump_headers
authored Feb 17, 2011
741 if ($output == "bz2") {
095d472 @vrana Customizable export
authored Oct 29, 2010
742 ob_start('bzcompress', 1e6);
743 }
8ab6fff @vrana Centralize dump_headers
authored Feb 17, 2011
744 if ($output == "gz") {
095d472 @vrana Customizable export
authored Oct 29, 2010
745 ob_start('gzencode', 1e6);
746 }
747 return $ext;
e40612a Use radio in export
jakubvrana authored Oct 2, 2009
748 }
749
7416164 @vrana Homepage customization
authored Jan 6, 2011
750 /** Print homepage
751 * @return bool whether to print default homepage
752 */
753 function homepage() {
754 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
755 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
756 echo ($_GET["ns"] !== "" ? '<a href="' . h(ME) . 'schema=">' . lang('Database schema') . "</a>\n" : "");
16a72b4 @vrana Shortcut for database privileges
authored Jun 3, 2011
757 echo (support("privileges") ? "<a href='" . h(ME) . "privileges='>" . lang('Privileges') . "</a>\n" : "");
7416164 @vrana Homepage customization
authored Jan 6, 2011
758 return true;
759 }
760
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
761 /** Prints navigation after Adminer title
d49903b @vrana Report invalid schema
authored Oct 18, 2010
762 * @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
763 * @return null
764 */
765 function navigation($missing) {
e672694 @vrana Rename $driver to $jush
authored May 7, 2010
766 global $VERSION, $connection, $token, $jush, $drivers;
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored Sep 19, 2009
767 ?>
768 <h1>
3ebfdd3 @vrana Simpler customization of name() link
authored Apr 3, 2011
769 <?php echo $this->name(); ?> <span class="version"><?php echo $VERSION; ?></span>
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored Sep 19, 2009
770 <a href="http://www.adminer.org/#download" id="version"><?php echo (version_compare($VERSION, $_COOKIE["adminer_version"]) < 0 ? h($_COOKIE["adminer_version"]) : ""); ?></a>
771 </h1>
772 <?php
605b093 @vrana List authentications
authored May 6, 2010
773 if ($missing == "auth") {
774 $first = true;
49565e0 @vrana Rename variables to avoid conflict with Adminer 2 sessions and enable…
authored Oct 15, 2010
775 foreach ((array) $_SESSION["pwds"] as $driver => $servers) {
605b093 @vrana List authentications
authored May 6, 2010
776 foreach ($servers as $server => $usernames) {
777 foreach ($usernames as $username => $password) {
6591d48 @vrana Replace isset($var) by $var !== null
authored May 14, 2012
778 if ($password !== null) {
605b093 @vrana List authentications
authored May 6, 2010
779 if ($first) {
f498219 @vrana Remove eventStop() used by AJAXification in past
authored May 14, 2012
780 echo "<p>\n";
605b093 @vrana List authentications
authored May 6, 2010
781 $first = false;
782 }
e672694 @vrana Rename $driver to $jush
authored May 7, 2010
783 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
784 }
785 }
786 }
787 }
788 } else {
c7f1a63 @vrana Extensible list of databases
authored Feb 24, 2012
789 $databases = $this->databases();
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
790 ?>
b95f24e Editor: User friendly data editor
jakubvrana authored Jul 3, 2009
791 <form action="" method="post">
fde1171 Add CSS classes (thanks to cvicebni ubor)
jakubvrana authored Oct 28, 2009
792 <p class="logout">
f7d4587 @vrana Hide SQL command link in case of an error
authored Oct 18, 2010
793 <?php
9d47d1e @vrana Whitespace
authored Oct 19, 2010
794 if (DB == "" || !$missing) {
8ad4809 @vrana Use class="active" instead of <b>
authored Nov 22, 2010
795 echo "<a href='" . h(ME) . "sql='" . bold(isset($_GET["sql"])) . ">" . lang('SQL command') . "</a>\n";
9d47d1e @vrana Whitespace
authored Oct 19, 2010
796 if (support("dump")) {
29d7d6c @vrana Modify dump link in AJAX
authored Dec 29, 2010
797 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
798 }
799 }
800 ?>
f498219 @vrana Remove eventStop() used by AJAXification in past
authored May 14, 2012
801 <input type="submit" name="logout" value="<?php echo lang('Logout'); ?>">
740ae10 @vrana Don't send incomplete forms
authored Mar 8, 2011
802 <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
803 </p>
b95f24e Editor: User friendly data editor
jakubvrana authored Jul 3, 2009
804 </form>
805 <form action="">
25cef1f Disable session.use_trans_sid to preserve export result
jakubvrana authored Aug 30, 2009
806 <p>
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
807 <?php hidden_fields_get(); ?>
0698409 Utilize html_select
jakubvrana authored Oct 2, 2009
808 <?php echo ($databases ? html_select("db", array("" => "(" . lang('database') . ")") + $databases, DB, "this.form.submit();") : '<input name="db" value="' . h(DB) . '">'); ?>
f498219 @vrana Remove eventStop() used by AJAXification in past
authored May 14, 2012
809 <input type="submit" value="<?php echo lang('Use'); ?>"<?php echo ($databases ? " class='hidden'" : ""); ?>>
b95f24e Editor: User friendly data editor
jakubvrana authored Jul 3, 2009
810 <?php
7352c28 Replace strlen() by != ""
jakubvrana authored Jan 9, 2010
811 if ($missing != "db" && DB != "" && $connection->select_db(DB)) {
6420c58 Schema support for PostgreSQL
jakubvrana authored May 5, 2010
812 if (support("scheme")) {
813 echo "<br>" . html_select("ns", array("" => "(" . lang('schema') . ")") + schemas(), $_GET["ns"], "this.form.submit();");
814 if ($_GET["ns"] != "") {
815 set_schema($_GET["ns"]);
8e81039 Link table names in SQL queries
jakubvrana authored May 2, 2010
816 }
6420c58 Schema support for PostgreSQL
jakubvrana authored May 5, 2010
817 }
f7d4587 @vrana Hide SQL command link in case of an error
authored Oct 18, 2010
818 if ($_GET["ns"] !== "" && !$missing) {
8ad4809 @vrana Use class="active" instead of <b>
authored Nov 22, 2010
819 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
820 $tables = tables_list();
821 if (!$tables) {
822 echo "<p class='message'>" . lang('No tables.') . "\n";
823 } else {
824 $this->tablesPrint($tables);
825 $links = array();
826 foreach ($tables as $table => $type) {
827 $links[] = preg_quote($table, '/');
828 }
829 echo "<script type='text/javascript'>\n";
28f21aa @vrana Escape JavaScript strings (bug #3093243)
authored Oct 22, 2010
830 echo "var jushLinks = { $jush: [ '" . js_escape(ME) . "table=\$&', /\\b(" . implode("|", $links) . ")\\b/g ] };\n";
6420c58 Schema support for PostgreSQL
jakubvrana authored May 5, 2010
831 foreach (array("bac", "bra", "sqlite_quo", "mssql_bra") as $val) {
e672694 @vrana Rename $driver to $jush
authored May 7, 2010
832 echo "jushLinks.$val = jushLinks.$jush;\n";
6420c58 Schema support for PostgreSQL
jakubvrana authored May 5, 2010
833 }
834 echo "</script>\n";
e5969d4 Shorten code
jakubvrana authored May 3, 2010
835 }
df0c4bb Simplify tablesPrint
jakubvrana authored Sep 23, 2009
836 }
837 }
6420c58 Schema support for PostgreSQL
jakubvrana authored May 5, 2010
838 echo (isset($_GET["sql"]) ? '<input type="hidden" name="sql" value="">'
839 : (isset($_GET["schema"]) ? '<input type="hidden" name="schema" value="">'
840 : (isset($_GET["dump"]) ? '<input type="hidden" name="dump" value="">'
841 : "")));
60c7ed9 @vrana MS SQL schema support
authored May 11, 2010
842 echo "</p></form>\n";
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored Sep 19, 2009
843 }
844 }
845
846 /** Prints table list in menu
df0c4bb Simplify tablesPrint
jakubvrana authored Sep 23, 2009
847 * @param array
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored Sep 19, 2009
848 * @return null
849 */
df0c4bb Simplify tablesPrint
jakubvrana authored Sep 23, 2009
850 function tablesPrint($tables) {
851 echo "<p id='tables'>\n";
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
852 foreach ($tables as $table => $type) {
8ad4809 @vrana Use class="active" instead of <b>
authored Nov 22, 2010
853 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
854 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
855 }
856 }
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
857
2c445a8 Extensibility basics
jakubvrana authored Jul 3, 2009
858 }
464d84a Define functions unconditionally
jakubvrana authored Sep 9, 2009
859
860 $adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer);
6591d48 @vrana Replace isset($var) by $var !== null
authored May 14, 2012
861 if ($adminer->operators === null) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
862 $adminer->operators = $operators;
863 }
Something went wrong with that request. Please try again.