Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 425 lines (406 sloc) 19.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);
f425601 @vrana Hide hidden columns in PostgreSQL (thanks to Pavel Stehule)
authored
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));
375a5c8 @vrana Non-MySQL binary types
authored
15 if (ereg('text|lob', $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();
ee3e045 @vrana Separate $where in limit function
authored
26 $from = ($select ? implode(", ", $select) : "*") . "\nFROM " . table($TABLE);
e44fbc2 Wrap SQL query
jakubvrana authored
27 $group_by = ($group && count($group) < count($select) ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : "");
116faf2 Mass delete
jakubvrana authored
28
390e38b @vrana Load long texts for inline-edit by AJAX
authored
29 if ($_GET["val"] && is_ajax()) {
30 header("Content-Type: text/plain; charset=utf-8");
31 foreach ($_GET["val"] as $unique_idf => $row) {
32 echo $connection->result("SELECT" . limit(idf_escape(key($row)) . " FROM " . table($TABLE), " WHERE " . where_check($unique_idf) . ($where ? " AND " . implode(" AND ", $where) : "") . ($order ? " ORDER BY " . implode(", ", $order) : ""), 1));
33 }
34 exit;
35 }
36
116faf2 Mass delete
jakubvrana authored
37 if ($_POST && !$error) {
56948c9 $_POST[check] may be empty
jakubvrana authored
38 $where_check = "(" . implode(") OR (", array_map('where_check', (array) $_POST["check"])) . ")";
6e50eb8 @vrana Pass primary key to insert_update function
authored
39 $primary = $unselected = null;
2ad8ab4 @vrana Primary key detection for other drivers
authored
40 foreach ($indexes as $index) {
41 if ($index["type"] == "PRIMARY") {
6e50eb8 @vrana Pass primary key to insert_update function
authored
42 $primary = array_flip($index["columns"]);
43 $unselected = ($select ? $primary : array());
2ad8ab4 @vrana Primary key detection for other drivers
authored
44 break;
45 }
46 }
d24ad78 Select boxes customization
jakubvrana authored
47 foreach ($select as $key => $val) {
48 $val = $_GET["columns"][$key];
49 if (!$val["fun"]) {
6e50eb8 @vrana Pass primary key to insert_update function
authored
50 unset($unselected[$val["col"]]);
d24ad78 Select boxes customization
jakubvrana authored
51 }
52 }
78639a9 Function results in edit
jakubvrana authored
53 if ($_POST["export"]) {
095d472 @vrana Customizable export
authored
54 $adminer->dumpHeaders($TABLE);
55 $adminer->dumpTable($TABLE, "");
5a99ef5 @vrana Save bytes
authored
56 if (ereg("[ct]sv", $_POST["format"])) { // CSV or TSV
b79ef09 Don't dump backticks in CSV column names
jakubvrana authored
57 $row = array_keys($fields);
58 if ($select) {
59 $row = array();
60 foreach ($select as $val) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
61 $row[] = (ereg('^`.*`$', $val) ? idf_unescape($val) : $val); //! columns looking like functions
b79ef09 Don't dump backticks in CSV column names
jakubvrana authored
62 }
63 }
64 dump_csv($row);
e4f5d17 Dump column names in CSV select export
jakubvrana authored
65 }
6e50eb8 @vrana Pass primary key to insert_update function
authored
66 if (!is_array($_POST["check"]) || $unselected === array()) {
ee3e045 @vrana Separate $where in limit function
authored
67 $where2 = $where;
68 if (is_array($_POST["check"])) {
69 $where2[] = "($where_check)";
70 }
095d472 @vrana Customizable export
authored
71 $adminer->dumpData($TABLE, "INSERT", "SELECT $from" . ($where2 ? "\nWHERE " . implode(" AND ", $where2) : "") . $group_by);
16c4ddb Single faster POST query with primary key
jakubvrana authored
72 } else {
fa5c952 Use extended INSERT in select export
jakubvrana authored
73 $union = array();
f7452ad Import and export
jakubvrana authored
74 foreach ($_POST["check"] as $val) {
16c4ddb Single faster POST query with primary key
jakubvrana authored
75 // where is not unique so OR can't be used
ee3e045 @vrana Separate $where in limit function
authored
76 $union[] = "(SELECT" . limit($from, "\nWHERE " . ($where ? implode(" AND ", $where) . " AND " : "") . where_check($val) . $group_by, 1) . ")";
116faf2 Mass delete
jakubvrana authored
77 }
095d472 @vrana Customizable export
authored
78 $adminer->dumpData($TABLE, "INSERT", implode(" UNION ALL ", $union));
116faf2 Mass delete
jakubvrana authored
79 }
78639a9 Function results in edit
jakubvrana authored
80 exit;
81 }
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored
82 if (!$adminer->selectEmailProcess($where, $foreign_keys)) {
d90bde5 Fix delete in select
jakubvrana authored
83 if ($_POST["save"] || $_POST["delete"]) { // edit
00d9b36 E-mail sending only in Editor
jakubvrana authored
84 $result = true;
85 $affected = 0;
60c7ed9 @vrana MS SQL schema support
authored
86 $query = table($TABLE);
28b2b8d Readable variable initialization
jakubvrana authored
87 $set = array();
00d9b36 E-mail sending only in Editor
jakubvrana authored
88 if (!$_POST["delete"]) {
89 foreach ($columns as $name => $val) { //! should check also for edit or insert privileges
a0def47 Date localization
jakubvrana authored
90 $val = process_input($fields[$name]);
3f5b683 Reintegrate sqlite branch
jakubvrana authored
91 if ($val !== null) {
92 if ($_POST["clone"]) {
93 $set[idf_escape($name)] = ($val !== false ? $val : idf_escape($name));
94 } elseif ($val !== false) {
95 $set[] = idf_escape($name) . " = $val";
96 }
00d9b36 E-mail sending only in Editor
jakubvrana authored
97 }
e7eb28d CSV import
jakubvrana authored
98 }
60c7ed9 @vrana MS SQL schema support
authored
99 $query .= ($_POST["clone"] ? " (" . implode(", ", array_keys($set)) . ")\nSELECT " . implode(", ", $set) . "\nFROM " . table($TABLE) : " SET\n" . implode(",\n", $set));
e7eb28d CSV import
jakubvrana authored
100 }
00d9b36 E-mail sending only in Editor
jakubvrana authored
101 if ($_POST["delete"] || $set) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
102 $command = "UPDATE";
103 if ($_POST["delete"]) {
104 $command = "DELETE";
105 $query = "FROM $query";
106 }
107 if ($_POST["clone"]) {
108 $command = "INSERT";
109 $query = "INTO $query";
110 }
6e50eb8 @vrana Pass primary key to insert_update function
authored
111 if ($_POST["all"] || ($unselected === array() && $_POST["check"]) || count($group) < count($select)) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
112 $result = queries($command . " $query" . ($_POST["all"] ? ($where ? "\nWHERE " . implode(" AND ", $where) : "") : "\nWHERE $where_check"));
64d616c Rename get_dbh to connection
jakubvrana authored
113 $affected = $connection->affected_rows;
00d9b36 E-mail sending only in Editor
jakubvrana authored
114 } else {
115 foreach ((array) $_POST["check"] as $val) {
116 // where is not unique so OR can't be used
ee3e045 @vrana Separate $where in limit function
authored
117 $result = queries($command . limit1($query, "\nWHERE " . where_check($val)));
00d9b36 E-mail sending only in Editor
jakubvrana authored
118 if (!$result) {
119 break;
120 }
64d616c Rename get_dbh to connection
jakubvrana authored
121 $affected += $connection->affected_rows;
38059b6 Remove empty if
jakubvrana authored
122 }
e7eb28d CSV import
jakubvrana authored
123 }
78639a9 Function results in edit
jakubvrana authored
124 }
dbdd40a Introduce queries_redirect function
jakubvrana authored
125 queries_redirect(remove_from_uri("page"), lang('%d item(s) have been affected.', $affected), $result);
00d9b36 E-mail sending only in Editor
jakubvrana authored
126 //! display edit page in case of an error
e0d9b3c In-place editation in select
jakubvrana authored
127 } elseif (!$_POST["import"]) { // modify
5050de5 @vrana Display modify hint as title
authored
128 if (!$_POST["val"]) {
129 $error = lang('Double click on a value to modify it.');
130 } else {
131 $result = true;
132 $affected = 0;
133 foreach ($_POST["val"] as $unique_idf => $row) {
134 $set = array();
135 foreach ($row as $key => $val) {
136 $key = bracket_escape($key, 1); // 1 - back
0782a7b @vrana Save '' instead of NULL for empty char (some drivers don't have varchar)
authored
137 $set[] = idf_escape($key) . " = " . (ereg('char|text', $fields[$key]["type"]) || $val != "" ? $adminer->processInput($fields[$key], $val) : "NULL");
5050de5 @vrana Display modify hint as title
authored
138 }
ca27ffc @vrana Display 0 in SQLite (bug #3120685)
authored
139 $query = table($TABLE) . " SET " . implode(", ", $set);
140 $where2 = " WHERE " . where_check($unique_idf) . ($where ? " AND " . implode(" AND ", $where) : "");
141 $result = queries("UPDATE" . (count($group) < count($select) ? " $query$where2" : limit1($query, $where2))); // can change row on a different page without unique key
5050de5 @vrana Display modify hint as title
authored
142 if (!$result) {
143 break;
144 }
145 $affected += $connection->affected_rows;
e0d9b3c In-place editation in select
jakubvrana authored
146 }
5050de5 @vrana Display modify hint as title
authored
147 queries_redirect(remove_from_uri(), lang('%d item(s) have been affected.', $affected), $result);
e0d9b3c In-place editation in select
jakubvrana authored
148 }
25f01d3 Compress export and import
jakubvrana authored
149 } elseif (is_string($file = get_file("csv_file", true))) {
00d9b36 E-mail sending only in Editor
jakubvrana authored
150 $file = preg_replace("~^\xEF\xBB\xBF~", '', $file); //! character set
cb370a8 Respect max_allowed_packet in CSV import
jakubvrana authored
151 $result = true;
e895368 Use ON DUPLICATE KEY UPDATE for CSV import
jakubvrana authored
152 $cols = array_keys($fields);
8a04897 Use atomic group for CSV regexp
jakubvrana authored
153 preg_match_all('~(?>"[^"]*"|[^"\\r\\n]+)+~', $file, $matches);
e895368 Use ON DUPLICATE KEY UPDATE for CSV import
jakubvrana authored
154 $affected = count($matches[0]);
d0c72ec Driver specific BEGIN
jakubvrana authored
155 begin();
e225d22 @vrana TSV export and import (bug #3097657)
authored
156 $separator = ($_POST["separator"] == "csv" ? "," : ($_POST["separator"] == "tsv" ? "\t" : ";"));
00d9b36 E-mail sending only in Editor
jakubvrana authored
157 foreach ($matches[0] as $key => $val) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
158 preg_match_all("~((\"[^\"]*\")+|[^$separator]*)$separator~", $val . $separator, $matches2);
e895368 Use ON DUPLICATE KEY UPDATE for CSV import
jakubvrana authored
159 if (!$key && !array_diff($matches2[1], $cols)) { //! doesn't work with column names containing ",\n
00d9b36 E-mail sending only in Editor
jakubvrana authored
160 // first row corresponds to column names - use it for table structure
e895368 Use ON DUPLICATE KEY UPDATE for CSV import
jakubvrana authored
161 $cols = $matches2[1];
162 $affected--;
00d9b36 E-mail sending only in Editor
jakubvrana authored
163 } else {
782921b @vrana Finish SQLite
authored
164 $set = array();
e895368 Use ON DUPLICATE KEY UPDATE for CSV import
jakubvrana authored
165 foreach ($matches2[1] as $i => $col) {
7e644b4 @vrana Save bytes ($connection->quote shortcut)
authored
166 $set[idf_escape($cols[$i])] = ($col == "" && $fields[$cols[$i]]["null"] ? "NULL" : q(str_replace('""', '"', preg_replace('~^"|"$~', '', $col))));
00d9b36 E-mail sending only in Editor
jakubvrana authored
167 }
6e50eb8 @vrana Pass primary key to insert_update function
authored
168 $result = insert_update($TABLE, $set, $primary);
e895368 Use ON DUPLICATE KEY UPDATE for CSV import
jakubvrana authored
169 if (!$result) {
170 break;
cb370a8 Respect max_allowed_packet in CSV import
jakubvrana authored
171 }
172 }
173 }
6ba224b Rollback unsuccessful CSV import
jakubvrana authored
174 if ($result) {
acf7a42 Improve CSV; export
jakubvrana authored
175 queries("COMMIT");
6ba224b Rollback unsuccessful CSV import
jakubvrana authored
176 }
dbdd40a Introduce queries_redirect function
jakubvrana authored
177 queries_redirect(remove_from_uri("page"), lang('%d row(s) have been imported.', $affected), $result);
782921b @vrana Finish SQLite
authored
178 queries("ROLLBACK"); // after queries_redirect() to not overwrite error
00d9b36 E-mail sending only in Editor
jakubvrana authored
179 } else {
180 $error = upload_error($file);
d83b654 Detect import errors
jakubvrana authored
181 }
ec23248 Exportable select
jakubvrana authored
182 }
116faf2 Mass delete
jakubvrana authored
183 }
c16c57b E-mail sending
jakubvrana authored
184
b9ffd64 Remove common prefix in backward key
jakubvrana authored
185 $table_name = $adminer->tableName($table_status);
186 page_header(lang('Select') . ": $table_name", $error);
e0d9b3c In-place editation in select
jakubvrana authored
187 session_write_close();
116faf2 Mass delete
jakubvrana authored
188
f2ed237 Display table links above table structure
jakubvrana authored
189 $set = null;
430034c Cottage homework
jakubvrana authored
190 if (isset($rights["insert"])) {
98507da Function verify_version doesn't use version parameter
jakubvrana authored
191 $set = "";
192 foreach ((array) $_GET["where"] as $val) {
193 if (count($foreign_keys[$val["col"]]) == 1 && ($val["op"] == "="
a1609c7 Align numbers to right in select
jakubvrana authored
194 || (!$val["op"] && !ereg('[_%]', $val["val"])) // LIKE in Editor
98507da Function verify_version doesn't use version parameter
jakubvrana authored
195 )) {
196 $set .= "&set" . urlencode("[" . bracket_escape($val["col"]) . "]") . "=" . urlencode($val["val"]);
197 }
198 }
667bfec Decomposition
jakubvrana authored
199 }
f2ed237 Display table links above table structure
jakubvrana authored
200 $adminer->selectLinks($table_status, $set);
667bfec Decomposition
jakubvrana authored
201
ffcea8b Rights
jakubvrana authored
202 if (!$columns) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
203 echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "." : ": " . error()) . "\n";
ffcea8b Rights
jakubvrana authored
204 } else {
38894b2 @vrana Send all forms by AJAX
authored
205 echo "<form action='' id='form'>\n";
d24ad78 Select boxes customization
jakubvrana authored
206 echo "<div style='display: none;'>";
3f5b683 Reintegrate sqlite branch
jakubvrana authored
207 hidden_fields_get();
8878799 @vrana Respect namespace
authored
208 echo (DB != "" ? '<input type="hidden" name="db" value="' . h(DB) . '">' . (isset($_GET["ns"]) ? '<input type="hidden" name="ns" value="' . h($_GET["ns"]) . '">' : "") : ""); // not used in Editor
79d1902 Substitute table name to $TABLE
jakubvrana authored
209 echo '<input type="hidden" name="select" value="' . h($TABLE) . '">';
d24ad78 Select boxes customization
jakubvrana authored
210 echo "</div>\n";
211 $adminer->selectColumnsPrint($select, $columns);
212 $adminer->selectSearchPrint($where, $columns, $indexes);
213 $adminer->selectOrderPrint($order, $columns, $indexes);
214 $adminer->selectLimitPrint($limit);
215 $adminer->selectLengthPrint($text_length);
216 $adminer->selectActionPrint($text_length);
ffcea8b Rights
jakubvrana authored
217 echo "</form>\n";
218
bd25295 Don't redirect from last page
jakubvrana authored
219 $page = $_GET["page"];
220 if ($page == "last") {
60c7ed9 @vrana MS SQL schema support
authored
221 $found_rows = $connection->result("SELECT COUNT(*) FROM " . table($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : ""));
31afb96 @vrana Last page with empty result (thanks to Frantisek Svoboda)
authored
222 $page = floor(max(0, $found_rows - 1) / $limit);
bd25295 Don't redirect from last page
jakubvrana authored
223 }
224
04eccba @vrana Allow bigger numbers under 32 bits
authored
225 $query = "SELECT" . limit((+$limit && $group && count($group) < count($select) && $jush == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . $from, ($where ? "\nWHERE " . implode(" AND ", $where) : "") . $group_by, ($limit != "" ? +$limit : null), ($page ? $limit * $page : 0), "\n");
c64c4fd Adminer class
jakubvrana authored
226 echo $adminer->selectQuery($query);
8b74511 Print SQL query (fixes #2082448)
jakubvrana authored
227
64d616c Rename get_dbh to connection
jakubvrana authored
228 $result = $connection->query($query);
21ea4ae Check errors
jakubvrana authored
229 if (!$result) {
c1130ed Simplify SQL syntax errors everywhere
jakubvrana authored
230 echo "<p class='error'>" . error() . "\n";
ffcea8b Rights
jakubvrana authored
231 } else {
e672694 @vrana Rename $driver to $jush
authored
232 if ($jush == "mssql") {
1b144a1 MS SQL pagination
jakubvrana authored
233 $result->seek($limit * $page);
234 }
f2365d0 Typo
jakubvrana authored
235 $email_fields = array();
b535853 @vrana Full AJAX only with pushState to work correctly with history
authored
236 echo "<form action='' method='post' enctype='multipart/form-data'>\n";
3f5b683 Reintegrate sqlite branch
jakubvrana authored
237 $rows = array();
238 while ($row = $result->fetch_assoc()) {
239 $rows[] = $row;
240 }
241 // use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest)
1b144a1 MS SQL pagination
jakubvrana authored
242 if ($_GET["page"] != "last") {
04eccba @vrana Allow bigger numbers under 32 bits
authored
243 $found_rows = (+$limit && $group && count($group) < count($select)
e672694 @vrana Rename $driver to $jush
authored
244 ? ($jush == "sql" ? $connection->result(" SELECT FOUND_ROWS()") : $connection->result("SELECT COUNT(*) FROM ($query) x")) // space to allow mysql.trace_mode
1b144a1 MS SQL pagination
jakubvrana authored
245 : count($rows)
246 );
247 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored
248
249 if (!$rows) {
ace55ed HTML instead of XHTML
jakubvrana authored
250 echo "<p class='message'>" . lang('No rows.') . "\n";
21ea4ae Check errors
jakubvrana authored
251 } else {
09e93de Move backward keys to Editor
jakubvrana authored
252 $backward_keys = $adminer->backwardKeys($TABLE, $table_name);
c42c46a Table relations
jakubvrana authored
253
3c5c0f0 Use camelCase in JavaScript
jakubvrana authored
254 echo "<table cellspacing='0' class='nowrap' onclick='tableClick(event);'>\n";
22a7ebd @vrana Hide edit link without columns
authored
255 echo "<thead><tr>" . (!$group && $select ? "" : "<td><input type='checkbox' id='all-page' onclick='formCheck(this, /check/);'> <a href='" . h($_GET["modify"] ? remove_from_uri("modify") : $_SERVER["REQUEST_URI"] . "&modify=1") . "'>" . lang('edit') . "</a>");
5034123 Apply field name with functions
jakubvrana authored
256 $names = array();
c40d1d0 Always handle double click
jakubvrana authored
257 $functions = array();
5034123 Apply field name with functions
jakubvrana authored
258 reset($select);
9bc9b9f @vrana Don't overwrite variable
authored
259 $rank = 1;
ba90d60 Introduce adminer_select_val
jakubvrana authored
260 foreach ($rows[0] as $key => $val) {
5034123 Apply field name with functions
jakubvrana authored
261 $val = $_GET["columns"][key($select)];
ba9c9a5 Display SQL function with braces in select heading
jakubvrana authored
262 $field = $fields[$select ? $val["col"] : $key];
9bc9b9f @vrana Don't overwrite variable
authored
263 $name = ($field ? $adminer->fieldName($field, $rank) : "*");
7352c28 Replace strlen() by != ""
jakubvrana authored
264 if ($name != "") {
9bc9b9f @vrana Don't overwrite variable
authored
265 $rank++;
5034123 Apply field name with functions
jakubvrana authored
266 $names[$key] = $name;
b05684a @vrana Order by DESC with grouping
authored
267 $column = idf_escape($key);
6585b23 @vrana Generic AJAX links
authored
268 echo '<th><a href="' . h(remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key) . ($order[0] == $column || $order[0] == $key || (!$order && $group[0] == $column) ? '&desc%5B0%5D=1' : '')) . '">' . apply_sql_function($val["fun"], $name) . "</a>"; // $order[0] == $key - COUNT(*) //! columns looking like functions
116c873 Ignore tables and fields with empty name
jakubvrana authored
269 }
c40d1d0 Always handle double click
jakubvrana authored
270 $functions[$key] = $val["fun"];
5034123 Apply field name with functions
jakubvrana authored
271 next($select);
ba90d60 Introduce adminer_select_val
jakubvrana authored
272 }
e0d9b3c In-place editation in select
jakubvrana authored
273 $lengths = array();
274 if ($_GET["modify"]) {
275 foreach ($rows as $row) {
276 foreach ($row as $key => $val) {
277 $lengths[$key] = max($lengths[$key], min(40, strlen(utf8_decode($val))));
278 }
279 }
280 }
09e93de Move backward keys to Editor
jakubvrana authored
281 echo ($backward_keys ? "<th>" . lang('Relations') : "") . "</thead>\n";
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored
282 foreach ($adminer->rowDescriptions($rows, $foreign_keys) as $n => $row) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
283 $unique_array = unique_array($rows[$n], $indexes);
16290b0 Respect where in COUNT(*) link
jakubvrana authored
284 $unique_idf = "";
285 foreach ($unique_array as $key => $val) {
286 $unique_idf .= "&" . (isset($val) ? urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($val) : "null%5B%5D=" . urlencode($key));
287 }
22a7ebd @vrana Hide edit link without columns
authored
288 echo "<tr" . odd() . ">" . (!$group && $select ? "" : "<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($group) < count($select) || information_schema(DB) ? "" : " <a href='" . h(ME . "edit=" . urlencode($TABLE) . $unique_idf) . "'>" . lang('edit') . "</a>"));
21ea4ae Check errors
jakubvrana authored
289 foreach ($row as $key => $val) {
78e49f0 Pass $field to select_val
jakubvrana authored
290 if (isset($names[$key])) {
a1609c7 Align numbers to right in select
jakubvrana authored
291 $field = $fields[$key];
7352c28 Replace strlen() by != ""
jakubvrana authored
292 if ($val != "" && (!isset($email_fields[$key]) || $email_fields[$key] != "")) {
1cf374b @vrana Rename functions (avoid conflict with WordPress)
authored
293 $email_fields[$key] = (is_mail($val) ? $names[$key] : ""); //! filled e-mails can be contained on other pages
116c873 Ignore tables and fields with empty name
jakubvrana authored
294 }
5911cf1 Always call select_val
jakubvrana authored
295 $link = "";
a1609c7 Align numbers to right in select
jakubvrana authored
296 $val = $adminer->editVal($val, $field);
116c873 Ignore tables and fields with empty name
jakubvrana authored
297 if (!isset($val)) {
298 $val = "<i>NULL</i>";
21ea4ae Check errors
jakubvrana authored
299 } else {
5a73c01 @vrana Treat binary type as hex
authored
300 if (ereg('blob|bytea|raw|file', $field["type"]) && $val != "") {
35ec64c Link COUNT(*) result to listing
jakubvrana authored
301 $link = h(ME . 'download=' . urlencode($TABLE) . '&field=' . urlencode($key) . $unique_idf);
97b8c7b Display images in Editor
jakubvrana authored
302 }
ca27ffc @vrana Display 0 in SQLite (bug #3120685)
authored
303 if ($val === "") { // === - may be int
116c873 Ignore tables and fields with empty name
jakubvrana authored
304 $val = "&nbsp;";
7352c28 Replace strlen() by != ""
jakubvrana authored
305 } elseif ($text_length != "" && ereg('text|blob', $field["type"]) && is_utf8($val)) {
04eccba @vrana Allow bigger numbers under 32 bits
authored
306 $val = shorten_utf8($val, max(0, +$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
307 } else {
50881f8 Move whitespace to CSS
jakubvrana authored
308 $val = h($val);
21ea4ae Check errors
jakubvrana authored
309 }
116c873 Ignore tables and fields with empty name
jakubvrana authored
310
db46fc2 Maintain insert prefill value
jakubvrana authored
311 if (!$link) { // link related items
312 foreach ((array) $foreign_keys[$key] as $foreign_key) {
81f58ed @vrana Link more foreign keys
authored
313 if (count($foreign_keys[$key]) == 1 || end($foreign_key["source"]) == $key) {
314 $link = "";
db46fc2 Maintain insert prefill value
jakubvrana authored
315 foreach ($foreign_key["source"] as $i => $source) {
316 $link .= where_link($i, $foreign_key["target"][$i], $rows[$n][$source]);
317 }
7352c28 Replace strlen() by != ""
jakubvrana authored
318 $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
81f58ed @vrana Link more foreign keys
authored
319 if (count($foreign_key["source"]) == 1) {
320 break;
321 }
116c873 Ignore tables and fields with empty name
jakubvrana authored
322 }
21ea4ae Check errors
jakubvrana authored
323 }
ffcea8b Rights
jakubvrana authored
324 }
35ec64c Link COUNT(*) result to listing
jakubvrana authored
325 if ($key == "COUNT(*)") { //! columns looking like functions
326 $link = h(ME . "select=" . urlencode($TABLE));
327 $i = 0;
16290b0 Respect where in COUNT(*) link
jakubvrana authored
328 foreach ((array) $_GET["where"] as $v) {
329 if (!array_key_exists($v["col"], $unique_array)) {
22eb69b @vrana Remove operator double encode
authored
330 $link .= h(where_link($i++, $v["col"], $v["val"], $v["op"]));
16290b0 Respect where in COUNT(*) link
jakubvrana authored
331 }
332 }
333 foreach ($unique_array as $k => $v) {
186c058 Utilize where_link function
jakubvrana authored
334 $link .= h(where_link($i++, $k, $v, (isset($v) ? "=" : "IS NULL")));
35ec64c Link COUNT(*) result to listing
jakubvrana authored
335 }
336 }
fa3dd55 Parent
jakubvrana authored
337 }
2cec758 @vrana Direct links from HTTPS to HTTP
authored
338 if (!$link) {
1cf374b @vrana Rename functions (avoid conflict with WordPress)
authored
339 if (is_mail($val)) {
2cec758 @vrana Direct links from HTTPS to HTTP
authored
340 $link = "mailto:$val";
341 }
342 if ($protocol = is_url($row[$key])) {
343 $link = ($protocol == "http" && $HTTPS
344 ? $row[$key] // HTTP links from HTTPS pages don't receive Referer automatically
345 : "$protocol://www.adminer.org/redirect/?url=" . urlencode($row[$key]) // intermediate page to hide Referer, may be changed to rel="noreferrer" in HTML5
346 );
347 }
bc78866 Link URLs in select
jakubvrana authored
348 }
e0d9b3c In-place editation in select
jakubvrana authored
349 $id = h("val[$unique_idf][" . bracket_escape($key) . "]");
de24145 @vrana Clear POST with AJAX redirect
authored
350 $value = $_POST["val"][$unique_idf][bracket_escape($key)];
e0d9b3c In-place editation in select
jakubvrana authored
351 $h_value = h(isset($value) ? $value : $row[$key]);
687b3fd @vrana Replace <strong> by <b> and <em> by <i>
authored
352 $long = strpos($val, "<i>...</i>");
390e38b @vrana Load long texts for inline-edit by AJAX
authored
353 $editable = is_utf8($val) && $rows[$n][$key] == $row[$key] && !$functions[$key];
375a5c8 @vrana Non-MySQL binary types
authored
354 $text = ereg('text|lob', $field["type"]);
e0d9b3c In-place editation in select
jakubvrana authored
355 echo (($_GET["modify"] && $editable) || isset($value)
71438d5 @vrana Handle keypress instead of keydown (bug #3112458)
authored
356 ? "<td>" . ($text ? "<textarea name='$id' cols='30' rows='" . (substr_count($row[$key], "\n") + 1) . "' onkeypress='return textareaKeypress(this, event);'>$h_value</textarea>" : "<input name='$id' value='$h_value' size='$lengths[$key]'>")
390e38b @vrana Load long texts for inline-edit by AJAX
authored
357 : "<td id='$id' ondblclick=\"" . ($editable ? "selectDblClick(this, event" . ($long ? ", 2" : ($text ? ", 1" : "")) . ")" : "alert('" . h(lang('Use edit link to modify this value.')) . "')") . ";\">" . $adminer->selectVal($val, $link, $field)
e0d9b3c In-place editation in select
jakubvrana authored
358 );
667bfec Decomposition
jakubvrana authored
359 }
360 }
33aec2c @vrana Move <td> from Adminer::backwardKeysPrint
authored
361 if ($backward_keys) {
362 echo "<td>";
363 }
09e93de Move backward keys to Editor
jakubvrana authored
364 $adminer->backwardKeysPrint($backward_keys, $rows[$n]);
26e8ab9 Close </tr> because of white-space: pre
jakubvrana authored
365 echo "</tr>\n"; // close to allow white-space: pre
5ab708a Compact pages
jakubvrana authored
366 }
21ea4ae Check errors
jakubvrana authored
367 echo "</table>\n";
3f5b683 Reintegrate sqlite branch
jakubvrana authored
368 }
369
370 parse_str($_COOKIE["adminer_export"], $adminer_export);
371
bd25295 Don't redirect from last page
jakubvrana authored
372 if ($rows || $page) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
373 $exact_count = true;
04eccba @vrana Allow bigger numbers under 32 bits
authored
374 if ($_GET["page"] != "last" && +$limit && count($group) >= count($select) && ($found_rows >= $limit || $page)) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
375 $found_rows = $table_status["Rows"];
bd25295 Don't redirect from last page
jakubvrana authored
376 if (!isset($found_rows) || $where || 2 * $page * $limit > $found_rows || ($table_status["Engine"] == "InnoDB" && $found_rows < 1e4)) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
377 // slow with big tables
378 ob_flush();
379 flush();
60c7ed9 @vrana MS SQL schema support
authored
380 $found_rows = $connection->result("SELECT COUNT(*) FROM " . table($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : ""));
3f5b683 Reintegrate sqlite branch
jakubvrana authored
381 } else {
382 $exact_count = false;
383 }
4cdc459 FOUND_ROWS works with last SELECT
jakubvrana authored
384 }
fde1171 Add CSS classes (thanks to cvicebni ubor)
jakubvrana authored
385 echo "<p class='pages'>";
04eccba @vrana Allow bigger numbers under 32 bits
authored
386 if (+$limit && $found_rows > $limit) {
bd25295 Don't redirect from last page
jakubvrana authored
387 // display first, previous 4, next 4 and last page
21ea4ae Check errors
jakubvrana authored
388 $max_page = floor(($found_rows - 1) / $limit);
9802869 @vrana Merge from master
authored
389 echo '<a href="' . h(remove_from_uri("page")) . "\" onclick=\"pageClick(this.href, +prompt('" . lang('Page') . "', '" . ($page + 1) . "'), event); return false;\">" . lang('Page') . "</a>:";
6e3c7cb @vrana Use AJAX for pagination
authored
390 echo pagination(0, $page) . ($page > 5 ? " ..." : "");
bd25295 Don't redirect from last page
jakubvrana authored
391 for ($i = max(1, $page - 4); $i < min($max_page, $page + 5); $i++) {
392 echo pagination($i, $page);
21ea4ae Check errors
jakubvrana authored
393 }
6585b23 @vrana Generic AJAX links
authored
394 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
395 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored
396 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
397
e0d9b3c In-place editation in select
jakubvrana authored
398 if (!information_schema(DB)) {
399 ?>
400 <fieldset><legend><?php echo lang('Edit'); ?></legend><div>
38894b2 @vrana Send all forms by AJAX
authored
401 <input type="submit" id="save" value="<?php echo lang('Save'); ?>" title="<?php echo lang('Double click on a value to modify it.'); ?>">
402 <input type="submit" name="edit" value="<?php echo lang('Edit'); ?>">
403 <input type="submit" name="clone" value="<?php echo lang('Clone'); ?>">
404 <input type="submit" name="delete" value="<?php echo lang('Delete'); ?>" onclick="return confirm('<?php echo lang('Are you sure?'); ?> (' + (this.form['all'].checked ? <?php echo $found_rows; ?> : formChecked(this, /check/)) + ')');">
e0d9b3c In-place editation in select
jakubvrana authored
405 </div></fieldset>
406 <?php
407 }
dc667ea Hide select export and import
jakubvrana authored
408 print_fieldset("export", lang('Export'));
be3410f @vrana Simplify dumpOutput, dumpFormat and dumpData methods
authored
409 $output = $adminer->dumpOutput();
410 echo ($output ? html_select("output", $output, $adminer_export["output"]) . " " : "") . html_select("format", $adminer->dumpFormat(), $adminer_export["format"]);
fc6e71a @vrana Disable AJAX export
authored
411 echo " <input type='submit' name='export' value='" . lang('Export') . "' onclick='eventStop(event);'>\n";
dc667ea Hide select export and import
jakubvrana authored
412 echo "</div></fieldset>\n";
667bfec Decomposition
jakubvrana authored
413 }
dba6a90 @vrana Property num_rows can be empty
authored
414 print_fieldset("import", lang('CSV Import'), !$rows);
3f5b683 Reintegrate sqlite branch
jakubvrana authored
415 echo "<input type='hidden' name='token' value='$token'><input type='file' name='csv_file'> ";
e225d22 @vrana TSV export and import (bug #3097657)
authored
416 echo html_select("separator", array("csv" => "CSV,", "csv;" => "CSV;", "tsv" => "TSV"), $adminer_export["format"], 1); // 1 - select
3f5b683 Reintegrate sqlite branch
jakubvrana authored
417 echo " <input type='submit' name='import' value='" . lang('Import') . "'>\n";
dc667ea Hide select export and import
jakubvrana authored
418 echo "</div></fieldset>\n";
c16c57b E-mail sending
jakubvrana authored
419
1e55d47 User interface for e-mail {$name}
jakubvrana authored
420 $adminer->selectEmailPrint(array_filter($email_fields, 'strlen'), $columns);
c16c57b E-mail sending
jakubvrana authored
421
e7eb28d CSV import
jakubvrana authored
422 echo "</form>\n";
667bfec Decomposition
jakubvrana authored
423 }
424 }
Something went wrong with that request. Please try again.