Translation update done using Pootle.
[phpmyadmin/ammaryasirr.git] / tbl_change.php
blob8befabb7f2b68e8331d4d82d540409affbfac444
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 require_once './libraries/data_mysql.inc.php';
25 /**
26 * Sets global variables.
27 * Here it's better to use a if, instead of the '?' operator
28 * to avoid setting a variable to '' when it's not present in $_REQUEST
30 if (isset($_REQUEST['where_clause'])) {
31 $where_clause = $_REQUEST['where_clause'];
33 if (isset($_REQUEST['clause_is_unique'])) {
34 $clause_is_unique = $_REQUEST['clause_is_unique'];
36 if (isset($_SESSION['edit_next'])) {
37 $where_clause = $_SESSION['edit_next'];
38 unset($_SESSION['edit_next']);
39 $after_insert = 'edit_next';
41 if (isset($_REQUEST['sql_query'])) {
42 $sql_query = $_REQUEST['sql_query'];
44 if (isset($_REQUEST['ShowFunctionFields'])) {
45 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
47 if (isset($_REQUEST['ShowFieldTypesInDataEditView'])) {
48 $cfg['ShowFieldTypesInDataEditView'] = $_REQUEST['ShowFieldTypesInDataEditView'];
50 if (isset($_REQUEST['default_action'])) {
51 $default_action = $_REQUEST['default_action'];
54 /**
55 * file listing
57 require_once './libraries/file_listing.php';
60 /**
61 * Defines the url to return to in case of error in a sql statement
62 * (at this point, $GLOBALS['goto'] will be set but could be empty)
64 if (empty($GLOBALS['goto'])) {
65 if (strlen($table)) {
66 // avoid a problem (see bug #2202709)
67 $GLOBALS['goto'] = 'tbl_sql.php';
68 } else {
69 $GLOBALS['goto'] = 'db_sql.php';
72 /**
73 * @todo check if we could replace by "db_|tbl_" - please clarify!?
75 $_url_params = array(
76 'db' => $db,
77 'sql_query' => $sql_query
80 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
81 $_url_params['table'] = $table;
84 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
85 unset($_url_params);
88 /**
89 * Sets parameters for links
90 * where is this variable used?
91 * replace by PMA_generate_common_url($url_params);
93 $url_query = PMA_generate_common_url($url_params, 'html', '');
95 /**
96 * get table information
97 * @todo should be done by a Table object
99 require_once './libraries/tbl_info.inc.php';
102 * Get comments for table fileds/columns
104 $comments_map = array();
106 if ($GLOBALS['cfg']['ShowPropertyComments']) {
107 $comments_map = PMA_getComments($db, $table);
111 * START REGULAR OUTPUT
115 * used in ./libraries/header.inc.php to load JavaScript library file
117 $GLOBALS['js_include'][] = 'functions.js';
118 $GLOBALS['js_include'][] = 'tbl_change.js';
119 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
120 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
122 * HTTP and HTML headers
124 require_once './libraries/header.inc.php';
127 * Displays the query submitted and its result
129 * @todo where does $disp_message and $disp_query come from???
131 if (! empty($disp_message)) {
132 if (! isset($disp_query)) {
133 $disp_query = null;
135 PMA_showMessage($disp_message, $disp_query);
139 * Displays top menu links
141 require_once './libraries/tbl_links.inc.php';
145 * Get the analysis of SHOW CREATE TABLE for this table
146 * @todo should be handled by class Table
148 $show_create_table = PMA_DBI_fetch_value(
149 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
150 0, 1);
151 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
152 unset($show_create_table);
155 * Get the list of the fields of the current table
157 PMA_DBI_select_db($db);
158 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
159 null, null, null, PMA_DBI_QUERY_STORE);
160 $rows = array();
161 if (isset($where_clause)) {
162 // when in edit mode load all selected rows from table
163 $insert_mode = false;
164 if (is_array($where_clause)) {
165 $where_clause_array = $where_clause;
166 } else {
167 $where_clause_array = array(0 => $where_clause);
170 $result = array();
171 $found_unique_key = false;
172 $where_clauses = array();
174 foreach ($where_clause_array as $key_id => $where_clause) {
175 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';';
176 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
177 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
178 $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
180 // No row returned
181 if (! $rows[$key_id]) {
182 unset($rows[$key_id], $where_clause_array[$key_id]);
183 PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query);
184 echo "\n";
185 require './libraries/footer.inc.php';
186 } else { // end if (no row returned)
187 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
188 list($unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true);
189 if (! empty($unique_condition)) {
190 $found_unique_key = true;
192 unset($unique_condition, $tmp_clause_is_unique);
196 } else {
197 // no primary key given, just load first row - but what happens if table is empty?
198 $insert_mode = true;
199 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
200 $rows = array_fill(0, $cfg['InsertRows'], false);
203 // Copying a row - fetched data will be inserted as a new row, therefore the where clause is needless.
204 if (isset($default_action) && $default_action === 'insert') {
205 unset($where_clause, $where_clauses);
208 // retrieve keys into foreign fields, if any
209 $foreigners = PMA_getForeigners($db, $table);
213 * Displays the form
215 // autocomplete feature of IE kills the "onchange" event handler and it
216 // must be replaced by the "onpropertychange" one in this case
217 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7)
218 ? 'onpropertychange'
219 : 'onchange';
220 // Had to put the URI because when hosted on an https server,
221 // some browsers send wrongly this form to the http server.
224 <!-- Set on key handler for moving using by Ctrl+arrows -->
225 <script src="./js/keyhandler.js" type="text/javascript"></script>
226 <script type="text/javascript">
227 //<![CDATA[
228 var switch_movement = 0;
229 document.onkeydown = onKeyDownArrowsHandler;
230 //]]>
231 </script>
232 <?php
234 $_form_params = array(
235 'db' => $db,
236 'table' => $table,
237 'goto' => $GLOBALS['goto'],
238 'err_url' => $err_url,
239 'sql_query' => $sql_query,
241 if (isset($where_clauses)) {
242 foreach ($where_clause_array as $key_id => $where_clause) {
243 $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
246 if (isset($clause_is_unique)) {
247 $_form_params['clause_is_unique'] = $clause_is_unique;
252 <!-- Insert/Edit form -->
253 <form id="insertForm" method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
254 <?php
255 echo PMA_generate_common_hidden_inputs($_form_params);
257 $titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
259 // Set if we passed the first timestamp field
260 $timestamp_seen = 0;
261 $fields_cnt = count($table_fields);
263 $tabindex = 0;
264 $tabindex_for_function = +3000;
265 $tabindex_for_null = +6000;
266 $tabindex_for_value = 0;
267 $o_rows = 0;
268 $biggest_max_file_size = 0;
270 // user can toggle the display of Function column
271 // (currently does not work for multi-edits)
272 $url_params['db'] = $db;
273 $url_params['table'] = $table;
274 if (isset($where_clause)) {
275 $url_params['where_clause'] = trim($where_clause);
277 if (! empty($sql_query)) {
278 $url_params['sql_query'] = $sql_query;
281 if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) {
282 echo __('Show');
284 if (! $cfg['ShowFunctionFields']) {
285 $this_url_params = array_merge($url_params,
286 array('ShowFunctionFields' => 1, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
287 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . __('Function') . '</a>' . "\n";
289 if (! $cfg['ShowFieldTypesInDataEditView']) {
290 $this_other_url_params = array_merge($url_params,
291 array('ShowFieldTypesInDataEditView' => 1, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
292 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_other_url_params) . '">' . __('Type') . '</a>' . "\n";
295 foreach ($rows as $row_id => $vrow) {
296 if ($vrow === false) {
297 unset($vrow);
300 $jsvkey = $row_id;
301 $rownumber_param = '&amp;rownumber=' . $row_id;
302 $vkey = '[multi_edit][' . $jsvkey . ']';
304 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ? $result[$row_id] : $result);
305 if ($insert_mode && $row_id > 0) {
306 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_' . $row_id . '" />';
307 echo '<label for="insert_ignore_' . $row_id . '">' . __('Ignore') . '</label><br />' . "\n";
310 <table class="insertRowTable">
311 <thead>
312 <tr>
313 <th><?php echo __('Column'); ?></th>
315 <?php
316 if ($cfg['ShowFieldTypesInDataEditView']) {
317 $this_url_params = array_merge($url_params,
318 array('ShowFieldTypesInDataEditView' => 0, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
319 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Type') . '</a></th>' . "\n";
322 if ($cfg['ShowFunctionFields']) {
323 $this_url_params = array_merge($url_params,
324 array('ShowFunctionFields' => 0, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
325 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Function') . '</a></th>' . "\n";
328 <th><?php echo __('Null'); ?></th>
329 <th><?php echo __('Value'); ?></th>
330 </tr>
331 </thead>
332 <tfoot>
333 <tr>
334 <th colspan="5" align="right" class="tblFooters">
335 <input type="submit" value="<?php echo __('Go'); ?>" />
336 </th>
337 </tr>
338 </tfoot>
339 <tbody>
340 <?php
341 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
342 $m_rows = $o_rows + 1;
344 $odd_row = true;
345 for ($i = 0; $i < $fields_cnt; $i++) {
346 if (! isset($table_fields[$i]['processed'])) {
347 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
348 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
349 // True_Type contains only the type (stops at first bracket)
350 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
352 // d a t e t i m e
354 // Current date should not be set as default if the field is NULL
355 // for the current row, but do not put here the current datetime
356 // if there is a default value (the real default value will be set
357 // in the Default value logic below)
359 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
360 // $field['Default'] is not set if it contains NULL:
361 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
362 // but, look what we get if we switch to iso: (Default is NULL)
363 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
364 // so I force a NULL into it (I don't think it's possible
365 // to have an empty default value for DATETIME)
366 // then, the "if" after this one will work
367 if ($table_fields[$i]['Type'] == 'datetime'
368 && ! isset($table_fields[$i]['Default'])
369 && isset($table_fields[$i]['Null'])
370 && $table_fields[$i]['Null'] == 'YES') {
371 $table_fields[$i]['Default'] = null;
374 $table_fields[$i]['len'] =
375 preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1;
378 if (isset($comments_map[$table_fields[$i]['Field']])) {
379 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
380 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
381 . $table_fields[$i]['Field_html'] . '</span>';
382 } else {
383 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
386 // The type column.
387 // Fix for bug #3152931 'ENUM and SET cannot have "Binary" option'
388 // If check to ensure types such as "enum('one','two','binary',..)" or
389 // "enum('one','two','varbinary',..)" are not categorized as binary.
390 if (stripos($table_fields[$i]['Type'], 'binary') === 0
391 || stripos($table_fields[$i]['Type'], 'varbinary') === 0) {
392 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
393 } else {
394 $table_fields[$i]['is_binary'] = false;
397 // If check to ensure types such as "enum('one','two','blob',..)" or
398 // "enum('one','two','tinyblob',..)" etc. are not categorized as blob.
399 if (stripos($table_fields[$i]['Type'], 'blob') === 0
400 || stripos($table_fields[$i]['Type'], 'tinyblob') === 0
401 || stripos($table_fields[$i]['Type'], 'mediumblob') === 0
402 || stripos($table_fields[$i]['Type'], 'longblob') === 0) {
403 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
404 } else {
405 $table_fields[$i]['is_blob'] = false;
408 // If check to ensure types such as "enum('one','two','char',..)" or
409 // "enum('one','two','varchar',..)" are not categorized as char.
410 if (stripos($table_fields[$i]['Type'], 'char') === 0
411 || stripos($table_fields[$i]['Type'], 'varchar') === 0) {
412 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
413 } else {
414 $table_fields[$i]['is_char'] = false;
417 $table_fields[$i]['first_timestamp'] = false;
418 switch ($table_fields[$i]['True_Type']) {
419 case 'set':
420 $table_fields[$i]['pma_type'] = 'set';
421 $table_fields[$i]['wrap'] = '';
422 break;
423 case 'enum':
424 $table_fields[$i]['pma_type'] = 'enum';
425 $table_fields[$i]['wrap'] = '';
426 break;
427 case 'timestamp':
428 if (!$timestamp_seen) { // can only occur once per table
429 $timestamp_seen = 1;
430 $table_fields[$i]['first_timestamp'] = true;
432 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
433 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
434 break;
436 default:
437 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
438 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
439 break;
442 $field = $table_fields[$i];
443 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
445 if (-1 === $field['len']) {
446 $field['len'] = PMA_DBI_field_len($vresult, $i);
448 //Call validation when the form submited...
449 $unnullify_trigger = $chg_evt_handler . "=\"return verificationsAfterFieldChange('". PMA_escapeJsString($field['Field_md5']) . "', '"
450 . PMA_escapeJsString($jsvkey) . "','".$field['pma_type']."')\"";
452 // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
453 $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
455 if ($field['Type'] == 'datetime'
456 && ! isset($field['Default'])
457 && ! is_null($field['Default'])
458 && ($insert_mode || ! isset($vrow[$field['Field']]))) {
459 // INSERT case or
460 // UPDATE case with an NULL value
461 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
464 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; ?>">
465 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center">
466 <?php echo $field['Field_title']; ?>
467 <input type="hidden" name="fields_name<?php echo $field_name_appendix; ?>" value="<?php echo $field['Field_html']; ?>"/>
468 </td>
469 <?php if ($cfg['ShowFieldTypesInDataEditView']) { ?>
470 <td align="center"<?php echo $field['wrap']; ?>><span class="column_type"><?php echo $field['pma_type']; ?></span>
471 </td>
473 <?php } //End if
475 // Prepares the field value
476 $real_null_value = false;
477 $special_chars_encoded = '';
478 if (isset($vrow)) {
479 // (we are editing)
480 if (is_null($vrow[$field['Field']])) {
481 $real_null_value = true;
482 $vrow[$field['Field']] = '';
483 $special_chars = '';
484 $data = $vrow[$field['Field']];
485 } elseif ($field['True_Type'] == 'bit') {
486 $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
487 } else {
488 // special binary "characters"
489 if ($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) {
490 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
491 $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]);
492 $field['display_binary_as_hex'] = true;
493 } else {
494 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
496 } // end if
497 $special_chars = htmlspecialchars($vrow[$field['Field']]);
499 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
500 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
502 $data = $vrow[$field['Field']];
503 } // end if... else...
505 //when copying row, it is useful to empty auto-increment column to prevent duplicate key error
506 if (isset($default_action) && $default_action === 'insert') {
507 if ($field['Key'] === 'PRI' && strpos($field['Extra'], 'auto_increment') !== false) {
508 $data = $special_chars_encoded = $special_chars = null;
511 // If a timestamp field value is not included in an update
512 // statement MySQL auto-update it to the current timestamp;
513 // however, things have changed since MySQL 4.1, so
514 // it's better to set a fields_prev in this situation
515 $backup_field = '<input type="hidden" name="fields_prev'
516 . $field_name_appendix . '" value="'
517 . htmlspecialchars($vrow[$field['Field']]) . '" />';
518 } else {
519 // (we are inserting)
520 // display default values
521 if (! isset($field['Default'])) {
522 $field['Default'] = '';
523 $real_null_value = true;
524 $data = '';
525 } else {
526 $data = $field['Default'];
528 if ($field['True_Type'] == 'bit') {
529 $special_chars = PMA_convert_bit_default_value($field['Default']);
530 } else {
531 $special_chars = htmlspecialchars($field['Default']);
533 $backup_field = '';
534 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
535 // this will select the UNHEX function while inserting
536 if (($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) && $_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
537 $field['display_binary_as_hex'] = true;
541 $idindex = ($o_rows * $fields_cnt) + $i + 1;
542 $tabindex = $idindex;
544 // Get a list of data types that are not yet supported.
545 $no_support_types = PMA_unsupportedDatatypes();
547 // The function column
548 // -------------------
549 // We don't want binary data to be destroyed
550 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
551 // stored or retrieved" so it does not mean that the contents is
552 // binary
553 if ($cfg['ShowFunctionFields']) {
554 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
555 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
556 echo ' <td align="center">' . __('Binary') . '</td>' . "\n";
557 } elseif (strstr($field['True_Type'], 'enum') || strstr($field['True_Type'], 'set') || in_array($field['pma_type'], $no_support_types)) {
558 echo ' <td align="center">--</td>' . "\n";
559 } else {
561 <td>
562 <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">
563 <?php
564 echo PMA_getFunctionsForField($field, $insert_mode);
566 </select>
567 </td>
568 <?php
570 } // end if ($cfg['ShowFunctionFields'])
573 // The null column
574 // ---------------
575 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
576 echo ' <td>' . "\n";
577 if ($field['Null'] == 'YES') {
578 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
579 if ($real_null_value && !$field['first_timestamp']) {
580 echo ' value="on"';
582 echo ' />' . "\n";
584 echo ' <input type="checkbox" class="checkbox_null" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
585 . ' name="fields_null' . $field_name_appendix . '"';
586 if ($real_null_value && !$field['first_timestamp']) {
587 echo ' checked="checked"';
589 echo ' id="field_' . ($idindex) . '_2" />';
591 // nullify_code is needed by the js nullify() function
592 if (strstr($field['True_Type'], 'enum')) {
593 if (strlen($field['Type']) > 20) {
594 $nullify_code = '1';
595 } else {
596 $nullify_code = '2';
598 } elseif (strstr($field['True_Type'], 'set')) {
599 $nullify_code = '3';
600 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
601 // foreign key in a drop-down
602 $nullify_code = '4';
603 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
604 // foreign key with a browsing icon
605 $nullify_code = '6';
606 } else {
607 $nullify_code = '5';
609 // to be able to generate calls to nullify() in jQuery
610 echo '<input type="hidden" class="nullify_code" name="nullify_code' . $field_name_appendix . '" value="' . $nullify_code . '" />';
611 echo '<input type="hidden" class="hashed_field" name="hashed_field' . $field_name_appendix . '" value="' . $field['Field_md5'] . '" />';
612 echo '<input type="hidden" class="multi_edit" name="multi_edit' . $field_name_appendix . '" value="' . PMA_escapeJsString($vkey) . '" />';
614 echo ' </td>' . "\n";
616 // The value column (depends on type)
617 // ----------------
618 // See bug #1667887 for the reason why we don't use the maxlength
619 // HTML attribute
621 echo ' <td>' . "\n";
622 // Will be used by js/tbl_change.js to set the default value
623 // for the "Continue insertion" feature
624 echo '<span class="default_value hide">' . $special_chars . '</span>';
625 if ($foreignData['foreign_link'] == true) {
626 echo $backup_field . "\n";
628 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
629 value="foreign" />
630 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
631 class="textfield" <?php echo $unnullify_trigger; ?>
632 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
633 id="field_<?php echo ($idindex); ?>_3"
634 value="<?php echo htmlspecialchars($data); ?>" />
635 <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>
636 <?php
637 } elseif (is_array($foreignData['disp_row'])) {
638 echo $backup_field . "\n";
640 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
641 value="foreign" />
642 <select name="fields<?php echo $field_name_appendix; ?>"
643 <?php echo $unnullify_trigger; ?>
644 class="textfield"
645 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
646 id="field_<?php echo ($idindex); ?>_3">
647 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
648 </select>
649 <?php
650 // still needed? :
651 unset($foreignData['disp_row']);
652 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
654 &nbsp;</td>
655 </tr>
656 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
657 <td colspan="5" align="right">
658 <?php echo $backup_field . "\n"; ?>
659 <textarea name="fields<?php echo $field_name_appendix; ?>"
660 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
661 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
662 dir="<?php echo $text_dir; ?>"
663 id="field_<?php echo ($idindex); ?>_3"
664 <?php echo $unnullify_trigger; ?>
665 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
666 ><?php echo $special_chars_encoded; ?></textarea>
667 <?php
668 } elseif (strstr($field['pma_type'], 'text')) {
669 echo $backup_field . "\n";
671 <textarea name="fields<?php echo $field_name_appendix; ?>"
672 rows="<?php echo $cfg['TextareaRows']; ?>"
673 cols="<?php echo $cfg['TextareaCols']; ?>"
674 dir="<?php echo $text_dir; ?>"
675 id="field_<?php echo ($idindex); ?>_3"
676 <?php echo $unnullify_trigger; ?>
677 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
678 ><?php echo $special_chars_encoded; ?></textarea>
679 <?php
680 echo "\n";
681 if (strlen($special_chars) > 32000) {
682 echo " </td>\n";
683 echo ' <td>' . __('Because of its length,<br /> this column might not be editable');
685 } elseif ($field['pma_type'] == 'enum') {
686 if (! isset($table_fields[$i]['values'])) {
687 $table_fields[$i]['values'] = array();
688 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
689 // Removes automatic MySQL escape format
690 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
691 $table_fields[$i]['values'][] = array(
692 'plain' => $val,
693 'html' => htmlspecialchars($val),
697 $field_enum_values = $table_fields[$i]['values'];
699 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
700 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
701 <?php
702 echo "\n" . ' ' . $backup_field . "\n";
704 // show dropdown or radio depend on length
705 if (strlen($field['Type']) > 20) {
707 <select name="fields<?php echo $field_name_appendix; ?>"
708 <?php echo $unnullify_trigger; ?>
709 class="textfield"
710 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
711 id="field_<?php echo ($idindex); ?>_3">
712 <option value="">&nbsp;</option>
713 <?php
714 echo "\n";
716 foreach ($field_enum_values as $enum_value) {
717 echo ' ';
718 echo '<option value="' . $enum_value['html'] . '"';
719 if ($data == $enum_value['plain']
720 || ($data == ''
721 && (! isset($where_clause) || $field['Null'] != 'YES')
722 && isset($field['Default'])
723 && $enum_value['plain'] == $field['Default'])) {
724 echo ' selected="selected"';
726 echo '>' . $enum_value['html'] . '</option>' . "\n";
727 } // end for
730 </select>
731 <?php
732 } else {
733 $j = 0;
734 foreach ($field_enum_values as $enum_value) {
735 echo ' ';
736 echo '<input type="radio" name="fields' . $field_name_appendix . '"';
737 echo ' class="textfield"';
738 echo ' value="' . $enum_value['html'] . '"';
739 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
740 echo $unnullify_trigger;
741 if ($data == $enum_value['plain']
742 || ($data == ''
743 && (! isset($where_clause) || $field['Null'] != 'YES')
744 && isset($field['Default'])
745 && $enum_value['plain'] == $field['Default'])) {
746 echo ' checked="checked"';
748 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
749 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
750 . $enum_value['html'] . '</label>' . "\n";
751 $j++;
752 } // end for
753 } // end else
754 } elseif ($field['pma_type'] == 'set') {
755 if (! isset($table_fields[$i]['values'])) {
756 $table_fields[$i]['values'] = array();
757 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
758 $table_fields[$i]['values'][] = array(
759 'plain' => $val,
760 'html' => htmlspecialchars($val),
763 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
765 $field_set_values = $table_fields[$i]['values'];
766 $select_size = $table_fields[$i]['select_size'];
768 $vset = array_flip(explode(',', $data));
769 echo $backup_field . "\n";
771 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
772 <select name="fields<?php echo $field_name_appendix . '[]'; ?>"
773 class="textfield"
774 size="<?php echo $select_size; ?>"
775 multiple="multiple" <?php echo $unnullify_trigger; ?>
776 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
777 id="field_<?php echo ($idindex); ?>_3">
778 <?php
779 foreach ($field_set_values as $field_set_value) {
780 echo ' ';
781 echo '<option value="' . $field_set_value['html'] . '"';
782 if (isset($vset[$field_set_value['plain']])) {
783 echo ' selected="selected"';
785 echo '>' . $field_set_value['html'] . '</option>' . "\n";
786 } // end for
788 </select>
789 <?php
791 // We don't want binary data destroyed
792 elseif ($field['is_binary'] || $field['is_blob']) {
793 if (($cfg['ProtectBinary'] && $field['is_blob'])
794 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
795 echo "\n";
796 // for blobstreaming
797 if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
799 echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_md5'] . $vkey . '" value="' . $data . '" />';
800 echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . __('Remove BLOB Repository Reference') . "<br />";
801 echo PMA_BS_CreateReferenceLink($data, $db);
802 echo "<br />";
804 else
806 echo __('Binary - do not edit');
807 if (isset($data)) {
808 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
809 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
810 unset($data_size);
812 echo "\n";
813 } // end if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
815 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
816 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
817 <?php
818 } elseif ($field['is_blob']) {
819 echo "\n";
820 echo $backup_field . "\n";
822 <textarea name="fields<?php echo $field_name_appendix; ?>"
823 rows="<?php echo $cfg['TextareaRows']; ?>"
824 cols="<?php echo $cfg['TextareaCols']; ?>"
825 dir="<?php echo $text_dir; ?>"
826 id="field_<?php echo ($idindex); ?>_3"
827 <?php echo $unnullify_trigger; ?>
828 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
829 ><?php echo $special_chars_encoded; ?></textarea>
830 <?php
832 } else {
833 // field size should be at least 4 and max $cfg['LimitChars']
834 $fieldsize = min(max($field['len'], 4), $cfg['LimitChars']);
835 echo "\n";
836 echo $backup_field . "\n";
838 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
839 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
840 class="textfield" <?php echo $unnullify_trigger; ?>
841 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
842 id="field_<?php echo ($idindex); ?>_3" />
843 <?php
844 } // end if...elseif...else
846 // Upload choice (only for BLOBs because the binary
847 // attribute does not imply binary contents)
848 // (displayed whatever value the ProtectBinary has)
850 if ($is_upload && $field['is_blob']) {
851 // check if field type is of longblob and if the table is PBMS enabled.
852 if (($field['pma_type'] == "longblob") && PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type)) {
853 echo '<br />';
854 echo '<input type="checkbox" name="upload_blob_repo' . $vkey . '[' . $field['Field_md5'] . ']" /> ' . __('Upload to BLOB repository');
857 echo '<br />';
858 echo '<input type="file" name="fields_upload' . $vkey . '[' . $field['Field_md5'] . ']" class="textfield" id="field_' . $idindex . '_3" size="10" ' . $unnullify_trigger . '/>&nbsp;';
860 // find maximum upload size, based on field type
862 * @todo with functions this is not so easy, as you can basically
863 * process any data with function like MD5
865 $max_field_sizes = array(
866 'tinyblob' => '256',
867 'blob' => '65536',
868 'mediumblob' => '16777216',
869 'longblob' => '4294967296'); // yeah, really
871 $this_field_max_size = $max_upload_size; // from PHP max
872 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
873 $this_field_max_size = $max_field_sizes[$field['pma_type']];
875 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
876 // do not generate here the MAX_FILE_SIZE, because we should
877 // put only one in the form to accommodate the biggest field
878 if ($this_field_max_size > $biggest_max_file_size) {
879 $biggest_max_file_size = $this_field_max_size;
883 if (!empty($cfg['UploadDir'])) {
884 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
885 if ($files === false) {
886 echo ' <font color="red">' . __('Error') . '</font><br />' . "\n";
887 echo ' ' . __('The directory you set for upload work cannot be reached') . "\n";
888 } elseif (!empty($files)) {
889 echo "<br />\n";
890 echo ' <i>' . __('Or') . '</i>' . ' ' . __('web server upload directory') . ':<br />' . "\n";
891 echo ' <select size="1" name="fields_uploadlocal' . $vkey . '[' . $field['Field_md5'] . ']">' . "\n";
892 echo ' <option value="" selected="selected"></option>' . "\n";
893 echo $files;
894 echo ' </select>' . "\n";
896 } // end if (web-server upload directory)
897 } // end elseif (binary or blob)
899 elseif (in_array($field['pma_type'], $no_support_types)) {
900 // ignore this column to avoid changing it
902 else {
903 // field size should be at least 4 and max 40
904 $fieldsize = min(max($field['len'], 4), 40);
905 echo $backup_field . "\n";
906 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== false)) {
907 echo "\n";
909 <textarea name="fields<?php echo $field_name_appendix; ?>"
910 rows="<?php echo $cfg['CharTextareaRows']; ?>"
911 cols="<?php echo $cfg['CharTextareaCols']; ?>"
912 dir="<?php echo $text_dir; ?>"
913 id="field_<?php echo ($idindex); ?>_3"
914 <?php echo $unnullify_trigger; ?>
915 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
916 ><?php echo $special_chars_encoded; ?></textarea>
917 <?php
918 } else {
919 $the_class = 'textfield';
920 if ($field['pma_type'] == 'date') {
921 $the_class .= ' datefield';
922 } elseif ($field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
923 $the_class .= ' datetimefield';
926 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
927 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
928 class="<?php echo $the_class; ?>" <?php echo $unnullify_trigger; ?>
929 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
930 id="field_<?php echo ($idindex); ?>_3" />
931 <?php
932 if ($field['Extra'] == 'auto_increment') {
934 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
935 <?php
936 } // end if
937 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
939 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
940 <?php
942 if (substr($field['pma_type'], 0, 8) == 'datetime') {
944 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="datetime" />
945 <?php
947 if ($field['True_Type'] == 'bit') {
949 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
950 <?php
952 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
953 // the _3 suffix points to the date field
954 // the _2 suffix points to the corresponding NULL checkbox
955 // in dateFormat, 'yy' means the year with 4 digits
960 </td>
961 </tr>
962 <?php
963 $odd_row = !$odd_row;
964 } // end for
965 $o_rows++;
966 echo ' </tbody></table><br />';
967 } // end foreach on multi-edit
969 <br />
971 <fieldset id="actions_panel">
972 <table border="0" cellpadding="5" cellspacing="0">
973 <tr>
974 <td valign="middle" nowrap="nowrap">
975 <select name="submit_type" class="control_at_footer" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
976 <?php
977 if (isset($where_clause)) {
979 <option value="save"><?php echo __('Save'); ?></option>
980 <?php
983 <option value="insert"><?php echo __('Insert as new row'); ?></option>
984 <option value="insertignore"><?php echo __('Insert as new row and ignore errors'); ?></option>
985 <option value="showinsert"><?php echo __('Show insert query'); ?></option>
986 </select>
987 <?php
988 echo "\n";
990 if (! isset($after_insert)) {
991 $after_insert = 'back';
994 </td>
995 <td valign="middle">
996 &nbsp;&nbsp;&nbsp;<strong><?php echo __('and then'); ?></strong>&nbsp;&nbsp;&nbsp;
997 </td>
998 <td valign="middle" nowrap="nowrap">
999 <select name="after_insert">
1000 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to previous page'); ?></option>
1001 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Insert another new row'); ?></option>
1002 <?php
1003 if (isset($where_clause)) {
1005 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to this page'); ?></option>
1006 <?php
1007 // If we have just numeric primary key, we can also edit next
1008 // in 2.8.2, we were looking for `field_name` = numeric_value
1009 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1010 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1011 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause)) {
1013 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo __('Edit next row'); ?></option>
1014 <?php
1018 </select>
1019 </td>
1020 </tr>
1022 <tr>
1023 <td>
1024 <?php echo PMA_showHint(__('Use TAB key to move from value to value, or CTRL+arrows to move anywhere')); ?>
1025 </td>
1026 <td colspan="3" align="right" valign="middle">
1027 <input type="submit" class="control_at_footer" value="<?php echo __('Go'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1028 <input type="reset" class="control_at_footer" value="<?php echo __('Reset'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1029 </td>
1030 </tr>
1031 </table>
1032 </fieldset>
1033 <?php if ($biggest_max_file_size > 0) {
1034 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1035 } ?>
1036 </form>
1037 <?php
1038 if ($insert_mode) {
1040 <!-- Continue insertion form -->
1041 <form id="continueForm" method="post" action="tbl_replace.php" name="continueForm" >
1042 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1043 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1044 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
1045 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
1046 <?php
1047 if (isset($where_clauses)) {
1048 foreach ($where_clause_array as $key_id => $where_clause) {
1049 echo '<input type="hidden" name="where_clause[' . $key_id . ']" value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n";
1052 $tmp = '<select name="insert_rows" id="insert_rows">' . "\n";
1053 $option_values = array(1,2,5,10,15,20,30,40);
1054 foreach ($option_values as $value) {
1055 $tmp .= '<option value="' . $value . '"';
1056 if ($value == $cfg['InsertRows']) {
1057 $tmp .= ' selected="selected"';
1059 $tmp .= '>' . $value . '</option>' . "\n";
1061 $tmp .= '</select>' . "\n";
1062 echo "\n" . sprintf(__('Continue insertion with %s rows'), $tmp);
1063 unset($tmp);
1064 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>' . "\n";
1065 echo '</form>' . "\n";
1069 * Displays the footer
1071 require './libraries/footer.inc.php';