Skip to content

HTTPS clone URL

Subversion checkout URL

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