Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 478 lines (460 sloc) 20.936 kb
667bfec4 » jakubvrana
2007-07-02 Decomposition
1 <?php
79d19028 » jakubvrana
2009-08-29 Substitute table name to $TABLE
2 $TABLE = $_GET["select"];
3 $table_status = table_status($TABLE);
4 $indexes = indexes($TABLE);
f4256013 »
2010-11-11 Hide hidden columns in PostgreSQL (thanks to Pavel Stehule)
5 $fields = fields($TABLE);
dea345cb » jakubvrana
2009-09-09 Substitute foreign keys in e-mail fields
6 $foreign_keys = column_foreign_keys($TABLE);
98483e10 »
2012-07-15 SQLite: Better editing in tables without a primary key
7 $oid = "";
37d81464 »
2011-02-01 Utilize oids in PostgreSQL
8 if ($table_status["Oid"] == "t") {
98483e10 »
2012-07-15 SQLite: Better editing in tables without a primary key
9 $oid = ($jush == "sqlite" ? "rowid" : "oid");
10 $indexes[] = array("type" => "PRIMARY", "columns" => array($oid));
37d81464 »
2011-02-01 Utilize oids in PostgreSQL
11 }
ead05e68 »
2011-07-13 Remember export and import options
12 parse_str($_COOKIE["adminer_import"], $adminer_import);
dea345cb » jakubvrana
2009-09-09 Substitute foreign keys in e-mail fields
13
64ba9242 » jakubvrana
2009-06-21 Comments
14 $rights = array(); // privilege => 0
15 $columns = array(); // selectable columns
0115315a » jakubvrana
2010-04-22 Init with null
16 $text_length = null;
ffcea8b5 » jakubvrana
2007-07-06 Rights
17 foreach ($fields as $key => $field) {
c64c4fd1 » jakubvrana
2009-07-27 Adminer class
18 $name = $adminer->fieldName($field);
7352c281 » jakubvrana
2010-01-09 Replace strlen() by != ""
19 if (isset($field["privileges"]["select"]) && $name != "") {
1e4d11e9 » jakubvrana
2009-07-23 Select from foreign keys in Editor
20 $columns[$key] = html_entity_decode(strip_tags($name));
375a5c8e »
2010-05-26 Non-MySQL binary types
21 if (ereg('text|lob', $field["type"])) {
d24ad780 » jakubvrana
2009-07-27 Select boxes customization
22 $text_length = $adminer->selectLengthProcess();
16c4ddb4 » jakubvrana
2009-07-13 Single faster POST query with primary key
23 }
ffcea8b5 » jakubvrana
2007-07-06 Rights
24 }
430034c3 » jakubvrana
2007-07-09 Cottage homework
25 $rights += $field["privileges"];
26 }
27
d24ad780 » jakubvrana
2009-07-27 Select boxes customization
28 list($select, $group) = $adminer->selectColumnsProcess($columns, $indexes);
07e1ae10 » jakubvrana
2009-07-28 FOUND_ROWS only with GROUP BY
29 $where = $adminer->selectSearchProcess($fields, $indexes);
30 $order = $adminer->selectOrderProcess($fields, $indexes);
d24ad780 » jakubvrana
2009-07-27 Select boxes customization
31 $limit = $adminer->selectLimitProcess();
98483e10 »
2012-07-15 SQLite: Better editing in tables without a primary key
32 $from = ($select ? implode(", ", $select) : ($oid ? "$oid, " : "") . "*") . "\nFROM " . table($TABLE);
e44fbc2e » jakubvrana
2010-03-11 Wrap SQL query
33 $group_by = ($group && count($group) < count($select) ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : "");
116faf2e » jakubvrana
2008-01-08 Mass delete
34
390e38b8 »
2010-10-18 Load long texts for inline-edit by AJAX
35 if ($_GET["val"] && is_ajax()) {
36 header("Content-Type: text/plain; charset=utf-8");
37 foreach ($_GET["val"] as $unique_idf => $row) {
38 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));
39 }
40 exit;
41 }
42
116faf2e » jakubvrana
2008-01-08 Mass delete
43 if ($_POST && !$error) {
56948c93 » jakubvrana
2009-07-16 $_POST[check] may be empty
44 $where_check = "(" . implode(") OR (", array_map('where_check', (array) $_POST["check"])) . ")";
6e50eb8e »
2010-07-22 Pass primary key to insert_update function
45 $primary = $unselected = null;
2ad8ab47 »
2010-07-22 Primary key detection for other drivers
46 foreach ($indexes as $index) {
47 if ($index["type"] == "PRIMARY") {
6e50eb8e »
2010-07-22 Pass primary key to insert_update function
48 $primary = array_flip($index["columns"]);
49 $unselected = ($select ? $primary : array());
2ad8ab47 »
2010-07-22 Primary key detection for other drivers
50 break;
51 }
52 }
d2c513d1 »
2011-05-24 Column names customization (bug #3194500)
53 foreach ((array) $unselected as $key => $val) {
54 if (in_array(idf_escape($key), $select)) {
55 unset($unselected[$key]);
d24ad780 » jakubvrana
2009-07-27 Select boxes customization
56 }
57 }
78639a98 » jakubvrana
2008-10-01 Function results in edit
58 if ($_POST["export"]) {
ead05e68 »
2011-07-13 Remember export and import options
59 cookie("adminer_import", "output=" . urlencode($_POST["output"]) . "&format=" . urlencode($_POST["format"]));
8ab6fffe »
2011-02-17 Centralize dump_headers
60 dump_headers($TABLE);
095d4723 »
2010-10-29 Customizable export
61 $adminer->dumpTable($TABLE, "");
6e50eb8e »
2010-07-22 Pass primary key to insert_update function
62 if (!is_array($_POST["check"]) || $unselected === array()) {
ee3e0459 »
2010-05-14 Separate $where in limit function
63 $where2 = $where;
64 if (is_array($_POST["check"])) {
65 $where2[] = "($where_check)";
66 }
15715b32 »
2011-02-15 Export SQL command result (bug #3116854)
67 $query = "SELECT $from" . ($where2 ? "\nWHERE " . implode(" AND ", $where2) : "") . $group_by;
16c4ddb4 » jakubvrana
2009-07-13 Single faster POST query with primary key
68 } else {
fa5c952a » jakubvrana
2009-06-15 Use extended INSERT in select export
69 $union = array();
f7452add » jakubvrana
2009-04-01 Import and export
70 foreach ($_POST["check"] as $val) {
16c4ddb4 » jakubvrana
2009-07-13 Single faster POST query with primary key
71 // where is not unique so OR can't be used
ee3e0459 »
2010-05-14 Separate $where in limit function
72 $union[] = "(SELECT" . limit($from, "\nWHERE " . ($where ? implode(" AND ", $where) . " AND " : "") . where_check($val) . $group_by, 1) . ")";
116faf2e » jakubvrana
2008-01-08 Mass delete
73 }
15715b32 »
2011-02-15 Export SQL command result (bug #3116854)
74 $query = implode(" UNION ALL ", $union);
116faf2e » jakubvrana
2008-01-08 Mass delete
75 }
15715b32 »
2011-02-15 Export SQL command result (bug #3116854)
76 $adminer->dumpData($TABLE, "table", $query);
78639a98 » jakubvrana
2008-10-01 Function results in edit
77 exit;
78 }
dea345cb » jakubvrana
2009-09-09 Substitute foreign keys in e-mail fields
79 if (!$adminer->selectEmailProcess($where, $foreign_keys)) {
d90bde5b » jakubvrana
2010-04-27 Fix delete in select
80 if ($_POST["save"] || $_POST["delete"]) { // edit
00d9b361 » jakubvrana
2009-07-24 E-mail sending only in Editor
81 $result = true;
82 $affected = 0;
60c7ed9a »
2010-05-11 MS SQL schema support
83 $query = table($TABLE);
28b2b8db » jakubvrana
2009-07-30 Readable variable initialization
84 $set = array();
00d9b361 » jakubvrana
2009-07-24 E-mail sending only in Editor
85 if (!$_POST["delete"]) {
86 foreach ($columns as $name => $val) { //! should check also for edit or insert privileges
a0def479 » jakubvrana
2009-07-27 Date localization
87 $val = process_input($fields[$name]);
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
88 if ($val !== null) {
89 if ($_POST["clone"]) {
90 $set[idf_escape($name)] = ($val !== false ? $val : idf_escape($name));
91 } elseif ($val !== false) {
92 $set[] = idf_escape($name) . " = $val";
93 }
00d9b361 » jakubvrana
2009-07-24 E-mail sending only in Editor
94 }
e7eb28d3 » jakubvrana
2008-12-30 CSV import
95 }
60c7ed9a »
2010-05-11 MS SQL schema support
96 $query .= ($_POST["clone"] ? " (" . implode(", ", array_keys($set)) . ")\nSELECT " . implode(", ", $set) . "\nFROM " . table($TABLE) : " SET\n" . implode(",\n", $set));
e7eb28d3 » jakubvrana
2008-12-30 CSV import
97 }
00d9b361 » jakubvrana
2009-07-24 E-mail sending only in Editor
98 if ($_POST["delete"] || $set) {
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
99 $command = "UPDATE";
100 if ($_POST["delete"]) {
101 $command = "DELETE";
102 $query = "FROM $query";
103 }
104 if ($_POST["clone"]) {
105 $command = "INSERT";
106 $query = "INTO $query";
107 }
6e50eb8e »
2010-07-22 Pass primary key to insert_update function
108 if ($_POST["all"] || ($unselected === array() && $_POST["check"]) || count($group) < count($select)) {
f1153aa3 »
2012-07-27 Display assigned auto_increment after clone
109 $result = queries("$command $query" . ($_POST["all"] ? ($where ? "\nWHERE " . implode(" AND ", $where) : "") : "\nWHERE $where_check"));
64d616c0 » jakubvrana
2009-09-22 Rename get_dbh to connection
110 $affected = $connection->affected_rows;
00d9b361 » jakubvrana
2009-07-24 E-mail sending only in Editor
111 } else {
112 foreach ((array) $_POST["check"] as $val) {
113 // where is not unique so OR can't be used
ee3e0459 »
2010-05-14 Separate $where in limit function
114 $result = queries($command . limit1($query, "\nWHERE " . where_check($val)));
00d9b361 » jakubvrana
2009-07-24 E-mail sending only in Editor
115 if (!$result) {
116 break;
117 }
64d616c0 » jakubvrana
2009-09-22 Rename get_dbh to connection
118 $affected += $connection->affected_rows;
38059b61 » jakubvrana
2009-06-30 Remove empty if
119 }
e7eb28d3 » jakubvrana
2008-12-30 CSV import
120 }
78639a98 » jakubvrana
2008-10-01 Function results in edit
121 }
f1153aa3 »
2012-07-27 Display assigned auto_increment after clone
122 $message = lang('%d item(s) have been affected.', $affected);
123 if ($_POST["clone"] && $result && $affected == 1) {
124 $last_id = last_id();
125 if ($last_id) {
126 $message = lang('Item%s has been inserted.', " $last_id");
127 }
128 }
129 queries_redirect(remove_from_uri("page"), $message, $result);
00d9b361 » jakubvrana
2009-07-24 E-mail sending only in Editor
130 //! display edit page in case of an error
e0d9b3c8 » jakubvrana
2010-04-23 In-place editation in select
131 } elseif (!$_POST["import"]) { // modify
5050de57 »
2010-05-07 Display modify hint as title
132 if (!$_POST["val"]) {
133 $error = lang('Double click on a value to modify it.');
134 } else {
135 $result = true;
136 $affected = 0;
137 foreach ($_POST["val"] as $unique_idf => $row) {
138 $set = array();
139 foreach ($row as $key => $val) {
140 $key = bracket_escape($key, 1); // 1 - back
0782a7b2 »
2010-10-17 Save '' instead of NULL for empty char (some drivers don't have varchar)
141 $set[] = idf_escape($key) . " = " . (ereg('char|text', $fields[$key]["type"]) || $val != "" ? $adminer->processInput($fields[$key], $val) : "NULL");
5050de57 »
2010-05-07 Display modify hint as title
142 }
ca27ffc2 »
2010-11-29 Display 0 in SQLite (bug #3120685)
143 $query = table($TABLE) . " SET " . implode(", ", $set);
144 $where2 = " WHERE " . where_check($unique_idf) . ($where ? " AND " . implode(" AND ", $where) : "");
145 $result = queries("UPDATE" . (count($group) < count($select) ? " $query$where2" : limit1($query, $where2))); // can change row on a different page without unique key
5050de57 »
2010-05-07 Display modify hint as title
146 if (!$result) {
147 break;
148 }
149 $affected += $connection->affected_rows;
e0d9b3c8 » jakubvrana
2010-04-23 In-place editation in select
150 }
5050de57 »
2010-05-07 Display modify hint as title
151 queries_redirect(remove_from_uri(), lang('%d item(s) have been affected.', $affected), $result);
e0d9b3c8 » jakubvrana
2010-04-23 In-place editation in select
152 }
25f01d35 » jakubvrana
2009-08-28 Compress export and import
153 } elseif (is_string($file = get_file("csv_file", true))) {
9ff10f83 »
2011-03-07 Parse UTF-16 and UTF-8 BOM in all text uploads
154 //! character set
ead05e68 »
2011-07-13 Remember export and import options
155 cookie("adminer_import", "output=" . urlencode($adminer_import["output"]) . "&format=" . urlencode($_POST["separator"]));
cb370a8a » jakubvrana
2009-08-20 Respect max_allowed_packet in CSV import
156 $result = true;
e8953684 » jakubvrana
2009-08-30 Use ON DUPLICATE KEY UPDATE for CSV import
157 $cols = array_keys($fields);
8a048978 » jakubvrana
2010-02-24 Use atomic group for CSV regexp
158 preg_match_all('~(?>"[^"]*"|[^"\\r\\n]+)+~', $file, $matches);
e8953684 » jakubvrana
2009-08-30 Use ON DUPLICATE KEY UPDATE for CSV import
159 $affected = count($matches[0]);
d0c72eca » jakubvrana
2010-04-23 Driver specific BEGIN
160 begin();
e225d22f »
2010-10-29 TSV export and import (bug #3097657)
161 $separator = ($_POST["separator"] == "csv" ? "," : ($_POST["separator"] == "tsv" ? "\t" : ";"));
00d9b361 » jakubvrana
2009-07-24 E-mail sending only in Editor
162 foreach ($matches[0] as $key => $val) {
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
163 preg_match_all("~((\"[^\"]*\")+|[^$separator]*)$separator~", $val . $separator, $matches2);
e8953684 » jakubvrana
2009-08-30 Use ON DUPLICATE KEY UPDATE for CSV import
164 if (!$key && !array_diff($matches2[1], $cols)) { //! doesn't work with column names containing ",\n
00d9b361 » jakubvrana
2009-07-24 E-mail sending only in Editor
165 // first row corresponds to column names - use it for table structure
e8953684 » jakubvrana
2009-08-30 Use ON DUPLICATE KEY UPDATE for CSV import
166 $cols = $matches2[1];
167 $affected--;
00d9b361 » jakubvrana
2009-07-24 E-mail sending only in Editor
168 } else {
782921b6 »
2010-05-27 Finish SQLite
169 $set = array();
e8953684 » jakubvrana
2009-08-30 Use ON DUPLICATE KEY UPDATE for CSV import
170 foreach ($matches2[1] as $i => $col) {
7e644b43 »
2010-10-13 Save bytes ($connection->quote shortcut)
171 $set[idf_escape($cols[$i])] = ($col == "" && $fields[$cols[$i]]["null"] ? "NULL" : q(str_replace('""', '"', preg_replace('~^"|"$~', '', $col))));
00d9b361 » jakubvrana
2009-07-24 E-mail sending only in Editor
172 }
6e50eb8e »
2010-07-22 Pass primary key to insert_update function
173 $result = insert_update($TABLE, $set, $primary);
e8953684 » jakubvrana
2009-08-30 Use ON DUPLICATE KEY UPDATE for CSV import
174 if (!$result) {
175 break;
cb370a8a » jakubvrana
2009-08-20 Respect max_allowed_packet in CSV import
176 }
177 }
178 }
6ba224be » jakubvrana
2010-02-24 Rollback unsuccessful CSV import
179 if ($result) {
acf7a424 » jakubvrana
2010-04-22 Improve CSV; export
180 queries("COMMIT");
6ba224be » jakubvrana
2010-02-24 Rollback unsuccessful CSV import
181 }
dbdd40a1 » jakubvrana
2009-10-13 Introduce queries_redirect function
182 queries_redirect(remove_from_uri("page"), lang('%d row(s) have been imported.', $affected), $result);
782921b6 »
2010-05-27 Finish SQLite
183 queries("ROLLBACK"); // after queries_redirect() to not overwrite error
00d9b361 » jakubvrana
2009-07-24 E-mail sending only in Editor
184 } else {
185 $error = upload_error($file);
d83b6548 » jakubvrana
2009-04-16 Detect import errors
186 }
ec23248c » jakubvrana
2008-08-16 Exportable select
187 }
116faf2e » jakubvrana
2008-01-08 Mass delete
188 }
c16c57b1 » jakubvrana
2009-07-11 E-mail sending
189
b9ffd64d » jakubvrana
2009-09-08 Remove common prefix in backward key
190 $table_name = $adminer->tableName($table_status);
72b80151 »
2012-08-19 Load more data in select
191 if (is_ajax()) {
364dcfe6 »
2012-08-20 Comment
192 // needs to send headers
72b80151 »
2012-08-19 Load more data in select
193 ob_start('clean_output');
194 }
b9ffd64d » jakubvrana
2009-09-08 Remove common prefix in backward key
195 page_header(lang('Select') . ": $table_name", $error);
116faf2e » jakubvrana
2008-01-08 Mass delete
196
f2ed2379 » jakubvrana
2009-09-20 Display table links above table structure
197 $set = null;
430034c3 » jakubvrana
2007-07-09 Cottage homework
198 if (isset($rights["insert"])) {
98507da3 » jakubvrana
2009-07-30 Function verify_version doesn't use version parameter
199 $set = "";
200 foreach ((array) $_GET["where"] as $val) {
201 if (count($foreign_keys[$val["col"]]) == 1 && ($val["op"] == "="
a1609c79 » jakubvrana
2009-09-25 Align numbers to right in select
202 || (!$val["op"] && !ereg('[_%]', $val["val"])) // LIKE in Editor
98507da3 » jakubvrana
2009-07-30 Function verify_version doesn't use version parameter
203 )) {
204 $set .= "&set" . urlencode("[" . bracket_escape($val["col"]) . "]") . "=" . urlencode($val["val"]);
205 }
206 }
667bfec4 » jakubvrana
2007-07-02 Decomposition
207 }
f2ed2379 » jakubvrana
2009-09-20 Display table links above table structure
208 $adminer->selectLinks($table_status, $set);
667bfec4 » jakubvrana
2007-07-02 Decomposition
209
ffcea8b5 » jakubvrana
2007-07-06 Rights
210 if (!$columns) {
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
211 echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "." : ": " . error()) . "\n";
ffcea8b5 » jakubvrana
2007-07-06 Rights
212 } else {
b68ddcad »
2011-03-21 Send all forms by Ctrl+Enter on <select>
213 echo "<form action='' id='form'>\n";
d24ad780 » jakubvrana
2009-07-27 Select boxes customization
214 echo "<div style='display: none;'>";
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
215 hidden_fields_get();
8878799c »
2010-05-06 Respect namespace
216 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
79d19028 » jakubvrana
2009-08-29 Substitute table name to $TABLE
217 echo '<input type="hidden" name="select" value="' . h($TABLE) . '">';
d24ad780 » jakubvrana
2009-07-27 Select boxes customization
218 echo "</div>\n";
219 $adminer->selectColumnsPrint($select, $columns);
220 $adminer->selectSearchPrint($where, $columns, $indexes);
221 $adminer->selectOrderPrint($order, $columns, $indexes);
222 $adminer->selectLimitPrint($limit);
223 $adminer->selectLengthPrint($text_length);
739bcb09 »
2012-05-16 Warn about selecting data without index
224 $adminer->selectActionPrint($indexes);
ffcea8b5 » jakubvrana
2007-07-06 Rights
225 echo "</form>\n";
226
bd252953 » jakubvrana
2010-04-22 Don't redirect from last page
227 $page = $_GET["page"];
228 if ($page == "last") {
60c7ed9a »
2010-05-11 MS SQL schema support
229 $found_rows = $connection->result("SELECT COUNT(*) FROM " . table($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : ""));
31afb968 »
2010-10-18 Last page with empty result (thanks to Frantisek Svoboda)
230 $page = floor(max(0, $found_rows - 1) / $limit);
bd252953 » jakubvrana
2010-04-22 Don't redirect from last page
231 }
232
700a78b3 »
2012-08-23 selectQueryBuild() method
233 $query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page);
234 if (!$query) {
235 $query = "SELECT" . limit(
236 (+$limit && $group && count($group) < count($select) && $jush == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . $from,
237 ($where ? "\nWHERE " . implode(" AND ", $where) : "") . $group_by,
238 ($limit != "" ? +$limit : null),
239 ($page ? $limit * $page : 0),
240 "\n"
241 );
242 }
c64c4fd1 » jakubvrana
2009-07-27 Adminer class
243 echo $adminer->selectQuery($query);
8b745113 » jakubvrana
2008-09-01 Print SQL query (fixes #2082448)
244
64d616c0 » jakubvrana
2009-09-22 Rename get_dbh to connection
245 $result = $connection->query($query);
21ea4aea » jakubvrana
2007-09-03 Check errors
246 if (!$result) {
c1130ed5 » jakubvrana
2009-12-17 Simplify SQL syntax errors everywhere
247 echo "<p class='error'>" . error() . "\n";
ffcea8b5 » jakubvrana
2007-07-06 Rights
248 } else {
e6726941 »
2010-05-07 Rename $driver to $jush
249 if ($jush == "mssql") {
1b144a12 » jakubvrana
2010-04-23 MS SQL pagination
250 $result->seek($limit * $page);
251 }
f2365d08 » jakubvrana
2009-07-11 Typo
252 $email_fields = array();
b5358536 »
2010-11-12 Full AJAX only with pushState to work correctly with history
253 echo "<form action='' method='post' enctype='multipart/form-data'>\n";
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
254 $rows = array();
255 while ($row = $result->fetch_assoc()) {
6a491373 »
2011-05-24 Pagination support in Oracle (bug #3306828)
256 if ($page && $jush == "oracle") {
257 unset($row["RNUM"]);
258 }
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
259 $rows[] = $row;
260 }
261 // use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest)
1b144a12 » jakubvrana
2010-04-23 MS SQL pagination
262 if ($_GET["page"] != "last") {
04eccbad »
2010-10-22 Allow bigger numbers under 32 bits
263 $found_rows = (+$limit && $group && count($group) < count($select)
e6726941 »
2010-05-07 Rename $driver to $jush
264 ? ($jush == "sql" ? $connection->result(" SELECT FOUND_ROWS()") : $connection->result("SELECT COUNT(*) FROM ($query) x")) // space to allow mysql.trace_mode
1b144a12 » jakubvrana
2010-04-23 MS SQL pagination
265 : count($rows)
266 );
267 }
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
268
269 if (!$rows) {
ace55ed1 » jakubvrana
2009-07-11 HTML instead of XHTML
270 echo "<p class='message'>" . lang('No rows.') . "\n";
21ea4aea » jakubvrana
2007-09-03 Check errors
271 } else {
09e93ded » jakubvrana
2009-09-23 Move backward keys to Editor
272 $backward_keys = $adminer->backwardKeys($TABLE, $table_name);
c42c46a2 » jakubvrana
2009-07-15 Table relations
273
72b80151 »
2012-08-19 Load more data in select
274 echo "<table id='table' cellspacing='0' class='nowrap checkable' onclick='tableClick(event);' onkeydown='return editingKeydown(event);'>\n";
22a7ebd1 »
2010-07-01 Hide edit link without columns
275 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>");
50341236 » jakubvrana
2009-07-23 Apply field name with functions
276 $names = array();
c40d1d0d » jakubvrana
2010-04-26 Always handle double click
277 $functions = array();
50341236 » jakubvrana
2009-07-23 Apply field name with functions
278 reset($select);
9bc9b9fa »
2010-10-24 Don't overwrite variable
279 $rank = 1;
ba90d60b » jakubvrana
2009-07-14 Introduce adminer_select_val
280 foreach ($rows[0] as $key => $val) {
98483e10 »
2012-07-15 SQLite: Better editing in tables without a primary key
281 if ($key != $oid) {
37d81464 »
2011-02-01 Utilize oids in PostgreSQL
282 $val = $_GET["columns"][key($select)];
d2c513d1 »
2011-05-24 Column names customization (bug #3194500)
283 $field = $fields[$select ? ($val ? $val["col"] : current($select)) : $key];
37d81464 »
2011-02-01 Utilize oids in PostgreSQL
284 $name = ($field ? $adminer->fieldName($field, $rank) : "*");
285 if ($name != "") {
286 $rank++;
287 $names[$key] = $name;
1501d60f »
2012-08-08 Descending order after second click on column caption
288 $column = idf_escape($key);
70fb696f »
2012-04-30 Link to descending order
289 $href = remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key);
1501d60f »
2012-08-08 Descending order after second click on column caption
290 $desc = "&desc%5B0%5D=1";
57e5896b »
2012-07-29 Autohide column context menu in select
291 echo '<th onmouseover="columnMouse(this);" onmouseout="columnMouse(this, \' hidden\');">';
1501d60f »
2012-08-08 Descending order after second click on column caption
292 echo '<a href="' . h($href . ($order[0] == $column || $order[0] == $key || (!$order && count($group) < count($select) && $group[0] == $column) ? $desc : '')) . '">'; // $order[0] == $key - COUNT(*)
293 echo (!$select || $val ? apply_sql_function($val["fun"], $name) : h(current($select))) . "</a>"; //! columns looking like functions
57e5896b »
2012-07-29 Autohide column context menu in select
294 echo "<span class='column hidden'>";
1501d60f »
2012-08-08 Descending order after second click on column caption
295 echo "<a href='" . h($href . $desc) . "' title='" . lang('descending') . "' class='text'> ↓</a>";
e2dbb9c7 »
2012-07-29 Links for column search in select
296 if (!$val["fun"]) {
297 echo '<a href="#fieldset-search" onclick="selectSearch(\'' . h(js_escape($key)) . '\'); return false;" title="' . lang('Search') . '" class="text jsonly"> =</a>';
298 }
57e5896b »
2012-07-29 Autohide column context menu in select
299 echo "</span>";
37d81464 »
2011-02-01 Utilize oids in PostgreSQL
300 }
301 $functions[$key] = $val["fun"];
302 next($select);
116c8736 » jakubvrana
2009-07-21 Ignore tables and fields with empty name
303 }
ba90d60b » jakubvrana
2009-07-14 Introduce adminer_select_val
304 }
e0d9b3c8 » jakubvrana
2010-04-23 In-place editation in select
305 $lengths = array();
306 if ($_GET["modify"]) {
307 foreach ($rows as $row) {
308 foreach ($row as $key => $val) {
309 $lengths[$key] = max($lengths[$key], min(40, strlen(utf8_decode($val))));
310 }
311 }
312 }
09e93ded » jakubvrana
2009-09-23 Move backward keys to Editor
313 echo ($backward_keys ? "<th>" . lang('Relations') : "") . "</thead>\n";
72b80151 »
2012-08-19 Load more data in select
314 if (is_ajax()) {
315 if ($limit % 2 == 1 && $page % 2 == 1) {
316 odd();
317 }
318 ob_end_clean();
319 }
dea345cb » jakubvrana
2009-09-09 Substitute foreign keys in e-mail fields
320 foreach ($adminer->rowDescriptions($rows, $foreign_keys) as $n => $row) {
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
321 $unique_array = unique_array($rows[$n], $indexes);
16290b09 » jakubvrana
2010-04-15 Respect where in COUNT(*) link
322 $unique_idf = "";
323 foreach ($unique_array as $key => $val) {
6591d485 »
2012-05-13 Replace isset($var) by $var !== null
324 $unique_idf .= "&" . ($val !== null ? urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($val) : "null%5B%5D=" . urlencode($key));
16290b09 » jakubvrana
2010-04-15 Respect where in COUNT(*) link
325 }
22a7ebd1 »
2010-07-01 Hide edit link without columns
326 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>"));
21ea4aea » jakubvrana
2007-09-03 Check errors
327 foreach ($row as $key => $val) {
78e49f01 » jakubvrana
2009-07-24 Pass $field to select_val
328 if (isset($names[$key])) {
a1609c79 » jakubvrana
2009-09-25 Align numbers to right in select
329 $field = $fields[$key];
7352c281 » jakubvrana
2010-01-09 Replace strlen() by != ""
330 if ($val != "" && (!isset($email_fields[$key]) || $email_fields[$key] != "")) {
1cf374bf »
2010-10-16 Rename functions (avoid conflict with WordPress)
331 $email_fields[$key] = (is_mail($val) ? $names[$key] : ""); //! filled e-mails can be contained on other pages
116c8736 » jakubvrana
2009-07-21 Ignore tables and fields with empty name
332 }
5911cf17 » jakubvrana
2009-07-21 Always call select_val
333 $link = "";
a1609c79 » jakubvrana
2009-09-25 Align numbers to right in select
334 $val = $adminer->editVal($val, $field);
c4a57246 »
2012-05-13 Simplify work with NULL values in select
335 if ($val !== null) {
5a73c012 »
2010-09-28 Treat binary type as hex
336 if (ereg('blob|bytea|raw|file', $field["type"]) && $val != "") {
35ec64c6 » jakubvrana
2010-04-02 Link COUNT(*) result to listing
337 $link = h(ME . 'download=' . urlencode($TABLE) . '&field=' . urlencode($key) . $unique_idf);
97b8c7b6 » jakubvrana
2009-07-24 Display images in Editor
338 }
ca27ffc2 »
2010-11-29 Display 0 in SQLite (bug #3120685)
339 if ($val === "") { // === - may be int
116c8736 » jakubvrana
2009-07-21 Ignore tables and fields with empty name
340 $val = "&nbsp;";
c4a57246 »
2012-05-13 Simplify work with NULL values in select
341 } elseif (is_utf8($val)) {
342 if ($text_length != "" && ereg('text|blob', $field["type"])) {
343 $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
344 } else {
345 $val = h($val);
346 }
21ea4aea » jakubvrana
2007-09-03 Check errors
347 }
116c8736 » jakubvrana
2009-07-21 Ignore tables and fields with empty name
348
db46fc24 » jakubvrana
2009-08-03 Maintain insert prefill value
349 if (!$link) { // link related items
350 foreach ((array) $foreign_keys[$key] as $foreign_key) {
81f58ed9 »
2010-11-03 Link more foreign keys
351 if (count($foreign_keys[$key]) == 1 || end($foreign_key["source"]) == $key) {
352 $link = "";
db46fc24 » jakubvrana
2009-08-03 Maintain insert prefill value
353 foreach ($foreign_key["source"] as $i => $source) {
354 $link .= where_link($i, $foreign_key["target"][$i], $rows[$n][$source]);
355 }
7352c281 » jakubvrana
2010-01-09 Replace strlen() by != ""
356 $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
81f58ed9 »
2010-11-03 Link more foreign keys
357 if (count($foreign_key["source"]) == 1) {
358 break;
359 }
116c8736 » jakubvrana
2009-07-21 Ignore tables and fields with empty name
360 }
21ea4aea » jakubvrana
2007-09-03 Check errors
361 }
ffcea8b5 » jakubvrana
2007-07-06 Rights
362 }
35ec64c6 » jakubvrana
2010-04-02 Link COUNT(*) result to listing
363 if ($key == "COUNT(*)") { //! columns looking like functions
364 $link = h(ME . "select=" . urlencode($TABLE));
365 $i = 0;
16290b09 » jakubvrana
2010-04-15 Respect where in COUNT(*) link
366 foreach ((array) $_GET["where"] as $v) {
367 if (!array_key_exists($v["col"], $unique_array)) {
22eb69b5 »
2010-05-12 Remove operator double encode
368 $link .= h(where_link($i++, $v["col"], $v["val"], $v["op"]));
16290b09 » jakubvrana
2010-04-15 Respect where in COUNT(*) link
369 }
370 }
371 foreach ($unique_array as $k => $v) {
80626485 »
2011-02-08 Use IS NULL operator for null value in where_link function
372 $link .= h(where_link($i++, $k, $v));
35ec64c6 » jakubvrana
2010-04-02 Link COUNT(*) result to listing
373 }
374 }
fa3dd557 » jakubvrana
2007-07-02 Parent
375 }
2cec7584 »
2010-05-25 Direct links from HTTPS to HTTP
376 if (!$link) {
1cf374bf »
2010-10-16 Rename functions (avoid conflict with WordPress)
377 if (is_mail($val)) {
2cec7584 »
2010-05-25 Direct links from HTTPS to HTTP
378 $link = "mailto:$val";
379 }
380 if ($protocol = is_url($row[$key])) {
381 $link = ($protocol == "http" && $HTTPS
382 ? $row[$key] // HTTP links from HTTPS pages don't receive Referer automatically
383 : "$protocol://www.adminer.org/redirect/?url=" . urlencode($row[$key]) // intermediate page to hide Referer, may be changed to rel="noreferrer" in HTML5
384 );
385 }
bc78866a » jakubvrana
2009-10-02 Link URLs in select
386 }
e0d9b3c8 » jakubvrana
2010-04-23 In-place editation in select
387 $id = h("val[$unique_idf][" . bracket_escape($key) . "]");
de24145d »
2010-10-18 Clear POST with AJAX redirect
388 $value = $_POST["val"][$unique_idf][bracket_escape($key)];
6591d485 »
2012-05-13 Replace isset($var) by $var !== null
389 $h_value = h($value !== null ? $value : $row[$key]);
687b3fdd »
2010-05-20 Replace <strong> by <b> and <em> by <i>
390 $long = strpos($val, "<i>...</i>");
390e38b8 »
2010-10-18 Load long texts for inline-edit by AJAX
391 $editable = is_utf8($val) && $rows[$n][$key] == $row[$key] && !$functions[$key];
375a5c8e »
2010-05-26 Non-MySQL binary types
392 $text = ereg('text|lob', $field["type"]);
6591d485 »
2012-05-13 Replace isset($var) by $var !== null
393 echo (($_GET["modify"] && $editable) || $value !== null
7d152fba »
2011-03-21 Utilize bodyKeydown function
394 ? "<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]'>")
390e38b8 »
2010-10-18 Load long texts for inline-edit by AJAX
395 : "<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)
e0d9b3c8 » jakubvrana
2010-04-23 In-place editation in select
396 );
667bfec4 » jakubvrana
2007-07-02 Decomposition
397 }
398 }
33aec2c7 »
2011-01-18 Move <td> from Adminer::backwardKeysPrint
399 if ($backward_keys) {
400 echo "<td>";
401 }
09e93ded » jakubvrana
2009-09-23 Move backward keys to Editor
402 $adminer->backwardKeysPrint($backward_keys, $rows[$n]);
26e8ab97 » jakubvrana
2009-10-30 Close </tr> because of white-space: pre
403 echo "</tr>\n"; // close to allow white-space: pre
5ab708a1 » jakubvrana
2007-07-25 Compact pages
404 }
72b80151 »
2012-08-19 Load more data in select
405 if (is_ajax()) {
406 exit;
407 }
21ea4aea » jakubvrana
2007-09-03 Check errors
408 echo "</table>\n";
023b62a3 »
2011-08-11 Highlight checked rows
409 echo (!$group && $select ? "" : "<script type='text/javascript'>tableCheck();</script>\n");
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
410 }
411
bd252953 » jakubvrana
2010-04-22 Don't redirect from last page
412 if ($rows || $page) {
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
413 $exact_count = true;
04eccbad »
2010-10-22 Allow bigger numbers under 32 bits
414 if ($_GET["page"] != "last" && +$limit && count($group) >= count($select) && ($found_rows >= $limit || $page)) {
c8282994 »
2011-07-29 Fast number of rows with big tables in PostgreSQL (thanks to juzna)
415 $found_rows = found_rows($table_status, $where);
416 if ($found_rows < max(1e4, 2 * ($page + 1) * $limit)) {
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
417 // slow with big tables
ea6d6e0d »
2012-08-19 Simplify slow queries
418 $found_rows = reset(slow_query("SELECT COUNT(*) FROM " . table($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : "")));
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
419 } else {
420 $exact_count = false;
421 }
4cdc4598 » jakubvrana
2009-07-16 FOUND_ROWS works with last SELECT
422 }
fde11717 » jakubvrana
2009-10-28 Add CSS classes (thanks to cvicebni ubor)
423 echo "<p class='pages'>";
6a7021db »
2012-08-19 Time out long running select count
424 if (+$limit && ($found_rows === false || $found_rows > $limit)) {
bd252953 » jakubvrana
2010-04-22 Don't redirect from last page
425 // display first, previous 4, next 4 and last page
6a7021db »
2012-08-19 Time out long running select count
426 $max_page = ($found_rows === false
427 ? $page + (count($rows) >= $limit ? 2 : 1)
428 : floor(($found_rows - 1) / $limit)
429 );
9802869d »
2010-11-12 Merge from master
430 echo '<a href="' . h(remove_from_uri("page")) . "\" onclick=\"pageClick(this.href, +prompt('" . lang('Page') . "', '" . ($page + 1) . "'), event); return false;\">" . lang('Page') . "</a>:";
6e3c7cba »
2010-10-18 Use AJAX for pagination
431 echo pagination(0, $page) . ($page > 5 ? " ..." : "");
bd252953 » jakubvrana
2010-04-22 Don't redirect from last page
432 for ($i = max(1, $page - 4); $i < min($max_page, $page + 5); $i++) {
433 echo pagination($i, $page);
21ea4aea » jakubvrana
2007-09-03 Check errors
434 }
fc689f59 »
2012-08-19 Fix last page link
435 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>");
5ab708a1 » jakubvrana
2007-07-25 Compact pages
436 }
68211ac4 »
2012-08-20 Don't display Load more data on last page
437 echo ($found_rows !== false ? " (" . ($exact_count ? "" : "~ ") . lang('%d row(s)', $found_rows) . ")" : "");
438 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>' : '');
439 echo " " . checkbox("all", 1, 0, lang('whole result')) . "\n";
8b745113 » jakubvrana
2008-09-01 Print SQL query (fixes #2082448)
440
e641e5ce »
2011-05-24 Limit commands and import in customization (bug #3194432)
441 if ($adminer->selectCommandPrint()) {
e0d9b3c8 » jakubvrana
2010-04-23 In-place editation in select
442 ?>
443 <fieldset><legend><?php echo lang('Edit'); ?></legend><div>
db2ac19b »
2011-08-10 Save is available without JS
444 <input type="submit" value="<?php echo lang('Save'); ?>"<?php echo ($_GET["modify"] ? '' : ' title="' . lang('Double click on a value to modify it.') . '" class="jsonly"'); ?>>
38894b29 »
2010-11-23 Send all forms by AJAX
445 <input type="submit" name="edit" value="<?php echo lang('Edit'); ?>">
446 <input type="submit" name="clone" value="<?php echo lang('Clone'); ?>">
447 <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/)) + ')');">
e0d9b3c8 » jakubvrana
2010-04-23 In-place editation in select
448 </div></fieldset>
449 <?php
450 }
1e70b74f »
2011-12-21 Ability to disable export
451 $format = $adminer->dumpFormat();
452 if ($format) {
453 print_fieldset("export", lang('Export'));
454 $output = $adminer->dumpOutput();
455 echo ($output ? html_select("output", $output, $adminer_import["output"]) . " " : "");
456 echo html_select("format", $format, $adminer_import["format"]);
f498219f »
2012-05-14 Remove eventStop() used by AJAXification in past
457 echo " <input type='submit' name='export' value='" . lang('Export') . "'>\n";
1e70b74f »
2011-12-21 Ability to disable export
458 echo "</div></fieldset>\n";
459 }
667bfec4 » jakubvrana
2007-07-02 Decomposition
460 }
e641e5ce »
2011-05-24 Limit commands and import in customization (bug #3194432)
461 if ($adminer->selectImportPrint()) {
462 print_fieldset("import", lang('Import'), !$rows);
463 echo "<input type='file' name='csv_file'> ";
ead05e68 »
2011-07-13 Remember export and import options
464 echo html_select("separator", array("csv" => "CSV,", "csv;" => "CSV;", "tsv" => "TSV"), $adminer_import["format"], 1); // 1 - select
e641e5ce »
2011-05-24 Limit commands and import in customization (bug #3194432)
465 echo " <input type='submit' name='import' value='" . lang('Import') . "'>";
466 echo "<input type='hidden' name='token' value='$token'>\n";
467 echo "</div></fieldset>\n";
468 }
c16c57b1 » jakubvrana
2009-07-11 E-mail sending
469
1e55d475 » jakubvrana
2009-09-09 User interface for e-mail {$name}
470 $adminer->selectEmailPrint(array_filter($email_fields, 'strlen'), $columns);
c16c57b1 » jakubvrana
2009-07-11 E-mail sending
471
e7eb28d3 » jakubvrana
2008-12-30 CSV import
472 echo "</form>\n";
667bfec4 » jakubvrana
2007-07-02 Decomposition
473 }
474 }
72b80151 »
2012-08-19 Load more data in select
475
476 if (is_ajax()) {
477 exit;
478 }
Something went wrong with that request. Please try again.