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