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="<?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 // The function column
541 // -------------------
542 // We don't want binary data to be destroyed
543 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
544 // stored or retrieved" so it does not mean that the contents is
546 if ($cfg['ShowFunctionFields']) {
547 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
548 ||
($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
549 echo ' <td align="center">' . __('Binary') . '</td>' . "\n";
550 } elseif (strstr($field['True_Type'], 'enum') ||
strstr($field['True_Type'], 'set') ||
'geometry' == $field['pma_type']) {
551 echo ' <td align="center">--</td>' . "\n";
555 <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">
560 // Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
561 // or something similar. Then directly look up the entry in the RestrictFunctions array,
562 // which will then reveal the available dropdown options
563 if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
564 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
565 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
566 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
567 $default_function = $cfg['DefaultFunctions'][$current_func_type];
570 $default_function = '';
573 $dropdown_built = array();
574 $op_spacing_needed = FALSE;
576 // what function defined as default?
577 // for the first timestamp we don't set the default function
578 // if there is a default value for the timestamp
579 // (not including CURRENT_TIMESTAMP)
580 // and the column does not have the
581 // ON UPDATE DEFAULT TIMESTAMP attribute.
583 if ($field['True_Type'] == 'timestamp'
584 && empty($field['Default'])
586 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
587 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
590 // For primary keys of type char(36) or varchar(36) UUID if the default function
591 // Only applies to insert mode, as it would silently trash data on updates.
593 && $field['Key'] == 'PRI'
594 && ($field['Type'] == 'char(36)' ||
$field['Type'] == 'varchar(36)')
596 $default_function = $cfg['DefaultFunctions']['pk_char36'];
599 // this is set only when appropriate and is always true
600 if (isset($field['display_binary_as_hex'])) {
601 $default_function = 'UNHEX';
604 // loop on the dropdown array and print all available options for that field.
605 foreach ($dropdown as $each_dropdown){
607 if ($default_function === $each_dropdown) {
608 echo ' selected="selected"';
610 echo '>' . $each_dropdown . '</option>' . "\n";
611 $dropdown_built[$each_dropdown] = 'TRUE';
612 $op_spacing_needed = TRUE;
615 // For compatibility's sake, do not let out all other functions. Instead
616 // print a separator (blank) and then show ALL functions which weren't shown
618 $cnt_functions = count($cfg['Functions']);
619 for ($j = 0; $j < $cnt_functions; $j++
) {
620 if (!isset($dropdown_built[$cfg['Functions'][$j]]) ||
$dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
621 // Is current function defined as default?
622 $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
623 ||
(!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
624 ?
' selected="selected"'
626 if ($op_spacing_needed == TRUE) {
628 echo '<option value="">--------</option>' . "\n";
629 $op_spacing_needed = FALSE;
633 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
642 } // end if ($cfg['ShowFunctionFields'])
647 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
649 if ($field['Null'] == 'YES') {
650 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
651 if ($real_null_value && !$field['first_timestamp']) {
656 echo ' <input type="checkbox" class="checkbox_null" tabindex="' . ($tabindex +
$tabindex_for_null) . '"'
657 . ' name="fields_null' . $field_name_appendix . '"';
658 if ($real_null_value && !$field['first_timestamp']) {
659 echo ' checked="checked"';
661 echo ' id="field_' . ($idindex) . '_2" />';
663 // nullify_code is needed by the js nullify() function
664 if (strstr($field['True_Type'], 'enum')) {
665 if (strlen($field['Type']) > 20) {
670 } elseif (strstr($field['True_Type'], 'set')) {
672 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
673 // foreign key in a drop-down
675 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
676 // foreign key with a browsing icon
681 // to be able to generate calls to nullify() in jQuery
682 echo '<input type="hidden" class="nullify_code" name="nullify_code' . $field_name_appendix . '" value="' . $nullify_code . '" />';
683 echo '<input type="hidden" class="hashed_field" name="hashed_field' . $field_name_appendix . '" value="' . $field['Field_md5'] . '" />';
684 echo '<input type="hidden" class="multi_edit" name="multi_edit' . $field_name_appendix . '" value="' . PMA_escapeJsString($vkey) . '" />';
686 echo ' </td>' . "\n";
688 // The value column (depends on type)
690 // See bug #1667887 for the reason why we don't use the maxlength
694 if ($foreignData['foreign_link'] == true) {
695 echo $backup_field . "\n";
697 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>"
699 <input type
="text" name
="fields<?php echo $field_name_appendix; ?>"
700 class="textfield" <?php
echo $unnullify_trigger; ?
>
701 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
702 id
="field_<?php echo ($idindex); ?>_3"
703 value
="<?php echo htmlspecialchars($data); ?>" />
704 <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
>
706 } elseif (is_array($foreignData['disp_row'])) {
707 echo $backup_field . "\n";
709 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>"
711 <select name
="fields<?php echo $field_name_appendix; ?>"
712 <?php
echo $unnullify_trigger; ?
>
714 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
715 id
="field_<?php echo ($idindex); ?>_3">
716 <?php
echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?
>
720 unset($foreignData['disp_row']);
721 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
725 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
726 <td colspan
="5" align
="right">
727 <?php
echo $backup_field . "\n"; ?
>
728 <textarea name
="fields<?php echo $field_name_appendix; ?>"
729 rows
="<?php echo ($cfg['TextareaRows']*2); ?>"
730 cols
="<?php echo ($cfg['TextareaCols']*2); ?>"
731 dir
="<?php echo $text_dir; ?>"
732 id
="field_<?php echo ($idindex); ?>_3"
733 <?php
echo $unnullify_trigger; ?
>
734 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
735 ><?php
echo $special_chars_encoded; ?
></textarea
>
737 } elseif (strstr($field['pma_type'], 'text')) {
738 echo $backup_field . "\n";
740 <textarea name
="fields<?php echo $field_name_appendix; ?>"
741 rows
="<?php echo $cfg['TextareaRows']; ?>"
742 cols
="<?php echo $cfg['TextareaCols']; ?>"
743 dir
="<?php echo $text_dir; ?>"
744 id
="field_<?php echo ($idindex); ?>_3"
745 <?php
echo $unnullify_trigger; ?
>
746 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
747 ><?php
echo $special_chars_encoded; ?
></textarea
>
750 if (strlen($special_chars) > 32000) {
752 echo ' <td>' . __(' Because of its length,<br /> this column might not be editable ');
754 } elseif ($field['pma_type'] == 'enum') {
755 if (! isset($table_fields[$i]['values'])) {
756 $table_fields[$i]['values'] = array();
757 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
758 // Removes automatic MySQL escape format
759 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
760 $table_fields[$i]['values'][] = array(
762 'html' => htmlspecialchars($val),
766 $field_enum_values = $table_fields[$i]['values'];
768 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>" value
="enum" />
769 <input type
="hidden" name
="fields<?php echo $field_name_appendix; ?>" value
="" />
771 echo "\n" . ' ' . $backup_field . "\n";
773 // show dropdown or radio depend on length
774 if (strlen($field['Type']) > 20) {
776 <select name
="fields<?php echo $field_name_appendix; ?>"
777 <?php
echo $unnullify_trigger; ?
>
779 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
780 id
="field_<?php echo ($idindex); ?>_3">
781 <option value
=""> 
;</option
>
785 foreach ($field_enum_values as $enum_value) {
787 echo '<option value="' . $enum_value['html'] . '"';
788 if ($data == $enum_value['plain']
790 && (! isset($where_clause) ||
$field['Null'] != 'YES')
791 && isset($field['Default'])
792 && $enum_value['plain'] == $field['Default'])) {
793 echo ' selected="selected"';
795 echo '>' . $enum_value['html'] . '</option>' . "\n";
803 foreach ($field_enum_values as $enum_value) {
805 echo '<input type="radio" name="fields' . $field_name_appendix . '"';
806 echo ' class="textfield"';
807 echo ' value="' . $enum_value['html'] . '"';
808 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
809 echo $unnullify_trigger;
810 if ($data == $enum_value['plain']
812 && (! isset($where_clause) ||
$field['Null'] != 'YES')
813 && isset($field['Default'])
814 && $enum_value['plain'] == $field['Default'])) {
815 echo ' checked="checked"';
817 echo ' tabindex="' . ($tabindex +
$tabindex_for_value) . '" />';
818 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
819 . $enum_value['html'] . '</label>' . "\n";
823 } elseif ($field['pma_type'] == 'set') {
824 if (! isset($table_fields[$i]['values'])) {
825 $table_fields[$i]['values'] = array();
826 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
827 $table_fields[$i]['values'][] = array(
829 'html' => htmlspecialchars($val),
832 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
834 $field_set_values = $table_fields[$i]['values'];
835 $select_size = $table_fields[$i]['select_size'];
837 $vset = array_flip(explode(',', $data));
838 echo $backup_field . "\n";
840 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>" value
="set" />
841 <select name
="fields<?php echo $field_name_appendix . '[]'; ?>"
843 size
="<?php echo $select_size; ?>"
844 multiple
="multiple" <?php
echo $unnullify_trigger; ?
>
845 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
846 id
="field_<?php echo ($idindex); ?>_3">
848 foreach ($field_set_values as $field_set_value) {
850 echo '<option value="' . $field_set_value['html'] . '"';
851 if (isset($vset[$field_set_value['plain']])) {
852 echo ' selected="selected"';
854 echo '>' . $field_set_value['html'] . '</option>' . "\n";
860 // We don't want binary data destroyed
861 elseif ($field['is_binary'] ||
$field['is_blob']) {
862 if (($cfg['ProtectBinary'] && $field['is_blob'])
863 ||
($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
866 if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
868 echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_md5'] . $vkey . '" value="' . $data . '" />';
869 echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . __('Remove BLOB Repository Reference') . "<br />";
870 echo PMA_BS_CreateReferenceLink($data, $db);
875 echo __('Binary - do not edit');
877 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
878 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
882 } // end if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
884 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>" value
="protected" />
885 <input type
="hidden" name
="fields<?php echo $field_name_appendix; ?>" value
="" />
887 } elseif ($field['is_blob']) {
889 echo $backup_field . "\n";
891 <textarea name
="fields<?php echo $field_name_appendix; ?>"
892 rows
="<?php echo $cfg['TextareaRows']; ?>"
893 cols
="<?php echo $cfg['TextareaCols']; ?>"
894 dir
="<?php echo $text_dir; ?>"
895 id
="field_<?php echo ($idindex); ?>_3"
896 <?php
echo $unnullify_trigger; ?
>
897 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
898 ><?php
echo $special_chars_encoded; ?
></textarea
>
902 // field size should be at least 4 and max $cfg['LimitChars']
903 $fieldsize = min(max($field['len'], 4), $cfg['LimitChars']);
905 echo $backup_field . "\n";
907 <input type
="text" name
="fields<?php echo $field_name_appendix; ?>"
908 value
="<?php echo $special_chars; ?>" size
="<?php echo $fieldsize; ?>"
909 class="textfield" <?php
echo $unnullify_trigger; ?
>
910 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
911 id
="field_<?php echo ($idindex); ?>_3" />
913 } // end if...elseif...else
915 // Upload choice (only for BLOBs because the binary
916 // attribute does not imply binary contents)
917 // (displayed whatever value the ProtectBinary has)
919 if ($is_upload && $field['is_blob']) {
920 // check if field type is of longblob and if the table is PBMS enabled.
921 if (($field['pma_type'] == "longblob") && PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type)) {
923 echo '<input type="checkbox" name="upload_blob_repo' . $vkey . '[' . $field['Field_md5'] . ']" /> ' . __('Upload to BLOB repository');
927 echo '<input type="file" name="fields_upload' . $vkey . '[' . $field['Field_md5'] . ']" class="textfield" id="field_' . $idindex . '_3" size="10" ' . $unnullify_trigger . '/> ';
929 // find maximum upload size, based on field type
931 * @todo with functions this is not so easy, as you can basically
932 * process any data with function like MD5
934 $max_field_sizes = array(
937 'mediumblob' => '16777216',
938 'longblob' => '4294967296'); // yeah, really
940 $this_field_max_size = $max_upload_size; // from PHP max
941 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
942 $this_field_max_size = $max_field_sizes[$field['pma_type']];
944 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
945 // do not generate here the MAX_FILE_SIZE, because we should
946 // put only one in the form to accommodate the biggest field
947 if ($this_field_max_size > $biggest_max_file_size) {
948 $biggest_max_file_size = $this_field_max_size;
952 if (!empty($cfg['UploadDir'])) {
953 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
954 if ($files === FALSE) {
955 echo ' <font color="red">' . __('Error') . '</font><br />' . "\n";
956 echo ' ' . __('The directory you set for upload work cannot be reached') . "\n";
957 } elseif (!empty($files)) {
959 echo ' <i>' . __('Or') . '</i>' . ' ' . __('web server upload directory') . ':<br />' . "\n";
960 echo ' <select size="1" name="fields_uploadlocal' . $vkey . '[' . $field['Field_md5'] . ']">' . "\n";
961 echo ' <option value="" selected="selected"></option>' . "\n";
963 echo ' </select>' . "\n";
965 } // end if (web-server upload directory)
966 } // end elseif (binary or blob)
968 elseif ('geometry' == $field['pma_type']) {
969 // ignore this column to avoid changing it
972 // field size should be at least 4 and max 40
973 $fieldsize = min(max($field['len'], 4), 40);
974 echo $backup_field . "\n";
975 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' ||
strpos($data, "\n") !== FALSE)) {
978 <textarea name
="fields<?php echo $field_name_appendix; ?>"
979 rows
="<?php echo $cfg['CharTextareaRows']; ?>"
980 cols
="<?php echo $cfg['CharTextareaCols']; ?>"
981 dir
="<?php echo $text_dir; ?>"
982 id
="field_<?php echo ($idindex); ?>_3"
983 <?php
echo $unnullify_trigger; ?
>
984 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
985 ><?php
echo $special_chars_encoded; ?
></textarea
>
988 $the_class = 'textfield';
989 if ($field['pma_type'] == 'date') {
990 $the_class .= ' datefield';
991 } elseif ($field['pma_type'] == 'datetime' ||
substr($field['pma_type'], 0, 9) == 'timestamp') {
992 $the_class .= ' datetimefield';
995 <input type
="text" name
="fields<?php echo $field_name_appendix; ?>"
996 value
="<?php echo $special_chars; ?>" size
="<?php echo $fieldsize; ?>"
997 class="<?php echo $the_class; ?>" <?php
echo $unnullify_trigger; ?
>
998 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
999 id
="field_<?php echo ($idindex); ?>_3" />
1001 if ($field['Extra'] == 'auto_increment') {
1003 <input type
="hidden" name
="auto_increment<?php echo $field_name_appendix; ?>" value
="1" />
1006 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
1008 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>" value
="timestamp" />
1011 if (substr($field['pma_type'], 0, 8) == 'datetime') {
1013 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>" value
="datetime" />
1016 if ($field['True_Type'] == 'bit') {
1018 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>" value
="bit" />
1021 if ($field['pma_type'] == 'date' ||
$field['pma_type'] == 'datetime' ||
substr($field['pma_type'], 0, 9) == 'timestamp') {
1022 // the _3 suffix points to the date field
1023 // the _2 suffix points to the corresponding NULL checkbox
1024 // in dateFormat, 'yy' means the year with 4 digits
1032 $odd_row = !$odd_row;
1035 echo ' </tbody></table><br />';
1036 } // end foreach on multi-edit
1040 <fieldset id
="actions_panel">
1041 <table border
="0" cellpadding
="5" cellspacing
="0">
1043 <td valign
="middle" nowrap
="nowrap">
1044 <select name
="submit_type" class="control_at_footer" tabindex
="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
1046 if (isset($where_clause)) {
1048 <option value
="save"><?php
echo __('Save'); ?
></option
>
1052 <option value
="insert"><?php
echo __('Insert as new row'); ?
></option
>
1053 <option value
="insertignore"><?php
echo __('Insert as new row and ignore errors'); ?
></option
>
1054 <option value
="showinsert"><?php
echo __('Show insert query'); ?
></option
>
1059 if (!isset($after_insert)) {
1060 $after_insert = 'back';
1064 <td valign
="middle">
1065  
; 
; 
;<strong
><?php
echo __('and then'); ?
></strong
> 
; 
; 
;
1067 <td valign
="middle" nowrap
="nowrap">
1068 <select name
="after_insert">
1069 <option value
="back" <?php
echo ($after_insert == 'back' ?
'selected="selected"' : ''); ?
>><?php
echo __('Go back to previous page'); ?
></option
>
1070 <option value
="new_insert" <?php
echo ($after_insert == 'new_insert' ?
'selected="selected"' : ''); ?
>><?php
echo __('Insert another new row'); ?
></option
>
1072 if (isset($where_clause)) {
1074 <option value
="same_insert" <?php
echo ($after_insert == 'same_insert' ?
'selected="selected"' : ''); ?
>><?php
echo __('Go back to this page'); ?
></option
>
1076 // If we have just numeric primary key, we can also edit next
1077 // in 2.8.2, we were looking for `field_name` = numeric_value
1078 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1079 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1080 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause)) {
1082 <option value
="edit_next" <?php
echo ($after_insert == 'edit_next' ?
'selected="selected"' : ''); ?
>><?php
echo __('Edit next row'); ?
></option
>
1093 <?php
echo PMA_showHint(__('Use TAB key to move from value to value, or CTRL+arrows to move anywhere')); ?
>
1095 <td colspan
="3" align
="right" valign
="middle">
1096 <input type
="submit" class="control_at_footer" value
="<?php echo __('Go'); ?>" tabindex
="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id
="buttonYes" />
1097 <input type
="reset" class="control_at_footer" value
="<?php echo __('Reset'); ?>" tabindex
="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1102 <?php
if ($biggest_max_file_size > 0) {
1103 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1109 <!-- Continue insertion form
-->
1110 <form id
="continueForm" method
="post" action
="tbl_replace.php" name
="continueForm" >
1111 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
1112 <input type
="hidden" name
="goto" value
="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1113 <input type
="hidden" name
="err_url" value
="<?php echo htmlspecialchars($err_url); ?>" />
1114 <input type
="hidden" name
="sql_query" value
="<?php echo htmlspecialchars($sql_query); ?>" />
1116 if (isset($where_clauses)) {
1117 foreach ($where_clause_array as $key_id => $where_clause) {
1118 echo '<input type="hidden" name="where_clause[' . $key_id . ']" value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n";
1121 $tmp = '<select name="insert_rows" id="insert_rows">' . "\n";
1122 $option_values = array(1,2,5,10,15,20,30,40);
1123 foreach ($option_values as $value) {
1124 $tmp .= '<option value="' . $value . '"';
1125 if ($value == $cfg['InsertRows']) {
1126 $tmp .= ' selected="selected"';
1128 $tmp .= '>' . $value . '</option>' . "\n";
1130 $tmp .= '</select>' . "\n";
1131 echo "\n" . sprintf(__('Continue insertion with %s rows'), $tmp);
1133 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>' . "\n";
1134 echo '</form>' . "\n";
1138 * Displays the footer
1140 require './libraries/footer.inc.php';