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)
13 * Gets the variables sent or posted to this script and displays the header
15 require_once './libraries/common.inc.php';
18 * Ensures db and table are valid, else moves to the "parent" script
20 require_once './libraries/db_table_exists.lib.php';
23 * Sets global variables.
24 * Here it's better to use a if, instead of the '?' operator
25 * to avoid setting a variable to '' when it's not present in $_REQUEST
27 if (isset($_REQUEST['where_clause'])) {
28 $where_clause = $_REQUEST['where_clause'];
30 if (isset($_REQUEST['clause_is_unique'])) {
31 $clause_is_unique = $_REQUEST['clause_is_unique'];
33 if (isset($_SESSION['edit_next'])) {
34 $where_clause = $_SESSION['edit_next'];
35 unset($_SESSION['edit_next']);
36 $after_insert = 'edit_next';
38 if (isset($_REQUEST['sql_query'])) {
39 $sql_query = $_REQUEST['sql_query'];
41 if (isset($_REQUEST['ShowFunctionFields'])) {
42 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
44 if (isset($_REQUEST['ShowFieldTypesInDataEditView'])) {
45 $cfg['ShowFieldTypesInDataEditView'] = $_REQUEST['ShowFieldTypesInDataEditView'];
49 * load relation data, foreign keys
51 require_once './libraries/relation.lib.php';
56 require_once './libraries/file_listing.php';
60 * Defines the url to return to in case of error in a sql statement
61 * (at this point, $GLOBALS['goto'] will be set but could be empty)
63 if (empty($GLOBALS['goto'])) {
65 // avoid a problem (see bug #2202709)
66 $GLOBALS['goto'] = 'tbl_sql.php';
68 $GLOBALS['goto'] = 'db_sql.php';
72 * @todo check if we could replace by "db_|tbl_" - please clarify!?
76 'sql_query' => $sql_query
79 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
80 $_url_params['table'] = $table;
83 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
88 * Sets parameters for links
89 * where is this variable used?
90 * replace by PMA_generate_common_url($url_params);
92 $url_query = PMA_generate_common_url($url_params, 'html', '');
95 * get table information
96 * @todo should be done by a Table object
98 require_once './libraries/tbl_info.inc.php';
101 * Get comments for table fileds/columns
103 $comments_map = array();
105 if ($GLOBALS['cfg']['ShowPropertyComments']) {
106 $comments_map = PMA_getComments($db, $table);
110 * START REGULAR OUTPUT
114 * used in ./libraries/header.inc.php to load JavaScript library file
116 $GLOBALS['js_include'][] = 'tbl_change.js';
117 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
118 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
120 * HTTP and HTML headers
122 require_once './libraries/header.inc.php';
125 * Displays the query submitted and its result
127 * @todo where does $disp_message and $disp_query come from???
129 if (! empty($disp_message)) {
130 if (! isset($disp_query)) {
133 PMA_showMessage($disp_message, $disp_query);
137 * Displays top menu links
139 require_once './libraries/tbl_links.inc.php';
143 * Get the analysis of SHOW CREATE TABLE for this table
144 * @todo should be handled by class Table
146 $show_create_table = PMA_DBI_fetch_value(
147 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
149 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
150 unset($show_create_table);
153 * Get the list of the fields of the current table
155 PMA_DBI_select_db($db);
156 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
157 null, null, null, PMA_DBI_QUERY_STORE
);
159 if (isset($where_clause)) {
160 // when in edit mode load all selected rows from table
161 $insert_mode = false;
162 if (is_array($where_clause)) {
163 $where_clause_array = $where_clause;
165 $where_clause_array = array(0 => $where_clause);
169 $found_unique_key = false;
170 $where_clauses = array();
172 foreach ($where_clause_array as $key_id => $where_clause) {
173 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';';
174 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE
);
175 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
176 $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
179 if (! $rows[$key_id]) {
180 unset($rows[$key_id], $where_clause_array[$key_id]);
181 PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query);
183 require_once './libraries/footer.inc.php';
184 } else { // end if (no row returned)
185 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
186 list($unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true);
187 if (! empty($unique_condition)) {
188 $found_unique_key = true;
190 unset($unique_condition, $tmp_clause_is_unique);
194 // no primary key given, just load first row - but what happens if table is empty?
196 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE
);
197 $rows = array_fill(0, $cfg['InsertRows'], false);
200 // retrieve keys into foreign fields, if any
201 $foreigners = PMA_getForeigners($db, $table);
207 // autocomplete feature of IE kills the "onchange" event handler and it
208 // must be replaced by the "onpropertychange" one in this case
209 $chg_evt_handler = (PMA_USR_BROWSER_AGENT
== 'IE' && PMA_USR_BROWSER_VER
>= 5 && PMA_USR_BROWSER_VER
< 7)
212 // Had to put the URI because when hosted on an https server,
213 // some browsers send wrongly this form to the http server.
215 if ($cfg['CtrlArrowsMoving']) {
217 <!-- Set on key handler
for moving using by Ctrl+arrows
-->
218 <script src
="./js/keyhandler.js" type
="text/javascript"></script
>
219 <script type
="text/javascript">
221 var switch_movement
= 0;
222 document
.onkeydown
= onKeyDownArrowsHandler
;
228 $_form_params = array(
231 'goto' => $GLOBALS['goto'],
232 'err_url' => $err_url,
233 'sql_query' => $sql_query,
235 if (isset($where_clauses)) {
236 foreach ($where_clause_array as $key_id => $where_clause) {
237 $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
240 if (isset($clause_is_unique)) {
241 $_form_params['clause_is_unique'] = $clause_is_unique;
246 <!-- Insert
/Edit form
-->
247 <form method
="post" action
="tbl_replace.php" name
="insertForm" <?php
if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?
>>
249 echo PMA_generate_common_hidden_inputs($_form_params);
251 $titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
253 // Set if we passed the first timestamp field
255 $fields_cnt = count($table_fields);
258 $tabindex_for_function = +
3000;
259 $tabindex_for_null = +
6000;
260 $tabindex_for_value = 0;
262 $biggest_max_file_size = 0;
264 // user can toggle the display of Function column
265 // (currently does not work for multi-edits)
266 $url_params['db'] = $db;
267 $url_params['table'] = $table;
268 if (isset($where_clause)) {
269 $url_params['where_clause'] = trim($where_clause);
271 if (! empty($sql_query)) {
272 $url_params['sql_query'] = $sql_query;
275 if (! $cfg['ShowFunctionFields'] ||
! $cfg['ShowFieldTypesInDataEditView']) {
278 if (! $cfg['ShowFunctionFields']) {
279 $this_url_params = array_merge($url_params,
280 array('ShowFunctionFields' => 1, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
281 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . __('Function') . '</a>' . "\n";
283 if (! $cfg['ShowFieldTypesInDataEditView']) {
284 $this_other_url_params = array_merge($url_params,
285 array('ShowFieldTypesInDataEditView' => 1, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
286 echo ' : <a href="tbl_change.php' . PMA_generate_common_url($this_other_url_params) . '">' . __('Type') . '</a>' . "\n";
289 foreach ($rows as $row_id => $vrow) {
290 if ($vrow === false) {
295 $browse_foreigners_uri = '&pk=' . $row_id;
296 $vkey = '[multi_edit][' . $jsvkey . ']';
298 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ?
$result[$row_id] : $result);
299 if ($insert_mode && $row_id > 0) {
300 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_check_' . $row_id . '" />';
301 echo '<label for="insert_ignore_check_' . $row_id . '">' . __('Ignore') . '</label><br />' . "\n";
307 <th
><?php
echo __('Column'); ?
></th
>
310 if ($cfg['ShowFieldTypesInDataEditView']) {
311 $this_url_params = array_merge($url_params,
312 array('ShowFieldTypesInDataEditView' => 0, 'ShowFunctionFields' => $cfg['ShowFunctionFields'], 'goto' => 'sql.php'));
313 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Type') . '</a></th>' . "\n";
316 if ($cfg['ShowFunctionFields']) {
317 $this_url_params = array_merge($url_params,
318 array('ShowFunctionFields' => 0, 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'));
319 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . __('Hide') . '">' . __('Function') . '</a></th>' . "\n";
322 <th
><?php
echo __('Null'); ?
></th
>
323 <th
><?php
echo __('Value'); ?
></th
>
328 <th colspan
="5" align
="right" class="tblFooters">
329 <input type
="submit" value
="<?php echo __('Go'); ?>" />
335 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
336 $m_rows = $o_rows +
1;
339 for ($i = 0; $i < $fields_cnt; $i++
) {
340 if (! isset($table_fields[$i]['processed'])) {
341 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
342 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
343 // True_Type contains only the type (stops at first bracket)
344 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
348 // Current date should not be set as default if the field is NULL
349 // for the current row, but do not put here the current datetime
350 // if there is a default value (the real default value will be set
351 // in the Default value logic below)
353 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
354 // $field['Default'] is not set if it contains NULL:
355 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
356 // but, look what we get if we switch to iso: (Default is NULL)
357 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
358 // so I force a NULL into it (I don't think it's possible
359 // to have an empty default value for DATETIME)
360 // then, the "if" after this one will work
361 if ($table_fields[$i]['Type'] == 'datetime'
362 && ! isset($table_fields[$i]['Default'])
363 && isset($table_fields[$i]['Null'])
364 && $table_fields[$i]['Null'] == 'YES') {
365 $table_fields[$i]['Default'] = null;
368 $table_fields[$i]['len'] =
369 preg_match('@float|double@', $table_fields[$i]['Type']) ?
100 : -1;
372 if (isset($comments_map[$table_fields[$i]['Field']])) {
373 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
374 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
375 . $table_fields[$i]['Field_html'] . '</span>';
377 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
381 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
382 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
383 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
384 $table_fields[$i]['first_timestamp'] = false;
385 switch ($table_fields[$i]['True_Type']) {
387 $table_fields[$i]['pma_type'] = 'set';
388 $table_fields[$i]['wrap'] = '';
391 $table_fields[$i]['pma_type'] = 'enum';
392 $table_fields[$i]['wrap'] = '';
395 if (!$timestamp_seen) { // can only occur once per table
397 $table_fields[$i]['first_timestamp'] = true;
399 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
400 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
404 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
405 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
409 $field = $table_fields[$i];
410 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
412 if (-1 === $field['len']) {
413 $field['len'] = PMA_DBI_field_len($vresult, $i);
415 //Call validation when the form submited...
416 $unnullify_trigger = $chg_evt_handler . "=\"return Validator('". PMA_escapeJsString($field['Field_md5']) . "', '"
417 . PMA_escapeJsString($jsvkey) . "','".$field['pma_type']."')\"";
419 // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
420 $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
421 $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]';
424 if ($field['Type'] == 'datetime'
425 && ! isset($field['Default'])
426 && ! is_null($field['Default'])
427 && ($insert_mode ||
! isset($vrow[$field['Field']]))) {
429 // UPDATE case with an NULL value
430 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
433 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
434 <td
<?php
echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ?
'rowspan="2"' : ''); ?
> align
="center">
435 <?php
echo $field['Field_title']; ?
>
436 <input type
="hidden" name
="fields_name<?php echo $field_name_appendix; ?>" value
="<?php echo $field['Field_html']; ?>"/>
438 <?php
if ($cfg['ShowFieldTypesInDataEditView']) { ?
>
439 <td align
="center"<?php
echo $field['wrap']; ?
>>
440 <?php
echo $field['pma_type']; ?
>
445 // Prepares the field value
446 $real_null_value = FALSE;
447 $special_chars_encoded = '';
450 if (is_null($vrow[$field['Field']])) {
451 $real_null_value = TRUE;
452 $vrow[$field['Field']] = '';
454 $data = $vrow[$field['Field']];
455 } elseif ($field['True_Type'] == 'bit') {
456 $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
458 // special binary "characters"
459 if ($field['is_binary'] ||
($field['is_blob'] && ! $cfg['ProtectBinary'])) {
460 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
461 $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]);
462 $field['display_binary_as_hex'] = true;
464 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
467 $special_chars = htmlspecialchars($vrow[$field['Field']]);
469 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
470 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
472 $data = $vrow[$field['Field']];
473 } // end if... else...
474 // If a timestamp field value is not included in an update
475 // statement MySQL auto-update it to the current timestamp;
476 // however, things have changed since MySQL 4.1, so
477 // it's better to set a fields_prev in this situation
478 $backup_field = '<input type="hidden" name="fields_prev'
479 . $field_name_appendix . '" value="'
480 . htmlspecialchars($vrow[$field['Field']]) . '" />';
482 // (we are inserting)
483 // display default values
484 if (!isset($field['Default'])) {
485 $field['Default'] = '';
486 $real_null_value = TRUE;
489 $data = $field['Default'];
491 if ($field['True_Type'] == 'bit') {
492 $special_chars = PMA_convert_bit_default_value($field['Default']);
494 $special_chars = htmlspecialchars($field['Default']);
497 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
498 // this will select the UNHEX function while inserting
499 if (($field['is_binary'] ||
($field['is_blob'] && ! $cfg['ProtectBinary'])) && $_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
500 $field['display_binary_as_hex'] = true;
504 $idindex = ($o_rows * $fields_cnt) +
$i +
1;
505 $tabindex = (($idindex - 1) * 3) +
1;
507 // The function column
508 // -------------------
509 // We don't want binary data to be destroyed
510 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
511 // stored or retrieved" so it does not mean that the contents is
513 if ($cfg['ShowFunctionFields']) {
514 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
515 ||
($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
516 echo ' <td align="center">' . __('Binary') . '</td>' . "\n";
517 } elseif (strstr($field['True_Type'], 'enum') ||
strstr($field['True_Type'], 'set')) {
518 echo ' <td align="center">--</td>' . "\n";
522 <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">
527 // Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
528 // or something similar. Then directly look up the entry in the RestrictFunctions array,
529 // which will then reveal the available dropdown options
530 if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
531 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
532 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
533 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
534 $default_function = $cfg['DefaultFunctions'][$current_func_type];
537 $default_function = '';
540 $dropdown_built = array();
541 $op_spacing_needed = FALSE;
543 // what function defined as default?
544 // for the first timestamp we don't set the default function
545 // if there is a default value for the timestamp
546 // (not including CURRENT_TIMESTAMP)
547 // and the column does not have the
548 // ON UPDATE DEFAULT TIMESTAMP attribute.
550 if ($field['True_Type'] == 'timestamp'
551 && empty($field['Default'])
552 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
553 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
556 // For primary keys of type char(36) or varchar(36) UUID if the default function
557 // Only applies to insert mode, as it would silently trash data on updates.
559 && $field['Key'] == 'PRI'
560 && ($field['Type'] == 'char(36)' ||
$field['Type'] == 'varchar(36)')
562 $default_function = $cfg['DefaultFunctions']['pk_char36'];
565 // this is set only when appropriate and is always true
566 if (isset($field['display_binary_as_hex'])) {
567 $default_function = 'UNHEX';
570 // loop on the dropdown array and print all available options for that field.
571 foreach ($dropdown as $each_dropdown){
573 if ($default_function === $each_dropdown) {
574 echo ' selected="selected"';
576 echo '>' . $each_dropdown . '</option>' . "\n";
577 $dropdown_built[$each_dropdown] = 'TRUE';
578 $op_spacing_needed = TRUE;
581 // For compatibility's sake, do not let out all other functions. Instead
582 // print a separator (blank) and then show ALL functions which weren't shown
584 $cnt_functions = count($cfg['Functions']);
585 for ($j = 0; $j < $cnt_functions; $j++
) {
586 if (!isset($dropdown_built[$cfg['Functions'][$j]]) ||
$dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
587 // Is current function defined as default?
588 $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
589 ||
(!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
590 ?
' selected="selected"'
592 if ($op_spacing_needed == TRUE) {
594 echo '<option value="">--------</option>' . "\n";
595 $op_spacing_needed = FALSE;
599 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
608 } // end if ($cfg['ShowFunctionFields'])
613 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
615 if ($field['Null'] == 'YES') {
616 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
617 if ($real_null_value && !$field['first_timestamp']) {
622 echo ' <input type="checkbox" tabindex="' . ($tabindex +
$tabindex_for_null) . '"'
623 . ' name="fields_null' . $field_name_appendix . '"';
624 if ($real_null_value && !$field['first_timestamp']) {
625 echo ' checked="checked"';
627 echo ' id="field_' . ($idindex) . '_2"';
628 $onclick = ' onclick="if (this.checked) {nullify(';
629 if (strstr($field['True_Type'], 'enum')) {
630 if (strlen($field['Type']) > 20) {
635 } elseif (strstr($field['True_Type'], 'set')) {
637 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
638 // foreign key in a drop-down
640 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
641 // foreign key with a browsing icon
646 $onclick .= '\'' . PMA_escapeJsString($field['Field_html']) . '\', \'' . $field['Field_md5'] . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
649 echo ' </td>' . "\n";
651 // The value column (depends on type)
653 // See bug #1667887 for the reason why we don't use the maxlength
657 if ($foreignData['foreign_link'] == true) {
658 echo $backup_field . "\n";
660 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>"
662 <input type
="hidden" name
="fields<?php echo $field_name_appendix; ?>"
663 value
="" id
="field_<?php echo ($idindex); ?>_3A" />
664 <input type
="text" name
="field_<?php echo $field_name_appendix_md5; ?>"
665 class="textfield" <?php
echo $unnullify_trigger; ?
>
666 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
667 id
="field_<?php echo ($idindex); ?>_3"
668 value
="<?php echo htmlspecialchars($data); ?>" />
669 <script type
="text/javascript">
671 document
.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
672 document
.write(' href="browse_foreigners.php?');
673 document
.write('<?php echo PMA_generate_common_url($db, $table); ?>');
674 document
.writeln('&field=<?php echo PMA_escapeJsString(urlencode($field['Field
']) . $browse_foreigners_uri); ?>">');
675 document
.writeln('<?php echo str_replace("'", "\'
", $titles['Browse']); ?></a>');
679 } elseif (is_array($foreignData['disp_row'])) {
680 echo $backup_field . "\n
";
682 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>"
684 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>"
685 value="" id="field_
<?php
echo $idindex; ?
>_3A
" />
686 <select name="field_
<?php
echo $field_name_appendix_md5; ?
>"
687 <?php echo $unnullify_trigger; ?>
688 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
689 id="field_
<?php
echo ($idindex); ?
>_3
">
690 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
694 unset($foreignData['disp_row']);
695 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
699 <tr class="<?php
echo $odd_row ?
'odd' : 'even'; ?
>">
700 <td colspan="5" align="right
">
701 <?php echo $backup_field . "\n
"; ?>
702 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
703 rows="<?php
echo ($cfg['TextareaRows']*2); ?
>"
704 cols="<?php
echo ($cfg['TextareaCols']*2); ?
>"
705 dir="<?php
echo $text_dir; ?
>"
706 id="field_
<?php
echo ($idindex); ?
>_3
"
707 <?php echo $unnullify_trigger; ?>
708 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
709 ><?php echo $special_chars_encoded; ?></textarea>
711 } elseif (strstr($field['pma_type'], 'text')) {
712 echo $backup_field . "\n
";
714 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
715 rows="<?php
echo $cfg['TextareaRows']; ?
>"
716 cols="<?php
echo $cfg['TextareaCols']; ?
>"
717 dir="<?php
echo $text_dir; ?
>"
718 id="field_
<?php
echo ($idindex); ?
>_3
"
719 <?php echo $unnullify_trigger; ?>
720 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
721 ><?php echo $special_chars_encoded; ?></textarea>
724 if (strlen($special_chars) > 32000) {
726 echo ' <td>' . __(' Because of its length,<br /> this column might not be editable ');
728 } elseif ($field['pma_type'] == 'enum') {
729 if (! isset($table_fields[$i]['values'])) {
730 $table_fields[$i]['values'] = array();
731 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
732 // Removes automatic MySQL escape format
733 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
734 $table_fields[$i]['values'][] = array(
736 'html' => htmlspecialchars($val),
740 $field_enum_values = $table_fields[$i]['values'];
742 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="enum
" />
743 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>" value="" />
745 echo "\n
" . ' ' . $backup_field . "\n
";
747 // show dropdown or radio depend on length
748 if (strlen($field['Type']) > 20) {
750 <select name="field_
<?php
echo $field_name_appendix_md5; ?
>"
751 <?php echo $unnullify_trigger; ?>
752 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
753 id="field_
<?php
echo ($idindex); ?
>_3
">
754 <option value=""> </option>
758 foreach ($field_enum_values as $enum_value) {
760 echo '<option value="' . $enum_value['html
'] . '"';
761 if ($data == $enum_value['plain']
763 && (! isset($where_clause) || $field['Null'] != 'YES')
764 && isset($field['Default'])
765 && $enum_value['plain'] == $field['Default'])) {
766 echo ' selected="selected
"';
768 echo '>' . $enum_value['html'] . '</option>' . "\n
";
776 foreach ($field_enum_values as $enum_value) {
778 echo '<input type="radio
" name="field_
' . $field_name_appendix_md5 . '"';
779 echo ' value="' . $enum_value['html
'] . '"';
780 echo ' id="field_
' . ($idindex) . '_3_
' . $j . '"';
781 echo $unnullify_trigger;
782 if ($data == $enum_value['plain']
784 && (! isset($where_clause) || $field['Null'] != 'YES')
785 && isset($field['Default'])
786 && $enum_value['plain'] == $field['Default'])) {
787 echo ' checked="checked
"';
789 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
790 echo '<label for="field_
' . $idindex . '_3_
' . $j . '">'
791 . $enum_value['html'] . '</label>' . "\n
";
795 } elseif ($field['pma_type'] == 'set') {
796 if (! isset($table_fields[$i]['values'])) {
797 $table_fields[$i]['values'] = array();
798 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
799 $table_fields[$i]['values'][] = array(
801 'html' => htmlspecialchars($val),
804 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
806 $field_set_values = $table_fields[$i]['values'];
807 $select_size = $table_fields[$i]['select_size'];
809 $vset = array_flip(explode(',', $data));
810 echo $backup_field . "\n
";
812 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="set
" />
813 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>" value="" />
814 <select name="field_
<?php
echo $field_name_appendix_md5; ?
>"
815 size="<?php
echo $select_size; ?
>"
816 multiple="multiple
" <?php echo $unnullify_trigger; ?>
817 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
818 id="field_
<?php
echo ($idindex); ?
>_3
">
820 foreach ($field_set_values as $field_set_value) {
822 echo '<option value="' . $field_set_value['html
'] . '"';
823 if (isset($vset[$field_set_value['plain']])) {
824 echo ' selected="selected
"';
826 echo '>' . $field_set_value['html'] . '</option>' . "\n
";
832 // We don't want binary data destroyed
833 elseif ($field['is_binary'] || $field['is_blob']) {
834 if (($cfg['ProtectBinary'] && $field['is_blob'])
835 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
838 $bs_reference_exists = FALSE;
840 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
843 $PMA_Config = $GLOBALS['PMA_Config'];
845 if (!empty($PMA_Config))
847 $requiredTblType = $PMA_Config->get('PBXT_NAME');
849 if ($requiredTblType == strtolower ($tbl_type))
851 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
853 // check if blobstreaming plugins exist
856 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
858 if (!empty($bs_tables) && strlen($db) > 0)
860 $bs_tables = $bs_tables[$db];
862 if (isset($bs_tables))
864 $allBSTablesExist = TRUE;
866 foreach ($bs_tables as $table_key=>$bs_tbl)
867 if (!$bs_tables[$table_key]['Exists'])
869 $allBSTablesExist = FALSE;
873 if ($allBSTablesExist)
874 $bs_reference_exists = PMA_BS_ReferenceExists($data, $db);
875 } // end if (isset($bs_tables))
876 } // end if (!empty($bs_tables) && strlen($db) > 0)
877 } // end if ($pluginsExist)
878 } // end if ($requiredTblType == strtolower ($tbl_type))
879 } // end if (!empty($PMA_Config))
880 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
882 if ($bs_reference_exists)
884 echo '<input type="hidden
" name="remove_blob_ref_
' . $field['Field_md5
'] . $vkey . '" value="' . $data . '" />';
885 echo '<input type="checkbox
" name="remove_blob_repo_
' . $field['Field_md5
'] . $vkey . '" /> ' . __('Remove BLOB Repository Reference') . "<br
/>";
886 echo PMA_BS_CreateReferenceLink($data, $db);
891 echo __('Binary - do not edit');
893 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
894 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
898 } // end if ($bs_reference_exists)
900 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="protected" />
901 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>" value="" />
903 } elseif ($field['is_blob']) {
905 echo $backup_field . "\n
";
907 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
908 rows="<?php
echo $cfg['TextareaRows']; ?
>"
909 cols="<?php
echo $cfg['TextareaCols']; ?
>"
910 dir="<?php
echo $text_dir; ?
>"
911 id="field_
<?php
echo ($idindex); ?
>_3
"
912 <?php echo $unnullify_trigger; ?>
913 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
914 ><?php echo $special_chars_encoded; ?></textarea>
918 // field size should be at least 4 and max 40
919 $fieldsize = min(max($field['len'], 4), 40);
921 echo $backup_field . "\n
";
923 <input type="text
" name="fields
<?php
echo $field_name_appendix; ?
>"
924 value="<?php
echo $special_chars; ?
>" size="<?php
echo $fieldsize; ?
>"
925 class="textfield
" <?php echo $unnullify_trigger; ?>
926 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
927 id="field_
<?php
echo ($idindex); ?
>_3
" />
929 } // end if...elseif...else
931 // Upload choice (only for BLOBs because the binary
932 // attribute does not imply binary contents)
933 // (displayed whatever value the ProtectBinary has)
935 if ($is_upload && $field['is_blob']) {
936 // check if field type is of longblob
937 if ($field['pma_type'] == "longblob
")
939 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
942 $PMA_Config = $GLOBALS['PMA_Config'];
944 // is PMA_Config's data loaded? continue only if it is
945 if (!empty($PMA_Config))
947 $requiredTblType = $PMA_Config->get('PBXT_NAME');
949 if ($requiredTblType == strtolower ($tbl_type))
951 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
953 // check if blobstreaming plugins exist
956 $curlExists = $PMA_Config->get('CURL_EXISTS');
958 // check if CURL exists
961 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
963 // check for BLOBStreamable databases and if current database name is provided
964 if (!empty($bs_tables) && strlen($db) > 0)
966 $bs_tables = $bs_tables[$db];
968 // check if reference to BLOBStreaming tables exists
969 if (isset($bs_tables))
971 $allBSTablesExist = TRUE;
973 foreach ($bs_tables as $table_key=>$bs_tbl)
974 if (!$bs_tables[$table_key]['Exists'])
976 $allBSTablesExist = FALSE;
980 // check if necessary BLOBStreaming tables exist
981 if ($allBSTablesExist)
984 echo '<input type="checkbox
" name="upload_blob_repo_
' . $field['Field_md5
'] . $vkey . '" /> ' . __('Upload to BLOB repository');
985 } // end if ($allBSTablesExist)
986 } // end if (isset($bs_tables)
987 } // end if (!empty($bs_tables) && strlen ($db) > 0)
988 } // end if ($curlExists)
989 } // end if ($pluginsExist)
990 } // end if ($requiredTblType == strtolower ($tbl_type))
991 } // end if (!empty($PMA_Config))
992 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
996 echo '<input type="file
" name="fields_upload_
' . $field['Field_md5
'] . $vkey . '" class="textfield
" id="field_
' . $idindex . '_3
" size="10" ' . $unnullify_trigger . '/> ';
998 // find maximum upload size, based on field type
1000 * @todo with functions this is not so easy, as you can basically
1001 * process any data with function like MD5
1003 $max_field_sizes = array(
1004 'tinyblob' => '256',
1006 'mediumblob' => '16777216',
1007 'longblob' => '4294967296'); // yeah, really
1009 $this_field_max_size = $max_upload_size; // from PHP max
1010 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
1011 $this_field_max_size = $max_field_sizes[$field['pma_type']];
1013 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n
";
1014 // do not generate here the MAX_FILE_SIZE, because we should
1015 // put only one in the form to accommodate the biggest field
1016 if ($this_field_max_size > $biggest_max_file_size) {
1017 $biggest_max_file_size = $this_field_max_size;
1021 if (!empty($cfg['UploadDir'])) {
1022 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
1023 if ($files === FALSE) {
1024 echo ' <font color="red
">' . __('Error') . '</font><br />' . "\n
";
1025 echo ' ' . __('The directory you set for upload work cannot be reached') . "\n
";
1026 } elseif (!empty($files)) {
1028 echo ' <i>' . __('Or') . '</i>' . ' ' . __('web server upload directory') . ':<br />' . "\n
";
1029 echo ' <select size="1" name="fields_uploadlocal_
' . $field['Field_md5
'] . $vkey . '">' . "\n
";
1030 echo ' <option value="" selected="selected
"></option>' . "\n
";
1032 echo ' </select>' . "\n
";
1034 } // end if (web-server upload directory)
1035 } // end elseif (binary or blob)
1037 // field size should be at least 4 and max 40
1038 $fieldsize = min(max($field['len'], 4), 40);
1039 echo $backup_field . "\n
";
1040 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n
") !== FALSE)) {
1043 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
1044 rows="<?php
echo $cfg['CharTextareaRows']; ?
>"
1045 cols="<?php
echo $cfg['CharTextareaCols']; ?
>"
1046 dir="<?php
echo $text_dir; ?
>"
1047 id="field_
<?php
echo ($idindex); ?
>_3
"
1048 <?php echo $unnullify_trigger; ?>
1049 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
1050 ><?php echo $special_chars_encoded; ?></textarea>
1054 <input type="text
" name="fields
<?php
echo $field_name_appendix; ?
>"
1055 value="<?php
echo $special_chars; ?
>" size="<?php
echo $fieldsize; ?
>"
1056 class="textfield
" <?php echo $unnullify_trigger; ?>
1057 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
1058 id="field_
<?php
echo ($idindex); ?
>_3
" />
1060 if ($field['Extra'] == 'auto_increment') {
1062 <input type="hidden
" name="auto_increment
<?php
echo $field_name_appendix; ?
>" value="1" />
1065 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
1067 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="timestamp
" />
1070 if (substr($field['pma_type'], 0, 8) == 'datetime') {
1072 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="datetime
" />
1075 if ($field['True_Type'] == 'bit') {
1077 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="bit
" />
1080 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
1081 // the _3 suffix points to the date field
1082 // the _2 suffix points to the corresponding NULL checkbox
1083 // in dateFormat, 'yy' means the year with 4 digits
1085 <script type="text
/javascript
">
1088 $('#field_<?php echo ($idindex); ?>_3').datepicker({
1093 <?php echo ($field['pma_type'] == 'date' ? "showTime
: false,":"showTime
: true,"); ?>
1094 dateFormat: 'yy-mm-dd',
1096 constrainInput: false
1109 $odd_row = !$odd_row;
1112 echo ' </tbody></table><br />';
1113 } // end foreach on multi-edit
1118 <table border="0" cellpadding="5" cellspacing="0">
1120 <td valign="middle
" nowrap="nowrap
">
1121 <select name="submit_type
" tabindex="<?php
echo ($tabindex +
$tabindex_for_value +
1); ?
>">
1123 if (isset($where_clause)) {
1125 <option value="save
"><?php echo __('Save'); ?></option>
1129 <option value="insert
"><?php echo __('Insert as new row'); ?></option>
1130 <option value="insertignore
"><?php echo __('Insert as new row and ignore errors'); ?></option>
1131 <option value="showinsert
"><?php echo __('Show insert query'); ?></option>
1136 if (!isset($after_insert)) {
1137 $after_insert = 'back';
1141 <td valign="middle
">
1142 <strong><?php echo __('and then'); ?></strong>
1144 <td valign="middle
" nowrap="nowrap
">
1145 <select name="after_insert
">
1146 <option value="back
" <?php echo ($after_insert == 'back' ? 'selected="selected
"' : ''); ?>><?php echo __('Go back to previous page'); ?></option>
1147 <option value="new_insert
" <?php echo ($after_insert == 'new_insert' ? 'selected="selected
"' : ''); ?>><?php echo __('Insert another new row'); ?></option>
1149 if (isset($where_clause)) {
1151 <option value="same_insert
" <?php echo ($after_insert == 'same_insert' ? 'selected="selected
"' : ''); ?>><?php echo __('Go back to this page'); ?></option>
1153 // If we have just numeric primary key, we can also edit next
1154 // in 2.8.2, we were looking for `field_name` = numeric_value
1155 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1156 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1157 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause)) {
1159 <option value="edit_next
" <?php echo ($after_insert == 'edit_next' ? 'selected="selected
"' : ''); ?>><?php echo __('Edit next row'); ?></option>
1170 <?php echo PMA_showHint(__('Use TAB key to move from value to value, or CTRL+arrows to move anywhere')); ?>
1172 <td colspan="3" align="right
" valign="middle
">
1173 <input type="submit
" value="<?php
echo __('Go'); ?
>" tabindex="<?php
echo ($tabindex +
$tabindex_for_value +
6); ?
>" id="buttonYes
" />
1174 <input type="reset
" value="<?php
echo __('Reset'); ?
>" tabindex="<?php
echo ($tabindex +
$tabindex_for_value +
7); ?
>" />
1179 <?php if ($biggest_max_file_size > 0) {
1180 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n
";
1186 <!-- Restart insertion form -->
1187 <form method="post
" action="tbl_replace
.php
" name="restartForm
" >
1188 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1189 <input type="hidden
" name="goto" value="<?php
echo htmlspecialchars($GLOBALS['goto']); ?
>" />
1190 <input type="hidden
" name="err_url
" value="<?php
echo htmlspecialchars($err_url); ?
>" />
1191 <input type="hidden
" name="sql_query
" value="<?php
echo htmlspecialchars($sql_query); ?
>" />
1193 if (isset($where_clauses)) {
1194 foreach ($where_clause_array as $key_id => $where_clause) {
1195 echo '<input type="hidden
" name="where_clause
[' . $key_id . ']" value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n
";
1198 $tmp = '<select name="insert_rows
" id="insert_rows
" onchange="this
.form
.submit();" >' . "\n
";
1199 $option_values = array(1,2,5,10,15,20,30,40);
1200 foreach ($option_values as $value) {
1201 $tmp .= '<option value="' . $value . '"';
1202 if ($value == $cfg['InsertRows']) {
1203 $tmp .= ' selected="selected
"';
1205 $tmp .= '>' . $value . '</option>' . "\n
";
1207 $tmp .= '</select>' . "\n
";
1208 echo "\n
" . sprintf(__('Restart insertion with %s rows'), $tmp);
1210 echo '<noscript><input type="submit
" value="' . __('Go
') . '" /></noscript>' . "\n
";
1211 echo '</form>' . "\n
";
1215 * Displays the footer
1217 require_once './libraries/footer.inc.php';