Skip to content

HTTPS clone URL

Subversion checkout URL

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