Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 408 lines (390 sloc) 18.407 kb
667bfec4 »
2007-07-02 Decomposition
1 <?php
79d19028 »
2009-08-29 Substitute table name to $TABLE
2 $TABLE = $_GET["select"];
3 $table_status = table_status($TABLE);
4 $indexes = indexes($TABLE);
4c2268d3 »
2010-05-21 PostgreSQL hidden columns support
5 $fields = fields($TABLE, 1); // 1 - hidden
dea345cb »
2009-09-09 Substitute foreign keys in e-mail fields
6 $foreign_keys = column_foreign_keys($TABLE);
7
64ba9242 »
2009-06-21 Comments
8 $rights = array(); // privilege => 0
9 $columns = array(); // selectable columns
0115315a »
2010-04-22 Init with null
10 $text_length = null;
ffcea8b5 »
2007-07-06 Rights
11 foreach ($fields as $key => $field) {
c64c4fd1 »
2009-07-27 Adminer class
12 $name = $adminer->fieldName($field);
7352c281 »
2010-01-09 Replace strlen() by != ""
13 if (isset($field["privileges"]["select"]) && $name != "") {
1e4d11e9 »
2009-07-23 Select from foreign keys in Editor
14 $columns[$key] = html_entity_decode(strip_tags($name));
375a5c8e »
2010-05-26 Non-MySQL binary types
15 if (ereg('text|lob', $field["type"])) {
d24ad780 »
2009-07-27 Select boxes customization
16 $text_length = $adminer->selectLengthProcess();
16c4ddb4 »
2009-07-13 Single faster POST query with primary key
17 }
ffcea8b5 »
2007-07-06 Rights
18 }
430034c3 »
2007-07-09 Cottage homework
19 $rights += $field["privileges"];
20 }
21
d24ad780 »
2009-07-27 Select boxes customization
22 list($select, $group) = $adminer->selectColumnsProcess($columns, $indexes);
07e1ae10 »
2009-07-28 FOUND_ROWS only with GROUP BY
23 $where = $adminer->selectSearchProcess($fields, $indexes);
24 $order = $adminer->selectOrderProcess($fields, $indexes);
d24ad780 »
2009-07-27 Select boxes customization
25 $limit = $adminer->selectLimitProcess();
ee3e0459 »
2010-05-14 Separate $where in limit function
26 $from = ($select ? implode(", ", $select) : "*") . "\nFROM " . table($TABLE);
e44fbc2e »
2010-03-11 Wrap SQL query
27 $group_by = ($group && count($group) < count($select) ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : "");
116faf2e »
2008-01-08 Mass delete
28
29 if ($_POST && !$error) {
56948c93 »
2009-07-16 $_POST[check] may be empty
30 $where_check = "(" . implode(") OR (", array_map('where_check', (array) $_POST["check"])) . ")";
6e50eb8e »
2010-07-22 Pass primary key to insert_update function
31 $primary = $unselected = null;
2ad8ab47 »
2010-07-22 Primary key detection for other drivers
32 foreach ($indexes as $index) {
33 if ($index["type"] == "PRIMARY") {
6e50eb8e »
2010-07-22 Pass primary key to insert_update function
34 $primary = array_flip($index["columns"]);
35 $unselected = ($select ? $primary : array());
2ad8ab47 »
2010-07-22 Primary key detection for other drivers
36 break;
37 }
38 }
d24ad780 »
2009-07-27 Select boxes customization
39 foreach ($select as $key => $val) {
40 $val = $_GET["columns"][$key];
41 if (!$val["fun"]) {
6e50eb8e »
2010-07-22 Pass primary key to insert_update function
42 unset($unselected[$val["col"]]);
d24ad780 »
2009-07-27 Select boxes customization
43 }
44 }
78639a98 »
2008-10-01 Function results in edit
45 if ($_POST["export"]) {
095d4723 »
2010-10-29 Customizable export
46 $adminer->dumpHeaders($TABLE);
47 $adminer->dumpTable($TABLE, "");
e225d22f »
2010-10-29 TSV export and import (bug #3097657)
48 if (ereg("csv|tsv", $_POST["format"])) {
b79ef09b »
2009-11-30 Don't dump backticks in CSV column names
49 $row = array_keys($fields);
50 if ($select) {
51 $row = array();
52 foreach ($select as $val) {
3f5b6834 »
2010-04-21 Reintegrate sqlite branch
53 $row[] = (ereg('^`.*`$', $val) ? idf_unescape($val) : $val); //! columns looking like functions
b79ef09b »
2009-11-30 Don't dump backticks in CSV column names
54 }
55 }
56 dump_csv($row);
e4f5d17e »
2009-08-25 Dump column names in CSV select export
57 }
6e50eb8e »
2010-07-22 Pass primary key to insert_update function
58 if (!is_array($_POST["check"]) || $unselected === array()) {
ee3e0459 »
2010-05-14 Separate $where in limit function
59 $where2 = $where;
60 if (is_array($_POST["check"])) {
61 $where2[] = "($where_check)";
62 }
095d4723 »
2010-10-29 Customizable export
63 $adminer->dumpData($TABLE, "INSERT", "SELECT $from" . ($where2 ? "\nWHERE " . implode(" AND ", $where2) : "") . $group_by);
16c4ddb4 »
2009-07-13 Single faster POST query with primary key
64 } else {
fa5c952a »
2009-06-15 Use extended INSERT in select export
65 $union = array();
f7452add »
2009-04-01 Import and export
66 foreach ($_POST["check"] as $val) {
16c4ddb4 »
2009-07-13 Single faster POST query with primary key
67 // where is not unique so OR can't be used
ee3e0459 »
2010-05-14 Separate $where in limit function
68 $union[] = "(SELECT" . limit($from, "\nWHERE " . ($where ? implode(" AND ", $where) . " AND " : "") . where_check($val) . $group_by, 1) . ")";
116faf2e »
2008-01-08 Mass delete
69 }
095d4723 »
2010-10-29 Customizable export
70 $adminer->dumpData($TABLE, "INSERT", implode(" UNION ALL ", $union));
116faf2e »
2008-01-08 Mass delete
71 }
78639a98 »
2008-10-01 Function results in edit
72 exit;
73 }
dea345cb »
2009-09-09 Substitute foreign keys in e-mail fields
74 if (!$adminer->selectEmailProcess($where, $foreign_keys)) {
d90bde5b »
2010-04-27 Fix delete in select
75 if ($_POST["save"] || $_POST["delete"]) { // edit
00d9b361 »
2009-07-24 E-mail sending only in Editor
76 $result = true;
77 $affected = 0;
60c7ed9a »
2010-05-11 MS SQL schema support
78 $query = table($TABLE);
28b2b8db »
2009-07-30 Readable variable initialization
79 $set = array();
00d9b361 »
2009-07-24 E-mail sending only in Editor
80 if (!$_POST["delete"]) {
81 foreach ($columns as $name => $val) { //! should check also for edit or insert privileges
a0def479 »
2009-07-27 Date localization
82 $val = process_input($fields[$name]);
3f5b6834 »
2010-04-21 Reintegrate sqlite branch
83 if ($val !== null) {
84 if ($_POST["clone"]) {
85 $set[idf_escape($name)] = ($val !== false ? $val : idf_escape($name));
86 } elseif ($val !== false) {
87 $set[] = idf_escape($name) . " = $val";
88 }
00d9b361 »
2009-07-24 E-mail sending only in Editor
89 }
e7eb28d3 »
2008-12-30 CSV import
90 }
60c7ed9a »
2010-05-11 MS SQL schema support
91 $query .= ($_POST["clone"] ? " (" . implode(", ", array_keys($set)) . ")\nSELECT " . implode(", ", $set) . "\nFROM " . table($TABLE) : " SET\n" . implode(",\n", $set));
e7eb28d3 »
2008-12-30 CSV import
92 }
00d9b361 »
2009-07-24 E-mail sending only in Editor
93 if ($_POST["delete"] || $set) {
3f5b6834 »
2010-04-21 Reintegrate sqlite branch
94 $command = "UPDATE";
95 if ($_POST["delete"]) {
96 $command = "DELETE";
97 $query = "FROM $query";
98 }
99 if ($_POST["clone"]) {
100 $command = "INSERT";
101 $query = "INTO $query";
102 }
6e50eb8e »
2010-07-22 Pass primary key to insert_update function
103 if ($_POST["all"] || ($unselected === array() && $_POST["check"]) || count($group) < count($select)) {
3f5b6834 »
2010-04-21 Reintegrate sqlite branch
104 $result = queries($command . " $query" . ($_POST["all"] ? ($where ? "\nWHERE " . implode(" AND ", $where) : "") : "\nWHERE $where_check"));
64d616c0 »
2009-09-22 Rename get_dbh to connection
105 $affected = $connection->affected_rows;
00d9b361 »
2009-07-24 E-mail sending only in Editor
106 } else {
107 foreach ((array) $_POST["check"] as $val) {
108 // where is not unique so OR can't be used
ee3e0459 »
2010-05-14 Separate $where in limit function
109 $result = queries($command . limit1($query, "\nWHERE " . where_check($val)));
00d9b361 »
2009-07-24 E-mail sending only in Editor
110 if (!$result) {
111 break;
112 }
64d616c0 »
2009-09-22 Rename get_dbh to connection
113 $affected += $connection->affected_rows;
38059b61 »
2009-06-30 Remove empty if
114 }
e7eb28d3 »
2008-12-30 CSV import
115 }
78639a98 »
2008-10-01 Function results in edit
116 }
dbdd40a1 »
2009-10-13 Introduce queries_redirect function
117 queries_redirect(remove_from_uri("page"), lang('%d item(s) have been affected.', $affected), $result);
00d9b361 »
2009-07-24 E-mail sending only in Editor
118 //! display edit page in case of an error
e0d9b3c8 »
2010-04-23 In-place editation in select
119 } elseif (!$_POST["import"]) { // modify
5050de57 »
2010-05-07 Display modify hint as title
120 if (!$_POST["val"]) {
121 $error = lang('Double click on a value to modify it.');
122 } else {
123 $result = true;
124 $affected = 0;
125 foreach ($_POST["val"] as $unique_idf => $row) {
126 $set = array();
127 foreach ($row as $key => $val) {
128 $key = bracket_escape($key, 1); // 1 - back
0782a7b2 »
2010-10-17 Save '' instead of NULL for empty char (some drivers don't have varchar)
129 $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
130 }
ee3e0459 »
2010-05-14 Separate $where in limit function
131 $result = queries("UPDATE" . limit1(table($TABLE) . " SET " . implode(", ", $set), " WHERE " . where_check($unique_idf) . ($where ? " AND " . implode(" AND ", $where) : ""))); // can change row on a different page without unique key
5050de57 »
2010-05-07 Display modify hint as title
132 if (!$result) {
133 break;
134 }
135 $affected += $connection->affected_rows;
e0d9b3c8 »
2010-04-23 In-place editation in select
136 }
5050de57 »
2010-05-07 Display modify hint as title
137 queries_redirect(remove_from_uri(), lang('%d item(s) have been affected.', $affected), $result);
e0d9b3c8 »
2010-04-23 In-place editation in select
138 }
25f01d35 »
2009-08-28 Compress export and import
139 } elseif (is_string($file = get_file("csv_file", true))) {
00d9b361 »
2009-07-24 E-mail sending only in Editor
140 $file = preg_replace("~^\xEF\xBB\xBF~", '', $file); //! character set
cb370a8a »
2009-08-20 Respect max_allowed_packet in CSV import
141 $result = true;
e8953684 »
2009-08-30 Use ON DUPLICATE KEY UPDATE for CSV import
142 $cols = array_keys($fields);
8a048978 »
2010-02-24 Use atomic group for CSV regexp
143 preg_match_all('~(?>"[^"]*"|[^"\\r\\n]+)+~', $file, $matches);
e8953684 »
2009-08-30 Use ON DUPLICATE KEY UPDATE for CSV import
144 $affected = count($matches[0]);
d0c72eca »
2010-04-23 Driver specific BEGIN
145 begin();
e225d22f »
2010-10-29 TSV export and import (bug #3097657)
146 $separator = ($_POST["separator"] == "csv" ? "," : ($_POST["separator"] == "tsv" ? "\t" : ";"));
00d9b361 »
2009-07-24 E-mail sending only in Editor
147 foreach ($matches[0] as $key => $val) {
3f5b6834 »
2010-04-21 Reintegrate sqlite branch
148 preg_match_all("~((\"[^\"]*\")+|[^$separator]*)$separator~", $val . $separator, $matches2);
e8953684 »
2009-08-30 Use ON DUPLICATE KEY UPDATE for CSV import
149 if (!$key && !array_diff($matches2[1], $cols)) { //! doesn't work with column names containing ",\n
00d9b361 »
2009-07-24 E-mail sending only in Editor
150 // first row corresponds to column names - use it for table structure
e8953684 »
2009-08-30 Use ON DUPLICATE KEY UPDATE for CSV import
151 $cols = $matches2[1];
152 $affected--;
00d9b361 »
2009-07-24 E-mail sending only in Editor
153 } else {
782921b6 »
2010-05-27 Finish SQLite
154 $set = array();
e8953684 »
2009-08-30 Use ON DUPLICATE KEY UPDATE for CSV import
155 foreach ($matches2[1] as $i => $col) {
7e644b43 »
2010-10-13 Save bytes ($connection->quote shortcut)
156 $set[idf_escape($cols[$i])] = ($col == "" && $fields[$cols[$i]]["null"] ? "NULL" : q(str_replace('""', '"', preg_replace('~^"|"$~', '', $col))));
00d9b361 »
2009-07-24 E-mail sending only in Editor
157 }
6e50eb8e »
2010-07-22 Pass primary key to insert_update function
158 $result = insert_update($TABLE, $set, $primary);
e8953684 »
2009-08-30 Use ON DUPLICATE KEY UPDATE for CSV import
159 if (!$result) {
160 break;
cb370a8a »
2009-08-20 Respect max_allowed_packet in CSV import
161 }
162 }
163 }
6ba224be »
2010-02-24 Rollback unsuccessful CSV import
164 if ($result) {
acf7a424 »
2010-04-22 Improve CSV; export
165 queries("COMMIT");
6ba224be »
2010-02-24 Rollback unsuccessful CSV import
166 }
dbdd40a1 »
2009-10-13 Introduce queries_redirect function
167 queries_redirect(remove_from_uri("page"), lang('%d row(s) have been imported.', $affected), $result);
782921b6 »
2010-05-27 Finish SQLite
168 queries("ROLLBACK"); // after queries_redirect() to not overwrite error
00d9b361 »
2009-07-24 E-mail sending only in Editor
169 } else {
170 $error = upload_error($file);
d83b6548 »
2009-04-16 Detect import errors
171 }
ec23248c »
2008-08-16 Exportable select
172 }
116faf2e »
2008-01-08 Mass delete
173 }
c16c57b1 »
2009-07-11 E-mail sending
174
b9ffd64d »
2009-09-08 Remove common prefix in backward key
175 $table_name = $adminer->tableName($table_status);
176 page_header(lang('Select') . ": $table_name", $error);
e0d9b3c8 »
2010-04-23 In-place editation in select
177 session_write_close();
116faf2e »
2008-01-08 Mass delete
178
f2ed2379 »
2009-09-20 Display table links above table structure
179 $set = null;
430034c3 »
2007-07-09 Cottage homework
180 if (isset($rights["insert"])) {
98507da3 »
2009-07-30 Function verify_version doesn't use version parameter
181 $set = "";
182 foreach ((array) $_GET["where"] as $val) {
183 if (count($foreign_keys[$val["col"]]) == 1 && ($val["op"] == "="
a1609c79 »
2009-09-25 Align numbers to right in select
184 || (!$val["op"] && !ereg('[_%]', $val["val"])) // LIKE in Editor
98507da3 »
2009-07-30 Function verify_version doesn't use version parameter
185 )) {
186 $set .= "&set" . urlencode("[" . bracket_escape($val["col"]) . "]") . "=" . urlencode($val["val"]);
187 }
188 }
667bfec4 »
2007-07-02 Decomposition
189 }
f2ed2379 »
2009-09-20 Display table links above table structure
190 $adminer->selectLinks($table_status, $set);
667bfec4 »
2007-07-02 Decomposition
191
ffcea8b5 »
2007-07-06 Rights
192 if (!$columns) {
3f5b6834 »
2010-04-21 Reintegrate sqlite branch
193 echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "." : ": " . error()) . "\n";
ffcea8b5 »
2007-07-06 Rights
194 } else {
5ee29cb0 »
2008-08-07 Select columns, aggregation
195 echo "<form action='' id='form'>\n";
d24ad780 »
2009-07-27 Select boxes customization
196 echo "<div style='display: none;'>";
3f5b6834 »
2010-04-21 Reintegrate sqlite branch
197 hidden_fields_get();
8878799c »
2010-05-06 Respect namespace
198 echo (DB != "" ? '<input type="hidden" name="db" value="' . h(DB) . '">' . (isset($_GET["ns"]) ? '<input type="hidden" name="ns" value="' . h($_GET["ns"]) . '">' : "") : ""); // not used in Editor
79d19028 »
2009-08-29 Substitute table name to $TABLE
199 echo '<input type="hidden" name="select" value="' . h($TABLE) . '">';
d24ad780 »
2009-07-27 Select boxes customization
200 echo "</div>\n";
201 $adminer->selectColumnsPrint($select, $columns);
202 $adminer->selectSearchPrint($where, $columns, $indexes);
203 $adminer->selectOrderPrint($order, $columns, $indexes);
204 $adminer->selectLimitPrint($limit);
205 $adminer->selectLengthPrint($text_length);
206 $adminer->selectActionPrint($text_length);
ffcea8b5 »
2007-07-06 Rights
207 echo "</form>\n";
208
bd252953 »
2010-04-22 Don't redirect from last page
209 $page = $_GET["page"];
210 if ($page == "last") {
60c7ed9a »
2010-05-11 MS SQL schema support
211 $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)
212 $page = floor(max(0, $found_rows - 1) / $limit);
bd252953 »
2010-04-22 Don't redirect from last page
213 }
214
04eccbad »
2010-10-22 Allow bigger numbers under 32 bits
215 $query = "SELECT" . limit((+$limit && $group && count($group) < count($select) && $jush == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . $from, ($where ? "\nWHERE " . implode(" AND ", $where) : "") . $group_by, ($limit != "" ? +$limit : null), ($page ? $limit * $page : 0), "\n");
c64c4fd1 »
2009-07-27 Adminer class
216 echo $adminer->selectQuery($query);
8b745113 »
2008-09-01 Print SQL query (fixes #2082448)
217
64d616c0 »
2009-09-22 Rename get_dbh to connection
218 $result = $connection->query($query);
21ea4aea »
2007-09-03 Check errors
219 if (!$result) {
c1130ed5 »
2009-12-17 Simplify SQL syntax errors everywhere
220 echo "<p class='error'>" . error() . "\n";
ffcea8b5 »
2007-07-06 Rights
221 } else {
e6726941 »
2010-05-07 Rename $driver to $jush
222 if ($jush == "mssql") {
1b144a12 »
2010-04-23 MS SQL pagination
223 $result->seek($limit * $page);
224 }
f2365d08 »
2009-07-11 Typo
225 $email_fields = array();
e7eb28d3 »
2008-12-30 CSV import
226 echo "<form action='' method='post' enctype='multipart/form-data'>\n";
3f5b6834 »
2010-04-21 Reintegrate sqlite branch
227 $rows = array();
228 while ($row = $result->fetch_assoc()) {
229 $rows[] = $row;
230 }
231 // use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest)
1b144a12 »
2010-04-23 MS SQL pagination
232 if ($_GET["page"] != "last") {
04eccbad »
2010-10-22 Allow bigger numbers under 32 bits
233 $found_rows = (+$limit && $group && count($group) < count($select)
e6726941 »
2010-05-07 Rename $driver to $jush
234 ? ($jush == "sql" ? $connection->result(" SELECT FOUND_ROWS()") : $connection->result("SELECT COUNT(*) FROM ($query) x")) // space to allow mysql.trace_mode
1b144a12 »
2010-04-23 MS SQL pagination
235 : count($rows)
236 );
237 }
3f5b6834 »
2010-04-21 Reintegrate sqlite branch
238
239 if (!$rows) {
ace55ed1 »
2009-07-11 HTML instead of XHTML
240 echo "<p class='message'>" . lang('No rows.') . "\n";
21ea4aea »
2007-09-03 Check errors
241 } else {
09e93ded »
2009-09-23 Move backward keys to Editor
242 $backward_keys = $adminer->backwardKeys($TABLE, $table_name);
c42c46a2 »
2009-07-15 Table relations
243
3c5c0f01 »
2009-12-17 Use camelCase in JavaScript
244 echo "<table cellspacing='0' class='nowrap' onclick='tableClick(event);'>\n";
22a7ebd1 »
2010-07-01 Hide edit link without columns
245 echo "<thead><tr>" . (!$group && $select ? "" : "<td><input type='checkbox' id='all-page' onclick='formCheck(this, /check/);'> <a href='" . h($_GET["modify"] ? remove_from_uri("modify") : $_SERVER["REQUEST_URI"] . "&modify=1") . "'>" . lang('edit') . "</a>");
50341236 »
2009-07-23 Apply field name with functions
246 $names = array();
c40d1d0d »
2010-04-26 Always handle double click
247 $functions = array();
50341236 »
2009-07-23 Apply field name with functions
248 reset($select);
9bc9b9fa »
2010-10-24 Don't overwrite variable
249 $rank = 1;
ba90d60b »
2009-07-14 Introduce adminer_select_val
250 foreach ($rows[0] as $key => $val) {
50341236 »
2009-07-23 Apply field name with functions
251 $val = $_GET["columns"][key($select)];
ba9c9a52 »
2009-07-24 Display SQL function with braces in select heading
252 $field = $fields[$select ? $val["col"] : $key];
9bc9b9fa »
2010-10-24 Don't overwrite variable
253 $name = ($field ? $adminer->fieldName($field, $rank) : "*");
7352c281 »
2010-01-09 Replace strlen() by != ""
254 if ($name != "") {
9bc9b9fa »
2010-10-24 Don't overwrite variable
255 $rank++;
50341236 »
2009-07-23 Apply field name with functions
256 $names[$key] = $name;
b05684a5 »
2010-10-24 Order by DESC with grouping
257 $column = idf_escape($key);
258 echo '<th><a href="' . h(remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key) . ($order[0] == $column || $order[0] == $key || (!$order && $group[0] == $column) ? '&desc%5B0%5D=1' : '')) . '">' . apply_sql_function($val["fun"], $name) . "</a>"; // $order[0] == $key - COUNT(*) //! columns looking like functions
116c8736 »
2009-07-21 Ignore tables and fields with empty name
259 }
c40d1d0d »
2010-04-26 Always handle double click
260 $functions[$key] = $val["fun"];
50341236 »
2009-07-23 Apply field name with functions
261 next($select);
ba90d60b »
2009-07-14 Introduce adminer_select_val
262 }
e0d9b3c8 »
2010-04-23 In-place editation in select
263 $lengths = array();
264 if ($_GET["modify"]) {
265 foreach ($rows as $row) {
266 foreach ($row as $key => $val) {
267 $lengths[$key] = max($lengths[$key], min(40, strlen(utf8_decode($val))));
268 }
269 }
270 }
09e93ded »
2009-09-23 Move backward keys to Editor
271 echo ($backward_keys ? "<th>" . lang('Relations') : "") . "</thead>\n";
dea345cb »
2009-09-09 Substitute foreign keys in e-mail fields
272 foreach ($adminer->rowDescriptions($rows, $foreign_keys) as $n => $row) {
3f5b6834 »
2010-04-21 Reintegrate sqlite branch
273 $unique_array = unique_array($rows[$n], $indexes);
16290b09 »
2010-04-15 Respect where in COUNT(*) link
274 $unique_idf = "";
275 foreach ($unique_array as $key => $val) {
276 $unique_idf .= "&" . (isset($val) ? urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($val) : "null%5B%5D=" . urlencode($key));
277 }
22a7ebd1 »
2010-07-01 Hide edit link without columns
278 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 »
2007-09-03 Check errors
279 foreach ($row as $key => $val) {
78e49f01 »
2009-07-24 Pass $field to select_val
280 if (isset($names[$key])) {
a1609c79 »
2009-09-25 Align numbers to right in select
281 $field = $fields[$key];
7352c281 »
2010-01-09 Replace strlen() by != ""
282 if ($val != "" && (!isset($email_fields[$key]) || $email_fields[$key] != "")) {
1cf374bf »
2010-10-16 Rename functions (avoid conflict with WordPress)
283 $email_fields[$key] = (is_mail($val) ? $names[$key] : ""); //! filled e-mails can be contained on other pages
116c8736 »
2009-07-21 Ignore tables and fields with empty name
284 }
5911cf17 »
2009-07-21 Always call select_val
285 $link = "";
a1609c79 »
2009-09-25 Align numbers to right in select
286 $val = $adminer->editVal($val, $field);
116c8736 »
2009-07-21 Ignore tables and fields with empty name
287 if (!isset($val)) {
288 $val = "<i>NULL</i>";
21ea4aea »
2007-09-03 Check errors
289 } else {
5a73c012 »
2010-09-28 Treat binary type as hex
290 if (ereg('blob|bytea|raw|file', $field["type"]) && $val != "") {
35ec64c6 »
2010-04-02 Link COUNT(*) result to listing
291 $link = h(ME . 'download=' . urlencode($TABLE) . '&field=' . urlencode($key) . $unique_idf);
97b8c7b6 »
2009-07-24 Display images in Editor
292 }
7352c281 »
2010-01-09 Replace strlen() by != ""
293 if ($val == "") {
116c8736 »
2009-07-21 Ignore tables and fields with empty name
294 $val = "&nbsp;";
7352c281 »
2010-01-09 Replace strlen() by != ""
295 } elseif ($text_length != "" && ereg('text|blob', $field["type"]) && is_utf8($val)) {
04eccbad »
2010-10-22 Allow bigger numbers under 32 bits
296 $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
116c8736 »
2009-07-21 Ignore tables and fields with empty name
297 } else {
50881f89 »
2009-10-13 Move whitespace to CSS
298 $val = h($val);
21ea4aea »
2007-09-03 Check errors
299 }
116c8736 »
2009-07-21 Ignore tables and fields with empty name
300
db46fc24 »
2009-08-03 Maintain insert prefill value
301 if (!$link) { // link related items
302 foreach ((array) $foreign_keys[$key] as $foreign_key) {
303 if (count($foreign_keys[$key]) == 1 || count($foreign_key["source"]) == 1) {
304 foreach ($foreign_key["source"] as $i => $source) {
305 $link .= where_link($i, $foreign_key["target"][$i], $rows[$n][$source]);
306 }
7352c281 »
2010-01-09 Replace strlen() by != ""
307 $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
db46fc24 »
2009-08-03 Maintain insert prefill value
308 break;
116c8736 »
2009-07-21 Ignore tables and fields with empty name
309 }
21ea4aea »
2007-09-03 Check errors
310 }
ffcea8b5 »
2007-07-06 Rights
311 }
35ec64c6 »
2010-04-02 Link COUNT(*) result to listing
312 if ($key == "COUNT(*)") { //! columns looking like functions
313 $link = h(ME . "select=" . urlencode($TABLE));
314 $i = 0;
16290b09 »
2010-04-15 Respect where in COUNT(*) link
315 foreach ((array) $_GET["where"] as $v) {
316 if (!array_key_exists($v["col"], $unique_array)) {
22eb69b5 »
2010-05-12 Remove operator double encode
317 $link .= h(where_link($i++, $v["col"], $v["val"], $v["op"]));
16290b09 »
2010-04-15 Respect where in COUNT(*) link
318 }
319 }
320 foreach ($unique_array as $k => $v) {
186c0589 »
2010-04-15 Utilize where_link function
321 $link .= h(where_link($i++, $k, $v, (isset($v) ? "=" : "IS NULL")));
35ec64c6 »
2010-04-02 Link COUNT(*) result to listing
322 }
323 }
fa3dd557 »
2007-07-02 Parent
324 }
2cec7584 »
2010-05-25 Direct links from HTTPS to HTTP
325 if (!$link) {
1cf374bf »
2010-10-16 Rename functions (avoid conflict with WordPress)
326 if (is_mail($val)) {
2cec7584 »
2010-05-25 Direct links from HTTPS to HTTP
327 $link = "mailto:$val";
328 }
329 if ($protocol = is_url($row[$key])) {
330 $link = ($protocol == "http" && $HTTPS
331 ? $row[$key] // HTTP links from HTTPS pages don't receive Referer automatically
332 : "$protocol://www.adminer.org/redirect/?url=" . urlencode($row[$key]) // intermediate page to hide Referer, may be changed to rel="noreferrer" in HTML5
333 );
334 }
bc78866a »
2009-10-02 Link URLs in select
335 }
e0d9b3c8 »
2010-04-23 In-place editation in select
336 $id = h("val[$unique_idf][" . bracket_escape($key) . "]");
337 $value = $_POST["val"][$unique_idf][bracket_escape($key)];
338 $h_value = h(isset($value) ? $value : $row[$key]);
687b3fdd »
2010-05-20 Replace <strong> by <b> and <em> by <i>
339 $long = strpos($val, "<i>...</i>");
c40d1d0d »
2010-04-26 Always handle double click
340 $editable = is_utf8($val) && !$long && $rows[$n][$key] == $row[$key] && !$functions[$key];
375a5c8e »
2010-05-26 Non-MySQL binary types
341 $text = ereg('text|lob', $field["type"]);
e0d9b3c8 »
2010-04-23 In-place editation in select
342 echo (($_GET["modify"] && $editable) || isset($value)
644c355d »
2010-10-17 Send the form by Ctrl+Enter in all textareas
343 ? "<td>" . ($text ? "<textarea name='$id' cols='30' rows='" . (substr_count($row[$key], "\n") + 1) . "' onkeydown='return textareaKeydown(this, event);'>$h_value</textarea>" : "<input name='$id' value='$h_value' size='$lengths[$key]'>")
210802d1 »
2010-10-17 Change message to "increase Text length"
344 : "<td id='$id' ondblclick=\"" . ($editable ? "selectDblClick(this, event" . ($text ? ", 1" : "") . ")" : "alert('" . h($long ? lang('Increase Text length to modify this value.') : lang('Use edit link to modify this value.')) . "')") . ";\">" . $adminer->selectVal($val, $link, $field)
e0d9b3c8 »
2010-04-23 In-place editation in select
345 );
667bfec4 »
2007-07-02 Decomposition
346 }
347 }
09e93ded »
2009-09-23 Move backward keys to Editor
348 $adminer->backwardKeysPrint($backward_keys, $rows[$n]);
26e8ab97 »
2009-10-30 Close </tr> because of white-space: pre
349 echo "</tr>\n"; // close to allow white-space: pre
5ab708a1 »
2007-07-25 Compact pages
350 }
21ea4aea »
2007-09-03 Check errors
351 echo "</table>\n";
3f5b6834 »
2010-04-21 Reintegrate sqlite branch
352 }
353
354 parse_str($_COOKIE["adminer_export"], $adminer_export);
355
bd252953 »
2010-04-22 Don't redirect from last page
356 if ($rows || $page) {
3f5b6834 »
2010-04-21 Reintegrate sqlite branch
357 $exact_count = true;
04eccbad »
2010-10-22 Allow bigger numbers under 32 bits
358 if ($_GET["page"] != "last" && +$limit && count($group) >= count($select) && ($found_rows >= $limit || $page)) {
3f5b6834 »
2010-04-21 Reintegrate sqlite branch
359 $found_rows = $table_status["Rows"];
bd252953 »
2010-04-22 Don't redirect from last page
360 if (!isset($found_rows) || $where || 2 * $page * $limit > $found_rows || ($table_status["Engine"] == "InnoDB" && $found_rows < 1e4)) {
3f5b6834 »
2010-04-21 Reintegrate sqlite branch
361 // slow with big tables
362 ob_flush();
363 flush();
60c7ed9a »
2010-05-11 MS SQL schema support
364 $found_rows = $connection->result("SELECT COUNT(*) FROM " . table($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : ""));
3f5b6834 »
2010-04-21 Reintegrate sqlite branch
365 } else {
366 $exact_count = false;
367 }
4cdc4598 »
2009-07-16 FOUND_ROWS works with last SELECT
368 }
fde11717 »
2009-10-28 Add CSS classes (thanks to cvicebni ubor)
369 echo "<p class='pages'>";
04eccbad »
2010-10-22 Allow bigger numbers under 32 bits
370 if (+$limit && $found_rows > $limit) {
bd252953 »
2010-04-22 Don't redirect from last page
371 // display first, previous 4, next 4 and last page
21ea4aea »
2007-09-03 Check errors
372 $max_page = floor(($found_rows - 1) / $limit);
5a11c99e »
2010-06-29 Ability to jump to any page by JavaScript
373 echo '<a href="' . h(remove_from_uri("page")) . "\" onclick=\"var page = +prompt('" . lang('Page') . "', '" . ($page + 1) . "'); if (!isNaN(page) &amp;&amp; page) location.href = this.href + (page != 1 ? '&amp;page=' + (page - 1) : ''); return false;\">" . lang('Page') . "</a>:" . pagination(0, $page) . ($page > 5 ? " ..." : "");
bd252953 »
2010-04-22 Don't redirect from last page
374 for ($i = max(1, $page - 4); $i < min($max_page, $page + 5); $i++) {
375 echo pagination($i, $page);
21ea4aea »
2007-09-03 Check errors
376 }
bd252953 »
2010-04-22 Don't redirect from last page
377 echo ($page + 5 < $max_page ? " ..." : "") . ($exact_count ? pagination($max_page, $page) : ' <a href="' . h(remove_from_uri() . "&page=last") . '">' . lang('last') . "</a>");
5ab708a1 »
2007-07-25 Compact pages
378 }
3f5b6834 »
2010-04-21 Reintegrate sqlite branch
379 echo " (" . ($exact_count ? "" : "~ ") . lang('%d row(s)', $found_rows) . ") " . checkbox("all", 1, 0, lang('whole result')) . "\n";
8b745113 »
2008-09-01 Print SQL query (fixes #2082448)
380
e0d9b3c8 »
2010-04-23 In-place editation in select
381 if (!information_schema(DB)) {
382 ?>
383 <fieldset><legend><?php echo lang('Edit'); ?></legend><div>
5050de57 »
2010-05-07 Display modify hint as title
384 <input type="submit" value="<?php echo lang('Save'); ?>" title="<?php echo lang('Double click on a value to modify it.'); ?>">
e0d9b3c8 »
2010-04-23 In-place editation in select
385 <input type="submit" name="edit" value="<?php echo lang('Edit'); ?>">
386 <input type="submit" name="clone" value="<?php echo lang('Clone'); ?>">
a93bc191 »
2010-10-18 Create confirm function
387 <input type="submit" name="delete" value="<?php echo lang('Delete'); ?>"<?php echo confirm("(this.form['all'].checked ? $found_rows : formChecked(this, /check/))"); ?>>
e0d9b3c8 »
2010-04-23 In-place editation in select
388 </div></fieldset>
389 <?php
390 }
dc667ea1 »
2009-09-11 Hide select export and import
391 print_fieldset("export", lang('Export'));
be3410f8 »
2010-10-29 Simplify dumpOutput, dumpFormat and dumpData methods
392 $output = $adminer->dumpOutput();
393 echo ($output ? html_select("output", $output, $adminer_export["output"]) . " " : "") . html_select("format", $adminer->dumpFormat(), $adminer_export["format"]);
e40612a4 »
2009-10-02 Use radio in export
394 echo " <input type='submit' name='export' value='" . lang('Export') . "'>\n";
dc667ea1 »
2009-09-11 Hide select export and import
395 echo "</div></fieldset>\n";
667bfec4 »
2007-07-02 Decomposition
396 }
dba6a906 »
2010-08-03 Property num_rows can be empty
397 print_fieldset("import", lang('CSV Import'), !$rows);
3f5b6834 »
2010-04-21 Reintegrate sqlite branch
398 echo "<input type='hidden' name='token' value='$token'><input type='file' name='csv_file'> ";
e225d22f »
2010-10-29 TSV export and import (bug #3097657)
399 echo html_select("separator", array("csv" => "CSV,", "csv;" => "CSV;", "tsv" => "TSV"), $adminer_export["format"], 1); // 1 - select
3f5b6834 »
2010-04-21 Reintegrate sqlite branch
400 echo " <input type='submit' name='import' value='" . lang('Import') . "'>\n";
dc667ea1 »
2009-09-11 Hide select export and import
401 echo "</div></fieldset>\n";
c16c57b1 »
2009-07-11 E-mail sending
402
1e55d475 »
2009-09-09 User interface for e-mail {$name}
403 $adminer->selectEmailPrint(array_filter($email_fields, 'strlen'), $columns);
c16c57b1 »
2009-07-11 E-mail sending
404
e7eb28d3 »
2008-12-30 CSV import
405 echo "</form>\n";
667bfec4 »
2007-07-02 Decomposition
406 }
407 }
Something went wrong with that request. Please try again.