Skip to content
Newer
Older
100644 380 lines (348 sloc) 13.3 KB
667bfec Decomposition
jakubvrana authored Jul 2, 2007
1 <?php
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
2 function get_dbh() {
3 // can be used in customization, $dbh is minified
4 global $dbh;
5 return $dbh;
6 }
7
667bfec Decomposition
jakubvrana authored Jul 2, 2007
8 function idf_escape($idf) {
9 return "`" . str_replace("`", "``", $idf) . "`";
10 }
11
12 function idf_unescape($idf) {
13 return str_replace("``", "`", $idf);
14 }
15
16 function bracket_escape($idf, $back = false) {
64ba924 Comments
jakubvrana authored Jun 21, 2009
17 // escape brackets inside name="x[]"
73e8631 Move stuff to functions.inc.php
jakubvrana authored Jul 9, 2007
18 static $trans = array(':' => ':1', ']' => ':2', '[' => ':3');
667bfec Decomposition
jakubvrana authored Jul 2, 2007
19 return strtr($idf, ($back ? array_flip($trans) : $trans));
20 }
21
689699a Shortcut for htmlspecialchars
jakubvrana authored Jul 28, 2009
22 function h($string) {
23 return htmlspecialchars($string, ENT_QUOTES);
24 }
25
c196985 Function nbsp
jakubvrana authored Aug 25, 2009
26 function nbsp($string) {
27 return (strlen(trim($string)) ? h($string) : "&nbsp;");
28 }
29
1e4d11e Select from foreign keys in Editor
jakubvrana authored Jul 23, 2009
30 function optionlist($options, $selected = null, $use_keys = false) {
667bfec Decomposition
jakubvrana authored Jul 2, 2007
31 $return = "";
32 foreach ($options as $k => $v) {
33 if (is_array($v)) {
689699a Shortcut for htmlspecialchars
jakubvrana authored Jul 28, 2009
34 $return .= '<optgroup label="' . h($k) . '">';
667bfec Decomposition
jakubvrana authored Jul 2, 2007
35 }
ced9de9 Create single column foreign key in table structure
jakubvrana authored Jul 2, 2009
36 foreach ((is_array($v) ? $v : array($k => $v)) as $key => $val) {
cb6d36c HTML instead of XHTML
jakubvrana authored Jul 28, 2009
37 $return .= '<option' . ($use_keys || is_string($key) ? ' value="' . h($key) . '"' : '') . (($use_keys || is_string($key) ? (string) $key : $val) === $selected ? ' selected' : '') . '>' . h($val);
667bfec Decomposition
jakubvrana authored Jul 2, 2007
38 }
39 if (is_array($v)) {
40 $return .= '</optgroup>';
41 }
42 }
43 return $return;
44 }
45
0bd864e Allow specifying column in get_vals
jakubvrana authored May 21, 2009
46 function get_vals($query, $column = 0) {
5f16c75 Prepare for version 2
jakubvrana authored May 8, 2009
47 global $dbh;
7769f2c Separate get_vals
jakubvrana authored Jul 11, 2007
48 $return = array();
5f16c75 Prepare for version 2
jakubvrana authored May 8, 2009
49 $result = $dbh->query($query);
49f7886 SHOW DATABASES can be revoked
jakubvrana authored Sep 30, 2008
50 if ($result) {
51 while ($row = $result->fetch_row()) {
0bd864e Allow specifying column in get_vals
jakubvrana authored May 21, 2009
52 $return[] = $row[$column];
49f7886 SHOW DATABASES can be revoked
jakubvrana authored Sep 30, 2008
53 }
54 $result->free();
7769f2c Separate get_vals
jakubvrana authored Jul 11, 2007
55 }
56 return $return;
57 }
58
667bfec Decomposition
jakubvrana authored Jul 2, 2007
59 function unique_idf($row, $indexes) {
720f5fc Restructure indexes
jakubvrana authored Jul 5, 2007
60 foreach ($indexes as $index) {
61 if ($index["type"] == "PRIMARY" || $index["type"] == "UNIQUE") {
62 $return = array();
63 foreach ($index["columns"] as $key) {
64ba924 Comments
jakubvrana authored Jun 21, 2009
64 if (!isset($row[$key])) { // NULL is ambiguous
720f5fc Restructure indexes
jakubvrana authored Jul 5, 2007
65 continue 2;
667bfec Decomposition
jakubvrana authored Jul 2, 2007
66 }
430034c Cottage homework
jakubvrana authored Jul 9, 2007
67 $return[] = urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($row[$key]);
667bfec Decomposition
jakubvrana authored Jul 2, 2007
68 }
720f5fc Restructure indexes
jakubvrana authored Jul 5, 2007
69 return $return;
667bfec Decomposition
jakubvrana authored Jul 2, 2007
70 }
71 }
72 $return = array();
73 foreach ($row as $key => $val) {
26c9d64 Fix long SQL query crash (bug #2839231)
jakubvrana authored Aug 19, 2009
74 if (!preg_match('~^(COUNT\\((\\*|(DISTINCT )?`(?:[^`]|``)+`)\\)|(AVG|GROUP_CONCAT|MAX|MIN|SUM)\\(`(?:[^`]|``)+`\\))$~', $key)) { //! columns looking like functions
988a29f Don't use aggregation functions in unique_idf
jakubvrana authored Jul 28, 2009
75 $return[] = (isset($val) ? urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($val) : "null%5B%5D=" . urlencode($key));
76 }
430034c Cottage homework
jakubvrana authored Jul 9, 2007
77 }
78 return $return;
79 }
80
9ea3112 Mandatory $where in where()
jakubvrana authored Aug 8, 2008
81 function where($where) {
5f16c75 Prepare for version 2
jakubvrana authored May 8, 2009
82 global $dbh;
430034c Cottage homework
jakubvrana authored Jul 9, 2007
83 $return = array();
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
84 foreach ((array) $where["where"] as $key => $val) {
581bd35 Respect function results in where()
jakubvrana authored Aug 8, 2008
85 $key = bracket_escape($key, "back");
26c9d64 Fix long SQL query crash (bug #2839231)
jakubvrana authored Aug 19, 2009
86 $return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]|``)+`\\)$~', $key) ? $key : idf_escape($key)) . " = BINARY " . $dbh->quote($val); //! enum and set, columns looking like functions
430034c Cottage homework
jakubvrana authored Jul 9, 2007
87 }
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
88 foreach ((array) $where["null"] as $key) {
581bd35 Respect function results in where()
jakubvrana authored Aug 8, 2008
89 $key = bracket_escape($key, "back");
26c9d64 Fix long SQL query crash (bug #2839231)
jakubvrana authored Aug 19, 2009
90 $return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]|``)+`\\)$~', $key) ? $key : idf_escape($key)) . " IS NULL";
667bfec Decomposition
jakubvrana authored Jul 2, 2007
91 }
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
92 return implode(" AND ", $return);
667bfec Decomposition
jakubvrana authored Jul 2, 2007
93 }
94
0cd2afb Remove single item clone
jakubvrana authored Jun 7, 2009
95 function where_check($val) {
96 parse_str($val, $check);
97 return where($check);
98 }
99
c42c46a Table relations
jakubvrana authored Jul 15, 2009
100 function where_link($i, $column, $value) {
db46fc2 Maintain insert prefill value
jakubvrana authored Aug 3, 2009
101 return "&where%5B$i%5D%5Bcol%5D=" . urlencode($column) . "&where%5B$i%5D%5Bop%5D=%3D&where%5B$i%5D%5Bval%5D=" . urlencode($value);
c42c46a Table relations
jakubvrana authored Jul 15, 2009
102 }
103
430034c Cottage homework
jakubvrana authored Jul 9, 2007
104 function redirect($location, $message = null) {
105 if (isset($message)) {
ff74bf0 Allow multiple messages
jakubvrana authored Apr 18, 2008
106 $_SESSION["messages"][] = $message;
430034c Cottage homework
jakubvrana authored Jul 9, 2007
107 }
108 if (strlen(SID)) {
64ba924 Comments
jakubvrana authored Jun 21, 2009
109 // append SID if session cookies are disabled
430034c Cottage homework
jakubvrana authored Jul 9, 2007
110 $location .= (strpos($location, "?") === false ? "?" : "&") . SID;
111 }
112 header("Location: " . (strlen($location) ? $location : "."));
113 exit;
114 }
115
748ee83 Print SQL command with multiple queries
jakubvrana authored Sep 3, 2008
116 function query_redirect($query, $location, $message, $redirect = true, $execute = true, $failed = false) {
98507da Function verify_version doesn't use version parameter
jakubvrana authored Jul 30, 2009
117 global $dbh, $error, $adminer;
10bdbed Save queries to history
jakubvrana authored Jun 4, 2009
118 $sql = "";
119 if ($query) {
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
120 $sql = $adminer->messageQuery($query);
10bdbed Save queries to history
jakubvrana authored Jun 4, 2009
121 }
748ee83 Print SQL command with multiple queries
jakubvrana authored Sep 3, 2008
122 if ($execute) {
5f16c75 Prepare for version 2
jakubvrana authored May 8, 2009
123 $failed = !$dbh->query($query);
748ee83 Print SQL command with multiple queries
jakubvrana authored Sep 3, 2008
124 }
125 if ($failed) {
689699a Shortcut for htmlspecialchars
jakubvrana authored Jul 28, 2009
126 $error = h($dbh->error) . $sql;
c48a017 Print SQL query by error
jakubvrana authored Sep 2, 2008
127 return false;
f91b2c4 Print SQL query by message
jakubvrana authored Sep 2, 2008
128 }
c48a017 Print SQL query by error
jakubvrana authored Sep 2, 2008
129 if ($redirect) {
130 redirect($location, $message . $sql);
131 }
132 return true;
f91b2c4 Print SQL query by message
jakubvrana authored Sep 2, 2008
133 }
134
748ee83 Print SQL command with multiple queries
jakubvrana authored Sep 3, 2008
135 function queries($query = null) {
5f16c75 Prepare for version 2
jakubvrana authored May 8, 2009
136 global $dbh;
748ee83 Print SQL command with multiple queries
jakubvrana authored Sep 3, 2008
137 static $queries = array();
138 if (!isset($query)) {
64ba924 Comments
jakubvrana authored Jun 21, 2009
139 // return executed queries without parameter
36950eb Tables and views
jakubvrana authored Sep 25, 2008
140 return implode(";\n", $queries);
748ee83 Print SQL command with multiple queries
jakubvrana authored Sep 3, 2008
141 }
142 $queries[] = $query;
5f16c75 Prepare for version 2
jakubvrana authored May 8, 2009
143 return $dbh->query($query);
748ee83 Print SQL command with multiple queries
jakubvrana authored Sep 3, 2008
144 }
145
d41d446 remove_from_uri()
jakubvrana authored Jul 27, 2007
146 function remove_from_uri($param = "") {
6272cae Unconditionally remove session_name() in remove_from_uri()
jakubvrana authored Jul 28, 2007
147 $param = "($param|" . session_name() . ")";
d41d446 remove_from_uri()
jakubvrana authored Jul 27, 2007
148 return preg_replace("~\\?$param=[^&]*&~", '?', preg_replace("~\\?$param=[^&]*\$|&$param=[^&]*~", '', $_SERVER["REQUEST_URI"]));
149 }
150
c565c54 Let pagination function return
jakubvrana authored Jul 15, 2009
151 function pagination($page) {
689699a Shortcut for htmlspecialchars
jakubvrana authored Jul 28, 2009
152 return " " . ($page == $_GET["page"] ? $page + 1 : '<a href="' . h(remove_from_uri("page") . ($page ? "&page=$page" : "")) . '">' . ($page + 1) . "</a>");
1456283 Pages on last page
jakubvrana authored Aug 7, 2008
153 }
154
430034c Cottage homework
jakubvrana authored Jul 9, 2007
155 function get_file($key) {
64ba924 Comments
jakubvrana authored Jun 21, 2009
156 // returns int for error, string otherwise
430034c Cottage homework
jakubvrana authored Jul 9, 2007
157 if (isset($_POST["files"][$key])) {
64ba924 Comments
jakubvrana authored Jun 21, 2009
158 // get the file from hidden field if the user was logged out
430034c Cottage homework
jakubvrana authored Jul 9, 2007
159 $length = strlen($_POST["files"][$key]);
4d38c7d Protection against big POST data
jakubvrana authored Mar 18, 2008
160 return ($length && $length < 4 ? intval($_POST["files"][$key]) : base64_decode($_POST["files"][$key]));
430034c Cottage homework
jakubvrana authored Jul 9, 2007
161 }
162 return (!$_FILES[$key] || $_FILES[$key]["error"] ? $_FILES[$key]["error"] : file_get_contents($_FILES[$key]["tmp_name"]));
163 }
164
e2a03c0 Show upload_max_filesize
jakubvrana authored Jul 16, 2009
165 function upload_error($error) {
166 $max_size = ($error == UPLOAD_ERR_INI_SIZE ? ini_get("upload_max_filesize") : null); // post_max_size is checked in index.php
b2a7c7a Execute SQL file stored on server disk
jakubvrana authored Aug 25, 2009
167 return ($error ? lang('Unable to upload a file.') . ($max_size ? " " . lang('Maximum allowed file size is %sB.', $max_size) : "") : lang('File does not exist.'));
e2a03c0 Show upload_max_filesize
jakubvrana authored Jul 16, 2009
168 }
169
4e5b126 Highlight odd and hover rows
jakubvrana authored Apr 30, 2009
170 function odd($s = ' class="odd"') {
171 static $i = 0;
172 if (!$s) { // reset counter
1b97f48 Reset odd() for each result
jakubvrana authored May 18, 2009
173 $i = -1;
4e5b126 Highlight odd and hover rows
jakubvrana authored Apr 30, 2009
174 }
1b97f48 Reset odd() for each result
jakubvrana authored May 18, 2009
175 return ($i++ % 2 ? $s : '');
4e5b126 Highlight odd and hover rows
jakubvrana authored Apr 30, 2009
176 }
177
fbebb08 Use separate connection for exploring indexes
jakubvrana authored Jun 3, 2009
178 function select($result, $dbh2 = null) {
ae372aa Database abstraction
jakubvrana authored Jul 10, 2007
179 if (!$result->num_rows) {
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
180 echo "<p class='message'>" . lang('No rows.') . "\n";
430034c Cottage homework
jakubvrana authored Jul 9, 2007
181 } else {
be8f88e Don't wrap select results
jakubvrana authored Jun 11, 2009
182 echo "<table cellspacing='0' class='nowrap'>\n";
64ba924 Comments
jakubvrana authored Jun 21, 2009
183 $links = array(); // colno => orgtable - create links from these columns
184 $indexes = array(); // orgtable => array(column => colno) - primary keys
185 $columns = array(); // orgtable => array(column => ) - not selected columns in primary key
186 $blobs = array(); // colno => bool - display bytes for blobs
187 $types = array(); // colno => type - display char in <code>
188 odd(''); // reset odd for each result
ae372aa Database abstraction
jakubvrana authored Jul 10, 2007
189 for ($i=0; $row = $result->fetch_row(); $i++) {
430034c Cottage homework
jakubvrana authored Jul 9, 2007
190 if (!$i) {
191 echo "<thead><tr>";
192 for ($j=0; $j < count($row); $j++) {
ae372aa Database abstraction
jakubvrana authored Jul 10, 2007
193 $field = $result->fetch_field();
038e688 Primary key flag is not always set
jakubvrana authored Jul 19, 2007
194 if (strlen($field->orgtable)) {
ae372aa Database abstraction
jakubvrana authored Jul 10, 2007
195 if (!isset($indexes[$field->orgtable])) {
64ba924 Comments
jakubvrana authored Jun 21, 2009
196 // find primary key in each table
ae372aa Database abstraction
jakubvrana authored Jul 10, 2007
197 $indexes[$field->orgtable] = array();
fbebb08 Use separate connection for exploring indexes
jakubvrana authored Jun 3, 2009
198 foreach (indexes($field->orgtable, $dbh2) as $index) {
430034c Cottage homework
jakubvrana authored Jul 9, 2007
199 if ($index["type"] == "PRIMARY") {
ae372aa Database abstraction
jakubvrana authored Jul 10, 2007
200 $indexes[$field->orgtable] = array_flip($index["columns"]);
430034c Cottage homework
jakubvrana authored Jul 9, 2007
201 break;
202 }
203 }
ae372aa Database abstraction
jakubvrana authored Jul 10, 2007
204 $columns[$field->orgtable] = $indexes[$field->orgtable];
430034c Cottage homework
jakubvrana authored Jul 9, 2007
205 }
a01944e Primary key links
jakubvrana authored Jul 10, 2007
206 if (isset($columns[$field->orgtable][$field->orgname])) {
207 unset($columns[$field->orgtable][$field->orgname]);
208 $indexes[$field->orgtable][$field->orgname] = $j;
209 $links[$j] = $field->orgtable;
210 }
430034c Cottage homework
jakubvrana authored Jul 9, 2007
211 }
ae372aa Database abstraction
jakubvrana authored Jul 10, 2007
212 if ($field->charsetnr == 63) {
430034c Cottage homework
jakubvrana authored Jul 9, 2007
213 $blobs[$j] = true;
214 }
ae6892d Display char type in <code>
jakubvrana authored Jul 15, 2007
215 $types[$j] = $field->type;
689699a Shortcut for htmlspecialchars
jakubvrana authored Jul 28, 2009
216 echo "<th>" . h($field->name);
430034c Cottage homework
jakubvrana authored Jul 9, 2007
217 }
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
218 echo "</thead>\n";
430034c Cottage homework
jakubvrana authored Jul 9, 2007
219 }
4e5b126 Highlight odd and hover rows
jakubvrana authored Apr 30, 2009
220 echo "<tr" . odd() . ">";
430034c Cottage homework
jakubvrana authored Jul 9, 2007
221 foreach ($row as $key => $val) {
222 if (!isset($val)) {
223 $val = "<i>NULL</i>";
224 } else {
017ffb5 Better UTF-8 detection
jakubvrana authored Jun 11, 2009
225 if ($blobs[$key] && !is_utf8($val)) {
8251896 Downloaded file name
jakubvrana authored Jun 11, 2009
226 $val = "<i>" . lang('%d byte(s)', strlen($val)) . "</i>"; //! link to download
a69fff7 Print \n as <br />, not &nbsp;
jakubvrana authored Jun 21, 2009
227 } elseif (!strlen(trim($val, " \t"))) {
64ba924 Comments
jakubvrana authored Jun 21, 2009
228 $val = "&nbsp;"; // some content to print a border
e9ee9b8 Reformat
jakubvrana authored Jul 13, 2007
229 } else {
689699a Shortcut for htmlspecialchars
jakubvrana authored Jul 28, 2009
230 $val = nl2br(h($val));
ae6892d Display char type in <code>
jakubvrana authored Jul 15, 2007
231 if ($types[$key] == 254) {
232 $val = "<code>$val</code>";
233 }
e9ee9b8 Reformat
jakubvrana authored Jul 13, 2007
234 }
430034c Cottage homework
jakubvrana authored Jul 9, 2007
235 if (isset($links[$key]) && !$columns[$links[$key]]) {
236 $link = "edit=" . urlencode($links[$key]);
237 foreach ($indexes[$links[$key]] as $col => $j) {
98507da Function verify_version doesn't use version parameter
jakubvrana authored Jul 30, 2009
238 $link .= "&where" . urlencode("[" . bracket_escape($col) . "]") . "=" . urlencode($row[$j]);
430034c Cottage homework
jakubvrana authored Jul 9, 2007
239 }
98507da Function verify_version doesn't use version parameter
jakubvrana authored Jul 30, 2009
240 $val = "<a href='" . h(ME . $link) . "'>$val</a>";
430034c Cottage homework
jakubvrana authored Jul 9, 2007
241 }
242 }
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
243 echo "<td>$val";
430034c Cottage homework
jakubvrana authored Jul 9, 2007
244 }
245 }
246 echo "</table>\n";
247 }
ae372aa Database abstraction
jakubvrana authored Jul 10, 2007
248 $result->free();
73e8631 Move stuff to functions.inc.php
jakubvrana authored Jul 9, 2007
249 }
250
017ffb5 Better UTF-8 detection
jakubvrana authored Jun 11, 2009
251 function is_utf8($val) {
64ba924 Comments
jakubvrana authored Jun 21, 2009
252 // don't print control chars except \t\r\n
017ffb5 Better UTF-8 detection
jakubvrana authored Jun 11, 2009
253 return (preg_match('~~u', $val) && !preg_match('~[\\0-\\x8\\xB\\xC\\xE-\\x1F]~', $val));
254 }
255
cd07584 Save SQL query to history
jakubvrana authored Jun 15, 2009
256 function shorten_utf8($string, $length = 80, $suffix = "") {
95764b0 Shorten binary strings
jakubvrana authored Aug 25, 2009
257 if (!preg_match("~^((?:.|\n){0,$length})(.|\n)?~u", $string, $match)) { // ~s causes trash in $match[2] under some PHP versions
258 preg_match("(^([\t\r\n -~]{0,$length})(.?))s", $string, $match);
259 }
689699a Shortcut for htmlspecialchars
jakubvrana authored Jul 28, 2009
260 return h($match[1]) . $suffix . ($match[2] ? "<em>...</em>" : "");
02a851c Shorten texts in PHP
jakubvrana authored Aug 24, 2007
261 }
3920ebb Remove InnoDB table comment in Tables and views
jakubvrana authored Oct 3, 2008
262
8251896 Downloaded file name
jakubvrana authored Jun 11, 2009
263 function friendly_url($val) {
64ba924 Comments
jakubvrana authored Jun 21, 2009
264 // used for blobs and export
8251896 Downloaded file name
jakubvrana authored Jun 11, 2009
265 return preg_replace('~[^a-z0-9_]~i', '-', $val);
266 }
267
820c882 Bulk clone
jakubvrana authored Oct 9, 2008
268 function hidden_fields($process, $ignore = array()) {
5d7071a Choose language through option-list
jakubvrana authored Oct 3, 2008
269 while (list($key, $val) = each($process)) {
270 if (is_array($val)) {
271 foreach ($val as $k => $v) {
272 $process[$key . "[$k]"] = $v;
273 }
274 } elseif (!in_array($key, $ignore)) {
689699a Shortcut for htmlspecialchars
jakubvrana authored Jul 28, 2009
275 echo '<input type="hidden" name="' . h($key) . '" value="' . h($val) . '">';
5d7071a Choose language through option-list
jakubvrana authored Oct 3, 2008
276 }
277 }
278 }
61640ee Move common functions
jakubvrana authored Jul 3, 2009
279
1e4d11e Select from foreign keys in Editor
jakubvrana authored Jul 23, 2009
280 function column_foreign_keys($table) {
281 $return = array();
282 foreach (foreign_keys($table) as $foreign_key) {
283 foreach ($foreign_key["source"] as $val) {
284 $return[$val][] = $foreign_key;
285 }
286 }
287 return $return;
288 }
289
290 function input($field, $value, $function) {
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
291 global $types, $adminer;
689699a Shortcut for htmlspecialchars
jakubvrana authored Jul 28, 2009
292 $name = h(bracket_escape($field["field"]));
61640ee Move common functions
jakubvrana authored Jul 3, 2009
293 echo "<td class='function'>";
294 if ($field["type"] == "enum") {
cb6d36c HTML instead of XHTML
jakubvrana authored Jul 28, 2009
295 echo "&nbsp;<td>" . (isset($_GET["select"]) ? " <label><input type='radio' name='fields[$name]' value='-1' checked><em>" . lang('original') . "</em></label>" : "");
4cead56 Edit default values directly in table creation
jakubvrana authored Aug 21, 2009
296 if ($field["null"]) {
cb6d36c HTML instead of XHTML
jakubvrana authored Jul 28, 2009
297 echo " <label><input type='radio' name='fields[$name]' value=''" . (($field["null"] ? isset($value) : strlen($value)) || isset($_GET["select"]) ? '' : ' checked') . '>' . ($field["null"] ? '<em>NULL</em>' : '') . '</label>';
61640ee Move common functions
jakubvrana authored Jul 3, 2009
298 }
4cead56 Edit default values directly in table creation
jakubvrana authored Aug 21, 2009
299 echo "<input type='radio' name='fields[$name]' value='0'" . ($value === 0 ? ' checked' : '') . '>';
26c9d64 Fix long SQL query crash (bug #2839231)
jakubvrana authored Aug 19, 2009
300 preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
61640ee Move common functions
jakubvrana authored Jul 3, 2009
301 foreach ($matches[1] as $i => $val) {
302 $val = stripcslashes(str_replace("''", "'", $val));
303 $checked = (is_int($value) ? $value == $i+1 : $value === $val);
4cead56 Edit default values directly in table creation
jakubvrana authored Aug 21, 2009
304 echo " <label><input type='radio' name='fields[$name]' value='" . ($i+1) . "'" . ($checked ? ' checked' : '') . '>' . h($val) . '</label>';
61640ee Move common functions
jakubvrana authored Jul 3, 2009
305 }
306 } else {
9fc052b Unselect original after value input
jakubvrana authored Jul 28, 2009
307 $functions = (isset($_GET["select"]) ? array("orig" => lang('original')) : array()) + $adminer->editFunctions($field);
308 $first = array_search("", $functions) + (isset($_GET["select"]) ? 1 : 0);
689699a Shortcut for htmlspecialchars
jakubvrana authored Jul 28, 2009
309 $onchange = ($first ? " onchange=\"var f = this.form['function[" . addcslashes($name, "\r\n'\\") . "]']; if ($first > f.selectedIndex) f.selectedIndex = $first;\"" : "");
c196985 Function nbsp
jakubvrana authored Aug 25, 2009
310 echo (count($functions) > 1 ? "<select name='function[$name]'>" . optionlist($functions, $function) . "</select>" : nbsp($functions[0])) . '<td>';
689699a Shortcut for htmlspecialchars
jakubvrana authored Jul 28, 2009
311 $input = $adminer->editInput($_GET["edit"], $field, " name='fields[$name]'$onchange", $value); // usage in call is without a table
e1abcda Treat tinyint(1) as boolean
jakubvrana authored Jul 28, 2009
312 if (strlen($input)) {
313 echo $input;
1e4d11e Select from foreign keys in Editor
jakubvrana authored Jul 23, 2009
314 } elseif ($field["type"] == "set") { //! 64 bits
26c9d64 Fix long SQL query crash (bug #2839231)
jakubvrana authored Aug 19, 2009
315 preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
61640ee Move common functions
jakubvrana authored Jul 3, 2009
316 foreach ($matches[1] as $i => $val) {
317 $val = stripcslashes(str_replace("''", "'", $val));
318 $checked = (is_int($value) ? ($value >> $i) & 1 : in_array($val, explode(",", $value), true));
4cead56 Edit default values directly in table creation
jakubvrana authored Aug 21, 2009
319 echo " <label><input type='checkbox' name='fields[$name][$i]' value='" . (1 << $i) . "'" . ($checked ? ' checked' : '') . "$onchange>" . h($val) . '</label>';
61640ee Move common functions
jakubvrana authored Jul 3, 2009
320 }
321 } elseif (strpos($field["type"], "text") !== false) {
689699a Shortcut for htmlspecialchars
jakubvrana authored Jul 28, 2009
322 echo "<textarea name='fields[$name]' cols='50' rows='12'$onchange>" . h($value) . '</textarea>';
5abd943 Change simple preg_match to ereg
jakubvrana authored Jul 13, 2009
323 } elseif (ereg('binary|blob', $field["type"])) {
689699a Shortcut for htmlspecialchars
jakubvrana authored Jul 28, 2009
324 echo (ini_get("file_uploads") ? "<input type='file' name='$name'$onchange>" : lang('File uploads are disabled.'));
61640ee Move common functions
jakubvrana authored Jul 3, 2009
325 } else {
326 // int(3) is only a display hint
327 $maxlength = (!ereg('int', $field["type"]) && preg_match('~^([0-9]+)(,([0-9]+))?$~', $field["length"], $match) ? ($match[1] + ($match[3] ? 1 : 0) + ($match[2] && !$field["unsigned"] ? 1 : 0)) : ($types[$field["type"]] ? $types[$field["type"]] + ($field["unsigned"] ? 0 : 1) : 0));
689699a Shortcut for htmlspecialchars
jakubvrana authored Jul 28, 2009
328 echo "<input name='fields[$name]' value='" . h($value) . "'" . ($maxlength ? " maxlength='$maxlength'" : "") . "$onchange>";
61640ee Move common functions
jakubvrana authored Jul 3, 2009
329 }
330 }
331 }
332
a0def47 Date localization
jakubvrana authored Jul 27, 2009
333 function process_input($field) {
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
334 global $dbh, $adminer;
a0def47 Date localization
jakubvrana authored Jul 27, 2009
335 $idf = bracket_escape($field["field"]);
61640ee Move common functions
jakubvrana authored Jul 3, 2009
336 $function = $_POST["function"][$idf];
337 $value = $_POST["fields"][$idf];
338 if ($field["type"] == "enum" ? $value == -1 : $function == "orig") {
339 return false;
340 } elseif ($field["type"] == "enum" || $field["auto_increment"] ? !strlen($value) : $function == "NULL") {
341 return "NULL";
342 } elseif ($field["type"] == "enum") {
4cead56 Edit default values directly in table creation
jakubvrana authored Aug 21, 2009
343 return intval($value);
61640ee Move common functions
jakubvrana authored Jul 3, 2009
344 } elseif ($field["type"] == "set") {
4cead56 Edit default values directly in table creation
jakubvrana authored Aug 21, 2009
345 return array_sum((array) $value);
5abd943 Change simple preg_match to ereg
jakubvrana authored Jul 13, 2009
346 } elseif (ereg('binary|blob', $field["type"])) {
61640ee Move common functions
jakubvrana authored Jul 3, 2009
347 $file = get_file($idf);
348 if (!is_string($file)) {
349 return false; //! report errors
350 }
572d86c Change simple preg_match to ereg
jakubvrana authored Jul 15, 2009
351 return "_binary" . $dbh->quote($file);
61640ee Move common functions
jakubvrana authored Jul 3, 2009
352 } else {
a0def47 Date localization
jakubvrana authored Jul 27, 2009
353 return $adminer->processInput($field, $value, $function);
61640ee Move common functions
jakubvrana authored Jul 3, 2009
354 }
355 }
356
357 function dump_csv($row) {
358 foreach ($row as $key => $val) {
359 if (preg_match("~[\"\n,]~", $val) || (isset($val) && !strlen($val))) {
360 $row[$key] = '"' . str_replace('"', '""', $val) . '"';
361 }
362 }
363 echo implode(",", $row) . "\n";
364 }
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
365
e331067 Move apply_sql_function
jakubvrana authored Aug 18, 2009
366 function apply_sql_function($function, $column) {
367 return ($function ? ($function == "count distinct" ? "COUNT(DISTINCT " : strtoupper("$function(")) . "$column)" : $column);
368 }
369
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
370 function is_email($email) {
371 $atom = '[-a-z0-9!#$%&\'*+/=?^_`{|}~]'; // characters of local-name
372 $domain = '[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])'; // one domain component
373 return eregi("^$atom+(\\.$atom+)*@($domain?\\.)+$domain\$", $email);
374 }
375
376 function email_header($header) {
473c3a2 Fix email_header
jakubvrana authored Jul 12, 2009
377 // iconv_mime_encode requires PHP 5, imap_8bit requires IMAP extension
378 return "=?UTF-8?B?" . base64_encode($header) . "?="; //! split long lines
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
379 }
Something went wrong with that request. Please try again.