Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 586 lines (546 sloc) 20.909 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() {
49565e0 @vrana Rename variables to avoid conflict with Adminer 2 sessions and enabled r...
authored
17 return array(SERVER, $_GET["username"], get_session("pwds"));
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() {
4ba2d85 @vrana Allow permanent login without customization
authored
24 return password_file();
95b4ea4 Permanent login
jakubvrana authored
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() {
b0d637b @vrana Avoid fatal errors
authored
39 global $drivers;
2faa08c Customize login and login form
jakubvrana authored
40 ?>
0205440 HTML whitespace
jakubvrana authored
41 <table cellspacing="0">
4b9d451 @vrana SQLite version supports two systems
authored
42 <tr><th><?php echo lang('System'); ?><td><?php echo html_select("driver", $drivers, DRIVER); ?>
3f5b683 Reintegrate sqlite branch
jakubvrana authored
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";
4ba2d85 @vrana Allow permanent login without customization
authored
52 echo checkbox("permanent", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n";
2faa08c Customize login and login form
jakubvrana authored
53 }
c64c4fd Adminer class
jakubvrana authored
54
55 /** Authorize the user
56 * @param string
57 * @param string
58 * @return bool
59 */
60 function login($login, $password) {
61 return true;
97b8c7b Display images in Editor
jakubvrana authored
62 }
c64c4fd Adminer class
jakubvrana authored
63
64 /** Table caption used in navigation and headings
65 * @param array result of SHOW TABLE STATUS
66 * @return string
67 */
68 function tableName($tableStatus) {
689699a Shortcut for htmlspecialchars
jakubvrana authored
69 return h($tableStatus["Name"]);
c64c4fd Adminer class
jakubvrana authored
70 }
71
72 /** Field caption used in select and edit
73 * @param array single field returned from fields()
6c97b80 Display only first five columns in Editor example
jakubvrana authored
74 * @param int order of column in select
c64c4fd Adminer class
jakubvrana authored
75 * @return string
76 */
6c97b80 Display only first five columns in Editor example
jakubvrana authored
77 function fieldName($field, $order = 0) {
689699a Shortcut for htmlspecialchars
jakubvrana authored
78 return '<span title="' . h($field["full_type"]) . '">' . h($field["field"]) . '</span>';
c64c4fd Adminer class
jakubvrana authored
79 }
80
f2ed237 Display table links above table structure
jakubvrana authored
81 /** Print links after select heading
c64c4fd Adminer class
jakubvrana authored
82 * @param array result of SHOW TABLE STATUS
294b10b Highlight current link
jakubvrana authored
83 * @param string new item options, NULL for no new item
f2ed237 Display table links above table structure
jakubvrana authored
84 * @return null
c64c4fd Adminer class
jakubvrana authored
85 */
f2ed237 Display table links above table structure
jakubvrana authored
86 function selectLinks($tableStatus, $set = "") {
294b10b Highlight current link
jakubvrana authored
87 echo '<p class="tabs">';
2d8a2de Change table operations descriptions
jakubvrana authored
88 $links = array("select" => lang('Select data'), "table" => lang('Show structure'));
da6f1f8 @vrana Driver specific view detection
authored
89 if (is_view($tableStatus)) {
294b10b Highlight current link
jakubvrana authored
90 $links["view"] = lang('Alter view');
3f5b683 Reintegrate sqlite branch
jakubvrana authored
91 } else {
92 $links["create"] = lang('Alter table');
f2ed237 Display table links above table structure
jakubvrana authored
93 }
94 if (isset($set)) {
294b10b Highlight current link
jakubvrana authored
95 $links["edit"] = lang('New item');
96 }
97 foreach ($links as $key => $val) {
94a2be5 Highlight current links
jakubvrana authored
98 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
99 }
100 echo "\n";
c64c4fd Adminer class
jakubvrana authored
101 }
102
103 /** Find backward keys for table
104 * @param string
09e93de Move backward keys to Editor
jakubvrana authored
105 * @param string
106 * @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
107 */
09e93de Move backward keys to Editor
jakubvrana authored
108 function backwardKeys($table, $tableName) {
c64c4fd Adminer class
jakubvrana authored
109 return array();
110 }
111
09e93de Move backward keys to Editor
jakubvrana authored
112 /** Print backward keys for row
113 * @param array result of $this->backwardKeys()
114 * @param array
115 * @return null
116 */
117 function backwardKeysPrint($backwardKeys, $row) {
118 }
119
c64c4fd Adminer class
jakubvrana authored
120 /** Query printed in select before execution
121 * @param string query to be executed
122 * @return string
123 */
124 function selectQuery($query) {
e672694 @vrana Rename $driver to $jush
authored
125 global $jush;
6457cb6 @vrana Title for last page link
authored
126 return "<p><a href='" . h(remove_from_uri("page")) . "&amp;page=last' title='" . lang('Page') . ": " . lang('last') . "'>&gt;&gt;</a> <code class='jush-$jush'>" . h(str_replace("\n", " ", $query)) . "</code> <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>\n";
c64c4fd Adminer class
jakubvrana authored
127 }
128
129 /** Description of a row in a table
130 * @param string
131 * @return string SQL expression, empty string for no description
132 */
133 function rowDescription($table) {
134 return "";
135 }
136
137 /** Get descriptions of selected data
138 * @param array all data to print
139 * @param array
140 * @return array
141 */
142 function rowDescriptions($rows, $foreignKeys) {
143 return $rows;
144 }
145
146 /** Value printed in select table
a0def47 Date localization
jakubvrana authored
147 * @param string HTML-escaped value to print
c64c4fd Adminer class
jakubvrana authored
148 * @param string link to foreign key
149 * @param array single field returned from fields()
150 * @return string
151 */
152 function selectVal($val, $link, $field) {
5a73c01 @vrana Treat binary type as hex
authored
153 $return = ($val != "<i>NULL</i>" && ereg("^char|binary", $field["type"]) ? "<code>$val</code>" : $val);
154 if (ereg('blob|bytea|raw|file', $field["type"]) && !is_utf8($val)) {
7197ab1 @vrana Report correct length of blob (bug #3070569)
authored
155 $return = lang('%d byte(s)', strlen(html_entity_decode($val, ENT_QUOTES)));
4921235 Hide edit functions in Editor
jakubvrana authored
156 }
12c042c Function htmlspecialchars now uses ENT_QUOTES
jakubvrana authored
157 return ($link ? "<a href='$link'>$return</a>" : $return);
c64c4fd Adminer class
jakubvrana authored
158 }
159
a0def47 Date localization
jakubvrana authored
160 /** Value conversion used in select and edit
161 * @param string
162 * @param array single field returned from fields()
2011428 Use LIKE operator in Editor
jakubvrana authored
163 * @return string
a0def47 Date localization
jakubvrana authored
164 */
165 function editVal($val, $field) {
5a73c01 @vrana Treat binary type as hex
authored
166 return (ereg("binary", $field["type"]) ? reset(unpack("H*", $val)) : $val);
a0def47 Date localization
jakubvrana authored
167 }
168
d24ad78 Select boxes customization
jakubvrana authored
169 /** Print columns box in select
170 * @param array result of selectColumnsProcess()
171 * @param array selectable columns
172 * @return null
173 */
174 function selectColumnsPrint($select, $columns) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
175 global $functions, $grouping;
dc667ea Hide select export and import
jakubvrana authored
176 print_fieldset("select", lang('Select'), $select);
d24ad78 Select boxes customization
jakubvrana authored
177 $i = 0;
3f5b683 Reintegrate sqlite branch
jakubvrana authored
178 $fun_group = array(lang('Functions') => $functions, lang('Aggregation') => $grouping);
d24ad78 Select boxes customization
jakubvrana authored
179 foreach ($select as $key => $val) {
180 $val = $_GET["columns"][$key];
0698409 Utilize html_select
jakubvrana authored
181 echo "<div>" . html_select("columns[$i][fun]", array(-1 => "") + $fun_group, $val["fun"]);
3f5b683 Reintegrate sqlite branch
jakubvrana authored
182 echo "(<select name='columns[$i][col]'><option>" . optionlist($columns, $val["col"], true) . "</select>)</div>\n";
d24ad78 Select boxes customization
jakubvrana authored
183 $i++;
184 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored
185 echo "<div>" . html_select("columns[$i][fun]", array(-1 => "") + $fun_group, "", "this.nextSibling.nextSibling.onchange();");
186 echo "(<select name='columns[$i][col]' onchange='selectAddRow(this);'><option>" . optionlist($columns, null, true) . "</select>)</div>\n";
d24ad78 Select boxes customization
jakubvrana authored
187 echo "</div></fieldset>\n";
188 }
189
190 /** Print search box in select
191 * @param array result of selectSearchProcess()
192 * @param array selectable columns
193 * @param array
194 * @return null
195 */
196 function selectSearchPrint($where, $columns, $indexes) {
dc667ea Hide select export and import
jakubvrana authored
197 print_fieldset("search", lang('Search'), $where);
d24ad78 Select boxes customization
jakubvrana authored
198 foreach ($indexes as $i => $index) {
199 if ($index["type"] == "FULLTEXT") {
689699a Shortcut for htmlspecialchars
jakubvrana authored
200 echo "(<i>" . implode("</i>, <i>", array_map('h', $index["columns"])) . "</i>) AGAINST";
201 echo " <input name='fulltext[$i]' value='" . h($_GET["fulltext"][$i]) . "'>";
6b30cfa Separate checkbox
jakubvrana authored
202 echo checkbox("boolean[$i]", 1, isset($_GET["boolean"][$i]), "BOOL");
d24ad78 Select boxes customization
jakubvrana authored
203 echo "<br>\n";
204 }
205 }
206 $i = 0;
207 foreach ((array) $_GET["where"] as $val) {
7352c28 Replace strlen() by != ""
jakubvrana authored
208 if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
209 echo "<div><select name='where[$i][col]'><option value=''>(" . lang('anywhere') . ")" . optionlist($columns, $val["col"], true) . "</select>";
0698409 Utilize html_select
jakubvrana authored
210 echo html_select("where[$i][op]", $this->operators, $val["op"]);
689699a Shortcut for htmlspecialchars
jakubvrana authored
211 echo "<input name='where[$i][val]' value='" . h($val["val"]) . "'></div>\n";
d24ad78 Select boxes customization
jakubvrana authored
212 $i++;
213 }
214 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored
215 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
216 echo html_select("where[$i][op]", $this->operators);
d24ad78 Select boxes customization
jakubvrana authored
217 echo "<input name='where[$i][val]'></div>\n";
218 echo "</div></fieldset>\n";
219 }
220
221 /** Print order box in select
222 * @param array result of selectOrderProcess()
223 * @param array selectable columns
224 * @param array
225 * @return null
226 */
227 function selectOrderPrint($order, $columns, $indexes) {
dc667ea Hide select export and import
jakubvrana authored
228 print_fieldset("sort", lang('Sort'), $order);
d24ad78 Select boxes customization
jakubvrana authored
229 $i = 0;
230 foreach ((array) $_GET["order"] as $key => $val) {
231 if (isset($columns[$val])) {
232 echo "<div><select name='order[$i]'><option>" . optionlist($columns, $val, true) . "</select>";
6b30cfa Separate checkbox
jakubvrana authored
233 echo checkbox("desc[$i]", 1, isset($_GET["desc"][$key]), lang('descending')) . "</div>\n";
d24ad78 Select boxes customization
jakubvrana authored
234 $i++;
235 }
236 }
3c5c0f0 Use camelCase in JavaScript
jakubvrana authored
237 echo "<div><select name='order[$i]' onchange='selectAddRow(this);'><option>" . optionlist($columns, null, true) . "</select>";
6b30cfa Separate checkbox
jakubvrana authored
238 echo checkbox("desc[$i]", 1, 0, lang('descending')) . "</div>\n";
d24ad78 Select boxes customization
jakubvrana authored
239 echo "</div></fieldset>\n";
240 }
241
242 /** Print limit box in select
243 * @param string result of selectLimitProcess()
244 * @return null
245 */
246 function selectLimitPrint($limit) {
247 echo "<fieldset><legend>" . lang('Limit') . "</legend><div>"; // <div> for easy styling
689699a Shortcut for htmlspecialchars
jakubvrana authored
248 echo "<input name='limit' size='3' value='" . h($limit) . "'>";
d24ad78 Select boxes customization
jakubvrana authored
249 echo "</div></fieldset>\n";
250 }
251
252 /** Print text length box in select
253 * @param string result of selectLengthProcess()
254 * @return null
255 */
256 function selectLengthPrint($text_length) {
257 if (isset($text_length)) {
258 echo "<fieldset><legend>" . lang('Text length') . "</legend><div>";
689699a Shortcut for htmlspecialchars
jakubvrana authored
259 echo '<input name="text_length" size="3" value="' . h($text_length) . '">';
d24ad78 Select boxes customization
jakubvrana authored
260 echo "</div></fieldset>\n";
261 }
262 }
263
264 /** Print action box in select
265 * @return null
266 */
267 function selectActionPrint() {
268 echo "<fieldset><legend>" . lang('Action') . "</legend><div>";
269 echo "<input type='submit' value='" . lang('Select') . "'>";
270 echo "</div></fieldset>\n";
271 }
272
1a6a73a Rename selectExtra to selectEmail
jakubvrana authored
273 /** Print extra text in the end of a select form
274 * @param array fields holding e-mails
1e55d47 User interface for e-mail {$name}
jakubvrana authored
275 * @param array selectable columns
1a6a73a Rename selectExtra to selectEmail
jakubvrana authored
276 * @return null
277 */
1e55d47 User interface for e-mail {$name}
jakubvrana authored
278 function selectEmailPrint($emailFields, $columns) {
1a6a73a Rename selectExtra to selectEmail
jakubvrana authored
279 }
280
d24ad78 Select boxes customization
jakubvrana authored
281 /** Process columns box in select
282 * @param array selectable columns
1e55d47 User interface for e-mail {$name}
jakubvrana authored
283 * @param array
d24ad78 Select boxes customization
jakubvrana authored
284 * @return array (array(select_expressions), array(group_expressions))
285 */
286 function selectColumnsProcess($columns, $indexes) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
287 global $functions, $grouping;
d24ad78 Select boxes customization
jakubvrana authored
288 $select = array(); // select expressions, empty for *
289 $group = array(); // expressions without aggregation - will be used for GROUP BY if an aggregation function is used
290 foreach ((array) $_GET["columns"] as $key => $val) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
291 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
292 $select[$key] = apply_sql_function($val["fun"], (isset($columns[$val["col"]]) ? idf_escape($val["col"]) : "*"));
3f5b683 Reintegrate sqlite branch
jakubvrana authored
293 if (!in_array($val["fun"], $grouping)) {
d24ad78 Select boxes customization
jakubvrana authored
294 $group[] = $select[$key];
295 }
296 }
297 }
298 return array($select, $group);
299 }
300
301 /** Process search box in select
302 * @param array
303 * @param array
304 * @return array expressions to join by AND
305 */
07e1ae1 FOUND_ROWS only with GROUP BY
jakubvrana authored
306 function selectSearchProcess($fields, $indexes) {
7e644b4 @vrana Save bytes ($connection->quote shortcut)
authored
307 global $jush;
d24ad78 Select boxes customization
jakubvrana authored
308 $return = array();
309 foreach ($indexes as $i => $index) {
7352c28 Replace strlen() by != ""
jakubvrana authored
310 if ($index["type"] == "FULLTEXT" && $_GET["fulltext"][$i] != "") {
7e644b4 @vrana Save bytes ($connection->quote shortcut)
authored
311 $return[] = "MATCH (" . implode(", ", array_map('idf_escape', $index["columns"])) . ") AGAINST (" . q($_GET["fulltext"][$i]) . (isset($_GET["boolean"][$i]) ? " IN BOOLEAN MODE" : "") . ")";
d24ad78 Select boxes customization
jakubvrana authored
312 }
313 }
314 foreach ((array) $_GET["where"] as $val) {
7352c28 Replace strlen() by != ""
jakubvrana authored
315 if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
316 $cond = " $val[op]";
317 if (ereg('IN$', $val["op"])) {
318 $in = process_length($val["val"]);
319 $cond .= " (" . ($in != "" ? $in : "NULL") . ")";
320 } elseif ($val["op"] == "LIKE %%") {
321 $cond = " LIKE " . $this->processInput($fields[$val["col"]], "%$val[val]%");
322 } elseif (!ereg('NULL$', $val["op"])) {
323 $cond .= " " . $this->processInput($fields[$val["col"]], $val["val"]);
324 }
7352c28 Replace strlen() by != ""
jakubvrana authored
325 if ($val["col"] != "") {
98b88eb Remove fulltext search without index
jakubvrana authored
326 $return[] = idf_escape($val["col"]) . $cond;
d24ad78 Select boxes customization
jakubvrana authored
327 } else {
98b88eb Remove fulltext search without index
jakubvrana authored
328 // find anywhere
329 $cols = array();
330 foreach ($fields as $name => $field) {
331 if (is_numeric($val["val"]) || !ereg('int|float|double|decimal', $field["type"])) {
d79b160 Illegal mix of collations
jakubvrana authored
332 $name = idf_escape($name);
782921b @vrana Finish SQLite
authored
333 $cols[] = ($jush == "sql" && ereg('char|text|enum|set', $field["type"]) && !ereg('^utf8', $field["collation"]) ? "CONVERT($name USING utf8)" : $name);
d24ad78 Select boxes customization
jakubvrana authored
334 }
335 }
d79b160 Illegal mix of collations
jakubvrana authored
336 $return[] = ($cols ? "(" . implode("$cond OR ", $cols) . "$cond)" : "0");
d24ad78 Select boxes customization
jakubvrana authored
337 }
338 }
339 }
340 return $return;
341 }
342
343 /** Process order box in select
344 * @param array
345 * @param array
346 * @return array expressions to join by comma
347 */
07e1ae1 FOUND_ROWS only with GROUP BY
jakubvrana authored
348 function selectOrderProcess($fields, $indexes) {
d24ad78 Select boxes customization
jakubvrana authored
349 $return = array();
350 foreach ((array) $_GET["order"] as $key => $val) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
351 if (isset($fields[$val]) || preg_match('~^((COUNT\\(DISTINCT |[A-Z0-9_]+\\()(`(?:[^`]|``)+`|"(?:[^"]|"")+")\\)|COUNT\\(\\*\\))$~', $val)) { //! MS SQL uses []
352 $return[] = (isset($fields[$val]) ? idf_escape($val) : $val) . (isset($_GET["desc"][$key]) ? " DESC" : "");
d24ad78 Select boxes customization
jakubvrana authored
353 }
354 }
355 return $return;
356 }
357
358 /** Process limit box in select
359 * @return string expression to use in LIMIT, will be escaped
360 */
361 function selectLimitProcess() {
362 return (isset($_GET["limit"]) ? $_GET["limit"] : "30");
363 }
364
365 /** Process length box in select
366 * @return string number of characters to shorten texts, will be escaped
367 */
368 function selectLengthProcess() {
369 return (isset($_GET["text_length"]) ? $_GET["text_length"] : "100");
370 }
371
c64c4fd Adminer class
jakubvrana authored
372 /** Process extras in select form
373 * @param array AND conditions
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored
374 * @param array
c64c4fd Adminer class
jakubvrana authored
375 * @return bool true if processed, false to process other parts of form
376 */
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored
377 function selectEmailProcess($where, $foreignKeys) {
c64c4fd Adminer class
jakubvrana authored
378 return false;
379 }
380
381 /** Query printed after execution in the message
382 * @param string executed query
383 * @return string
384 */
385 function messageQuery($query) {
e672694 @vrana Rename $driver to $jush
authored
386 global $jush;
be49e08 Improve session restarting
jakubvrana authored
387 restart_session();
c64c4fd Adminer class
jakubvrana authored
388 $id = "sql-" . count($_SESSION["messages"]);
49565e0 @vrana Rename variables to avoid conflict with Adminer 2 sessions and enabled r...
authored
389 $history = &get_session("queries");
2bd9b39 @vrana Save database drop to global history
authored
390 $history[$_GET["db"]][] = (strlen($query) > 1e6 // not DB - reset in drop database
391 ? ereg_replace('[\x80-\xFF]+$', '', substr($query, 0, 1e6)) . "\n..." // [\x80-\xFF] - valid UTF-8, \n - can end by one-line comment
392 : $query
393 ); //! respect $_GET["ns"]
394 return " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><div id='$id' class='hidden'><pre class='jush-$jush'>" . shorten_utf8($query, 1000) . '</pre><p><a href="' . h(str_replace("db=" . urlencode(DB), "db=" . urlencode($_GET["db"]), ME) . 'sql=&history=' . (count($history[$_GET["db"]]) - 1)) . '">' . lang('Edit') . '</a></div>';
c64c4fd Adminer class
jakubvrana authored
395 }
396
397 /** Functions displayed in edit form
398 * @param array single field from fields()
399 * @return array
400 */
401 function editFunctions($field) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
402 global $edit_functions;
02f7521 Fix input onchange
jakubvrana authored
403 $return = ($field["null"] ? "NULL/" : "");
3f5b683 Reintegrate sqlite branch
jakubvrana authored
404 foreach ($edit_functions as $key => $functions) {
405 if (!$key || (!isset($_GET["call"]) && (isset($_GET["select"]) || where($_GET)))) { // relative functions
406 foreach ($functions as $pattern => $val) {
407 if (!$pattern || ereg($pattern, $field["type"])) {
408 $return .= "/$val";
409 }
410 }
309f681 Relative function concat
jakubvrana authored
411 }
4921235 Hide edit functions in Editor
jakubvrana authored
412 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored
413 return explode("/", $return);
4921235 Hide edit functions in Editor
jakubvrana authored
414 }
c64c4fd Adminer class
jakubvrana authored
415
416 /** Get options to display edit field
417 * @param string table name
418 * @param array single field from fields()
e1abcda Treat tinyint(1) as boolean
jakubvrana authored
419 * @param string attributes to use inside the tag
420 * @param string
421 * @return string custom input field or empty string for default
c64c4fd Adminer class
jakubvrana authored
422 */
e1abcda Treat tinyint(1) as boolean
jakubvrana authored
423 function editInput($table, $field, $attrs, $value) {
ec0282b Enum editing
jakubvrana authored
424 if ($field["type"] == "enum") {
687b3fd @vrana Replace <strong> by <b> and <em> by <i>
authored
425 return ($field["null"] ? "<label><input type='radio'$attrs value=''" . (isset($value) || isset($_GET["select"]) ? "" : " checked") . "><i>NULL</i></label> " : "")
426 . "<label><input type='radio'$attrs value='0'" . ($value === 0 ? " checked" : "") . "><i>" . lang('empty') . "</i></label>"
ec0282b Enum editing
jakubvrana authored
427 ;
428 }
429 return "";
4921235 Hide edit functions in Editor
jakubvrana authored
430 }
c64c4fd Adminer class
jakubvrana authored
431
432 /** Process sent input
433 * @param array single field from fields()
a0def47 Date localization
jakubvrana authored
434 * @param string
435 * @param string
c64c4fd Adminer class
jakubvrana authored
436 * @return string expression to use in a query
437 */
a0def47 Date localization
jakubvrana authored
438 function processInput($field, $value, $function = "") {
439 $name = $field["field"];
7e644b4 @vrana Save bytes ($connection->quote shortcut)
authored
440 $return = q($value);
3f5b683 Reintegrate sqlite branch
jakubvrana authored
441 if (ereg('^(now|getdate|uuid)$', $function)) {
c64c4fd Adminer class
jakubvrana authored
442 $return = "$function()";
e4df0c6 @vrana MS SQL functions
authored
443 } elseif (ereg('^current_(date|timestamp)$', $function)) {
444 $return = $function;
3f5b683 Reintegrate sqlite branch
jakubvrana authored
445 } elseif (ereg('^([+-]|\\|\\|)$', $function)) {
c64c4fd Adminer class
jakubvrana authored
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)";
5a73c01 @vrana Treat binary type as hex
authored
451 } elseif (ereg('^(md5|sha1|password|encrypt|hex)$', $function)) {
c64c4fd Adminer class
jakubvrana authored
452 $return = "$function($return)";
453 }
5a73c01 @vrana Treat binary type as hex
authored
454 if (ereg("binary", $field["type"])) {
455 $return = "unhex($return)";
456 }
c64c4fd Adminer class
jakubvrana authored
457 return $return;
a78c941 Empty value in Editor as NULL
jakubvrana authored
458 }
c64c4fd Adminer class
jakubvrana authored
459
e40612a Use radio in export
jakubvrana authored
460 /** Returns export output options
461 * @param bool generate select (otherwise radio)
3f5b683 Reintegrate sqlite branch
jakubvrana authored
462 * @param string
e40612a Use radio in export
jakubvrana authored
463 * @return string
464 */
3f5b683 Reintegrate sqlite branch
jakubvrana authored
465 function dumpOutput($select, $value = "") {
e40612a Use radio in export
jakubvrana authored
466 $return = array('text' => lang('open'), 'file' => lang('save'));
467 if (function_exists('gzencode')) {
468 $return['gz'] = 'gzip';
469 }
470 if (function_exists('bzcompress')) {
471 $return['bz2'] = 'bzip2';
472 }
473 // ZipArchive requires temporary file, ZIP can be created by gzcompress - see PEAR File_Archive
3f5b683 Reintegrate sqlite branch
jakubvrana authored
474 return html_select("output", $return, $value, $select);
e40612a Use radio in export
jakubvrana authored
475 }
476
477 /** Returns export format options
478 * @param bool generate select (otherwise radio)
3f5b683 Reintegrate sqlite branch
jakubvrana authored
479 * @param string
e40612a Use radio in export
jakubvrana authored
480 * @return string
481 */
3f5b683 Reintegrate sqlite branch
jakubvrana authored
482 function dumpFormat($select, $value = "") {
483 return html_select("format", array('sql' => 'SQL', 'csv' => 'CSV,', 'csv;' => 'CSV;'), $value, $select);
e40612a Use radio in export
jakubvrana authored
484 }
485
c64c4fd Adminer class
jakubvrana authored
486 /** Prints navigation after Adminer title
487 * @param string can be "auth" if there is no database connection or "db" if there is no database selected
488 * @return null
489 */
490 function navigation($missing) {
e672694 @vrana Rename $driver to $jush
authored
491 global $VERSION, $connection, $token, $jush, $drivers;
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored
492 ?>
493 <h1>
494 <a href="http://www.adminer.org/" id="h1"><?php echo $this->name(); ?></a>
495 <span class="version"><?php echo $VERSION; ?></span>
496 <a href="http://www.adminer.org/#download" id="version"><?php echo (version_compare($VERSION, $_COOKIE["adminer_version"]) < 0 ? h($_COOKIE["adminer_version"]) : ""); ?></a>
497 </h1>
498 <?php
605b093 @vrana List authentications
authored
499 if ($missing == "auth") {
500 $first = true;
49565e0 @vrana Rename variables to avoid conflict with Adminer 2 sessions and enabled r...
authored
501 foreach ((array) $_SESSION["pwds"] as $driver => $servers) {
605b093 @vrana List authentications
authored
502 foreach ($servers as $server => $usernames) {
503 foreach ($usernames as $username => $password) {
504 if (isset($password)) {
505 if ($first) {
506 echo "<p>\n";
507 $first = false;
508 }
e672694 @vrana Rename $driver to $jush
authored
509 echo "<a href='" . h(auth_url($driver, $server, $username)) . "'>($drivers[$driver]) " . h($username . ($server != "" ? "@$server" : "")) . "</a><br>\n";
605b093 @vrana List authentications
authored
510 }
511 }
512 }
513 }
514 } else {
c64c4fd Adminer class
jakubvrana authored
515 $databases = get_databases();
516 ?>
b95f24e Editor: User friendly data editor
jakubvrana authored
517 <form action="" method="post">
fde1171 Add CSS classes (thanks to cvicebni ubor)
jakubvrana authored
518 <p class="logout">
94a2be5 Highlight current links
jakubvrana authored
519 <a href="<?php echo h(ME); ?>sql="><?php echo bold(lang('SQL command'), isset($_GET["sql"])); ?></a>
a7cdc85 @vrana Dump support is optional
authored
520 <?php if (support("dump")) { ?>
7ee5992 Revert 1511 (always dump all tables)
jakubvrana authored
521 <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>
a7cdc85 @vrana Dump support is optional
authored
522 <?php } ?>
3f5b683 Reintegrate sqlite branch
jakubvrana authored
523 <input type="hidden" name="token" value="<?php echo $token; ?>">
ace55ed HTML instead of XHTML
jakubvrana authored
524 <input type="submit" name="logout" value="<?php echo lang('Logout'); ?>">
d2ba593 Browsers interpret <form><p></form> as <form><p></form></p>
jakubvrana authored
525 </p>
b95f24e Editor: User friendly data editor
jakubvrana authored
526 </form>
527 <form action="">
25cef1f Disable session.use_trans_sid to preserve export result
jakubvrana authored
528 <p>
3f5b683 Reintegrate sqlite branch
jakubvrana authored
529 <?php hidden_fields_get(); ?>
0698409 Utilize html_select
jakubvrana authored
530 <?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
531 <input type="submit" value="<?php echo lang('Use'); ?>"<?php echo ($databases ? " class='hidden'" : ""); ?>>
b95f24e Editor: User friendly data editor
jakubvrana authored
532 <?php
7352c28 Replace strlen() by != ""
jakubvrana authored
533 if ($missing != "db" && DB != "" && $connection->select_db(DB)) {
6420c58 Schema support for PostgreSQL
jakubvrana authored
534 if (support("scheme")) {
535 echo "<br>" . html_select("ns", array("" => "(" . lang('schema') . ")") + schemas(), $_GET["ns"], "this.form.submit();");
536 if ($_GET["ns"] != "") {
537 set_schema($_GET["ns"]);
8e81039 Link table names in SQL queries
jakubvrana authored
538 }
6420c58 Schema support for PostgreSQL
jakubvrana authored
539 }
540 if ($_GET["ns"] !== "") {
541 $tables = tables_list();
542 if (!$tables) {
543 echo "<p class='message'>" . lang('No tables.') . "\n";
544 } else {
545 $this->tablesPrint($tables);
546 $links = array();
547 foreach ($tables as $table => $type) {
548 $links[] = preg_quote($table, '/');
549 }
550 echo "<script type='text/javascript'>\n";
e672694 @vrana Rename $driver to $jush
authored
551 echo "var jushLinks = { $jush: [ '" . addcslashes(h(ME), "\\'/") . "table=\$&', /\\b(" . implode("|", $links) . ")\\b/g ] };\n";
6420c58 Schema support for PostgreSQL
jakubvrana authored
552 foreach (array("bac", "bra", "sqlite_quo", "mssql_bra") as $val) {
e672694 @vrana Rename $driver to $jush
authored
553 echo "jushLinks.$val = jushLinks.$jush;\n";
6420c58 Schema support for PostgreSQL
jakubvrana authored
554 }
555 echo "</script>\n";
e5969d4 Shorten code
jakubvrana authored
556 }
6420c58 Schema support for PostgreSQL
jakubvrana authored
557 echo '<p><a href="' . h(ME) . 'create=">' . bold(lang('Create new table'), $_GET["create"] === "") . "</a>\n";
df0c4bb Simplify tablesPrint
jakubvrana authored
558 }
559 }
6420c58 Schema support for PostgreSQL
jakubvrana authored
560 echo (isset($_GET["sql"]) ? '<input type="hidden" name="sql" value="">'
561 : (isset($_GET["schema"]) ? '<input type="hidden" name="schema" value="">'
562 : (isset($_GET["dump"]) ? '<input type="hidden" name="dump" value="">'
563 : "")));
60c7ed9 @vrana MS SQL schema support
authored
564 echo "</p></form>\n";
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored
565 }
566 }
567
568 /** Prints table list in menu
df0c4bb Simplify tablesPrint
jakubvrana authored
569 * @param array
d3227c9 Move <h1> to $adminer->navigation
jakubvrana authored
570 * @return null
571 */
df0c4bb Simplify tablesPrint
jakubvrana authored
572 function tablesPrint($tables) {
573 echo "<p id='tables'>\n";
3f5b683 Reintegrate sqlite branch
jakubvrana authored
574 foreach ($tables as $table => $type) {
94a2be5 Highlight current links
jakubvrana authored
575 echo '<a href="' . h(ME) . 'select=' . urlencode($table) . '">' . bold(lang('select'), $_GET["select"] == $table) . '</a> ';
576 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
577 }
578 }
c64c4fd Adminer class
jakubvrana authored
579
2c445a8 Extensibility basics
jakubvrana authored
580 }
464d84a Define functions unconditionally
jakubvrana authored
581
582 $adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer);
3f5b683 Reintegrate sqlite branch
jakubvrana authored
583 if (!isset($adminer->operators)) {
584 $adminer->operators = $operators;
585 }
Something went wrong with that request. Please try again.