Translation update done using Pootle.
[phpmyadmin/tyronm.git] / tbl_change.php
blobe7011ebbf14083446d96c60db66dbcf0972a9125
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 require_once './libraries/data_mysql.inc.php';
25 /**
26 * Sets global variables.
27 * Here it's better to use a if, instead of the '?' operator
28 * to avoid setting a variable to '' when it's not present in $_REQUEST
30 if (isset($_REQUEST['where_clause'])) {
31 $where_clause = $_REQUEST['where_clause'];
33 if (isset($_REQUEST['clause_is_unique'])) {
34 $clause_is_unique = $_REQUEST['clause_is_unique'];
36 if (isset($_SESSION['edit_next'])) {
37 $where_clause = $_SESSION['edit_next'];
38 unset($_SESSION['edit_next']);
39 $after_insert = 'edit_next';
41 if (isset($_REQUEST['sql_query'])) {
42 $sql_query = $_REQUEST['sql_query'];
44 if (isset($_REQUEST['ShowFunctionFields'])) {
45 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
47 if (isset($_REQUEST['ShowFieldTypesInDataEditView'])) {
48 $cfg['ShowFieldTypesInDataEditView'] = $_REQUEST['ShowFieldTypesInDataEditView'];
50 if (isset($_REQUEST['default_action'])) {
51 $default_action = $_REQUEST['default_action'];
54 /**
55 * file listing
57 require_once './libraries/file_listing.php';
60 /**
61 * Defines the url to return to in case of error in a sql statement
62 * (at this point, $GLOBALS['goto'] will be set but could be empty)
64 if (empty($GLOBALS['goto'])) {
65 if (strlen($table)) {
66 // avoid a problem (see bug #2202709)
67 $GLOBALS['goto'] = 'tbl_sql.php';
68 } else {
69 $GLOBALS['goto'] = 'db_sql.php';
72 /**
73 * @todo check if we could replace by "db_|tbl_" - please clarify!?
75 $_url_params = array(
76 'db' => $db,
77 'sql_query' => $sql_query
80 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
81 $_url_params['table'] = $table;
84 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
85 unset($_url_params);
88 /**
89 * Sets parameters for links
90 * where is this variable used?
91 * replace by PMA_generate_common_url($url_params);
93 $url_query = PMA_generate_common_url($url_params, 'html', '');
95 /**
96 * get table information
97 * @todo should be done by a Table object
99 require_once './libraries/tbl_info.inc.php';
102 * Get comments for table fileds/columns
104 $comments_map = array();
106 if ($GLOBALS['cfg']['ShowPropertyComments']) {
107 $comments_map = PMA_getComments($db, $table);
111 * START REGULAR OUTPUT
115 * used in ./libraries/header.inc.php to load JavaScript library file
117 $GLOBALS['js_include'][] = 'functions.js';
118 $GLOBALS['js_include'][] = 'tbl_change.js';
119 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
120 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
122 // required for GIS editor
123 $GLOBALS['js_include'][] = 'gis_data_editor.js';
124 $GLOBALS['js_include'][] = 'jquery/jquery.svg.js';
125 $GLOBALS['js_include'][] = 'jquery/jquery.mousewheel.js';
126 $GLOBALS['js_include'][] = 'jquery/jquery.event.drag-2.0.min.js';
127 $GLOBALS['js_include'][] = 'tbl_gis_visualization.js';
128 $GLOBALS['js_include'][] = 'openlayers/OpenLayers.js';
129 $GLOBALS['js_include'][] = 'OpenStreetMap.js';
132 * HTTP and HTML headers
134 require_once './libraries/header.inc.php';
137 * Displays the query submitted and its result
139 * @todo where does $disp_message and $disp_query come from???
141 if (! empty($disp_message)) {
142 if (! isset($disp_query)) {
143 $disp_query = null;
145 PMA_showMessage($disp_message, $disp_query);
149 * Displays top menu links
151 require_once './libraries/tbl_links.inc.php';
155 * Get the analysis of SHOW CREATE TABLE for this table
156 * @todo should be handled by class Table
158 $show_create_table = PMA_DBI_fetch_value(
159 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
160 0, 1);
161 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
162 unset($show_create_table);
165 * Get the list of the fields of the current table
167 PMA_DBI_select_db($db);
168 $table_fields = array_values(PMA_DBI_get_columns($db, $table));
169 $rows = array();
170 if (isset($where_clause)) {
171 // when in edit mode load all selected rows from table
172 $insert_mode = false;
173 if (is_array($where_clause)) {
174 $where_clause_array = $where_clause;
175 } else {
176 $where_clause_array = array(0 => $where_clause);
179 $result = array();
180 $found_unique_key = false;
181 $where_clauses = array();
183 foreach ($where_clause_array as $key_id => $where_clause) {
184 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';';
185 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
186 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
187 $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
189 // No row returned
190 if (! $rows[$key_id]) {
191 unset($rows[$key_id], $where_clause_array[$key_id]);
192 PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query);
193 echo "\n";
194 require './libraries/footer.inc.php';
195 } else { // end if (no row returned)
196 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
197 list($unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true);
198 if (! empty($unique_condition)) {
199 $found_unique_key = true;
201 unset($unique_condition, $tmp_clause_is_unique);
205 } else {
206 // no primary key given, just load first row - but what happens if table is empty?
207 $insert_mode = true;
208 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
209 $rows = array_fill(0, $cfg['InsertRows'], false);
212 // Copying a row - fetched data will be inserted as a new row, therefore the where clause is needless.
213 if (isset($default_action) && $default_action === 'insert') {
214 unset($where_clause, $where_clauses);
217 // retrieve keys into foreign fields, if any
218 $foreigners = PMA_getForeigners($db, $table);
222 * Displays the form
224 // autocomplete feature of IE kills the "onchange" event handler and it
225 // must be replaced by the "onpropertychange" one in this case
226 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7)
227 ? 'onpropertychange'
228 : 'onchange';
229 // Had to put the URI because when hosted on an https server,
230 // some browsers send wrongly this form to the http server.
233 <!-- Set on key handler for moving using by Ctrl+arrows -->
234 <script src="./js/keyhandler.js" type="text/javascript"></script>
235 <script type="text/javascript">
236 //<![CDATA[
237 var switch_movement = 0;
238 document.onkeydown = onKeyDownArrowsHandler;
239 //]]>
240 </script>
241 <?php
243 $_form_params = array(
244 'db' => $db,
245 'table' => $table,
246 'goto' => $GLOBALS['goto'],
247 'err_url' => $err_url,
248 'sql_query' => $sql_query,
250 if (isset($where_clauses)) {
251 foreach ($where_clause_array as $key_id => $where_clause) {
252 $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
255 if (isset($clause_is_unique)) {
256 $_form_params['clause_is_unique'] = $clause_is_unique;
261 <!-- Insert/Edit form -->
262 <form id="insertForm" method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
263 <?php
264 echo PMA_generate_common_hidden_inputs($_form_params);
266 $titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
268 // Set if we passed the first timestamp field
269 $timestamp_seen = 0;
270 $fields_cnt = count($table_fields);
272 $tabindex = 0;
273 $tabindex_for_function = +3000;
274 $tabindex_for_null = +6000;
275 $tabindex_for_value = 0;
276 $o_rows = 0;
277 $biggest_max_file_size = 0;
279 // user can toggle the display of Function column
280 // (currently does not work for multi-edits)
281 $url_params['db'] = $db;
282 $url_params['table'] = $table;
283 if (isset($where_clause)) {
284 $url_params['where_clause'] = trim($where_clause);
286 if (! empty($sql_query)) {
287 $url_params['sql_query'] = $sql_query;
290 if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) {
291 echo __('Show');
293 if (! $cfg['ShowFunctionFields']) {
294 $this_url_params = array_merge($url_params,
295 array('ShowFunctionFields' => 1, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
296 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . __('Function') . '</a>' . "\n";
298 if (! $cfg['ShowFieldTypesInDataEditView']) {
299 $this_other_url_params = array_merge($url_params,
300 array('ShowFieldTypesInDataEditView' => 1, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
301 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_other_url_params) . '">' . __('Type') . '</a>' . "\n";
304 foreach ($rows as $row_id => $vrow) {
305 if ($vrow === false) {
306 unset($vrow);
309 $jsvkey = $row_id;
310 $rownumber_param = '&amp;rownumber=' . $row_id;
311 $vkey = '[multi_edit][' . $jsvkey . ']';
313 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ? $result[$row_id] : $result);
314 if ($insert_mode && $row_id > 0) {
315 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_' . $row_id . '" />';
316 echo '<label for="insert_ignore_' . $row_id . '">' . __('Ignore') . '</label><br />' . "\n";
319 <table class="insertRowTable">
320 <thead>
321 <tr>
322 <th><?php echo __('Column'); ?></th>
324 <?php
325 if ($cfg['ShowFieldTypesInDataEditView']) {
326 $this_url_params = array_merge($url_params,
327 array('ShowFieldTypesInDataEditView' => 0, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
328 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Type') . '</a></th>' . "\n";
331 if ($cfg['ShowFunctionFields']) {
332 $this_url_params = array_merge($url_params,
333 array('ShowFunctionFields' => 0, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
334 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Function') . '</a></th>' . "\n";
337 <th><?php echo __('Null'); ?></th>
338 <th><?php echo __('Value'); ?></th>
339 </tr>
340 </thead>
341 <tfoot>
342 <tr>
343 <th colspan="5" align="right" class="tblFooters">
344 <input type="submit" value="<?php echo __('Go'); ?>" />
345 </th>
346 </tr>
347 </tfoot>
348 <tbody>
349 <?php
350 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
351 $m_rows = $o_rows + 1;
353 $odd_row = true;
354 for ($i = 0; $i < $fields_cnt; $i++) {
355 if (! isset($table_fields[$i]['processed'])) {
356 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
357 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
358 // True_Type contains only the type (stops at first bracket)
359 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
361 // d a t e t i m e
363 // Current date should not be set as default if the field is NULL
364 // for the current row, but do not put here the current datetime
365 // if there is a default value (the real default value will be set
366 // in the Default value logic below)
368 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
369 // $field['Default'] is not set if it contains NULL:
370 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
371 // but, look what we get if we switch to iso: (Default is NULL)
372 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
373 // so I force a NULL into it (I don't think it's possible
374 // to have an empty default value for DATETIME)
375 // then, the "if" after this one will work
376 if ($table_fields[$i]['Type'] == 'datetime'
377 && ! isset($table_fields[$i]['Default'])
378 && isset($table_fields[$i]['Null'])
379 && $table_fields[$i]['Null'] == 'YES') {
380 $table_fields[$i]['Default'] = null;
383 $table_fields[$i]['len'] =
384 preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1;
387 if (isset($comments_map[$table_fields[$i]['Field']])) {
388 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
389 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
390 . $table_fields[$i]['Field_html'] . '</span>';
391 } else {
392 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
395 // The type column.
396 // Fix for bug #3152931 'ENUM and SET cannot have "Binary" option'
397 // If check to ensure types such as "enum('one','two','binary',..)" or
398 // "enum('one','two','varbinary',..)" are not categorized as binary.
399 if (stripos($table_fields[$i]['Type'], 'binary') === 0
400 || stripos($table_fields[$i]['Type'], 'varbinary') === 0) {
401 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
402 } else {
403 $table_fields[$i]['is_binary'] = false;
406 // If check to ensure types such as "enum('one','two','blob',..)" or
407 // "enum('one','two','tinyblob',..)" etc. are not categorized as blob.
408 if (stripos($table_fields[$i]['Type'], 'blob') === 0
409 || stripos($table_fields[$i]['Type'], 'tinyblob') === 0
410 || stripos($table_fields[$i]['Type'], 'mediumblob') === 0
411 || stripos($table_fields[$i]['Type'], 'longblob') === 0) {
412 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
413 } else {
414 $table_fields[$i]['is_blob'] = false;
417 // If check to ensure types such as "enum('one','two','char',..)" or
418 // "enum('one','two','varchar',..)" are not categorized as char.
419 if (stripos($table_fields[$i]['Type'], 'char') === 0
420 || stripos($table_fields[$i]['Type'], 'varchar') === 0) {
421 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
422 } else {
423 $table_fields[$i]['is_char'] = false;
426 $table_fields[$i]['first_timestamp'] = false;
427 switch ($table_fields[$i]['True_Type']) {
428 case 'set':
429 $table_fields[$i]['pma_type'] = 'set';
430 $table_fields[$i]['wrap'] = '';
431 break;
432 case 'enum':
433 $table_fields[$i]['pma_type'] = 'enum';
434 $table_fields[$i]['wrap'] = '';
435 break;
436 case 'timestamp':
437 if (!$timestamp_seen) { // can only occur once per table
438 $timestamp_seen = 1;
439 $table_fields[$i]['first_timestamp'] = true;
441 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
442 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
443 break;
445 default:
446 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
447 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
448 break;
451 $field = $table_fields[$i];
452 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
454 if (-1 === $field['len']) {
455 $field['len'] = PMA_DBI_field_len($vresult, $i);
457 //Call validation when the form submited...
458 $unnullify_trigger = $chg_evt_handler . "=\"return verificationsAfterFieldChange('". PMA_escapeJsString($field['Field_md5']) . "', '"
459 . PMA_escapeJsString($jsvkey) . "','".$field['pma_type']."')\"";
461 // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
462 $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
464 if ($field['Type'] == 'datetime'
465 && ! isset($field['Default'])
466 && ! is_null($field['Default'])
467 && ($insert_mode || ! isset($vrow[$field['Field']]))) {
468 // INSERT case or
469 // UPDATE case with an NULL value
470 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
473 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; ?>">
474 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center">
475 <?php echo $field['Field_title']; ?>
476 <input type="hidden" name="fields_name<?php echo $field_name_appendix; ?>" value="<?php echo $field['Field_html']; ?>"/>
477 </td>
478 <?php if ($cfg['ShowFieldTypesInDataEditView']) { ?>
479 <td align="center"<?php echo $field['wrap']; ?>><span class="column_type"><?php echo $field['pma_type']; ?></span>
480 </td>
482 <?php } //End if
484 // Get a list of GIS data types.
485 $gis_data_types = PMA_getGISDatatypes();
487 // Prepares the field value
488 $real_null_value = false;
489 $special_chars_encoded = '';
490 if (isset($vrow)) {
491 // (we are editing)
492 if (is_null($vrow[$field['Field']])) {
493 $real_null_value = true;
494 $vrow[$field['Field']] = '';
495 $special_chars = '';
496 $data = $vrow[$field['Field']];
497 } elseif ($field['True_Type'] == 'bit') {
498 $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
499 } elseif (in_array($field['True_Type'], $gis_data_types)) {
500 // Convert gis data to Well Know Text format
501 $vrow[$field['Field']] = PMA_asWKT($vrow[$field['Field']], true);
502 $special_chars = htmlspecialchars($vrow[$field['Field']]);
503 } else {
504 // special binary "characters"
505 if ($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) {
506 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
507 $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]);
508 $field['display_binary_as_hex'] = true;
509 } else {
510 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
512 } // end if
513 $special_chars = htmlspecialchars($vrow[$field['Field']]);
515 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
516 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
518 $data = $vrow[$field['Field']];
519 } // end if... else...
521 //when copying row, it is useful to empty auto-increment column to prevent duplicate key error
522 if (isset($default_action) && $default_action === 'insert') {
523 if ($field['Key'] === 'PRI' && strpos($field['Extra'], 'auto_increment') !== false) {
524 $data = $special_chars_encoded = $special_chars = null;
527 // If a timestamp field value is not included in an update
528 // statement MySQL auto-update it to the current timestamp;
529 // however, things have changed since MySQL 4.1, so
530 // it's better to set a fields_prev in this situation
531 $backup_field = '<input type="hidden" name="fields_prev'
532 . $field_name_appendix . '" value="'
533 . htmlspecialchars($vrow[$field['Field']]) . '" />';
534 } else {
535 // (we are inserting)
536 // display default values
537 if (! isset($field['Default'])) {
538 $field['Default'] = '';
539 $real_null_value = true;
540 $data = '';
541 } else {
542 $data = $field['Default'];
544 if ($field['True_Type'] == 'bit') {
545 $special_chars = PMA_convert_bit_default_value($field['Default']);
546 } else {
547 $special_chars = htmlspecialchars($field['Default']);
549 $backup_field = '';
550 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
551 // this will select the UNHEX function while inserting
552 if (($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) && $_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
553 $field['display_binary_as_hex'] = true;
557 $idindex = ($o_rows * $fields_cnt) + $i + 1;
558 $tabindex = $idindex;
560 // Get a list of data types that are not yet supported.
561 $no_support_types = PMA_unsupportedDatatypes();
563 // The function column
564 // -------------------
565 // We don't want binary data to be destroyed
566 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
567 // stored or retrieved" so it does not mean that the contents is
568 // binary
569 if ($cfg['ShowFunctionFields']) {
570 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
571 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
572 echo ' <td align="center">' . __('Binary') . '</td>' . "\n";
573 } elseif (strstr($field['True_Type'], 'enum') || strstr($field['True_Type'], 'set') || in_array($field['pma_type'], $no_support_types)) {
574 echo ' <td align="center">--</td>' . "\n";
575 } else {
577 <td>
578 <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">
579 <?php
580 echo PMA_getFunctionsForField($field, $insert_mode);
582 </select>
583 </td>
584 <?php
586 } // end if ($cfg['ShowFunctionFields'])
589 // The null column
590 // ---------------
591 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
592 echo ' <td>' . "\n";
593 if ($field['Null'] == 'YES') {
594 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
595 if ($real_null_value && !$field['first_timestamp']) {
596 echo ' value="on"';
598 echo ' />' . "\n";
600 echo ' <input type="checkbox" class="checkbox_null" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
601 . ' name="fields_null' . $field_name_appendix . '"';
602 if ($real_null_value && !$field['first_timestamp']) {
603 echo ' checked="checked"';
605 echo ' id="field_' . ($idindex) . '_2" />';
607 // nullify_code is needed by the js nullify() function
608 if (strstr($field['True_Type'], 'enum')) {
609 if (strlen($field['Type']) > 20) {
610 $nullify_code = '1';
611 } else {
612 $nullify_code = '2';
614 } elseif (strstr($field['True_Type'], 'set')) {
615 $nullify_code = '3';
616 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
617 // foreign key in a drop-down
618 $nullify_code = '4';
619 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
620 // foreign key with a browsing icon
621 $nullify_code = '6';
622 } else {
623 $nullify_code = '5';
625 // to be able to generate calls to nullify() in jQuery
626 echo '<input type="hidden" class="nullify_code" name="nullify_code' . $field_name_appendix . '" value="' . $nullify_code . '" />';
627 echo '<input type="hidden" class="hashed_field" name="hashed_field' . $field_name_appendix . '" value="' . $field['Field_md5'] . '" />';
628 echo '<input type="hidden" class="multi_edit" name="multi_edit' . $field_name_appendix . '" value="' . PMA_escapeJsString($vkey) . '" />';
630 echo ' </td>' . "\n";
632 // The value column (depends on type)
633 // ----------------
634 // See bug #1667887 for the reason why we don't use the maxlength
635 // HTML attribute
637 echo ' <td>' . "\n";
638 // Will be used by js/tbl_change.js to set the default value
639 // for the "Continue insertion" feature
640 echo '<span class="default_value hide">' . $special_chars . '</span>';
641 if ($foreignData['foreign_link'] == true) {
642 echo $backup_field . "\n";
644 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
645 value="foreign" />
646 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
647 class="textfield" <?php echo $unnullify_trigger; ?>
648 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
649 id="field_<?php echo ($idindex); ?>_3"
650 value="<?php echo htmlspecialchars($data); ?>" />
651 <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>
652 <?php
653 } elseif (is_array($foreignData['disp_row'])) {
654 echo $backup_field . "\n";
656 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
657 value="foreign" />
658 <select name="fields<?php echo $field_name_appendix; ?>"
659 <?php echo $unnullify_trigger; ?>
660 class="textfield"
661 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
662 id="field_<?php echo ($idindex); ?>_3">
663 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
664 </select>
665 <?php
666 // still needed? :
667 unset($foreignData['disp_row']);
668 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
670 &nbsp;</td>
671 </tr>
672 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
673 <td colspan="5" align="right">
674 <?php echo $backup_field . "\n"; ?>
675 <textarea name="fields<?php echo $field_name_appendix; ?>"
676 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
677 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
678 dir="<?php echo $text_dir; ?>"
679 id="field_<?php echo ($idindex); ?>_3"
680 <?php echo $unnullify_trigger; ?>
681 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
682 ><?php echo $special_chars_encoded; ?></textarea>
683 <?php
684 } elseif (strstr($field['pma_type'], 'text')) {
685 echo $backup_field . "\n";
687 <textarea name="fields<?php echo $field_name_appendix; ?>"
688 rows="<?php echo $cfg['TextareaRows']; ?>"
689 cols="<?php echo $cfg['TextareaCols']; ?>"
690 dir="<?php echo $text_dir; ?>"
691 id="field_<?php echo ($idindex); ?>_3"
692 <?php echo $unnullify_trigger; ?>
693 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
694 ><?php echo $special_chars_encoded; ?></textarea>
695 <?php
696 echo "\n";
697 if (strlen($special_chars) > 32000) {
698 echo " </td>\n";
699 echo ' <td>' . __('Because of its length,<br /> this column might not be editable');
701 } elseif ($field['pma_type'] == 'enum') {
702 if (! isset($table_fields[$i]['values'])) {
703 $table_fields[$i]['values'] = array();
704 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
705 // Removes automatic MySQL escape format
706 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
707 $table_fields[$i]['values'][] = array(
708 'plain' => $val,
709 'html' => htmlspecialchars($val),
713 $field_enum_values = $table_fields[$i]['values'];
715 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
716 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
717 <?php
718 echo "\n" . ' ' . $backup_field . "\n";
720 // show dropdown or radio depend on length
721 if (strlen($field['Type']) > 20) {
723 <select name="fields<?php echo $field_name_appendix; ?>"
724 <?php echo $unnullify_trigger; ?>
725 class="textfield"
726 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
727 id="field_<?php echo ($idindex); ?>_3">
728 <option value="">&nbsp;</option>
729 <?php
730 echo "\n";
732 foreach ($field_enum_values as $enum_value) {
733 echo ' ';
734 echo '<option value="' . $enum_value['html'] . '"';
735 if ($data == $enum_value['plain']
736 || ($data == ''
737 && (! isset($where_clause) || $field['Null'] != 'YES')
738 && isset($field['Default'])
739 && $enum_value['plain'] == $field['Default'])) {
740 echo ' selected="selected"';
742 echo '>' . $enum_value['html'] . '</option>' . "\n";
743 } // end for
746 </select>
747 <?php
748 } else {
749 $j = 0;
750 foreach ($field_enum_values as $enum_value) {
751 echo ' ';
752 echo '<input type="radio" name="fields' . $field_name_appendix . '"';
753 echo ' class="textfield"';
754 echo ' value="' . $enum_value['html'] . '"';
755 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
756 echo $unnullify_trigger;
757 if ($data == $enum_value['plain']
758 || ($data == ''
759 && (! isset($where_clause) || $field['Null'] != 'YES')
760 && isset($field['Default'])
761 && $enum_value['plain'] == $field['Default'])) {
762 echo ' checked="checked"';
764 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
765 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
766 . $enum_value['html'] . '</label>' . "\n";
767 $j++;
768 } // end for
769 } // end else
770 } elseif ($field['pma_type'] == 'set') {
771 if (! isset($table_fields[$i]['values'])) {
772 $table_fields[$i]['values'] = array();
773 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
774 $table_fields[$i]['values'][] = array(
775 'plain' => $val,
776 'html' => htmlspecialchars($val),
779 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
781 $field_set_values = $table_fields[$i]['values'];
782 $select_size = $table_fields[$i]['select_size'];
784 $vset = array_flip(explode(',', $data));
785 echo $backup_field . "\n";
787 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
788 <select name="fields<?php echo $field_name_appendix . '[]'; ?>"
789 class="textfield"
790 size="<?php echo $select_size; ?>"
791 multiple="multiple" <?php echo $unnullify_trigger; ?>
792 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
793 id="field_<?php echo ($idindex); ?>_3">
794 <?php
795 foreach ($field_set_values as $field_set_value) {
796 echo ' ';
797 echo '<option value="' . $field_set_value['html'] . '"';
798 if (isset($vset[$field_set_value['plain']])) {
799 echo ' selected="selected"';
801 echo '>' . $field_set_value['html'] . '</option>' . "\n";
802 } // end for
804 </select>
805 <?php
807 // We don't want binary data destroyed
808 elseif ($field['is_binary'] || $field['is_blob']) {
809 if (($cfg['ProtectBinary'] && $field['is_blob'])
810 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])
812 echo "\n";
813 // for blobstreaming
814 if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type)
815 && PMA_BS_IsPBMSReference($data, $db)
817 echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_md5'] . $vkey . '" value="' . $data . '" />';
818 echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . __('Remove BLOB Repository Reference') . "<br />";
819 echo PMA_BS_CreateReferenceLink($data, $db);
820 echo "<br />";
821 } else {
822 echo __('Binary - do not edit');
823 if (isset($data)) {
824 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
825 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
826 unset($data_size);
828 echo "\n";
829 } // end if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
831 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
832 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
833 <?php
834 } elseif ($field['is_blob']) {
835 echo "\n";
836 echo $backup_field . "\n";
838 <textarea name="fields<?php echo $field_name_appendix; ?>"
839 rows="<?php echo $cfg['TextareaRows']; ?>"
840 cols="<?php echo $cfg['TextareaCols']; ?>"
841 dir="<?php echo $text_dir; ?>"
842 id="field_<?php echo ($idindex); ?>_3"
843 <?php echo $unnullify_trigger; ?>
844 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
845 ><?php echo $special_chars_encoded; ?></textarea>
846 <?php
848 } else {
849 // field size should be at least 4 and max $cfg['LimitChars']
850 $fieldsize = min(max($field['len'], 4), $cfg['LimitChars']);
851 echo "\n";
852 echo $backup_field . "\n";
854 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
855 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
856 class="textfield" <?php echo $unnullify_trigger; ?>
857 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
858 id="field_<?php echo ($idindex); ?>_3" />
859 <?php
860 } // end if...elseif...else
862 // Upload choice (only for BLOBs because the binary
863 // attribute does not imply binary contents)
864 // (displayed whatever value the ProtectBinary has)
866 if ($is_upload && $field['is_blob']) {
867 // check if field type is of longblob and if the table is PBMS enabled.
868 if (($field['pma_type'] == "longblob")
869 && PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type)
871 echo '<br />';
872 echo '<input type="checkbox" name="upload_blob_repo' . $vkey . '[' . $field['Field_md5'] . ']" /> ' . __('Upload to BLOB repository');
875 echo '<br />';
876 echo '<input type="file" name="fields_upload' . $vkey . '[' . $field['Field_md5'] . ']" class="textfield" id="field_' . $idindex . '_3" size="10" ' . $unnullify_trigger . '/>&nbsp;';
878 // find maximum upload size, based on field type
880 * @todo with functions this is not so easy, as you can basically
881 * process any data with function like MD5
883 $max_field_sizes = array(
884 'tinyblob' => '256',
885 'blob' => '65536',
886 'mediumblob' => '16777216',
887 'longblob' => '4294967296'); // yeah, really
889 $this_field_max_size = $max_upload_size; // from PHP max
890 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
891 $this_field_max_size = $max_field_sizes[$field['pma_type']];
893 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
894 // do not generate here the MAX_FILE_SIZE, because we should
895 // put only one in the form to accommodate the biggest field
896 if ($this_field_max_size > $biggest_max_file_size) {
897 $biggest_max_file_size = $this_field_max_size;
901 if (!empty($cfg['UploadDir'])) {
902 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
903 if ($files === false) {
904 echo ' <font color="red">' . __('Error') . '</font><br />' . "\n";
905 echo ' ' . __('The directory you set for upload work cannot be reached') . "\n";
906 } elseif (!empty($files)) {
907 echo "<br />\n";
908 echo ' <i>' . __('Or') . '</i>' . ' ' . __('web server upload directory') . ':<br />' . "\n";
909 echo ' <select size="1" name="fields_uploadlocal' . $vkey . '[' . $field['Field_md5'] . ']">' . "\n";
910 echo ' <option value="" selected="selected"></option>' . "\n";
911 echo $files;
912 echo ' </select>' . "\n";
914 } // end if (web-server upload directory)
915 } // end elseif (binary or blob)
916 elseif (in_array($field['pma_type'], $no_support_types)) {
917 // ignore this column to avoid changing it
918 } else {
919 // field size should be at least 4 and max 40
920 $fieldsize = min(max($field['len'], 4), 40);
921 echo $backup_field . "\n";
922 if ($field['is_char']
923 && ($cfg['CharEditing'] == 'textarea'
924 || strpos($data, "\n") !== false)
926 echo "\n";
928 <textarea name="fields<?php echo $field_name_appendix; ?>"
929 rows="<?php echo $cfg['CharTextareaRows']; ?>"
930 cols="<?php echo $cfg['CharTextareaCols']; ?>"
931 dir="<?php echo $text_dir; ?>"
932 id="field_<?php echo ($idindex); ?>_3"
933 <?php echo $unnullify_trigger; ?>
934 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
935 ><?php echo $special_chars_encoded; ?></textarea>
936 <?php
937 } else {
938 $the_class = 'textfield';
939 if ($field['pma_type'] == 'date') {
940 $the_class .= ' datefield';
941 } elseif ($field['pma_type'] == 'datetime'
942 || substr($field['pma_type'], 0, 9) == 'timestamp'
944 $the_class .= ' datetimefield';
947 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
948 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
949 class="<?php echo $the_class; ?>" <?php echo $unnullify_trigger; ?>
950 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
951 id="field_<?php echo ($idindex); ?>_3" />
952 <?php
953 if ($field['Extra'] == 'auto_increment') {
955 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
956 <?php
957 } // end if
958 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
960 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
961 <?php
963 if (substr($field['pma_type'], 0, 8) == 'datetime') {
965 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="datetime" />
966 <?php
968 if ($field['True_Type'] == 'bit') {
970 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
971 <?php
973 if ($field['pma_type'] == 'date'
974 || $field['pma_type'] == 'datetime'
975 || substr($field['pma_type'], 0, 9) == 'timestamp'
977 // the _3 suffix points to the date field
978 // the _2 suffix points to the corresponding NULL checkbox
979 // in dateFormat, 'yy' means the year with 4 digits
983 if (in_array($field['pma_type'], $gis_data_types)) {
984 $data_val = isset($vrow[$field['Field']]) ? $vrow[$field['Field']] : '';
985 $_url_params = array(
986 'field' => $field['Field_title'],
987 'value' => $data_val,
989 if ($field['pma_type'] != 'geometry') {
990 $_url_params = $_url_params + array('gis_data[gis_type]' => strtoupper($field['pma_type']));
992 $edit_url = 'gis_data_editor.php' . PMA_generate_common_url($_url_params);
993 $edit_str = PMA_getIcon('b_edit.png', __('Edit/Insert'), true);
994 echo('<span class="open_gis_editor">');
995 echo(PMA_linkOrButton($edit_url, $edit_str, array(), false, false, '_blank'));
996 echo('</span>');
999 </td>
1000 </tr>
1001 <?php
1002 $odd_row = !$odd_row;
1003 } // end for
1004 $o_rows++;
1005 echo ' </tbody></table><br />';
1006 } // end foreach on multi-edit
1008 <div id="gis_editor"></div><div id="popup_background"></div>
1009 <br />
1010 <fieldset id="actions_panel">
1011 <table border="0" cellpadding="5" cellspacing="0">
1012 <tr>
1013 <td valign="middle" nowrap="nowrap">
1014 <select name="submit_type" class="control_at_footer" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
1015 <?php
1016 if (isset($where_clause)) {
1018 <option value="save"><?php echo __('Save'); ?></option>
1019 <?php
1022 <option value="insert"><?php echo __('Insert as new row'); ?></option>
1023 <option value="insertignore"><?php echo __('Insert as new row and ignore errors'); ?></option>
1024 <option value="showinsert"><?php echo __('Show insert query'); ?></option>
1025 </select>
1026 <?php
1027 echo "\n";
1029 if (! isset($after_insert)) {
1030 $after_insert = 'back';
1033 </td>
1034 <td valign="middle">
1035 &nbsp;&nbsp;&nbsp;<strong><?php echo __('and then'); ?></strong>&nbsp;&nbsp;&nbsp;
1036 </td>
1037 <td valign="middle" nowrap="nowrap">
1038 <select name="after_insert">
1039 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to previous page'); ?></option>
1040 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Insert another new row'); ?></option>
1041 <?php
1042 if (isset($where_clause)) {
1044 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to this page'); ?></option>
1045 <?php
1046 // If we have just numeric primary key, we can also edit next
1047 // in 2.8.2, we were looking for `field_name` = numeric_value
1048 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1049 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1050 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause)) {
1052 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo __('Edit next row'); ?></option>
1053 <?php
1057 </select>
1058 </td>
1059 </tr>
1061 <tr>
1062 <td>
1063 <?php echo PMA_showHint(__('Use TAB key to move from value to value, or CTRL+arrows to move anywhere')); ?>
1064 </td>
1065 <td colspan="3" align="right" valign="middle">
1066 <input type="submit" class="control_at_footer" value="<?php echo __('Go'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1067 <input type="reset" class="control_at_footer" value="<?php echo __('Reset'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1068 </td>
1069 </tr>
1070 </table>
1071 </fieldset>
1072 <?php if ($biggest_max_file_size > 0) {
1073 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1074 } ?>
1075 </form>
1076 <?php
1077 if ($insert_mode) {
1079 <!-- Continue insertion form -->
1080 <form id="continueForm" method="post" action="tbl_replace.php" name="continueForm" >
1081 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1082 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1083 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
1084 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
1085 <?php
1086 if (isset($where_clauses)) {
1087 foreach ($where_clause_array as $key_id => $where_clause) {
1088 echo '<input type="hidden" name="where_clause[' . $key_id . ']" value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n";
1091 $tmp = '<select name="insert_rows" id="insert_rows">' . "\n";
1092 $option_values = array(1,2,5,10,15,20,30,40);
1093 foreach ($option_values as $value) {
1094 $tmp .= '<option value="' . $value . '"';
1095 if ($value == $cfg['InsertRows']) {
1096 $tmp .= ' selected="selected"';
1098 $tmp .= '>' . $value . '</option>' . "\n";
1100 $tmp .= '</select>' . "\n";
1101 echo "\n" . sprintf(__('Continue insertion with %s rows'), $tmp);
1102 unset($tmp);
1103 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>' . "\n";
1104 echo '</form>' . "\n";
1108 * Displays the footer
1110 require './libraries/footer.inc.php';