Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 528 lines (489 sloc) 18.61 kb
2c445a8 Extensibility basics
jakubvrana authored
1 <?php
c64c4fd Adminer class
jakubvrana authored
2 class Adminer {
d24ad78 Select boxes customization
jakubvrana authored
3 var $functions = array("char_length", "from_unixtime", "hex", "lower", "round", "sec_to_time", "time_to_sec", "unix_timestamp", "upper");
e0fbf33 Rename distinct to count distinct
jakubvrana authored
4 var $grouping = array("avg", "count", "count distinct", "group_concat", "max", "min", "sum");
d24ad78 Select boxes customization
jakubvrana authored
5 var $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "REGEXP", "IN", "IS NULL", "NOT LIKE", "NOT REGEXP", "NOT IN", "IS NOT NULL");
c64c4fd Adminer class
jakubvrana authored
6
7 /** Name in title and navigation
8 * @return string
9 */
10 function name() {
b349612 Remove useless translations
jakubvrana authored
11 return "Adminer";
c64c4fd Adminer class
jakubvrana authored
12 }
13
14 /** Connection parameters
15 * @return array ($server, $username, $password)
16 */
17 function credentials() {
18 return array($_GET["server"], $_SESSION["usernames"][$_GET["server"]], $_SESSION["passwords"][$_GET["server"]]);
19 }
20
21 /** Identifier of selected database
22 * @return string
23 */
24 function database() {
3022dcb Define DB
jakubvrana authored
25 // should be used everywhere instead of DB
26 return DB;
c64c4fd Adminer class
jakubvrana authored
27 }
28
29 /** Print login form
30 * @param string
31 * @return null
32 */
33 function loginForm($username) {
2faa08c Customize login and login form
jakubvrana authored
34 ?>
0205440 HTML whitespace
jakubvrana authored
35 <table cellspacing="0">
689699a Shortcut for htmlspecialchars
jakubvrana authored
36 <tr><th><?php echo lang('Server'); ?><td><input name="server" value="<?php echo h($_GET["server"]); ?>">
37 <tr><th><?php echo lang('Username'); ?><td><input name="username" value="<?php echo h($username); ?>">
0205440 HTML whitespace
jakubvrana authored
38 <tr><th><?php echo lang('Password'); ?><td><input type="password" name="password">
39 </table>
2faa08c Customize login and login form
jakubvrana authored
40 <?php
41 }
c64c4fd Adminer class
jakubvrana authored
42
43 /** Authorize the user
44 * @param string
45 * @param string
46 * @return bool
47 */
48 function login($login, $password) {
49 return true;
97b8c7b Display images in Editor
jakubvrana authored
50 }
c64c4fd Adminer class
jakubvrana authored
51
52 /** Table caption used in navigation and headings
53 * @param array result of SHOW TABLE STATUS
54 * @return string
55 */
56 function tableName($tableStatus) {
689699a Shortcut for htmlspecialchars
jakubvrana authored
57 return h($tableStatus["Name"]);
c64c4fd Adminer class
jakubvrana authored
58 }
59
60 /** Field caption used in select and edit
61 * @param array single field returned from fields()
6c97b80 Display only first five columns in Editor example
jakubvrana authored
62 * @param int order of column in select
c64c4fd Adminer class
jakubvrana authored
63 * @return string
64 */
6c97b80 Display only first five columns in Editor example
jakubvrana authored
65 function fieldName($field, $order = 0) {
689699a Shortcut for htmlspecialchars
jakubvrana authored
66 return '<span title="' . h($field["full_type"]) . '">' . h($field["field"]) . '</span>';
c64c4fd Adminer class
jakubvrana authored
67 }
68
f2ed237 Display table links above table structure
jakubvrana authored
69 /** Print links after select heading
c64c4fd Adminer class
jakubvrana authored
70 * @param array result of SHOW TABLE STATUS
294b10b Highlight current link
jakubvrana authored
71 * @param string new item options, NULL for no new item
f2ed237 Display table links above table structure
jakubvrana authored
72 * @return null
c64c4fd Adminer class
jakubvrana authored
73 */
f2ed237 Display table links above table structure
jakubvrana authored
74 function selectLinks($tableStatus, $set = "") {
294b10b Highlight current link
jakubvrana authored
75 echo '<p class="tabs">';
76 $links = array("select" => lang('Select table'), "table" => lang('Table structure'));
f2ed237 Display table links above table structure
jakubvrana authored
77 if (isset($tableStatus["Rows"])) {
294b10b Highlight current link
jakubvrana authored
78 $links["create"] = lang('Alter table');
f2ed237 Display table links above table structure
jakubvrana authored
79 } else {
294b10b Highlight current link
jakubvrana authored
80 $links["view"] = lang('Alter view');
f2ed237 Display table links above table structure
jakubvrana authored
81 }
82 if (isset($set)) {
294b10b Highlight current link
jakubvrana authored
83 $links["edit"] = lang('New item');
84 }
85 foreach ($links as $key => $val) {
86 echo " <a href='" . h(ME) . "$key=" . urlencode($tableStatus["Name"]) . ($key == "edit" ? $set : "") . "'>" . (isset($_GET[$key]) ? "<b>$val</b>" : $val) . "</a>";
f2ed237 Display table links above table structure
jakubvrana authored
87 }
88 echo "\n";
c64c4fd Adminer class
jakubvrana authored
89 }
90
91 /** Find backward keys for table
92 * @param string
09e93de Move backward keys to Editor
jakubvrana authored
93 * @param string
94 * @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
95 */
09e93de Move backward keys to Editor
jakubvrana authored
96 function backwardKeys($table, $tableName) {
c64c4fd Adminer class
jakubvrana authored
97 return array();
98 }
99
09e93de Move backward keys to Editor
jakubvrana authored
100 /** Print backward keys for row
101 * @param array result of $this->backwardKeys()
102 * @param array
103 * @return null
104 */
105 function backwardKeysPrint($backwardKeys, $row) {
106 }
107
c64c4fd Adminer class
jakubvrana authored
108 /** Query printed in select before execution
109 * @param string query to be executed
110 * @return string
111 */
112 function selectQuery($query) {
9c09ebe End element for IE
jakubvrana authored
113 return "<p><code class='jush-sql'>" . h($query) . "</code> <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a></p>\n";
c64c4fd Adminer class
jakubvrana authored
114 }
115
116 /** Description of a row in a table
117 * @param string
118 * @return string SQL expression, empty string for no description
119 */
120 function rowDescription($table) {
121 return "";
122 }
123
124 /** Get descriptions of selected data
125 * @param array all data to print
126 * @param array
127 * @return array
128 */
129 function rowDescriptions($rows, $foreignKeys) {
130 return $rows;
131 }
132
133 /** Value printed in select table
a0def47 Date localization
jakubvrana authored
134 * @param string HTML-escaped value to print
c64c4fd Adminer class
jakubvrana authored
135 * @param string link to foreign key
136 * @param array single field returned from fields()
137 * @return string
138 */
139 function selectVal($val, $link, $field) {
bb46cc9 Don't use <code> for NULL
jakubvrana authored
140 $return = ($val != "<i>NULL</i>" && $field["type"] == "char" ? "<code>$val</code>" : $val);
c64c4fd Adminer class
jakubvrana authored
141 if (ereg('blob|binary', $field["type"]) && !is_utf8($val)) {
142 $return = lang('%d byte(s)', strlen($val));
4921235 Hide edit functions in Editor
jakubvrana authored
143 }
12c042c Function htmlspecialchars now uses ENT_QUOTES
jakubvrana authored
144 return ($link ? "<a href='$link'>$return</a>" : $return);
c64c4fd Adminer class
jakubvrana authored
145 }
146
a0def47 Date localization
jakubvrana authored
147 /** Value conversion used in select and edit
148 * @param string
149 * @param array single field returned from fields()
2011428 Use LIKE operator in Editor
jakubvrana authored
150 * @return string
a0def47 Date localization
jakubvrana authored
151 */
152 function editVal($val, $field) {
153 return $val;
154 }
155
d24ad78 Select boxes customization
jakubvrana authored
156 /** Print columns box in select
157 * @param array result of selectColumnsProcess()
158 * @param array selectable columns
159 * @return null
160 */
161 function selectColumnsPrint($select, $columns) {
dc667ea Hide select export and import
jakubvrana authored
162 print_fieldset("select", lang('Select'), $select);
d24ad78 Select boxes customization
jakubvrana authored
163 $i = 0;
164 $fun_group = array(lang('Functions') => $this->functions, lang('Aggregation') => $this->grouping);
165 foreach ($select as $key => $val) {
166 $val = $_GET["columns"][$key];
0698409 Utilize html_select
jakubvrana authored
167 echo "<div>" . html_select("columns[$i][fun]", array(-1 => "") + $fun_group, $val["fun"]);
d24ad78 Select boxes customization
jakubvrana authored
168 echo "<select name='columns[$i][col]'><option>" . optionlist($columns, $val["col"], true) . "</select></div>\n";
169 $i++;
170 }
0698409 Utilize html_select
jakubvrana authored
171 echo "<div>" . html_select("columns[$i][fun]", array(-1 => "") + $fun_group, "", "this.nextSibling.onchange();");
d24ad78 Select boxes customization
jakubvrana authored
172 echo "<select name='columns[$i][col]' onchange='select_add_row(this);'><option>" . optionlist($columns, null, true) . "</select></div>\n";
173 echo "</div></fieldset>\n";
174 }
175
176 /** Print search box in select
177 * @param array result of selectSearchProcess()
178 * @param array selectable columns
179 * @param array
180 * @return null
181 */
182 function selectSearchPrint($where, $columns, $indexes) {
dc667ea Hide select export and import
jakubvrana authored
183 print_fieldset("search", lang('Search'), $where);
d24ad78 Select boxes customization
jakubvrana authored
184 foreach ($indexes as $i => $index) {
185 if ($index["type"] == "FULLTEXT") {
689699a Shortcut for htmlspecialchars
jakubvrana authored
186 echo "(<i>" . implode("</i>, <i>", array_map('h', $index["columns"])) . "</i>) AGAINST";
187 echo " <input name='fulltext[$i]' value='" . h($_GET["fulltext"][$i]) . "'>";
6b30cfa Separate checkbox
jakubvrana authored
188 echo checkbox("boolean[$i]", 1, isset($_GET["boolean"][$i]), "BOOL");
d24ad78 Select boxes customization
jakubvrana authored
189 echo "<br>\n";
190 }
191 }
192 $i = 0;
193 foreach ((array) $_GET["where"] as $val) {
194 if (strlen("$val[col]$val[val]") && in_array($val["op"], $this->operators)) {
195 echo "<div><select name='where[$i][col]'><option value=''>" . lang('(anywhere)') . optionlist($columns, $val["col"], true) . "</select>";
0698409 Utilize html_select
jakubvrana authored
196 echo html_select("where[$i][op]", $this->operators, $val["op"]);
689699a Shortcut for htmlspecialchars
jakubvrana authored
197 echo "<input name='where[$i][val]' value='" . h($val["val"]) . "'></div>\n";
d24ad78 Select boxes customization
jakubvrana authored
198 $i++;
199 }
200 }
201 echo "<div><select name='where[$i][col]' onchange='select_add_row(this);'><option value=''>" . lang('(anywhere)') . optionlist($columns, null, true) . "</select>";
0698409 Utilize html_select
jakubvrana authored
202 echo html_select("where[$i][op]", $this->operators);
d24ad78 Select boxes customization
jakubvrana authored
203 echo "<input name='where[$i][val]'></div>\n";
204 echo "</div></fieldset>\n";
205 }
206
207 /** Print order box in select
208 * @param array result of selectOrderProcess()
209 * @param array selectable columns
210 * @param array
211 * @return null
212 */
213 function selectOrderPrint($order, $columns, $indexes) {
dc667ea Hide select export and import
jakubvrana authored
214 print_fieldset("sort", lang('Sort'), $order);
d24ad78 Select boxes customization
jakubvrana authored
215 $i = 0;
216 foreach ((array) $_GET["order"] as $key => $val) {
217 if (isset($columns[$val])) {
218 echo "<div><select name='order[$i]'><option>" . optionlist($columns, $val, true) . "</select>";
6b30cfa Separate checkbox
jakubvrana authored
219 echo checkbox("desc[$i]", 1, isset($_GET["desc"][$key]), lang('descending')) . "</div>\n";
d24ad78 Select boxes customization
jakubvrana authored
220 $i++;
221 }
222 }
223 echo "<div><select name='order[$i]' onchange='select_add_row(this);'><option>" . optionlist($columns, null, true) . "</select>";
6b30cfa Separate checkbox
jakubvrana authored
224 echo checkbox("desc[$i]", 1, 0, lang('descending')) . "</div>\n";
d24ad78 Select boxes customization
jakubvrana authored
225 echo "</div></fieldset>\n";
226 }
227
228 /** Print limit box in select
229 * @param string result of selectLimitProcess()
230 * @return null
231 */
232 function selectLimitPrint($limit) {
233 echo "<fieldset><legend>" . lang('Limit') . "</legend><div>"; // <div> for easy styling
689699a Shortcut for htmlspecialchars
jakubvrana authored
234 echo "<input name='limit' size='3' value='" . h($limit) . "'>";
d24ad78 Select boxes customization
jakubvrana authored
235 echo "</div></fieldset>\n";
236 }
237
238 /** Print text length box in select
239 * @param string result of selectLengthProcess()
240 * @return null
241 */
242 function selectLengthPrint($text_length) {
243 if (isset($text_length)) {
244 echo "<fieldset><legend>" . lang('Text length') . "</legend><div>";
689699a Shortcut for htmlspecialchars
jakubvrana authored
245 echo '<input name="text_length" size="3" value="' . h($text_length) . '">';
d24ad78 Select boxes customization
jakubvrana authored
246 echo "</div></fieldset>\n";
247 }
248 }
249
250 /** Print action box in select
251 * @return null
252 */
253 function selectActionPrint() {
254 echo "<fieldset><legend>" . lang('Action') . "</legend><div>";
255 echo "<input type='submit' value='" . lang('Select') . "'>";
256 echo "</div></fieldset>\n";
257 }
258
1a6a73a Rename selectExtra to selectEmail
jakubvrana authored
259 /** Print extra text in the end of a select form
260 * @param array fields holding e-mails
1e55d47 User interface for e-mail {$name}
jakubvrana authored
261 * @param array selectable columns
1a6a73a Rename selectExtra to selectEmail
jakubvrana authored
262 * @return null
263 */
1e55d47 User interface for e-mail {$name}
jakubvrana authored
264 function selectEmailPrint($emailFields, $columns) {
1a6a73a Rename selectExtra to selectEmail
jakubvrana authored
265 }
266
d24ad78 Select boxes customization
jakubvrana authored
267 /** Process columns box in select
268 * @param array selectable columns
1e55d47 User interface for e-mail {$name}
jakubvrana authored
269 * @param array
d24ad78 Select boxes customization
jakubvrana authored
270 * @return array (array(select_expressions), array(group_expressions))
271 */
272 function selectColumnsProcess($columns, $indexes) {
273 $select = array(); // select expressions, empty for *
274 $group = array(); // expressions without aggregation - will be used for GROUP BY if an aggregation function is used
275 foreach ((array) $_GET["columns"] as $key => $val) {
276 if ($val["fun"] == "count" || (isset($columns[$val["col"]]) && (!$val["fun"] || in_array($val["fun"], $this->functions) || in_array($val["fun"], $this->grouping)))) {
277 $select[$key] = apply_sql_function($val["fun"], (isset($columns[$val["col"]]) ? idf_escape($val["col"]) : "*"));
278 if (!in_array($val["fun"], $this->grouping)) {
279 $group[] = $select[$key];
280 }
281 }
282 }
283 return array($select, $group);
284 }
285
286 /** Process search box in select
287 * @param array
288 * @param array
289 * @return array expressions to join by AND
290 */
07e1ae1 FOUND_ROWS only with GROUP BY
jakubvrana authored
291 function selectSearchProcess($fields, $indexes) {
64d616c Rename get_dbh to connection
jakubvrana authored
292 global $connection;
d24ad78 Select boxes customization
jakubvrana authored
293 $return = array();
294 foreach ($indexes as $i => $index) {
295 if ($index["type"] == "FULLTEXT" && strlen($_GET["fulltext"][$i])) {
64d616c Rename get_dbh to connection
jakubvrana authored
296 $return[] = "MATCH (" . implode(", ", array_map('idf_escape', $index["columns"])) . ") AGAINST (" . $connection->quote($_GET["fulltext"][$i]) . (isset($_GET["boolean"][$i]) ? " IN BOOLEAN MODE" : "") . ")";
d24ad78 Select boxes customization
jakubvrana authored
297 }
298 }
299 foreach ((array) $_GET["where"] as $val) {
300 if (strlen("$val[col]$val[val]") && in_array($val["op"], $this->operators)) {
98b88eb Remove fulltext search without index
jakubvrana authored
301 $in = process_length($val["val"]);
302 $cond = " $val[op]" . (ereg('NULL$', $val["op"]) ? "" : (ereg('IN$', $val["op"]) ? " (" . (strlen($in) ? $in : "NULL") . ")" : " " . $this->processInput($fields[$val["col"]], $val["val"])));
303 if (strlen($val["col"])) {
304 $return[] = idf_escape($val["col"]) . $cond;
d24ad78 Select boxes customization
jakubvrana authored
305 } else {
98b88eb Remove fulltext search without index
jakubvrana authored
306 // find anywhere
307 $cols = array();
308 foreach ($fields as $name => $field) {
309 if (is_numeric($val["val"]) || !ereg('int|float|double|decimal', $field["type"])) {
310 $cols[] = $name;
d24ad78 Select boxes customization
jakubvrana authored
311 }
312 }
98b88eb Remove fulltext search without index
jakubvrana authored
313 $return[] = ($cols ? "(" . implode("$cond OR ", array_map('idf_escape', $cols)) . "$cond)" : "0");
d24ad78 Select boxes customization
jakubvrana authored
314 }
315 }
316 }
317 return $return;
318 }
319
320 /** Process order box in select
321 * @param array
322 * @param array
323 * @return array expressions to join by comma
324 */
07e1ae1 FOUND_ROWS only with GROUP BY
jakubvrana authored
325 function selectOrderProcess($fields, $indexes) {
d24ad78 Select boxes customization
jakubvrana authored
326 $return = array();
327 foreach ((array) $_GET["order"] as $key => $val) {
821d040 Order by COUNT (thanks to paranoiq)
jakubvrana authored
328 if (isset($fields[$val]) || preg_match('~^((COUNT\\(DISTINCT |[A-Z0-9_]+\\()`(?:[^`]|``)+`\\)|COUNT\\(\\*\\))$~', $val)) {
d24ad78 Select boxes customization
jakubvrana authored
329 $return[] = idf_escape($val) . (isset($_GET["desc"][$key]) ? " DESC" : "");
330 }
331 }
332 return $return;
333 }
334
335 /** Process limit box in select
336 * @return string expression to use in LIMIT, will be escaped
337 */
338 function selectLimitProcess() {
339 return (isset($_GET["limit"]) ? $_GET["limit"] : "30");
340 }
341
342 /** Process length box in select
343 * @return string number of characters to shorten texts, will be escaped
344 */
345 function selectLengthProcess() {
346 return (isset($_GET["text_length"]) ? $_GET["text_length"] : "100");
347 }
348
c64c4fd Adminer class
jakubvrana authored
349 /** Process extras in select form
350 * @param array AND conditions
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored
351 * @param array
c64c4fd Adminer class
jakubvrana authored
352 * @return bool true if processed, false to process other parts of form
353 */
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored
354 function selectEmailProcess($where, $foreignKeys) {
c64c4fd Adminer class
jakubvrana authored
355 return false;
356 }
357
358 /** Query printed after execution in the message
359 * @param string executed query
360 * @return string
361 */
362 function messageQuery($query) {
be49e08 Improve session restarting
jakubvrana authored
363 restart_session();
c64c4fd Adminer class
jakubvrana authored
364 $id = "sql-" . count($_SESSION["messages"]);
3022dcb Define DB
jakubvrana authored
365 $_SESSION["history"][$_GET["server"]][DB][] = $query;
11982f1 Shorten printed SQL query
jakubvrana authored
366 return " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><div id='$id' class='hidden'><pre class='jush-sql'>" . shorten_utf8($query, 1000) . '</pre><a href="' . h(ME . 'sql=&history=' . (count($_SESSION["history"][$_GET["server"]][DB]) - 1)) . '">' . lang('Edit') . '</a></div>';
c64c4fd Adminer class
jakubvrana authored
367 }
368
369 /** Functions displayed in edit form
370 * @param array single field from fields()
371 * @return array
372 */
373 function editFunctions($field) {
374 $return = array("");
4cead56 Edit default values directly in table creation
jakubvrana authored
375 if (ereg('char|date|time', $field["type"])) {
376 $return = (ereg('char', $field["type"]) ? array("", "md5", "sha1", "password", "uuid") : array("", "now")); //! JavaScript for disabling maxlength
377 }
378 if (!isset($_GET["call"]) && (isset($_GET["select"]) || where($_GET))) {
379 // relative functions
380 if (ereg('int|float|double|decimal', $field["type"])) {
381 $return = array("", "+", "-");
4921235 Hide edit functions in Editor
jakubvrana authored
382 }
4cead56 Edit default values directly in table creation
jakubvrana authored
383 if (ereg('date', $field["type"])) {
384 $return[] = "+ interval";
385 $return[] = "- interval";
386 }
387 if (ereg('time', $field["type"])) {
388 $return[] = "addtime";
389 $return[] = "subtime";
4921235 Hide edit functions in Editor
jakubvrana authored
390 }
309f681 Relative function concat
jakubvrana authored
391 if (ereg('char|text', $field["type"])) {
392 $return[] = "concat";
393 }
4921235 Hide edit functions in Editor
jakubvrana authored
394 }
4cead56 Edit default values directly in table creation
jakubvrana authored
395 if ($field["null"]) {
c64c4fd Adminer class
jakubvrana authored
396 array_unshift($return, "NULL");
397 }
9fc052b Unselect original after value input
jakubvrana authored
398 return $return;
4921235 Hide edit functions in Editor
jakubvrana authored
399 }
c64c4fd Adminer class
jakubvrana authored
400
401 /** Get options to display edit field
402 * @param string table name
403 * @param array single field from fields()
e1abcda Treat tinyint(1) as boolean
jakubvrana authored
404 * @param string attributes to use inside the tag
405 * @param string
406 * @return string custom input field or empty string for default
c64c4fd Adminer class
jakubvrana authored
407 */
e1abcda Treat tinyint(1) as boolean
jakubvrana authored
408 function editInput($table, $field, $attrs, $value) {
ec0282b Enum editing
jakubvrana authored
409 if ($field["type"] == "enum") {
410 return ($field["null"] ? "<label><input type='radio'$attrs value=''" . (isset($value) || isset($_GET["select"]) ? "" : " checked") . "><em>NULL</em></label> " : "")
411 . "<input type='radio'$attrs value='0'" . ($value === 0 ? " checked" : "") . ">"
412 ;
413 }
414 return "";
4921235 Hide edit functions in Editor
jakubvrana authored
415 }
c64c4fd Adminer class
jakubvrana authored
416
417 /** Process sent input
418 * @param array single field from fields()
a0def47 Date localization
jakubvrana authored
419 * @param string
420 * @param string
c64c4fd Adminer class
jakubvrana authored
421 * @return string expression to use in a query
422 */
a0def47 Date localization
jakubvrana authored
423 function processInput($field, $value, $function = "") {
64d616c Rename get_dbh to connection
jakubvrana authored
424 global $connection;
a0def47 Date localization
jakubvrana authored
425 $name = $field["field"];
64d616c Rename get_dbh to connection
jakubvrana authored
426 $return = $connection->quote($value);
c64c4fd Adminer class
jakubvrana authored
427 if (ereg('^(now|uuid)$', $function)) {
428 $return = "$function()";
429 } elseif (ereg('^[+-]$', $function)) {
430 $return = idf_escape($name) . " $function $return";
431 } elseif (ereg('^[+-] interval$', $function)) {
432 $return = idf_escape($name) . " $function " . (preg_match("~^([0-9]+|'[0-9.: -]') [A-Z_]+$~i", $value) ? $value : $return);
309f681 Relative function concat
jakubvrana authored
433 } elseif (ereg('^(addtime|subtime|concat)$', $function)) {
c64c4fd Adminer class
jakubvrana authored
434 $return = "$function(" . idf_escape($name) . ", $return)";
435 } elseif (ereg('^(md5|sha1|password)$', $function)) {
436 $return = "$function($return)";
437 }
438 return $return;
a78c941 Empty value in Editor as NULL
jakubvrana authored
439 }
c64c4fd Adminer class
jakubvrana authored
440
e40612a Use radio in export
jakubvrana authored
441 /** Returns export output options
442 * @param bool generate select (otherwise radio)
443 * @return string
444 */
445 function dumpOutput($select) {
446 $return = array('text' => lang('open'), 'file' => lang('save'));
447 if (function_exists('gzencode')) {
448 $return['gz'] = 'gzip';
449 }
450 if (function_exists('bzcompress')) {
451 $return['bz2'] = 'bzip2';
452 }
453 // ZipArchive requires temporary file, ZIP can be created by gzcompress - see PEAR File_Archive
454 return html_select("output", $return, "text", $select);
455 }
456
457 /** Returns export format options
458 * @param bool generate select (otherwise radio)
459 * @return string
460 */
461 function dumpFormat($select) {
462 return html_select("format", array('sql' => 'SQL', 'csv' => 'CSV'), "sql", $select);
463 }
464
c64c4fd Adminer class
jakubvrana authored
465 /** Prints navigation after Adminer title
466 * @param string can be "auth" if there is no database connection or "db" if there is no database selected
467 * @return null
468 */
469 function navigation($missing) {
df0c4bb Simplify tablesPrint
jakubvrana authored
470 global $VERSION, $connection;
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored
471 ?>
472 <h1>
473 <a href="http://www.adminer.org/" id="h1"><?php echo $this->name(); ?></a>
474 <span class="version"><?php echo $VERSION; ?></span>
475 <a href="http://www.adminer.org/#download" id="version"><?php echo (version_compare($VERSION, $_COOKIE["adminer_version"]) < 0 ? h($_COOKIE["adminer_version"]) : ""); ?></a>
476 </h1>
477 <?php
c64c4fd Adminer class
jakubvrana authored
478 if ($missing != "auth") {
479 $databases = get_databases();
480 ?>
b95f24e Editor: User friendly data editor
jakubvrana authored
481 <form action="" method="post">
fde1171 Add CSS classes (thanks to cvicebni ubor)
jakubvrana authored
482 <p class="logout">
98507da Function verify_version doesn't use version parameter
jakubvrana authored
483 <a href="<?php echo h(ME); ?>sql="><?php echo lang('SQL command'); ?></a>
484 <a href="<?php echo h(ME); ?>dump=<?php echo urlencode(isset($_GET["table"]) ? $_GET["table"] : $_GET["select"]); ?>"><?php echo lang('Dump'); ?></a>
ace55ed HTML instead of XHTML
jakubvrana authored
485 <input type="hidden" name="token" value="<?php echo $_SESSION["tokens"][$_GET["server"]]; ?>">
486 <input type="submit" name="logout" value="<?php echo lang('Logout'); ?>">
d2ba593 Browsers interpret <form><p></form> as <form><p></form></p>
jakubvrana authored
487 </p>
b95f24e Editor: User friendly data editor
jakubvrana authored
488 </form>
489 <form action="">
25cef1f Disable session.use_trans_sid to preserve export result
jakubvrana authored
490 <p>
491 <?php if (SID) { ?><input type="hidden" name="<?php echo session_name(); ?>" value="<?php echo h(session_id()); ?>"><?php } ?>
492 <?php if (strlen($_GET["server"])) { ?><input type="hidden" name="server" value="<?php echo h($_GET["server"]); ?>"><?php } ?>
0698409 Utilize html_select
jakubvrana authored
493 <?php echo ($databases ? html_select("db", array("" => "(" . lang('database') . ")") + $databases, DB, "this.form.submit();") : '<input name="db" value="' . h(DB) . '">'); ?>
ace55ed HTML instead of XHTML
jakubvrana authored
494 <?php if (isset($_GET["sql"])) { ?><input type="hidden" name="sql" value=""><?php } ?>
495 <?php if (isset($_GET["schema"])) { ?><input type="hidden" name="schema" value=""><?php } ?>
496 <?php if (isset($_GET["dump"])) { ?><input type="hidden" name="dump" value=""><?php } ?>
fbac7fa Spaces
jakubvrana authored
497 <input type="submit" value="<?php echo lang('Use'); ?>"<?php echo ($databases ? " class='hidden'" : ""); ?>>
d2ba593 Browsers interpret <form><p></form> as <form><p></form></p>
jakubvrana authored
498 </p>
b95f24e Editor: User friendly data editor
jakubvrana authored
499 </form>
500 <?php
df0c4bb Simplify tablesPrint
jakubvrana authored
501 if ($missing != "db" && strlen(DB) && $connection->select_db(DB)) {
5e01a62 Prepare for SQLite
jakubvrana authored
502 $tables = tables_list();
df0c4bb Simplify tablesPrint
jakubvrana authored
503 if (!$tables) {
504 echo "<p class='message'>" . lang('No tables.') . "\n";
505 } else {
506 $this->tablesPrint($tables);
507 }
508 echo '<p><a href="' . h(ME) . 'create=">' . lang('Create new table') . "</a>\n";
509 }
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored
510 }
511 }
512
513 /** Prints table list in menu
df0c4bb Simplify tablesPrint
jakubvrana authored
514 * @param array
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored
515 * @return null
516 */
df0c4bb Simplify tablesPrint
jakubvrana authored
517 function tablesPrint($tables) {
518 echo "<p id='tables'>\n";
519 foreach ($tables as $table) {
520 echo '<a href="' . h(ME) . 'select=' . urlencode($table) . '">' . lang('select') . '</a> ';
521 echo '<a href="' . h(ME) . 'table=' . urlencode($table) . '">' . $this->tableName(array("Name" => $table)) . "</a><br>\n"; //! Adminer::tableName may work with full table status
b95f24e Editor: User friendly data editor
jakubvrana authored
522 }
523 }
c64c4fd Adminer class
jakubvrana authored
524
2c445a8 Extensibility basics
jakubvrana authored
525 }
464d84a Define functions unconditionally
jakubvrana authored
526
527 $adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer);
Something went wrong with that request. Please try again.