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 if ($foreignData['foreign_link'] == true) {
698 echo $backup_field . "\n";
700 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>"
702 <input type
="text" name
="fields<?php echo $field_name_appendix; ?>"
703 class="textfield" <?php
echo $unnullify_trigger; ?
>
704 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
705 id
="field_<?php echo ($idindex); ?>_3"
706 value
="<?php echo htmlspecialchars($data); ?>" />
707 <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
>
709 } elseif (is_array($foreignData['disp_row'])) {
710 echo $backup_field . "\n";
712 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>"
714 <select name
="fields<?php echo $field_name_appendix; ?>"
715 <?php
echo $unnullify_trigger; ?
>
717 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
718 id
="field_<?php echo ($idindex); ?>_3">
719 <?php
echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?
>
723 unset($foreignData['disp_row']);
724 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
728 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
729 <td colspan
="5" align
="right">
730 <?php
echo $backup_field . "\n"; ?
>
731 <textarea name
="fields<?php echo $field_name_appendix; ?>"
732 rows
="<?php echo ($cfg['TextareaRows']*2); ?>"
733 cols
="<?php echo ($cfg['TextareaCols']*2); ?>"
734 dir
="<?php echo $text_dir; ?>"
735 id
="field_<?php echo ($idindex); ?>_3"
736 <?php
echo $unnullify_trigger; ?
>
737 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
738 ><?php
echo $special_chars_encoded; ?
></textarea
>
740 } elseif (strstr($field['pma_type'], 'text')) {
741 echo $backup_field . "\n";
743 <textarea name
="fields<?php echo $field_name_appendix; ?>"
744 rows
="<?php echo $cfg['TextareaRows']; ?>"
745 cols
="<?php echo $cfg['TextareaCols']; ?>"
746 dir
="<?php echo $text_dir; ?>"
747 id
="field_<?php echo ($idindex); ?>_3"
748 <?php
echo $unnullify_trigger; ?
>
749 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
750 ><?php
echo $special_chars_encoded; ?
></textarea
>
753 if (strlen($special_chars) > 32000) {
755 echo ' <td>' . __(' Because of its length,<br /> this column might not be editable ');
757 } elseif ($field['pma_type'] == 'enum') {
758 if (! isset($table_fields[$i]['values'])) {
759 $table_fields[$i]['values'] = array();
760 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
761 // Removes automatic MySQL escape format
762 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
763 $table_fields[$i]['values'][] = array(
765 'html' => htmlspecialchars($val),
769 $field_enum_values = $table_fields[$i]['values'];
771 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>" value
="enum" />
772 <input type
="hidden" name
="fields<?php echo $field_name_appendix; ?>" value
="" />
774 echo "\n" . ' ' . $backup_field . "\n";
776 // show dropdown or radio depend on length
777 if (strlen($field['Type']) > 20) {
779 <select name
="fields<?php echo $field_name_appendix; ?>"
780 <?php
echo $unnullify_trigger; ?
>
782 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
783 id
="field_<?php echo ($idindex); ?>_3">
784 <option value
=""> 
;</option
>
788 foreach ($field_enum_values as $enum_value) {
790 echo '<option value="' . $enum_value['html'] . '"';
791 if ($data == $enum_value['plain']
793 && (! isset($where_clause) ||
$field['Null'] != 'YES')
794 && isset($field['Default'])
795 && $enum_value['plain'] == $field['Default'])) {
796 echo ' selected="selected"';
798 echo '>' . $enum_value['html'] . '</option>' . "\n";
806 foreach ($field_enum_values as $enum_value) {
808 echo '<input type="radio" name="fields' . $field_name_appendix . '"';
809 echo ' class="textfield"';
810 echo ' value="' . $enum_value['html'] . '"';
811 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
812 echo $unnullify_trigger;
813 if ($data == $enum_value['plain']
815 && (! isset($where_clause) ||
$field['Null'] != 'YES')
816 && isset($field['Default'])
817 && $enum_value['plain'] == $field['Default'])) {
818 echo ' checked="checked"';
820 echo ' tabindex="' . ($tabindex +
$tabindex_for_value) . '" />';
821 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
822 . $enum_value['html'] . '</label>' . "\n";
826 } elseif ($field['pma_type'] == 'set') {
827 if (! isset($table_fields[$i]['values'])) {
828 $table_fields[$i]['values'] = array();
829 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
830 $table_fields[$i]['values'][] = array(
832 'html' => htmlspecialchars($val),
835 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
837 $field_set_values = $table_fields[$i]['values'];
838 $select_size = $table_fields[$i]['select_size'];
840 $vset = array_flip(explode(',', $data));
841 echo $backup_field . "\n";
843 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>" value
="set" />
844 <select name
="fields<?php echo $field_name_appendix . '[]'; ?>"
846 size
="<?php echo $select_size; ?>"
847 multiple
="multiple" <?php
echo $unnullify_trigger; ?
>
848 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
849 id
="field_<?php echo ($idindex); ?>_3">
851 foreach ($field_set_values as $field_set_value) {
853 echo '<option value="' . $field_set_value['html'] . '"';
854 if (isset($vset[$field_set_value['plain']])) {
855 echo ' selected="selected"';
857 echo '>' . $field_set_value['html'] . '</option>' . "\n";
863 // We don't want binary data destroyed
864 elseif ($field['is_binary'] ||
$field['is_blob']) {
865 if (($cfg['ProtectBinary'] && $field['is_blob'])
866 ||
($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
869 if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
871 echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_md5'] . $vkey . '" value="' . $data . '" />';
872 echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . __('Remove BLOB Repository Reference') . "<br />";
873 echo PMA_BS_CreateReferenceLink($data, $db);
878 echo __('Binary - do not edit');
880 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
881 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
885 } // end if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
887 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>" value
="protected" />
888 <input type
="hidden" name
="fields<?php echo $field_name_appendix; ?>" value
="" />
890 } elseif ($field['is_blob']) {
892 echo $backup_field . "\n";
894 <textarea name
="fields<?php echo $field_name_appendix; ?>"
895 rows
="<?php echo $cfg['TextareaRows']; ?>"
896 cols
="<?php echo $cfg['TextareaCols']; ?>"
897 dir
="<?php echo $text_dir; ?>"
898 id
="field_<?php echo ($idindex); ?>_3"
899 <?php
echo $unnullify_trigger; ?
>
900 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
901 ><?php
echo $special_chars_encoded; ?
></textarea
>
905 // field size should be at least 4 and max $cfg['LimitChars']
906 $fieldsize = min(max($field['len'], 4), $cfg['LimitChars']);
908 echo $backup_field . "\n";
910 <input type
="text" name
="fields<?php echo $field_name_appendix; ?>"
911 value
="<?php echo $special_chars; ?>" size
="<?php echo $fieldsize; ?>"
912 class="textfield" <?php
echo $unnullify_trigger; ?
>
913 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
914 id
="field_<?php echo ($idindex); ?>_3" />
916 } // end if...elseif...else
918 // Upload choice (only for BLOBs because the binary
919 // attribute does not imply binary contents)
920 // (displayed whatever value the ProtectBinary has)
922 if ($is_upload && $field['is_blob']) {
923 // check if field type is of longblob and if the table is PBMS enabled.
924 if (($field['pma_type'] == "longblob") && PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type)) {
926 echo '<input type="checkbox" name="upload_blob_repo' . $vkey . '[' . $field['Field_md5'] . ']" /> ' . __('Upload to BLOB repository');
930 echo '<input type="file" name="fields_upload' . $vkey . '[' . $field['Field_md5'] . ']" class="textfield" id="field_' . $idindex . '_3" size="10" ' . $unnullify_trigger . '/> ';
932 // find maximum upload size, based on field type
934 * @todo with functions this is not so easy, as you can basically
935 * process any data with function like MD5
937 $max_field_sizes = array(
940 'mediumblob' => '16777216',
941 'longblob' => '4294967296'); // yeah, really
943 $this_field_max_size = $max_upload_size; // from PHP max
944 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
945 $this_field_max_size = $max_field_sizes[$field['pma_type']];
947 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
948 // do not generate here the MAX_FILE_SIZE, because we should
949 // put only one in the form to accommodate the biggest field
950 if ($this_field_max_size > $biggest_max_file_size) {
951 $biggest_max_file_size = $this_field_max_size;
955 if (!empty($cfg['UploadDir'])) {
956 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
957 if ($files === FALSE) {
958 echo ' <font color="red">' . __('Error') . '</font><br />' . "\n";
959 echo ' ' . __('The directory you set for upload work cannot be reached') . "\n";
960 } elseif (!empty($files)) {
962 echo ' <i>' . __('Or') . '</i>' . ' ' . __('web server upload directory') . ':<br />' . "\n";
963 echo ' <select size="1" name="fields_uploadlocal' . $vkey . '[' . $field['Field_md5'] . ']">' . "\n";
964 echo ' <option value="" selected="selected"></option>' . "\n";
966 echo ' </select>' . "\n";
968 } // end if (web-server upload directory)
969 } // end elseif (binary or blob)
971 elseif (in_array($field['pma_type'], $no_support_types)) {
972 // ignore this column to avoid changing it
975 // field size should be at least 4 and max 40
976 $fieldsize = min(max($field['len'], 4), 40);
977 echo $backup_field . "\n";
978 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' ||
strpos($data, "\n") !== FALSE)) {
981 <textarea name
="fields<?php echo $field_name_appendix; ?>"
982 rows
="<?php echo $cfg['CharTextareaRows']; ?>"
983 cols
="<?php echo $cfg['CharTextareaCols']; ?>"
984 dir
="<?php echo $text_dir; ?>"
985 id
="field_<?php echo ($idindex); ?>_3"
986 <?php
echo $unnullify_trigger; ?
>
987 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
988 ><?php
echo $special_chars_encoded; ?
></textarea
>
991 $the_class = 'textfield';
992 if ($field['pma_type'] == 'date') {
993 $the_class .= ' datefield';
994 } elseif ($field['pma_type'] == 'datetime' ||
substr($field['pma_type'], 0, 9) == 'timestamp') {
995 $the_class .= ' datetimefield';
998 <input type
="text" name
="fields<?php echo $field_name_appendix; ?>"
999 value
="<?php echo $special_chars; ?>" size
="<?php echo $fieldsize; ?>"
1000 class="<?php echo $the_class; ?>" <?php
echo $unnullify_trigger; ?
>
1001 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
1002 id
="field_<?php echo ($idindex); ?>_3" />
1004 if ($field['Extra'] == 'auto_increment') {
1006 <input type
="hidden" name
="auto_increment<?php echo $field_name_appendix; ?>" value
="1" />
1009 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
1011 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>" value
="timestamp" />
1014 if (substr($field['pma_type'], 0, 8) == 'datetime') {
1016 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>" value
="datetime" />
1019 if ($field['True_Type'] == 'bit') {
1021 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>" value
="bit" />
1024 if ($field['pma_type'] == 'date' ||
$field['pma_type'] == 'datetime' ||
substr($field['pma_type'], 0, 9) == 'timestamp') {
1025 // the _3 suffix points to the date field
1026 // the _2 suffix points to the corresponding NULL checkbox
1027 // in dateFormat, 'yy' means the year with 4 digits
1035 $odd_row = !$odd_row;
1038 echo ' </tbody></table><br />';
1039 } // end foreach on multi-edit
1043 <fieldset id
="actions_panel">
1044 <table border
="0" cellpadding
="5" cellspacing
="0">
1046 <td valign
="middle" nowrap
="nowrap">
1047 <select name
="submit_type" class="control_at_footer" tabindex
="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
1049 if (isset($where_clause)) {
1051 <option value
="save"><?php
echo __('Save'); ?
></option
>
1055 <option value
="insert"><?php
echo __('Insert as new row'); ?
></option
>
1056 <option value
="insertignore"><?php
echo __('Insert as new row and ignore errors'); ?
></option
>
1057 <option value
="showinsert"><?php
echo __('Show insert query'); ?
></option
>
1062 if (!isset($after_insert)) {
1063 $after_insert = 'back';
1067 <td valign
="middle">
1068  
; 
; 
;<strong
><?php
echo __('and then'); ?
></strong
> 
; 
; 
;
1070 <td valign
="middle" nowrap
="nowrap">
1071 <select name
="after_insert">
1072 <option value
="back" <?php
echo ($after_insert == 'back' ?
'selected="selected"' : ''); ?
>><?php
echo __('Go back to previous page'); ?
></option
>
1073 <option value
="new_insert" <?php
echo ($after_insert == 'new_insert' ?
'selected="selected"' : ''); ?
>><?php
echo __('Insert another new row'); ?
></option
>
1075 if (isset($where_clause)) {
1077 <option value
="same_insert" <?php
echo ($after_insert == 'same_insert' ?
'selected="selected"' : ''); ?
>><?php
echo __('Go back to this page'); ?
></option
>
1079 // If we have just numeric primary key, we can also edit next
1080 // in 2.8.2, we were looking for `field_name` = numeric_value
1081 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1082 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1083 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause)) {
1085 <option value
="edit_next" <?php
echo ($after_insert == 'edit_next' ?
'selected="selected"' : ''); ?
>><?php
echo __('Edit next row'); ?
></option
>
1096 <?php
echo PMA_showHint(__('Use TAB key to move from value to value, or CTRL+arrows to move anywhere')); ?
>
1098 <td colspan
="3" align
="right" valign
="middle">
1099 <input type
="submit" class="control_at_footer" value
="<?php echo __('Go'); ?>" tabindex
="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id
="buttonYes" />
1100 <input type
="reset" class="control_at_footer" value
="<?php echo __('Reset'); ?>" tabindex
="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1105 <?php
if ($biggest_max_file_size > 0) {
1106 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1112 <!-- Continue insertion form
-->
1113 <form id
="continueForm" method
="post" action
="tbl_replace.php" name
="continueForm" >
1114 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
1115 <input type
="hidden" name
="goto" value
="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1116 <input type
="hidden" name
="err_url" value
="<?php echo htmlspecialchars($err_url); ?>" />
1117 <input type
="hidden" name
="sql_query" value
="<?php echo htmlspecialchars($sql_query); ?>" />
1119 if (isset($where_clauses)) {
1120 foreach ($where_clause_array as $key_id => $where_clause) {
1121 echo '<input type="hidden" name="where_clause[' . $key_id . ']" value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n";
1124 $tmp = '<select name="insert_rows" id="insert_rows">' . "\n";
1125 $option_values = array(1,2,5,10,15,20,30,40);
1126 foreach ($option_values as $value) {
1127 $tmp .= '<option value="' . $value . '"';
1128 if ($value == $cfg['InsertRows']) {
1129 $tmp .= ' selected="selected"';
1131 $tmp .= '>' . $value . '</option>' . "\n";
1133 $tmp .= '</select>' . "\n";
1134 echo "\n" . sprintf(__('Continue insertion with %s rows'), $tmp);
1136 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>' . "\n";
1137 echo '</form>' . "\n";
1141 * Displays the footer
1143 require './libraries/footer.inc.php';