Translation update done using Pootle.
[phpmyadmin/lorilee.git] / tbl_change.php
blob8ec78f544ecbf485c7f4d5a3199d8098dae0a867
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'][] = 'tbl_change.js';
111 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
112 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
114 * HTTP and HTML headers
116 require_once './libraries/header.inc.php';
119 * Displays the query submitted and its result
121 * @todo where does $disp_message and $disp_query come from???
123 if (! empty($disp_message)) {
124 if (! isset($disp_query)) {
125 $disp_query = null;
127 PMA_showMessage($disp_message, $disp_query);
131 * Displays top menu links
133 require_once './libraries/tbl_links.inc.php';
137 * Get the analysis of SHOW CREATE TABLE for this table
138 * @todo should be handled by class Table
140 $show_create_table = PMA_DBI_fetch_value(
141 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
142 0, 1);
143 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
144 unset($show_create_table);
147 * Get the list of the fields of the current table
149 PMA_DBI_select_db($db);
150 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
151 null, null, null, PMA_DBI_QUERY_STORE);
152 $rows = array();
153 if (isset($where_clause)) {
154 // when in edit mode load all selected rows from table
155 $insert_mode = false;
156 if (is_array($where_clause)) {
157 $where_clause_array = $where_clause;
158 } else {
159 $where_clause_array = array(0 => $where_clause);
162 $result = array();
163 $found_unique_key = false;
164 $where_clauses = array();
166 foreach ($where_clause_array as $key_id => $where_clause) {
167 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';';
168 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
169 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
170 $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
172 // No row returned
173 if (! $rows[$key_id]) {
174 unset($rows[$key_id], $where_clause_array[$key_id]);
175 PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query);
176 echo "\n";
177 require './libraries/footer.inc.php';
178 } else { // end if (no row returned)
179 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
180 list($unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true);
181 if (! empty($unique_condition)) {
182 $found_unique_key = true;
184 unset($unique_condition, $tmp_clause_is_unique);
187 } else {
188 // no primary key given, just load first row - but what happens if table is empty?
189 $insert_mode = true;
190 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
191 $rows = array_fill(0, $cfg['InsertRows'], false);
194 // retrieve keys into foreign fields, if any
195 $foreigners = PMA_getForeigners($db, $table);
199 * Displays the form
201 // autocomplete feature of IE kills the "onchange" event handler and it
202 // must be replaced by the "onpropertychange" one in this case
203 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7)
204 ? 'onpropertychange'
205 : 'onchange';
206 // Had to put the URI because when hosted on an https server,
207 // some browsers send wrongly this form to the http server.
209 if ($cfg['CtrlArrowsMoving']) {
211 <!-- Set on key handler for moving using by Ctrl+arrows -->
212 <script src="./js/keyhandler.js" type="text/javascript"></script>
213 <script type="text/javascript">
214 //<![CDATA[
215 var switch_movement = 0;
216 document.onkeydown = onKeyDownArrowsHandler;
217 //]]>
218 </script>
219 <?php
222 $_form_params = array(
223 'db' => $db,
224 'table' => $table,
225 'goto' => $GLOBALS['goto'],
226 'err_url' => $err_url,
227 'sql_query' => $sql_query,
229 if (isset($where_clauses)) {
230 foreach ($where_clause_array as $key_id => $where_clause) {
231 $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
234 if (isset($clause_is_unique)) {
235 $_form_params['clause_is_unique'] = $clause_is_unique;
240 <!-- Insert/Edit form -->
241 <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>>
242 <?php
243 echo PMA_generate_common_hidden_inputs($_form_params);
245 $titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
247 // Set if we passed the first timestamp field
248 $timestamp_seen = 0;
249 $fields_cnt = count($table_fields);
251 $tabindex = 0;
252 $tabindex_for_function = +3000;
253 $tabindex_for_null = +6000;
254 $tabindex_for_value = 0;
255 $o_rows = 0;
256 $biggest_max_file_size = 0;
258 // user can toggle the display of Function column
259 // (currently does not work for multi-edits)
260 $url_params['db'] = $db;
261 $url_params['table'] = $table;
262 if (isset($where_clause)) {
263 $url_params['where_clause'] = trim($where_clause);
265 if (! empty($sql_query)) {
266 $url_params['sql_query'] = $sql_query;
269 if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) {
270 echo __('Show');
272 if (! $cfg['ShowFunctionFields']) {
273 $this_url_params = array_merge($url_params,
274 array('ShowFunctionFields' => 1, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
275 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . __('Function') . '</a>' . "\n";
277 if (! $cfg['ShowFieldTypesInDataEditView']) {
278 $this_other_url_params = array_merge($url_params,
279 array('ShowFieldTypesInDataEditView' => 1, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
280 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_other_url_params) . '">' . __('Type') . '</a>' . "\n";
283 foreach ($rows as $row_id => $vrow) {
284 if ($vrow === false) {
285 unset($vrow);
288 $jsvkey = $row_id;
289 $browse_foreigners_uri = '&amp;pk=' . $row_id;
290 $vkey = '[multi_edit][' . $jsvkey . ']';
292 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ? $result[$row_id] : $result);
293 if ($insert_mode && $row_id > 0) {
294 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_check_' . $row_id . '" />';
295 echo '<label for="insert_ignore_check_' . $row_id . '">' . __('Ignore') . '</label><br />' . "\n";
298 <table>
299 <thead>
300 <tr>
301 <th><?php echo __('Column'); ?></th>
303 <?php
304 if ($cfg['ShowFieldTypesInDataEditView']) {
305 $this_url_params = array_merge($url_params,
306 array('ShowFieldTypesInDataEditView' => 0, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
307 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Type') . '</a></th>' . "\n";
310 if ($cfg['ShowFunctionFields']) {
311 $this_url_params = array_merge($url_params,
312 array('ShowFunctionFields' => 0, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
313 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Function') . '</a></th>' . "\n";
316 <th><?php echo __('Null'); ?></th>
317 <th><?php echo __('Value'); ?></th>
318 </tr>
319 </thead>
320 <tfoot>
321 <tr>
322 <th colspan="5" align="right" class="tblFooters">
323 <input type="submit" value="<?php echo __('Go'); ?>" />
324 </th>
325 </tr>
326 </tfoot>
327 <tbody>
328 <?php
329 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
330 $m_rows = $o_rows + 1;
332 $odd_row = true;
333 for ($i = 0; $i < $fields_cnt; $i++) {
334 if (! isset($table_fields[$i]['processed'])) {
335 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
336 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
337 // True_Type contains only the type (stops at first bracket)
338 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
340 // d a t e t i m e
342 // Current date should not be set as default if the field is NULL
343 // for the current row, but do not put here the current datetime
344 // if there is a default value (the real default value will be set
345 // in the Default value logic below)
347 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
348 // $field['Default'] is not set if it contains NULL:
349 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
350 // but, look what we get if we switch to iso: (Default is NULL)
351 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
352 // so I force a NULL into it (I don't think it's possible
353 // to have an empty default value for DATETIME)
354 // then, the "if" after this one will work
355 if ($table_fields[$i]['Type'] == 'datetime'
356 && ! isset($table_fields[$i]['Default'])
357 && isset($table_fields[$i]['Null'])
358 && $table_fields[$i]['Null'] == 'YES') {
359 $table_fields[$i]['Default'] = null;
362 $table_fields[$i]['len'] =
363 preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1;
366 if (isset($comments_map[$table_fields[$i]['Field']])) {
367 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
368 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
369 . $table_fields[$i]['Field_html'] . '</span>';
370 } else {
371 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
374 // The type column
375 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
376 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
377 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
378 $table_fields[$i]['first_timestamp'] = false;
379 switch ($table_fields[$i]['True_Type']) {
380 case 'set':
381 $table_fields[$i]['pma_type'] = 'set';
382 $table_fields[$i]['wrap'] = '';
383 break;
384 case 'enum':
385 $table_fields[$i]['pma_type'] = 'enum';
386 $table_fields[$i]['wrap'] = '';
387 break;
388 case 'timestamp':
389 if (!$timestamp_seen) { // can only occur once per table
390 $timestamp_seen = 1;
391 $table_fields[$i]['first_timestamp'] = true;
393 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
394 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
395 break;
397 default:
398 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
399 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
400 break;
403 $field = $table_fields[$i];
404 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
406 if (-1 === $field['len']) {
407 $field['len'] = PMA_DBI_field_len($vresult, $i);
409 //Call validation when the form submited...
410 $unnullify_trigger = $chg_evt_handler . "=\"return Validator('". PMA_escapeJsString($field['Field_md5']) . "', '"
411 . PMA_escapeJsString($jsvkey) . "','".$field['pma_type']."')\"";
413 // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
414 $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
415 $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]';
418 if ($field['Type'] == 'datetime'
419 && ! isset($field['Default'])
420 && ! is_null($field['Default'])
421 && ($insert_mode || ! isset($vrow[$field['Field']]))) {
422 // INSERT case or
423 // UPDATE case with an NULL value
424 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
427 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
428 <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center">
429 <?php echo $field['Field_title']; ?>
430 <input type="hidden" name="fields_name<?php echo $field_name_appendix; ?>" value="<?php echo $field['Field_html']; ?>"/>
431 </td>
432 <?php if ($cfg['ShowFieldTypesInDataEditView']) { ?>
433 <td align="center"<?php echo $field['wrap']; ?>>
434 <?php echo $field['pma_type']; ?>
435 </td>
437 <?php } //End if
439 // Prepares the field value
440 $real_null_value = FALSE;
441 $special_chars_encoded = '';
442 if (isset($vrow)) {
443 // (we are editing)
444 if (is_null($vrow[$field['Field']])) {
445 $real_null_value = TRUE;
446 $vrow[$field['Field']] = '';
447 $special_chars = '';
448 $data = $vrow[$field['Field']];
449 } elseif ($field['True_Type'] == 'bit') {
450 $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
451 } else {
452 // special binary "characters"
453 if ($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) {
454 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
455 $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]);
456 $field['display_binary_as_hex'] = true;
457 } else {
458 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
460 } // end if
461 $special_chars = htmlspecialchars($vrow[$field['Field']]);
463 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
464 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
466 $data = $vrow[$field['Field']];
467 } // end if... else...
468 // If a timestamp field value is not included in an update
469 // statement MySQL auto-update it to the current timestamp;
470 // however, things have changed since MySQL 4.1, so
471 // it's better to set a fields_prev in this situation
472 $backup_field = '<input type="hidden" name="fields_prev'
473 . $field_name_appendix . '" value="'
474 . htmlspecialchars($vrow[$field['Field']]) . '" />';
475 } else {
476 // (we are inserting)
477 // display default values
478 if (!isset($field['Default'])) {
479 $field['Default'] = '';
480 $real_null_value = TRUE;
481 $data = '';
482 } else {
483 $data = $field['Default'];
485 if ($field['True_Type'] == 'bit') {
486 $special_chars = PMA_convert_bit_default_value($field['Default']);
487 } else {
488 $special_chars = htmlspecialchars($field['Default']);
490 $backup_field = '';
491 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
492 // this will select the UNHEX function while inserting
493 if (($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) && $_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
494 $field['display_binary_as_hex'] = true;
498 $idindex = ($o_rows * $fields_cnt) + $i + 1;
499 $tabindex = (($idindex - 1) * 3) + 1;
501 // The function column
502 // -------------------
503 // We don't want binary data to be destroyed
504 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
505 // stored or retrieved" so it does not mean that the contents is
506 // binary
507 if ($cfg['ShowFunctionFields']) {
508 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
509 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
510 echo ' <td align="center">' . __('Binary') . '</td>' . "\n";
511 } elseif (strstr($field['True_Type'], 'enum') || strstr($field['True_Type'], 'set')) {
512 echo ' <td align="center">--</td>' . "\n";
513 } else {
515 <td>
516 <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">
517 <option></option>
518 <?php
519 $selected = '';
521 // Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
522 // or something similar. Then directly look up the entry in the RestrictFunctions array,
523 // which will then reveal the available dropdown options
524 if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
525 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
526 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
527 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
528 $default_function = $cfg['DefaultFunctions'][$current_func_type];
529 } else {
530 $dropdown = array();
531 $default_function = '';
534 $dropdown_built = array();
535 $op_spacing_needed = FALSE;
537 // what function defined as default?
538 // for the first timestamp we don't set the default function
539 // if there is a default value for the timestamp
540 // (not including CURRENT_TIMESTAMP)
541 // and the column does not have the
542 // ON UPDATE DEFAULT TIMESTAMP attribute.
544 if ($field['True_Type'] == 'timestamp'
545 && empty($field['Default'])
546 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
547 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
550 // For primary keys of type char(36) or varchar(36) UUID if the default function
551 // Only applies to insert mode, as it would silently trash data on updates.
552 if ($insert_mode
553 && $field['Key'] == 'PRI'
554 && ($field['Type'] == 'char(36)' || $field['Type'] == 'varchar(36)')
556 $default_function = $cfg['DefaultFunctions']['pk_char36'];
559 // this is set only when appropriate and is always true
560 if (isset($field['display_binary_as_hex'])) {
561 $default_function = 'UNHEX';
564 // loop on the dropdown array and print all available options for that field.
565 foreach ($dropdown as $each_dropdown){
566 echo '<option';
567 if ($default_function === $each_dropdown) {
568 echo ' selected="selected"';
570 echo '>' . $each_dropdown . '</option>' . "\n";
571 $dropdown_built[$each_dropdown] = 'TRUE';
572 $op_spacing_needed = TRUE;
575 // For compatibility's sake, do not let out all other functions. Instead
576 // print a separator (blank) and then show ALL functions which weren't shown
577 // yet.
578 $cnt_functions = count($cfg['Functions']);
579 for ($j = 0; $j < $cnt_functions; $j++) {
580 if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
581 // Is current function defined as default?
582 $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
583 || (!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
584 ? ' selected="selected"'
585 : '';
586 if ($op_spacing_needed == TRUE) {
587 echo ' ';
588 echo '<option value="">--------</option>' . "\n";
589 $op_spacing_needed = FALSE;
592 echo ' ';
593 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
595 } // end for
596 unset($selected);
598 </select>
599 </td>
600 <?php
602 } // end if ($cfg['ShowFunctionFields'])
605 // The null column
606 // ---------------
607 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
608 echo ' <td>' . "\n";
609 if ($field['Null'] == 'YES') {
610 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
611 if ($real_null_value && !$field['first_timestamp']) {
612 echo ' value="on"';
614 echo ' />' . "\n";
616 echo ' <input type="checkbox" tabindex="' . ($tabindex + $tabindex_for_null) . '"'
617 . ' name="fields_null' . $field_name_appendix . '"';
618 if ($real_null_value && !$field['first_timestamp']) {
619 echo ' checked="checked"';
621 echo ' id="field_' . ($idindex) . '_2"';
622 $onclick = ' onclick="if (this.checked) {nullify(';
623 if (strstr($field['True_Type'], 'enum')) {
624 if (strlen($field['Type']) > 20) {
625 $onclick .= '1, ';
626 } else {
627 $onclick .= '2, ';
629 } elseif (strstr($field['True_Type'], 'set')) {
630 $onclick .= '3, ';
631 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
632 // foreign key in a drop-down
633 $onclick .= '4, ';
634 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
635 // foreign key with a browsing icon
636 $onclick .= '6, ';
637 } else {
638 $onclick .= '5, ';
640 $onclick .= '\'' . PMA_escapeJsString($field['Field_html']) . '\', \'' . $field['Field_md5'] . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
641 echo $onclick;
643 echo ' </td>' . "\n";
645 // The value column (depends on type)
646 // ----------------
647 // See bug #1667887 for the reason why we don't use the maxlength
648 // HTML attribute
650 echo ' <td>' . "\n";
651 if ($foreignData['foreign_link'] == true) {
652 echo $backup_field . "\n";
654 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
655 value="foreign" />
656 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
657 value="" id="field_<?php echo ($idindex); ?>_3A" />
658 <input type="text" name="field_<?php echo $field_name_appendix_md5; ?>"
659 class="textfield" <?php echo $unnullify_trigger; ?>
660 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
661 id="field_<?php echo ($idindex); ?>_3"
662 value="<?php echo htmlspecialchars($data); ?>" />
663 <script type="text/javascript">
664 //<![CDATA[
665 document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
666 document.write(' href="browse_foreigners.php?');
667 document.write('<?php echo PMA_generate_common_url($db, $table); ?>');
668 document.writeln('&amp;field=<?php echo PMA_escapeJsString(urlencode($field['Field']) . $browse_foreigners_uri); ?>">');
669 document.writeln('<?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
670 //]]>
671 </script>
672 <?php
673 } elseif (is_array($foreignData['disp_row'])) {
674 echo $backup_field . "\n";
676 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>"
677 value="foreign" />
678 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>"
679 value="" id="field_<?php echo $idindex; ?>_3A" />
680 <select name="field_<?php echo $field_name_appendix_md5; ?>"
681 <?php echo $unnullify_trigger; ?>
682 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
683 id="field_<?php echo ($idindex); ?>_3">
684 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
685 </select>
686 <?php
687 // still needed? :
688 unset($foreignData['disp_row']);
689 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
691 &nbsp;</td>
692 </tr>
693 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
694 <td colspan="5" align="right">
695 <?php echo $backup_field . "\n"; ?>
696 <textarea name="fields<?php echo $field_name_appendix; ?>"
697 rows="<?php echo ($cfg['TextareaRows']*2); ?>"
698 cols="<?php echo ($cfg['TextareaCols']*2); ?>"
699 dir="<?php echo $text_dir; ?>"
700 id="field_<?php echo ($idindex); ?>_3"
701 <?php echo $unnullify_trigger; ?>
702 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
703 ><?php echo $special_chars_encoded; ?></textarea>
704 <?php
705 } elseif (strstr($field['pma_type'], 'text')) {
706 echo $backup_field . "\n";
708 <textarea name="fields<?php echo $field_name_appendix; ?>"
709 rows="<?php echo $cfg['TextareaRows']; ?>"
710 cols="<?php echo $cfg['TextareaCols']; ?>"
711 dir="<?php echo $text_dir; ?>"
712 id="field_<?php echo ($idindex); ?>_3"
713 <?php echo $unnullify_trigger; ?>
714 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
715 ><?php echo $special_chars_encoded; ?></textarea>
716 <?php
717 echo "\n";
718 if (strlen($special_chars) > 32000) {
719 echo " </td>\n";
720 echo ' <td>' . __(' Because of its length,<br /> this column might not be editable ');
722 } elseif ($field['pma_type'] == 'enum') {
723 if (! isset($table_fields[$i]['values'])) {
724 $table_fields[$i]['values'] = array();
725 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
726 // Removes automatic MySQL escape format
727 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
728 $table_fields[$i]['values'][] = array(
729 'plain' => $val,
730 'html' => htmlspecialchars($val),
734 $field_enum_values = $table_fields[$i]['values'];
736 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="enum" />
737 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
738 <?php
739 echo "\n" . ' ' . $backup_field . "\n";
741 // show dropdown or radio depend on length
742 if (strlen($field['Type']) > 20) {
744 <select name="field_<?php echo $field_name_appendix_md5; ?>"
745 <?php echo $unnullify_trigger; ?>
746 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
747 id="field_<?php echo ($idindex); ?>_3">
748 <option value="">&nbsp;</option>
749 <?php
750 echo "\n";
752 foreach ($field_enum_values as $enum_value) {
753 echo ' ';
754 echo '<option value="' . $enum_value['html'] . '"';
755 if ($data == $enum_value['plain']
756 || ($data == ''
757 && (! isset($where_clause) || $field['Null'] != 'YES')
758 && isset($field['Default'])
759 && $enum_value['plain'] == $field['Default'])) {
760 echo ' selected="selected"';
762 echo '>' . $enum_value['html'] . '</option>' . "\n";
763 } // end for
766 </select>
767 <?php
768 } else {
769 $j = 0;
770 foreach ($field_enum_values as $enum_value) {
771 echo ' ';
772 echo '<input type="radio" name="field_' . $field_name_appendix_md5 . '"';
773 echo ' value="' . $enum_value['html'] . '"';
774 echo ' id="field_' . ($idindex) . '_3_' . $j . '"';
775 echo $unnullify_trigger;
776 if ($data == $enum_value['plain']
777 || ($data == ''
778 && (! isset($where_clause) || $field['Null'] != 'YES')
779 && isset($field['Default'])
780 && $enum_value['plain'] == $field['Default'])) {
781 echo ' checked="checked"';
783 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
784 echo '<label for="field_' . $idindex . '_3_' . $j . '">'
785 . $enum_value['html'] . '</label>' . "\n";
786 $j++;
787 } // end for
788 } // end else
789 } elseif ($field['pma_type'] == 'set') {
790 if (! isset($table_fields[$i]['values'])) {
791 $table_fields[$i]['values'] = array();
792 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
793 $table_fields[$i]['values'][] = array(
794 'plain' => $val,
795 'html' => htmlspecialchars($val),
798 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
800 $field_set_values = $table_fields[$i]['values'];
801 $select_size = $table_fields[$i]['select_size'];
803 $vset = array_flip(explode(',', $data));
804 echo $backup_field . "\n";
806 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="set" />
807 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
808 <select name="field_<?php echo $field_name_appendix_md5; ?>"
809 size="<?php echo $select_size; ?>"
810 multiple="multiple" <?php echo $unnullify_trigger; ?>
811 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
812 id="field_<?php echo ($idindex); ?>_3">
813 <?php
814 foreach ($field_set_values as $field_set_value) {
815 echo ' ';
816 echo '<option value="' . $field_set_value['html'] . '"';
817 if (isset($vset[$field_set_value['plain']])) {
818 echo ' selected="selected"';
820 echo '>' . $field_set_value['html'] . '</option>' . "\n";
821 } // end for
823 </select>
824 <?php
826 // We don't want binary data destroyed
827 elseif ($field['is_binary'] || $field['is_blob']) {
828 if (($cfg['ProtectBinary'] && $field['is_blob'])
829 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
830 echo "\n";
831 // for blobstreaming
832 if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
834 echo '<input type="hidden" name="remove_blob_ref_' . $field['Field_md5'] . $vkey . '" value="' . $data . '" />';
835 echo '<input type="checkbox" name="remove_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . __('Remove BLOB Repository Reference') . "<br />";
836 echo PMA_BS_CreateReferenceLink($data, $db);
837 echo "<br />";
839 else
841 echo __('Binary - do not edit');
842 if (isset($data)) {
843 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
844 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
845 unset($data_size);
847 echo "\n";
848 } // end if (PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type) && PMA_BS_IsPBMSReference($data, $db))
850 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="protected" />
851 <input type="hidden" name="fields<?php echo $field_name_appendix; ?>" value="" />
852 <?php
853 } elseif ($field['is_blob']) {
854 echo "\n";
855 echo $backup_field . "\n";
857 <textarea name="fields<?php echo $field_name_appendix; ?>"
858 rows="<?php echo $cfg['TextareaRows']; ?>"
859 cols="<?php echo $cfg['TextareaCols']; ?>"
860 dir="<?php echo $text_dir; ?>"
861 id="field_<?php echo ($idindex); ?>_3"
862 <?php echo $unnullify_trigger; ?>
863 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
864 ><?php echo $special_chars_encoded; ?></textarea>
865 <?php
867 } else {
868 // field size should be at least 4 and max 40
869 $fieldsize = min(max($field['len'], 4), 40);
870 echo "\n";
871 echo $backup_field . "\n";
873 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
874 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
875 class="textfield" <?php echo $unnullify_trigger; ?>
876 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
877 id="field_<?php echo ($idindex); ?>_3" />
878 <?php
879 } // end if...elseif...else
881 // Upload choice (only for BLOBs because the binary
882 // attribute does not imply binary contents)
883 // (displayed whatever value the ProtectBinary has)
885 if ($is_upload && $field['is_blob']) {
886 // check if field type is of longblob and if the table is PBMS enabled.
887 if (($field['pma_type'] == "longblob") && PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type)) {
888 echo '<br />';
889 echo '<input type="checkbox" name="upload_blob_repo_' . $field['Field_md5'] . $vkey . '" /> ' . __('Upload to BLOB repository');
892 echo '<br />';
893 echo '<input type="file" name="fields_upload_' . $field['Field_md5'] . $vkey . '" class="textfield" id="field_' . $idindex . '_3" size="10" ' . $unnullify_trigger . '/>&nbsp;';
895 // find maximum upload size, based on field type
897 * @todo with functions this is not so easy, as you can basically
898 * process any data with function like MD5
900 $max_field_sizes = array(
901 'tinyblob' => '256',
902 'blob' => '65536',
903 'mediumblob' => '16777216',
904 'longblob' => '4294967296'); // yeah, really
906 $this_field_max_size = $max_upload_size; // from PHP max
907 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
908 $this_field_max_size = $max_field_sizes[$field['pma_type']];
910 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n";
911 // do not generate here the MAX_FILE_SIZE, because we should
912 // put only one in the form to accommodate the biggest field
913 if ($this_field_max_size > $biggest_max_file_size) {
914 $biggest_max_file_size = $this_field_max_size;
918 if (!empty($cfg['UploadDir'])) {
919 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
920 if ($files === FALSE) {
921 echo ' <font color="red">' . __('Error') . '</font><br />' . "\n";
922 echo ' ' . __('The directory you set for upload work cannot be reached') . "\n";
923 } elseif (!empty($files)) {
924 echo "<br />\n";
925 echo ' <i>' . __('Or') . '</i>' . ' ' . __('web server upload directory') . ':<br />' . "\n";
926 echo ' <select size="1" name="fields_uploadlocal_' . $field['Field_md5'] . $vkey . '">' . "\n";
927 echo ' <option value="" selected="selected"></option>' . "\n";
928 echo $files;
929 echo ' </select>' . "\n";
931 } // end if (web-server upload directory)
932 } // end elseif (binary or blob)
933 else {
934 // field size should be at least 4 and max 40
935 $fieldsize = min(max($field['len'], 4), 40);
936 echo $backup_field . "\n";
937 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n") !== FALSE)) {
938 echo "\n";
940 <textarea name="fields<?php echo $field_name_appendix; ?>"
941 rows="<?php echo $cfg['CharTextareaRows']; ?>"
942 cols="<?php echo $cfg['CharTextareaCols']; ?>"
943 dir="<?php echo $text_dir; ?>"
944 id="field_<?php echo ($idindex); ?>_3"
945 <?php echo $unnullify_trigger; ?>
946 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
947 ><?php echo $special_chars_encoded; ?></textarea>
948 <?php
949 } else {
951 <input type="text" name="fields<?php echo $field_name_appendix; ?>"
952 value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>"
953 class="textfield" <?php echo $unnullify_trigger; ?>
954 tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"
955 id="field_<?php echo ($idindex); ?>_3" />
956 <?php
957 if ($field['Extra'] == 'auto_increment') {
959 <input type="hidden" name="auto_increment<?php echo $field_name_appendix; ?>" value="1" />
960 <?php
961 } // end if
962 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
964 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="timestamp" />
965 <?php
967 if (substr($field['pma_type'], 0, 8) == 'datetime') {
969 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="datetime" />
970 <?php
972 if ($field['True_Type'] == 'bit') {
974 <input type="hidden" name="fields_type<?php echo $field_name_appendix; ?>" value="bit" />
975 <?php
977 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || 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
982 <script type="text/javascript">
983 //<![CDATA[
984 $(function() {
985 $('#field_<?php echo ($idindex); ?>_3').datepicker({
986 duration: '',
987 time24h: true,
988 stepMinutes: 1,
989 stepHours: 1,
990 <?php echo ($field['pma_type'] == 'date' ? "showTime: false,":"showTime: true,"); ?>
991 dateFormat: 'yy-mm-dd',
992 altTimeField: '',
993 constrainInput: false
996 //]]>
997 </script>
998 <?php
1003 </td>
1004 </tr>
1005 <?php
1006 $odd_row = !$odd_row;
1007 } // end for
1008 $o_rows++;
1009 echo ' </tbody></table><br />';
1010 } // end foreach on multi-edit
1012 <br />
1014 <fieldset>
1015 <table border="0" cellpadding="5" cellspacing="0">
1016 <tr>
1017 <td valign="middle" nowrap="nowrap">
1018 <select name="submit_type" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
1019 <?php
1020 if (isset($where_clause)) {
1022 <option value="save"><?php echo __('Save'); ?></option>
1023 <?php
1026 <option value="insert"><?php echo __('Insert as new row'); ?></option>
1027 <option value="insertignore"><?php echo __('Insert as new row and ignore errors'); ?></option>
1028 <option value="showinsert"><?php echo __('Show insert query'); ?></option>
1029 </select>
1030 <?php
1031 echo "\n";
1033 if (!isset($after_insert)) {
1034 $after_insert = 'back';
1037 </td>
1038 <td valign="middle">
1039 &nbsp;&nbsp;&nbsp;<strong><?php echo __('and then'); ?></strong>&nbsp;&nbsp;&nbsp;
1040 </td>
1041 <td valign="middle" nowrap="nowrap">
1042 <select name="after_insert">
1043 <option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to previous page'); ?></option>
1044 <option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Insert another new row'); ?></option>
1045 <?php
1046 if (isset($where_clause)) {
1048 <option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo __('Go back to this page'); ?></option>
1049 <?php
1050 // If we have just numeric primary key, we can also edit next
1051 // in 2.8.2, we were looking for `field_name` = numeric_value
1052 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1053 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1054 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause)) {
1056 <option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo __('Edit next row'); ?></option>
1057 <?php
1061 </select>
1062 </td>
1063 </tr>
1065 <tr>
1066 <td>
1067 <?php echo PMA_showHint(__('Use TAB key to move from value to value, or CTRL+arrows to move anywhere')); ?>
1068 </td>
1069 <td colspan="3" align="right" valign="middle">
1070 <input type="submit" value="<?php echo __('Go'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 6); ?>" id="buttonYes" />
1071 <input type="reset" value="<?php echo __('Reset'); ?>" tabindex="<?php echo ($tabindex + $tabindex_for_value + 7); ?>" />
1072 </td>
1073 </tr>
1074 </table>
1075 </fieldset>
1076 <?php if ($biggest_max_file_size > 0) {
1077 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
1078 } ?>
1079 </form>
1080 <?php
1081 if ($insert_mode) {
1083 <!-- Restart insertion form -->
1084 <form method="post" action="tbl_replace.php" name="restartForm" >
1085 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1086 <input type="hidden" name="goto" value="<?php echo htmlspecialchars($GLOBALS['goto']); ?>" />
1087 <input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
1088 <input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
1089 <?php
1090 if (isset($where_clauses)) {
1091 foreach ($where_clause_array as $key_id => $where_clause) {
1092 echo '<input type="hidden" name="where_clause[' . $key_id . ']" value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n";
1095 $tmp = '<select name="insert_rows" id="insert_rows" onchange="this.form.submit();" >' . "\n";
1096 $option_values = array(1,2,5,10,15,20,30,40);
1097 foreach ($option_values as $value) {
1098 $tmp .= '<option value="' . $value . '"';
1099 if ($value == $cfg['InsertRows']) {
1100 $tmp .= ' selected="selected"';
1102 $tmp .= '>' . $value . '</option>' . "\n";
1104 $tmp .= '</select>' . "\n";
1105 echo "\n" . sprintf(__('Restart insertion with %s rows'), $tmp);
1106 unset($tmp);
1107 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>' . "\n";
1108 echo '</form>' . "\n";
1112 * Displays the footer
1114 require './libraries/footer.inc.php';