Skip to content

HTTPS clone URL

Subversion checkout URL

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