Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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