Translated using Weblate.
[phpmyadmin.git] / tbl_change.php
blobba1aba296c12a265e96d9a7808c3dd3dded04975
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Displays form for editing and inserting new table rows
6 * register_globals_save (mark this file save for disabling register globals)
8 * @package PhpMyAdmin
9 */
11 /**
12 * Gets the variables sent or posted to this script and displays the header
14 require_once './libraries/common.inc.php';
15 require_once './libraries/common.lib.php';
17 /**
18 * Ensures db and table are valid, else moves to the "parent" script
20 require_once './libraries/db_table_exists.lib.php';
22 // load additional configuration variables
23 if (PMA_DRIZZLE) {
24 include_once './libraries/data_drizzle.inc.php';
25 } else {
26 include_once './libraries/data_mysql.inc.php';
29 /**
30 * Sets global variables.
31 * Here it's better to use a if, instead of the '?' operator
32 * to avoid setting a variable to '' when it's not present in $_REQUEST
34 if (isset($_REQUEST['where_clause'])) {
35 $where_clause = $_REQUEST['where_clause'];
37 if (isset($_REQUEST['clause_is_unique'])) {
38 $clause_is_unique = $_REQUEST['clause_is_unique'];
40 if (isset($_SESSION['edit_next'])) {
41 $where_clause = $_SESSION['edit_next'];
42 unset($_SESSION['edit_next']);
43 $after_insert = 'edit_next';
45 if (isset($_REQUEST['sql_query'])) {
46 $sql_query = $_REQUEST['sql_query'];
48 if (isset($_REQUEST['ShowFunctionFields'])) {
49 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
51 if (isset($_REQUEST['ShowFieldTypesInDataEditView'])) {
52 $cfg['ShowFieldTypesInDataEditView'] = $_REQUEST['ShowFieldTypesInDataEditView'];
54 if (isset($_REQUEST['default_action'])) {
55 $default_action = $_REQUEST['default_action'];
58 /**
59 * file listing
61 require_once './libraries/file_listing.php';
64 /**
65 * Defines the url to return to in case of error in a sql statement
66 * (at this point, $GLOBALS['goto'] will be set but could be empty)
68 if (empty($GLOBALS['goto'])) {
69 if (strlen($table)) {
70 // avoid a problem (see bug #2202709)
71 $GLOBALS['goto'] = 'tbl_sql.php';
72 } else {
73 $GLOBALS['goto'] = 'db_sql.php';
76 /**
77 * @todo check if we could replace by "db_|tbl_" - please clarify!?
79 $_url_params = array(
80 'db' => $db,
81 'sql_query' => $sql_query
84 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
85 $_url_params['table'] = $table;
88 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
89 unset($_url_params);
92 /**
93 * Sets parameters for links
94 * where is this variable used?
95 * replace by PMA_generate_common_url($url_params);
97 $url_query = PMA_generate_common_url($url_params, 'html', '');
99 /**
100 * get table information
101 * @todo should be done by a Table object
103 require_once './libraries/tbl_info.inc.php';
106 * Get comments for table fileds/columns
108 $comments_map = array();
110 if ($GLOBALS['cfg']['ShowPropertyComments']) {
111 $comments_map = PMA_getComments($db, $table);
115 * START REGULAR OUTPUT
119 * used in ./libraries/header.inc.php to load JavaScript library file
121 $GLOBALS['js_include'][] = 'functions.js';
122 $GLOBALS['js_include'][] = 'tbl_change.js';
123 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.16.custom.js';
124 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
125 $GLOBALS['js_include'][] = 'gis_data_editor.js';
128 * HTTP and HTML headers
130 require_once './libraries/header.inc.php';
133 * Displays the query submitted and its result
135 * @todo where does $disp_message and $disp_query come from???
137 if (! empty($disp_message)) {
138 if (! isset($disp_query)) {
139 $disp_query = null;
141 PMA_showMessage($disp_message, $disp_query);
145 * Displays top menu links
147 require_once './libraries/tbl_links.inc.php';
151 * Get the analysis of SHOW CREATE TABLE for this table
152 * @todo should be handled by class Table
154 $show_create_table = PMA_DBI_fetch_value(
155 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
156 0, 1
158 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
159 unset($show_create_table);
162 * Get the list of the fields of the current table
164 PMA_DBI_select_db($db);
165 $table_fields = array_values(PMA_DBI_get_columns($db, $table));
166 $rows = array();
167 if (isset($where_clause)) {
168 // when in edit mode load all selected rows from table
169 $insert_mode = false;
170 if (is_array($where_clause)) {
171 $where_clause_array = $where_clause;
172 } else {
173 $where_clause_array = array(0 => $where_clause);
176 $result = array();
177 $found_unique_key = false;
178 $where_clauses = array();
180 foreach ($where_clause_array as $key_id => $where_clause) {
181 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
182 . ' WHERE ' . $where_clause . ';';
183 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
184 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
185 $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
187 // No row returned
188 if (! $rows[$key_id]) {
189 unset($rows[$key_id], $where_clause_array[$key_id]);
190 PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query);
191 echo "\n";
192 include './libraries/footer.inc.php';
193 } else { // end if (no row returned)
194 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
195 list($unique_condition, $tmp_clause_is_unique)
196 = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true);
197 if (! empty($unique_condition)) {
198 $found_unique_key = true;
200 unset($unique_condition, $tmp_clause_is_unique);
204 } else {
205 // no primary key given, just load first row - but what happens if table is empty?
206 $insert_mode = true;
207 $result = PMA_DBI_query(
208 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;',
209 null,
210 PMA_DBI_QUERY_STORE
212 $rows = array_fill(0, $cfg['InsertRows'], false);
215 // Copying a row - fetched data will be inserted as a new row, therefore the where clause is needless.
216 if (isset($default_action) && $default_action === 'insert') {
217 unset($where_clause, $where_clauses);
220 // retrieve keys into foreign fields, if any
221 $foreigners = PMA_getForeigners($db, $table);
225 * Displays the form
227 // autocomplete feature of IE kills the "onchange" event handler and it
228 // must be replaced by the "onpropertychange" one in this case
229 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7)
230 ? 'onpropertychange'
231 : 'onchange';
232 // Had to put the URI because when hosted on an https server,
233 // some browsers send wrongly this form to the http server.
236 <!-- Set on key handler for moving using by Ctrl+arrows -->
237 <script src="./js/keyhandler.js" type="text/javascript"></script>
238 <script type="text/javascript">
239 //<![CDATA[
240 var switch_movement = 0;
241 document.onkeydown = onKeyDownArrowsHandler;
242 //]]>
243 </script>
244 <?php
246 $_form_params = array(
247 'db' => $db,
248 'table' => $table,
249 'goto' => $GLOBALS['goto'],
250 'err_url' => $err_url,
251 'sql_query' => $sql_query,
253 if (isset($where_clauses)) {
254 foreach ($where_clause_array as $key_id => $where_clause) {
255 $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
258 if (isset($clause_is_unique)) {
259 $_form_params['clause_is_unique'] = $clause_is_unique;
264 <!-- Insert/Edit form -->
265 <form id="insertForm" method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
266 <?php
267 echo PMA_generate_common_hidden_inputs($_form_params);
269 $titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
271 // Set if we passed the first timestamp field
272 $timestamp_seen = 0;
273 $fields_cnt = count($table_fields);
275 $tabindex = 0;
276 $tabindex_for_function = +3000;
277 $tabindex_for_null = +6000;
278 $tabindex_for_value = 0;
279 $o_rows = 0;
280 $biggest_max_file_size = 0;
282 // user can toggle the display of Function column
283 // (currently does not work for multi-edits)
284 $url_params['db'] = $db;
285 $url_params['table'] = $table;
286 if (isset($where_clause)) {
287 $url_params['where_clause'] = trim($where_clause);
289 if (! empty($sql_query)) {
290 $url_params['sql_query'] = $sql_query;
293 if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) {
294 echo __('Show');
296 if (! $cfg['ShowFunctionFields']) {
297 $this_url_params = array_merge(
298 $url_params,
299 array(
300 'ShowFunctionFields' => 1,
301 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'],
302 'goto' => 'sql.php'
305 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . __('Function') . '</a>' . "\n";
307 if (! $cfg['ShowFieldTypesInDataEditView']) {
308 $this_other_url_params = array_merge(
309 $url_params,
310 array(
311 'ShowFieldTypesInDataEditView' => 1,
312 'ShowFunctionFields' => $cfg['ShowFunctionFields'],
313 'goto' => 'sql.php'
316 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_other_url_params) . '">' . __('Type') . '</a>' . "\n";
319 foreach ($rows as $row_id => $vrow) {
320 if ($vrow === false) {
321 unset($vrow);
324 $jsvkey = $row_id;
325 $rownumber_param = '&amp;rownumber=' . $row_id;
326 $vkey = '[multi_edit][' . $jsvkey . ']';
328 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ? $result[$row_id] : $result);
329 if ($insert_mode && $row_id > 0) {
330 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_' . $row_id . '" />';
331 echo '<label for="insert_ignore_' . $row_id . '">' . __('Ignore') . '</label><br />' . "\n";
334 <table class="insertRowTable">
335 <thead>
336 <tr>
337 <th><?php echo __('Column'); ?></th>
339 <?php
340 if ($cfg['ShowFieldTypesInDataEditView']) {
341 $this_url_params = array_merge(
342 $url_params,
343 array(
344 'ShowFieldTypesInDataEditView' => 0,
345 'ShowFunctionFields' => $cfg['ShowFunctionFields'],
346 'goto' => 'sql.php'
349 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Type') . '</a></th>' . "\n";
352 if ($cfg['ShowFunctionFields']) {
353 $this_url_params = array_merge(
354 $url_params,
355 array(
356 'ShowFunctionFields' => 0,
357 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'],
358 'goto' => 'sql.php'
361 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Function') . '</a></th>' . "\n";
364 <th><?php echo __('Null'); ?></th>
365 <th><?php echo __('Value'); ?></th>
366 </tr>
367 </thead>
368 <tfoot>
369 <tr>
370 <th colspan="5" align="right" class="tblFooters">
371 <input type="submit" value="<?php echo __('Go'); ?>" />
372 </th>
373 </tr>
374 </tfoot>
375 <tbody>
376 <?php
377 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
378 $m_rows = $o_rows + 1;
380 $odd_row = true;
381 for ($i = 0; $i < $fields_cnt; $i++) {
382 if (! isset($table_fields[$i]['processed'])) {
383 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
384 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
385 // True_Type contains only the type (stops at first bracket)
386 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
388 // d a t e t i m e
390 // Current date should not be set as default if the field is NULL
391 // for the current row, but do not put here the current datetime
392 // if there is a default value (the real default value will be set
393 // in the Default value logic below)
395 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
396 // $field['Default'] is not set if it contains NULL:
397 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
398 // but, look what we get if we switch to iso: (Default is NULL)
399 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
400 // so I force a NULL into it (I don't think it's possible
401 // to have an empty default value for DATETIME)
402 // then, the "if" after this one will work
403 if ($table_fields[$i]['Type'] == 'datetime'
404 && ! isset($table_fields[$i]['Default'])
405 && isset($table_fields[$i]['Null'])
406 && $table_fields[$i]['Null'] == 'YES'
408 $table_fields[$i]['Default'] = null;
411 $table_fields[$i]['len']
412 = preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1;
415 if (isset($comments_map[$table_fields[$i]['Field']])) {
416 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
417 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
418 . $table_fields[$i]['Field_html'] . '</span>';
419 } else {
420 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
423 // The type column.
424 // Fix for bug #3152931 'ENUM and SET cannot have "Binary" option'
425 // If check to ensure types such as "enum('one','two','binary',..)" or
426 // "enum('one','two','varbinary',..)" are not categorized as binary.
427 if (stripos($table_fields[$i]['Type'], 'binary') === 0
428 || stripos($table_fields[$i]['Type'], 'varbinary') === 0
430 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
431 } else {
432 $table_fields[$i]['is_binary'] = false;
435 // If check to ensure types such as "enum('one','two','blob',..)" or
436 // "enum('one','two','tinyblob',..)" etc. are not categorized as blob.
437 if (stripos($table_fields[$i]['Type'], 'blob') === 0
438 || stripos($table_fields[$i]['Type'], 'tinyblob') === 0
439 || stripos($table_fields[$i]['Type'], 'mediumblob') === 0
440 || stripos($table_fields[$i]['Type'], 'longblob') === 0
442 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
443 } else {
444 $table_fields[$i]['is_blob'] = false;
447 // If check to ensure types such as "enum('one','two','char',..)" or
448 // "enum('one','two','varchar',..)" are not categorized as char.
449 if (stripos($table_fields[$i]['Type'], 'char') === 0
450 || stripos($table_fields[$i]['Type'], 'varchar') === 0
452 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
453 } else {
454 $table_fields[$i]['is_char'] = false;
457 $table_fields[$i]['first_timestamp'] = false;
458 switch ($table_fields[$i]['True_Type']) {
459 case 'set':
460 $table_fields[$i]['pma_type'] = 'set';
461 $table_fields[$i]['wrap'] = '';
462 break;
463 case 'enum':
464 $table_fields[$i]['pma_type'] = 'enum';
465 $table_fields[$i]['wrap'] = '';
466 break;
467 case 'timestamp':
468 if (!$timestamp_seen) { // can only occur once per table
469 $timestamp_seen = 1;
470 $table_fields[$i]['first_timestamp'] = true;
472 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
473 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
474 break;
476 default:
477 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
478 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
479 break;
482 $field = $table_fields[$i];
483 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
485 if (-1 === $field['len']) {
486 $field['len'] = PMA_DBI_field_len($vresult, $i);
487 // length is unknown for geometry fields, make enough space to edit very simple WKTs
488 if (-1 === $field['len']) {
489 $field['len'] = 30;
492 //Call validation when the form submited...
493 $unnullify_trigger = $chg_evt_handler . "=\"return verificationsAfterFieldChange('"
494 . PMA_escapeJsString($field['Field_md5']) . "', '"
495 . PMA_escapeJsString($jsvkey) . "','".$field['pma_type']."')\"";
497 // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
498 $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
500 if ($field['Type'] == 'datetime'
501 && ! isset($field['Default'])
502 && ! is_null($field['Default'])
503 && ($insert_mode || ! isset($vrow[$field['Field']]))
505 // INSERT case or
506 // UPDATE case with an NULL value
507 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
510 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; ?>">
511 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center">
512 <?php echo $field['Field_title']; ?>
513 <input type="hidden" name="fields_name<?php echo $field_name_appendix; ?>" value="<?php echo $field['Field_html']; ?>"/>
514 </td>
515 <?php if ($cfg['ShowFieldTypesInDataEditView']) { ?>
516 <td align="center"<?php echo $field['wrap']; ?>><span class="column_type"><?php echo $field['pma_type']; ?></span>
517 </td>
519 <?php } //End if
521 // Get a list of GIS data types.
522 $gis_data_types = PMA_getGISDatatypes();
524 // Prepares the field value
525 $real_null_value = false;
526 $special_chars_encoded = '';
527 if (isset($vrow)) {
528 // (we are editing)
529 if (is_null($vrow[$field['Field']])) {
530 $real_null_value = true;
531 $vrow[$field['Field']] = '';
532 $special_chars = '';
533 $data = $vrow[$field['Field']];
534 } elseif ($field['True_Type'] == 'bit') {
535 $special_chars = PMA_printable_bit_value(
536 $vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']
538 } elseif (in_array($field['True_Type'], $gis_data_types)) {
539 // Convert gis data to Well Know Text format
540 $vrow[$field['Field']] = PMA_asWKT($vrow[$field['Field']], true);
541 $special_chars = htmlspecialchars($vrow[$field['Field']]);
542 } else {
543 // special binary "characters"
544 if ($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) {
545 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
546 $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]);
547 $field['display_binary_as_hex'] = true;
548 } else {
549 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
551 } // end if
552 $special_chars = htmlspecialchars($vrow[$field['Field']]);
554 //We need to duplicate the first \n or otherwise we will lose
555 //the first newline entered in a VARCHAR or TEXT column
556 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
558 $data = $vrow[$field['Field']];
559 } // end if... else...
561 //when copying row, it is useful to empty auto-increment column to prevent duplicate key error
562 if (isset($default_action) && $default_action === 'insert') {
563 if ($field['Key'] === 'PRI' && strpos($field['Extra'], 'auto_increment') !== false) {
564 $data = $special_chars_encoded = $special_chars = null;
567 // If a timestamp field value is not included in an update
568 // statement MySQL auto-update it to the current timestamp;
569 // however, things have changed since MySQL 4.1, so
570 // it's better to set a fields_prev in this situation
571 $backup_field = '<input type="hidden" name="fields_prev'
572 . $field_name_appendix . '" value="'
573 . htmlspecialchars($vrow[$field['Field']]) . '" />';
574 } else {
575 // (we are inserting)
576 // display default values
577 if (! isset($field['Default'])) {
578 $field['Default'] = '';
579 $real_null_value = true;
580 $data = '';
581 } else {
582 $data = $field['Default'];
584 if ($field['True_Type'] == 'bit') {
585 $special_chars = PMA_convert_bit_default_value($field['Default']);
586 } else {
587 $special_chars = htmlspecialchars($field['Default']);
589 $backup_field = '';
590 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
591 // this will select the UNHEX function while inserting
592 if (($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary']))
593 && $_SESSION['tmp_user_values']['display_binary_as_hex']
594 && $cfg['ShowFunctionFields']
596 $field['display_binary_as_hex'] = true;
600 $idindex = ($o_rows * $fields_cnt) + $i + 1;
601 $tabindex = $idindex;
603 // Get a list of data types that are not yet supported.
604 $no_support_types = PMA_unsupportedDatatypes();
606 // The function column
607 // -------------------
608 // We don't want binary data to be destroyed
609 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
610 // stored or retrieved" so it does not mean that the contents is
611 // binary
612 if ($cfg['ShowFunctionFields']) {
613 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
614 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])
616 echo ' <td align="center">' . __('Binary') . '</td>' . "\n";
617 } elseif (strstr($field['True_Type'], 'enum')
618 || strstr($field['True_Type'], 'set')
619 || in_array($field['pma_type'], $no_support_types)
621 echo ' <td align="center">--</td>' . "\n";
622 } else {
624 <td>
625 <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">
626 <?php
627 echo PMA_getFunctionsForField($field, $insert_mode);
629 </select>
630 </td>
631 <?php
633 } // end if ($cfg['ShowFunctionFields'])
636 // The null column
637 // ---------------
638 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
639 echo ' <td>' . "\n";
640 if ($field['Null'] == 'YES') {
641 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
642 if ($real_null_value && !$field['first_timestamp']) {
643 echo ' value="on"';
645 echo ' />' . "\n";
647 echo ' <input type="checkbox" class="checkbox_null" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
648 . ' name="fields_null' . $field_name_appendix . '"';
649 if ($real_null_value && !$field['first_timestamp']) {
650 echo ' checked="checked"';
652 echo ' id="field_' . ($idindex) . '_2" />';
654 // nullify_code is needed by the js nullify() function
655 if (strstr($field['True_Type'], 'enum')) {
656 if (strlen($field['Type']) > 20) {
657 $nullify_code = '1';
658 } else {
659 $nullify_code = '2';
661 } elseif (strstr($field['True_Type'], 'set')) {
662 $nullify_code = '3';
663 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
664 // foreign key in a drop-down
665 $nullify_code = '4';
666 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
667 // foreign key with a browsing icon
668 $nullify_code = '6';
669 } else {
670 $nullify_code = '5';
672 // to be able to generate calls to nullify() in jQuery
673 echo '<input type="hidden" class="nullify_code" name="nullify_code'
674 . $field_name_appendix . '" value="' . $nullify_code . '" />';
675 echo '<input type="hidden" class="hashed_field" name="hashed_field'
676 . $field_name_appendix . '" value="' . $field['Field_md5'] . '" />';
677 echo '<input type="hidden" class="multi_edit" name="multi_edit'
678 . $field_name_appendix . '" value="' . PMA_escapeJsString($vkey) . '" />';
680 echo ' </td>' . "\n";
682 // The value column (depends on type)
683 // ----------------
684 // See bug #1667887 for the reason why we don't use the maxlength
685 // HTML attribute
687 echo ' <td>' . "\n";
688 // Will be used by js/tbl_change.js to set the default value
689 // for the "Continue insertion" feature
690 echo '<span class="default_value hide">' . $special_chars . '</span>';
691 if ($foreignData['foreign_link'] == true) {
692 echo $backup_field . "\n";
694 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
695 value="foreign" />
696 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
697 class="textfield" <?php echo $unnullify_trigger; ?>
698 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
699 id="field_<?php echo ($idindex); ?>_3"
700 value="<?php echo htmlspecialchars($data); ?>" />
701 <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); ?>&amp;field=<?php echo PMA_escapeJsString(urlencode($field['Field']) . $rownumber_param); ?>"><?php echo str_replace("'", "\'", $titles['Browse']); ?></a>
702 <?php
703 } elseif (is_array($foreignData['disp_row'])) {
704 echo $backup_field . "\n";
706 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
707 value="foreign" />
708 <select name="fields<?php echo $field_name_appendix; ?>"
709 <?php echo $unnullify_trigger; ?>
710 class="textfield"
711 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
712 id="field_<?php echo ($idindex); ?>_3">
713 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
714 </select>
715 <?php
716 // still needed? :
717 unset($foreignData['disp_row']);
718 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
720 &nbsp;</td>
721 </tr>
722 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
723 <td colspan="5" align="right">
724 <?php echo $backup_field . "\n"; ?>
725 <textarea name="fields<?php echo $field_name_appendix; ?>"
726 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
727 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
728 dir="<?php echo $text_dir; ?>"
729 id="field_<?php echo ($idindex); ?>_3"
730 <?php echo $unnullify_trigger; ?>
731 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
732 ><?php echo $special_chars_encoded; ?></textarea>
733 <?php
734 } elseif (strstr($field['pma_type'], 'text')) {
735 echo $backup_field . "\n";
737 <textarea name="fields<?php echo $field_name_appendix; ?>"
738 rows="<?php echo $cfg['TextareaRows']; ?>"
739 cols="<?php echo $cfg['TextareaCols']; ?>"
740 dir="<?php echo $text_dir; ?>"
741 id="field_<?php echo ($idindex); ?>_3"
742 <?php echo $unnullify_trigger; ?>
743 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
744 ><?php echo $special_chars_encoded; ?></textarea>
745 <?php
746 echo "\n";
747 if (strlen($special_chars) > 32000) {
748 echo " </td>\n";
749 echo ' <td>' . __('Because of its length,<br /> this column might not be editable');
751 } elseif ($field['pma_type'] == 'enum') {
752 if (! isset($table_fields[$i]['values'])) {
753 $table_fields[$i]['values'] = array();
754 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
755 // Removes automatic MySQL escape format
756 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
757 $table_fields[$i]['values'][] = array(
758 'plain' => $val,
759 'html' => htmlspecialchars($val),
763 $field_enum_values = $table_fields[$i]['values'];
765 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
766 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
767 <?php
768 echo "\n" . ' ' . $backup_field . "\n";
770 // show dropdown or radio depend on length
771 if (strlen($field['Type']) > 20) {
773 <select name="fields<?php echo $field_name_appendix; ?>"
774 <?php echo $unnullify_trigger; ?>
775 class="textfield"
776 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
777 id="field_<?php echo ($idindex); ?>_3">
778 <option value="">&nbsp;</option>
779 <?php
780 echo "\n";
782 foreach ($field_enum_values as $enum_value) {
783 echo ' ';
784 echo '<option value="' . $enum_value['html'] . '"';
785 if ($data == $enum_value['plain']
786 || ($data == ''
787 && (! isset($where_clause) || $field['Null'] != 'YES')
788 && isset($field['Default'])
789 && $enum_value['plain'] == $field['Default'])
791 echo ' selected="selected"';
793 echo '>' . $enum_value['html'] . '</option>' . "\n";
794 } // end for
797 </select>
798 <?php
799 } else {
800 $j = 0;
801 foreach ($field_enum_values as $enum_value) {
802 echo ' ';
803 echo '<input type="radio" name="fields' . $field_name_appendix . '"';
804 echo ' class="textfield"';
805 echo ' value="' . $enum_value['html'] . '"';
806 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
807 echo $unnullify_trigger;
808 if ($data == $enum_value['plain']
809 || ($data == ''
810 && (! isset($where_clause) || $field['Null'] != 'YES')
811 && isset($field['Default'])
812 && $enum_value['plain'] == $field['Default'])
814 echo ' checked="checked"';
816 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
817 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
818 . $enum_value['html'] . '</label>' . "\n";
819 $j++;
820 } // end for
821 } // end else
822 } elseif ($field['pma_type'] == 'set') {
823 if (! isset($table_fields[$i]['values'])) {
824 $table_fields[$i]['values'] = array();
825 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
826 $table_fields[$i]['values'][] = array(
827 'plain' => $val,
828 'html' => htmlspecialchars($val),
831 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
833 $field_set_values = $table_fields[$i]['values'];
834 $select_size = $table_fields[$i]['select_size'];
836 $vset = array_flip(explode(',', $data));
837 echo $backup_field . "\n";
839 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
840 <select name="fields<?php echo $field_name_appendix . '[]'; ?>"
841 class="textfield"
842 size="<?php echo $select_size; ?>"
843 multiple="multiple" <?php echo $unnullify_trigger; ?>
844 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
845 id="field_<?php echo ($idindex); ?>_3">
846 <?php
847 foreach ($field_set_values as $field_set_value) {
848 echo ' ';
849 echo '<option value="' . $field_set_value['html'] . '"';
850 if (isset($vset[$field_set_value['plain']])) {
851 echo ' selected="selected"';
853 echo '>' . $field_set_value['html'] . '</option>' . "\n";
854 } // end for
856 </select>
857 <?php
858 // We don't want binary data destroyed
859 } elseif ($field['is_binary'] || $field['is_blob']) {
860 if (($cfg['ProtectBinary'] && $field['is_blob'])
861 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])
863 echo __('Binary - do not edit');
864 if (isset($data)) {
865 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
866 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
867 unset($data_size);
870 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
871 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
872 <?php
873 } elseif ($field['is_blob']) {
874 echo "\n";
875 echo $backup_field . "\n";
877 <textarea name="fields<?php echo $field_name_appendix; ?>"
878 rows="<?php echo $cfg['TextareaRows']; ?>"
879 cols="<?php echo $cfg['TextareaCols']; ?>"
880 dir="<?php echo $text_dir; ?>"
881 id="field_<?php echo ($idindex); ?>_3"
882 <?php echo $unnullify_trigger; ?>
883 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
884 ><?php echo $special_chars_encoded; ?></textarea>
885 <?php
887 } else {
888 // field size should be at least 4 and max $cfg['LimitChars']
889 $fieldsize = min(max($field['len'], 4), $cfg['LimitChars']);
890 echo "\n";
891 echo $backup_field . "\n";
893 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
894 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
895 class="textfield" <?php echo $unnullify_trigger; ?>
896 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
897 id="field_<?php echo ($idindex); ?>_3" />
898 <?php
899 } // end if...elseif...else
901 // Upload choice (only for BLOBs because the binary
902 // attribute does not imply binary contents)
903 // (displayed whatever value the ProtectBinary has)
905 if ($is_upload && $field['is_blob']) {
906 echo '<br />';
907 echo '<input type="file" name="fields_upload' . $vkey . '[' . $field['Field_md5'] . ']" class="textfield" id="field_' . $idindex . '_3" size="10" ' . $unnullify_trigger . '/>&nbsp;';
909 // find maximum upload size, based on field type
911 * @todo with functions this is not so easy, as you can basically
912 * process any data with function like MD5
914 $max_field_sizes = array(
915 'tinyblob' => '256',
916 'blob' => '65536',
917 'mediumblob' => '16777216',
918 'longblob' => '4294967296'); // yeah, really
920 $this_field_max_size = $max_upload_size; // from PHP max
921 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
922 $this_field_max_size = $max_field_sizes[$field['pma_type']];
924 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
925 // do not generate here the MAX_FILE_SIZE, because we should
926 // put only one in the form to accommodate the biggest field
927 if ($this_field_max_size > $biggest_max_file_size) {
928 $biggest_max_file_size = $this_field_max_size;
932 if (!empty($cfg['UploadDir'])) {
933 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
934 if ($files === false) {
935 echo ' <font color="red">' . __('Error') . '</font><br />' . "\n";
936 echo ' ' . __('The directory you set for upload work cannot be reached') . "\n";
937 } elseif (!empty($files)) {
938 echo "<br />\n";
939 echo ' <i>' . __('Or') . '</i>' . ' ' . __('web server upload directory') . ':<br />' . "\n";
940 echo ' <select size="1" name="fields_uploadlocal' . $vkey . '[' . $field['Field_md5'] . ']">' . "\n";
941 echo ' <option value="" selected="selected"></option>' . "\n";
942 echo $files;
943 echo ' </select>' . "\n";
945 } // end if (web-server upload directory)
946 // end elseif (binary or blob)
947 } elseif (! in_array($field['pma_type'], $no_support_types)) {
948 // ignore this column to avoid changing it
949 if ($field['is_char']) {
950 $fieldsize = $extracted_fieldspec['spec_in_brackets'];
951 } else {
953 * This case happens for example for INT or DATE columns;
954 * in these situations, the value returned in $field['len']
955 * seems appropriate.
957 $fieldsize = $field['len'];
959 $fieldsize = min(max($fieldsize, $cfg['MinSizeForInputField']), $cfg['MaxSizeForInputField']);
960 echo $backup_field . "\n";
961 if ($field['is_char']
962 && ($cfg['CharEditing'] == 'textarea'
963 || strpos($data, "\n") !== false)
965 echo "\n";
967 <textarea class="char" name="fields<?php echo $field_name_appendix; ?>"
968 rows="<?php echo $cfg['CharTextareaRows']; ?>"
969 cols="<?php echo $cfg['CharTextareaCols']; ?>"
970 dir="<?php echo $text_dir; ?>"
971 id="field_<?php echo ($idindex); ?>_3"
972 <?php echo $unnullify_trigger; ?>
973 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
974 ><?php echo $special_chars_encoded; ?></textarea>
975 <?php
976 } else {
977 $the_class = 'textfield';
978 if ($field['pma_type'] == 'date') {
979 $the_class .= ' datefield';
980 } elseif ($field['pma_type'] == 'datetime'
981 || substr($field['pma_type'], 0, 9) == 'timestamp'
983 $the_class .= ' datetimefield';
986 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
987 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
988 class="<?php echo $the_class; ?>" <?php echo $unnullify_trigger; ?>
989 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
990 id="field_<?php echo ($idindex); ?>_3" />
991 <?php
992 if ($field['Extra'] == 'auto_increment') {
994 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
995 <?php
996 } // end if
997 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
999 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
1000 <?php
1002 if (substr($field['pma_type'], 0, 8) == 'datetime') {
1004 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="datetime" />
1005 <?php
1007 if ($field['True_Type'] == 'bit') {
1009 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
1010 <?php
1012 if ($field['pma_type'] == 'date'
1013 || $field['pma_type'] == 'datetime'
1014 || substr($field['pma_type'], 0, 9) == 'timestamp'
1016 // the _3 suffix points to the date field
1017 // the _2 suffix points to the corresponding NULL checkbox
1018 // in dateFormat, 'yy' means the year with 4 digits
1022 if (in_array($field['pma_type'], $gis_data_types)) {
1023 $data_val = isset($vrow[$field['Field']]) ? $vrow[$field['Field']] : '';
1024 $_url_params = array(
1025 'field' => $field['Field_title'],
1026 'value' => $data_val,
1028 if ($field['pma_type'] != 'geometry') {
1029 $_url_params = $_url_params + array('gis_data[gis_type]' => strtoupper($field['pma_type']));
1031 $edit_url = 'gis_data_editor.php' . PMA_generate_common_url($_url_params);
1032 $edit_str = PMA_getIcon('b_edit.png', __('Edit/Insert'));
1033 echo('<span class="open_gis_editor">');
1034 echo(PMA_linkOrButton($edit_url, $edit_str, array(), false, false, '_blank'));
1035 echo('</span>');
1038 </td>
1039 </tr>
1040 <?php
1041 $odd_row = !$odd_row;
1042 } // end for
1043 $o_rows++;
1044 echo ' </tbody></table><br />';
1045 } // end foreach on multi-edit
1047 <div id="gis_editor"></div><div id="popup_background"></div>
1048 <br />
1049 <fieldset id="actions_panel">
1050 <table border="0" cellpadding="5" cellspacing="0">
1051 <tr>
1052 <td valign="middle" nowrap="nowrap">
1053 <select name="submit_type" class="control_at_footer" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
1054 <?php
1055 if (isset($where_clause)) {
1057 <option value="save"><?php echo __('Save'); ?></option>
1058 <?php
1061 <option value="insert"><?php echo __('Insert as new row'); ?></option>
1062 <option value="insertignore"><?php echo __('Insert as new row and ignore errors'); ?></option>
1063 <option value="showinsert"><?php echo __('Show insert query'); ?></option>
1064 </select>
1065 <?php
1066 echo "\n";
1068 if (! isset($after_insert)) {
1069 $after_insert = 'back';
1072 </td>
1073 <td valign="middle">
1074 &nbsp;&nbsp;&nbsp;<strong><?php echo __('and then'); ?></strong>&nbsp;&nbsp;&nbsp;
1075 </td>
1076 <td valign="middle" nowrap="nowrap">
1077 <select name="after_insert">
1078 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to previous page'); ?></option>
1079 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Insert another new row'); ?></option>
1080 <?php
1081 if (isset($where_clause)) {
1083 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to this page'); ?></option>
1084 <?php
1085 // If we have just numeric primary key, we can also edit next
1086 // in 2.8.2, we were looking for `field_name` = numeric_value
1087 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1088 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1089 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause)) {
1091 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo __('Edit next row'); ?></option>
1092 <?php
1096 </select>
1097 </td>
1098 </tr>
1100 <tr>
1101 <td>
1102 <?php echo PMA_showHint(__('Use TAB key to move from value to value, or CTRL+arrows to move anywhere')); ?>
1103 </td>
1104 <td colspan="3" align="right" valign="middle">
1105 <input type="submit" class="control_at_footer" value="<?php echo __('Go'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1106 <input type="reset" class="control_at_footer" value="<?php echo __('Reset'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1107 </td>
1108 </tr>
1109 </table>
1110 </fieldset>
1111 <?php if ($biggest_max_file_size > 0) {
1112 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1113 } ?>
1114 </form>
1115 <?php
1116 if ($insert_mode) {
1118 <!-- Continue insertion form -->
1119 <form id="continueForm" method="post" action="tbl_replace.php" name="continueForm" >
1120 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1121 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1122 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
1123 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
1124 <?php
1125 if (isset($where_clauses)) {
1126 foreach ($where_clause_array as $key_id => $where_clause) {
1127 echo '<input type="hidden" name="where_clause[' . $key_id . ']" value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n";
1130 $tmp = '<select name="insert_rows" id="insert_rows">' . "\n";
1131 $option_values = array(1,2,5,10,15,20,30,40);
1132 foreach ($option_values as $value) {
1133 $tmp .= '<option value="' . $value . '"';
1134 if ($value == $cfg['InsertRows']) {
1135 $tmp .= ' selected="selected"';
1137 $tmp .= '>' . $value . '</option>' . "\n";
1139 $tmp .= '</select>' . "\n";
1140 echo "\n" . sprintf(__('Continue insertion with %s rows'), $tmp);
1141 unset($tmp);
1142 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>' . "\n";
1143 echo '</form>' . "\n";
1147 * Displays the footer
1149 require './libraries/footer.inc.php';