Translation update done using Pootle.
[phpmyadmin/dkf.git] / tbl_change.php
blob54e0d7f0ff2098ead5ac49564681f4c5f9fb4fdb
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';
16 /**
17 * Ensures db and table are valid, else moves to the "parent" script
19 require_once './libraries/db_table_exists.lib.php';
21 /**
22 * Sets global variables.
23 * Here it's better to use a if, instead of the '?' operator
24 * to avoid setting a variable to '' when it's not present in $_REQUEST
26 if (isset($_REQUEST['where_clause'])) {
27 $where_clause = $_REQUEST['where_clause'];
29 if (isset($_REQUEST['clause_is_unique'])) {
30 $clause_is_unique = $_REQUEST['clause_is_unique'];
32 if (isset($_SESSION['edit_next'])) {
33 $where_clause = $_SESSION['edit_next'];
34 unset($_SESSION['edit_next']);
35 $after_insert = 'edit_next';
37 if (isset($_REQUEST['sql_query'])) {
38 $sql_query = $_REQUEST['sql_query'];
40 if (isset($_REQUEST['ShowFunctionFields'])) {
41 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
43 if (isset($_REQUEST['ShowFieldTypesInDataEditView'])) {
44 $cfg['ShowFieldTypesInDataEditView'] = $_REQUEST['ShowFieldTypesInDataEditView'];
47 /**
48 * file listing
50 require_once './libraries/file_listing.php';
53 /**
54 * Defines the url to return to in case of error in a sql statement
55 * (at this point, $GLOBALS['goto'] will be set but could be empty)
57 if (empty($GLOBALS['goto'])) {
58 if (strlen($table)) {
59 // avoid a problem (see bug #2202709)
60 $GLOBALS['goto'] = 'tbl_sql.php';
61 } else {
62 $GLOBALS['goto'] = 'db_sql.php';
65 /**
66 * @todo check if we could replace by "db_|tbl_" - please clarify!?
68 $_url_params = array(
69 'db' => $db,
70 'sql_query' => $sql_query
73 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
74 $_url_params['table'] = $table;
77 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
78 unset($_url_params);
81 /**
82 * Sets parameters for links
83 * where is this variable used?
84 * replace by PMA_generate_common_url($url_params);
86 $url_query = PMA_generate_common_url($url_params, 'html', '');
88 /**
89 * get table information
90 * @todo should be done by a Table object
92 require_once './libraries/tbl_info.inc.php';
94 /**
95 * Get comments for table fileds/columns
97 $comments_map = array();
99 if ($GLOBALS['cfg']['ShowPropertyComments']) {
100 $comments_map = PMA_getComments($db, $table);
104 * START REGULAR OUTPUT
108 * used in ./libraries/header.inc.php to load JavaScript library file
110 $GLOBALS['js_include'][] = 'functions.js';
111 $GLOBALS['js_include'][] = 'tbl_change.js';
112 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
113 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
115 * HTTP and HTML headers
117 require_once './libraries/header.inc.php';
120 * Displays the query submitted and its result
122 * @todo where does $disp_message and $disp_query come from???
124 if (! empty($disp_message)) {
125 if (! isset($disp_query)) {
126 $disp_query = null;
128 PMA_showMessage($disp_message, $disp_query);
132 * Displays top menu links
134 require_once './libraries/tbl_links.inc.php';
138 * Get the analysis of SHOW CREATE TABLE for this table
139 * @todo should be handled by class Table
141 $show_create_table = PMA_DBI_fetch_value(
142 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
143 0, 1);
144 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
145 unset($show_create_table);
148 * Get the list of the fields of the current table
150 PMA_DBI_select_db($db);
151 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
152 null, null, null, PMA_DBI_QUERY_STORE);
153 $rows = array();
154 if (isset($where_clause)) {
155 // when in edit mode load all selected rows from table
156 $insert_mode = false;
157 if (is_array($where_clause)) {
158 $where_clause_array = $where_clause;
159 } else {
160 $where_clause_array = array(0 => $where_clause);
163 $result = array();
164 $found_unique_key = false;
165 $where_clauses = array();
167 foreach ($where_clause_array as $key_id => $where_clause) {
168 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';';
169 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
170 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
171 $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
173 // No row returned
174 if (! $rows[$key_id]) {
175 unset($rows[$key_id], $where_clause_array[$key_id]);
176 PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query);
177 echo "\n";
178 require './libraries/footer.inc.php';
179 } else { // end if (no row returned)
180 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
181 list($unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true);
182 if (! empty($unique_condition)) {
183 $found_unique_key = true;
185 unset($unique_condition, $tmp_clause_is_unique);
188 } else {
189 // no primary key given, just load first row - but what happens if table is empty?
190 $insert_mode = true;
191 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
192 $rows = array_fill(0, $cfg['InsertRows'], false);
195 // retrieve keys into foreign fields, if any
196 $foreigners = PMA_getForeigners($db, $table);
200 * Displays the form
202 // autocomplete feature of IE kills the "onchange" event handler and it
203 // must be replaced by the "onpropertychange" one in this case
204 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7)
205 ? 'onpropertychange'
206 : 'onchange';
207 // Had to put the URI because when hosted on an https server,
208 // some browsers send wrongly this form to the http server.
210 if ($cfg['CtrlArrowsMoving']) {
212 <!-- Set on key handler for moving using by Ctrl+arrows -->
213 <script src="./js/keyhandler.js" type="text/javascript"></script>
214 <script type="text/javascript">
215 //<![CDATA[
216 var switch_movement = 0;
217 document.onkeydown = onKeyDownArrowsHandler;
218 //]]>
219 </script>
220 <?php
223 $_form_params = array(
224 'db' => $db,
225 'table' => $table,
226 'goto' => $GLOBALS['goto'],
227 'err_url' => $err_url,
228 'sql_query' => $sql_query,
230 if (isset($where_clauses)) {
231 foreach ($where_clause_array as $key_id => $where_clause) {
232 $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
235 if (isset($clause_is_unique)) {
236 $_form_params['clause_is_unique'] = $clause_is_unique;
241 <!-- Insert/Edit form -->
242 <form id="insertForm" method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
243 <?php
244 echo PMA_generate_common_hidden_inputs($_form_params);
246 $titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
248 // Set if we passed the first timestamp field
249 $timestamp_seen = 0;
250 $fields_cnt = count($table_fields);
252 $tabindex = 0;
253 $tabindex_for_function = +3000;
254 $tabindex_for_null = +6000;
255 $tabindex_for_value = 0;
256 $o_rows = 0;
257 $biggest_max_file_size = 0;
259 // user can toggle the display of Function column
260 // (currently does not work for multi-edits)
261 $url_params['db'] = $db;
262 $url_params['table'] = $table;
263 if (isset($where_clause)) {
264 $url_params['where_clause'] = trim($where_clause);
266 if (! empty($sql_query)) {
267 $url_params['sql_query'] = $sql_query;
270 if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) {
271 echo __('Show');
273 if (! $cfg['ShowFunctionFields']) {
274 $this_url_params = array_merge($url_params,
275 array('ShowFunctionFields' => 1, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
276 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . __('Function') . '</a>' . "\n";
278 if (! $cfg['ShowFieldTypesInDataEditView']) {
279 $this_other_url_params = array_merge($url_params,
280 array('ShowFieldTypesInDataEditView' => 1, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
281 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_other_url_params) . '">' . __('Type') . '</a>' . "\n";
284 foreach ($rows as $row_id => $vrow) {
285 if ($vrow === false) {
286 unset($vrow);
289 $jsvkey = $row_id;
290 $browse_foreigners_uri = '&amp;pk=' . $row_id;
291 $vkey = '[multi_edit][' . $jsvkey . ']';
293 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ? $result[$row_id] : $result);
294 if ($insert_mode && $row_id > 0) {
295 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_' . $row_id . '" />';
296 echo '<label for="insert_ignore_' . $row_id . '">' . __('Ignore') . '</label><br />' . "\n";
299 <table class="insertRowTable">
300 <thead>
301 <tr>
302 <th><?php echo __('Column'); ?></th>
304 <?php
305 if ($cfg['ShowFieldTypesInDataEditView']) {
306 $this_url_params = array_merge($url_params,
307 array('ShowFieldTypesInDataEditView' => 0, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
308 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Type') . '</a></th>' . "\n";
311 if ($cfg['ShowFunctionFields']) {
312 $this_url_params = array_merge($url_params,
313 array('ShowFunctionFields' => 0, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
314 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Function') . '</a></th>' . "\n";
317 <th><?php echo __('Null'); ?></th>
318 <th><?php echo __('Value'); ?></th>
319 </tr>
320 </thead>
321 <tfoot>
322 <tr>
323 <th colspan="5" align="right" class="tblFooters">
324 <input type="submit" value="<?php echo __('Go'); ?>" />
325 </th>
326 </tr>
327 </tfoot>
328 <tbody>
329 <?php
330 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
331 $m_rows = $o_rows + 1;
333 $odd_row = true;
334 for ($i = 0; $i < $fields_cnt; $i++) {
335 if (! isset($table_fields[$i]['processed'])) {
336 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
337 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
338 // True_Type contains only the type (stops at first bracket)
339 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
341 // d a t e t i m e
343 // Current date should not be set as default if the field is NULL
344 // for the current row, but do not put here the current datetime
345 // if there is a default value (the real default value will be set
346 // in the Default value logic below)
348 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
349 // $field['Default'] is not set if it contains NULL:
350 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
351 // but, look what we get if we switch to iso: (Default is NULL)
352 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
353 // so I force a NULL into it (I don't think it's possible
354 // to have an empty default value for DATETIME)
355 // then, the "if" after this one will work
356 if ($table_fields[$i]['Type'] == 'datetime'
357 && ! isset($table_fields[$i]['Default'])
358 && isset($table_fields[$i]['Null'])
359 && $table_fields[$i]['Null'] == 'YES') {
360 $table_fields[$i]['Default'] = null;
363 $table_fields[$i]['len'] =
364 preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1;
367 if (isset($comments_map[$table_fields[$i]['Field']])) {
368 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
369 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
370 . $table_fields[$i]['Field_html'] . '</span>';
371 } else {
372 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
375 // The type column
376 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
377 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
378 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
379 $table_fields[$i]['first_timestamp'] = false;
380 switch ($table_fields[$i]['True_Type']) {
381 case 'set':
382 $table_fields[$i]['pma_type'] = 'set';
383 $table_fields[$i]['wrap'] = '';
384 break;
385 case 'enum':
386 $table_fields[$i]['pma_type'] = 'enum';
387 $table_fields[$i]['wrap'] = '';
388 break;
389 case 'timestamp':
390 if (!$timestamp_seen) { // can only occur once per table
391 $timestamp_seen = 1;
392 $table_fields[$i]['first_timestamp'] = true;
394 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
395 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
396 break;
398 default:
399 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
400 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
401 break;
404 $field = $table_fields[$i];
405 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
407 if (-1 === $field['len']) {
408 $field['len'] = PMA_DBI_field_len($vresult, $i);
410 //Call validation when the form submited...
411 $unnullify_trigger = $chg_evt_handler . "=\"return Validator('". PMA_escapeJsString($field['Field_md5']) . "', '"
412 . PMA_escapeJsString($jsvkey) . "','".$field['pma_type']."')\"";
414 // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
415 $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
416 $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]';
419 if ($field['Type'] == 'datetime'
420 && ! isset($field['Default'])
421 && ! is_null($field['Default'])
422 && ($insert_mode || ! isset($vrow[$field['Field']]))) {
423 // INSERT case or
424 // UPDATE case with an NULL value
425 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
428 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
429 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center">
430 <?php echo $field['Field_title']; ?>
431 <input type="hidden" name="fields_name<?php echo $field_name_appendix; ?>" value="<?php echo $field['Field_html']; ?>"/>
432 </td>
433 <?php if ($cfg['ShowFieldTypesInDataEditView']) { ?>
434 <td align="center"<?php echo $field['wrap']; ?>><span class="column_type">
435 <?php echo $field['pma_type']; ?></span>
436 </td>
438 <?php } //End if
440 // Prepares the field value
441 $real_null_value = FALSE;
442 $special_chars_encoded = '';
443 if (isset($vrow)) {
444 // (we are editing)
445 if (is_null($vrow[$field['Field']])) {
446 $real_null_value = TRUE;
447 $vrow[$field['Field']] = '';
448 $special_chars = '';
449 $data = $vrow[$field['Field']];
450 } elseif ($field['True_Type'] == 'bit') {
451 $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
452 } else {
453 // special binary "characters"
454 if ($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) {
455 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
456 $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]);
457 $field['display_binary_as_hex'] = true;
458 } else {
459 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
461 } // end if
462 $special_chars = htmlspecialchars($vrow[$field['Field']]);
464 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
465 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
467 $data = $vrow[$field['Field']];
468 } // end if... else...
469 // If a timestamp field value is not included in an update
470 // statement MySQL auto-update it to the current timestamp;
471 // however, things have changed since MySQL 4.1, so
472 // it's better to set a fields_prev in this situation
473 $backup_field = '<input type="hidden" name="fields_prev'
474 . $field_name_appendix . '" value="'
475 . htmlspecialchars($vrow[$field['Field']]) . '" />';
476 } else {
477 // (we are inserting)
478 // display default values
479 if (!isset($field['Default'])) {
480 $field['Default'] = '';
481 $real_null_value = TRUE;
482 $data = '';
483 } else {
484 $data = $field['Default'];
486 if ($field['True_Type'] == 'bit') {
487 $special_chars = PMA_convert_bit_default_value($field['Default']);
488 } else {
489 $special_chars = htmlspecialchars($field['Default']);
491 $backup_field = '';
492 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
493 // this will select the UNHEX function while inserting
494 if (($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) && $_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
495 $field['display_binary_as_hex'] = true;
499 $idindex = ($o_rows * $fields_cnt) + $i + 1;
500 $tabindex = $idindex;
502 // The function column
503 // -------------------
504 // We don't want binary data to be destroyed
505 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
506 // stored or retrieved" so it does not mean that the contents is
507 // binary
508 if ($cfg['ShowFunctionFields']) {
509 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
510 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
511 echo ' <td align="center">' . __('Binary') . '</td>' . "\n";
512 } elseif (strstr($field['True_Type'], 'enum') || strstr($field['True_Type'], 'set')) {
513 echo ' <td align="center">--</td>' . "\n";
514 } else {
516 <td>
517 <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">
518 <option></option>
519 <?php
520 $selected = '';
522 // Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
523 // or something similar. Then directly look up the entry in the RestrictFunctions array,
524 // which will then reveal the available dropdown options
525 if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
526 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
527 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
528 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
529 $default_function = $cfg['DefaultFunctions'][$current_func_type];
530 } else {
531 $dropdown = array();
532 $default_function = '';
535 $dropdown_built = array();
536 $op_spacing_needed = FALSE;
538 // what function defined as default?
539 // for the first timestamp we don't set the default function
540 // if there is a default value for the timestamp
541 // (not including CURRENT_TIMESTAMP)
542 // and the column does not have the
543 // ON UPDATE DEFAULT TIMESTAMP attribute.
545 if ($field['True_Type'] == 'timestamp'
546 && empty($field['Default'])
547 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
548 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
551 // For primary keys of type char(36) or varchar(36) UUID if the default function
552 // Only applies to insert mode, as it would silently trash data on updates.
553 if ($insert_mode
554 && $field['Key'] == 'PRI'
555 && ($field['Type'] == 'char(36)' || $field['Type'] == 'varchar(36)')
557 $default_function = $cfg['DefaultFunctions']['pk_char36'];
560 // this is set only when appropriate and is always true
561 if (isset($field['display_binary_as_hex'])) {
562 $default_function = 'UNHEX';
565 // loop on the dropdown array and print all available options for that field.
566 foreach ($dropdown as $each_dropdown){
567 echo '<option';
568 if ($default_function === $each_dropdown) {
569 echo ' selected="selected"';
571 echo '>' . $each_dropdown . '</option>' . "\n";
572 $dropdown_built[$each_dropdown] = 'TRUE';
573 $op_spacing_needed = TRUE;
576 // For compatibility's sake, do not let out all other functions. Instead
577 // print a separator (blank) and then show ALL functions which weren't shown
578 // yet.
579 $cnt_functions = count($cfg['Functions']);
580 for ($j = 0; $j < $cnt_functions; $j++) {
581 if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
582 // Is current function defined as default?
583 $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
584 || (!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
585 ? ' selected="selected"'
586 : '';
587 if ($op_spacing_needed == TRUE) {
588 echo ' ';
589 echo '<option value="">--------</option>' . "\n";
590 $op_spacing_needed = FALSE;
593 echo ' ';
594 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
596 } // end for
597 unset($selected);
599 </select>
600 </td>
601 <?php
603 } // end if ($cfg['ShowFunctionFields'])
606 // The null column
607 // ---------------
608 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
609 echo ' <td>' . "\n";
610 if ($field['Null'] == 'YES') {
611 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
612 if ($real_null_value && !$field['first_timestamp']) {
613 echo ' value="on"';
615 echo ' />' . "\n";
617 echo ' <input type="checkbox" class="checkbox_null" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
618 . ' name="fields_null' . $field_name_appendix . '"';
619 if ($real_null_value && !$field['first_timestamp']) {
620 echo ' checked="checked"';
622 echo ' id="field_' . ($idindex) . '_2" />';
624 // nullify_code is needed by the js nullify() function
625 if (strstr($field['True_Type'], 'enum')) {
626 if (strlen($field['Type']) > 20) {
627 $nullify_code = '1';
628 } else {
629 $nullify_code = '2';
631 } elseif (strstr($field['True_Type'], 'set')) {
632 $nullify_code = '3';
633 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
634 // foreign key in a drop-down
635 $nullify_code = '4';
636 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
637 // foreign key with a browsing icon
638 $nullify_code = '6';
639 } else {
640 $nullify_code = '5';
642 // to be able to generate calls to nullify() in jQuery
643 echo '<input type="hidden" class="nullify_code" name="nullify_code' . $field_name_appendix . '" value="' . $nullify_code . '" />';
644 echo '<input type="hidden" class="hashed_field" name="hashed_field' . $field_name_appendix . '" value="' . $field['Field_md5'] . '" />';
645 echo '<input type="hidden" class="multi_edit" name="multi_edit' . $field_name_appendix . '" value="' . PMA_escapeJsString($vkey) . '" />';
647 echo ' </td>' . "\n";
649 // The value column (depends on type)
650 // ----------------
651 // See bug #1667887 for the reason why we don't use the maxlength
652 // HTML attribute
654 echo ' <td>' . "\n";
655 if ($foreignData['foreign_link'] == true) {
656 echo $backup_field . "\n";
658 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
659 value="foreign" />
660 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
661 value="" id="field_<?php echo ($idindex); ?>_3A" />
662 <input type="text" name="field_<?php echo $field_name_appendix_md5; ?>"
663 class="textfield" <?php echo $unnullify_trigger; ?>
664 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
665 id="field_<?php echo ($idindex); ?>_3"
666 value="<?php echo htmlspecialchars($data); ?>" />
667 <script type="text/javascript">
668 //<![CDATA[
669 document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
670 document.write(' href="browse_foreigners.php?');
671 document.write('<?php echo PMA_generate_common_url($db, $table); ?>');
672 document.writeln('&amp;field=<?php echo PMA_escapeJsString(urlencode($field['Field']) . $browse_foreigners_uri); ?>">');
673 document.writeln('<?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
674 //]]>
675 </script>
676 <?php
677 } elseif (is_array($foreignData['disp_row'])) {
678 echo $backup_field . "\n";
680 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
681 value="foreign" />
682 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
683 value="" id="field_<?php echo $idindex; ?>_3A" />
684 <select name="field_<?php echo $field_name_appendix_md5; ?>"
685 <?php echo $unnullify_trigger; ?>
686 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
687 id="field_<?php echo ($idindex); ?>_3">
688 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
689 </select>
690 <?php
691 // still needed? :
692 unset($foreignData['disp_row']);
693 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
695 &nbsp;</td>
696 </tr>
697 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
698 <td colspan="5" align="right">
699 <?php echo $backup_field . "\n"; ?>
700 <textarea name="fields<?php echo $field_name_appendix; ?>"
701 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
702 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
703 dir="<?php echo $text_dir; ?>"
704 id="field_<?php echo ($idindex); ?>_3"
705 <?php echo $unnullify_trigger; ?>
706 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
707 ><?php echo $special_chars_encoded; ?></textarea>
708 <?php
709 } elseif (strstr($field['pma_type'], 'text')) {
710 echo $backup_field . "\n";
712 <textarea name="fields<?php echo $field_name_appendix; ?>"
713 rows="<?php echo $cfg['TextareaRows']; ?>"
714 cols="<?php echo $cfg['TextareaCols']; ?>"
715 dir="<?php echo $text_dir; ?>"
716 id="field_<?php echo ($idindex); ?>_3"
717 <?php echo $unnullify_trigger; ?>
718 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
719 ><?php echo $special_chars_encoded; ?></textarea>
720 <?php
721 echo "\n";
722 if (strlen($special_chars) > 32000) {
723 echo " </td>\n";
724 echo ' <td>' . __(' Because of its length,<br /> this column might not be editable ');
726 } elseif ($field['pma_type'] == 'enum') {
727 if (! isset($table_fields[$i]['values'])) {
728 $table_fields[$i]['values'] = array();
729 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
730 // Removes automatic MySQL escape format
731 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
732 $table_fields[$i]['values'][] = array(
733 'plain' => $val,
734 'html' => htmlspecialchars($val),
738 $field_enum_values = $table_fields[$i]['values'];
740 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
741 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
742 <?php
743 echo "\n" . ' ' . $backup_field . "\n";
745 // show dropdown or radio depend on length
746 if (strlen($field['Type']) > 20) {
748 <select name="field_<?php echo $field_name_appendix_md5; ?>"
749 <?php echo $unnullify_trigger; ?>
750 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
751 id="field_<?php echo ($idindex); ?>_3">
752 <option value="">&nbsp;</option>
753 <?php
754 echo "\n";
756 foreach ($field_enum_values as $enum_value) {
757 echo ' ';
758 echo '<option value="' . $enum_value['html'] . '"';
759 if ($data == $enum_value['plain']
760 || ($data == ''
761 && (! isset($where_clause) || $field['Null'] != 'YES')
762 && isset($field['Default'])
763 && $enum_value['plain'] == $field['Default'])) {
764 echo ' selected="selected"';
766 echo '>' . $enum_value['html'] . '</option>' . "\n";
767 } // end for
770 </select>
771 <?php
772 } else {
773 $j = 0;
774 foreach ($field_enum_values as $enum_value) {
775 echo ' ';
776 echo '<input type="radio" name="field_' . $field_name_appendix_md5 . '"';
777 echo ' value="' . $enum_value['html'] . '"';
778 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
779 echo $unnullify_trigger;
780 if ($data == $enum_value['plain']
781 || ($data == ''
782 && (! isset($where_clause) || $field['Null'] != 'YES')
783 && isset($field['Default'])
784 && $enum_value['plain'] == $field['Default'])) {
785 echo ' checked="checked"';
787 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
788 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
789 . $enum_value['html'] . '</label>' . "\n";
790 $j++;
791 } // end for
792 } // end else
793 } elseif ($field['pma_type'] == 'set') {
794 if (! isset($table_fields[$i]['values'])) {
795 $table_fields[$i]['values'] = array();
796 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
797 $table_fields[$i]['values'][] = array(
798 'plain' => $val,
799 'html' => htmlspecialchars($val),
802 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
804 $field_set_values = $table_fields[$i]['values'];
805 $select_size = $table_fields[$i]['select_size'];
807 $vset = array_flip(explode(',', $data));
808 echo $backup_field . "\n";
810 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
811 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
812 <select name="field_<?php echo $field_name_appendix_md5; ?>"
813 size="<?php echo $select_size; ?>"
814 multiple="multiple" <?php echo $unnullify_trigger; ?>
815 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
816 id="field_<?php echo ($idindex); ?>_3">
817 <?php
818 foreach ($field_set_values as $field_set_value) {
819 echo ' ';
820 echo '<option value="' . $field_set_value['html'] . '"';
821 if (isset($vset[$field_set_value['plain']])) {
822 echo ' selected="selected"';
824 echo '>' . $field_set_value['html'] . '</option>' . "\n";
825 } // end for
827 </select>
828 <?php
830 // We don't want binary data destroyed
831 elseif ($field['is_binary'] || $field['is_blob']) {
832 if (($cfg['ProtectBinary'] && $field['is_blob'])
833 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
834 echo "\n";
835 // for blobstreaming
836 if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
838 echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_md5'] . $vkey . '" value="' . $data . '" />';
839 echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . __('Remove BLOB Repository Reference') . "<br />";
840 echo PMA_BS_CreateReferenceLink($data, $db);
841 echo "<br />";
843 else
845 echo __('Binary - do not edit');
846 if (isset($data)) {
847 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
848 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
849 unset($data_size);
851 echo "\n";
852 } // end if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
854 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
855 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
856 <?php
857 } elseif ($field['is_blob']) {
858 echo "\n";
859 echo $backup_field . "\n";
861 <textarea name="fields<?php echo $field_name_appendix; ?>"
862 rows="<?php echo $cfg['TextareaRows']; ?>"
863 cols="<?php echo $cfg['TextareaCols']; ?>"
864 dir="<?php echo $text_dir; ?>"
865 id="field_<?php echo ($idindex); ?>_3"
866 <?php echo $unnullify_trigger; ?>
867 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
868 ><?php echo $special_chars_encoded; ?></textarea>
869 <?php
871 } else {
872 // field size should be at least 4 and max 40
873 $fieldsize = min(max($field['len'], 4), 40);
874 echo "\n";
875 echo $backup_field . "\n";
877 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
878 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
879 class="textfield" <?php echo $unnullify_trigger; ?>
880 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
881 id="field_<?php echo ($idindex); ?>_3" />
882 <?php
883 } // end if...elseif...else
885 // Upload choice (only for BLOBs because the binary
886 // attribute does not imply binary contents)
887 // (displayed whatever value the ProtectBinary has)
889 if ($is_upload && $field['is_blob']) {
890 // check if field type is of longblob and if the table is PBMS enabled.
891 if (($field['pma_type'] == "longblob") && PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type)) {
892 echo '<br />';
893 echo '<input type="checkbox" name="upload_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . __('Upload to BLOB repository');
896 echo '<br />';
897 echo '<input type="file" name="fields_upload_' . $field['Field_md5'] . $vkey . '" class="textfield" id="field_' . $idindex . '_3" size="10" ' . $unnullify_trigger . '/>&nbsp;';
899 // find maximum upload size, based on field type
901 * @todo with functions this is not so easy, as you can basically
902 * process any data with function like MD5
904 $max_field_sizes = array(
905 'tinyblob' => '256',
906 'blob' => '65536',
907 'mediumblob' => '16777216',
908 'longblob' => '4294967296'); // yeah, really
910 $this_field_max_size = $max_upload_size; // from PHP max
911 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
912 $this_field_max_size = $max_field_sizes[$field['pma_type']];
914 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
915 // do not generate here the MAX_FILE_SIZE, because we should
916 // put only one in the form to accommodate the biggest field
917 if ($this_field_max_size > $biggest_max_file_size) {
918 $biggest_max_file_size = $this_field_max_size;
922 if (!empty($cfg['UploadDir'])) {
923 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
924 if ($files === FALSE) {
925 echo ' <font color="red">' . __('Error') . '</font><br />' . "\n";
926 echo ' ' . __('The directory you set for upload work cannot be reached') . "\n";
927 } elseif (!empty($files)) {
928 echo "<br />\n";
929 echo ' <i>' . __('Or') . '</i>' . ' ' . __('web server upload directory') . ':<br />' . "\n";
930 echo ' <select size="1" name="fields_uploadlocal_' . $field['Field_md5'] . $vkey . '">' . "\n";
931 echo ' <option value="" selected="selected"></option>' . "\n";
932 echo $files;
933 echo ' </select>' . "\n";
935 } // end if (web-server upload directory)
936 } // end elseif (binary or blob)
937 else {
938 // field size should be at least 4 and max 40
939 $fieldsize = min(max($field['len'], 4), 40);
940 echo $backup_field . "\n";
941 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== FALSE)) {
942 echo "\n";
944 <textarea name="fields<?php echo $field_name_appendix; ?>"
945 rows="<?php echo $cfg['CharTextareaRows']; ?>"
946 cols="<?php echo $cfg['CharTextareaCols']; ?>"
947 dir="<?php echo $text_dir; ?>"
948 id="field_<?php echo ($idindex); ?>_3"
949 <?php echo $unnullify_trigger; ?>
950 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
951 ><?php echo $special_chars_encoded; ?></textarea>
952 <?php
953 } else {
955 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
956 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
957 class="textfield" <?php echo $unnullify_trigger; ?>
958 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
959 id="field_<?php echo ($idindex); ?>_3" />
960 <?php
961 if ($field['Extra'] == 'auto_increment') {
963 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
964 <?php
965 } // end if
966 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
968 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
969 <?php
971 if (substr($field['pma_type'], 0, 8) == 'datetime') {
973 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="datetime" />
974 <?php
976 if ($field['True_Type'] == 'bit') {
978 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
979 <?php
981 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
982 // the _3 suffix points to the date field
983 // the _2 suffix points to the corresponding NULL checkbox
984 // in dateFormat, 'yy' means the year with 4 digits
986 <script type="text/javascript">
987 //<![CDATA[
988 $(function() {
989 $('#field_<?php echo ($idindex); ?>_3').datepicker({
990 duration: '',
991 time24h: true,
992 stepMinutes: 1,
993 stepHours: 1,
994 <?php echo ($field['pma_type'] == 'date' ? "showTime: false,":"showTime: true,"); ?>
995 dateFormat: 'yy-mm-dd',
996 altTimeField: '',
997 constrainInput: false
1000 //]]>
1001 </script>
1002 <?php
1007 </td>
1008 </tr>
1009 <?php
1010 $odd_row = !$odd_row;
1011 } // end for
1012 $o_rows++;
1013 echo ' </tbody></table><br />';
1014 } // end foreach on multi-edit
1016 <br />
1018 <fieldset>
1019 <table border="0" cellpadding="5" cellspacing="0">
1020 <tr>
1021 <td valign="middle" nowrap="nowrap">
1022 <select name="submit_type" class="control_at_footer" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
1023 <?php
1024 if (isset($where_clause)) {
1026 <option value="save"><?php echo __('Save'); ?></option>
1027 <?php
1030 <option value="insert"><?php echo __('Insert as new row'); ?></option>
1031 <option value="insertignore"><?php echo __('Insert as new row and ignore errors'); ?></option>
1032 <option value="showinsert"><?php echo __('Show insert query'); ?></option>
1033 </select>
1034 <?php
1035 echo "\n";
1037 if (!isset($after_insert)) {
1038 $after_insert = 'back';
1041 </td>
1042 <td valign="middle">
1043 &nbsp;&nbsp;&nbsp;<strong><?php echo __('and then'); ?></strong>&nbsp;&nbsp;&nbsp;
1044 </td>
1045 <td valign="middle" nowrap="nowrap">
1046 <select name="after_insert">
1047 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to previous page'); ?></option>
1048 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Insert another new row'); ?></option>
1049 <?php
1050 if (isset($where_clause)) {
1052 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to this page'); ?></option>
1053 <?php
1054 // If we have just numeric primary key, we can also edit next
1055 // in 2.8.2, we were looking for `field_name` = numeric_value
1056 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1057 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1058 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause)) {
1060 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo __('Edit next row'); ?></option>
1061 <?php
1065 </select>
1066 </td>
1067 </tr>
1069 <tr>
1070 <td>
1071 <?php echo PMA_showHint(__('Use TAB key to move from value to value, or CTRL+arrows to move anywhere')); ?>
1072 </td>
1073 <td colspan="3" align="right" valign="middle">
1074 <input type="submit" class="control_at_footer" value="<?php echo __('Go'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1075 <input type="reset" class="control_at_footer" value="<?php echo __('Reset'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1076 </td>
1077 </tr>
1078 </table>
1079 </fieldset>
1080 <?php if ($biggest_max_file_size > 0) {
1081 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1082 } ?>
1083 </form>
1084 <?php
1085 if ($insert_mode) {
1087 <!-- Continue insertion form -->
1088 <form id="continueForm" method="post" action="tbl_replace.php" name="continueForm" >
1089 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1090 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1091 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
1092 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
1093 <?php
1094 if (isset($where_clauses)) {
1095 foreach ($where_clause_array as $key_id => $where_clause) {
1096 echo '<input type="hidden" name="where_clause[' . $key_id . ']" value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n";
1099 $tmp = '<select name="insert_rows" id="insert_rows">' . "\n";
1100 $option_values = array(1,2,5,10,15,20,30,40);
1101 foreach ($option_values as $value) {
1102 $tmp .= '<option value="' . $value . '"';
1103 if ($value == $cfg['InsertRows']) {
1104 $tmp .= ' selected="selected"';
1106 $tmp .= '>' . $value . '</option>' . "\n";
1108 $tmp .= '</select>' . "\n";
1109 echo "\n" . sprintf(__('Continue insertion with %s rows'), $tmp);
1110 unset($tmp);
1111 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>' . "\n";
1112 echo '</form>' . "\n";
1116 * Displays the footer
1118 require './libraries/footer.inc.php';