Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 339 lines (321 sloc) 15.025 kB
667bfec Decomposition
jakubvrana authored
1 <?php
79d1902 Substitute table name to $TABLE
jakubvrana authored
2 $TABLE = $_GET["select"];
3 $table_status = table_status($TABLE);
4 $indexes = indexes($TABLE);
5 $fields = fields($TABLE);
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored
6 $foreign_keys = column_foreign_keys($TABLE);
7
64ba924 Comments
jakubvrana authored
8 $rights = array(); // privilege => 0
9 $columns = array(); // selectable columns
0115315 Init with null
jakubvrana authored
10 $text_length = null;
ffcea8b Rights
jakubvrana authored
11 foreach ($fields as $key => $field) {
c64c4fd Adminer class
jakubvrana authored
12 $name = $adminer->fieldName($field);
7352c28 Replace strlen() by != ""
jakubvrana authored
13 if (isset($field["privileges"]["select"]) && $name != "") {
1e4d11e Select from foreign keys in Editor
jakubvrana authored
14 $columns[$key] = html_entity_decode(strip_tags($name));
5abd943 Change simple preg_match to ereg
jakubvrana authored
15 if (ereg('text|blob', $field["type"])) {
d24ad78 Select boxes customization
jakubvrana authored
16 $text_length = $adminer->selectLengthProcess();
16c4ddb Single faster POST query with primary key
jakubvrana authored
17 }
ffcea8b Rights
jakubvrana authored
18 }
430034c Cottage homework
jakubvrana authored
19 $rights += $field["privileges"];
20 }
21
d24ad78 Select boxes customization
jakubvrana authored
22 list($select, $group) = $adminer->selectColumnsProcess($columns, $indexes);
07e1ae1 FOUND_ROWS only with GROUP BY
jakubvrana authored
23 $where = $adminer->selectSearchProcess($fields, $indexes);
24 $order = $adminer->selectOrderProcess($fields, $indexes);
d24ad78 Select boxes customization
jakubvrana authored
25 $limit = $adminer->selectLimitProcess();
e44fbc2 Wrap SQL query
jakubvrana authored
26 $from = ($select ? implode(", ", $select) : "*") . "\nFROM " . idf_escape($TABLE) . ($where ? "\nWHERE " . implode(" AND ", $where) : "");
27 $group_by = ($group && count($group) < count($select) ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : "");
116faf2 Mass delete
jakubvrana authored
28
29 if ($_POST && !$error) {
56948c9 $_POST[check] may be empty
jakubvrana authored
30 $where_check = "(" . implode(") OR (", array_map('where_check', (array) $_POST["check"])) . ")";
a3d2266 Order by first index in Editor by default
jakubvrana authored
31 $primary = ($indexes["PRIMARY"] ? ($select ? array_flip($indexes["PRIMARY"]["columns"]) : array()) : null); // empty array means that all primary fields are selected
d24ad78 Select boxes customization
jakubvrana authored
32 foreach ($select as $key => $val) {
33 $val = $_GET["columns"][$key];
34 if (!$val["fun"]) {
35 unset($primary[$val["col"]]);
36 }
37 }
78639a9 Function results in edit
jakubvrana authored
38 if ($_POST["export"]) {
79d1902 Substitute table name to $TABLE
jakubvrana authored
39 dump_headers($TABLE);
40 dump_table($TABLE, "");
e4f5d17 Dump column names in CSV select export
jakubvrana authored
41 if ($_POST["format"] != "sql") { // Editor doesn't send format
b79ef09 Don't dump backticks in CSV column names
jakubvrana authored
42 $row = array_keys($fields);
43 if ($select) {
44 $row = array();
45 foreach ($select as $val) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
46 $row[] = (ereg('^`.*`$', $val) ? idf_unescape($val) : $val); //! columns looking like functions
b79ef09 Don't dump backticks in CSV column names
jakubvrana authored
47 }
48 }
49 dump_csv($row);
e4f5d17 Dump column names in CSV select export
jakubvrana authored
50 }
16c4ddb Single faster POST query with primary key
jakubvrana authored
51 if (!is_array($_POST["check"]) || $primary === array()) {
79d1902 Substitute table name to $TABLE
jakubvrana authored
52 dump_data($TABLE, "INSERT", "SELECT $from" . (is_array($_POST["check"]) ? ($where ? " AND " : " WHERE ") . "($where_check)" : "") . $group_by);
16c4ddb Single faster POST query with primary key
jakubvrana authored
53 } else {
fa5c952 Use extended INSERT in select export
jakubvrana authored
54 $union = array();
f7452ad Import and export
jakubvrana authored
55 foreach ($_POST["check"] as $val) {
16c4ddb Single faster POST query with primary key
jakubvrana authored
56 // where is not unique so OR can't be used
3f5b683 Reintegrate sqlite branch
jakubvrana authored
57 $union[] = "(SELECT" . limit("$from " . ($where ? "AND " : "WHERE ") . where_check($val) . $group_by, 1) . ")";
116faf2 Mass delete
jakubvrana authored
58 }
79d1902 Substitute table name to $TABLE
jakubvrana authored
59 dump_data($TABLE, "INSERT", implode(" UNION ALL ", $union));
116faf2 Mass delete
jakubvrana authored
60 }
78639a9 Function results in edit
jakubvrana authored
61 exit;
62 }
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored
63 if (!$adminer->selectEmailProcess($where, $foreign_keys)) {
00d9b36 E-mail sending only in Editor
jakubvrana authored
64 if (!$_POST["import"]) { // edit
65 $result = true;
66 $affected = 0;
3f5b683 Reintegrate sqlite branch
jakubvrana authored
67 $query = idf_escape($TABLE);
28b2b8d Readable variable initialization
jakubvrana authored
68 $set = array();
00d9b36 E-mail sending only in Editor
jakubvrana authored
69 if (!$_POST["delete"]) {
70 foreach ($columns as $name => $val) { //! should check also for edit or insert privileges
a0def47 Date localization
jakubvrana authored
71 $val = process_input($fields[$name]);
3f5b683 Reintegrate sqlite branch
jakubvrana authored
72 if ($val !== null) {
73 if ($_POST["clone"]) {
74 $set[idf_escape($name)] = ($val !== false ? $val : idf_escape($name));
75 } elseif ($val !== false) {
76 $set[] = idf_escape($name) . " = $val";
77 }
00d9b36 E-mail sending only in Editor
jakubvrana authored
78 }
e7eb28d CSV import
jakubvrana authored
79 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored
80 $query .= ($_POST["clone"] ? " (" . implode(", ", array_keys($set)) . ")\nSELECT " . implode(", ", $set) . "\nFROM " . idf_escape($TABLE) : " SET\n" . implode(",\n", $set));
e7eb28d CSV import
jakubvrana authored
81 }
00d9b36 E-mail sending only in Editor
jakubvrana authored
82 if ($_POST["delete"] || $set) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
83 $command = "UPDATE";
84 if ($_POST["delete"]) {
85 $command = "DELETE";
86 $query = "FROM $query";
87 }
88 if ($_POST["clone"]) {
89 $command = "INSERT";
90 $query = "INTO $query";
91 }
92 if ($_POST["all"] || ($primary === array() && $_POST["check"]) || count($group) < count($select)) {
93 $result = queries($command . " $query" . ($_POST["all"] ? ($where ? "\nWHERE " . implode(" AND ", $where) : "") : "\nWHERE $where_check"));
64d616c Rename get_dbh to connection
jakubvrana authored
94 $affected = $connection->affected_rows;
00d9b36 E-mail sending only in Editor
jakubvrana authored
95 } else {
96 foreach ((array) $_POST["check"] as $val) {
97 // where is not unique so OR can't be used
3f5b683 Reintegrate sqlite branch
jakubvrana authored
98 $result = queries($command . limit1($query . "\nWHERE " . where_check($val)));
00d9b36 E-mail sending only in Editor
jakubvrana authored
99 if (!$result) {
100 break;
101 }
64d616c Rename get_dbh to connection
jakubvrana authored
102 $affected += $connection->affected_rows;
38059b6 Remove empty if
jakubvrana authored
103 }
e7eb28d CSV import
jakubvrana authored
104 }
78639a9 Function results in edit
jakubvrana authored
105 }
dbdd40a Introduce queries_redirect function
jakubvrana authored
106 queries_redirect(remove_from_uri("page"), lang('%d item(s) have been affected.', $affected), $result);
00d9b36 E-mail sending only in Editor
jakubvrana authored
107 //! display edit page in case of an error
25f01d3 Compress export and import
jakubvrana authored
108 } elseif (is_string($file = get_file("csv_file", true))) {
00d9b36 E-mail sending only in Editor
jakubvrana authored
109 $file = preg_replace("~^\xEF\xBB\xBF~", '', $file); //! character set
cb370a8 Respect max_allowed_packet in CSV import
jakubvrana authored
110 $result = true;
e895368 Use ON DUPLICATE KEY UPDATE for CSV import
jakubvrana authored
111 $cols = array_keys($fields);
8a04897 Use atomic group for CSV regexp
jakubvrana authored
112 preg_match_all('~(?>"[^"]*"|[^"\\r\\n]+)+~', $file, $matches);
e895368 Use ON DUPLICATE KEY UPDATE for CSV import
jakubvrana authored
113 $affected = count($matches[0]);
96ee5db Import CSV in transaction
jakubvrana authored
114 queries("START TRANSACTION");
3f5b683 Reintegrate sqlite branch
jakubvrana authored
115 $separator = ($_POST["separator"] == ";" ? ";" : ",");
00d9b36 E-mail sending only in Editor
jakubvrana authored
116 foreach ($matches[0] as $key => $val) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
117 preg_match_all("~((\"[^\"]*\")+|[^$separator]*)$separator~", $val . $separator, $matches2);
e895368 Use ON DUPLICATE KEY UPDATE for CSV import
jakubvrana authored
118 if (!$key && !array_diff($matches2[1], $cols)) { //! doesn't work with column names containing ",\n
00d9b36 E-mail sending only in Editor
jakubvrana authored
119 // first row corresponds to column names - use it for table structure
e895368 Use ON DUPLICATE KEY UPDATE for CSV import
jakubvrana authored
120 $cols = $matches2[1];
121 $affected--;
00d9b36 E-mail sending only in Editor
jakubvrana authored
122 } else {
e895368 Use ON DUPLICATE KEY UPDATE for CSV import
jakubvrana authored
123 $set = "";
124 foreach ($matches2[1] as $i => $col) {
7352c28 Replace strlen() by != ""
jakubvrana authored
125 $set .= ", " . idf_escape($cols[$i]) . " = " . ($col == "" && $fields[$cols[$i]]["null"] ? "NULL" : $connection->quote(str_replace('""', '"', preg_replace('~^"|"$~', '', $col))));
00d9b36 E-mail sending only in Editor
jakubvrana authored
126 }
2c76578 Reduce size
jakubvrana authored
127 $set = substr($set, 1);
128 $result = queries("INSERT INTO " . idf_escape($_GET["select"]) . " SET$set ON DUPLICATE KEY UPDATE$set");
e895368 Use ON DUPLICATE KEY UPDATE for CSV import
jakubvrana authored
129 if (!$result) {
130 break;
cb370a8 Respect max_allowed_packet in CSV import
jakubvrana authored
131 }
132 }
133 }
6ba224b Rollback unsuccessful CSV import
jakubvrana authored
134 if ($result) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
135 queries("COMMIT");
6ba224b Rollback unsuccessful CSV import
jakubvrana authored
136 }
dbdd40a Introduce queries_redirect function
jakubvrana authored
137 queries_redirect(remove_from_uri("page"), lang('%d row(s) have been imported.', $affected), $result);
6ba224b Rollback unsuccessful CSV import
jakubvrana authored
138 queries("ROLLBACK");
00d9b36 E-mail sending only in Editor
jakubvrana authored
139 } else {
140 $error = upload_error($file);
d83b654 Detect import errors
jakubvrana authored
141 }
ec23248 Exportable select
jakubvrana authored
142 }
116faf2 Mass delete
jakubvrana authored
143 }
c16c57b E-mail sending
jakubvrana authored
144
b9ffd64 Remove common prefix in backward key
jakubvrana authored
145 $table_name = $adminer->tableName($table_status);
146 page_header(lang('Select') . ": $table_name", $error);
116faf2 Mass delete
jakubvrana authored
147
f2ed237 Display table links above table structure
jakubvrana authored
148 $set = null;
430034c Cottage homework
jakubvrana authored
149 if (isset($rights["insert"])) {
98507da Function verify_version doesn't use version parameter
jakubvrana authored
150 $set = "";
151 foreach ((array) $_GET["where"] as $val) {
152 if (count($foreign_keys[$val["col"]]) == 1 && ($val["op"] == "="
a1609c7 Align numbers to right in select
jakubvrana authored
153 || (!$val["op"] && !ereg('[_%]', $val["val"])) // LIKE in Editor
98507da Function verify_version doesn't use version parameter
jakubvrana authored
154 )) {
155 $set .= "&set" . urlencode("[" . bracket_escape($val["col"]) . "]") . "=" . urlencode($val["val"]);
156 }
157 }
667bfec Decomposition
jakubvrana authored
158 }
f2ed237 Display table links above table structure
jakubvrana authored
159 $adminer->selectLinks($table_status, $set);
667bfec Decomposition
jakubvrana authored
160
ffcea8b Rights
jakubvrana authored
161 if (!$columns) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
162 echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "." : ": " . error()) . "\n";
ffcea8b Rights
jakubvrana authored
163 } else {
5ee29cb Select columns, aggregation
jakubvrana authored
164 echo "<form action='' id='form'>\n";
d24ad78 Select boxes customization
jakubvrana authored
165 echo "<div style='display: none;'>";
3f5b683 Reintegrate sqlite branch
jakubvrana authored
166 hidden_fields_get();
7352c28 Replace strlen() by != ""
jakubvrana authored
167 echo (DB != "" ? '<input type="hidden" name="db" value="' . h(DB) . '">' : ""); // not used in Editor
79d1902 Substitute table name to $TABLE
jakubvrana authored
168 echo '<input type="hidden" name="select" value="' . h($TABLE) . '">';
d24ad78 Select boxes customization
jakubvrana authored
169 echo "</div>\n";
170 $adminer->selectColumnsPrint($select, $columns);
171 $adminer->selectSearchPrint($where, $columns, $indexes);
172 $adminer->selectOrderPrint($order, $columns, $indexes);
173 $adminer->selectLimitPrint($limit);
174 $adminer->selectLengthPrint($text_length);
175 $adminer->selectActionPrint($text_length);
ffcea8b Rights
jakubvrana authored
176 echo "</form>\n";
177
bd25295 Don't redirect from last page
jakubvrana authored
178 $page = $_GET["page"];
179 if ($page == "last") {
180 session_write_close();
181 $found_rows = $connection->result("SELECT COUNT(*) FROM " . idf_escape($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : ""));
182 $page = floor(($found_rows - 1) / $limit);
183 }
184
185 $query = "SELECT" . limit((intval($limit) && $group && count($group) < count($select) && $driver == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . $from . $group_by, ($limit != "" ? intval($limit) : null), ($page ? $limit * $page : 0));
c64c4fd Adminer class
jakubvrana authored
186 echo $adminer->selectQuery($query);
8b74511 Print SQL query (fixes #2082448)
jakubvrana authored
187
64d616c Rename get_dbh to connection
jakubvrana authored
188 $result = $connection->query($query);
21ea4ae Check errors
jakubvrana authored
189 if (!$result) {
c1130ed Simplify SQL syntax errors everywhere
jakubvrana authored
190 echo "<p class='error'>" . error() . "\n";
ffcea8b Rights
jakubvrana authored
191 } else {
f2365d0 Typo
jakubvrana authored
192 $email_fields = array();
e7eb28d CSV import
jakubvrana authored
193 echo "<form action='' method='post' enctype='multipart/form-data'>\n";
3f5b683 Reintegrate sqlite branch
jakubvrana authored
194 $rows = array();
195 while ($row = $result->fetch_assoc()) {
196 $rows[] = $row;
197 }
198 // use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest)
199 $found_rows = (intval($limit) && $group && count($group) < count($select)
200 ? ($driver == "sql" ? $connection->result(" SELECT FOUND_ROWS()") : $connection->result("SELECT COUNT(*) FROM ($query) x")) // space to allow mysql.trace_mode
201 : count($rows)
202 );
203
204 if (!$rows) {
ace55ed HTML instead of XHTML
jakubvrana authored
205 echo "<p class='message'>" . lang('No rows.') . "\n";
21ea4ae Check errors
jakubvrana authored
206 } else {
09e93de Move backward keys to Editor
jakubvrana authored
207 $backward_keys = $adminer->backwardKeys($TABLE, $table_name);
c42c46a Table relations
jakubvrana authored
208
3c5c0f0 Use camelCase in JavaScript
jakubvrana authored
209 echo "<table cellspacing='0' class='nowrap' onclick='tableClick(event);'>\n";
210 echo "<thead><tr><td><input type='checkbox' id='all-page' onclick='formCheck(this, /check/);'>";
5034123 Apply field name with functions
jakubvrana authored
211 $names = array();
212 reset($select);
23df820 Distinguish no column order in fieldName
jakubvrana authored
213 $order = 1;
ba90d60 Introduce adminer_select_val
jakubvrana authored
214 foreach ($rows[0] as $key => $val) {
5034123 Apply field name with functions
jakubvrana authored
215 $val = $_GET["columns"][key($select)];
ba9c9a5 Display SQL function with braces in select heading
jakubvrana authored
216 $field = $fields[$select ? $val["col"] : $key];
6c97b80 Display only first five columns in Editor example
jakubvrana authored
217 $name = ($field ? $adminer->fieldName($field, $order) : "*");
7352c28 Replace strlen() by != ""
jakubvrana authored
218 if ($name != "") {
6c97b80 Display only first five columns in Editor example
jakubvrana authored
219 $order++;
5034123 Apply field name with functions
jakubvrana authored
220 $names[$key] = $name;
305a055 Go to first page after sorting (thanks to Jan Cerny)
jakubvrana authored
221 echo '<th><a href="' . h(remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key) . ($_GET["order"][0] == $key && !$_GET["desc"][0] ? '&desc%5B0%5D=1' : '')) . '">' . apply_sql_function($val["fun"], $name) . "</a>"; //! columns looking like functions
116c873 Ignore tables and fields with empty name
jakubvrana authored
222 }
5034123 Apply field name with functions
jakubvrana authored
223 next($select);
ba90d60 Introduce adminer_select_val
jakubvrana authored
224 }
09e93de Move backward keys to Editor
jakubvrana authored
225 echo ($backward_keys ? "<th>" . lang('Relations') : "") . "</thead>\n";
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored
226 foreach ($adminer->rowDescriptions($rows, $foreign_keys) as $n => $row) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
227 $unique_array = unique_array($rows[$n], $indexes);
16290b0 Respect where in COUNT(*) link
jakubvrana authored
228 $unique_idf = "";
229 foreach ($unique_array as $key => $val) {
230 $unique_idf .= "&" . (isset($val) ? urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($val) : "null%5B%5D=" . urlencode($key));
231 }
35ec64c Link COUNT(*) result to listing
jakubvrana authored
232 echo "<tr" . odd() . "><td>" . checkbox("check[]", substr($unique_idf, 1), in_array(substr($unique_idf, 1), (array) $_POST["check"]), "", "this.form['all'].checked = false; formUncheck('all-page');") . (count($select) != count($group) || information_schema(DB) ? '' : " <a href='" . h(ME . "edit=" . urlencode($TABLE) . $unique_idf) . "'>" . lang('edit') . "</a>");
21ea4ae Check errors
jakubvrana authored
233 foreach ($row as $key => $val) {
78e49f0 Pass $field to select_val
jakubvrana authored
234 if (isset($names[$key])) {
a1609c7 Align numbers to right in select
jakubvrana authored
235 $field = $fields[$key];
7352c28 Replace strlen() by != ""
jakubvrana authored
236 if ($val != "" && (!isset($email_fields[$key]) || $email_fields[$key] != "")) {
5034123 Apply field name with functions
jakubvrana authored
237 $email_fields[$key] = (is_email($val) ? $names[$key] : ""); //! filled e-mails may be contained on other pages
116c873 Ignore tables and fields with empty name
jakubvrana authored
238 }
5911cf1 Always call select_val
jakubvrana authored
239 $link = "";
a1609c7 Align numbers to right in select
jakubvrana authored
240 $val = $adminer->editVal($val, $field);
116c873 Ignore tables and fields with empty name
jakubvrana authored
241 if (!isset($val)) {
242 $val = "<i>NULL</i>";
21ea4ae Check errors
jakubvrana authored
243 } else {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
244 if (ereg('binary|blob|bytea', $field["type"]) && $val != "") {
35ec64c Link COUNT(*) result to listing
jakubvrana authored
245 $link = h(ME . 'download=' . urlencode($TABLE) . '&field=' . urlencode($key) . $unique_idf);
97b8c7b Display images in Editor
jakubvrana authored
246 }
7352c28 Replace strlen() by != ""
jakubvrana authored
247 if ($val == "") {
116c873 Ignore tables and fields with empty name
jakubvrana authored
248 $val = "&nbsp;";
7352c28 Replace strlen() by != ""
jakubvrana authored
249 } elseif ($text_length != "" && ereg('text|blob', $field["type"]) && is_utf8($val)) {
1859adc Comments
jakubvrana authored
250 $val = shorten_utf8($val, max(0, intval($text_length))); // usage of LEFT() would reduce traffic but complicate query - expected average speedup: .001 s VS .01 s on local network
116c873 Ignore tables and fields with empty name
jakubvrana authored
251 } else {
50881f8 Move whitespace to CSS
jakubvrana authored
252 $val = h($val);
21ea4ae Check errors
jakubvrana authored
253 }
116c873 Ignore tables and fields with empty name
jakubvrana authored
254
db46fc2 Maintain insert prefill value
jakubvrana authored
255 if (!$link) { // link related items
256 foreach ((array) $foreign_keys[$key] as $foreign_key) {
257 if (count($foreign_keys[$key]) == 1 || count($foreign_key["source"]) == 1) {
258 foreach ($foreign_key["source"] as $i => $source) {
259 $link .= where_link($i, $foreign_key["target"][$i], $rows[$n][$source]);
260 }
7352c28 Replace strlen() by != ""
jakubvrana authored
261 $link = h(($foreign_key["db"] != "" ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($foreign_key["db"]), ME) : ME) . 'select=' . urlencode($foreign_key["table"]) . $link); // InnoDB supports non-UNIQUE keys
db46fc2 Maintain insert prefill value
jakubvrana authored
262 break;
116c873 Ignore tables and fields with empty name
jakubvrana authored
263 }
21ea4ae Check errors
jakubvrana authored
264 }
ffcea8b Rights
jakubvrana authored
265 }
35ec64c Link COUNT(*) result to listing
jakubvrana authored
266 if ($key == "COUNT(*)") { //! columns looking like functions
267 $link = h(ME . "select=" . urlencode($TABLE));
268 $i = 0;
16290b0 Respect where in COUNT(*) link
jakubvrana authored
269 foreach ((array) $_GET["where"] as $v) {
270 if (!array_key_exists($v["col"], $unique_array)) {
186c058 Utilize where_link function
jakubvrana authored
271 $link .= h(where_link($i++, $v["col"], $v["val"], urlencode($v["op"])));
16290b0 Respect where in COUNT(*) link
jakubvrana authored
272 }
273 }
274 foreach ($unique_array as $k => $v) {
186c058 Utilize where_link function
jakubvrana authored
275 $link .= h(where_link($i++, $k, $v, (isset($v) ? "=" : "IS NULL")));
35ec64c Link COUNT(*) result to listing
jakubvrana authored
276 }
277 }
fa3dd55 Parent
jakubvrana authored
278 }
d6e3fc7 Link e-mails
jakubvrana authored
279 if (!$link && is_email($val)) {
280 $link = "mailto:$val";
281 }
ecb56e6 Link unescaped URL
jakubvrana authored
282 if (!$link && is_url($row[$key])) {
283 $link = "http://www.adminer.org/redirect/?url=" . urlencode($row[$key]); // intermediate page to hide Referer
bc78866 Link URLs in select
jakubvrana authored
284 }
a1609c7 Align numbers to right in select
jakubvrana authored
285 $val = $adminer->selectVal($val, $link, $field);
116c873 Ignore tables and fields with empty name
jakubvrana authored
286 echo "<td>$val";
667bfec Decomposition
jakubvrana authored
287 }
288 }
09e93de Move backward keys to Editor
jakubvrana authored
289 $adminer->backwardKeysPrint($backward_keys, $rows[$n]);
26e8ab9 Close </tr> because of white-space: pre
jakubvrana authored
290 echo "</tr>\n"; // close to allow white-space: pre
5ab708a Compact pages
jakubvrana authored
291 }
21ea4ae Check errors
jakubvrana authored
292 echo "</table>\n";
3f5b683 Reintegrate sqlite branch
jakubvrana authored
293 }
294
295 parse_str($_COOKIE["adminer_export"], $adminer_export);
296
bd25295 Don't redirect from last page
jakubvrana authored
297 if ($rows || $page) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
298 $exact_count = true;
bd25295 Don't redirect from last page
jakubvrana authored
299 if (intval($limit) && count($group) >= count($select) && ($found_rows >= $limit || $page)) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
300 $found_rows = $table_status["Rows"];
bd25295 Don't redirect from last page
jakubvrana authored
301 if (!isset($found_rows) || $where || 2 * $page * $limit > $found_rows || ($table_status["Engine"] == "InnoDB" && $found_rows < 1e4)) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
302 // slow with big tables
303 ob_flush();
304 flush();
305 $found_rows = $connection->result("SELECT COUNT(*) FROM " . idf_escape($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : ""));
306 } else {
307 $exact_count = false;
308 }
4cdc459 FOUND_ROWS works with last SELECT
jakubvrana authored
309 }
fde1171 Add CSS classes (thanks to cvicebni ubor)
jakubvrana authored
310 echo "<p class='pages'>";
e4b188c Display found rows
jakubvrana authored
311 if (intval($limit) && $found_rows > $limit) {
bd25295 Don't redirect from last page
jakubvrana authored
312 // display first, previous 4, next 4 and last page
21ea4ae Check errors
jakubvrana authored
313 $max_page = floor(($found_rows - 1) / $limit);
bd25295 Don't redirect from last page
jakubvrana authored
314 echo lang('Page') . ":" . pagination(0, $page) . ($page > 5 ? " ..." : "");
315 for ($i = max(1, $page - 4); $i < min($max_page, $page + 5); $i++) {
316 echo pagination($i, $page);
21ea4ae Check errors
jakubvrana authored
317 }
bd25295 Don't redirect from last page
jakubvrana authored
318 echo ($page + 5 < $max_page ? " ..." : "") . ($exact_count ? pagination($max_page, $page) : ' <a href="' . h(remove_from_uri() . "&page=last") . '">' . lang('last') . "</a>");
5ab708a Compact pages
jakubvrana authored
319 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored
320 echo " (" . ($exact_count ? "" : "~ ") . lang('%d row(s)', $found_rows) . ") " . checkbox("all", 1, 0, lang('whole result')) . "\n";
8b74511 Print SQL query (fixes #2082448)
jakubvrana authored
321
3c5c0f0 Use camelCase in JavaScript
jakubvrana authored
322 echo (information_schema(DB) ? "" : "<fieldset><legend>" . lang('Edit') . "</legend><div><input type='submit' name='edit' value='" . lang('Edit') . "'> <input type='submit' name='clone' value='" . lang('Clone') . "'> <input type='submit' name='delete' value='" . lang('Delete') . "' onclick=\"return confirm('" . lang('Are you sure?') . " (' + (this.form['all'].checked ? $found_rows : formChecked(this, /check/)) + ')');\"></div></fieldset>\n");
dc667ea Hide select export and import
jakubvrana authored
323 print_fieldset("export", lang('Export'));
3f5b683 Reintegrate sqlite branch
jakubvrana authored
324 echo $adminer->dumpOutput(1, $adminer_export["output"]) . " " . $adminer->dumpFormat(1, $adminer_export["format"]); // 1 - select
e40612a Use radio in export
jakubvrana authored
325 echo " <input type='submit' name='export' value='" . lang('Export') . "'>\n";
dc667ea Hide select export and import
jakubvrana authored
326 echo "</div></fieldset>\n";
667bfec Decomposition
jakubvrana authored
327 }
dc667ea Hide select export and import
jakubvrana authored
328 print_fieldset("import", lang('CSV Import'), !$result->num_rows);
3f5b683 Reintegrate sqlite branch
jakubvrana authored
329 echo "<input type='hidden' name='token' value='$token'><input type='file' name='csv_file'> ";
330 echo html_select("separator", array(",", ";"), ($adminer_export["format"] == "csv;" ? ";" : ","), 1); // 1 - select
331 echo " <input type='submit' name='import' value='" . lang('Import') . "'>\n";
dc667ea Hide select export and import
jakubvrana authored
332 echo "</div></fieldset>\n";
c16c57b E-mail sending
jakubvrana authored
333
1e55d47 User interface for e-mail {$name}
jakubvrana authored
334 $adminer->selectEmailPrint(array_filter($email_fields, 'strlen'), $columns);
c16c57b E-mail sending
jakubvrana authored
335
e7eb28d CSV import
jakubvrana authored
336 echo "</form>\n";
667bfec Decomposition
jakubvrana authored
337 }
338 }
Something went wrong with that request. Please try again.