Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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