Changed slider to use fixed-size 'blind' animation instead of 'slide'
[phpmyadmin.git] / tbl_change.php
blob5395ddabde8b17bcf468a7f632295694ca48d9a1
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 require_once './libraries/data_drizzle.inc.php';
25 } else {
26 require_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.custom.js';
124 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
126 // required for GIS editor
127 $GLOBALS['js_include'][] = 'gis_data_editor.js';
128 $GLOBALS['js_include'][] = 'jquery/jquery.sprintf.js';
129 $GLOBALS['js_include'][] = 'jquery/jquery.svg.js';
130 $GLOBALS['js_include'][] = 'jquery/jquery.mousewheel.js';
131 $GLOBALS['js_include'][] = 'jquery/jquery.event.drag-2.0.min.js';
132 $GLOBALS['js_include'][] = 'tbl_gis_visualization.js';
133 $GLOBALS['js_include'][] = 'openlayers/OpenLayers.js';
134 $GLOBALS['js_include'][] = 'OpenStreetMap.js';
137 * HTTP and HTML headers
139 require_once './libraries/header.inc.php';
142 * Displays the query submitted and its result
144 * @todo where does $disp_message and $disp_query come from???
146 if (! empty($disp_message)) {
147 if (! isset($disp_query)) {
148 $disp_query = null;
150 PMA_showMessage($disp_message, $disp_query);
154 * Displays top menu links
156 require_once './libraries/tbl_links.inc.php';
160 * Get the analysis of SHOW CREATE TABLE for this table
161 * @todo should be handled by class Table
163 $show_create_table = PMA_DBI_fetch_value(
164 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
165 0, 1);
166 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
167 unset($show_create_table);
170 * Get the list of the fields of the current table
172 PMA_DBI_select_db($db);
173 $table_fields = array_values(PMA_DBI_get_columns($db, $table));
174 $rows = array();
175 if (isset($where_clause)) {
176 // when in edit mode load all selected rows from table
177 $insert_mode = false;
178 if (is_array($where_clause)) {
179 $where_clause_array = $where_clause;
180 } else {
181 $where_clause_array = array(0 => $where_clause);
184 $result = array();
185 $found_unique_key = false;
186 $where_clauses = array();
188 foreach ($where_clause_array as $key_id => $where_clause) {
189 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';';
190 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
191 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
192 $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
194 // No row returned
195 if (! $rows[$key_id]) {
196 unset($rows[$key_id], $where_clause_array[$key_id]);
197 PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query);
198 echo "\n";
199 require './libraries/footer.inc.php';
200 } else { // end if (no row returned)
201 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
202 list($unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true);
203 if (! empty($unique_condition)) {
204 $found_unique_key = true;
206 unset($unique_condition, $tmp_clause_is_unique);
210 } else {
211 // no primary key given, just load first row - but what happens if table is empty?
212 $insert_mode = true;
213 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
214 $rows = array_fill(0, $cfg['InsertRows'], false);
217 // Copying a row - fetched data will be inserted as a new row, therefore the where clause is needless.
218 if (isset($default_action) && $default_action === 'insert') {
219 unset($where_clause, $where_clauses);
222 // retrieve keys into foreign fields, if any
223 $foreigners = PMA_getForeigners($db, $table);
227 * Displays the form
229 // autocomplete feature of IE kills the "onchange" event handler and it
230 // must be replaced by the "onpropertychange" one in this case
231 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7)
232 ? 'onpropertychange'
233 : 'onchange';
234 // Had to put the URI because when hosted on an https server,
235 // some browsers send wrongly this form to the http server.
238 <!-- Set on key handler for moving using by Ctrl+arrows -->
239 <script src="./js/keyhandler.js" type="text/javascript"></script>
240 <script type="text/javascript">
241 //<![CDATA[
242 var switch_movement = 0;
243 document.onkeydown = onKeyDownArrowsHandler;
244 //]]>
245 </script>
246 <?php
248 $_form_params = array(
249 'db' => $db,
250 'table' => $table,
251 'goto' => $GLOBALS['goto'],
252 'err_url' => $err_url,
253 'sql_query' => $sql_query,
255 if (isset($where_clauses)) {
256 foreach ($where_clause_array as $key_id => $where_clause) {
257 $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
260 if (isset($clause_is_unique)) {
261 $_form_params['clause_is_unique'] = $clause_is_unique;
266 <!-- Insert/Edit form -->
267 <form id="insertForm" method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
268 <?php
269 echo PMA_generate_common_hidden_inputs($_form_params);
271 $titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
273 // Set if we passed the first timestamp field
274 $timestamp_seen = 0;
275 $fields_cnt = count($table_fields);
277 $tabindex = 0;
278 $tabindex_for_function = +3000;
279 $tabindex_for_null = +6000;
280 $tabindex_for_value = 0;
281 $o_rows = 0;
282 $biggest_max_file_size = 0;
284 // user can toggle the display of Function column
285 // (currently does not work for multi-edits)
286 $url_params['db'] = $db;
287 $url_params['table'] = $table;
288 if (isset($where_clause)) {
289 $url_params['where_clause'] = trim($where_clause);
291 if (! empty($sql_query)) {
292 $url_params['sql_query'] = $sql_query;
295 if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) {
296 echo __('Show');
298 if (! $cfg['ShowFunctionFields']) {
299 $this_url_params = array_merge($url_params,
300 array('ShowFunctionFields' => 1, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
301 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . __('Function') . '</a>' . "\n";
303 if (! $cfg['ShowFieldTypesInDataEditView']) {
304 $this_other_url_params = array_merge($url_params,
305 array('ShowFieldTypesInDataEditView' => 1, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
306 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_other_url_params) . '">' . __('Type') . '</a>' . "\n";
309 foreach ($rows as $row_id => $vrow) {
310 if ($vrow === false) {
311 unset($vrow);
314 $jsvkey = $row_id;
315 $rownumber_param = '&amp;rownumber=' . $row_id;
316 $vkey = '[multi_edit][' . $jsvkey . ']';
318 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ? $result[$row_id] : $result);
319 if ($insert_mode && $row_id > 0) {
320 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_' . $row_id . '" />';
321 echo '<label for="insert_ignore_' . $row_id . '">' . __('Ignore') . '</label><br />' . "\n";
324 <table class="insertRowTable">
325 <thead>
326 <tr>
327 <th><?php echo __('Column'); ?></th>
329 <?php
330 if ($cfg['ShowFieldTypesInDataEditView']) {
331 $this_url_params = array_merge($url_params,
332 array('ShowFieldTypesInDataEditView' => 0, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
333 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Type') . '</a></th>' . "\n";
336 if ($cfg['ShowFunctionFields']) {
337 $this_url_params = array_merge($url_params,
338 array('ShowFunctionFields' => 0, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
339 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Function') . '</a></th>' . "\n";
342 <th><?php echo __('Null'); ?></th>
343 <th><?php echo __('Value'); ?></th>
344 </tr>
345 </thead>
346 <tfoot>
347 <tr>
348 <th colspan="5" align="right" class="tblFooters">
349 <input type="submit" value="<?php echo __('Go'); ?>" />
350 </th>
351 </tr>
352 </tfoot>
353 <tbody>
354 <?php
355 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
356 $m_rows = $o_rows + 1;
358 $odd_row = true;
359 for ($i = 0; $i < $fields_cnt; $i++) {
360 if (! isset($table_fields[$i]['processed'])) {
361 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
362 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
363 // True_Type contains only the type (stops at first bracket)
364 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
366 // d a t e t i m e
368 // Current date should not be set as default if the field is NULL
369 // for the current row, but do not put here the current datetime
370 // if there is a default value (the real default value will be set
371 // in the Default value logic below)
373 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
374 // $field['Default'] is not set if it contains NULL:
375 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
376 // but, look what we get if we switch to iso: (Default is NULL)
377 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
378 // so I force a NULL into it (I don't think it's possible
379 // to have an empty default value for DATETIME)
380 // then, the "if" after this one will work
381 if ($table_fields[$i]['Type'] == 'datetime'
382 && ! isset($table_fields[$i]['Default'])
383 && isset($table_fields[$i]['Null'])
384 && $table_fields[$i]['Null'] == 'YES') {
385 $table_fields[$i]['Default'] = null;
388 $table_fields[$i]['len'] =
389 preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1;
392 if (isset($comments_map[$table_fields[$i]['Field']])) {
393 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
394 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
395 . $table_fields[$i]['Field_html'] . '</span>';
396 } else {
397 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
400 // The type column.
401 // Fix for bug #3152931 'ENUM and SET cannot have "Binary" option'
402 // If check to ensure types such as "enum('one','two','binary',..)" or
403 // "enum('one','two','varbinary',..)" are not categorized as binary.
404 if (stripos($table_fields[$i]['Type'], 'binary') === 0
405 || stripos($table_fields[$i]['Type'], 'varbinary') === 0) {
406 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
407 } else {
408 $table_fields[$i]['is_binary'] = false;
411 // If check to ensure types such as "enum('one','two','blob',..)" or
412 // "enum('one','two','tinyblob',..)" etc. are not categorized as blob.
413 if (stripos($table_fields[$i]['Type'], 'blob') === 0
414 || stripos($table_fields[$i]['Type'], 'tinyblob') === 0
415 || stripos($table_fields[$i]['Type'], 'mediumblob') === 0
416 || stripos($table_fields[$i]['Type'], 'longblob') === 0) {
417 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
418 } else {
419 $table_fields[$i]['is_blob'] = false;
422 // If check to ensure types such as "enum('one','two','char',..)" or
423 // "enum('one','two','varchar',..)" are not categorized as char.
424 if (stripos($table_fields[$i]['Type'], 'char') === 0
425 || stripos($table_fields[$i]['Type'], 'varchar') === 0) {
426 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
427 } else {
428 $table_fields[$i]['is_char'] = false;
431 $table_fields[$i]['first_timestamp'] = false;
432 switch ($table_fields[$i]['True_Type']) {
433 case 'set':
434 $table_fields[$i]['pma_type'] = 'set';
435 $table_fields[$i]['wrap'] = '';
436 break;
437 case 'enum':
438 $table_fields[$i]['pma_type'] = 'enum';
439 $table_fields[$i]['wrap'] = '';
440 break;
441 case 'timestamp':
442 if (!$timestamp_seen) { // can only occur once per table
443 $timestamp_seen = 1;
444 $table_fields[$i]['first_timestamp'] = true;
446 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
447 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
448 break;
450 default:
451 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
452 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
453 break;
456 $field = $table_fields[$i];
457 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
459 if (-1 === $field['len']) {
460 $field['len'] = PMA_DBI_field_len($vresult, $i);
461 // length is unknown for geometry fields, make enough space to edit very simple WKTs
462 if (-1 === $field['len']) {
463 $field['len'] = 30;
466 //Call validation when the form submited...
467 $unnullify_trigger = $chg_evt_handler . "=\"return verificationsAfterFieldChange('". PMA_escapeJsString($field['Field_md5']) . "', '"
468 . PMA_escapeJsString($jsvkey) . "','".$field['pma_type']."')\"";
470 // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
471 $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
473 if ($field['Type'] == 'datetime'
474 && ! isset($field['Default'])
475 && ! is_null($field['Default'])
476 && ($insert_mode || ! isset($vrow[$field['Field']]))) {
477 // INSERT case or
478 // UPDATE case with an NULL value
479 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
482 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; ?>">
483 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center">
484 <?php echo $field['Field_title']; ?>
485 <input type="hidden" name="fields_name<?php echo $field_name_appendix; ?>" value="<?php echo $field['Field_html']; ?>"/>
486 </td>
487 <?php if ($cfg['ShowFieldTypesInDataEditView']) { ?>
488 <td align="center"<?php echo $field['wrap']; ?>><span class="column_type"><?php echo $field['pma_type']; ?></span>
489 </td>
491 <?php } //End if
493 // Get a list of GIS data types.
494 $gis_data_types = PMA_getGISDatatypes();
496 // Prepares the field value
497 $real_null_value = false;
498 $special_chars_encoded = '';
499 if (isset($vrow)) {
500 // (we are editing)
501 if (is_null($vrow[$field['Field']])) {
502 $real_null_value = true;
503 $vrow[$field['Field']] = '';
504 $special_chars = '';
505 $data = $vrow[$field['Field']];
506 } elseif ($field['True_Type'] == 'bit') {
507 $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
508 } elseif (in_array($field['True_Type'], $gis_data_types)) {
509 // Convert gis data to Well Know Text format
510 $vrow[$field['Field']] = PMA_asWKT($vrow[$field['Field']], true);
511 $special_chars = htmlspecialchars($vrow[$field['Field']]);
512 } else {
513 // special binary "characters"
514 if ($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) {
515 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
516 $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]);
517 $field['display_binary_as_hex'] = true;
518 } else {
519 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
521 } // end if
522 $special_chars = htmlspecialchars($vrow[$field['Field']]);
524 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
525 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
527 $data = $vrow[$field['Field']];
528 } // end if... else...
530 //when copying row, it is useful to empty auto-increment column to prevent duplicate key error
531 if (isset($default_action) && $default_action === 'insert') {
532 if ($field['Key'] === 'PRI' && strpos($field['Extra'], 'auto_increment') !== false) {
533 $data = $special_chars_encoded = $special_chars = null;
536 // If a timestamp field value is not included in an update
537 // statement MySQL auto-update it to the current timestamp;
538 // however, things have changed since MySQL 4.1, so
539 // it's better to set a fields_prev in this situation
540 $backup_field = '<input type="hidden" name="fields_prev'
541 . $field_name_appendix . '" value="'
542 . htmlspecialchars($vrow[$field['Field']]) . '" />';
543 } else {
544 // (we are inserting)
545 // display default values
546 if (! isset($field['Default'])) {
547 $field['Default'] = '';
548 $real_null_value = true;
549 $data = '';
550 } else {
551 $data = $field['Default'];
553 if ($field['True_Type'] == 'bit') {
554 $special_chars = PMA_convert_bit_default_value($field['Default']);
555 } else {
556 $special_chars = htmlspecialchars($field['Default']);
558 $backup_field = '';
559 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
560 // this will select the UNHEX function while inserting
561 if (($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) && $_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
562 $field['display_binary_as_hex'] = true;
566 $idindex = ($o_rows * $fields_cnt) + $i + 1;
567 $tabindex = $idindex;
569 // Get a list of data types that are not yet supported.
570 $no_support_types = PMA_unsupportedDatatypes();
572 // The function column
573 // -------------------
574 // We don't want binary data to be destroyed
575 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
576 // stored or retrieved" so it does not mean that the contents is
577 // binary
578 if ($cfg['ShowFunctionFields']) {
579 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
580 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
581 echo ' <td align="center">' . __('Binary') . '</td>' . "\n";
582 } elseif (strstr($field['True_Type'], 'enum') || strstr($field['True_Type'], 'set') || in_array($field['pma_type'], $no_support_types)) {
583 echo ' <td align="center">--</td>' . "\n";
584 } else {
586 <td>
587 <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">
588 <?php
589 echo PMA_getFunctionsForField($field, $insert_mode);
591 </select>
592 </td>
593 <?php
595 } // end if ($cfg['ShowFunctionFields'])
598 // The null column
599 // ---------------
600 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
601 echo ' <td>' . "\n";
602 if ($field['Null'] == 'YES') {
603 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
604 if ($real_null_value && !$field['first_timestamp']) {
605 echo ' value="on"';
607 echo ' />' . "\n";
609 echo ' <input type="checkbox" class="checkbox_null" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
610 . ' name="fields_null' . $field_name_appendix . '"';
611 if ($real_null_value && !$field['first_timestamp']) {
612 echo ' checked="checked"';
614 echo ' id="field_' . ($idindex) . '_2" />';
616 // nullify_code is needed by the js nullify() function
617 if (strstr($field['True_Type'], 'enum')) {
618 if (strlen($field['Type']) > 20) {
619 $nullify_code = '1';
620 } else {
621 $nullify_code = '2';
623 } elseif (strstr($field['True_Type'], 'set')) {
624 $nullify_code = '3';
625 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
626 // foreign key in a drop-down
627 $nullify_code = '4';
628 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
629 // foreign key with a browsing icon
630 $nullify_code = '6';
631 } else {
632 $nullify_code = '5';
634 // to be able to generate calls to nullify() in jQuery
635 echo '<input type="hidden" class="nullify_code" name="nullify_code' . $field_name_appendix . '" value="' . $nullify_code . '" />';
636 echo '<input type="hidden" class="hashed_field" name="hashed_field' . $field_name_appendix . '" value="' . $field['Field_md5'] . '" />';
637 echo '<input type="hidden" class="multi_edit" name="multi_edit' . $field_name_appendix . '" value="' . PMA_escapeJsString($vkey) . '" />';
639 echo ' </td>' . "\n";
641 // The value column (depends on type)
642 // ----------------
643 // See bug #1667887 for the reason why we don't use the maxlength
644 // HTML attribute
646 echo ' <td>' . "\n";
647 // Will be used by js/tbl_change.js to set the default value
648 // for the "Continue insertion" feature
649 echo '<span class="default_value hide">' . $special_chars . '</span>';
650 if ($foreignData['foreign_link'] == true) {
651 echo $backup_field . "\n";
653 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
654 value="foreign" />
655 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
656 class="textfield" <?php echo $unnullify_trigger; ?>
657 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
658 id="field_<?php echo ($idindex); ?>_3"
659 value="<?php echo htmlspecialchars($data); ?>" />
660 <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>
661 <?php
662 } elseif (is_array($foreignData['disp_row'])) {
663 echo $backup_field . "\n";
665 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
666 value="foreign" />
667 <select name="fields<?php echo $field_name_appendix; ?>"
668 <?php echo $unnullify_trigger; ?>
669 class="textfield"
670 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
671 id="field_<?php echo ($idindex); ?>_3">
672 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
673 </select>
674 <?php
675 // still needed? :
676 unset($foreignData['disp_row']);
677 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
679 &nbsp;</td>
680 </tr>
681 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
682 <td colspan="5" align="right">
683 <?php echo $backup_field . "\n"; ?>
684 <textarea name="fields<?php echo $field_name_appendix; ?>"
685 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
686 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
687 dir="<?php echo $text_dir; ?>"
688 id="field_<?php echo ($idindex); ?>_3"
689 <?php echo $unnullify_trigger; ?>
690 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
691 ><?php echo $special_chars_encoded; ?></textarea>
692 <?php
693 } elseif (strstr($field['pma_type'], 'text')) {
694 echo $backup_field . "\n";
696 <textarea name="fields<?php echo $field_name_appendix; ?>"
697 rows="<?php echo $cfg['TextareaRows']; ?>"
698 cols="<?php echo $cfg['TextareaCols']; ?>"
699 dir="<?php echo $text_dir; ?>"
700 id="field_<?php echo ($idindex); ?>_3"
701 <?php echo $unnullify_trigger; ?>
702 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
703 ><?php echo $special_chars_encoded; ?></textarea>
704 <?php
705 echo "\n";
706 if (strlen($special_chars) > 32000) {
707 echo " </td>\n";
708 echo ' <td>' . __('Because of its length,<br /> this column might not be editable');
710 } elseif ($field['pma_type'] == 'enum') {
711 if (! isset($table_fields[$i]['values'])) {
712 $table_fields[$i]['values'] = array();
713 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
714 // Removes automatic MySQL escape format
715 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
716 $table_fields[$i]['values'][] = array(
717 'plain' => $val,
718 'html' => htmlspecialchars($val),
722 $field_enum_values = $table_fields[$i]['values'];
724 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
725 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
726 <?php
727 echo "\n" . ' ' . $backup_field . "\n";
729 // show dropdown or radio depend on length
730 if (strlen($field['Type']) > 20) {
732 <select name="fields<?php echo $field_name_appendix; ?>"
733 <?php echo $unnullify_trigger; ?>
734 class="textfield"
735 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
736 id="field_<?php echo ($idindex); ?>_3">
737 <option value="">&nbsp;</option>
738 <?php
739 echo "\n";
741 foreach ($field_enum_values as $enum_value) {
742 echo ' ';
743 echo '<option value="' . $enum_value['html'] . '"';
744 if ($data == $enum_value['plain']
745 || ($data == ''
746 && (! isset($where_clause) || $field['Null'] != 'YES')
747 && isset($field['Default'])
748 && $enum_value['plain'] == $field['Default'])) {
749 echo ' selected="selected"';
751 echo '>' . $enum_value['html'] . '</option>' . "\n";
752 } // end for
755 </select>
756 <?php
757 } else {
758 $j = 0;
759 foreach ($field_enum_values as $enum_value) {
760 echo ' ';
761 echo '<input type="radio" name="fields' . $field_name_appendix . '"';
762 echo ' class="textfield"';
763 echo ' value="' . $enum_value['html'] . '"';
764 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
765 echo $unnullify_trigger;
766 if ($data == $enum_value['plain']
767 || ($data == ''
768 && (! isset($where_clause) || $field['Null'] != 'YES')
769 && isset($field['Default'])
770 && $enum_value['plain'] == $field['Default'])) {
771 echo ' checked="checked"';
773 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
774 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
775 . $enum_value['html'] . '</label>' . "\n";
776 $j++;
777 } // end for
778 } // end else
779 } elseif ($field['pma_type'] == 'set') {
780 if (! isset($table_fields[$i]['values'])) {
781 $table_fields[$i]['values'] = array();
782 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
783 $table_fields[$i]['values'][] = array(
784 'plain' => $val,
785 'html' => htmlspecialchars($val),
788 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
790 $field_set_values = $table_fields[$i]['values'];
791 $select_size = $table_fields[$i]['select_size'];
793 $vset = array_flip(explode(',', $data));
794 echo $backup_field . "\n";
796 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
797 <select name="fields<?php echo $field_name_appendix . '[]'; ?>"
798 class="textfield"
799 size="<?php echo $select_size; ?>"
800 multiple="multiple" <?php echo $unnullify_trigger; ?>
801 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
802 id="field_<?php echo ($idindex); ?>_3">
803 <?php
804 foreach ($field_set_values as $field_set_value) {
805 echo ' ';
806 echo '<option value="' . $field_set_value['html'] . '"';
807 if (isset($vset[$field_set_value['plain']])) {
808 echo ' selected="selected"';
810 echo '>' . $field_set_value['html'] . '</option>' . "\n";
811 } // end for
813 </select>
814 <?php
816 // We don't want binary data destroyed
817 elseif ($field['is_binary'] || $field['is_blob']) {
818 if (($cfg['ProtectBinary'] && $field['is_blob'])
819 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])
821 echo "\n";
822 // for blobstreaming
823 if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type)
824 && PMA_BS_IsPBMSReference($data, $db)
826 echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_md5'] . $vkey . '" value="' . $data . '" />';
827 echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . __('Remove BLOB Repository Reference') . "<br />";
828 echo PMA_BS_CreateReferenceLink($data, $db);
829 echo "<br />";
830 } else {
831 echo __('Binary - do not edit');
832 if (isset($data)) {
833 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
834 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
835 unset($data_size);
837 echo "\n";
838 } // end if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
840 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
841 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
842 <?php
843 } elseif ($field['is_blob']) {
844 echo "\n";
845 echo $backup_field . "\n";
847 <textarea name="fields<?php echo $field_name_appendix; ?>"
848 rows="<?php echo $cfg['TextareaRows']; ?>"
849 cols="<?php echo $cfg['TextareaCols']; ?>"
850 dir="<?php echo $text_dir; ?>"
851 id="field_<?php echo ($idindex); ?>_3"
852 <?php echo $unnullify_trigger; ?>
853 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
854 ><?php echo $special_chars_encoded; ?></textarea>
855 <?php
857 } else {
858 // field size should be at least 4 and max $cfg['LimitChars']
859 $fieldsize = min(max($field['len'], 4), $cfg['LimitChars']);
860 echo "\n";
861 echo $backup_field . "\n";
863 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
864 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
865 class="textfield" <?php echo $unnullify_trigger; ?>
866 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
867 id="field_<?php echo ($idindex); ?>_3" />
868 <?php
869 } // end if...elseif...else
871 // Upload choice (only for BLOBs because the binary
872 // attribute does not imply binary contents)
873 // (displayed whatever value the ProtectBinary has)
875 if ($is_upload && $field['is_blob']) {
876 // check if field type is of longblob and if the table is PBMS enabled.
877 if (($field['pma_type'] == "longblob")
878 && PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type)
880 echo '<br />';
881 echo '<input type="checkbox" name="upload_blob_repo' . $vkey . '[' . $field['Field_md5'] . ']" /> ' . __('Upload to BLOB repository');
884 echo '<br />';
885 echo '<input type="file" name="fields_upload' . $vkey . '[' . $field['Field_md5'] . ']" class="textfield" id="field_' . $idindex . '_3" size="10" ' . $unnullify_trigger . '/>&nbsp;';
887 // find maximum upload size, based on field type
889 * @todo with functions this is not so easy, as you can basically
890 * process any data with function like MD5
892 $max_field_sizes = array(
893 'tinyblob' => '256',
894 'blob' => '65536',
895 'mediumblob' => '16777216',
896 'longblob' => '4294967296'); // yeah, really
898 $this_field_max_size = $max_upload_size; // from PHP max
899 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
900 $this_field_max_size = $max_field_sizes[$field['pma_type']];
902 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
903 // do not generate here the MAX_FILE_SIZE, because we should
904 // put only one in the form to accommodate the biggest field
905 if ($this_field_max_size > $biggest_max_file_size) {
906 $biggest_max_file_size = $this_field_max_size;
910 if (!empty($cfg['UploadDir'])) {
911 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
912 if ($files === false) {
913 echo ' <font color="red">' . __('Error') . '</font><br />' . "\n";
914 echo ' ' . __('The directory you set for upload work cannot be reached') . "\n";
915 } elseif (!empty($files)) {
916 echo "<br />\n";
917 echo ' <i>' . __('Or') . '</i>' . ' ' . __('web server upload directory') . ':<br />' . "\n";
918 echo ' <select size="1" name="fields_uploadlocal' . $vkey . '[' . $field['Field_md5'] . ']">' . "\n";
919 echo ' <option value="" selected="selected"></option>' . "\n";
920 echo $files;
921 echo ' </select>' . "\n";
923 } // end if (web-server upload directory)
924 } // end elseif (binary or blob)
925 elseif (in_array($field['pma_type'], $no_support_types)) {
926 // ignore this column to avoid changing it
927 } else {
928 // field size should be at least 4 and max 40
929 $fieldsize = min(max($field['len'], 4), 40);
930 echo $backup_field . "\n";
931 if ($field['is_char']
932 && ($cfg['CharEditing'] == 'textarea'
933 || strpos($data, "\n") !== false)
935 echo "\n";
937 <textarea name="fields<?php echo $field_name_appendix; ?>"
938 rows="<?php echo $cfg['CharTextareaRows']; ?>"
939 cols="<?php echo $cfg['CharTextareaCols']; ?>"
940 dir="<?php echo $text_dir; ?>"
941 id="field_<?php echo ($idindex); ?>_3"
942 <?php echo $unnullify_trigger; ?>
943 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
944 ><?php echo $special_chars_encoded; ?></textarea>
945 <?php
946 } else {
947 $the_class = 'textfield';
948 if ($field['pma_type'] == 'date') {
949 $the_class .= ' datefield';
950 } elseif ($field['pma_type'] == 'datetime'
951 || substr($field['pma_type'], 0, 9) == 'timestamp'
953 $the_class .= ' datetimefield';
956 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
957 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
958 class="<?php echo $the_class; ?>" <?php echo $unnullify_trigger; ?>
959 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
960 id="field_<?php echo ($idindex); ?>_3" />
961 <?php
962 if ($field['Extra'] == 'auto_increment') {
964 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
965 <?php
966 } // end if
967 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
969 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
970 <?php
972 if (substr($field['pma_type'], 0, 8) == 'datetime') {
974 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="datetime" />
975 <?php
977 if ($field['True_Type'] == 'bit') {
979 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
980 <?php
982 if ($field['pma_type'] == 'date'
983 || $field['pma_type'] == 'datetime'
984 || substr($field['pma_type'], 0, 9) == 'timestamp'
986 // the _3 suffix points to the date field
987 // the _2 suffix points to the corresponding NULL checkbox
988 // in dateFormat, 'yy' means the year with 4 digits
992 if (in_array($field['pma_type'], $gis_data_types)) {
993 $data_val = isset($vrow[$field['Field']]) ? $vrow[$field['Field']] : '';
994 $_url_params = array(
995 'field' => $field['Field_title'],
996 'value' => $data_val,
998 if ($field['pma_type'] != 'geometry') {
999 $_url_params = $_url_params + array('gis_data[gis_type]' => strtoupper($field['pma_type']));
1001 $edit_url = 'gis_data_editor.php' . PMA_generate_common_url($_url_params);
1002 $edit_str = PMA_getIcon('b_edit.png', __('Edit/Insert'), true);
1003 echo('<span class="open_gis_editor">');
1004 echo(PMA_linkOrButton($edit_url, $edit_str, array(), false, false, '_blank'));
1005 echo('</span>');
1008 </td>
1009 </tr>
1010 <?php
1011 $odd_row = !$odd_row;
1012 } // end for
1013 $o_rows++;
1014 echo ' </tbody></table><br />';
1015 } // end foreach on multi-edit
1017 <div id="gis_editor"></div><div id="popup_background"></div>
1018 <br />
1019 <fieldset id="actions_panel">
1020 <table border="0" cellpadding="5" cellspacing="0">
1021 <tr>
1022 <td valign="middle" nowrap="nowrap">
1023 <select name="submit_type" class="control_at_footer" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
1024 <?php
1025 if (isset($where_clause)) {
1027 <option value="save"><?php echo __('Save'); ?></option>
1028 <?php
1031 <option value="insert"><?php echo __('Insert as new row'); ?></option>
1032 <option value="insertignore"><?php echo __('Insert as new row and ignore errors'); ?></option>
1033 <option value="showinsert"><?php echo __('Show insert query'); ?></option>
1034 </select>
1035 <?php
1036 echo "\n";
1038 if (! isset($after_insert)) {
1039 $after_insert = 'back';
1042 </td>
1043 <td valign="middle">
1044 &nbsp;&nbsp;&nbsp;<strong><?php echo __('and then'); ?></strong>&nbsp;&nbsp;&nbsp;
1045 </td>
1046 <td valign="middle" nowrap="nowrap">
1047 <select name="after_insert">
1048 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to previous page'); ?></option>
1049 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Insert another new row'); ?></option>
1050 <?php
1051 if (isset($where_clause)) {
1053 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to this page'); ?></option>
1054 <?php
1055 // If we have just numeric primary key, we can also edit next
1056 // in 2.8.2, we were looking for `field_name` = numeric_value
1057 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1058 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1059 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause)) {
1061 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo __('Edit next row'); ?></option>
1062 <?php
1066 </select>
1067 </td>
1068 </tr>
1070 <tr>
1071 <td>
1072 <?php echo PMA_showHint(__('Use TAB key to move from value to value, or CTRL+arrows to move anywhere')); ?>
1073 </td>
1074 <td colspan="3" align="right" valign="middle">
1075 <input type="submit" class="control_at_footer" value="<?php echo __('Go'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1076 <input type="reset" class="control_at_footer" value="<?php echo __('Reset'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1077 </td>
1078 </tr>
1079 </table>
1080 </fieldset>
1081 <?php if ($biggest_max_file_size > 0) {
1082 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1083 } ?>
1084 </form>
1085 <?php
1086 if ($insert_mode) {
1088 <!-- Continue insertion form -->
1089 <form id="continueForm" method="post" action="tbl_replace.php" name="continueForm" >
1090 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1091 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1092 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
1093 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
1094 <?php
1095 if (isset($where_clauses)) {
1096 foreach ($where_clause_array as $key_id => $where_clause) {
1097 echo '<input type="hidden" name="where_clause[' . $key_id . ']" value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n";
1100 $tmp = '<select name="insert_rows" id="insert_rows">' . "\n";
1101 $option_values = array(1,2,5,10,15,20,30,40);
1102 foreach ($option_values as $value) {
1103 $tmp .= '<option value="' . $value . '"';
1104 if ($value == $cfg['InsertRows']) {
1105 $tmp .= ' selected="selected"';
1107 $tmp .= '>' . $value . '</option>' . "\n";
1109 $tmp .= '</select>' . "\n";
1110 echo "\n" . sprintf(__('Continue insertion with %s rows'), $tmp);
1111 unset($tmp);
1112 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>' . "\n";
1113 echo '</form>' . "\n";
1117 * Displays the footer
1119 require './libraries/footer.inc.php';