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