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