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