Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 326 lines (311 sloc) 17.301 kB
667bfec Decomposition
jakubvrana authored
1 <?php
d72bf4c Select specific variables
jakubvrana authored
2 $functions = array("char_length", "from_unixtime", "hex", "lower", "round", "sec_to_time", "time_to_sec", "unix_timestamp", "upper");
64ba924 Comments
jakubvrana authored
3 $grouping = array("avg", "count", "distinct", "group_concat", "max", "min", "sum"); // distinct is short for COUNT(DISTINCT)
116faf2 Mass delete
jakubvrana authored
4 $table_status = table_status($_GET["select"]);
5 $indexes = indexes($_GET["select"]);
26c2ff0 NOT operators
jakubvrana authored
6 $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "REGEXP", "IN", "IS NULL", "NOT LIKE", "NOT REGEXP", "NOT IN", "IS NOT NULL");
f78779b Maria engine supports fulltext
jakubvrana authored
7 if (eregi('^(MyISAM|Maria)$', $table_status["Engine"])) {
116faf2 Mass delete
jakubvrana authored
8 $operators[] = "AGAINST";
9 }
ffcea8b Rights
jakubvrana authored
10 $fields = fields($_GET["select"]);
64ba924 Comments
jakubvrana authored
11 $rights = array(); // privilege => 0
12 $columns = array(); // selectable columns
02a851c Shorten texts in PHP
jakubvrana authored
13 unset($text_length);
ffcea8b Rights
jakubvrana authored
14 foreach ($fields as $key => $field) {
430034c Cottage homework
jakubvrana authored
15 if (isset($field["privileges"]["select"])) {
ffcea8b Rights
jakubvrana authored
16 $columns[] = $key;
02a851c Shorten texts in PHP
jakubvrana authored
17 if (preg_match('~text|blob~', $field["type"])) {
18 $text_length = (isset($_GET["text_length"]) ? $_GET["text_length"] : "100");
19 }
ffcea8b Rights
jakubvrana authored
20 }
430034c Cottage homework
jakubvrana authored
21 $rights += $field["privileges"];
22 }
23
64ba924 Comments
jakubvrana authored
24 $select = array(); // select expressions, empty for *
25 $group = array(); // expressions without aggregation - will be used for GROUP BY if an aggregation function is used
5ee29cb Select columns, aggregation
jakubvrana authored
26 foreach ((array) $_GET["columns"] as $key => $val) {
27 if ($val["fun"] == "count" || (in_array($val["col"], $columns, true) && (!$val["fun"] || in_array($val["fun"], $functions) || in_array($val["fun"], $grouping)))) {
28 $select[$key] = (in_array($val["col"], $columns, true) ? (!$val["fun"] ? idf_escape($val["col"]) : ($val["fun"] == "distinct" ? "COUNT(DISTINCT " : strtoupper("$val[fun](")) . idf_escape($val["col"]) . ")") : "COUNT(*)");
29 if (!in_array($val["fun"], $grouping)) {
30 $group[] = $select[$key];
31 }
32 }
33 }
64ba924 Comments
jakubvrana authored
34 $where = array(); // where expressions - will be joined by AND
116faf2 Mass delete
jakubvrana authored
35 foreach ($indexes as $i => $index) {
36 if ($index["type"] == "FULLTEXT" && strlen($_GET["fulltext"][$i])) {
5f16c75 Prepare for version 2
jakubvrana authored
37 $where[] = "MATCH (" . implode(", ", array_map('idf_escape', $index["columns"])) . ") AGAINST ('" . $dbh->escape_string($_GET["fulltext"][$i]) . "'" . (isset($_GET["boolean"][$i]) ? " IN BOOLEAN MODE" : "") . ")";
116faf2 Mass delete
jakubvrana authored
38 }
39 }
40 foreach ((array) $_GET["where"] as $val) {
25bc058 Search in any column
jakubvrana authored
41 if (strlen("$val[col]$val[val]") && in_array($val["op"], $operators)) {
42 if ($val["op"] == "AGAINST") {
5f16c75 Prepare for version 2
jakubvrana authored
43 $where[] = "MATCH (" . idf_escape($val["col"]) . ") AGAINST ('" . $dbh->escape_string($val["val"]) . "' IN BOOLEAN MODE)";
25bc058 Search in any column
jakubvrana authored
44 } elseif (ereg('IN$', $val["op"]) && !strlen($in = process_length($val["val"]))) {
45 $where[] = "0";
116faf2 Mass delete
jakubvrana authored
46 } else {
5f16c75 Prepare for version 2
jakubvrana authored
47 $cond = " $val[op]" . (ereg('NULL$', $val["op"]) ? "" : (ereg('IN$', $val["op"]) ? " ($in)" : " '" . $dbh->escape_string($val["val"]) . "'")); //! this searches in numeric values too
25bc058 Search in any column
jakubvrana authored
48 if (strlen($val["col"])) {
49 $where[] = idf_escape($val["col"]) . $cond;
50 } else {
64ba924 Comments
jakubvrana authored
51 // find anywhere
25bc058 Search in any column
jakubvrana authored
52 $cols = array();
53 foreach ($fields as $name => $field) {
54 if (is_numeric($val["val"]) || !ereg('int|float|double|decimal', $field["type"])) {
55 $cols[] = $name;
56 }
57 }
58 $where[] = ($cols ? "(" . implode("$cond OR ", array_map('idf_escape', $cols)) . "$cond)" : "0");
59 }
116faf2 Mass delete
jakubvrana authored
60 }
61 }
62 }
64ba924 Comments
jakubvrana authored
63 $order = array(); // order expressions - will be joined by comma
116faf2 Mass delete
jakubvrana authored
64 foreach ((array) $_GET["order"] as $key => $val) {
5805eba Remove order of not used functions
jakubvrana authored
65 if (in_array($val, $columns, true) || in_array($val, $select, true)) {
116faf2 Mass delete
jakubvrana authored
66 $order[] = idf_escape($val) . (isset($_GET["desc"][$key]) ? " DESC" : "");
67 }
68 }
69 $limit = (isset($_GET["limit"]) ? $_GET["limit"] : "30");
5ee29cb Select columns, aggregation
jakubvrana authored
70 $from = "FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . ($group && count($group) < count($select) ? " GROUP BY " . implode(", ", $group) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "") . (strlen($limit) ? " LIMIT " . intval($limit) . (intval($_GET["page"]) ? " OFFSET " . ($limit * $_GET["page"]) : "") : "");
116faf2 Mass delete
jakubvrana authored
71
72 if ($_POST && !$error) {
78639a9 Function results in edit
jakubvrana authored
73 if ($_POST["export"]) {
9890b6c Export Output in select.inc.php
jakubvrana authored
74 dump_headers($_GET["select"]);
f48161b CSV Byte-order-mark
jakubvrana authored
75 dump_table($_GET["select"], "");
5b70b5b Change variable name
jakubvrana authored
76 $query = "SELECT " . ($select ? implode(", ", $select) : "*") . " FROM " . idf_escape($_GET["select"]);
f7452ad Import and export
jakubvrana authored
77 if (is_array($_POST["check"])) {
fa5c952 Use extended INSERT in select export
jakubvrana authored
78 $union = array();
f7452ad Import and export
jakubvrana authored
79 foreach ($_POST["check"] as $val) {
64ba924 Comments
jakubvrana authored
80 // where may not be unique so OR can't be used
fa5c952 Use extended INSERT in select export
jakubvrana authored
81 $union[] = "($query WHERE " . implode(" AND ", where_check($val)) . " LIMIT 1)";
116faf2 Mass delete
jakubvrana authored
82 }
fa5c952 Use extended INSERT in select export
jakubvrana authored
83 dump_data($_GET["select"], "INSERT", implode(" UNION ALL ", $union));
f7452ad Import and export
jakubvrana authored
84 } else {
5b70b5b Change variable name
jakubvrana authored
85 dump_data($_GET["select"], "INSERT", $query . ($where ? " WHERE " . implode(" AND ", $where) : ""));
116faf2 Mass delete
jakubvrana authored
86 }
78639a9 Function results in edit
jakubvrana authored
87 exit;
88 }
d83b654 Detect import errors
jakubvrana authored
89 if (!$_POST["import"]) { // edit
e7eb28d CSV import
jakubvrana authored
90 $result = true;
91 $affected = 0;
92 $command = ($_POST["delete"] ? ($_POST["all"] && !$where ? "TRUNCATE " : "DELETE FROM ") : ($_POST["clone"] ? "INSERT INTO " : "UPDATE ")) . idf_escape($_GET["select"]);
93 if (!$_POST["delete"]) {
94 $set = array();
95 foreach ($fields as $name => $field) {
96 $val = process_input($name, $field);
97 if ($_POST["clone"]) {
98 $set[] = ($val !== false ? $val : idf_escape($name));
99 } elseif ($val !== false) {
0cd2afb Remove single item clone
jakubvrana authored
100 $set[] = "\n" . idf_escape($name) . " = $val";
e7eb28d CSV import
jakubvrana authored
101 }
102 }
0cd2afb Remove single item clone
jakubvrana authored
103 $command .= ($_POST["clone"] ? "\nSELECT " . implode(", ", $set) . " FROM " . idf_escape($_GET["select"]) : " SET" . implode(",", $set));
e7eb28d CSV import
jakubvrana authored
104 }
105 if (!$_POST["delete"] && !$set) {
106 // nothing
107 } elseif ($_POST["all"]) {
108 $result = queries($command . ($where ? " WHERE " . implode(" AND ", $where) : ""));
5f16c75 Prepare for version 2
jakubvrana authored
109 $affected = $dbh->affected_rows;
e7eb28d CSV import
jakubvrana authored
110 } else {
111 foreach ((array) $_POST["check"] as $val) {
112 parse_str($val, $check);
64ba924 Comments
jakubvrana authored
113 // where may not be unique so OR can't be used
e7eb28d CSV import
jakubvrana authored
114 $result = queries($command . " WHERE " . implode(" AND ", where($check)) . " LIMIT 1");
115 if (!$result) {
116 break;
117 }
5f16c75 Prepare for version 2
jakubvrana authored
118 $affected += $dbh->affected_rows;
78639a9 Function results in edit
jakubvrana authored
119 }
120 }
e7eb28d CSV import
jakubvrana authored
121 query_redirect(queries(), remove_from_uri("page"), lang('%d item(s) have been affected.', $affected), $result, false, !$result);
122 //! display edit page in case of an error
d83b654 Detect import errors
jakubvrana authored
123 } elseif (is_string($file = get_file("csv_file"))) {
124 $file = preg_replace("~^\xEF\xBB\xBF~", '', $file); //! character set
125 $cols = "";
126 $rows = array(); //! packet size
127 preg_match_all('~("[^"]*"|[^"\\n]+)+~', $file, $matches);
128 foreach ($matches[0] as $key => $val) {
129 $row = array();
130 preg_match_all('~(("[^"]*")+|[^,]*),~', "$val,", $matches2);
131 if (!$key && !array_diff($matches2[1], array_keys($fields))) { //! doesn't work with column names containing ",\n
64ba924 Comments
jakubvrana authored
132 // first row corresponds to column names - use it for table structure
d83b654 Detect import errors
jakubvrana authored
133 $cols = " (" . implode(", ", array_map('idf_escape', $matches2[1])) . ")";
134 } else {
135 foreach ($matches2[1] as $col) {
5f16c75 Prepare for version 2
jakubvrana authored
136 $row[] = (!strlen($col) ? "NULL" : "'" . $dbh->escape_string(str_replace('""', '"', preg_replace('~^".*"$~s', '', $col))) . "'");
d83b654 Detect import errors
jakubvrana authored
137 }
64ba924 Comments
jakubvrana authored
138 $rows[] = "\n(" . implode(", ", $row) . ")";
d83b654 Detect import errors
jakubvrana authored
139 }
140 }
64ba924 Comments
jakubvrana authored
141 $result = queries("INSERT INTO " . idf_escape($_GET["select"]) . "$cols VALUES" . implode(",", $rows));
5f16c75 Prepare for version 2
jakubvrana authored
142 query_redirect(queries(), remove_from_uri("page"), lang('%d row(s) has been imported.', $dbh->affected_rows), $result, false, !$result);
d83b654 Detect import errors
jakubvrana authored
143 } else {
144 $error = lang('Unable to upload a file.');
ec23248 Exportable select
jakubvrana authored
145 }
116faf2 Mass delete
jakubvrana authored
146 }
820c882 Bulk clone
jakubvrana authored
147 page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]), $error);
116faf2 Mass delete
jakubvrana authored
148
4099271 Cross links to select and table (bug #2236232)
jakubvrana authored
149 echo "<p>";
430034c Cottage homework
jakubvrana authored
150 if (isset($rights["insert"])) {
3d254a3 TODO
jakubvrana authored
151 //! pass search values forth and back
4099271 Cross links to select and table (bug #2236232)
jakubvrana authored
152 echo '<a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '">' . lang('New item') . '</a> ';
667bfec Decomposition
jakubvrana authored
153 }
d886b00 Link to view
jakubvrana authored
154 echo '<a href="' . htmlspecialchars($SELF) . (isset($table_status["Engine"]) ? 'table=' : 'view=') . urlencode($_GET['select']) . '">' . lang('Table structure') . '</a>';
4099271 Cross links to select and table (bug #2236232)
jakubvrana authored
155 echo "</p>\n";
667bfec Decomposition
jakubvrana authored
156
ffcea8b Rights
jakubvrana authored
157 if (!$columns) {
5f16c75 Prepare for version 2
jakubvrana authored
158 echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "" : ": " . htmlspecialchars($dbh->error)) . ".</p>\n";
ffcea8b Rights
jakubvrana authored
159 } else {
5ee29cb Select columns, aggregation
jakubvrana authored
160 echo "<form action='' id='form'>\n";
b142000 Hide fieldsets in select
jakubvrana authored
161 echo '<fieldset><legend><a href="#fieldset-select" onclick="return !toggle(\'fieldset-select\');">' . lang('Select') . "</a></legend><div id='fieldset-select'" . ($select ? "" : " class='hidden'") . ">\n";
ffcea8b Rights
jakubvrana authored
162 if (strlen($_GET["server"])) {
163 echo '<input type="hidden" name="server" value="' . htmlspecialchars($_GET["server"]) . '" />';
667bfec Decomposition
jakubvrana authored
164 }
ffcea8b Rights
jakubvrana authored
165 echo '<input type="hidden" name="db" value="' . htmlspecialchars($_GET["db"]) . '" />';
166 echo '<input type="hidden" name="select" value="' . htmlspecialchars($_GET["select"]) . '" />';
167 echo "\n";
5ee29cb Select columns, aggregation
jakubvrana authored
168 $i = 0;
169 $fun_group = array(lang('Functions') => $functions, lang('Aggregation') => $grouping);
170 foreach ($select as $key => $val) {
171 $val = $_GET["columns"][$key];
172 echo "<div><select name='columns[$i][fun]'><option></option>" . optionlist($fun_group, $val["fun"]) . "</select>";
173 echo "<select name='columns[$i][col]'><option></option>" . optionlist($columns, $val["col"]) . "</select></div>\n";
174 $i++;
175 }
176 echo "<div><select name='columns[$i][fun]' onchange='this.nextSibling.onchange();'><option></option>" . optionlist($fun_group) . "</select>";
540e217 Separate JavaScript
jakubvrana authored
177 echo "<select name='columns[$i][col]' onchange='select_add_row(this);'><option></option>" . optionlist($columns) . "</select></div>\n";
b142000 Hide fieldsets in select
jakubvrana authored
178 echo "</div></fieldset>\n";
ffcea8b Rights
jakubvrana authored
179
b142000 Hide fieldsets in select
jakubvrana authored
180 echo '<fieldset><legend><a href="#fieldset-search" onclick="return !toggle(\'fieldset-search\');">' . lang('Search') . "</a></legend><div id='fieldset-search'" . ($where ? "" : " class='hidden'") . ">\n";
430034c Cottage homework
jakubvrana authored
181 foreach ($indexes as $i => $index) {
182 if ($index["type"] == "FULLTEXT") {
9e2848d Escape fulltext columns
jakubvrana authored
183 echo "(<i>" . implode("</i>, <i>", array_map('htmlspecialchars', $index["columns"])) . "</i>) AGAINST";
430034c Cottage homework
jakubvrana authored
184 echo ' <input name="fulltext[' . $i . ']" value="' . htmlspecialchars($_GET["fulltext"][$i]) . '" />';
78639a9 Function results in edit
jakubvrana authored
185 echo "<label><input type='checkbox' name='boolean[$i]' value='1'" . (isset($_GET["boolean"][$i]) ? " checked='checked'" : "") . " />" . lang('BOOL') . "</label>";
430034c Cottage homework
jakubvrana authored
186 echo "<br />\n";
187 }
188 }
ffcea8b Rights
jakubvrana authored
189 $i = 0;
190 foreach ((array) $_GET["where"] as $val) {
25bc058 Search in any column
jakubvrana authored
191 if (strlen("$val[col]$val[val]") && in_array($val["op"], $operators)) {
a96dfd0 Promote search anywhere
jakubvrana authored
192 echo "<div><select name='where[$i][col]'><option value=''>" . lang('(anywhere)') . "</option>" . optionlist($columns, $val["col"]) . "</select>";
71430ee IE fixes
jakubvrana authored
193 echo "<select name='where[$i][op]' onchange='where_change(this);'>" . optionlist($operators, $val["op"]) . "</select>";
540e217 Separate JavaScript
jakubvrana authored
194 echo "<input name='where[$i][val]' value=\"" . htmlspecialchars($val["val"]) . '"' . (ereg('NULL$', $val["op"]) ? " class='hidden'" : "") . " /></div>\n";
ffcea8b Rights
jakubvrana authored
195 $i++;
196 }
197 }
540e217 Separate JavaScript
jakubvrana authored
198 echo "<div><select name='where[$i][col]' onchange='select_add_row(this);'><option value=''>" . lang('(anywhere)') . "</option>" . optionlist($columns) . "</select>";
71430ee IE fixes
jakubvrana authored
199 echo "<select name='where[$i][op]' onchange='where_change(this);'>" . optionlist($operators) . "</select>";
4f6f2d4 JavaScript for adding where and order
jakubvrana authored
200 echo "<input name='where[$i][val]' /></div>\n";
b142000 Hide fieldsets in select
jakubvrana authored
201 echo "</div></fieldset>\n";
202
203 echo '<fieldset><legend><a href="#fieldset-sort" onclick="return !toggle(\'fieldset-sort\');">' . lang('Sort') . "</a></legend><div id='fieldset-sort'" . (count($order) > 1 ? "" : " class='hidden'") . ">\n";
204 $i = 0;
205 foreach ((array) $_GET["order"] as $key => $val) {
206 if (in_array($val, $columns, true)) {
207 echo "<div><select name='order[$i]'><option></option>" . optionlist($columns, $val) . "</select>";
b0ee71e Update translations
jakubvrana authored
208 echo "<label><input type='checkbox' name='desc[$i]' value='1'" . (isset($_GET["desc"][$key]) ? " checked='checked'" : "") . " />" . lang('descending') . "</label></div>\n";
b142000 Hide fieldsets in select
jakubvrana authored
209 $i++;
210 }
211 }
212 echo "<div><select name='order[$i]' onchange='select_add_row(this);'><option></option>" . optionlist($columns) . "</select>";
b0ee71e Update translations
jakubvrana authored
213 echo "<label><input type='checkbox' name='desc[$i]' value='1' />" . lang('descending') . "</label></div>\n";
b142000 Hide fieldsets in select
jakubvrana authored
214 echo "</div></fieldset>\n";
ffcea8b Rights
jakubvrana authored
215
64ba924 Comments
jakubvrana authored
216 echo "<fieldset><legend>" . lang('Limit') . "</legend><div>"; // <div> for easy styling
b142000 Hide fieldsets in select
jakubvrana authored
217 echo "<input name='limit' size='3' value=\"" . htmlspecialchars($limit) . "\" />";
218 echo "</div></fieldset>\n";
ffcea8b Rights
jakubvrana authored
219
63441b1 Max text length
jakubvrana authored
220 if (isset($text_length)) {
b142000 Hide fieldsets in select
jakubvrana authored
221 echo "<fieldset><legend>" . lang('Text length') . "</legend><div>";
222 echo "<input name='text_length' size='3' value=\"" . htmlspecialchars($text_length) . "\" />";
223 echo "</div></fieldset>\n";
63441b1 Max text length
jakubvrana authored
224 }
225
b142000 Hide fieldsets in select
jakubvrana authored
226 echo "<fieldset><legend>" . lang('Action') . "</legend><div>";
227 echo "<input type='submit' value='" . lang('Select') . "' />";
228 echo "</div></fieldset>\n";
ffcea8b Rights
jakubvrana authored
229 echo "</form>\n";
230
8b74511 Print SQL query (fixes #2082448)
jakubvrana authored
231 $query = "SELECT " . ($select ? (count($group) < count($select) ? "SQL_CALC_FOUND_ROWS " : "") . implode(", ", $select) : "*") . " $from";
06faef2 Print SQL query by messages
jakubvrana authored
232 echo "<p><code class='jush-sql'>" . htmlspecialchars($query) . "</code> <a href='" . htmlspecialchars($SELF) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a></p>\n";
8b74511 Print SQL query (fixes #2082448)
jakubvrana authored
233
5f16c75 Prepare for version 2
jakubvrana authored
234 $result = $dbh->query($query);
21ea4ae Check errors
jakubvrana authored
235 if (!$result) {
5f16c75 Prepare for version 2
jakubvrana authored
236 echo "<p class='error'>" . htmlspecialchars($dbh->error) . "</p>\n";
ffcea8b Rights
jakubvrana authored
237 } else {
e7eb28d CSV import
jakubvrana authored
238 echo "<form action='' method='post' enctype='multipart/form-data'>\n";
21ea4ae Check errors
jakubvrana authored
239 if (!$result->num_rows) {
240 echo "<p class='message'>" . lang('No rows.') . "</p>\n";
241 } else {
242 $foreign_keys = array();
243 foreach (foreign_keys($_GET["select"]) as $foreign_key) {
244 foreach ($foreign_key["source"] as $val) {
245 $foreign_keys[$val][] = $foreign_key;
246 }
ffcea8b Rights
jakubvrana authored
247 }
21ea4ae Check errors
jakubvrana authored
248
d30face Remove useless table attributes (thanks to Juraj Krivda)
jakubvrana authored
249 echo "<table cellspacing='0' class='nowrap'>\n";
21ea4ae Check errors
jakubvrana authored
250 for ($j=0; $row = $result->fetch_assoc(); $j++) {
251 if (!$j) {
d5a4d14 Separate page and whole result check
jakubvrana authored
252 echo '<thead><tr><td><input type="checkbox" id="all-page" onclick="form_check(this, /check/);" /></td>';
e4089af Order rows by clicking on table heading
jakubvrana authored
253 foreach ($row as $key => $val) {
b142000 Hide fieldsets in select
jakubvrana authored
254 echo '<th><a href="' . htmlspecialchars(remove_from_uri('(order|desc)[^=]*') . '&order%5B0%5D=' . urlencode($key) . ($_GET["order"] == array($key) && !$_GET["desc"][0] ? '&desc%5B0%5D=1' : '')) . '">' . htmlspecialchars($key) . '</a></th>';
e4089af Order rows by clicking on table heading
jakubvrana authored
255 }
256 echo "</tr></thead>\n";
21ea4ae Check errors
jakubvrana authored
257 }
116faf2 Mass delete
jakubvrana authored
258 $unique_idf = implode('&amp;', unique_idf($row, $indexes));
0cd2afb Remove single item clone
jakubvrana authored
259 echo '<tr' . odd() . '><td><input type="checkbox" name="check[]" value="' . $unique_idf . '" onclick="this.form[\'all\'].checked = false; form_uncheck(\'all-page\');" />' . (count($select) == count($group) && $_GET["db"] != "information_schema" ? ' <a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '&amp;' . $unique_idf . '">' . lang('edit') . '</a></td>' : '');
21ea4ae Check errors
jakubvrana authored
260 foreach ($row as $key => $val) {
261 if (!isset($val)) {
262 $val = "<i>NULL</i>";
017ffb5 Better UTF-8 detection
jakubvrana authored
263 } elseif (preg_match('~blob|binary~', $fields[$key]["type"]) && !is_utf8($val)) {
116faf2 Mass delete
jakubvrana authored
264 $val = '<a href="' . htmlspecialchars($SELF) . 'download=' . urlencode($_GET["select"]) . '&amp;field=' . urlencode($key) . '&amp;' . $unique_idf . '">' . lang('%d byte(s)', strlen($val)) . '</a>';
02a851c Shorten texts in PHP
jakubvrana authored
265 } else {
4c75d84 Use &nbsp;
jakubvrana authored
266 if (!strlen(trim($val))) {
267 $val = "&nbsp;";
268 } elseif (intval($text_length) > 0 && preg_match('~blob|text~', $fields[$key]["type"])) {
33e8015 Shorten displayed SQL query
jakubvrana authored
269 $val = nl2br(shorten_utf8($val, intval($text_length)));
21ea4ae Check errors
jakubvrana authored
270 } else {
271 $val = nl2br(htmlspecialchars($val));
272 if ($fields[$key]["type"] == "char") {
273 $val = "<code>$val</code>";
274 }
02a851c Shorten texts in PHP
jakubvrana authored
275 }
21ea4ae Check errors
jakubvrana authored
276 foreach ((array) $foreign_keys[$key] as $foreign_key) {
277 if (count($foreign_keys[$key]) == 1 || count($foreign_key["source"]) == 1) {
64ba924 Comments
jakubvrana authored
278 // link related items
21ea4ae Check errors
jakubvrana authored
279 $val = "\">$val</a>";
280 foreach ($foreign_key["source"] as $i => $source) {
281 $val = "&amp;where%5B$i%5D%5Bcol%5D=" . urlencode($foreign_key["target"][$i]) . "&amp;where%5B$i%5D%5Bop%5D=%3D&amp;where%5B$i%5D%5Bval%5D=" . urlencode($row[$source]) . $val;
282 }
283 $val = '<a href="' . htmlspecialchars(strlen($foreign_key["db"]) ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($foreign_key["db"]), $SELF) : $SELF) . 'select=' . htmlspecialchars($foreign_key["table"]) . $val; // InnoDB supports non-UNIQUE keys
284 break;
ffcea8b Rights
jakubvrana authored
285 }
fa3dd55 Parent
jakubvrana authored
286 }
667bfec Decomposition
jakubvrana authored
287 }
21ea4ae Check errors
jakubvrana authored
288 echo "<td>$val</td>";
667bfec Decomposition
jakubvrana authored
289 }
21ea4ae Check errors
jakubvrana authored
290 echo "</tr>\n";
5ab708a Compact pages
jakubvrana authored
291 }
21ea4ae Check errors
jakubvrana authored
292 echo "</table>\n";
e4b188c Display found rows
jakubvrana authored
293
294 echo "<p>";
64ba924 Comments
jakubvrana authored
295 // use num_rows without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest)
5d311ef Comment
jakubvrana authored
296 $found_rows = (intval($limit) ? $dbh->result($dbh->query(count($group) < count($select)
297 ? " SELECT FOUND_ROWS()" // space to allow mysql.trace_mode
298 : "SELECT COUNT(*) FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "")
299 )) : $result->num_rows);
e4b188c Display found rows
jakubvrana authored
300 if (intval($limit) && $found_rows > $limit) {
64ba924 Comments
jakubvrana authored
301 // display first, previous 3, next 3 and last page
21ea4ae Check errors
jakubvrana authored
302 $max_page = floor(($found_rows - 1) / $limit);
e4b188c Display found rows
jakubvrana authored
303 echo lang('Page') . ":";
21ea4ae Check errors
jakubvrana authored
304 print_page(0);
305 if ($_GET["page"] > 3) {
306 echo " ...";
307 }
308 for ($i = max(1, $_GET["page"] - 2); $i < min($max_page, $_GET["page"] + 3); $i++) {
309 print_page($i);
310 }
311 if ($_GET["page"] + 3 < $max_page) {
312 echo " ...";
313 }
314 print_page($max_page);
5ab708a Compact pages
jakubvrana authored
315 }
d5a4d14 Separate page and whole result check
jakubvrana authored
316 echo " (" . lang('%d row(s)', $found_rows) . ') <label><input type="checkbox" name="all" value="1" />' . lang('whole result') . "</label></p>\n";
8b74511 Print SQL query (fixes #2082448)
jakubvrana authored
317
4f59613 Don't allow editing in information_schema
jakubvrana authored
318 echo ($_GET["db"] != "information_schema" ? "<fieldset><legend>" . lang('Edit') . "</legend><div><input type='submit' value='" . lang('Edit') . "' /> <input type='submit' name='clone' value='" . lang('Clone') . "' /> <input type='submit' name='delete' value='" . lang('Delete') . "'$confirm /></div></fieldset>\n" : "");
fb8a36b Compact export options
jakubvrana authored
319 echo "<fieldset><legend>" . lang('Export') . "</legend><div>$dump_output $dump_format <input type='submit' name='export' value='" . lang('Export') . "' /></div></fieldset>\n";
667bfec Decomposition
jakubvrana authored
320 }
21ea4ae Check errors
jakubvrana authored
321 $result->free();
e7eb28d CSV import
jakubvrana authored
322 echo "<fieldset><legend>" . lang('CSV Import') . "</legend><div><input type='hidden' name='token' value='$token' /><input type='file' name='csv_file' /> <input type='submit' name='import' value='" . lang('Import') . "' /></div></fieldset>\n";
323 echo "</form>\n";
667bfec Decomposition
jakubvrana authored
324 }
325 }
Something went wrong with that request. Please try again.