Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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