2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Displays form for editing and inserting new table rows
6 * register_globals_save (mark this file save for disabling register globals)
12 * Gets the variables sent or posted to this script and displays the header
14 require_once './libraries/common.inc.php';
17 * Ensures db and table are valid, else moves to the "parent" script
19 require_once './libraries/db_table_exists.lib.php';
22 * Sets global variables.
23 * Here it's better to use a if, instead of the '?' operator
24 * to avoid setting a variable to '' when it's not present in $_REQUEST
26 if (isset($_REQUEST['where_clause'])) {
27 $where_clause = $_REQUEST['where_clause'];
29 if (isset($_REQUEST['clause_is_unique'])) {
30 $clause_is_unique = $_REQUEST['clause_is_unique'];
32 if (isset($_SESSION['edit_next'])) {
33 $where_clause = $_SESSION['edit_next'];
34 unset($_SESSION['edit_next']);
35 $after_insert = 'edit_next';
37 if (isset($_REQUEST['sql_query'])) {
38 $sql_query = $_REQUEST['sql_query'];
40 if (isset($_REQUEST['ShowFunctionFields'])) {
41 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
43 if (isset($_REQUEST['ShowFieldTypesInDataEditView'])) {
44 $cfg['ShowFieldTypesInDataEditView'] = $_REQUEST['ShowFieldTypesInDataEditView'];
46 if (isset($_REQUEST['default_action'])) {
47 $default_action = $_REQUEST['default_action'];
53 require_once './libraries/file_listing.php';
57 * Defines the url to return to in case of error in a sql statement
58 * (at this point, $GLOBALS['goto'] will be set but could be empty)
60 if (empty($GLOBALS['goto'])) {
62 // avoid a problem (see bug #2202709)
63 $GLOBALS['goto'] = 'tbl_sql.php';
65 $GLOBALS['goto'] = 'db_sql.php';
69 * @todo check if we could replace by "db_|tbl_" - please clarify!?
73 'sql_query' => $sql_query
76 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
77 $_url_params['table'] = $table;
80 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
85 * Sets parameters for links
86 * where is this variable used?
87 * replace by PMA_generate_common_url($url_params);
89 $url_query = PMA_generate_common_url($url_params, 'html', '');
92 * get table information
93 * @todo should be done by a Table object
95 require_once './libraries/tbl_info.inc.php';
98 * Get comments for table fileds/columns
100 $comments_map = array();
102 if ($GLOBALS['cfg']['ShowPropertyComments']) {
103 $comments_map = PMA_getComments($db, $table);
107 * START REGULAR OUTPUT
111 * used in ./libraries/header.inc.php to load JavaScript library file
113 $GLOBALS['js_include'][] = 'functions.js';
114 $GLOBALS['js_include'][] = 'tbl_change.js';
115 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
116 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
118 * HTTP and HTML headers
120 require_once './libraries/header.inc.php';
123 * Displays the query submitted and its result
125 * @todo where does $disp_message and $disp_query come from???
127 if (! empty($disp_message)) {
128 if (! isset($disp_query)) {
131 PMA_showMessage($disp_message, $disp_query);
135 * Displays top menu links
137 require_once './libraries/tbl_links.inc.php';
141 * Get the analysis of SHOW CREATE TABLE for this table
142 * @todo should be handled by class Table
144 $show_create_table = PMA_DBI_fetch_value(
145 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
147 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
148 unset($show_create_table);
151 * Get the list of the fields of the current table
153 PMA_DBI_select_db($db);
154 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
155 null, null, null, PMA_DBI_QUERY_STORE
);
157 if (isset($where_clause)) {
158 // when in edit mode load all selected rows from table
159 $insert_mode = false;
160 if (is_array($where_clause)) {
161 $where_clause_array = $where_clause;
163 $where_clause_array = array(0 => $where_clause);
167 $found_unique_key = false;
168 $where_clauses = array();
170 foreach ($where_clause_array as $key_id => $where_clause) {
171 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';';
172 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE
);
173 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
174 $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
177 if (! $rows[$key_id]) {
178 unset($rows[$key_id], $where_clause_array[$key_id]);
179 PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query);
181 require './libraries/footer.inc.php';
182 } else { // end if (no row returned)
183 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
184 list($unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true);
185 if (! empty($unique_condition)) {
186 $found_unique_key = true;
188 unset($unique_condition, $tmp_clause_is_unique);
193 // no primary key given, just load first row - but what happens if table is empty?
195 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE
);
196 $rows = array_fill(0, $cfg['InsertRows'], false);
199 // Copying a row - fetched data will be inserted as a new row, therefore the where clause is needless.
200 if (isset($default_action) && $default_action === 'insert') {
201 unset($where_clause, $where_clauses);
204 // retrieve keys into foreign fields, if any
205 $foreigners = PMA_getForeigners($db, $table);
211 // autocomplete feature of IE kills the "onchange" event handler and it
212 // must be replaced by the "onpropertychange" one in this case
213 $chg_evt_handler = (PMA_USR_BROWSER_AGENT
== 'IE' && PMA_USR_BROWSER_VER
>= 5 && PMA_USR_BROWSER_VER
< 7)
216 // Had to put the URI because when hosted on an https server,
217 // some browsers send wrongly this form to the http server.
220 <!-- Set on key handler
for moving using by Ctrl+arrows
-->
221 <script src
="./js/keyhandler.js" type
="text/javascript"></script
>
222 <script type
="text/javascript">
224 var switch_movement
= 0;
225 document
.onkeydown
= onKeyDownArrowsHandler
;
230 $_form_params = array(
233 'goto' => $GLOBALS['goto'],
234 'err_url' => $err_url,
235 'sql_query' => $sql_query,
237 if (isset($where_clauses)) {
238 foreach ($where_clause_array as $key_id => $where_clause) {
239 $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
242 if (isset($clause_is_unique)) {
243 $_form_params['clause_is_unique'] = $clause_is_unique;
248 <!-- Insert
/Edit form
-->
249 <form id
="insertForm" method
="post" action
="tbl_replace.php" name
="insertForm" <?php
if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?
>>
251 echo PMA_generate_common_hidden_inputs($_form_params);
253 $titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
255 // Set if we passed the first timestamp field
257 $fields_cnt = count($table_fields);
260 $tabindex_for_function = +
3000;
261 $tabindex_for_null = +
6000;
262 $tabindex_for_value = 0;
264 $biggest_max_file_size = 0;
266 // user can toggle the display of Function column
267 // (currently does not work for multi-edits)
268 $url_params['db'] = $db;
269 $url_params['table'] = $table;
270 if (isset($where_clause)) {
271 $url_params['where_clause'] = trim($where_clause);
273 if (! empty($sql_query)) {
274 $url_params['sql_query'] = $sql_query;
277 if (! $cfg['ShowFunctionFields'] ||
! $cfg['ShowFieldTypesInDataEditView']) {
280 if (! $cfg['ShowFunctionFields']) {
281 $this_url_params = array_merge($url_params,
282 array('ShowFunctionFields' => 1, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
283 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . __('Function') . '</a>' . "\n";
285 if (! $cfg['ShowFieldTypesInDataEditView']) {
286 $this_other_url_params = array_merge($url_params,
287 array('ShowFieldTypesInDataEditView' => 1, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
288 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_other_url_params) . '">' . __('Type') . '</a>' . "\n";
291 foreach ($rows as $row_id => $vrow) {
292 if ($vrow === false) {
297 $rownumber_param = '&rownumber=' . $row_id;
298 $vkey = '[multi_edit][' . $jsvkey . ']';
300 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ?
$result[$row_id] : $result);
301 if ($insert_mode && $row_id > 0) {
302 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_' . $row_id . '" />';
303 echo '<label for="insert_ignore_' . $row_id . '">' . __('Ignore') . '</label><br />' . "\n";
306 <table
class="insertRowTable">
309 <th
><?php
echo __('Column'); ?
></th
>
312 if ($cfg['ShowFieldTypesInDataEditView']) {
313 $this_url_params = array_merge($url_params,
314 array('ShowFieldTypesInDataEditView' => 0, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
315 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Type') . '</a></th>' . "\n";
318 if ($cfg['ShowFunctionFields']) {
319 $this_url_params = array_merge($url_params,
320 array('ShowFunctionFields' => 0, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
321 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Function') . '</a></th>' . "\n";
324 <th
><?php
echo __('Null'); ?
></th
>
325 <th
><?php
echo __('Value'); ?
></th
>
330 <th colspan
="5" align
="right" class="tblFooters">
331 <input type
="submit" value
="<?php echo __('Go'); ?>" />
337 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
338 $m_rows = $o_rows +
1;
341 for ($i = 0; $i < $fields_cnt; $i++
) {
342 if (! isset($table_fields[$i]['processed'])) {
343 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
344 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
345 // True_Type contains only the type (stops at first bracket)
346 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
350 // Current date should not be set as default if the field is NULL
351 // for the current row, but do not put here the current datetime
352 // if there is a default value (the real default value will be set
353 // in the Default value logic below)
355 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
356 // $field['Default'] is not set if it contains NULL:
357 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
358 // but, look what we get if we switch to iso: (Default is NULL)
359 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
360 // so I force a NULL into it (I don't think it's possible
361 // to have an empty default value for DATETIME)
362 // then, the "if" after this one will work
363 if ($table_fields[$i]['Type'] == 'datetime'
364 && ! isset($table_fields[$i]['Default'])
365 && isset($table_fields[$i]['Null'])
366 && $table_fields[$i]['Null'] == 'YES') {
367 $table_fields[$i]['Default'] = null;
370 $table_fields[$i]['len'] =
371 preg_match('@float|double@', $table_fields[$i]['Type']) ?
100 : -1;
374 if (isset($comments_map[$table_fields[$i]['Field']])) {
375 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
376 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
377 . $table_fields[$i]['Field_html'] . '</span>';
379 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
383 // Fix for bug #3152931 'ENUM and SET cannot have "Binary" option'
384 // If check to ensure types such as "enum('one','two','binary',..)" or
385 // "enum('one','two','varbinary',..)" are not categorized as binary.
386 if (stripos($table_fields[$i]['Type'], 'binary') === 0
387 ||
stripos($table_fields[$i]['Type'], 'varbinary') === 0) {
388 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
390 $table_fields[$i]['is_binary'] = false;
393 // If check to ensure types such as "enum('one','two','blob',..)" or
394 // "enum('one','two','tinyblob',..)" etc. are not categorized as blob.
395 if (stripos($table_fields[$i]['Type'], 'blob') === 0
396 ||
stripos($table_fields[$i]['Type'], 'tinyblob') === 0
397 ||
stripos($table_fields[$i]['Type'], 'mediumblob') === 0
398 ||
stripos($table_fields[$i]['Type'], 'longblob') === 0) {
399 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
401 $table_fields[$i]['is_blob'] = false;
404 // If check to ensure types such as "enum('one','two','char',..)" or
405 // "enum('one','two','varchar',..)" are not categorized as char.
406 if (stripos($table_fields[$i]['Type'], 'char') === 0
407 ||
stripos($table_fields[$i]['Type'], 'varchar') === 0) {
408 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
410 $table_fields[$i]['is_char'] = false;
413 $table_fields[$i]['first_timestamp'] = false;
414 switch ($table_fields[$i]['True_Type']) {
416 $table_fields[$i]['pma_type'] = 'set';
417 $table_fields[$i]['wrap'] = '';
420 $table_fields[$i]['pma_type'] = 'enum';
421 $table_fields[$i]['wrap'] = '';
424 if (!$timestamp_seen) { // can only occur once per table
426 $table_fields[$i]['first_timestamp'] = true;
428 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
429 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
433 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
434 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
438 $field = $table_fields[$i];
439 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
441 if (-1 === $field['len']) {
442 $field['len'] = PMA_DBI_field_len($vresult, $i);
444 //Call validation when the form submited...
445 $unnullify_trigger = $chg_evt_handler . "=\"return verificationsAfterFieldChange('". PMA_escapeJsString($field['Field_md5']) . "', '"
446 . PMA_escapeJsString($jsvkey) . "','".$field['pma_type']."')\"";
448 // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
449 $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
451 if ($field['Type'] == 'datetime'
452 && ! isset($field['Default'])
453 && ! is_null($field['Default'])
454 && ($insert_mode ||
! isset($vrow[$field['Field']]))) {
456 // UPDATE case with an NULL value
457 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
460 <tr
class="noclick <?php echo $odd_row ? 'odd' : 'even'; ?>">
461 <td
<?php
echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ?
'rowspan="2"' : ''); ?
> align
="center">
462 <?php
echo $field['Field_title']; ?
>
463 <input type
="hidden" name
="fields_name<?php echo $field_name_appendix; ?>" value
="<?php echo $field['Field_html']; ?>"/>
465 <?php
if ($cfg['ShowFieldTypesInDataEditView']) { ?
>
466 <td align
="center"<?php
echo $field['wrap']; ?
>><span
class="column_type"><?php
echo $field['pma_type']; ?
></span
>
471 // Prepares the field value
472 $real_null_value = false;
473 $special_chars_encoded = '';
476 if (is_null($vrow[$field['Field']])) {
477 $real_null_value = true;
478 $vrow[$field['Field']] = '';
480 $data = $vrow[$field['Field']];
481 } elseif ($field['True_Type'] == 'bit') {
482 $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
484 // special binary "characters"
485 if ($field['is_binary'] ||
($field['is_blob'] && ! $cfg['ProtectBinary'])) {
486 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
487 $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]);
488 $field['display_binary_as_hex'] = true;
490 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
493 $special_chars = htmlspecialchars($vrow[$field['Field']]);
495 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
496 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
498 $data = $vrow[$field['Field']];
499 } // end if... else...
501 //when copying row, it is useful to empty auto-increment column to prevent duplicate key error
502 if (isset($default_action) && $default_action === 'insert') {
503 if ($field['Key'] === 'PRI' && strpos($field['Extra'], 'auto_increment') !== false) {
504 $data = $special_chars_encoded = $special_chars = NULL;
507 // If a timestamp field value is not included in an update
508 // statement MySQL auto-update it to the current timestamp;
509 // however, things have changed since MySQL 4.1, so
510 // it's better to set a fields_prev in this situation
511 $backup_field = '<input type="hidden" name="fields_prev'
512 . $field_name_appendix . '" value="'
513 . htmlspecialchars($vrow[$field['Field']]) . '" />';
515 // (we are inserting)
516 // display default values
517 if (! isset($field['Default'])) {
518 $field['Default'] = '';
519 $real_null_value = true;
522 $data = $field['Default'];
524 if ($field['True_Type'] == 'bit') {
525 $special_chars = PMA_convert_bit_default_value($field['Default']);
527 $special_chars = htmlspecialchars($field['Default']);
530 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
531 // this will select the UNHEX function while inserting
532 if (($field['is_binary'] ||
($field['is_blob'] && ! $cfg['ProtectBinary'])) && $_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
533 $field['display_binary_as_hex'] = true;
537 $idindex = ($o_rows * $fields_cnt) +
$i +
1;
538 $tabindex = $idindex;
540 // These GIS data types are not yet supported.
541 $no_support_types = array('geometry', 'point', 'linestring', 'polygon', 'multipoint', 'multilinestring', 'multipolygon', 'geometrycollection');
543 // The function column
544 // -------------------
545 // We don't want binary data to be destroyed
546 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
547 // stored or retrieved" so it does not mean that the contents is
549 if ($cfg['ShowFunctionFields']) {
550 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
551 ||
($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
552 echo ' <td align="center">' . __('Binary') . '</td>' . "\n";
553 } elseif (strstr($field['True_Type'], 'enum') ||
strstr($field['True_Type'], 'set') ||
in_array($field['pma_type'], $no_support_types)) {
554 echo ' <td align="center">--</td>' . "\n";
558 <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">
563 // Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
564 // or something similar. Then directly look up the entry in the RestrictFunctions array,
565 // which will then reveal the available dropdown options
566 if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
567 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
568 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
569 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
570 $default_function = $cfg['DefaultFunctions'][$current_func_type];
573 $default_function = '';
576 $dropdown_built = array();
577 $op_spacing_needed = false;
579 // what function defined as default?
580 // for the first timestamp we don't set the default function
581 // if there is a default value for the timestamp
582 // (not including CURRENT_TIMESTAMP)
583 // and the column does not have the
584 // ON UPDATE DEFAULT TIMESTAMP attribute.
586 if ($field['True_Type'] == 'timestamp'
587 && empty($field['Default'])
589 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
590 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
593 // For primary keys of type char(36) or varchar(36) UUID if the default function
594 // Only applies to insert mode, as it would silently trash data on updates.
596 && $field['Key'] == 'PRI'
597 && ($field['Type'] == 'char(36)' ||
$field['Type'] == 'varchar(36)')
599 $default_function = $cfg['DefaultFunctions']['pk_char36'];
602 // this is set only when appropriate and is always true
603 if (isset($field['display_binary_as_hex'])) {
604 $default_function = 'UNHEX';
607 // loop on the dropdown array and print all available options for that field.
608 foreach ($dropdown as $each_dropdown){
610 if ($default_function === $each_dropdown) {
611 echo ' selected="selected"';
613 echo '>' . $each_dropdown . '</option>' . "\n";
614 $dropdown_built[$each_dropdown] = 'true';
615 $op_spacing_needed = true;
618 // For compatibility's sake, do not let out all other functions. Instead
619 // print a separator (blank) and then show ALL functions which weren't shown
621 $cnt_functions = count($cfg['Functions']);
622 for ($j = 0; $j < $cnt_functions; $j++
) {
623 if (! isset($dropdown_built[$cfg['Functions'][$j]]) ||
$dropdown_built[$cfg['Functions'][$j]] != 'true') {
624 // Is current function defined as default?
625 $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
626 ||
(!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
627 ?
' selected="selected"'
629 if ($op_spacing_needed == true) {
631 echo '<option value="">--------</option>' . "\n";
632 $op_spacing_needed = false;
636 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
645 } // end if ($cfg['ShowFunctionFields'])
650 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
652 if ($field['Null'] == 'YES') {
653 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
654 if ($real_null_value && !$field['first_timestamp']) {
659 echo ' <input type="checkbox" class="checkbox_null" tabindex="' . ($tabindex +
$tabindex_for_null) . '"'
660 . ' name="fields_null' . $field_name_appendix . '"';
661 if ($real_null_value && !$field['first_timestamp']) {
662 echo ' checked="checked"';
664 echo ' id="field_' . ($idindex) . '_2" />';
666 // nullify_code is needed by the js nullify() function
667 if (strstr($field['True_Type'], 'enum')) {
668 if (strlen($field['Type']) > 20) {
673 } elseif (strstr($field['True_Type'], 'set')) {
675 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
676 // foreign key in a drop-down
678 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
679 // foreign key with a browsing icon
684 // to be able to generate calls to nullify() in jQuery
685 echo '<input type="hidden" class="nullify_code" name="nullify_code' . $field_name_appendix . '" value="' . $nullify_code . '" />';
686 echo '<input type="hidden" class="hashed_field" name="hashed_field' . $field_name_appendix . '" value="' . $field['Field_md5'] . '" />';
687 echo '<input type="hidden" class="multi_edit" name="multi_edit' . $field_name_appendix . '" value="' . PMA_escapeJsString($vkey) . '" />';
689 echo ' </td>' . "\n";
691 // The value column (depends on type)
693 // See bug #1667887 for the reason why we don't use the maxlength
697 // Will be used by js/tbl_change.js to set the default value
698 // for the "Continue insertion" feature
699 echo '<span class="default_value hide">' . $special_chars . '</span>';
700 if ($foreignData['foreign_link'] == true) {
701 echo $backup_field . "\n";
703 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>"
705 <input type
="text" name
="fields<?php echo $field_name_appendix; ?>"
706 class="textfield" <?php
echo $unnullify_trigger; ?
>
707 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
708 id
="field_<?php echo ($idindex); ?>_3"
709 value
="<?php echo htmlspecialchars($data); ?>" />
710 <a
class="hide foreign_values_anchor" target
="_blank" onclick
="window.open(this.href, 'foreigners', 'width=640,height=240,scrollbars=yes,resizable=yes'); return false;" href
="browse_foreigners.php?<?php echo PMA_generate_common_url($db, $table); ?>&field=<?php echo PMA_escapeJsString(urlencode($field['Field']) . $rownumber_param); ?>"><?php
echo str_replace("'", "\'", $titles['Browse']); ?
></a
>
712 } elseif (is_array($foreignData['disp_row'])) {
713 echo $backup_field . "\n";
715 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>"
717 <select name
="fields<?php echo $field_name_appendix; ?>"
718 <?php
echo $unnullify_trigger; ?
>
720 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
721 id
="field_<?php echo ($idindex); ?>_3">
722 <?php
echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?
>
726 unset($foreignData['disp_row']);
727 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
731 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
732 <td colspan
="5" align
="right">
733 <?php
echo $backup_field . "\n"; ?
>
734 <textarea name
="fields<?php echo $field_name_appendix; ?>"
735 rows
="<?php echo ($cfg['TextareaRows']*2); ?>"
736 cols
="<?php echo ($cfg['TextareaCols']*2); ?>"
737 dir
="<?php echo $text_dir; ?>"
738 id
="field_<?php echo ($idindex); ?>_3"
739 <?php
echo $unnullify_trigger; ?
>
740 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
741 ><?php
echo $special_chars_encoded; ?
></textarea
>
743 } elseif (strstr($field['pma_type'], 'text')) {
744 echo $backup_field . "\n";
746 <textarea name
="fields<?php echo $field_name_appendix; ?>"
747 rows
="<?php echo $cfg['TextareaRows']; ?>"
748 cols
="<?php echo $cfg['TextareaCols']; ?>"
749 dir
="<?php echo $text_dir; ?>"
750 id
="field_<?php echo ($idindex); ?>_3"
751 <?php
echo $unnullify_trigger; ?
>
752 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
753 ><?php
echo $special_chars_encoded; ?
></textarea
>
756 if (strlen($special_chars) > 32000) {
758 echo ' <td>' . __(' Because of its length,<br /> this column might not be editable ');
760 } elseif ($field['pma_type'] == 'enum') {
761 if (! isset($table_fields[$i]['values'])) {
762 $table_fields[$i]['values'] = array();
763 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
764 // Removes automatic MySQL escape format
765 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
766 $table_fields[$i]['values'][] = array(
768 'html' => htmlspecialchars($val),
772 $field_enum_values = $table_fields[$i]['values'];
774 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>" value
="enum" />
775 <input type
="hidden" name
="fields<?php echo $field_name_appendix; ?>" value
="" />
777 echo "\n" . ' ' . $backup_field . "\n";
779 // show dropdown or radio depend on length
780 if (strlen($field['Type']) > 20) {
782 <select name
="fields<?php echo $field_name_appendix; ?>"
783 <?php
echo $unnullify_trigger; ?
>
785 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
786 id
="field_<?php echo ($idindex); ?>_3">
787 <option value
=""> 
;</option
>
791 foreach ($field_enum_values as $enum_value) {
793 echo '<option value="' . $enum_value['html'] . '"';
794 if ($data == $enum_value['plain']
796 && (! isset($where_clause) ||
$field['Null'] != 'YES')
797 && isset($field['Default'])
798 && $enum_value['plain'] == $field['Default'])) {
799 echo ' selected="selected"';
801 echo '>' . $enum_value['html'] . '</option>' . "\n";
809 foreach ($field_enum_values as $enum_value) {
811 echo '<input type="radio" name="fields' . $field_name_appendix . '"';
812 echo ' class="textfield"';
813 echo ' value="' . $enum_value['html'] . '"';
814 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
815 echo $unnullify_trigger;
816 if ($data == $enum_value['plain']
818 && (! isset($where_clause) ||
$field['Null'] != 'YES')
819 && isset($field['Default'])
820 && $enum_value['plain'] == $field['Default'])) {
821 echo ' checked="checked"';
823 echo ' tabindex="' . ($tabindex +
$tabindex_for_value) . '" />';
824 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
825 . $enum_value['html'] . '</label>' . "\n";
829 } elseif ($field['pma_type'] == 'set') {
830 if (! isset($table_fields[$i]['values'])) {
831 $table_fields[$i]['values'] = array();
832 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
833 $table_fields[$i]['values'][] = array(
835 'html' => htmlspecialchars($val),
838 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
840 $field_set_values = $table_fields[$i]['values'];
841 $select_size = $table_fields[$i]['select_size'];
843 $vset = array_flip(explode(',', $data));
844 echo $backup_field . "\n";
846 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>" value
="set" />
847 <select name
="fields<?php echo $field_name_appendix . '[]'; ?>"
849 size
="<?php echo $select_size; ?>"
850 multiple
="multiple" <?php
echo $unnullify_trigger; ?
>
851 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
852 id
="field_<?php echo ($idindex); ?>_3">
854 foreach ($field_set_values as $field_set_value) {
856 echo '<option value="' . $field_set_value['html'] . '"';
857 if (isset($vset[$field_set_value['plain']])) {
858 echo ' selected="selected"';
860 echo '>' . $field_set_value['html'] . '</option>' . "\n";
866 // We don't want binary data destroyed
867 elseif ($field['is_binary'] ||
$field['is_blob']) {
868 if (($cfg['ProtectBinary'] && $field['is_blob'])
869 ||
($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
872 if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
874 echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_md5'] . $vkey . '" value="' . $data . '" />';
875 echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . __('Remove BLOB Repository Reference') . "<br />";
876 echo PMA_BS_CreateReferenceLink($data, $db);
881 echo __('Binary - do not edit');
883 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
884 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
888 } // end if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
890 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>" value
="protected" />
891 <input type
="hidden" name
="fields<?php echo $field_name_appendix; ?>" value
="" />
893 } elseif ($field['is_blob']) {
895 echo $backup_field . "\n";
897 <textarea name
="fields<?php echo $field_name_appendix; ?>"
898 rows
="<?php echo $cfg['TextareaRows']; ?>"
899 cols
="<?php echo $cfg['TextareaCols']; ?>"
900 dir
="<?php echo $text_dir; ?>"
901 id
="field_<?php echo ($idindex); ?>_3"
902 <?php
echo $unnullify_trigger; ?
>
903 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
904 ><?php
echo $special_chars_encoded; ?
></textarea
>
908 // field size should be at least 4 and max $cfg['LimitChars']
909 $fieldsize = min(max($field['len'], 4), $cfg['LimitChars']);
911 echo $backup_field . "\n";
913 <input type
="text" name
="fields<?php echo $field_name_appendix; ?>"
914 value
="<?php echo $special_chars; ?>" size
="<?php echo $fieldsize; ?>"
915 class="textfield" <?php
echo $unnullify_trigger; ?
>
916 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
917 id
="field_<?php echo ($idindex); ?>_3" />
919 } // end if...elseif...else
921 // Upload choice (only for BLOBs because the binary
922 // attribute does not imply binary contents)
923 // (displayed whatever value the ProtectBinary has)
925 if ($is_upload && $field['is_blob']) {
926 // check if field type is of longblob and if the table is PBMS enabled.
927 if (($field['pma_type'] == "longblob") && PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type)) {
929 echo '<input type="checkbox" name="upload_blob_repo' . $vkey . '[' . $field['Field_md5'] . ']" /> ' . __('Upload to BLOB repository');
933 echo '<input type="file" name="fields_upload' . $vkey . '[' . $field['Field_md5'] . ']" class="textfield" id="field_' . $idindex . '_3" size="10" ' . $unnullify_trigger . '/> ';
935 // find maximum upload size, based on field type
937 * @todo with functions this is not so easy, as you can basically
938 * process any data with function like MD5
940 $max_field_sizes = array(
943 'mediumblob' => '16777216',
944 'longblob' => '4294967296'); // yeah, really
946 $this_field_max_size = $max_upload_size; // from PHP max
947 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
948 $this_field_max_size = $max_field_sizes[$field['pma_type']];
950 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
951 // do not generate here the MAX_FILE_SIZE, because we should
952 // put only one in the form to accommodate the biggest field
953 if ($this_field_max_size > $biggest_max_file_size) {
954 $biggest_max_file_size = $this_field_max_size;
958 if (!empty($cfg['UploadDir'])) {
959 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
960 if ($files === false) {
961 echo ' <font color="red">' . __('Error') . '</font><br />' . "\n";
962 echo ' ' . __('The directory you set for upload work cannot be reached') . "\n";
963 } elseif (!empty($files)) {
965 echo ' <i>' . __('Or') . '</i>' . ' ' . __('web server upload directory') . ':<br />' . "\n";
966 echo ' <select size="1" name="fields_uploadlocal' . $vkey . '[' . $field['Field_md5'] . ']">' . "\n";
967 echo ' <option value="" selected="selected"></option>' . "\n";
969 echo ' </select>' . "\n";
971 } // end if (web-server upload directory)
972 } // end elseif (binary or blob)
974 elseif (in_array($field['pma_type'], $no_support_types)) {
975 // ignore this column to avoid changing it
978 // field size should be at least 4 and max 40
979 $fieldsize = min(max($field['len'], 4), 40);
980 echo $backup_field . "\n";
981 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' ||
strpos($data, "\n") !== false)) {
984 <textarea name
="fields<?php echo $field_name_appendix; ?>"
985 rows
="<?php echo $cfg['CharTextareaRows']; ?>"
986 cols
="<?php echo $cfg['CharTextareaCols']; ?>"
987 dir
="<?php echo $text_dir; ?>"
988 id
="field_<?php echo ($idindex); ?>_3"
989 <?php
echo $unnullify_trigger; ?
>
990 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
991 ><?php
echo $special_chars_encoded; ?
></textarea
>
994 $the_class = 'textfield';
995 if ($field['pma_type'] == 'date') {
996 $the_class .= ' datefield';
997 } elseif ($field['pma_type'] == 'datetime' ||
substr($field['pma_type'], 0, 9) == 'timestamp') {
998 $the_class .= ' datetimefield';
1001 <input type
="text" name
="fields<?php echo $field_name_appendix; ?>"
1002 value
="<?php echo $special_chars; ?>" size
="<?php echo $fieldsize; ?>"
1003 class="<?php echo $the_class; ?>" <?php
echo $unnullify_trigger; ?
>
1004 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
1005 id
="field_<?php echo ($idindex); ?>_3" />
1007 if ($field['Extra'] == 'auto_increment') {
1009 <input type
="hidden" name
="auto_increment<?php echo $field_name_appendix; ?>" value
="1" />
1012 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
1014 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>" value
="timestamp" />
1017 if (substr($field['pma_type'], 0, 8) == 'datetime') {
1019 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>" value
="datetime" />
1022 if ($field['True_Type'] == 'bit') {
1024 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>" value
="bit" />
1027 if ($field['pma_type'] == 'date' ||
$field['pma_type'] == 'datetime' ||
substr($field['pma_type'], 0, 9) == 'timestamp') {
1028 // the _3 suffix points to the date field
1029 // the _2 suffix points to the corresponding NULL checkbox
1030 // in dateFormat, 'yy' means the year with 4 digits
1038 $odd_row = !$odd_row;
1041 echo ' </tbody></table><br />';
1042 } // end foreach on multi-edit
1046 <fieldset id
="actions_panel">
1047 <table border
="0" cellpadding
="5" cellspacing
="0">
1049 <td valign
="middle" nowrap
="nowrap">
1050 <select name
="submit_type" class="control_at_footer" tabindex
="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
1052 if (isset($where_clause)) {
1054 <option value
="save"><?php
echo __('Save'); ?
></option
>
1058 <option value
="insert"><?php
echo __('Insert as new row'); ?
></option
>
1059 <option value
="insertignore"><?php
echo __('Insert as new row and ignore errors'); ?
></option
>
1060 <option value
="showinsert"><?php
echo __('Show insert query'); ?
></option
>
1065 if (! isset($after_insert)) {
1066 $after_insert = 'back';
1070 <td valign
="middle">
1071  
; 
; 
;<strong
><?php
echo __('and then'); ?
></strong
> 
; 
; 
;
1073 <td valign
="middle" nowrap
="nowrap">
1074 <select name
="after_insert">
1075 <option value
="back" <?php
echo ($after_insert == 'back' ?
'selected="selected"' : ''); ?
>><?php
echo __('Go back to previous page'); ?
></option
>
1076 <option value
="new_insert" <?php
echo ($after_insert == 'new_insert' ?
'selected="selected"' : ''); ?
>><?php
echo __('Insert another new row'); ?
></option
>
1078 if (isset($where_clause)) {
1080 <option value
="same_insert" <?php
echo ($after_insert == 'same_insert' ?
'selected="selected"' : ''); ?
>><?php
echo __('Go back to this page'); ?
></option
>
1082 // If we have just numeric primary key, we can also edit next
1083 // in 2.8.2, we were looking for `field_name` = numeric_value
1084 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1085 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1086 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause)) {
1088 <option value
="edit_next" <?php
echo ($after_insert == 'edit_next' ?
'selected="selected"' : ''); ?
>><?php
echo __('Edit next row'); ?
></option
>
1099 <?php
echo PMA_showHint(__('Use TAB key to move from value to value, or CTRL+arrows to move anywhere')); ?
>
1101 <td colspan
="3" align
="right" valign
="middle">
1102 <input type
="submit" class="control_at_footer" value
="<?php echo __('Go'); ?>" tabindex
="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id
="buttonYes" />
1103 <input type
="reset" class="control_at_footer" value
="<?php echo __('Reset'); ?>" tabindex
="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1108 <?php
if ($biggest_max_file_size > 0) {
1109 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1115 <!-- Continue insertion form
-->
1116 <form id
="continueForm" method
="post" action
="tbl_replace.php" name
="continueForm" >
1117 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
1118 <input type
="hidden" name
="goto" value
="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1119 <input type
="hidden" name
="err_url" value
="<?php echo htmlspecialchars($err_url); ?>" />
1120 <input type
="hidden" name
="sql_query" value
="<?php echo htmlspecialchars($sql_query); ?>" />
1122 if (isset($where_clauses)) {
1123 foreach ($where_clause_array as $key_id => $where_clause) {
1124 echo '<input type="hidden" name="where_clause[' . $key_id . ']" value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n";
1127 $tmp = '<select name="insert_rows" id="insert_rows">' . "\n";
1128 $option_values = array(1,2,5,10,15,20,30,40);
1129 foreach ($option_values as $value) {
1130 $tmp .= '<option value="' . $value . '"';
1131 if ($value == $cfg['InsertRows']) {
1132 $tmp .= ' selected="selected"';
1134 $tmp .= '>' . $value . '</option>' . "\n";
1136 $tmp .= '</select>' . "\n";
1137 echo "\n" . sprintf(__('Continue insertion with %s rows'), $tmp);
1139 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>' . "\n";
1140 echo '</form>' . "\n";
1144 * Displays the footer
1146 require './libraries/footer.inc.php';