Fixed bugs in show error message ine multi row change in table structure
[phpmyadmin/madhuracj.git] / tbl_change.php
blob94c7da078d109f06f78df6fe91e7277544555f84
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 /**
23 * Sets global variables.
24 * Here it's better to use a if, instead of the '?' operator
25 * to avoid setting a variable to '' when it's not present in $_REQUEST
27 if (isset($_REQUEST['where_clause'])) {
28 $where_clause = $_REQUEST['where_clause'];
30 if (isset($_REQUEST['clause_is_unique'])) {
31 $clause_is_unique = $_REQUEST['clause_is_unique'];
33 if (isset($_SESSION['edit_next'])) {
34 $where_clause = $_SESSION['edit_next'];
35 unset($_SESSION['edit_next']);
36 $after_insert = 'edit_next';
38 if (isset($_REQUEST['sql_query'])) {
39 $sql_query = $_REQUEST['sql_query'];
41 if (isset($_REQUEST['ShowFunctionFields'])) {
42 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
44 if (isset($_REQUEST['ShowFieldTypesInDataEditView'])) {
45 $cfg['ShowFieldTypesInDataEditView'] = $_REQUEST['ShowFieldTypesInDataEditView'];
47 if (isset($_REQUEST['default_action'])) {
48 $default_action = $_REQUEST['default_action'];
51 /**
52 * file listing
54 require_once './libraries/file_listing.php';
57 /**
58 * Defines the url to return to in case of error in a sql statement
59 * (at this point, $GLOBALS['goto'] will be set but could be empty)
61 if (empty($GLOBALS['goto'])) {
62 if (strlen($table)) {
63 // avoid a problem (see bug #2202709)
64 $GLOBALS['goto'] = 'tbl_sql.php';
65 } else {
66 $GLOBALS['goto'] = 'db_sql.php';
69 /**
70 * @todo check if we could replace by "db_|tbl_" - please clarify!?
72 $_url_params = array(
73 'db' => $db,
74 'sql_query' => $sql_query
77 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
78 $_url_params['table'] = $table;
81 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
82 unset($_url_params);
85 /**
86 * Sets parameters for links
87 * where is this variable used?
88 * replace by PMA_generate_common_url($url_params);
90 $url_query = PMA_generate_common_url($url_params, 'html', '');
92 /**
93 * get table information
94 * @todo should be done by a Table object
96 require_once './libraries/tbl_info.inc.php';
98 /**
99 * Get comments for table fileds/columns
101 $comments_map = array();
103 if ($GLOBALS['cfg']['ShowPropertyComments']) {
104 $comments_map = PMA_getComments($db, $table);
108 * START REGULAR OUTPUT
112 * used in ./libraries/header.inc.php to load JavaScript library file
114 $GLOBALS['js_include'][] = 'functions.js';
115 $GLOBALS['js_include'][] = 'tbl_change.js';
116 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
117 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
119 * HTTP and HTML headers
121 require_once './libraries/header.inc.php';
124 * Displays the query submitted and its result
126 * @todo where does $disp_message and $disp_query come from???
128 if (! empty($disp_message)) {
129 if (! isset($disp_query)) {
130 $disp_query = null;
132 PMA_showMessage($disp_message, $disp_query);
136 * Displays top menu links
138 require_once './libraries/tbl_links.inc.php';
142 * Get the analysis of SHOW CREATE TABLE for this table
143 * @todo should be handled by class Table
145 $show_create_table = PMA_DBI_fetch_value(
146 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
147 0, 1);
148 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
149 unset($show_create_table);
152 * Get the list of the fields of the current table
154 PMA_DBI_select_db($db);
155 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
156 null, null, null, PMA_DBI_QUERY_STORE);
157 $rows = array();
158 if (isset($where_clause)) {
159 // when in edit mode load all selected rows from table
160 $insert_mode = false;
161 if (is_array($where_clause)) {
162 $where_clause_array = $where_clause;
163 } else {
164 $where_clause_array = array(0 => $where_clause);
167 $result = array();
168 $found_unique_key = false;
169 $where_clauses = array();
171 foreach ($where_clause_array as $key_id => $where_clause) {
172 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';';
173 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
174 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
175 $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
177 // No row returned
178 if (! $rows[$key_id]) {
179 unset($rows[$key_id], $where_clause_array[$key_id]);
180 PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query);
181 echo "\n";
182 require './libraries/footer.inc.php';
183 } else { // end if (no row returned)
184 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
185 list($unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true);
186 if (! empty($unique_condition)) {
187 $found_unique_key = true;
189 unset($unique_condition, $tmp_clause_is_unique);
193 } else {
194 // no primary key given, just load first row - but what happens if table is empty?
195 $insert_mode = true;
196 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
197 $rows = array_fill(0, $cfg['InsertRows'], false);
200 // Copying a row - fetched data will be inserted as a new row, therefore the where clause is needless.
201 if (isset($default_action) && $default_action === 'insert') {
202 unset($where_clause, $where_clauses);
205 // retrieve keys into foreign fields, if any
206 $foreigners = PMA_getForeigners($db, $table);
210 * Displays the form
212 // autocomplete feature of IE kills the "onchange" event handler and it
213 // must be replaced by the "onpropertychange" one in this case
214 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7)
215 ? 'onpropertychange'
216 : 'onchange';
217 // Had to put the URI because when hosted on an https server,
218 // some browsers send wrongly this form to the http server.
221 <!-- Set on key handler for moving using by Ctrl+arrows -->
222 <script src="./js/keyhandler.js" type="text/javascript"></script>
223 <script type="text/javascript">
224 //<![CDATA[
225 var switch_movement = 0;
226 document.onkeydown = onKeyDownArrowsHandler;
227 //]]>
228 </script>
229 <?php
231 $_form_params = array(
232 'db' => $db,
233 'table' => $table,
234 'goto' => $GLOBALS['goto'],
235 'err_url' => $err_url,
236 'sql_query' => $sql_query,
238 if (isset($where_clauses)) {
239 foreach ($where_clause_array as $key_id => $where_clause) {
240 $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
243 if (isset($clause_is_unique)) {
244 $_form_params['clause_is_unique'] = $clause_is_unique;
249 <!-- Insert/Edit form -->
250 <form id="insertForm" method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
251 <?php
252 echo PMA_generate_common_hidden_inputs($_form_params);
254 $titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
256 // Set if we passed the first timestamp field
257 $timestamp_seen = 0;
258 $fields_cnt = count($table_fields);
260 $tabindex = 0;
261 $tabindex_for_function = +3000;
262 $tabindex_for_null = +6000;
263 $tabindex_for_value = 0;
264 $o_rows = 0;
265 $biggest_max_file_size = 0;
267 // user can toggle the display of Function column
268 // (currently does not work for multi-edits)
269 $url_params['db'] = $db;
270 $url_params['table'] = $table;
271 if (isset($where_clause)) {
272 $url_params['where_clause'] = trim($where_clause);
274 if (! empty($sql_query)) {
275 $url_params['sql_query'] = $sql_query;
278 if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) {
279 echo __('Show');
281 if (! $cfg['ShowFunctionFields']) {
282 $this_url_params = array_merge($url_params,
283 array('ShowFunctionFields' => 1, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
284 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . __('Function') . '</a>' . "\n";
286 if (! $cfg['ShowFieldTypesInDataEditView']) {
287 $this_other_url_params = array_merge($url_params,
288 array('ShowFieldTypesInDataEditView' => 1, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
289 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_other_url_params) . '">' . __('Type') . '</a>' . "\n";
292 foreach ($rows as $row_id => $vrow) {
293 if ($vrow === false) {
294 unset($vrow);
297 $jsvkey = $row_id;
298 $rownumber_param = '&amp;rownumber=' . $row_id;
299 $vkey = '[multi_edit][' . $jsvkey . ']';
301 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ? $result[$row_id] : $result);
302 if ($insert_mode && $row_id > 0) {
303 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_' . $row_id . '" />';
304 echo '<label for="insert_ignore_' . $row_id . '">' . __('Ignore') . '</label><br />' . "\n";
307 <table class="insertRowTable">
308 <thead>
309 <tr>
310 <th><?php echo __('Column'); ?></th>
312 <?php
313 if ($cfg['ShowFieldTypesInDataEditView']) {
314 $this_url_params = array_merge($url_params,
315 array('ShowFieldTypesInDataEditView' => 0, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
316 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Type') . '</a></th>' . "\n";
319 if ($cfg['ShowFunctionFields']) {
320 $this_url_params = array_merge($url_params,
321 array('ShowFunctionFields' => 0, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
322 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Function') . '</a></th>' . "\n";
325 <th><?php echo __('Null'); ?></th>
326 <th><?php echo __('Value'); ?></th>
327 </tr>
328 </thead>
329 <tfoot>
330 <tr>
331 <th colspan="5" align="right" class="tblFooters">
332 <input type="submit" value="<?php echo __('Go'); ?>" />
333 </th>
334 </tr>
335 </tfoot>
336 <tbody>
337 <?php
338 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
339 $m_rows = $o_rows + 1;
341 $odd_row = true;
342 for ($i = 0; $i < $fields_cnt; $i++) {
343 if (! isset($table_fields[$i]['processed'])) {
344 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
345 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
346 // True_Type contains only the type (stops at first bracket)
347 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
349 // d a t e t i m e
351 // Current date should not be set as default if the field is NULL
352 // for the current row, but do not put here the current datetime
353 // if there is a default value (the real default value will be set
354 // in the Default value logic below)
356 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
357 // $field['Default'] is not set if it contains NULL:
358 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
359 // but, look what we get if we switch to iso: (Default is NULL)
360 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
361 // so I force a NULL into it (I don't think it's possible
362 // to have an empty default value for DATETIME)
363 // then, the "if" after this one will work
364 if ($table_fields[$i]['Type'] == 'datetime'
365 && ! isset($table_fields[$i]['Default'])
366 && isset($table_fields[$i]['Null'])
367 && $table_fields[$i]['Null'] == 'YES') {
368 $table_fields[$i]['Default'] = null;
371 $table_fields[$i]['len'] =
372 preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1;
375 if (isset($comments_map[$table_fields[$i]['Field']])) {
376 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
377 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
378 . $table_fields[$i]['Field_html'] . '</span>';
379 } else {
380 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
383 // The type column.
384 // Fix for bug #3152931 'ENUM and SET cannot have "Binary" option'
385 // If check to ensure types such as "enum('one','two','binary',..)" or
386 // "enum('one','two','varbinary',..)" are not categorized as binary.
387 if (stripos($table_fields[$i]['Type'], 'binary') === 0
388 || stripos($table_fields[$i]['Type'], 'varbinary') === 0) {
389 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
390 } else {
391 $table_fields[$i]['is_binary'] = false;
394 // If check to ensure types such as "enum('one','two','blob',..)" or
395 // "enum('one','two','tinyblob',..)" etc. are not categorized as blob.
396 if (stripos($table_fields[$i]['Type'], 'blob') === 0
397 || stripos($table_fields[$i]['Type'], 'tinyblob') === 0
398 || stripos($table_fields[$i]['Type'], 'mediumblob') === 0
399 || stripos($table_fields[$i]['Type'], 'longblob') === 0) {
400 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
401 } else {
402 $table_fields[$i]['is_blob'] = false;
405 // If check to ensure types such as "enum('one','two','char',..)" or
406 // "enum('one','two','varchar',..)" are not categorized as char.
407 if (stripos($table_fields[$i]['Type'], 'char') === 0
408 || stripos($table_fields[$i]['Type'], 'varchar') === 0) {
409 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
410 } else {
411 $table_fields[$i]['is_char'] = false;
414 $table_fields[$i]['first_timestamp'] = false;
415 switch ($table_fields[$i]['True_Type']) {
416 case 'set':
417 $table_fields[$i]['pma_type'] = 'set';
418 $table_fields[$i]['wrap'] = '';
419 break;
420 case 'enum':
421 $table_fields[$i]['pma_type'] = 'enum';
422 $table_fields[$i]['wrap'] = '';
423 break;
424 case 'timestamp':
425 if (!$timestamp_seen) { // can only occur once per table
426 $timestamp_seen = 1;
427 $table_fields[$i]['first_timestamp'] = true;
429 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
430 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
431 break;
433 default:
434 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
435 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
436 break;
439 $field = $table_fields[$i];
440 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
442 if (-1 === $field['len']) {
443 $field['len'] = PMA_DBI_field_len($vresult, $i);
445 //Call validation when the form submited...
446 $unnullify_trigger = $chg_evt_handler . "=\"return verificationsAfterFieldChange('". PMA_escapeJsString($field['Field_md5']) . "', '"
447 . PMA_escapeJsString($jsvkey) . "','".$field['pma_type']."')\"";
449 // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
450 $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
452 if ($field['Type'] == 'datetime'
453 && ! isset($field['Default'])
454 && ! is_null($field['Default'])
455 && ($insert_mode || ! isset($vrow[$field['Field']]))) {
456 // INSERT case or
457 // UPDATE case with an NULL value
458 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
461 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; ?>">
462 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center">
463 <?php echo $field['Field_title']; ?>
464 <input type="hidden" name="fields_name<?php echo $field_name_appendix; ?>" value="<?php echo $field['Field_html']; ?>"/>
465 </td>
466 <?php if ($cfg['ShowFieldTypesInDataEditView']) { ?>
467 <td align="center"<?php echo $field['wrap']; ?>><span class="column_type"><?php echo $field['pma_type']; ?></span>
468 </td>
470 <?php } //End if
472 // Prepares the field value
473 $real_null_value = false;
474 $special_chars_encoded = '';
475 if (isset($vrow)) {
476 // (we are editing)
477 if (is_null($vrow[$field['Field']])) {
478 $real_null_value = true;
479 $vrow[$field['Field']] = '';
480 $special_chars = '';
481 $data = $vrow[$field['Field']];
482 } elseif ($field['True_Type'] == 'bit') {
483 $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
484 } else {
485 // special binary "characters"
486 if ($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) {
487 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
488 $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]);
489 $field['display_binary_as_hex'] = true;
490 } else {
491 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
493 } // end if
494 $special_chars = htmlspecialchars($vrow[$field['Field']]);
496 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
497 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
499 $data = $vrow[$field['Field']];
500 } // end if... else...
502 //when copying row, it is useful to empty auto-increment column to prevent duplicate key error
503 if (isset($default_action) && $default_action === 'insert') {
504 if ($field['Key'] === 'PRI' && strpos($field['Extra'], 'auto_increment') !== false) {
505 $data = $special_chars_encoded = $special_chars = NULL;
508 // If a timestamp field value is not included in an update
509 // statement MySQL auto-update it to the current timestamp;
510 // however, things have changed since MySQL 4.1, so
511 // it's better to set a fields_prev in this situation
512 $backup_field = '<input type="hidden" name="fields_prev'
513 . $field_name_appendix . '" value="'
514 . htmlspecialchars($vrow[$field['Field']]) . '" />';
515 } else {
516 // (we are inserting)
517 // display default values
518 if (! isset($field['Default'])) {
519 $field['Default'] = '';
520 $real_null_value = true;
521 $data = '';
522 } else {
523 $data = $field['Default'];
525 if ($field['True_Type'] == 'bit') {
526 $special_chars = PMA_convert_bit_default_value($field['Default']);
527 } else {
528 $special_chars = htmlspecialchars($field['Default']);
530 $backup_field = '';
531 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
532 // this will select the UNHEX function while inserting
533 if (($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) && $_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
534 $field['display_binary_as_hex'] = true;
538 $idindex = ($o_rows * $fields_cnt) + $i + 1;
539 $tabindex = $idindex;
541 // Get a list of data types that are not yet supported.
542 $no_support_types = PMA_unsupportedDatatypes();
544 // The function column
545 // -------------------
546 // We don't want binary data to be destroyed
547 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
548 // stored or retrieved" so it does not mean that the contents is
549 // binary
550 if ($cfg['ShowFunctionFields']) {
551 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
552 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
553 echo ' <td align="center">' . __('Binary') . '</td>' . "\n";
554 } elseif (strstr($field['True_Type'], 'enum') || strstr($field['True_Type'], 'set') || in_array($field['pma_type'], $no_support_types)) {
555 echo ' <td align="center">--</td>' . "\n";
556 } else {
558 <td>
559 <select name="funcs<?php echo $field_name_appendix; ?>" <?php echo $unnullify_trigger; ?> tabindex="<?php echo ($tabindex + $tabindex_for_function); ?>" id="field_<?php echo $idindex; ?>_1">
560 <?php
561 echo PMA_getFunctionsForField($field, $insert_mode);
563 </select>
564 </td>
565 <?php
567 } // end if ($cfg['ShowFunctionFields'])
570 // The null column
571 // ---------------
572 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
573 echo ' <td>' . "\n";
574 if ($field['Null'] == 'YES') {
575 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
576 if ($real_null_value && !$field['first_timestamp']) {
577 echo ' value="on"';
579 echo ' />' . "\n";
581 echo ' <input type="checkbox" class="checkbox_null" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
582 . ' name="fields_null' . $field_name_appendix . '"';
583 if ($real_null_value && !$field['first_timestamp']) {
584 echo ' checked="checked"';
586 echo ' id="field_' . ($idindex) . '_2" />';
588 // nullify_code is needed by the js nullify() function
589 if (strstr($field['True_Type'], 'enum')) {
590 if (strlen($field['Type']) > 20) {
591 $nullify_code = '1';
592 } else {
593 $nullify_code = '2';
595 } elseif (strstr($field['True_Type'], 'set')) {
596 $nullify_code = '3';
597 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
598 // foreign key in a drop-down
599 $nullify_code = '4';
600 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
601 // foreign key with a browsing icon
602 $nullify_code = '6';
603 } else {
604 $nullify_code = '5';
606 // to be able to generate calls to nullify() in jQuery
607 echo '<input type="hidden" class="nullify_code" name="nullify_code' . $field_name_appendix . '" value="' . $nullify_code . '" />';
608 echo '<input type="hidden" class="hashed_field" name="hashed_field' . $field_name_appendix . '" value="' . $field['Field_md5'] . '" />';
609 echo '<input type="hidden" class="multi_edit" name="multi_edit' . $field_name_appendix . '" value="' . PMA_escapeJsString($vkey) . '" />';
611 echo ' </td>' . "\n";
613 // The value column (depends on type)
614 // ----------------
615 // See bug #1667887 for the reason why we don't use the maxlength
616 // HTML attribute
618 echo ' <td>' . "\n";
619 // Will be used by js/tbl_change.js to set the default value
620 // for the "Continue insertion" feature
621 echo '<span class="default_value hide">' . $special_chars . '</span>';
622 if ($foreignData['foreign_link'] == true) {
623 echo $backup_field . "\n";
625 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
626 value="foreign" />
627 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
628 class="textfield" <?php echo $unnullify_trigger; ?>
629 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
630 id="field_<?php echo ($idindex); ?>_3"
631 value="<?php echo htmlspecialchars($data); ?>" />
632 <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>
633 <?php
634 } elseif (is_array($foreignData['disp_row'])) {
635 echo $backup_field . "\n";
637 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
638 value="foreign" />
639 <select name="fields<?php echo $field_name_appendix; ?>"
640 <?php echo $unnullify_trigger; ?>
641 class="textfield"
642 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
643 id="field_<?php echo ($idindex); ?>_3">
644 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
645 </select>
646 <?php
647 // still needed? :
648 unset($foreignData['disp_row']);
649 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
651 &nbsp;</td>
652 </tr>
653 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
654 <td colspan="5" align="right">
655 <?php echo $backup_field . "\n"; ?>
656 <textarea name="fields<?php echo $field_name_appendix; ?>"
657 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
658 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
659 dir="<?php echo $text_dir; ?>"
660 id="field_<?php echo ($idindex); ?>_3"
661 <?php echo $unnullify_trigger; ?>
662 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
663 ><?php echo $special_chars_encoded; ?></textarea>
664 <?php
665 } elseif (strstr($field['pma_type'], 'text')) {
666 echo $backup_field . "\n";
668 <textarea name="fields<?php echo $field_name_appendix; ?>"
669 rows="<?php echo $cfg['TextareaRows']; ?>"
670 cols="<?php echo $cfg['TextareaCols']; ?>"
671 dir="<?php echo $text_dir; ?>"
672 id="field_<?php echo ($idindex); ?>_3"
673 <?php echo $unnullify_trigger; ?>
674 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
675 ><?php echo $special_chars_encoded; ?></textarea>
676 <?php
677 echo "\n";
678 if (strlen($special_chars) > 32000) {
679 echo " </td>\n";
680 echo ' <td>' . __(' Because of its length,<br /> this column might not be editable ');
682 } elseif ($field['pma_type'] == 'enum') {
683 if (! isset($table_fields[$i]['values'])) {
684 $table_fields[$i]['values'] = array();
685 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
686 // Removes automatic MySQL escape format
687 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
688 $table_fields[$i]['values'][] = array(
689 'plain' => $val,
690 'html' => htmlspecialchars($val),
694 $field_enum_values = $table_fields[$i]['values'];
696 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
697 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
698 <?php
699 echo "\n" . ' ' . $backup_field . "\n";
701 // show dropdown or radio depend on length
702 if (strlen($field['Type']) > 20) {
704 <select name="fields<?php echo $field_name_appendix; ?>"
705 <?php echo $unnullify_trigger; ?>
706 class="textfield"
707 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
708 id="field_<?php echo ($idindex); ?>_3">
709 <option value="">&nbsp;</option>
710 <?php
711 echo "\n";
713 foreach ($field_enum_values as $enum_value) {
714 echo ' ';
715 echo '<option value="' . $enum_value['html'] . '"';
716 if ($data == $enum_value['plain']
717 || ($data == ''
718 && (! isset($where_clause) || $field['Null'] != 'YES')
719 && isset($field['Default'])
720 && $enum_value['plain'] == $field['Default'])) {
721 echo ' selected="selected"';
723 echo '>' . $enum_value['html'] . '</option>' . "\n";
724 } // end for
727 </select>
728 <?php
729 } else {
730 $j = 0;
731 foreach ($field_enum_values as $enum_value) {
732 echo ' ';
733 echo '<input type="radio" name="fields' . $field_name_appendix . '"';
734 echo ' class="textfield"';
735 echo ' value="' . $enum_value['html'] . '"';
736 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
737 echo $unnullify_trigger;
738 if ($data == $enum_value['plain']
739 || ($data == ''
740 && (! isset($where_clause) || $field['Null'] != 'YES')
741 && isset($field['Default'])
742 && $enum_value['plain'] == $field['Default'])) {
743 echo ' checked="checked"';
745 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
746 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
747 . $enum_value['html'] . '</label>' . "\n";
748 $j++;
749 } // end for
750 } // end else
751 } elseif ($field['pma_type'] == 'set') {
752 if (! isset($table_fields[$i]['values'])) {
753 $table_fields[$i]['values'] = array();
754 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
755 $table_fields[$i]['values'][] = array(
756 'plain' => $val,
757 'html' => htmlspecialchars($val),
760 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
762 $field_set_values = $table_fields[$i]['values'];
763 $select_size = $table_fields[$i]['select_size'];
765 $vset = array_flip(explode(',', $data));
766 echo $backup_field . "\n";
768 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
769 <select name="fields<?php echo $field_name_appendix . '[]'; ?>"
770 class="textfield"
771 size="<?php echo $select_size; ?>"
772 multiple="multiple" <?php echo $unnullify_trigger; ?>
773 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
774 id="field_<?php echo ($idindex); ?>_3">
775 <?php
776 foreach ($field_set_values as $field_set_value) {
777 echo ' ';
778 echo '<option value="' . $field_set_value['html'] . '"';
779 if (isset($vset[$field_set_value['plain']])) {
780 echo ' selected="selected"';
782 echo '>' . $field_set_value['html'] . '</option>' . "\n";
783 } // end for
785 </select>
786 <?php
788 // We don't want binary data destroyed
789 elseif ($field['is_binary'] || $field['is_blob']) {
790 if (($cfg['ProtectBinary'] && $field['is_blob'])
791 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
792 echo "\n";
793 // for blobstreaming
794 if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
796 echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_md5'] . $vkey . '" value="' . $data . '" />';
797 echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . __('Remove BLOB Repository Reference') . "<br />";
798 echo PMA_BS_CreateReferenceLink($data, $db);
799 echo "<br />";
801 else
803 echo __('Binary - do not edit');
804 if (isset($data)) {
805 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
806 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
807 unset($data_size);
809 echo "\n";
810 } // end if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
812 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
813 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
814 <?php
815 } elseif ($field['is_blob']) {
816 echo "\n";
817 echo $backup_field . "\n";
819 <textarea name="fields<?php echo $field_name_appendix; ?>"
820 rows="<?php echo $cfg['TextareaRows']; ?>"
821 cols="<?php echo $cfg['TextareaCols']; ?>"
822 dir="<?php echo $text_dir; ?>"
823 id="field_<?php echo ($idindex); ?>_3"
824 <?php echo $unnullify_trigger; ?>
825 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
826 ><?php echo $special_chars_encoded; ?></textarea>
827 <?php
829 } else {
830 // field size should be at least 4 and max $cfg['LimitChars']
831 $fieldsize = min(max($field['len'], 4), $cfg['LimitChars']);
832 echo "\n";
833 echo $backup_field . "\n";
835 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
836 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
837 class="textfield" <?php echo $unnullify_trigger; ?>
838 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
839 id="field_<?php echo ($idindex); ?>_3" />
840 <?php
841 } // end if...elseif...else
843 // Upload choice (only for BLOBs because the binary
844 // attribute does not imply binary contents)
845 // (displayed whatever value the ProtectBinary has)
847 if ($is_upload && $field['is_blob']) {
848 // check if field type is of longblob and if the table is PBMS enabled.
849 if (($field['pma_type'] == "longblob") && PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type)) {
850 echo '<br />';
851 echo '<input type="checkbox" name="upload_blob_repo' . $vkey . '[' . $field['Field_md5'] . ']" /> ' . __('Upload to BLOB repository');
854 echo '<br />';
855 echo '<input type="file" name="fields_upload' . $vkey . '[' . $field['Field_md5'] . ']" class="textfield" id="field_' . $idindex . '_3" size="10" ' . $unnullify_trigger . '/>&nbsp;';
857 // find maximum upload size, based on field type
859 * @todo with functions this is not so easy, as you can basically
860 * process any data with function like MD5
862 $max_field_sizes = array(
863 'tinyblob' => '256',
864 'blob' => '65536',
865 'mediumblob' => '16777216',
866 'longblob' => '4294967296'); // yeah, really
868 $this_field_max_size = $max_upload_size; // from PHP max
869 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
870 $this_field_max_size = $max_field_sizes[$field['pma_type']];
872 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
873 // do not generate here the MAX_FILE_SIZE, because we should
874 // put only one in the form to accommodate the biggest field
875 if ($this_field_max_size > $biggest_max_file_size) {
876 $biggest_max_file_size = $this_field_max_size;
880 if (!empty($cfg['UploadDir'])) {
881 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
882 if ($files === false) {
883 echo ' <font color="red">' . __('Error') . '</font><br />' . "\n";
884 echo ' ' . __('The directory you set for upload work cannot be reached') . "\n";
885 } elseif (!empty($files)) {
886 echo "<br />\n";
887 echo ' <i>' . __('Or') . '</i>' . ' ' . __('web server upload directory') . ':<br />' . "\n";
888 echo ' <select size="1" name="fields_uploadlocal' . $vkey . '[' . $field['Field_md5'] . ']">' . "\n";
889 echo ' <option value="" selected="selected"></option>' . "\n";
890 echo $files;
891 echo ' </select>' . "\n";
893 } // end if (web-server upload directory)
894 } // end elseif (binary or blob)
896 elseif (in_array($field['pma_type'], $no_support_types)) {
897 // ignore this column to avoid changing it
899 else {
900 // field size should be at least 4 and max 40
901 $fieldsize = min(max($field['len'], 4), 40);
902 echo $backup_field . "\n";
903 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== false)) {
904 echo "\n";
906 <textarea name="fields<?php echo $field_name_appendix; ?>"
907 rows="<?php echo $cfg['CharTextareaRows']; ?>"
908 cols="<?php echo $cfg['CharTextareaCols']; ?>"
909 dir="<?php echo $text_dir; ?>"
910 id="field_<?php echo ($idindex); ?>_3"
911 <?php echo $unnullify_trigger; ?>
912 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
913 ><?php echo $special_chars_encoded; ?></textarea>
914 <?php
915 } else {
916 $the_class = 'textfield';
917 if ($field['pma_type'] == 'date') {
918 $the_class .= ' datefield';
919 } elseif ($field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
920 $the_class .= ' datetimefield';
923 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
924 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
925 class="<?php echo $the_class; ?>" <?php echo $unnullify_trigger; ?>
926 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
927 id="field_<?php echo ($idindex); ?>_3" />
928 <?php
929 if ($field['Extra'] == 'auto_increment') {
931 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
932 <?php
933 } // end if
934 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
936 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
937 <?php
939 if (substr($field['pma_type'], 0, 8) == 'datetime') {
941 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="datetime" />
942 <?php
944 if ($field['True_Type'] == 'bit') {
946 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
947 <?php
949 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
950 // the _3 suffix points to the date field
951 // the _2 suffix points to the corresponding NULL checkbox
952 // in dateFormat, 'yy' means the year with 4 digits
957 </td>
958 </tr>
959 <?php
960 $odd_row = !$odd_row;
961 } // end for
962 $o_rows++;
963 echo ' </tbody></table><br />';
964 } // end foreach on multi-edit
966 <br />
968 <fieldset id="actions_panel">
969 <table border="0" cellpadding="5" cellspacing="0">
970 <tr>
971 <td valign="middle" nowrap="nowrap">
972 <select name="submit_type" class="control_at_footer" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
973 <?php
974 if (isset($where_clause)) {
976 <option value="save"><?php echo __('Save'); ?></option>
977 <?php
980 <option value="insert"><?php echo __('Insert as new row'); ?></option>
981 <option value="insertignore"><?php echo __('Insert as new row and ignore errors'); ?></option>
982 <option value="showinsert"><?php echo __('Show insert query'); ?></option>
983 </select>
984 <?php
985 echo "\n";
987 if (! isset($after_insert)) {
988 $after_insert = 'back';
991 </td>
992 <td valign="middle">
993 &nbsp;&nbsp;&nbsp;<strong><?php echo __('and then'); ?></strong>&nbsp;&nbsp;&nbsp;
994 </td>
995 <td valign="middle" nowrap="nowrap">
996 <select name="after_insert">
997 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to previous page'); ?></option>
998 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Insert another new row'); ?></option>
999 <?php
1000 if (isset($where_clause)) {
1002 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to this page'); ?></option>
1003 <?php
1004 // If we have just numeric primary key, we can also edit next
1005 // in 2.8.2, we were looking for `field_name` = numeric_value
1006 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1007 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1008 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause)) {
1010 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo __('Edit next row'); ?></option>
1011 <?php
1015 </select>
1016 </td>
1017 </tr>
1019 <tr>
1020 <td>
1021 <?php echo PMA_showHint(__('Use TAB key to move from value to value, or CTRL+arrows to move anywhere')); ?>
1022 </td>
1023 <td colspan="3" align="right" valign="middle">
1024 <input type="submit" class="control_at_footer" value="<?php echo __('Go'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1025 <input type="reset" class="control_at_footer" value="<?php echo __('Reset'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1026 </td>
1027 </tr>
1028 </table>
1029 </fieldset>
1030 <?php if ($biggest_max_file_size > 0) {
1031 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1032 } ?>
1033 </form>
1034 <?php
1035 if ($insert_mode) {
1037 <!-- Continue insertion form -->
1038 <form id="continueForm" method="post" action="tbl_replace.php" name="continueForm" >
1039 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1040 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1041 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
1042 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
1043 <?php
1044 if (isset($where_clauses)) {
1045 foreach ($where_clause_array as $key_id => $where_clause) {
1046 echo '<input type="hidden" name="where_clause[' . $key_id . ']" value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n";
1049 $tmp = '<select name="insert_rows" id="insert_rows">' . "\n";
1050 $option_values = array(1,2,5,10,15,20,30,40);
1051 foreach ($option_values as $value) {
1052 $tmp .= '<option value="' . $value . '"';
1053 if ($value == $cfg['InsertRows']) {
1054 $tmp .= ' selected="selected"';
1056 $tmp .= '>' . $value . '</option>' . "\n";
1058 $tmp .= '</select>' . "\n";
1059 echo "\n" . sprintf(__('Continue insertion with %s rows'), $tmp);
1060 unset($tmp);
1061 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>' . "\n";
1062 echo '</form>' . "\n";
1066 * Displays the footer
1068 require './libraries/footer.inc.php';