Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 545 lines (503 sloc) 19.352 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) {
7352c28 Replace strlen() by != ""
jakubvrana authored
210 if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) {
d24ad78 Select boxes customization
jakubvrana authored
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) {
7352c28 Replace strlen() by != ""
jakubvrana authored
311 if ($index["type"] == "FULLTEXT" && $_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) {
7352c28 Replace strlen() by != ""
jakubvrana authored
316 if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) {
98b88eb Remove fulltext search without index
jakubvrana authored
317 $in = process_length($val["val"]);
7352c28 Replace strlen() by != ""
jakubvrana authored
318 $cond = " $val[op]" . (ereg('NULL$', $val["op"]) ? "" : (ereg('IN$', $val["op"]) ? " (" . ($in != "" ? $in : "NULL") . ")" : " " . $this->processInput($fields[$val["col"]], $val["val"])));
319 if ($val["col"] != "") {
98b88eb Remove fulltext search without index
jakubvrana authored
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"])) {
d79b160 Illegal mix of collations
jakubvrana authored
326 $name = idf_escape($name);
327 $cols[] = (ereg('char|text|enum|set', $field["type"]) && !ereg('^utf8', $field["collation"]) ? "CONVERT($name USING utf8)" : $name);
d24ad78 Select boxes customization
jakubvrana authored
328 }
329 }
d79b160 Illegal mix of collations
jakubvrana authored
330 $return[] = ($cols ? "(" . implode("$cond OR ", $cols) . "$cond)" : "0");
d24ad78 Select boxes customization
jakubvrana authored
331 }
332 }
333 }
334 return $return;
335 }
336
337 /** Process order box in select
338 * @param array
339 * @param array
340 * @return array expressions to join by comma
341 */
07e1ae1 FOUND_ROWS only with GROUP BY
jakubvrana authored
342 function selectOrderProcess($fields, $indexes) {
d24ad78 Select boxes customization
jakubvrana authored
343 $return = array();
344 foreach ((array) $_GET["order"] as $key => $val) {
821d040 Order by COUNT (thanks to paranoiq)
jakubvrana authored
345 if (isset($fields[$val]) || preg_match('~^((COUNT\\(DISTINCT |[A-Z0-9_]+\\()`(?:[^`]|``)+`\\)|COUNT\\(\\*\\))$~', $val)) {
d24ad78 Select boxes customization
jakubvrana authored
346 $return[] = idf_escape($val) . (isset($_GET["desc"][$key]) ? " DESC" : "");
347 }
348 }
349 return $return;
350 }
351
352 /** Process limit box in select
353 * @return string expression to use in LIMIT, will be escaped
354 */
355 function selectLimitProcess() {
356 return (isset($_GET["limit"]) ? $_GET["limit"] : "30");
357 }
358
359 /** Process length box in select
360 * @return string number of characters to shorten texts, will be escaped
361 */
362 function selectLengthProcess() {
363 return (isset($_GET["text_length"]) ? $_GET["text_length"] : "100");
364 }
365
c64c4fd Adminer class
jakubvrana authored
366 /** Process extras in select form
367 * @param array AND conditions
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored
368 * @param array
c64c4fd Adminer class
jakubvrana authored
369 * @return bool true if processed, false to process other parts of form
370 */
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored
371 function selectEmailProcess($where, $foreignKeys) {
c64c4fd Adminer class
jakubvrana authored
372 return false;
373 }
374
375 /** Query printed after execution in the message
376 * @param string executed query
377 * @return string
378 */
379 function messageQuery($query) {
be49e08 Improve session restarting
jakubvrana authored
380 restart_session();
c64c4fd Adminer class
jakubvrana authored
381 $id = "sql-" . count($_SESSION["messages"]);
3022dcb Define DB
jakubvrana authored
382 $_SESSION["history"][$_GET["server"]][DB][] = $query;
11982f1 Shorten printed SQL query
jakubvrana authored
383 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
384 }
385
386 /** Functions displayed in edit form
387 * @param array single field from fields()
388 * @return array
389 */
390 function editFunctions($field) {
391 $return = array("");
4cead56 Edit default values directly in table creation
jakubvrana authored
392 if (ereg('char|date|time', $field["type"])) {
393 $return = (ereg('char', $field["type"]) ? array("", "md5", "sha1", "password", "uuid") : array("", "now")); //! JavaScript for disabling maxlength
394 }
395 if (!isset($_GET["call"]) && (isset($_GET["select"]) || where($_GET))) {
396 // relative functions
397 if (ereg('int|float|double|decimal', $field["type"])) {
398 $return = array("", "+", "-");
4921235 Hide edit functions in Editor
jakubvrana authored
399 }
4cead56 Edit default values directly in table creation
jakubvrana authored
400 if (ereg('date', $field["type"])) {
401 $return[] = "+ interval";
402 $return[] = "- interval";
403 }
404 if (ereg('time', $field["type"])) {
405 $return[] = "addtime";
406 $return[] = "subtime";
4921235 Hide edit functions in Editor
jakubvrana authored
407 }
309f681 Relative function concat
jakubvrana authored
408 if (ereg('char|text', $field["type"])) {
409 $return[] = "concat";
410 }
4921235 Hide edit functions in Editor
jakubvrana authored
411 }
4cead56 Edit default values directly in table creation
jakubvrana authored
412 if ($field["null"]) {
c64c4fd Adminer class
jakubvrana authored
413 array_unshift($return, "NULL");
414 }
9fc052b Unselect original after value input
jakubvrana authored
415 return $return;
4921235 Hide edit functions in Editor
jakubvrana authored
416 }
c64c4fd Adminer class
jakubvrana authored
417
418 /** Get options to display edit field
419 * @param string table name
420 * @param array single field from fields()
e1abcda Treat tinyint(1) as boolean
jakubvrana authored
421 * @param string attributes to use inside the tag
422 * @param string
423 * @return string custom input field or empty string for default
c64c4fd Adminer class
jakubvrana authored
424 */
e1abcda Treat tinyint(1) as boolean
jakubvrana authored
425 function editInput($table, $field, $attrs, $value) {
ec0282b Enum editing
jakubvrana authored
426 if ($field["type"] == "enum") {
427 return ($field["null"] ? "<label><input type='radio'$attrs value=''" . (isset($value) || isset($_GET["select"]) ? "" : " checked") . "><em>NULL</em></label> " : "")
428 . "<input type='radio'$attrs value='0'" . ($value === 0 ? " checked" : "") . ">"
429 ;
430 }
431 return "";
4921235 Hide edit functions in Editor
jakubvrana authored
432 }
c64c4fd Adminer class
jakubvrana authored
433
434 /** Process sent input
435 * @param array single field from fields()
a0def47 Date localization
jakubvrana authored
436 * @param string
437 * @param string
c64c4fd Adminer class
jakubvrana authored
438 * @return string expression to use in a query
439 */
a0def47 Date localization
jakubvrana authored
440 function processInput($field, $value, $function = "") {
64d616c Rename get_dbh to connection
jakubvrana authored
441 global $connection;
a0def47 Date localization
jakubvrana authored
442 $name = $field["field"];
64d616c Rename get_dbh to connection
jakubvrana authored
443 $return = $connection->quote($value);
c64c4fd Adminer class
jakubvrana authored
444 if (ereg('^(now|uuid)$', $function)) {
445 $return = "$function()";
446 } elseif (ereg('^[+-]$', $function)) {
447 $return = idf_escape($name) . " $function $return";
448 } elseif (ereg('^[+-] interval$', $function)) {
449 $return = idf_escape($name) . " $function " . (preg_match("~^([0-9]+|'[0-9.: -]') [A-Z_]+$~i", $value) ? $value : $return);
309f681 Relative function concat
jakubvrana authored
450 } elseif (ereg('^(addtime|subtime|concat)$', $function)) {
c64c4fd Adminer class
jakubvrana authored
451 $return = "$function(" . idf_escape($name) . ", $return)";
452 } elseif (ereg('^(md5|sha1|password)$', $function)) {
453 $return = "$function($return)";
454 }
455 return $return;
a78c941 Empty value in Editor as NULL
jakubvrana authored
456 }
c64c4fd Adminer class
jakubvrana authored
457
e40612a Use radio in export
jakubvrana authored
458 /** Returns export output options
459 * @param bool generate select (otherwise radio)
460 * @return string
461 */
462 function dumpOutput($select) {
463 $return = array('text' => lang('open'), 'file' => lang('save'));
464 if (function_exists('gzencode')) {
465 $return['gz'] = 'gzip';
466 }
467 if (function_exists('bzcompress')) {
468 $return['bz2'] = 'bzip2';
469 }
470 // ZipArchive requires temporary file, ZIP can be created by gzcompress - see PEAR File_Archive
471 return html_select("output", $return, "text", $select);
472 }
473
474 /** Returns export format options
475 * @param bool generate select (otherwise radio)
476 * @return string
477 */
478 function dumpFormat($select) {
479 return html_select("format", array('sql' => 'SQL', 'csv' => 'CSV'), "sql", $select);
480 }
481
c64c4fd Adminer class
jakubvrana authored
482 /** Prints navigation after Adminer title
483 * @param string can be "auth" if there is no database connection or "db" if there is no database selected
484 * @return null
485 */
486 function navigation($missing) {
df0c4bb Simplify tablesPrint
jakubvrana authored
487 global $VERSION, $connection;
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored
488 ?>
489 <h1>
490 <a href="http://www.adminer.org/" id="h1"><?php echo $this->name(); ?></a>
491 <span class="version"><?php echo $VERSION; ?></span>
492 <a href="http://www.adminer.org/#download" id="version"><?php echo (version_compare($VERSION, $_COOKIE["adminer_version"]) < 0 ? h($_COOKIE["adminer_version"]) : ""); ?></a>
493 </h1>
494 <?php
c64c4fd Adminer class
jakubvrana authored
495 if ($missing != "auth") {
496 $databases = get_databases();
497 ?>
b95f24e Editor: User friendly data editor
jakubvrana authored
498 <form action="" method="post">
fde1171 Add CSS classes (thanks to cvicebni ubor)
jakubvrana authored
499 <p class="logout">
94a2be5 Highlight current links
jakubvrana authored
500 <a href="<?php echo h(ME); ?>sql="><?php echo bold(lang('SQL command'), isset($_GET["sql"])); ?></a>
501 <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
502 <input type="hidden" name="token" value="<?php echo $_SESSION["tokens"][$_GET["server"]]; ?>">
503 <input type="submit" name="logout" value="<?php echo lang('Logout'); ?>">
d2ba593 Browsers interpret <form><p></form> as <form><p></form></p>
jakubvrana authored
504 </p>
b95f24e Editor: User friendly data editor
jakubvrana authored
505 </form>
506 <form action="">
25cef1f Disable session.use_trans_sid to preserve export result
jakubvrana authored
507 <p>
508 <?php if (SID) { ?><input type="hidden" name="<?php echo session_name(); ?>" value="<?php echo h(session_id()); ?>"><?php } ?>
7352c28 Replace strlen() by != ""
jakubvrana authored
509 <?php if ($_GET["server"] != "") { ?><input type="hidden" name="server" value="<?php echo h($_GET["server"]); ?>"><?php } ?>
0698409 Utilize html_select
jakubvrana authored
510 <?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
511 <?php if (isset($_GET["sql"])) { ?><input type="hidden" name="sql" value=""><?php } ?>
512 <?php if (isset($_GET["schema"])) { ?><input type="hidden" name="schema" value=""><?php } ?>
513 <?php if (isset($_GET["dump"])) { ?><input type="hidden" name="dump" value=""><?php } ?>
fbac7fa Spaces
jakubvrana authored
514 <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
515 </p>
b95f24e Editor: User friendly data editor
jakubvrana authored
516 </form>
517 <?php
7352c28 Replace strlen() by != ""
jakubvrana authored
518 if ($missing != "db" && DB != "" && $connection->select_db(DB)) {
5e01a62 Prepare for SQLite
jakubvrana authored
519 $tables = tables_list();
df0c4bb Simplify tablesPrint
jakubvrana authored
520 if (!$tables) {
521 echo "<p class='message'>" . lang('No tables.') . "\n";
522 } else {
523 $this->tablesPrint($tables);
524 }
94a2be5 Highlight current links
jakubvrana authored
525 echo '<p><a href="' . h(ME) . 'create=">' . bold(lang('Create new table'), $_GET["create"] === "") . "</a>\n";
df0c4bb Simplify tablesPrint
jakubvrana authored
526 }
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored
527 }
528 }
529
530 /** Prints table list in menu
df0c4bb Simplify tablesPrint
jakubvrana authored
531 * @param array
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored
532 * @return null
533 */
df0c4bb Simplify tablesPrint
jakubvrana authored
534 function tablesPrint($tables) {
535 echo "<p id='tables'>\n";
536 foreach ($tables as $table) {
94a2be5 Highlight current links
jakubvrana authored
537 echo '<a href="' . h(ME) . 'select=' . urlencode($table) . '">' . bold(lang('select'), $_GET["select"] == $table) . '</a> ';
538 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
539 }
540 }
c64c4fd Adminer class
jakubvrana authored
541
2c445a8 Extensibility basics
jakubvrana authored
542 }
464d84a Define functions unconditionally
jakubvrana authored
543
544 $adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer);
Something went wrong with that request. Please try again.