Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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