bug #1715709 export in SQL format always includes procedures and functions
[phpmyadmin/crack.git] / tbl_change.php
blobd58c6aef595b2af68a35dc16ed65a5fde70b8d42
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 */
8 /**
9 * Gets the variables sent or posted to this script and displays the header
11 require_once './libraries/common.inc.php';
13 /**
14 * Sets global variables.
15 * Here it's better to use a if, instead of the '?' operator
16 * to avoid setting a variable to '' when it's not present in $_REQUEST
18 /**
19 * @todo this one is badly named, it's really a WHERE condition
20 * and exists even for tables not having a primary key or unique key
22 if (isset($_REQUEST['primary_key'])) {
23 $primary_key = $_REQUEST['primary_key'];
25 if (isset($_SESSION['edit_next'])) {
26 $primary_key = $_SESSION['edit_next'];
27 unset($_SESSION['edit_next']);
28 $after_insert = 'edit_next';
30 if (isset($_REQUEST['sql_query'])) {
31 $sql_query = $_REQUEST['sql_query'];
33 if (isset($_REQUEST['ShowFunctionFields'])) {
34 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
38 $js_to_run = 'tbl_change.js';
39 require_once './libraries/header.inc.php';
40 require_once './libraries/relation.lib.php'; // foreign keys
41 require_once './libraries/file_listing.php'; // file listing
44 /**
45 * Displays the query submitted and its result
47 if (! empty($disp_message)) {
48 if (! isset($disp_query)) {
49 $disp_query = null;
51 PMA_showMessage($disp_message, $disp_query);
55 /**
56 * Defines the url to return to in case of error in a sql statement
57 * (at this point, $goto might be set but empty)
59 if (empty($goto)) {
60 $goto = 'db_sql.php';
62 /**
63 * @todo check if we could replace by "db_|tbl_"
65 if (!preg_match('@^(db|tbl)_@', $goto)) {
66 $err_url = $goto . "?" . PMA_generate_common_url($db) . "&amp;sql_query=" . urlencode($sql_query);
67 } else {
68 $err_url = $goto . '?'
69 . PMA_generate_common_url($db)
70 . ((preg_match('@^(tbl_)@', $goto)) ? '&amp;table=' . urlencode($table) : '');
74 /**
75 * Ensures db and table are valid, else moves to the "parent" script
77 require_once './libraries/db_table_exists.lib.php';
80 /**
81 * Sets parameters for links
83 $url_query = PMA_generate_common_url($db, $table)
84 . '&amp;goto=tbl_sql.php';
86 require_once './libraries/tbl_info.inc.php';
88 /* Get comments */
90 $comments_map = array();
92 if ($GLOBALS['cfg']['ShowPropertyComments']) {
93 require_once './libraries/relation.lib.php';
94 require_once './libraries/transformations.lib.php';
96 $cfgRelation = PMA_getRelationsParam();
98 if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
99 $comments_map = PMA_getComments($db, $table);
104 * Displays top menu links
106 require_once './libraries/tbl_links.inc.php';
110 * Get the analysis of SHOW CREATE TABLE for this table
112 $show_create_table = PMA_DBI_fetch_value(
113 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
114 0, 1);
115 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
116 unset($show_create_table);
119 * Get the list of the fields of the current table
121 PMA_DBI_select_db($db);
122 $table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
123 if (isset($primary_key)) {
124 if (is_array($primary_key)) {
125 $primary_key_array = $primary_key;
126 } else {
127 $primary_key_array = array(0 => $primary_key);
130 $row = array();
131 $result = array();
132 $found_unique_key = false;
133 foreach ($primary_key_array as $rowcount => $primary_key) {
134 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';';
135 $result[$rowcount] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
136 $row[$rowcount] = PMA_DBI_fetch_assoc($result[$rowcount]);
137 $primary_keys[$rowcount] = str_replace('\\', '\\\\', $primary_key);
139 // No row returned
140 if (!$row[$rowcount]) {
141 unset($row[$rowcount], $primary_key_array[$rowcount]);
142 PMA_showMessage($strEmptyResultSet, $local_query);
143 echo "\n";
144 require_once './libraries/footer.inc.php';
145 } else { // end if (no record returned)
146 $meta = PMA_DBI_get_fields_meta($result[$rowcount]);
147 if ($tmp = PMA_getUniqueCondition($result[$rowcount], count($meta), $meta, $row[$rowcount], true)) {
148 $found_unique_key = true;
150 unset($tmp);
153 } else {
154 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
155 unset($row);
158 // <markus@noga.de>
159 // retrieve keys into foreign fields, if any
160 $cfgRelation = PMA_getRelationsParam();
161 $foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE);
165 * Displays the form
167 // loic1: autocomplete feature of IE kills the "onchange" event handler and it
168 // must be replaced by the "onpropertychange" one in this case
169 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5)
170 ? 'onpropertychange'
171 : 'onchange';
172 // Had to put the URI because when hosted on an https server,
173 // some browsers send wrongly this form to the http server.
176 <?php if ($cfg['CtrlArrowsMoving']) { ?>
177 <!-- Set on key handler for moving using by Ctrl+arrows -->
178 <script src="./js/keyhandler.js" type="text/javascript"></script>
179 <script type="text/javascript">
180 //<![CDATA[
181 var switch_movement = 0;
182 document.onkeydown = onKeyDownArrowsHandler;
183 //]]>
184 </script>
185 <?php } ?>
187 <!-- Change table properties form -->
188 <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
189 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
190 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($goto); ?>" />
191 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
192 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
193 <?php
194 if (isset($primary_keys)) {
195 foreach ($primary_key_array as $rowcount => $primary_key) {
196 echo '<input type="hidden" name="primary_key[' . $rowcount . ']" value="' . htmlspecialchars(trim($primary_key)) . '" />'. "\n";
199 echo "\n";
201 if ($cfg['PropertiesIconic'] === true || $cfg['PropertiesIconic'] === 'both') {
202 if ($cfg['PropertiesIconic'] === 'both') {
203 $iconic_spacer = '<div class="nowrap">';
204 } else {
205 $iconic_spacer = '';
208 $titles['Browse'] = $iconic_spacer . '<img width="16" height="16" src="' . $pmaThemeImage . 'b_browse.png" alt="' . $strBrowseForeignValues . '" title="' . $strBrowseForeignValues . '" border="0" />';
210 if ($cfg['PropertiesIconic'] === 'both') {
211 $titles['Browse'] .= '&nbsp;' . $strBrowseForeignValues . '</div>';
213 } else {
214 $titles['Browse'] = $strBrowseForeignValues;
217 // Set if we passed the first timestamp field
218 $timestamp_seen = 0;
219 $fields_cnt = PMA_DBI_num_rows($table_def);
221 // Set a flag here because the 'if' would not be valid in the loop
222 // if we set a value in some field
223 $insert_mode = (!isset($row) ? TRUE : FALSE);
224 if ($insert_mode) {
225 $loop_array = array();
226 for ($i = 0; $i < $cfg['InsertRows']; $i++) {
227 $loop_array[] = FALSE;
229 } else {
230 $loop_array = $row;
233 while ($trow = PMA_DBI_fetch_assoc($table_def)) {
234 $trow_table_def[] = $trow;
237 $tabindex = 0;
238 $tabindex_for_function = +1000;
239 $tabindex_for_null = +2000;
240 $tabindex_for_value = 0;
241 $o_rows = 0;
242 $biggest_max_file_size = 0;
244 // user can toggle the display of Function column
245 // (currently does not work for multi-edits)
246 $url_params['db'] = $db;
247 $url_params['table'] = $table;
248 if (isset($primary_key)) {
249 $url_params['primary_key'] = trim($primary_key);
251 if (! empty($sql_query)) {
252 $url_params['sql_query'] = $sql_query;
255 if (! $cfg['ShowFunctionFields']) {
256 $this_url_params = array_merge($url_params,
257 array('ShowFunctionFields' => 1));
258 echo $strShow . ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . $strFunction . '</a>' . "\n";
261 foreach ($loop_array as $vrowcount => $vrow) {
262 if ($vrow === FALSE) {
263 unset($vrow);
266 $jsvkey = $vrowcount;
267 $browse_foreigners_uri = '&amp;pk=' . $vrowcount;
268 $vkey = '[multi_edit][' . $jsvkey . ']';
270 $vresult = (isset($result) && is_array($result) && isset($result[$vrowcount]) ? $result[$vrowcount] : $result);
271 if ($insert_mode && $vrowcount > 0) {
272 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $vrowcount . '" id="insert_ignore_check_' . $vrowcount . '" />';
273 echo '<label for="insert_ignore_check_' . $vrowcount . '">' . $strIgnore . '</label><br />' . "\n";
276 <table>
277 <tr>
278 <th><?php echo $strField; ?></th>
279 <th><?php echo $strType; ?></th>
280 <?php
281 if ($cfg['ShowFunctionFields']) {
282 $this_url_params = array_merge($url_params,
283 array('ShowFunctionFields' => 0));
284 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . $strHide . '">' . $strFunction . '</a></th>' . "\n";
287 <th><?php echo $strNull; ?></th>
288 <th><?php echo $strValue; ?></th>
289 </tr>
290 <?php
292 // garvin: For looping on multiple rows, we need to reset any variable used inside the loop to indicate sth.
293 $timestamp_seen = 0;
294 unset($first_timestamp);
296 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
297 $m_rows = $o_rows + 1;
299 $odd_row = true;
300 for ($i = 0; $i < $fields_cnt; $i++) {
301 // Display the submit button after every 15 lines --swix
302 // (wanted to use an <a href="#bottom"> and <a name> instead,
303 // but it didn't worked because of the <base href>)
305 if ((($o_rows * $fields_cnt + $i) % 15 == 0) && ($i + $o_rows != 0)) {
307 <tr>
308 <th colspan="5" align="right" class="tblFooters">
309 <input type="submit" value="<?php echo $strGo; ?>" />&nbsp;
310 </th>
311 </tr>
312 <?php
313 } // end if
314 echo "\n";
316 $row_table_def = $trow_table_def[$i];
317 $row_table_def['True_Type'] = preg_replace('@\(.*@s', '', $row_table_def['Type']);
319 $field = $row_table_def['Field'];
320 $field_html = htmlspecialchars($field);
321 $field_md5 = md5($field);
323 $unnullify_trigger = $chg_evt_handler . "=\"return unNullify('" . PMA_escapeJsString($field_html) . "', '" . PMA_escapeJsString($jsvkey) . "')\"";
324 $field_name_appendix = $vkey . '[' . $field_html . ']';
325 $field_name_appendix_md5 = $field_md5 . $vkey . '[]';
328 // removed previous PHP3-workaround that caused a problem with
329 // field names like '000'
330 //$rowfield = $field;
332 // d a t e t i m e
334 // loic1: current date should not be set as default if the field is NULL
335 // for the current row
336 // lem9: but do not put here the current datetime if there is a default
337 // value (the real default value will be set in the
338 // Default value logic below)
340 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
341 // $row_table_def['Default'] is not set if it contains NULL:
342 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
343 // but, look what we get if we switch to iso: (Default is NULL)
344 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
345 // so I force a NULL into it (I don't think it's possible
346 // to have an empty default value for DATETIME)
347 // then, the "if" after this one will work
348 if ($row_table_def['Type'] == 'datetime'
349 && !isset($row_table_def['Default'])
350 && isset($row_table_def['Null'])
351 && $row_table_def['Null'] == 'YES') {
352 $row_table_def['Default'] = null;
355 if ($row_table_def['Type'] == 'datetime'
356 && (!isset($row_table_def['Default']))
357 && (!is_null($row_table_def['Default']))) {
358 // INSERT case
359 if ($insert_mode) {
360 if (isset($vrow)) {
361 $vrow[$field] = date('Y-m-d H:i:s', time());
362 } else {
363 $vrow = array($field => date('Y-m-d H:i:s', time()));
366 // UPDATE case with an empty and not NULL value under PHP4
367 elseif (empty($vrow[$field]) && is_null($vrow[$field])) {
368 $vrow[$field] = date('Y-m-d H:i:s', time());
369 } // end if... elseif...
371 $len = (preg_match('@float|double@', $row_table_def['Type']))
372 ? 100
373 : PMA_DBI_field_len($vresult, $i);
374 $first_timestamp = 0;
376 $field_name = $field_html;
377 if (isset($comments_map[$field])) {
378 $field_name = '<span style="border-bottom: 1px dashed black;" title="'
379 . htmlspecialchars($comments_map[$field]) . '">' . $field_name . '</span>';
383 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
384 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($row_table_def['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center"><?php echo $field_name; ?></td>
386 <?php
387 // The type column
388 $is_binary = stristr($row_table_def['Type'], 'binary');
389 $is_blob = stristr($row_table_def['Type'], 'blob');
390 $is_char = stristr($row_table_def['Type'], 'char');
391 switch ($row_table_def['True_Type']) {
392 case 'set':
393 $type = 'set';
394 $type_nowrap = '';
395 break;
396 case 'enum':
397 $type = 'enum';
398 $type_nowrap = '';
399 break;
400 case 'timestamp':
401 if (!$timestamp_seen) { // can only occur once per table
402 $timestamp_seen = 1;
403 $first_timestamp = 1;
405 $type = $row_table_def['Type'];
406 $type_nowrap = ' nowrap="nowrap"';
407 break;
409 default:
410 $type = $row_table_def['Type'];
411 $type_nowrap = ' nowrap="nowrap"';
412 break;
415 <td align="center"<?php echo $type_nowrap; ?>>
416 <?php echo $type; ?>
417 </td>
419 <?php
421 // Prepares the field value
422 $real_null_value = FALSE;
423 if (isset($vrow)) {
424 if (!isset($vrow[$field])
425 || (function_exists('is_null') && is_null($vrow[$field]))) {
426 $real_null_value = TRUE;
427 $vrow[$field] = '';
428 $special_chars = '';
429 $data = $vrow[$field];
430 } elseif ($row_table_def['True_Type'] == 'bit') {
431 $special_chars = '';
432 for ($j = 0; $j < ceil($len / 8); $j++) {
433 $special_chars .= sprintf('%08d', decbin(ord(substr($vrow[$field], $j, 1))));
435 $special_chars = substr($special_chars, -$len);
436 } else {
437 // loic1: special binary "characters"
438 if ($is_binary || $is_blob) {
439 $vrow[$field] = str_replace("\x00", '\0', $vrow[$field]);
440 $vrow[$field] = str_replace("\x08", '\b', $vrow[$field]);
441 $vrow[$field] = str_replace("\x0a", '\n', $vrow[$field]);
442 $vrow[$field] = str_replace("\x0d", '\r', $vrow[$field]);
443 $vrow[$field] = str_replace("\x1a", '\Z', $vrow[$field]);
444 } // end if
445 $special_chars = htmlspecialchars($vrow[$field]);
446 $data = $vrow[$field];
447 } // end if... else...
448 // loic1: if a timestamp field value is not included in an update
449 // statement MySQL auto-update it to the current timestamp
450 // lem9: however, things have changed since MySQL 4.1, so
451 // it's better to set a fields_prev in this situation
452 $backup_field = (PMA_MYSQL_INT_VERSION < 40100 && $row_table_def['True_Type'] == 'timestamp')
453 ? ''
454 : '<input type="hidden" name="fields_prev' . $field_name_appendix . '" value="' . htmlspecialchars($vrow[$field]) . '" />';
455 } else {
456 // loic1: display default values
457 if (!isset($row_table_def['Default'])) {
458 $row_table_def['Default'] = '';
459 $real_null_value = TRUE;
460 $data = '';
461 } else {
462 $data = $row_table_def['Default'];
464 $special_chars = htmlspecialchars($row_table_def['Default']);
465 $backup_field = '';
468 $idindex = ($o_rows * $fields_cnt) + $i + 1;
469 $tabindex = (($idindex - 1) * 3) + 1;
471 // The function column
472 // -------------------
473 // Change by Bernard M. Piller <bernard@bmpsystems.com>
474 // We don't want binary data to be destroyed
475 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
476 // stored or retrieved" so it does not mean that the contents is
477 // binary
478 if ($cfg['ShowFunctionFields']) {
479 if (($cfg['ProtectBinary'] && $is_blob && !$is_upload)
480 || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
481 echo ' <td align="center">' . $strBinary . '</td>' . "\n";
482 } elseif (strstr($row_table_def['True_Type'], 'enum') || strstr($row_table_def['True_Type'], 'set')) {
483 echo ' <td align="center">--</td>' . "\n";
484 } else {
486 <td>
487 <select name="funcs<?php echo $field_name_appendix; ?>" <?php echo $unnullify_trigger; ?> tabindex="<?php echo ($tabindex + $tabindex_for_function); ?>" id="field_<?php echo $idindex; ?>_1">
488 <option></option>
489 <?php
490 $selected = '';
492 // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
493 // or something similar. Then directly look up the entry in the RestrictFunctions array,
494 // which will then reveal the available dropdown options
495 if (isset($cfg['RestrictFunctions'])
496 && isset($cfg['RestrictColumnTypes'])
497 && isset($cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])])
498 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])]])) {
499 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])];
500 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
501 $default_function = $cfg['DefaultFunctions'][$current_func_type];
502 } else {
503 $dropdown = array();
504 $default_function = '';
507 $dropdown_built = array();
508 $op_spacing_needed = FALSE;
509 // garvin: loop on the dropdown array and print all available options for that field.
510 $cnt_dropdown = count($dropdown);
511 for ($j = 0; $j < $cnt_dropdown; $j++) {
512 // Is current function defined as default?
513 // For MySQL < 4.1.2, for the first timestamp we set as
514 // default function the one defined in config (which
515 // should be NOW()).
516 // For MySQL >= 4.1.2, we don't set the default function
517 // if there is a default value for the timestamp
518 // (not including CURRENT_TIMESTAMP)
519 // and the column does not have the
520 // ON UPDATE DEFAULT TIMESTAMP attribute.
522 if (PMA_MYSQL_INT_VERSION < 40102
523 || (PMA_MYSQL_INT_VERSION >= 40102
524 && !($row_table_def['True_Type'] == 'timestamp'
525 && !empty($row_table_def['Default'])
526 && !isset($analyzed_sql[0]['create_table_fields'][$field]['on_update_current_timestamp'])))) {
527 $selected = ($first_timestamp && $dropdown[$j] == $cfg['DefaultFunctions']['first_timestamp'])
528 || (!$first_timestamp && $dropdown[$j] == $default_function)
529 ? ' selected="selected"'
530 : '';
532 echo ' ';
533 echo '<option' . $selected . '>' . $dropdown[$j] . '</option>' . "\n";
534 $dropdown_built[$dropdown[$j]] = 'TRUE';
535 $op_spacing_needed = TRUE;
538 // garvin: For compatibility's sake, do not let out all other functions. Instead
539 // print a separator (blank) and then show ALL functions which weren't shown
540 // yet.
541 $cnt_functions = count($cfg['Functions']);
542 for ($j = 0; $j < $cnt_functions; $j++) {
543 if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
544 // Is current function defined as default?
545 $selected = ($first_timestamp && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
546 || (!$first_timestamp && $cfg['Functions'][$j] == $default_function)
547 ? ' selected="selected"'
548 : '';
549 if ($op_spacing_needed == TRUE) {
550 echo ' ';
551 echo '<option value="">--------</option>' . "\n";
552 $op_spacing_needed = FALSE;
555 echo ' ';
556 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
558 } // end for
559 unset($selected);
561 </select>
562 </td>
563 <?php
565 } // end if ($cfg['ShowFunctionFields'])
568 // The null column
569 // ---------------
570 echo ' <td>' . "\n";
571 if ($row_table_def['Null'] == 'YES') {
572 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
573 if ($real_null_value && !$first_timestamp) {
574 echo ' value="on"';
576 echo ' />' . "\n";
578 if (!(($cfg['ProtectBinary'] && $is_blob) || ($cfg['ProtectBinary'] == 'all' && $is_binary))) {
580 echo ' <input type="checkbox" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
581 . ' name="fields_null' . $field_name_appendix . '"';
582 if ($real_null_value && !$first_timestamp) {
583 echo ' checked="checked"';
585 echo ' id="field_' . ($idindex) . '_2"';
586 $onclick = ' onclick="if (this.checked) {nullify(';
587 if (strstr($row_table_def['True_Type'], 'enum')) {
588 if (strlen($row_table_def['Type']) > 20) {
589 $onclick .= '1, ';
590 } else {
591 $onclick .= '2, ';
593 } elseif (strstr($row_table_def['True_Type'], 'set')) {
594 $onclick .= '3, ';
595 } elseif ($foreigners && isset($foreigners[$field])) {
596 $onclick .= '4, ';
597 } else {
598 $onclick .= '5, ';
600 $onclick .= '\'' . PMA_escapeJsString($field_html) . '\', \'' . $field_md5 . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
601 echo $onclick;
602 } else {
603 echo ' <input type="hidden" name="fields_null' . $field_name_appendix . '"';
604 if ($real_null_value && !$first_timestamp) {
605 echo ' value="on"';
607 echo ' />' . "\n";
610 echo ' </td>' . "\n";
612 // The value column (depends on type)
613 // ----------------
615 require './libraries/get_foreign.lib.php';
617 if (isset($foreign_link) && $foreign_link == true) {
619 <td>
620 <?php echo $backup_field . "\n"; ?>
621 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
622 value="foreign" />
623 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
624 value="" id="field_<?php echo ($idindex); ?>_1" />
625 <input type="text" name="field_<?php echo $field_name_appendix_md5; ?>"
626 class="textfield" <?php echo $unnullify_trigger; ?>
627 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
628 id="field_<?php echo ($idindex); ?>_3"
629 value="<?php echo htmlspecialchars($data); ?>" />
630 <script type="text/javascript">
631 //<![CDATA[
632 document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
633 document.writeln(' href="browse_foreigners.php?');
634 document.writeln('<?php echo PMA_generate_common_url($db, $table); ?>');
635 document.writeln('&amp;field=<?php echo PMA_escapeJsString(urlencode($field) . $browse_foreigners_uri); ?>">');
636 document.writeln('<?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
637 //]]>
638 </script>
639 </td>
640 <?php
641 } elseif (isset($disp_row) && is_array($disp_row)) {
643 <td>
644 <?php echo $backup_field . "\n"; ?>
645 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
646 value="foreign" />
647 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
648 value="" id="field_<?php echo $idindex; ?>_1" />
649 <select name="field_<?php echo $field_name_appendix_md5; ?>"
650 <?php echo $unnullify_trigger; ?>
651 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
652 id="field_<?php echo ($idindex); ?>_3">
653 <?php echo PMA_foreignDropdown($disp_row, $foreign_field, $foreign_display, $data, $cfg['ForeignKeyMaxLimit']); ?>
654 </select>
655 </td>
656 <?php
657 unset($disp_row);
658 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($type, 'longtext')) {
660 <td>&nbsp;</td>
661 </tr>
662 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
663 <td colspan="5" align="right">
664 <?php echo $backup_field . "\n"; ?>
665 <textarea name="fields<?php echo $field_name_appendix; ?>"
666 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
667 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
668 dir="<?php echo $text_dir; ?>"
669 id="field_<?php echo ($idindex); ?>_3"
670 <?php echo $unnullify_trigger; ?>
671 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
672 ><?php echo $special_chars; ?></textarea>
673 </td>
674 <?php
675 } elseif (strstr($type, 'text')) {
677 <td>
678 <?php echo $backup_field . "\n"; ?>
679 <textarea name="fields<?php echo $field_name_appendix; ?>"
680 rows="<?php echo $cfg['TextareaRows']; ?>"
681 cols="<?php echo $cfg['TextareaCols']; ?>"
682 dir="<?php echo $text_dir; ?>"
683 id="field_<?php echo ($idindex); ?>_3"
684 <?php echo $unnullify_trigger; ?>
685 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
686 ><?php echo $special_chars; ?></textarea>
687 </td>
688 <?php
689 echo "\n";
690 if (strlen($special_chars) > 32000) {
691 echo ' <td>' . $strTextAreaLength . '</td>' . "\n";
693 } elseif ($type == 'enum') {
694 $enum = PMA_getEnumSetOptions($row_table_def['Type']);
695 $enum_cnt = count($enum);
697 <td>
698 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
699 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
700 <?php
701 echo "\n" . ' ' . $backup_field;
703 // show dropdown or radio depend on length
704 if (strlen($row_table_def['Type']) > 20) {
705 echo "\n";
707 <select name="field_<?php echo $field_name_appendix_md5; ?>"
708 <?php echo $unnullify_trigger; ?>
709 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
710 id="field_<?php echo ($idindex); ?>_3">
711 <option value=""></option>
712 <?php
713 echo "\n";
715 for ($j = 0; $j < $enum_cnt; $j++) {
716 // Removes automatic MySQL escape format
717 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
718 echo ' ';
719 //echo '<option value="' . htmlspecialchars($enum_atom) . '"';
720 echo '<option value="' . htmlspecialchars($enum_atom) . '"';
721 if ($data == $enum_atom
722 || ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
723 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
724 echo ' selected="selected"';
726 echo '>' . htmlspecialchars($enum_atom) . '</option>' . "\n";
727 } // end for
730 </select>
731 <?php
732 } else {
733 echo "\n";
734 for ($j = 0; $j < $enum_cnt; $j++) {
735 // Removes automatic MySQL escape format
736 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
737 echo ' ';
738 echo '<input type="radio" name="field_' . $field_name_appendix_md5 . '"';
739 echo ' value="' . htmlspecialchars($enum_atom) . '"';
740 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
741 echo ' onclick="';
742 echo "if (typeof(document.forms['insertForm'].elements['fields_null"
743 . $field_name_appendix . "']) != 'undefined') {document.forms['insertForm'].elements['fields_null"
744 . $field_name_appendix . "'].checked = false}";
745 echo '"';
746 if ($data == $enum_atom
747 || ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
748 && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
749 echo ' checked="checked"';
751 echo 'tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
752 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
753 . htmlspecialchars($enum_atom) . '</label>' . "\n";
754 } // end for
756 } // end else
757 echo "\n";
759 </td>
760 <?php
761 echo "\n";
762 } elseif ($type == 'set') {
763 $set = PMA_getEnumSetOptions($row_table_def['Type']);
765 if (isset($vset)) {
766 unset($vset);
768 for ($vals = explode(',', $data); list($t, $k) = each($vals);) {
769 $vset[$k] = 1;
771 $countset = count($set);
772 $size = min(4, $countset);
774 <td>
775 <?php echo $backup_field . "\n"; ?>
776 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
777 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
778 <select name="field_<?php echo $field_name_appendix_md5; ?>"
779 size="<?php echo $size; ?>"
780 multiple="multiple" <?php echo $unnullify_trigger; ?>
781 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
782 id="field_<?php echo ($idindex); ?>_3">
783 <?php
784 echo "\n";
785 for ($j = 0; $j < $countset; $j++) {
786 echo ' ';
787 //echo '<option value="'. htmlspecialchars($set[$j]) . '"';
788 echo '<option value="'. htmlspecialchars($set[$j]) . '"';
789 if (isset($vset[$set[$j]]) && $vset[$set[$j]]) {
790 echo ' selected="selected"';
792 echo '>' . htmlspecialchars($set[$j]) . '</option>' . "\n";
793 } // end for
795 </select>
796 </td>
797 <?php
799 // Change by Bernard M. Piller <bernard@bmpsystems.com>
800 // We don't want binary data destroyed
801 elseif ($is_binary || $is_blob) {
802 if (($cfg['ProtectBinary'] && $is_blob)
803 || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
804 echo "\n";
806 <td>
807 <?php
808 echo $strBinaryDoNotEdit;
809 if (isset($data)) {
810 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
811 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
812 unset($data_size);
814 echo "\n";
816 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
817 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
818 <?php
819 } elseif ($is_blob) {
820 echo "\n";
822 <td>
823 <?php echo $backup_field . "\n"; ?>
824 <textarea name="fields<?php echo $field_name_appendix; ?>"
825 rows="<?php echo $cfg['TextareaRows']; ?>"
826 cols="<?php echo $cfg['TextareaCols']; ?>"
827 dir="<?php echo $text_dir; ?>"
828 id="field_<?php echo ($idindex); ?>_3"
829 <?php echo $unnullify_trigger; ?>
830 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
831 ><?php echo $special_chars; ?></textarea>
832 <?php
834 } else {
835 // field size should be at least 4 and max 40
836 $fieldsize = min(max($len, 4), 40);
837 echo "\n";
839 <td>
840 <?php echo $backup_field . "\n"; ?>
841 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
842 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
843 class="textfield" <?php echo $unnullify_trigger; ?>
844 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
845 id="field_<?php echo ($idindex); ?>_3" />
846 <?php
847 } // end if...elseif...else
849 // Upload choice (only for BLOBs because the binary
850 // attribute does not imply binary contents)
851 // (displayed whatever value the ProtectBinary has)
853 if ($is_upload && $is_blob) {
854 echo '<br />';
855 echo '<input type="file" name="fields_upload_' . $field_html . $vkey . '" class="textfield" id="field_' . $idindex . '_3" size="10" />&nbsp;';
857 // find maximum upload size, based on field type
859 * @todo with functions this is not so easy, as you can basically
860 * process any data with function like MD5
862 $max_field_sizes = array(
863 'tinyblob' => '256',
864 'blob' => '65536',
865 'mediumblob' => '16777216',
866 'longblob' => '4294967296'); // yeah, really
868 $this_field_max_size = $max_upload_size; // from PHP max
869 if ($this_field_max_size > $max_field_sizes[$type]) {
870 $this_field_max_size = $max_field_sizes[$type];
872 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
873 // do not generate here the MAX_FILE_SIZE, because we should
874 // put only one in the form to accommodate the biggest field
875 if ($this_field_max_size > $biggest_max_file_size) {
876 $biggest_max_file_size = $this_field_max_size;
880 if (!empty($cfg['UploadDir'])) {
881 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
882 if ($files === FALSE) {
883 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
884 echo ' ' . $strWebServerUploadDirectoryError . "\n";
885 } elseif (!empty($files)) {
886 echo "<br />\n";
887 echo ' <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ':<br />' . "\n";
888 echo ' <select size="1" name="fields_uploadlocal_' . $field_html . $vkey . '">' . "\n";
889 echo ' <option value="" selected="selected"></option>' . "\n";
890 echo $files;
891 echo ' </select>' . "\n";
893 } // end if (web-server upload directory)
895 echo '</td>';
897 } // end elseif (binary or blob)
898 else {
899 // field size should be at least 4 and max 40
900 $fieldsize = min(max($len, 4), 40);
902 <td>
903 <?php
904 echo $backup_field . "\n";
905 if ($is_char && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== FALSE)) {
906 echo "\n";
908 <textarea name="fields<?php echo $field_name_appendix; ?>"
909 rows="<?php echo $cfg['CharTextareaRows']; ?>"
910 cols="<?php echo $cfg['CharTextareaCols']; ?>"
911 dir="<?php echo $text_dir; ?>"
912 id="field_<?php echo ($idindex); ?>_3"
913 <?php echo $unnullify_trigger; ?>
914 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
915 ><?php echo $special_chars; ?></textarea>
916 <?php
917 } else {
919 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
920 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
921 class="textfield" <?php echo $unnullify_trigger; ?>
922 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
923 id="field_<?php echo ($idindex); ?>_3" />
924 <?php
925 if ($row_table_def['Extra'] == 'auto_increment') {
927 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
928 <?php
929 } // end if
930 if (substr($type, 0, 9) == 'timestamp') {
932 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
933 <?php
935 if ($row_table_def['True_Type'] == 'bit') {
937 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
938 <?php
940 if ($type == 'date' || $type == 'datetime' || substr($type, 0, 9) == 'timestamp') {
942 <script type="text/javascript">
943 //<![CDATA[
944 document.write('<a title="<?php echo $strCalendar;?>"');
945 document.write(' href="javascript:openCalendar(\'<?php echo PMA_generate_common_url();?>\', \'insertForm\', \'field_<?php echo ($idindex); ?>_3\', \'<?php echo (PMA_MYSQL_INT_VERSION >= 40100 && substr($type, 0, 9) == 'timestamp') ? 'datetime' : substr($type, 0, 9); ?>\')">');
946 document.write('<img class="calendar"');
947 document.write(' src="<?php echo $pmaThemeImage; ?>b_calendar.png"');
948 document.write(' alt="<?php echo $strCalendar; ?>"/></a>');
949 //]]>
950 </script>
951 <?php
955 </td>
956 <?php
959 </tr>
960 <?php
961 $odd_row = !$odd_row;
962 } // end for
963 $o_rows++;
964 echo ' </table><br />';
965 } // end foreach on multi-edit
967 if ($insert_mode) {
968 $tmp = '<select name="insert_rows" id="insert_rows" onchange="this.form.submit();" />' . "\n";
969 $option_values = array(1,2,5,10,15,20,30,40);
970 foreach ($option_values as $value) {
971 $tmp .= '<option value="' . $value . '"';
972 if ($value == $cfg['InsertRows']) {
973 $tmp .= ' selected="selected"';
975 $tmp .= '>' . $value . '</option>' . "\n";
977 $tmp .= '</select>' . "\n";
978 echo "\n" . sprintf($strRestartInsertion, $tmp);
979 unset($tmp);
980 echo '<noscript><input type="submit" value="' . $strGo . '" /></noscript>' . "\n";
983 <br />
985 <table border="0" cellpadding="5" cellspacing="0">
986 <tr>
987 <td valign="middle" nowrap="nowrap">
988 <select name="submit_type" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
989 <?php
990 if (isset($primary_key)) {
992 <option value="<?php echo $strSave; ?>"><?php echo $strSave; ?></option>
993 <?php
996 <option value="<?php echo $strInsertAsNewRow; ?>"><?php echo $strInsertAsNewRow; ?></option>
997 </select>
998 <?php
999 echo "\n";
1001 if (!isset($after_insert)) {
1002 $after_insert = 'back';
1005 </td>
1006 <td valign="middle">
1007 &nbsp;&nbsp;&nbsp;<b><?php echo $strAndThen; ?></b>&nbsp;&nbsp;&nbsp;
1008 </td>
1009 <td valign="middle" nowrap="nowrap">
1010 <select name="after_insert">
1011 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertBack; ?></option>
1012 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNewInsert; ?></option>
1013 <?php
1014 if (isset($primary_key)) {
1016 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertSame; ?></option>
1017 <?php
1018 // If we have just numeric primary key, we can also edit next
1019 // in 2.8.2, we were looking for `field_name` = numeric_value
1020 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $primary_key)) {
1021 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1022 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $primary_key)) {
1024 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNext; ?></option>
1025 <?php
1029 </select>
1030 </td>
1031 </tr>
1033 <tr>
1034 <td>
1035 <?php echo PMA_showHint($strUseTabKey); ?>
1036 </td>
1037 <td colspan="3" align="right" valign="middle">
1038 <input type="submit" value="<?php echo $strGo; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1039 <input type="reset" value="<?php echo $strReset; ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1040 </td>
1041 </tr>
1042 </table>
1043 <?php if ($biggest_max_file_size > 0) {
1044 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1045 } ?>
1047 </form>
1049 <?php
1051 * Displays the footer
1053 require_once './libraries/footer.inc.php';