Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 564 lines (524 sloc) 20.02 kb
2c445a8 Extensibility basics
jakubvrana authored
1 <?php
c64c4fd Adminer class
jakubvrana authored
2 class Adminer {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
3 /** @var array operators used in select, null for all operators */
4 var $operators;
c64c4fd Adminer class
jakubvrana authored
5
6 /** Name in title and navigation
7 * @return string
8 */
9 function name() {
b349612 Remove useless translations
jakubvrana authored
10 return "Adminer";
c64c4fd Adminer class
jakubvrana authored
11 }
12
13 /** Connection parameters
14 * @return array ($server, $username, $password)
15 */
16 function credentials() {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
17 return array(SERVER, $_GET["username"], get_session("passwords"));
c64c4fd Adminer class
jakubvrana authored
18 }
19
95b4ea4 Permanent login
jakubvrana authored
20 /** Get key used for permanent login
21 * @return string cryptic string which gets combined with password
22 */
23 function permanentLogin() {
24 return "";
25 }
26
c64c4fd Adminer class
jakubvrana authored
27 /** Identifier of selected database
28 * @return string
29 */
30 function database() {
3022dcb Define DB
jakubvrana authored
31 // should be used everywhere instead of DB
32 return DB;
c64c4fd Adminer class
jakubvrana authored
33 }
34
35 /** Print login form
36 * @return null
37 */
3f5b683 Reintegrate sqlite branch
jakubvrana authored
38 function loginForm() {
39 global $drivers, $possible_drivers;
2faa08c Customize login and login form
jakubvrana authored
40 ?>
0205440 HTML whitespace
jakubvrana authored
41 <table cellspacing="0">
3f5b683 Reintegrate sqlite branch
jakubvrana authored
42 <tr><th><?php echo lang('System'); ?><td><?php echo (count($possible_drivers) > 3 ? html_select("driver", $drivers, DRIVER) : "<input type='hidden' name='driver' value='" . key($drivers) . "'>" . reset($drivers)); ?></tr>
43 <tr><th><?php echo lang('Server'); ?><td><input name="server" value="<?php echo h(SERVER); ?>">
4269b7b Auto-focus user-name in login form
jakubvrana authored
44 <tr><th><?php echo lang('Username'); ?><td><input id="username" name="username" value="<?php echo h($_GET["username"]); ?>">
0205440 HTML whitespace
jakubvrana authored
45 <tr><th><?php echo lang('Password'); ?><td><input type="password" name="password">
46 </table>
4269b7b Auto-focus user-name in login form
jakubvrana authored
47 <script type="text/javascript">
48 document.getElementById('username').focus();
49 </script>
2faa08c Customize login and login form
jakubvrana authored
50 <?php
8474399 Move Login button to customization
jakubvrana authored
51 echo "<p><input type='submit' value='" . lang('Login') . "'>\n";
95b4ea4 Permanent login
jakubvrana authored
52 if ($this->permanentLogin()) {
8474399 Move Login button to customization
jakubvrana authored
53 echo checkbox("permanent", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n";
95b4ea4 Permanent login
jakubvrana authored
54 }
2faa08c Customize login and login form
jakubvrana authored
55 }
c64c4fd Adminer class
jakubvrana authored
56
57 /** Authorize the user
58 * @param string
59 * @param string
60 * @return bool
61 */
62 function login($login, $password) {
63 return true;
97b8c7b Display images in Editor
jakubvrana authored
64 }
c64c4fd Adminer class
jakubvrana authored
65
66 /** Table caption used in navigation and headings
67 * @param array result of SHOW TABLE STATUS
68 * @return string
69 */
70 function tableName($tableStatus) {
689699a Shortcut for htmlspecialchars
jakubvrana authored
71 return h($tableStatus["Name"]);
c64c4fd Adminer class
jakubvrana authored
72 }
73
74 /** Field caption used in select and edit
75 * @param array single field returned from fields()
6c97b80 Display only first five columns in Editor example
jakubvrana authored
76 * @param int order of column in select
c64c4fd Adminer class
jakubvrana authored
77 * @return string
78 */
6c97b80 Display only first five columns in Editor example
jakubvrana authored
79 function fieldName($field, $order = 0) {
689699a Shortcut for htmlspecialchars
jakubvrana authored
80 return '<span title="' . h($field["full_type"]) . '">' . h($field["field"]) . '</span>';
c64c4fd Adminer class
jakubvrana authored
81 }
82
f2ed237 Display table links above table structure
jakubvrana authored
83 /** Print links after select heading
c64c4fd Adminer class
jakubvrana authored
84 * @param array result of SHOW TABLE STATUS
294b10b Highlight current link
jakubvrana authored
85 * @param string new item options, NULL for no new item
f2ed237 Display table links above table structure
jakubvrana authored
86 * @return null
c64c4fd Adminer class
jakubvrana authored
87 */
f2ed237 Display table links above table structure
jakubvrana authored
88 function selectLinks($tableStatus, $set = "") {
294b10b Highlight current link
jakubvrana authored
89 echo '<p class="tabs">';
2d8a2de Change table operations descriptions
jakubvrana authored
90 $links = array("select" => lang('Select data'), "table" => lang('Show structure'));
3f5b683 Reintegrate sqlite branch
jakubvrana authored
91 if (eregi("view", $tableStatus["Engine"])) {
294b10b Highlight current link
jakubvrana authored
92 $links["view"] = lang('Alter view');
3f5b683 Reintegrate sqlite branch
jakubvrana authored
93 } else {
94 $links["create"] = lang('Alter table');
f2ed237 Display table links above table structure
jakubvrana authored
95 }
96 if (isset($set)) {
294b10b Highlight current link
jakubvrana authored
97 $links["edit"] = lang('New item');
98 }
99 foreach ($links as $key => $val) {
94a2be5 Highlight current links
jakubvrana authored
100 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
101 }
102 echo "\n";
c64c4fd Adminer class
jakubvrana authored
103 }
104
105 /** Find backward keys for table
106 * @param string
09e93de Move backward keys to Editor
jakubvrana authored
107 * @param string
108 * @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
109 */
09e93de Move backward keys to Editor
jakubvrana authored
110 function backwardKeys($table, $tableName) {
c64c4fd Adminer class
jakubvrana authored
111 return array();
112 }
113
09e93de Move backward keys to Editor
jakubvrana authored
114 /** Print backward keys for row
115 * @param array result of $this->backwardKeys()
116 * @param array
117 * @return null
118 */
119 function backwardKeysPrint($backwardKeys, $row) {
120 }
121
c64c4fd Adminer class
jakubvrana authored
122 /** Query printed in select before execution
123 * @param string query to be executed
124 * @return string
125 */
126 function selectQuery($query) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
127 global $driver;
128 return "<p><code class='jush-$driver'>" . h(str_replace("\n", " ", $query)) . "</code> <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>\n";
c64c4fd Adminer class
jakubvrana authored
129 }
130
131 /** Description of a row in a table
132 * @param string
133 * @return string SQL expression, empty string for no description
134 */
135 function rowDescription($table) {
136 return "";
137 }
138
139 /** Get descriptions of selected data
140 * @param array all data to print
141 * @param array
142 * @return array
143 */
144 function rowDescriptions($rows, $foreignKeys) {
145 return $rows;
146 }
147
148 /** Value printed in select table
a0def47 Date localization
jakubvrana authored
149 * @param string HTML-escaped value to print
c64c4fd Adminer class
jakubvrana authored
150 * @param string link to foreign key
151 * @param array single field returned from fields()
152 * @return string
153 */
154 function selectVal($val, $link, $field) {
bb46cc9 Don't use <code> for NULL
jakubvrana authored
155 $return = ($val != "<i>NULL</i>" && $field["type"] == "char" ? "<code>$val</code>" : $val);
3f5b683 Reintegrate sqlite branch
jakubvrana authored
156 if (ereg('binary|blob|bytea', $field["type"]) && !is_utf8($val)) {
c64c4fd Adminer class
jakubvrana authored
157 $return = lang('%d byte(s)', strlen($val));
4921235 Hide edit functions in Editor
jakubvrana authored
158 }
12c042c Function htmlspecialchars now uses ENT_QUOTES
jakubvrana authored
159 return ($link ? "<a href='$link'>$return</a>" : $return);
c64c4fd Adminer class
jakubvrana authored
160 }
161
a0def47 Date localization
jakubvrana authored
162 /** Value conversion used in select and edit
163 * @param string
164 * @param array single field returned from fields()
2011428 Use LIKE operator in Editor
jakubvrana authored
165 * @return string
a0def47 Date localization
jakubvrana authored
166 */
167 function editVal($val, $field) {
168 return $val;
169 }
170
d24ad78 Select boxes customization
jakubvrana authored
171 /** Print columns box in select
172 * @param array result of selectColumnsProcess()
173 * @param array selectable columns
174 * @return null
175 */
176 function selectColumnsPrint($select, $columns) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
177 global $functions, $grouping;
dc667ea Hide select export and import
jakubvrana authored
178 print_fieldset("select", lang('Select'), $select);
d24ad78 Select boxes customization
jakubvrana authored
179 $i = 0;
3f5b683 Reintegrate sqlite branch
jakubvrana authored
180 $fun_group = array(lang('Functions') => $functions, lang('Aggregation') => $grouping);
d24ad78 Select boxes customization
jakubvrana authored
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"]);
3f5b683 Reintegrate sqlite branch
jakubvrana authored
184 echo "(<select name='columns[$i][col]'><option>" . optionlist($columns, $val["col"], true) . "</select>)</div>\n";
d24ad78 Select boxes customization
jakubvrana authored
185 $i++;
186 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored
187 echo "<div>" . html_select("columns[$i][fun]", array(-1 => "") + $fun_group, "", "this.nextSibling.nextSibling.onchange();");
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)) {
3f5b683 Reintegrate sqlite branch
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 }
3f5b683 Reintegrate sqlite branch
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) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
289 global $functions, $grouping;
d24ad78 Select boxes customization
jakubvrana authored
290 $select = array(); // select expressions, empty for *
291 $group = array(); // expressions without aggregation - will be used for GROUP BY if an aggregation function is used
292 foreach ((array) $_GET["columns"] as $key => $val) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
293 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
294 $select[$key] = apply_sql_function($val["fun"], (isset($columns[$val["col"]]) ? idf_escape($val["col"]) : "*"));
3f5b683 Reintegrate sqlite branch
jakubvrana authored
295 if (!in_array($val["fun"], $grouping)) {
d24ad78 Select boxes customization
jakubvrana authored
296 $group[] = $select[$key];
297 }
298 }
299 }
300 return array($select, $group);
301 }
302
303 /** Process search box in select
304 * @param array
305 * @param array
306 * @return array expressions to join by AND
307 */
07e1ae1 FOUND_ROWS only with GROUP BY
jakubvrana authored
308 function selectSearchProcess($fields, $indexes) {
64d616c Rename get_dbh to connection
jakubvrana authored
309 global $connection;
d24ad78 Select boxes customization
jakubvrana authored
310 $return = array();
311 foreach ($indexes as $i => $index) {
7352c28 Replace strlen() by != ""
jakubvrana authored
312 if ($index["type"] == "FULLTEXT" && $_GET["fulltext"][$i] != "") {
64d616c Rename get_dbh to connection
jakubvrana authored
313 $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
314 }
315 }
316 foreach ((array) $_GET["where"] as $val) {
7352c28 Replace strlen() by != ""
jakubvrana authored
317 if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
318 $cond = " $val[op]";
319 if (ereg('IN$', $val["op"])) {
320 $in = process_length($val["val"]);
321 $cond .= " (" . ($in != "" ? $in : "NULL") . ")";
322 } elseif ($val["op"] == "LIKE %%") {
323 $cond = " LIKE " . $this->processInput($fields[$val["col"]], "%$val[val]%");
324 } elseif (!ereg('NULL$', $val["op"])) {
325 $cond .= " " . $this->processInput($fields[$val["col"]], $val["val"]);
326 }
7352c28 Replace strlen() by != ""
jakubvrana authored
327 if ($val["col"] != "") {
98b88eb Remove fulltext search without index
jakubvrana authored
328 $return[] = idf_escape($val["col"]) . $cond;
d24ad78 Select boxes customization
jakubvrana authored
329 } else {
98b88eb Remove fulltext search without index
jakubvrana authored
330 // find anywhere
331 $cols = array();
332 foreach ($fields as $name => $field) {
333 if (is_numeric($val["val"]) || !ereg('int|float|double|decimal', $field["type"])) {
d79b160 Illegal mix of collations
jakubvrana authored
334 $name = idf_escape($name);
335 $cols[] = (ereg('char|text|enum|set', $field["type"]) && !ereg('^utf8', $field["collation"]) ? "CONVERT($name USING utf8)" : $name);
d24ad78 Select boxes customization
jakubvrana authored
336 }
337 }
d79b160 Illegal mix of collations
jakubvrana authored
338 $return[] = ($cols ? "(" . implode("$cond OR ", $cols) . "$cond)" : "0");
d24ad78 Select boxes customization
jakubvrana authored
339 }
340 }
341 }
342 return $return;
343 }
344
345 /** Process order box in select
346 * @param array
347 * @param array
348 * @return array expressions to join by comma
349 */
07e1ae1 FOUND_ROWS only with GROUP BY
jakubvrana authored
350 function selectOrderProcess($fields, $indexes) {
d24ad78 Select boxes customization
jakubvrana authored
351 $return = array();
352 foreach ((array) $_GET["order"] as $key => $val) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
353 if (isset($fields[$val]) || preg_match('~^((COUNT\\(DISTINCT |[A-Z0-9_]+\\()(`(?:[^`]|``)+`|"(?:[^"]|"")+")\\)|COUNT\\(\\*\\))$~', $val)) { //! MS SQL uses []
354 $return[] = (isset($fields[$val]) ? idf_escape($val) : $val) . (isset($_GET["desc"][$key]) ? " DESC" : "");
d24ad78 Select boxes customization
jakubvrana authored
355 }
356 }
357 return $return;
358 }
359
360 /** Process limit box in select
361 * @return string expression to use in LIMIT, will be escaped
362 */
363 function selectLimitProcess() {
364 return (isset($_GET["limit"]) ? $_GET["limit"] : "30");
365 }
366
367 /** Process length box in select
368 * @return string number of characters to shorten texts, will be escaped
369 */
370 function selectLengthProcess() {
371 return (isset($_GET["text_length"]) ? $_GET["text_length"] : "100");
372 }
373
c64c4fd Adminer class
jakubvrana authored
374 /** Process extras in select form
375 * @param array AND conditions
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored
376 * @param array
c64c4fd Adminer class
jakubvrana authored
377 * @return bool true if processed, false to process other parts of form
378 */
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored
379 function selectEmailProcess($where, $foreignKeys) {
c64c4fd Adminer class
jakubvrana authored
380 return false;
381 }
382
383 /** Query printed after execution in the message
384 * @param string executed query
385 * @return string
386 */
387 function messageQuery($query) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
388 global $driver;
be49e08 Improve session restarting
jakubvrana authored
389 restart_session();
c64c4fd Adminer class
jakubvrana authored
390 $id = "sql-" . count($_SESSION["messages"]);
3f5b683 Reintegrate sqlite branch
jakubvrana authored
391 $history = &get_session("history");
392 $history[DB][] = (strlen($query) > 1e6 ? ereg_replace('[\x80-\xFF]+$', '', substr($query, 0, 1e6)) . "\n..." : $query); // [\x80-\xFF] - valid UTF-8, \n - can end by one-line comment
393 return " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><div id='$id' class='hidden'><pre class='jush-$driver'>" . shorten_utf8($query, 1000) . '</pre><p><a href="' . h(ME . 'sql=&history=' . (count($history[DB]) - 1)) . '">' . lang('Edit') . '</a></div>';
c64c4fd Adminer class
jakubvrana authored
394 }
395
396 /** Functions displayed in edit form
397 * @param array single field from fields()
398 * @return array
399 */
400 function editFunctions($field) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
401 global $edit_functions;
02f7521 Fix input onchange
jakubvrana authored
402 $return = ($field["null"] ? "NULL/" : "");
3f5b683 Reintegrate sqlite branch
jakubvrana authored
403 foreach ($edit_functions as $key => $functions) {
404 if (!$key || (!isset($_GET["call"]) && (isset($_GET["select"]) || where($_GET)))) { // relative functions
405 foreach ($functions as $pattern => $val) {
406 if (!$pattern || ereg($pattern, $field["type"])) {
407 $return .= "/$val";
408 }
409 }
309f681 Relative function concat
jakubvrana authored
410 }
4921235 Hide edit functions in Editor
jakubvrana authored
411 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored
412 return explode("/", $return);
4921235 Hide edit functions in Editor
jakubvrana authored
413 }
c64c4fd Adminer class
jakubvrana authored
414
415 /** Get options to display edit field
416 * @param string table name
417 * @param array single field from fields()
e1abcda Treat tinyint(1) as boolean
jakubvrana authored
418 * @param string attributes to use inside the tag
419 * @param string
420 * @return string custom input field or empty string for default
c64c4fd Adminer class
jakubvrana authored
421 */
e1abcda Treat tinyint(1) as boolean
jakubvrana authored
422 function editInput($table, $field, $attrs, $value) {
ec0282b Enum editing
jakubvrana authored
423 if ($field["type"] == "enum") {
424 return ($field["null"] ? "<label><input type='radio'$attrs value=''" . (isset($value) || isset($_GET["select"]) ? "" : " checked") . "><em>NULL</em></label> " : "")
425 . "<input type='radio'$attrs value='0'" . ($value === 0 ? " checked" : "") . ">"
426 ;
427 }
428 return "";
4921235 Hide edit functions in Editor
jakubvrana authored
429 }
c64c4fd Adminer class
jakubvrana authored
430
431 /** Process sent input
432 * @param array single field from fields()
a0def47 Date localization
jakubvrana authored
433 * @param string
434 * @param string
c64c4fd Adminer class
jakubvrana authored
435 * @return string expression to use in a query
436 */
a0def47 Date localization
jakubvrana authored
437 function processInput($field, $value, $function = "") {
64d616c Rename get_dbh to connection
jakubvrana authored
438 global $connection;
a0def47 Date localization
jakubvrana authored
439 $name = $field["field"];
64d616c Rename get_dbh to connection
jakubvrana authored
440 $return = $connection->quote($value);
3f5b683 Reintegrate sqlite branch
jakubvrana authored
441 if (ereg('^(now|getdate|uuid)$', $function)) {
c64c4fd Adminer class
jakubvrana authored
442 $return = "$function()";
3f5b683 Reintegrate sqlite branch
jakubvrana authored
443 } elseif (ereg('^([+-]|\\|\\|)$', $function)) {
c64c4fd Adminer class
jakubvrana authored
444 $return = idf_escape($name) . " $function $return";
445 } elseif (ereg('^[+-] interval$', $function)) {
446 $return = idf_escape($name) . " $function " . (preg_match("~^([0-9]+|'[0-9.: -]') [A-Z_]+$~i", $value) ? $value : $return);
309f681 Relative function concat
jakubvrana authored
447 } elseif (ereg('^(addtime|subtime|concat)$', $function)) {
c64c4fd Adminer class
jakubvrana authored
448 $return = "$function(" . idf_escape($name) . ", $return)";
5df3abb Add encrypt SQL function (thanks to Dragonn)
jakubvrana authored
449 } elseif (ereg('^(md5|sha1|password|encrypt)$', $function)) {
c64c4fd Adminer class
jakubvrana authored
450 $return = "$function($return)";
451 }
452 return $return;
a78c941 Empty value in Editor as NULL
jakubvrana authored
453 }
c64c4fd Adminer class
jakubvrana authored
454
e40612a Use radio in export
jakubvrana authored
455 /** Returns export output options
456 * @param bool generate select (otherwise radio)
3f5b683 Reintegrate sqlite branch
jakubvrana authored
457 * @param string
e40612a Use radio in export
jakubvrana authored
458 * @return string
459 */
3f5b683 Reintegrate sqlite branch
jakubvrana authored
460 function dumpOutput($select, $value = "") {
e40612a Use radio in export
jakubvrana authored
461 $return = array('text' => lang('open'), 'file' => lang('save'));
462 if (function_exists('gzencode')) {
463 $return['gz'] = 'gzip';
464 }
465 if (function_exists('bzcompress')) {
466 $return['bz2'] = 'bzip2';
467 }
468 // ZipArchive requires temporary file, ZIP can be created by gzcompress - see PEAR File_Archive
3f5b683 Reintegrate sqlite branch
jakubvrana authored
469 return html_select("output", $return, $value, $select);
e40612a Use radio in export
jakubvrana authored
470 }
471
472 /** Returns export format options
473 * @param bool generate select (otherwise radio)
3f5b683 Reintegrate sqlite branch
jakubvrana authored
474 * @param string
e40612a Use radio in export
jakubvrana authored
475 * @return string
476 */
3f5b683 Reintegrate sqlite branch
jakubvrana authored
477 function dumpFormat($select, $value = "") {
478 return html_select("format", array('sql' => 'SQL', 'csv' => 'CSV,', 'csv;' => 'CSV;'), $value, $select);
e40612a Use radio in export
jakubvrana authored
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) {
8e81039 Link table names in SQL queries
jakubvrana authored
486 global $VERSION, $connection, $token, $driver;
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>
7ee5992 Revert 1511 (always dump all tables)
jakubvrana authored
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>
3f5b683 Reintegrate sqlite branch
jakubvrana authored
501 <input type="hidden" name="token" value="<?php echo $token; ?>">
ace55ed HTML instead of XHTML
jakubvrana authored
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>
3f5b683 Reintegrate sqlite branch
jakubvrana authored
507 <?php hidden_fields_get(); ?>
0698409 Utilize html_select
jakubvrana authored
508 <?php echo ($databases ? html_select("db", array("" => "(" . lang('database') . ")") + $databases, DB, "this.form.submit();") : '<input name="db" value="' . h(DB) . '">'); ?>
3f5b683 Reintegrate sqlite branch
jakubvrana authored
509 <input type="submit" value="<?php echo lang('Use'); ?>"<?php echo ($databases ? " class='hidden'" : ""); ?>>
b95f24e Editor: User friendly data editor
jakubvrana authored
510 <?php
7352c28 Replace strlen() by != ""
jakubvrana authored
511 if ($missing != "db" && DB != "" && $connection->select_db(DB)) {
6420c58 Schema support for PostgreSQL
jakubvrana authored
512 if (support("scheme")) {
513 echo "<br>" . html_select("ns", array("" => "(" . lang('schema') . ")") + schemas(), $_GET["ns"], "this.form.submit();");
514 if ($_GET["ns"] != "") {
515 set_schema($_GET["ns"]);
8e81039 Link table names in SQL queries
jakubvrana authored
516 }
6420c58 Schema support for PostgreSQL
jakubvrana authored
517 }
518 if ($_GET["ns"] !== "") {
519 $tables = tables_list();
520 if (!$tables) {
521 echo "<p class='message'>" . lang('No tables.') . "\n";
522 } else {
523 $this->tablesPrint($tables);
524 $links = array();
525 foreach ($tables as $table => $type) {
526 $links[] = preg_quote($table, '/');
527 }
528 echo "<script type='text/javascript'>\n";
529 echo "var jushLinks = { $driver: [ '" . addcslashes(h(ME), "\\'/") . "table=\$&', /\\b(" . implode("|", $links) . ")\\b/g ] };\n";
530 foreach (array("bac", "bra", "sqlite_quo", "mssql_bra") as $val) {
531 echo "jushLinks.$val = jushLinks.$driver;\n";
532 }
533 echo "</script>\n";
e5969d4 Shorten code
jakubvrana authored
534 }
6420c58 Schema support for PostgreSQL
jakubvrana authored
535 echo '<p><a href="' . h(ME) . 'create=">' . bold(lang('Create new table'), $_GET["create"] === "") . "</a>\n";
df0c4bb Simplify tablesPrint
jakubvrana authored
536 }
537 }
6420c58 Schema support for PostgreSQL
jakubvrana authored
538 echo (isset($_GET["sql"]) ? '<input type="hidden" name="sql" value="">'
539 : (isset($_GET["schema"]) ? '<input type="hidden" name="schema" value="">'
540 : (isset($_GET["dump"]) ? '<input type="hidden" name="dump" value="">'
541 : "")));
542 echo "</form>\n";
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored
543 }
544 }
545
546 /** Prints table list in menu
df0c4bb Simplify tablesPrint
jakubvrana authored
547 * @param array
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored
548 * @return null
549 */
df0c4bb Simplify tablesPrint
jakubvrana authored
550 function tablesPrint($tables) {
551 echo "<p id='tables'>\n";
3f5b683 Reintegrate sqlite branch
jakubvrana authored
552 foreach ($tables as $table => $type) {
94a2be5 Highlight current links
jakubvrana authored
553 echo '<a href="' . h(ME) . 'select=' . urlencode($table) . '">' . bold(lang('select'), $_GET["select"] == $table) . '</a> ';
554 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
555 }
556 }
c64c4fd Adminer class
jakubvrana authored
557
2c445a8 Extensibility basics
jakubvrana authored
558 }
464d84a Define functions unconditionally
jakubvrana authored
559
560 $adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer);
3f5b683 Reintegrate sqlite branch
jakubvrana authored
561 if (!isset($adminer->operators)) {
562 $adminer->operators = $operators;
563 }
Something went wrong with that request. Please try again.