2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Displays form for editing and inserting new table rows
6 * register_globals_save (mark this file save for disabling register globals)
12 * Gets the variables sent or posted to this script and displays the header
14 require_once './libraries/common.inc.php';
17 * Ensures db and table are valid, else moves to the "parent" script
19 require_once './libraries/db_table_exists.lib.php';
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'];
48 * load relation data, foreign keys
50 require_once './libraries/relation.lib.php';
55 require_once './libraries/file_listing.php';
59 * Defines the url to return to in case of error in a sql statement
60 * (at this point, $GLOBALS['goto'] will be set but could be empty)
62 if (empty($GLOBALS['goto'])) {
64 // avoid a problem (see bug #2202709)
65 $GLOBALS['goto'] = 'tbl_sql.php';
67 $GLOBALS['goto'] = 'db_sql.php';
71 * @todo check if we could replace by "db_|tbl_" - please clarify!?
75 'sql_query' => $sql_query
78 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
79 $_url_params['table'] = $table;
82 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
87 * Sets parameters for links
88 * where is this variable used?
89 * replace by PMA_generate_common_url($url_params);
91 $url_query = PMA_generate_common_url($url_params, 'html', '');
94 * get table information
95 * @todo should be done by a Table object
97 require_once './libraries/tbl_info.inc.php';
100 * Get comments for table fileds/columns
102 $comments_map = array();
104 if ($GLOBALS['cfg']['ShowPropertyComments']) {
105 $comments_map = PMA_getComments($db, $table);
109 * START REGULAR OUTPUT
113 * used in ./libraries/header.inc.php to load JavaScript library file
115 $GLOBALS['js_include'][] = 'tbl_change.js';
116 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
117 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
119 * HTTP and HTML headers
121 require_once './libraries/header.inc.php';
124 * Displays the query submitted and its result
126 * @todo where does $disp_message and $disp_query come from???
128 if (! empty($disp_message)) {
129 if (! isset($disp_query)) {
132 PMA_showMessage($disp_message, $disp_query);
136 * Displays top menu links
138 require_once './libraries/tbl_links.inc.php';
142 * Get the analysis of SHOW CREATE TABLE for this table
143 * @todo should be handled by class Table
145 $show_create_table = PMA_DBI_fetch_value(
146 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
148 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
149 unset($show_create_table);
152 * Get the list of the fields of the current table
154 PMA_DBI_select_db($db);
155 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
156 null, null, null, PMA_DBI_QUERY_STORE
);
158 if (isset($where_clause)) {
159 // when in edit mode load all selected rows from table
160 $insert_mode = false;
161 if (is_array($where_clause)) {
162 $where_clause_array = $where_clause;
164 $where_clause_array = array(0 => $where_clause);
168 $found_unique_key = false;
169 $where_clauses = array();
171 foreach ($where_clause_array as $key_id => $where_clause) {
172 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';';
173 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE
);
174 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
175 $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
178 if (! $rows[$key_id]) {
179 unset($rows[$key_id], $where_clause_array[$key_id]);
180 PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query);
182 require_once './libraries/footer.inc.php';
183 } else { // end if (no row returned)
184 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
185 list($unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true);
186 if (! empty($unique_condition)) {
187 $found_unique_key = true;
189 unset($unique_condition, $tmp_clause_is_unique);
193 // no primary key given, just load first row - but what happens if table is empty?
195 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE
);
196 $rows = array_fill(0, $cfg['InsertRows'], false);
199 // retrieve keys into foreign fields, if any
200 $foreigners = PMA_getForeigners($db, $table);
206 // autocomplete feature of IE kills the "onchange" event handler and it
207 // must be replaced by the "onpropertychange" one in this case
208 $chg_evt_handler = (PMA_USR_BROWSER_AGENT
== 'IE' && PMA_USR_BROWSER_VER
>= 5 && PMA_USR_BROWSER_VER
< 7)
211 // Had to put the URI because when hosted on an https server,
212 // some browsers send wrongly this form to the http server.
214 if ($cfg['CtrlArrowsMoving']) {
216 <!-- Set on key handler
for moving using by Ctrl+arrows
-->
217 <script src
="./js/keyhandler.js" type
="text/javascript"></script
>
218 <script type
="text/javascript">
220 var switch_movement
= 0;
221 document
.onkeydown
= onKeyDownArrowsHandler
;
227 $_form_params = array(
230 'goto' => $GLOBALS['goto'],
231 'err_url' => $err_url,
232 'sql_query' => $sql_query,
234 if (isset($where_clauses)) {
235 foreach ($where_clause_array as $key_id => $where_clause) {
236 $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
239 if (isset($clause_is_unique)) {
240 $_form_params['clause_is_unique'] = $clause_is_unique;
245 <!-- Insert
/Edit form
-->
246 <form method
="post" action
="tbl_replace.php" name
="insertForm" <?php
if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?
>>
248 echo PMA_generate_common_hidden_inputs($_form_params);
250 $titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
252 // Set if we passed the first timestamp field
254 $fields_cnt = count($table_fields);
257 $tabindex_for_function = +
3000;
258 $tabindex_for_null = +
6000;
259 $tabindex_for_value = 0;
261 $biggest_max_file_size = 0;
263 // user can toggle the display of Function column
264 // (currently does not work for multi-edits)
265 $url_params['db'] = $db;
266 $url_params['table'] = $table;
267 if (isset($where_clause)) {
268 $url_params['where_clause'] = trim($where_clause);
270 if (! empty($sql_query)) {
271 $url_params['sql_query'] = $sql_query;
274 if (! $cfg['ShowFunctionFields'] ||
! $cfg['ShowFieldTypesInDataEditView']) {
277 if (! $cfg['ShowFunctionFields']) {
278 $this_url_params = array_merge($url_params,
279 array('ShowFunctionFields' => 1, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
280 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . __('Function') . '</a>' . "\n";
282 if (! $cfg['ShowFieldTypesInDataEditView']) {
283 $this_other_url_params = array_merge($url_params,
284 array('ShowFieldTypesInDataEditView' => 1, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
285 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_other_url_params) . '">' . __('Type') . '</a>' . "\n";
288 foreach ($rows as $row_id => $vrow) {
289 if ($vrow === false) {
294 $browse_foreigners_uri = '&pk=' . $row_id;
295 $vkey = '[multi_edit][' . $jsvkey . ']';
297 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ?
$result[$row_id] : $result);
298 if ($insert_mode && $row_id > 0) {
299 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_check_' . $row_id . '" />';
300 echo '<label for="insert_ignore_check_' . $row_id . '">' . __('Ignore') . '</label><br />' . "\n";
306 <th
><?php
echo __('Column'); ?
></th
>
309 if ($cfg['ShowFieldTypesInDataEditView']) {
310 $this_url_params = array_merge($url_params,
311 array('ShowFieldTypesInDataEditView' => 0, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
312 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Type') . '</a></th>' . "\n";
315 if ($cfg['ShowFunctionFields']) {
316 $this_url_params = array_merge($url_params,
317 array('ShowFunctionFields' => 0, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
318 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Function') . '</a></th>' . "\n";
321 <th
><?php
echo __('Null'); ?
></th
>
322 <th
><?php
echo __('Value'); ?
></th
>
327 <th colspan
="5" align
="right" class="tblFooters">
328 <input type
="submit" value
="<?php echo __('Go'); ?>" />
334 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
335 $m_rows = $o_rows +
1;
338 for ($i = 0; $i < $fields_cnt; $i++
) {
339 if (! isset($table_fields[$i]['processed'])) {
340 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
341 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
342 // True_Type contains only the type (stops at first bracket)
343 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
347 // Current date should not be set as default if the field is NULL
348 // for the current row, but do not put here the current datetime
349 // if there is a default value (the real default value will be set
350 // in the Default value logic below)
352 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
353 // $field['Default'] is not set if it contains NULL:
354 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
355 // but, look what we get if we switch to iso: (Default is NULL)
356 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
357 // so I force a NULL into it (I don't think it's possible
358 // to have an empty default value for DATETIME)
359 // then, the "if" after this one will work
360 if ($table_fields[$i]['Type'] == 'datetime'
361 && ! isset($table_fields[$i]['Default'])
362 && isset($table_fields[$i]['Null'])
363 && $table_fields[$i]['Null'] == 'YES') {
364 $table_fields[$i]['Default'] = null;
367 $table_fields[$i]['len'] =
368 preg_match('@float|double@', $table_fields[$i]['Type']) ?
100 : -1;
371 if (isset($comments_map[$table_fields[$i]['Field']])) {
372 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
373 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
374 . $table_fields[$i]['Field_html'] . '</span>';
376 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
380 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
381 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
382 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
383 $table_fields[$i]['first_timestamp'] = false;
384 switch ($table_fields[$i]['True_Type']) {
386 $table_fields[$i]['pma_type'] = 'set';
387 $table_fields[$i]['wrap'] = '';
390 $table_fields[$i]['pma_type'] = 'enum';
391 $table_fields[$i]['wrap'] = '';
394 if (!$timestamp_seen) { // can only occur once per table
396 $table_fields[$i]['first_timestamp'] = true;
398 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
399 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
403 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
404 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
408 $field = $table_fields[$i];
409 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
411 if (-1 === $field['len']) {
412 $field['len'] = PMA_DBI_field_len($vresult, $i);
414 //Call validation when the form submited...
415 $unnullify_trigger = $chg_evt_handler . "=\"return Validator('". PMA_escapeJsString($field['Field_md5']) . "', '"
416 . PMA_escapeJsString($jsvkey) . "','".$field['pma_type']."')\"";
418 // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
419 $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
420 $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]';
423 if ($field['Type'] == 'datetime'
424 && ! isset($field['Default'])
425 && ! is_null($field['Default'])
426 && ($insert_mode ||
! isset($vrow[$field['Field']]))) {
428 // UPDATE case with an NULL value
429 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
432 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
433 <td
<?php
echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ?
'rowspan="2"' : ''); ?
> align
="center">
434 <?php
echo $field['Field_title']; ?
>
435 <input type
="hidden" name
="fields_name<?php echo $field_name_appendix; ?>" value
="<?php echo $field['Field_html']; ?>"/>
437 <?php
if ($cfg['ShowFieldTypesInDataEditView']) { ?
>
438 <td align
="center"<?php
echo $field['wrap']; ?
>>
439 <?php
echo $field['pma_type']; ?
>
444 // Prepares the field value
445 $real_null_value = FALSE;
446 $special_chars_encoded = '';
449 if (is_null($vrow[$field['Field']])) {
450 $real_null_value = TRUE;
451 $vrow[$field['Field']] = '';
453 $data = $vrow[$field['Field']];
454 } elseif ($field['True_Type'] == 'bit') {
455 $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
457 // special binary "characters"
458 if ($field['is_binary'] ||
($field['is_blob'] && ! $cfg['ProtectBinary'])) {
459 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
460 $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]);
461 $field['display_binary_as_hex'] = true;
463 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
466 $special_chars = htmlspecialchars($vrow[$field['Field']]);
468 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
469 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
471 $data = $vrow[$field['Field']];
472 } // end if... else...
473 // If a timestamp field value is not included in an update
474 // statement MySQL auto-update it to the current timestamp;
475 // however, things have changed since MySQL 4.1, so
476 // it's better to set a fields_prev in this situation
477 $backup_field = '<input type="hidden" name="fields_prev'
478 . $field_name_appendix . '" value="'
479 . htmlspecialchars($vrow[$field['Field']]) . '" />';
481 // (we are inserting)
482 // display default values
483 if (!isset($field['Default'])) {
484 $field['Default'] = '';
485 $real_null_value = TRUE;
488 $data = $field['Default'];
490 if ($field['True_Type'] == 'bit') {
491 $special_chars = PMA_convert_bit_default_value($field['Default']);
493 $special_chars = htmlspecialchars($field['Default']);
496 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
497 // this will select the UNHEX function while inserting
498 if (($field['is_binary'] ||
($field['is_blob'] && ! $cfg['ProtectBinary'])) && $_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
499 $field['display_binary_as_hex'] = true;
503 $idindex = ($o_rows * $fields_cnt) +
$i +
1;
504 $tabindex = (($idindex - 1) * 3) +
1;
506 // The function column
507 // -------------------
508 // We don't want binary data to be destroyed
509 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
510 // stored or retrieved" so it does not mean that the contents is
512 if ($cfg['ShowFunctionFields']) {
513 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
514 ||
($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
515 echo ' <td align="center">' . __('Binary') . '</td>' . "\n";
516 } elseif (strstr($field['True_Type'], 'enum') ||
strstr($field['True_Type'], 'set')) {
517 echo ' <td align="center">--</td>' . "\n";
521 <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">
526 // Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
527 // or something similar. Then directly look up the entry in the RestrictFunctions array,
528 // which will then reveal the available dropdown options
529 if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
530 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
531 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
532 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
533 $default_function = $cfg['DefaultFunctions'][$current_func_type];
536 $default_function = '';
539 $dropdown_built = array();
540 $op_spacing_needed = FALSE;
542 // what function defined as default?
543 // for the first timestamp we don't set the default function
544 // if there is a default value for the timestamp
545 // (not including CURRENT_TIMESTAMP)
546 // and the column does not have the
547 // ON UPDATE DEFAULT TIMESTAMP attribute.
549 if ($field['True_Type'] == 'timestamp'
550 && empty($field['Default'])
551 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
552 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
555 // For primary keys of type char(36) or varchar(36) UUID if the default function
556 // Only applies to insert mode, as it would silently trash data on updates.
558 && $field['Key'] == 'PRI'
559 && ($field['Type'] == 'char(36)' ||
$field['Type'] == 'varchar(36)')
561 $default_function = $cfg['DefaultFunctions']['pk_char36'];
564 // this is set only when appropriate and is always true
565 if (isset($field['display_binary_as_hex'])) {
566 $default_function = 'UNHEX';
569 // loop on the dropdown array and print all available options for that field.
570 foreach ($dropdown as $each_dropdown){
572 if ($default_function === $each_dropdown) {
573 echo ' selected="selected"';
575 echo '>' . $each_dropdown . '</option>' . "\n";
576 $dropdown_built[$each_dropdown] = 'TRUE';
577 $op_spacing_needed = TRUE;
580 // For compatibility's sake, do not let out all other functions. Instead
581 // print a separator (blank) and then show ALL functions which weren't shown
583 $cnt_functions = count($cfg['Functions']);
584 for ($j = 0; $j < $cnt_functions; $j++
) {
585 if (!isset($dropdown_built[$cfg['Functions'][$j]]) ||
$dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
586 // Is current function defined as default?
587 $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
588 ||
(!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
589 ?
' selected="selected"'
591 if ($op_spacing_needed == TRUE) {
593 echo '<option value="">--------</option>' . "\n";
594 $op_spacing_needed = FALSE;
598 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
607 } // end if ($cfg['ShowFunctionFields'])
612 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
614 if ($field['Null'] == 'YES') {
615 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
616 if ($real_null_value && !$field['first_timestamp']) {
621 echo ' <input type="checkbox" tabindex="' . ($tabindex +
$tabindex_for_null) . '"'
622 . ' name="fields_null' . $field_name_appendix . '"';
623 if ($real_null_value && !$field['first_timestamp']) {
624 echo ' checked="checked"';
626 echo ' id="field_' . ($idindex) . '_2"';
627 $onclick = ' onclick="if (this.checked) {nullify(';
628 if (strstr($field['True_Type'], 'enum')) {
629 if (strlen($field['Type']) > 20) {
634 } elseif (strstr($field['True_Type'], 'set')) {
636 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
637 // foreign key in a drop-down
639 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
640 // foreign key with a browsing icon
645 $onclick .= '\'' . PMA_escapeJsString($field['Field_html']) . '\', \'' . $field['Field_md5'] . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
648 echo ' </td>' . "\n";
650 // The value column (depends on type)
652 // See bug #1667887 for the reason why we don't use the maxlength
656 if ($foreignData['foreign_link'] == true) {
657 echo $backup_field . "\n";
659 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>"
661 <input type
="hidden" name
="fields<?php echo $field_name_appendix; ?>"
662 value
="" id
="field_<?php echo ($idindex); ?>_3A" />
663 <input type
="text" name
="field_<?php echo $field_name_appendix_md5; ?>"
664 class="textfield" <?php
echo $unnullify_trigger; ?
>
665 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
666 id
="field_<?php echo ($idindex); ?>_3"
667 value
="<?php echo htmlspecialchars($data); ?>" />
668 <script type
="text/javascript">
670 document
.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
671 document
.write(' href="browse_foreigners.php?');
672 document
.write('<?php echo PMA_generate_common_url($db, $table); ?>');
673 document
.writeln('&field=<?php echo PMA_escapeJsString(urlencode($field['Field
']) . $browse_foreigners_uri); ?>">');
674 document
.writeln('<?php echo str_replace("'", "\'
", $titles['Browse']); ?></a>');
678 } elseif (is_array($foreignData['disp_row'])) {
679 echo $backup_field . "\n
";
681 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>"
683 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>"
684 value="" id="field_
<?php
echo $idindex; ?
>_3A
" />
685 <select name="field_
<?php
echo $field_name_appendix_md5; ?
>"
686 <?php echo $unnullify_trigger; ?>
687 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
688 id="field_
<?php
echo ($idindex); ?
>_3
">
689 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
693 unset($foreignData['disp_row']);
694 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
698 <tr class="<?php
echo $odd_row ?
'odd' : 'even'; ?
>">
699 <td colspan="5" align="right
">
700 <?php echo $backup_field . "\n
"; ?>
701 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
702 rows="<?php
echo ($cfg['TextareaRows']*2); ?
>"
703 cols="<?php
echo ($cfg['TextareaCols']*2); ?
>"
704 dir="<?php
echo $text_dir; ?
>"
705 id="field_
<?php
echo ($idindex); ?
>_3
"
706 <?php echo $unnullify_trigger; ?>
707 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
708 ><?php echo $special_chars_encoded; ?></textarea>
710 } elseif (strstr($field['pma_type'], 'text')) {
711 echo $backup_field . "\n
";
713 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
714 rows="<?php
echo $cfg['TextareaRows']; ?
>"
715 cols="<?php
echo $cfg['TextareaCols']; ?
>"
716 dir="<?php
echo $text_dir; ?
>"
717 id="field_
<?php
echo ($idindex); ?
>_3
"
718 <?php echo $unnullify_trigger; ?>
719 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
720 ><?php echo $special_chars_encoded; ?></textarea>
723 if (strlen($special_chars) > 32000) {
725 echo ' <td>' . __(' Because of its length,<br /> this column might not be editable ');
727 } elseif ($field['pma_type'] == 'enum') {
728 if (! isset($table_fields[$i]['values'])) {
729 $table_fields[$i]['values'] = array();
730 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
731 // Removes automatic MySQL escape format
732 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
733 $table_fields[$i]['values'][] = array(
735 'html' => htmlspecialchars($val),
739 $field_enum_values = $table_fields[$i]['values'];
741 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="enum
" />
742 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>" value="" />
744 echo "\n
" . ' ' . $backup_field . "\n
";
746 // show dropdown or radio depend on length
747 if (strlen($field['Type']) > 20) {
749 <select name="field_
<?php
echo $field_name_appendix_md5; ?
>"
750 <?php echo $unnullify_trigger; ?>
751 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
752 id="field_
<?php
echo ($idindex); ?
>_3
">
753 <option value=""> </option>
757 foreach ($field_enum_values as $enum_value) {
759 echo '<option value="' . $enum_value['html
'] . '"';
760 if ($data == $enum_value['plain']
762 && (! isset($where_clause) || $field['Null'] != 'YES')
763 && isset($field['Default'])
764 && $enum_value['plain'] == $field['Default'])) {
765 echo ' selected="selected
"';
767 echo '>' . $enum_value['html'] . '</option>' . "\n
";
775 foreach ($field_enum_values as $enum_value) {
777 echo '<input type="radio
" name="field_
' . $field_name_appendix_md5 . '"';
778 echo ' value="' . $enum_value['html
'] . '"';
779 echo ' id="field_
' . ($idindex) . '_3_
' . $j . '"';
780 echo $unnullify_trigger;
781 if ($data == $enum_value['plain']
783 && (! isset($where_clause) || $field['Null'] != 'YES')
784 && isset($field['Default'])
785 && $enum_value['plain'] == $field['Default'])) {
786 echo ' checked="checked
"';
788 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
789 echo '<label for="field_
' . $idindex . '_3_
' . $j . '">'
790 . $enum_value['html'] . '</label>' . "\n
";
794 } elseif ($field['pma_type'] == 'set') {
795 if (! isset($table_fields[$i]['values'])) {
796 $table_fields[$i]['values'] = array();
797 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
798 $table_fields[$i]['values'][] = array(
800 'html' => htmlspecialchars($val),
803 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
805 $field_set_values = $table_fields[$i]['values'];
806 $select_size = $table_fields[$i]['select_size'];
808 $vset = array_flip(explode(',', $data));
809 echo $backup_field . "\n
";
811 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="set
" />
812 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>" value="" />
813 <select name="field_
<?php
echo $field_name_appendix_md5; ?
>"
814 size="<?php
echo $select_size; ?
>"
815 multiple="multiple
" <?php echo $unnullify_trigger; ?>
816 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
817 id="field_
<?php
echo ($idindex); ?
>_3
">
819 foreach ($field_set_values as $field_set_value) {
821 echo '<option value="' . $field_set_value['html
'] . '"';
822 if (isset($vset[$field_set_value['plain']])) {
823 echo ' selected="selected
"';
825 echo '>' . $field_set_value['html'] . '</option>' . "\n
";
831 // We don't want binary data destroyed
832 elseif ($field['is_binary'] || $field['is_blob']) {
833 if (($cfg['ProtectBinary'] && $field['is_blob'])
834 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
837 $bs_reference_exists = FALSE;
839 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
842 $PMA_Config = $GLOBALS['PMA_Config'];
844 if (!empty($PMA_Config))
846 $requiredTblType = $PMA_Config->get('PBXT_NAME');
848 if ($requiredTblType == strtolower ($tbl_type))
850 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
852 // check if blobstreaming plugins exist
855 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
857 if (!empty($bs_tables) && strlen($db) > 0)
859 $bs_tables = $bs_tables[$db];
861 if (isset($bs_tables))
863 $allBSTablesExist = TRUE;
865 foreach ($bs_tables as $table_key=>$bs_tbl)
866 if (!$bs_tables[$table_key]['Exists'])
868 $allBSTablesExist = FALSE;
872 if ($allBSTablesExist)
873 $bs_reference_exists = PMA_BS_ReferenceExists($data, $db);
874 } // end if (isset($bs_tables))
875 } // end if (!empty($bs_tables) && strlen($db) > 0)
876 } // end if ($pluginsExist)
877 } // end if ($requiredTblType == strtolower ($tbl_type))
878 } // end if (!empty($PMA_Config))
879 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
881 if ($bs_reference_exists)
883 echo '<input type="hidden
" name="remove_blob_ref_
' . $field['Field_md5
'] . $vkey . '" value="' . $data . '" />';
884 echo '<input type="checkbox
" name="remove_blob_repo_
' . $field['Field_md5
'] . $vkey . '" /> ' . __('Remove BLOB Repository Reference') . "<br
/>";
885 echo PMA_BS_CreateReferenceLink($data, $db);
890 echo __('Binary - do not edit');
892 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
893 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
897 } // end if ($bs_reference_exists)
899 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="protected" />
900 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>" value="" />
902 } elseif ($field['is_blob']) {
904 echo $backup_field . "\n
";
906 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
907 rows="<?php
echo $cfg['TextareaRows']; ?
>"
908 cols="<?php
echo $cfg['TextareaCols']; ?
>"
909 dir="<?php
echo $text_dir; ?
>"
910 id="field_
<?php
echo ($idindex); ?
>_3
"
911 <?php echo $unnullify_trigger; ?>
912 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
913 ><?php echo $special_chars_encoded; ?></textarea>
917 // field size should be at least 4 and max 40
918 $fieldsize = min(max($field['len'], 4), 40);
920 echo $backup_field . "\n
";
922 <input type="text
" name="fields
<?php
echo $field_name_appendix; ?
>"
923 value="<?php
echo $special_chars; ?
>" size="<?php
echo $fieldsize; ?
>"
924 class="textfield
" <?php echo $unnullify_trigger; ?>
925 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
926 id="field_
<?php
echo ($idindex); ?
>_3
" />
928 } // end if...elseif...else
930 // Upload choice (only for BLOBs because the binary
931 // attribute does not imply binary contents)
932 // (displayed whatever value the ProtectBinary has)
934 if ($is_upload && $field['is_blob']) {
935 // check if field type is of longblob
936 if ($field['pma_type'] == "longblob
")
938 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
941 $PMA_Config = $GLOBALS['PMA_Config'];
943 // is PMA_Config's data loaded? continue only if it is
944 if (!empty($PMA_Config))
946 $requiredTblType = $PMA_Config->get('PBXT_NAME');
948 if ($requiredTblType == strtolower ($tbl_type))
950 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
952 // check if blobstreaming plugins exist
955 $curlExists = $PMA_Config->get('CURL_EXISTS');
957 // check if CURL exists
960 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
962 // check for BLOBStreamable databases and if current database name is provided
963 if (!empty($bs_tables) && strlen($db) > 0)
965 $bs_tables = $bs_tables[$db];
967 // check if reference to BLOBStreaming tables exists
968 if (isset($bs_tables))
970 $allBSTablesExist = TRUE;
972 foreach ($bs_tables as $table_key=>$bs_tbl)
973 if (!$bs_tables[$table_key]['Exists'])
975 $allBSTablesExist = FALSE;
979 // check if necessary BLOBStreaming tables exist
980 if ($allBSTablesExist)
983 echo '<input type="checkbox
" name="upload_blob_repo_
' . $field['Field_md5
'] . $vkey . '" /> ' . __('Upload to BLOB repository');
984 } // end if ($allBSTablesExist)
985 } // end if (isset($bs_tables)
986 } // end if (!empty($bs_tables) && strlen ($db) > 0)
987 } // end if ($curlExists)
988 } // end if ($pluginsExist)
989 } // end if ($requiredTblType == strtolower ($tbl_type))
990 } // end if (!empty($PMA_Config))
991 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
995 echo '<input type="file
" name="fields_upload_
' . $field['Field_md5
'] . $vkey . '" class="textfield
" id="field_
' . $idindex . '_3
" size="10" ' . $unnullify_trigger . '/> ';
997 // find maximum upload size, based on field type
999 * @todo with functions this is not so easy, as you can basically
1000 * process any data with function like MD5
1002 $max_field_sizes = array(
1003 'tinyblob' => '256',
1005 'mediumblob' => '16777216',
1006 'longblob' => '4294967296'); // yeah, really
1008 $this_field_max_size = $max_upload_size; // from PHP max
1009 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
1010 $this_field_max_size = $max_field_sizes[$field['pma_type']];
1012 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n
";
1013 // do not generate here the MAX_FILE_SIZE, because we should
1014 // put only one in the form to accommodate the biggest field
1015 if ($this_field_max_size > $biggest_max_file_size) {
1016 $biggest_max_file_size = $this_field_max_size;
1020 if (!empty($cfg['UploadDir'])) {
1021 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
1022 if ($files === FALSE) {
1023 echo ' <font color="red
">' . __('Error') . '</font><br />' . "\n
";
1024 echo ' ' . __('The directory you set for upload work cannot be reached') . "\n
";
1025 } elseif (!empty($files)) {
1027 echo ' <i>' . __('Or') . '</i>' . ' ' . __('web server upload directory') . ':<br />' . "\n
";
1028 echo ' <select size="1" name="fields_uploadlocal_
' . $field['Field_md5
'] . $vkey . '">' . "\n
";
1029 echo ' <option value="" selected="selected
"></option>' . "\n
";
1031 echo ' </select>' . "\n
";
1033 } // end if (web-server upload directory)
1034 } // end elseif (binary or blob)
1036 // field size should be at least 4 and max 40
1037 $fieldsize = min(max($field['len'], 4), 40);
1038 echo $backup_field . "\n
";
1039 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n
") !== FALSE)) {
1042 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
1043 rows="<?php
echo $cfg['CharTextareaRows']; ?
>"
1044 cols="<?php
echo $cfg['CharTextareaCols']; ?
>"
1045 dir="<?php
echo $text_dir; ?
>"
1046 id="field_
<?php
echo ($idindex); ?
>_3
"
1047 <?php echo $unnullify_trigger; ?>
1048 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
1049 ><?php echo $special_chars_encoded; ?></textarea>
1053 <input type="text
" name="fields
<?php
echo $field_name_appendix; ?
>"
1054 value="<?php
echo $special_chars; ?
>" size="<?php
echo $fieldsize; ?
>"
1055 class="textfield
" <?php echo $unnullify_trigger; ?>
1056 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
1057 id="field_
<?php
echo ($idindex); ?
>_3
" />
1059 if ($field['Extra'] == 'auto_increment') {
1061 <input type="hidden
" name="auto_increment
<?php
echo $field_name_appendix; ?
>" value="1" />
1064 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
1066 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="timestamp
" />
1069 if (substr($field['pma_type'], 0, 8) == 'datetime') {
1071 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="datetime
" />
1074 if ($field['True_Type'] == 'bit') {
1076 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="bit
" />
1079 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
1080 // the _3 suffix points to the date field
1081 // the _2 suffix points to the corresponding NULL checkbox
1082 // in dateFormat, 'yy' means the year with 4 digits
1084 <script type="text
/javascript
">
1087 $('#field_<?php echo ($idindex); ?>_3').datepicker({
1092 <?php echo ($field['pma_type'] == 'date' ? "showTime
: false,":"showTime
: true,"); ?>
1093 dateFormat: 'yy-mm-dd',
1095 constrainInput: false
1108 $odd_row = !$odd_row;
1111 echo ' </tbody></table><br />';
1112 } // end foreach on multi-edit
1117 <table border="0" cellpadding="5" cellspacing="0">
1119 <td valign="middle
" nowrap="nowrap
">
1120 <select name="submit_type
" tabindex="<?php
echo ($tabindex +
$tabindex_for_value +
1); ?
>">
1122 if (isset($where_clause)) {
1124 <option value="save
"><?php echo __('Save'); ?></option>
1128 <option value="insert
"><?php echo __('Insert as new row'); ?></option>
1129 <option value="insertignore
"><?php echo __('Insert as new row and ignore errors'); ?></option>
1130 <option value="showinsert
"><?php echo __('Show insert query'); ?></option>
1135 if (!isset($after_insert)) {
1136 $after_insert = 'back';
1140 <td valign="middle
">
1141 <strong><?php echo __('and then'); ?></strong>
1143 <td valign="middle
" nowrap="nowrap
">
1144 <select name="after_insert
">
1145 <option value="back
" <?php echo ($after_insert == 'back' ? 'selected="selected
"' : ''); ?>><?php echo __('Go back to previous page'); ?></option>
1146 <option value="new_insert
" <?php echo ($after_insert == 'new_insert' ? 'selected="selected
"' : ''); ?>><?php echo __('Insert another new row'); ?></option>
1148 if (isset($where_clause)) {
1150 <option value="same_insert
" <?php echo ($after_insert == 'same_insert' ? 'selected="selected
"' : ''); ?>><?php echo __('Go back to this page'); ?></option>
1152 // If we have just numeric primary key, we can also edit next
1153 // in 2.8.2, we were looking for `field_name` = numeric_value
1154 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1155 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1156 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause)) {
1158 <option value="edit_next
" <?php echo ($after_insert == 'edit_next' ? 'selected="selected
"' : ''); ?>><?php echo __('Edit next row'); ?></option>
1169 <?php echo PMA_showHint(__('Use TAB key to move from value to value, or CTRL+arrows to move anywhere')); ?>
1171 <td colspan="3" align="right
" valign="middle
">
1172 <input type="submit
" value="<?php
echo __('Go'); ?
>" tabindex="<?php
echo ($tabindex +
$tabindex_for_value +
6); ?
>" id="buttonYes
" />
1173 <input type="reset
" value="<?php
echo __('Reset'); ?
>" tabindex="<?php
echo ($tabindex +
$tabindex_for_value +
7); ?
>" />
1178 <?php if ($biggest_max_file_size > 0) {
1179 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n
";
1185 <!-- Restart insertion form -->
1186 <form method="post
" action="tbl_replace
.php
" name="restartForm
" >
1187 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1188 <input type="hidden
" name="goto" value="<?php
echo htmlspecialchars($GLOBALS['goto']); ?
>" />
1189 <input type="hidden
" name="err_url
" value="<?php
echo htmlspecialchars($err_url); ?
>" />
1190 <input type="hidden
" name="sql_query
" value="<?php
echo htmlspecialchars($sql_query); ?
>" />
1192 if (isset($where_clauses)) {
1193 foreach ($where_clause_array as $key_id => $where_clause) {
1194 echo '<input type="hidden
" name="where_clause
[' . $key_id . ']" value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n
";
1197 $tmp = '<select name="insert_rows
" id="insert_rows
" onchange="this
.form
.submit();" >' . "\n
";
1198 $option_values = array(1,2,5,10,15,20,30,40);
1199 foreach ($option_values as $value) {
1200 $tmp .= '<option value="' . $value . '"';
1201 if ($value == $cfg['InsertRows']) {
1202 $tmp .= ' selected="selected
"';
1204 $tmp .= '>' . $value . '</option>' . "\n
";
1206 $tmp .= '</select>' . "\n
";
1207 echo "\n
" . sprintf(__('Restart insertion with %s rows'), $tmp);
1209 echo '<noscript><input type="submit
" value="' . __('Go
') . '" /></noscript>' . "\n
";
1210 echo '</form>' . "\n
";
1214 * Displays the footer
1216 require_once './libraries/footer.inc.php';