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