bugfix: makegrid broke styling of rows with conditions in table search
[phpmyadmin.git] / tbl_change.php
blob6024d804257715e434686bc572385b25423e43e3
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);
462 //Call validation when the form submited...
463 $unnullify_trigger = $chg_evt_handler . "=\"return verificationsAfterFieldChange('". PMA_escapeJsString($field['Field_md5']) . "', '"
464 . PMA_escapeJsString($jsvkey) . "','".$field['pma_type']."')\"";
466 // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
467 $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
469 if ($field['Type'] == 'datetime'
470 && ! isset($field['Default'])
471 && ! is_null($field['Default'])
472 && ($insert_mode || ! isset($vrow[$field['Field']]))) {
473 // INSERT case or
474 // UPDATE case with an NULL value
475 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
478 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; ?>">
479 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center">
480 <?php echo $field['Field_title']; ?>
481 <input type="hidden" name="fields_name<?php echo $field_name_appendix; ?>" value="<?php echo $field['Field_html']; ?>"/>
482 </td>
483 <?php if ($cfg['ShowFieldTypesInDataEditView']) { ?>
484 <td align="center"<?php echo $field['wrap']; ?>><span class="column_type"><?php echo $field['pma_type']; ?></span>
485 </td>
487 <?php } //End if
489 // Get a list of GIS data types.
490 $gis_data_types = PMA_getGISDatatypes();
492 // Prepares the field value
493 $real_null_value = false;
494 $special_chars_encoded = '';
495 if (isset($vrow)) {
496 // (we are editing)
497 if (is_null($vrow[$field['Field']])) {
498 $real_null_value = true;
499 $vrow[$field['Field']] = '';
500 $special_chars = '';
501 $data = $vrow[$field['Field']];
502 } elseif ($field['True_Type'] == 'bit') {
503 $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
504 } elseif (in_array($field['True_Type'], $gis_data_types)) {
505 // Convert gis data to Well Know Text format
506 $vrow[$field['Field']] = PMA_asWKT($vrow[$field['Field']], true);
507 $special_chars = htmlspecialchars($vrow[$field['Field']]);
508 } else {
509 // special binary "characters"
510 if ($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) {
511 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
512 $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]);
513 $field['display_binary_as_hex'] = true;
514 } else {
515 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
517 } // end if
518 $special_chars = htmlspecialchars($vrow[$field['Field']]);
520 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
521 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
523 $data = $vrow[$field['Field']];
524 } // end if... else...
526 //when copying row, it is useful to empty auto-increment column to prevent duplicate key error
527 if (isset($default_action) && $default_action === 'insert') {
528 if ($field['Key'] === 'PRI' && strpos($field['Extra'], 'auto_increment') !== false) {
529 $data = $special_chars_encoded = $special_chars = null;
532 // If a timestamp field value is not included in an update
533 // statement MySQL auto-update it to the current timestamp;
534 // however, things have changed since MySQL 4.1, so
535 // it's better to set a fields_prev in this situation
536 $backup_field = '<input type="hidden" name="fields_prev'
537 . $field_name_appendix . '" value="'
538 . htmlspecialchars($vrow[$field['Field']]) . '" />';
539 } else {
540 // (we are inserting)
541 // display default values
542 if (! isset($field['Default'])) {
543 $field['Default'] = '';
544 $real_null_value = true;
545 $data = '';
546 } else {
547 $data = $field['Default'];
549 if ($field['True_Type'] == 'bit') {
550 $special_chars = PMA_convert_bit_default_value($field['Default']);
551 } else {
552 $special_chars = htmlspecialchars($field['Default']);
554 $backup_field = '';
555 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
556 // this will select the UNHEX function while inserting
557 if (($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) && $_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
558 $field['display_binary_as_hex'] = true;
562 $idindex = ($o_rows * $fields_cnt) + $i + 1;
563 $tabindex = $idindex;
565 // Get a list of data types that are not yet supported.
566 $no_support_types = PMA_unsupportedDatatypes();
568 // The function column
569 // -------------------
570 // We don't want binary data to be destroyed
571 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
572 // stored or retrieved" so it does not mean that the contents is
573 // binary
574 if ($cfg['ShowFunctionFields']) {
575 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
576 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
577 echo ' <td align="center">' . __('Binary') . '</td>' . "\n";
578 } elseif (strstr($field['True_Type'], 'enum') || strstr($field['True_Type'], 'set') || in_array($field['pma_type'], $no_support_types)) {
579 echo ' <td align="center">--</td>' . "\n";
580 } else {
582 <td>
583 <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">
584 <?php
585 echo PMA_getFunctionsForField($field, $insert_mode);
587 </select>
588 </td>
589 <?php
591 } // end if ($cfg['ShowFunctionFields'])
594 // The null column
595 // ---------------
596 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
597 echo ' <td>' . "\n";
598 if ($field['Null'] == 'YES') {
599 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
600 if ($real_null_value && !$field['first_timestamp']) {
601 echo ' value="on"';
603 echo ' />' . "\n";
605 echo ' <input type="checkbox" class="checkbox_null" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
606 . ' name="fields_null' . $field_name_appendix . '"';
607 if ($real_null_value && !$field['first_timestamp']) {
608 echo ' checked="checked"';
610 echo ' id="field_' . ($idindex) . '_2" />';
612 // nullify_code is needed by the js nullify() function
613 if (strstr($field['True_Type'], 'enum')) {
614 if (strlen($field['Type']) > 20) {
615 $nullify_code = '1';
616 } else {
617 $nullify_code = '2';
619 } elseif (strstr($field['True_Type'], 'set')) {
620 $nullify_code = '3';
621 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
622 // foreign key in a drop-down
623 $nullify_code = '4';
624 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
625 // foreign key with a browsing icon
626 $nullify_code = '6';
627 } else {
628 $nullify_code = '5';
630 // to be able to generate calls to nullify() in jQuery
631 echo '<input type="hidden" class="nullify_code" name="nullify_code' . $field_name_appendix . '" value="' . $nullify_code . '" />';
632 echo '<input type="hidden" class="hashed_field" name="hashed_field' . $field_name_appendix . '" value="' . $field['Field_md5'] . '" />';
633 echo '<input type="hidden" class="multi_edit" name="multi_edit' . $field_name_appendix . '" value="' . PMA_escapeJsString($vkey) . '" />';
635 echo ' </td>' . "\n";
637 // The value column (depends on type)
638 // ----------------
639 // See bug #1667887 for the reason why we don't use the maxlength
640 // HTML attribute
642 echo ' <td>' . "\n";
643 // Will be used by js/tbl_change.js to set the default value
644 // for the "Continue insertion" feature
645 echo '<span class="default_value hide">' . $special_chars . '</span>';
646 if ($foreignData['foreign_link'] == true) {
647 echo $backup_field . "\n";
649 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
650 value="foreign" />
651 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
652 class="textfield" <?php echo $unnullify_trigger; ?>
653 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
654 id="field_<?php echo ($idindex); ?>_3"
655 value="<?php echo htmlspecialchars($data); ?>" />
656 <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>
657 <?php
658 } elseif (is_array($foreignData['disp_row'])) {
659 echo $backup_field . "\n";
661 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
662 value="foreign" />
663 <select name="fields<?php echo $field_name_appendix; ?>"
664 <?php echo $unnullify_trigger; ?>
665 class="textfield"
666 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
667 id="field_<?php echo ($idindex); ?>_3">
668 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
669 </select>
670 <?php
671 // still needed? :
672 unset($foreignData['disp_row']);
673 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
675 &nbsp;</td>
676 </tr>
677 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
678 <td colspan="5" align="right">
679 <?php echo $backup_field . "\n"; ?>
680 <textarea name="fields<?php echo $field_name_appendix; ?>"
681 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
682 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
683 dir="<?php echo $text_dir; ?>"
684 id="field_<?php echo ($idindex); ?>_3"
685 <?php echo $unnullify_trigger; ?>
686 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
687 ><?php echo $special_chars_encoded; ?></textarea>
688 <?php
689 } elseif (strstr($field['pma_type'], 'text')) {
690 echo $backup_field . "\n";
692 <textarea name="fields<?php echo $field_name_appendix; ?>"
693 rows="<?php echo $cfg['TextareaRows']; ?>"
694 cols="<?php echo $cfg['TextareaCols']; ?>"
695 dir="<?php echo $text_dir; ?>"
696 id="field_<?php echo ($idindex); ?>_3"
697 <?php echo $unnullify_trigger; ?>
698 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
699 ><?php echo $special_chars_encoded; ?></textarea>
700 <?php
701 echo "\n";
702 if (strlen($special_chars) > 32000) {
703 echo " </td>\n";
704 echo ' <td>' . __('Because of its length,<br /> this column might not be editable');
706 } elseif ($field['pma_type'] == 'enum') {
707 if (! isset($table_fields[$i]['values'])) {
708 $table_fields[$i]['values'] = array();
709 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
710 // Removes automatic MySQL escape format
711 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
712 $table_fields[$i]['values'][] = array(
713 'plain' => $val,
714 'html' => htmlspecialchars($val),
718 $field_enum_values = $table_fields[$i]['values'];
720 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
721 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
722 <?php
723 echo "\n" . ' ' . $backup_field . "\n";
725 // show dropdown or radio depend on length
726 if (strlen($field['Type']) > 20) {
728 <select name="fields<?php echo $field_name_appendix; ?>"
729 <?php echo $unnullify_trigger; ?>
730 class="textfield"
731 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
732 id="field_<?php echo ($idindex); ?>_3">
733 <option value="">&nbsp;</option>
734 <?php
735 echo "\n";
737 foreach ($field_enum_values as $enum_value) {
738 echo ' ';
739 echo '<option value="' . $enum_value['html'] . '"';
740 if ($data == $enum_value['plain']
741 || ($data == ''
742 && (! isset($where_clause) || $field['Null'] != 'YES')
743 && isset($field['Default'])
744 && $enum_value['plain'] == $field['Default'])) {
745 echo ' selected="selected"';
747 echo '>' . $enum_value['html'] . '</option>' . "\n";
748 } // end for
751 </select>
752 <?php
753 } else {
754 $j = 0;
755 foreach ($field_enum_values as $enum_value) {
756 echo ' ';
757 echo '<input type="radio" name="fields' . $field_name_appendix . '"';
758 echo ' class="textfield"';
759 echo ' value="' . $enum_value['html'] . '"';
760 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
761 echo $unnullify_trigger;
762 if ($data == $enum_value['plain']
763 || ($data == ''
764 && (! isset($where_clause) || $field['Null'] != 'YES')
765 && isset($field['Default'])
766 && $enum_value['plain'] == $field['Default'])) {
767 echo ' checked="checked"';
769 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
770 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
771 . $enum_value['html'] . '</label>' . "\n";
772 $j++;
773 } // end for
774 } // end else
775 } elseif ($field['pma_type'] == 'set') {
776 if (! isset($table_fields[$i]['values'])) {
777 $table_fields[$i]['values'] = array();
778 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
779 $table_fields[$i]['values'][] = array(
780 'plain' => $val,
781 'html' => htmlspecialchars($val),
784 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
786 $field_set_values = $table_fields[$i]['values'];
787 $select_size = $table_fields[$i]['select_size'];
789 $vset = array_flip(explode(',', $data));
790 echo $backup_field . "\n";
792 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
793 <select name="fields<?php echo $field_name_appendix . '[]'; ?>"
794 class="textfield"
795 size="<?php echo $select_size; ?>"
796 multiple="multiple" <?php echo $unnullify_trigger; ?>
797 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
798 id="field_<?php echo ($idindex); ?>_3">
799 <?php
800 foreach ($field_set_values as $field_set_value) {
801 echo ' ';
802 echo '<option value="' . $field_set_value['html'] . '"';
803 if (isset($vset[$field_set_value['plain']])) {
804 echo ' selected="selected"';
806 echo '>' . $field_set_value['html'] . '</option>' . "\n";
807 } // end for
809 </select>
810 <?php
812 // We don't want binary data destroyed
813 elseif ($field['is_binary'] || $field['is_blob']) {
814 if (($cfg['ProtectBinary'] && $field['is_blob'])
815 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])
817 echo "\n";
818 // for blobstreaming
819 if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type)
820 && PMA_BS_IsPBMSReference($data, $db)
822 echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_md5'] . $vkey . '" value="' . $data . '" />';
823 echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . __('Remove BLOB Repository Reference') . "<br />";
824 echo PMA_BS_CreateReferenceLink($data, $db);
825 echo "<br />";
826 } else {
827 echo __('Binary - do not edit');
828 if (isset($data)) {
829 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
830 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
831 unset($data_size);
833 echo "\n";
834 } // end if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
836 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
837 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
838 <?php
839 } elseif ($field['is_blob']) {
840 echo "\n";
841 echo $backup_field . "\n";
843 <textarea name="fields<?php echo $field_name_appendix; ?>"
844 rows="<?php echo $cfg['TextareaRows']; ?>"
845 cols="<?php echo $cfg['TextareaCols']; ?>"
846 dir="<?php echo $text_dir; ?>"
847 id="field_<?php echo ($idindex); ?>_3"
848 <?php echo $unnullify_trigger; ?>
849 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
850 ><?php echo $special_chars_encoded; ?></textarea>
851 <?php
853 } else {
854 // field size should be at least 4 and max $cfg['LimitChars']
855 $fieldsize = min(max($field['len'], 4), $cfg['LimitChars']);
856 echo "\n";
857 echo $backup_field . "\n";
859 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
860 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
861 class="textfield" <?php echo $unnullify_trigger; ?>
862 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
863 id="field_<?php echo ($idindex); ?>_3" />
864 <?php
865 } // end if...elseif...else
867 // Upload choice (only for BLOBs because the binary
868 // attribute does not imply binary contents)
869 // (displayed whatever value the ProtectBinary has)
871 if ($is_upload && $field['is_blob']) {
872 // check if field type is of longblob and if the table is PBMS enabled.
873 if (($field['pma_type'] == "longblob")
874 && PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type)
876 echo '<br />';
877 echo '<input type="checkbox" name="upload_blob_repo' . $vkey . '[' . $field['Field_md5'] . ']" /> ' . __('Upload to BLOB repository');
880 echo '<br />';
881 echo '<input type="file" name="fields_upload' . $vkey . '[' . $field['Field_md5'] . ']" class="textfield" id="field_' . $idindex . '_3" size="10" ' . $unnullify_trigger . '/>&nbsp;';
883 // find maximum upload size, based on field type
885 * @todo with functions this is not so easy, as you can basically
886 * process any data with function like MD5
888 $max_field_sizes = array(
889 'tinyblob' => '256',
890 'blob' => '65536',
891 'mediumblob' => '16777216',
892 'longblob' => '4294967296'); // yeah, really
894 $this_field_max_size = $max_upload_size; // from PHP max
895 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
896 $this_field_max_size = $max_field_sizes[$field['pma_type']];
898 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
899 // do not generate here the MAX_FILE_SIZE, because we should
900 // put only one in the form to accommodate the biggest field
901 if ($this_field_max_size > $biggest_max_file_size) {
902 $biggest_max_file_size = $this_field_max_size;
906 if (!empty($cfg['UploadDir'])) {
907 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
908 if ($files === false) {
909 echo ' <font color="red">' . __('Error') . '</font><br />' . "\n";
910 echo ' ' . __('The directory you set for upload work cannot be reached') . "\n";
911 } elseif (!empty($files)) {
912 echo "<br />\n";
913 echo ' <i>' . __('Or') . '</i>' . ' ' . __('web server upload directory') . ':<br />' . "\n";
914 echo ' <select size="1" name="fields_uploadlocal' . $vkey . '[' . $field['Field_md5'] . ']">' . "\n";
915 echo ' <option value="" selected="selected"></option>' . "\n";
916 echo $files;
917 echo ' </select>' . "\n";
919 } // end if (web-server upload directory)
920 } // end elseif (binary or blob)
921 elseif (in_array($field['pma_type'], $no_support_types)) {
922 // ignore this column to avoid changing it
923 } else {
924 // field size should be at least 4 and max 40
925 $fieldsize = min(max($field['len'], 4), 40);
926 echo $backup_field . "\n";
927 if ($field['is_char']
928 && ($cfg['CharEditing'] == 'textarea'
929 || strpos($data, "\n") !== false)
931 echo "\n";
933 <textarea name="fields<?php echo $field_name_appendix; ?>"
934 rows="<?php echo $cfg['CharTextareaRows']; ?>"
935 cols="<?php echo $cfg['CharTextareaCols']; ?>"
936 dir="<?php echo $text_dir; ?>"
937 id="field_<?php echo ($idindex); ?>_3"
938 <?php echo $unnullify_trigger; ?>
939 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
940 ><?php echo $special_chars_encoded; ?></textarea>
941 <?php
942 } else {
943 $the_class = 'textfield';
944 if ($field['pma_type'] == 'date') {
945 $the_class .= ' datefield';
946 } elseif ($field['pma_type'] == 'datetime'
947 || substr($field['pma_type'], 0, 9) == 'timestamp'
949 $the_class .= ' datetimefield';
952 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
953 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
954 class="<?php echo $the_class; ?>" <?php echo $unnullify_trigger; ?>
955 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
956 id="field_<?php echo ($idindex); ?>_3" />
957 <?php
958 if ($field['Extra'] == 'auto_increment') {
960 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
961 <?php
962 } // end if
963 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
965 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
966 <?php
968 if (substr($field['pma_type'], 0, 8) == 'datetime') {
970 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="datetime" />
971 <?php
973 if ($field['True_Type'] == 'bit') {
975 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
976 <?php
978 if ($field['pma_type'] == 'date'
979 || $field['pma_type'] == 'datetime'
980 || substr($field['pma_type'], 0, 9) == 'timestamp'
982 // the _3 suffix points to the date field
983 // the _2 suffix points to the corresponding NULL checkbox
984 // in dateFormat, 'yy' means the year with 4 digits
988 if (in_array($field['pma_type'], $gis_data_types)) {
989 $data_val = isset($vrow[$field['Field']]) ? $vrow[$field['Field']] : '';
990 $_url_params = array(
991 'field' => $field['Field_title'],
992 'value' => $data_val,
994 if ($field['pma_type'] != 'geometry') {
995 $_url_params = $_url_params + array('gis_data[gis_type]' => strtoupper($field['pma_type']));
997 $edit_url = 'gis_data_editor.php' . PMA_generate_common_url($_url_params);
998 $edit_str = PMA_getIcon('b_edit.png', __('Edit/Insert'), true);
999 echo('<span class="open_gis_editor">');
1000 echo(PMA_linkOrButton($edit_url, $edit_str, array(), false, false, '_blank'));
1001 echo('</span>');
1004 </td>
1005 </tr>
1006 <?php
1007 $odd_row = !$odd_row;
1008 } // end for
1009 $o_rows++;
1010 echo ' </tbody></table><br />';
1011 } // end foreach on multi-edit
1013 <div id="gis_editor"></div><div id="popup_background"></div>
1014 <br />
1015 <fieldset id="actions_panel">
1016 <table border="0" cellpadding="5" cellspacing="0">
1017 <tr>
1018 <td valign="middle" nowrap="nowrap">
1019 <select name="submit_type" class="control_at_footer" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
1020 <?php
1021 if (isset($where_clause)) {
1023 <option value="save"><?php echo __('Save'); ?></option>
1024 <?php
1027 <option value="insert"><?php echo __('Insert as new row'); ?></option>
1028 <option value="insertignore"><?php echo __('Insert as new row and ignore errors'); ?></option>
1029 <option value="showinsert"><?php echo __('Show insert query'); ?></option>
1030 </select>
1031 <?php
1032 echo "\n";
1034 if (! isset($after_insert)) {
1035 $after_insert = 'back';
1038 </td>
1039 <td valign="middle">
1040 &nbsp;&nbsp;&nbsp;<strong><?php echo __('and then'); ?></strong>&nbsp;&nbsp;&nbsp;
1041 </td>
1042 <td valign="middle" nowrap="nowrap">
1043 <select name="after_insert">
1044 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to previous page'); ?></option>
1045 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Insert another new row'); ?></option>
1046 <?php
1047 if (isset($where_clause)) {
1049 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to this page'); ?></option>
1050 <?php
1051 // If we have just numeric primary key, we can also edit next
1052 // in 2.8.2, we were looking for `field_name` = numeric_value
1053 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1054 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1055 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause)) {
1057 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo __('Edit next row'); ?></option>
1058 <?php
1062 </select>
1063 </td>
1064 </tr>
1066 <tr>
1067 <td>
1068 <?php echo PMA_showHint(__('Use TAB key to move from value to value, or CTRL+arrows to move anywhere')); ?>
1069 </td>
1070 <td colspan="3" align="right" valign="middle">
1071 <input type="submit" class="control_at_footer" value="<?php echo __('Go'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1072 <input type="reset" class="control_at_footer" value="<?php echo __('Reset'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1073 </td>
1074 </tr>
1075 </table>
1076 </fieldset>
1077 <?php if ($biggest_max_file_size > 0) {
1078 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1079 } ?>
1080 </form>
1081 <?php
1082 if ($insert_mode) {
1084 <!-- Continue insertion form -->
1085 <form id="continueForm" method="post" action="tbl_replace.php" name="continueForm" >
1086 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1087 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1088 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
1089 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
1090 <?php
1091 if (isset($where_clauses)) {
1092 foreach ($where_clause_array as $key_id => $where_clause) {
1093 echo '<input type="hidden" name="where_clause[' . $key_id . ']" value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n";
1096 $tmp = '<select name="insert_rows" id="insert_rows">' . "\n";
1097 $option_values = array(1,2,5,10,15,20,30,40);
1098 foreach ($option_values as $value) {
1099 $tmp .= '<option value="' . $value . '"';
1100 if ($value == $cfg['InsertRows']) {
1101 $tmp .= ' selected="selected"';
1103 $tmp .= '>' . $value . '</option>' . "\n";
1105 $tmp .= '</select>' . "\n";
1106 echo "\n" . sprintf(__('Continue insertion with %s rows'), $tmp);
1107 unset($tmp);
1108 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>' . "\n";
1109 echo '</form>' . "\n";
1113 * Displays the footer
1115 require './libraries/footer.inc.php';