Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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