Skip to content

HTTPS clone URL

Subversion checkout URL

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