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'];
46 * load relation data, foreign keys
48 require_once './libraries/relation.lib.php';
53 require_once './libraries/file_listing.php';
57 * Defines the url to return to in case of error in a sql statement
58 * (at this point, $GLOBALS['goto'] will be set but could be empty)
60 if (empty($GLOBALS['goto'])) {
62 // avoid a problem (see bug #2202709)
63 $GLOBALS['goto'] = 'tbl_sql.php';
65 $GLOBALS['goto'] = 'db_sql.php';
69 * @todo check if we could replace by "db_|tbl_" - please clarify!?
73 'sql_query' => $sql_query
76 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
77 $_url_params['table'] = $table;
80 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
85 * Sets parameters for links
86 * where is this variable used?
87 * replace by PMA_generate_common_url($url_params);
89 $url_query = PMA_generate_common_url($url_params, 'html', '');
92 * get table information
93 * @todo should be done by a Table object
95 require_once './libraries/tbl_info.inc.php';
98 * Get comments for table fileds/columns
100 $comments_map = array();
102 if ($GLOBALS['cfg']['ShowPropertyComments']) {
103 $comments_map = PMA_getComments($db, $table);
107 * START REGULAR OUTPUT
111 * used in ./libraries/header.inc.php to load JavaScript library file
113 $GLOBALS['js_include'][] = 'tbl_change.js';
116 * HTTP and HTML headers
118 require_once './libraries/header.inc.php';
121 * Displays the query submitted and its result
123 * @todo where does $disp_message and $disp_query come from???
125 if (! empty($disp_message)) {
126 if (! isset($disp_query)) {
129 PMA_showMessage($disp_message, $disp_query);
133 * Displays top menu links
135 require_once './libraries/tbl_links.inc.php';
139 * Get the analysis of SHOW CREATE TABLE for this table
140 * @todo should be handled by class Table
142 $show_create_table = PMA_DBI_fetch_value(
143 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
145 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
146 unset($show_create_table);
149 * Get the list of the fields of the current table
151 PMA_DBI_select_db($db);
152 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
153 null, null, null, PMA_DBI_QUERY_STORE
);
155 if (isset($where_clause)) {
156 // when in edit mode load all selected rows from table
157 $insert_mode = false;
158 if (is_array($where_clause)) {
159 $where_clause_array = $where_clause;
161 $where_clause_array = array(0 => $where_clause);
165 $found_unique_key = false;
166 $where_clauses = array();
168 foreach ($where_clause_array as $key_id => $where_clause) {
169 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';';
170 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE
);
171 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
172 $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
175 if (! $rows[$key_id]) {
176 unset($rows[$key_id], $where_clause_array[$key_id]);
177 PMA_showMessage($strEmptyResultSet, $local_query);
179 require_once './libraries/footer.inc.php';
180 } else { // end if (no row returned)
181 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
182 list($unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true);
183 if (! empty($unique_condition)) {
184 $found_unique_key = true;
186 unset($unique_condition, $tmp_clause_is_unique);
190 // no primary key given, just load first row - but what happens if table is empty?
192 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE
);
193 $rows = array_fill(0, $cfg['InsertRows'], false);
197 // retrieve keys into foreign fields, if any
198 $foreigners = PMA_getForeigners($db, $table);
204 // loic1: autocomplete feature of IE kills the "onchange" event handler and it
205 // must be replaced by the "onpropertychange" one in this case
206 $chg_evt_handler = (PMA_USR_BROWSER_AGENT
== 'IE' && PMA_USR_BROWSER_VER
>= 5 && PMA_USR_BROWSER_VER
< 7)
209 // Had to put the URI because when hosted on an https server,
210 // some browsers send wrongly this form to the http server.
212 if ($cfg['CtrlArrowsMoving']) {
214 <!-- Set on key handler
for moving using by Ctrl+arrows
-->
215 <script src
="./js/keyhandler.js" type
="text/javascript"></script
>
216 <script type
="text/javascript">
218 var switch_movement
= 0;
219 document
.onkeydown
= onKeyDownArrowsHandler
;
225 $_form_params = array(
228 'goto' => $GLOBALS['goto'],
229 'err_url' => $err_url,
230 'sql_query' => $sql_query,
232 if (isset($where_clauses)) {
233 foreach ($where_clause_array as $key_id => $where_clause) {
234 $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
237 if (isset($clause_is_unique)) {
238 $_form_params['clause_is_unique'] = $clause_is_unique;
242 <!-- Insert
/Edit form
-->
243 <form method
="post" action
="tbl_replace.php" name
="insertForm" <?php
if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?
>>
245 echo PMA_generate_common_hidden_inputs($_form_params);
247 $titles['Browse'] = PMA_getIcon('b_browse.png', $strBrowseForeignValues);
249 // Set if we passed the first timestamp field
251 $fields_cnt = count($table_fields);
254 $tabindex_for_function = +
3000;
255 $tabindex_for_null = +
6000;
256 $tabindex_for_value = 0;
258 $biggest_max_file_size = 0;
260 // user can toggle the display of Function column
261 // (currently does not work for multi-edits)
262 $url_params['db'] = $db;
263 $url_params['table'] = $table;
264 if (isset($where_clause)) {
265 $url_params['where_clause'] = trim($where_clause);
267 if (! empty($sql_query)) {
268 $url_params['sql_query'] = $sql_query;
271 if (! $cfg['ShowFunctionFields']) {
272 $this_url_params = array_merge($url_params,
273 array('ShowFunctionFields' => 1, 'goto' => 'sql.php'));
274 echo $strShow . ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . $strFunction . '</a>' . "\n";
277 foreach ($rows as $row_id => $vrow) {
278 if ($vrow === false) {
283 $browse_foreigners_uri = '&pk=' . $row_id;
284 $vkey = '[multi_edit][' . $jsvkey . ']';
286 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ?
$result[$row_id] : $result);
287 if ($insert_mode && $row_id > 0) {
288 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_check_' . $row_id . '" />';
289 echo '<label for="insert_ignore_check_' . $row_id . '">' . $strIgnore . '</label><br />' . "\n";
295 <th
><?php
echo $strField; ?
></th
>
296 <th
><?php
echo $strType; ?
></th
>
298 if ($cfg['ShowFunctionFields']) {
299 $this_url_params = array_merge($url_params,
300 array('ShowFunctionFields' => 0, 'goto' => 'sql.php'));
301 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . $strHide . '">' . $strFunction . '</a></th>' . "\n";
304 <th
><?php
echo $strNull; ?
></th
>
305 <th
><?php
echo $strValue; ?
></th
>
310 <th colspan
="5" align
="right" class="tblFooters">
311 <input type
="submit" value
="<?php echo $strGo; ?>" />
317 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
318 $m_rows = $o_rows +
1;
321 for ($i = 0; $i < $fields_cnt; $i++
) {
322 if (! isset($table_fields[$i]['processed'])) {
323 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
324 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
325 // True_Type contains only the type (stops at first bracket)
326 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
330 // loic1: current date should not be set as default if the field is NULL
331 // for the current row
332 // lem9: but do not put here the current datetime if there is a default
333 // value (the real default value will be set in the
334 // Default value logic below)
336 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
337 // $field['Default'] is not set if it contains NULL:
338 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
339 // but, look what we get if we switch to iso: (Default is NULL)
340 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
341 // so I force a NULL into it (I don't think it's possible
342 // to have an empty default value for DATETIME)
343 // then, the "if" after this one will work
344 if ($table_fields[$i]['Type'] == 'datetime'
345 && ! isset($table_fields[$i]['Default'])
346 && isset($table_fields[$i]['Null'])
347 && $table_fields[$i]['Null'] == 'YES') {
348 $table_fields[$i]['Default'] = null;
351 $table_fields[$i]['len'] =
352 preg_match('@float|double@', $table_fields[$i]['Type']) ?
100 : -1;
355 if (isset($comments_map[$table_fields[$i]['Field']])) {
356 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
357 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
358 . $table_fields[$i]['Field_html'] . '</span>';
360 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
364 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
365 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
366 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
367 $table_fields[$i]['first_timestamp'] = false;
368 switch ($table_fields[$i]['True_Type']) {
370 $table_fields[$i]['pma_type'] = 'set';
371 $table_fields[$i]['wrap'] = '';
374 $table_fields[$i]['pma_type'] = 'enum';
375 $table_fields[$i]['wrap'] = '';
378 if (!$timestamp_seen) { // can only occur once per table
380 $table_fields[$i]['first_timestamp'] = true;
382 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
383 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
387 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
388 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
392 $field = $table_fields[$i];
393 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
395 if (-1 === $field['len']) {
396 $field['len'] = PMA_DBI_field_len($vresult, $i);
399 $unnullify_trigger = $chg_evt_handler . "=\"return unNullify('"
400 . PMA_escapeJsString($field['Field_md5']) . "', '"
401 . PMA_escapeJsString($jsvkey) . "')\"";
403 // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
404 $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
405 $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]';
408 if ($field['Type'] == 'datetime'
409 && ! isset($field['Default'])
410 && ! is_null($field['Default'])
411 && ($insert_mode ||
! isset($vrow[$field['Field']]))) {
413 // UPDATE case with an NULL value
414 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
417 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
418 <td
<?php
echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ?
'rowspan="2"' : ''); ?
> align
="center">
419 <?php
echo $field['Field_title']; ?
>
420 <input type
="hidden" name
="fields_name<?php echo $field_name_appendix; ?>" value
="<?php echo $field['Field_html']; ?>"/>
422 <td align
="center"<?php
echo $field['wrap']; ?
>>
423 <?php
echo $field['pma_type']; ?
>
428 // Prepares the field value
429 $real_null_value = FALSE;
430 $special_chars_encoded = '';
433 // On a BLOB that can have a NULL value, the is_null() returns
434 // true if it has no content but for me this is different than
435 // having been set explicitely to NULL so I put an exception here
436 if (! $field['is_blob'] && is_null($vrow[$field['Field']])) {
437 $real_null_value = TRUE;
438 $vrow[$field['Field']] = '';
440 $data = $vrow[$field['Field']];
441 } elseif ($field['True_Type'] == 'bit') {
442 $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
444 // loic1: special binary "characters"
445 if ($field['is_binary'] ||
$field['is_blob']) {
446 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
447 $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]);
448 $field['display_binary_as_hex'] = true;
450 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
453 $special_chars = htmlspecialchars($vrow[$field['Field']]);
455 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
456 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
458 $data = $vrow[$field['Field']];
459 } // end if... else...
460 // loic1: if a timestamp field value is not included in an update
461 // statement MySQL auto-update it to the current timestamp
462 // lem9: however, things have changed since MySQL 4.1, so
463 // it's better to set a fields_prev in this situation
464 $backup_field = '<input type="hidden" name="fields_prev'
465 . $field_name_appendix . '" value="'
466 . htmlspecialchars($vrow[$field['Field']]) . '" />';
468 // (we are inserting)
469 // loic1: display default values
470 if (!isset($field['Default'])) {
471 $field['Default'] = '';
472 $real_null_value = TRUE;
475 $data = $field['Default'];
477 if ($field['True_Type'] == 'bit') {
478 $special_chars = PMA_convert_bit_default_value($field['Default']);
480 $special_chars = htmlspecialchars($field['Default']);
483 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
484 // this will select the UNHEX function while inserting
485 if (($field['is_binary'] ||
($field['is_blob'] && ! $cfg['ProtectBinary'])) && $_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
486 $field['display_binary_as_hex'] = true;
490 $idindex = ($o_rows * $fields_cnt) +
$i +
1;
491 $tabindex = (($idindex - 1) * 3) +
1;
493 // The function column
494 // -------------------
495 // Change by Bernard M. Piller <bernard@bmpsystems.com>
496 // We don't want binary data to be destroyed
497 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
498 // stored or retrieved" so it does not mean that the contents is
500 if ($cfg['ShowFunctionFields']) {
501 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
502 ||
($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
503 echo ' <td align="center">' . $strBinary . '</td>' . "\n";
504 } elseif (strstr($field['True_Type'], 'enum') ||
strstr($field['True_Type'], 'set')) {
505 echo ' <td align="center">--</td>' . "\n";
509 <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">
514 // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
515 // or something similar. Then directly look up the entry in the RestrictFunctions array,
516 // which will then reveal the available dropdown options
517 if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
518 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
519 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
520 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
521 $default_function = $cfg['DefaultFunctions'][$current_func_type];
524 $default_function = '';
527 $dropdown_built = array();
528 $op_spacing_needed = FALSE;
530 // what function defined as default?
531 // for the first timestamp we don't set the default function
532 // if there is a default value for the timestamp
533 // (not including CURRENT_TIMESTAMP)
534 // and the column does not have the
535 // ON UPDATE DEFAULT TIMESTAMP attribute.
537 if ($field['True_Type'] == 'timestamp'
538 && empty($field['Default'])
539 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
540 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
543 // For primary keys of type char(36) or varchar(36) UUID if the default function
544 // Only applies to insert mode, as it would silently trash data on updates.
546 && $field['Key'] == 'PRI'
547 && ($field['Type'] == 'char(36)' ||
$field['Type'] == 'varchar(36)')
549 $default_function = $cfg['DefaultFunctions']['pk_char36'];
552 // this is set only when appropriate and is always true
553 if (isset($field['display_binary_as_hex'])) {
554 $default_function = 'UNHEX';
557 // garvin: loop on the dropdown array and print all available options for that field.
558 foreach ($dropdown as $each_dropdown){
560 if ($default_function === $each_dropdown) {
561 echo ' selected="selected"';
563 echo '>' . $each_dropdown . '</option>' . "\n";
564 $dropdown_built[$each_dropdown] = 'TRUE';
565 $op_spacing_needed = TRUE;
568 // garvin: For compatibility's sake, do not let out all other functions. Instead
569 // print a separator (blank) and then show ALL functions which weren't shown
571 $cnt_functions = count($cfg['Functions']);
572 for ($j = 0; $j < $cnt_functions; $j++
) {
573 if (!isset($dropdown_built[$cfg['Functions'][$j]]) ||
$dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
574 // Is current function defined as default?
575 $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
576 ||
(!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
577 ?
' selected="selected"'
579 if ($op_spacing_needed == TRUE) {
581 echo '<option value="">--------</option>' . "\n";
582 $op_spacing_needed = FALSE;
586 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
595 } // end if ($cfg['ShowFunctionFields'])
600 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
602 if ($field['Null'] == 'YES') {
603 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
604 if ($real_null_value && !$field['first_timestamp']) {
609 if (!(($cfg['ProtectBinary'] && $field['is_blob']) ||
($cfg['ProtectBinary'] == 'all' && $field['is_binary']))) {
611 echo ' <input type="checkbox" tabindex="' . ($tabindex +
$tabindex_for_null) . '"'
612 . ' name="fields_null' . $field_name_appendix . '"';
613 if ($real_null_value && !$field['first_timestamp']) {
614 echo ' checked="checked"';
616 echo ' id="field_' . ($idindex) . '_2"';
617 $onclick = ' onclick="if (this.checked) {nullify(';
618 if (strstr($field['True_Type'], 'enum')) {
619 if (strlen($field['Type']) > 20) {
624 } elseif (strstr($field['True_Type'], 'set')) {
626 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
627 // foreign key in a drop-down
629 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
630 // foreign key with a browsing icon
635 $onclick .= '\'' . PMA_escapeJsString($field['Field_html']) . '\', \'' . $field['Field_md5'] . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
638 echo ' <input type="hidden" name="fields_null' . $field_name_appendix . '"';
639 if ($real_null_value && !$field['first_timestamp']) {
645 echo ' </td>' . "\n";
647 // The value column (depends on type)
649 // See bug #1667887 for the reason why we don't use the maxlength
653 if ($foreignData['foreign_link'] == true) {
654 echo $backup_field . "\n";
656 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>"
658 <input type
="hidden" name
="fields<?php echo $field_name_appendix; ?>"
659 value
="" id
="field_<?php echo ($idindex); ?>_3A" />
660 <input type
="text" name
="field_<?php echo $field_name_appendix_md5; ?>"
661 class="textfield" <?php
echo $unnullify_trigger; ?
>
662 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
663 id
="field_<?php echo ($idindex); ?>_3"
664 value
="<?php echo htmlspecialchars($data); ?>" />
665 <script type
="text/javascript">
667 document
.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
668 document
.write(' href="browse_foreigners.php?');
669 document
.write('<?php echo PMA_generate_common_url($db, $table); ?>');
670 document
.writeln('&field=<?php echo PMA_escapeJsString(urlencode($field['Field
']) . $browse_foreigners_uri); ?>">');
671 document
.writeln('<?php echo str_replace("'", "\'
", $titles['Browse']); ?></a>');
675 } elseif (is_array($foreignData['disp_row'])) {
676 echo $backup_field . "\n
";
678 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>"
680 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>"
681 value="" id="field_
<?php
echo $idindex; ?
>_3A
" />
682 <select name="field_
<?php
echo $field_name_appendix_md5; ?
>"
683 <?php echo $unnullify_trigger; ?>
684 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
685 id="field_
<?php
echo ($idindex); ?
>_3
">
686 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
690 unset($foreignData['disp_row']);
691 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
695 <tr class="<?php
echo $odd_row ?
'odd' : 'even'; ?
>">
696 <td colspan="5" align="right
">
697 <?php echo $backup_field . "\n
"; ?>
698 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
699 rows="<?php
echo ($cfg['TextareaRows']*2); ?
>"
700 cols="<?php
echo ($cfg['TextareaCols']*2); ?
>"
701 dir="<?php
echo $text_dir; ?
>"
702 id="field_
<?php
echo ($idindex); ?
>_3
"
703 <?php echo $unnullify_trigger; ?>
704 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
705 ><?php echo $special_chars_encoded; ?></textarea>
707 } elseif (strstr($field['pma_type'], 'text')) {
708 echo $backup_field . "\n
";
710 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
711 rows="<?php
echo $cfg['TextareaRows']; ?
>"
712 cols="<?php
echo $cfg['TextareaCols']; ?
>"
713 dir="<?php
echo $text_dir; ?
>"
714 id="field_
<?php
echo ($idindex); ?
>_3
"
715 <?php echo $unnullify_trigger; ?>
716 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
717 ><?php echo $special_chars_encoded; ?></textarea>
720 if (strlen($special_chars) > 32000) {
722 echo ' <td>' . $strTextAreaLength;
724 } elseif ($field['pma_type'] == 'enum') {
725 if (! isset($table_fields[$i]['values'])) {
726 $table_fields[$i]['values'] = array();
727 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
728 // Removes automatic MySQL escape format
729 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
730 $table_fields[$i]['values'][] = array(
732 'html' => htmlspecialchars($val),
736 $field_enum_values = $table_fields[$i]['values'];
738 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="enum
" />
739 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>" value="" />
741 echo "\n
" . ' ' . $backup_field . "\n
";
743 // show dropdown or radio depend on length
744 if (strlen($field['Type']) > 20) {
746 <select name="field_
<?php
echo $field_name_appendix_md5; ?
>"
747 <?php echo $unnullify_trigger; ?>
748 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
749 id="field_
<?php
echo ($idindex); ?
>_3
">
750 <option value=""> </option>
754 foreach ($field_enum_values as $enum_value) {
756 echo '<option value="' . $enum_value['html
'] . '"';
757 if ($data == $enum_value['plain']
759 && (! isset($where_clause) || $field['Null'] != 'YES')
760 && isset($field['Default'])
761 && $enum_value['plain'] == $field['Default'])) {
762 echo ' selected="selected
"';
764 echo '>' . $enum_value['html'] . '</option>' . "\n
";
772 foreach ($field_enum_values as $enum_value) {
774 echo '<input type="radio
" name="field_
' . $field_name_appendix_md5 . '"';
775 echo ' value="' . $enum_value['html
'] . '"';
776 echo ' id="field_
' . ($idindex) . '_3_
' . $j . '"';
777 echo $unnullify_trigger;
778 if ($data == $enum_value['plain']
780 && (! isset($where_clause) || $field['Null'] != 'YES')
781 && isset($field['Default'])
782 && $enum_value['plain'] == $field['Default'])) {
783 echo ' checked="checked
"';
785 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
786 echo '<label for="field_
' . $idindex . '_3_
' . $j . '">'
787 . $enum_value['html'] . '</label>' . "\n
";
791 } elseif ($field['pma_type'] == 'set') {
792 if (! isset($table_fields[$i]['values'])) {
793 $table_fields[$i]['values'] = array();
794 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
795 $table_fields[$i]['values'][] = array(
797 'html' => htmlspecialchars($val),
800 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
802 $field_set_values = $table_fields[$i]['values'];
803 $select_size = $table_fields[$i]['select_size'];
805 $vset = array_flip(explode(',', $data));
806 echo $backup_field . "\n
";
808 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="set
" />
809 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>" value="" />
810 <select name="field_
<?php
echo $field_name_appendix_md5; ?
>"
811 size="<?php
echo $select_size; ?
>"
812 multiple="multiple
" <?php echo $unnullify_trigger; ?>
813 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
814 id="field_
<?php
echo ($idindex); ?
>_3
">
816 foreach ($field_set_values as $field_set_value) {
818 echo '<option value="' . $field_set_value['html
'] . '"';
819 if (isset($vset[$field_set_value['plain']])) {
820 echo ' selected="selected
"';
822 echo '>' . $field_set_value['html'] . '</option>' . "\n
";
828 // Change by Bernard M. Piller <bernard@bmpsystems.com>
829 // We don't want binary data destroyed
830 elseif ($field['is_binary'] || $field['is_blob']) {
831 if (($cfg['ProtectBinary'] && $field['is_blob'])
832 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
834 // rajk - for blobstreaming
835 $bs_reference_exists = FALSE;
837 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
840 $PMA_Config = $_SESSION['PMA_Config'];
842 if (!empty($PMA_Config))
844 $requiredTblType = $PMA_Config->get('PBXT_NAME');
846 if ($requiredTblType == strtolower ($tbl_type))
848 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
850 // check if blobstreaming plugins exist
853 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
855 if (!empty($bs_tables) && strlen($db) > 0)
857 $bs_tables = $bs_tables[$db];
859 if (isset($bs_tables))
861 $allBSTablesExist = TRUE;
863 foreach ($bs_tables as $table_key=>$bs_tbl)
864 if (!$bs_tables[$table_key]['Exists'])
866 $allBSTablesExist = FALSE;
870 if ($allBSTablesExist)
871 $bs_reference_exists = PMA_BS_ReferenceExists($data, $db);
872 } // end if (isset($bs_tables))
873 } // end if (!empty($bs_tables) && strlen($db) > 0)
874 } // end if ($pluginsExist)
875 } // end if ($requiredTblType == strtolower ($tbl_type))
876 } // end if (!empty($PMA_Config))
877 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
879 if ($bs_reference_exists)
881 echo '<input type="hidden
" name="remove_blob_ref_
' . $field['Field_md5
'] . $vkey . '" value="' . $data . '" />';
882 echo '<input type="checkbox
" name="remove_blob_repo_
' . $field['Field_md5
'] . $vkey . '" /> ' . $strBLOBRepositoryRemove . "<br
/>";
883 echo PMA_BS_CreateReferenceLink($data, $db);
888 echo $strBinaryDoNotEdit;
890 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
891 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
895 } // end if ($bs_reference_exists)
897 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="protected" />
898 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>" value="" />
900 } elseif ($field['is_blob']) {
902 echo $backup_field . "\n
";
904 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
905 rows="<?php
echo $cfg['TextareaRows']; ?
>"
906 cols="<?php
echo $cfg['TextareaCols']; ?
>"
907 dir="<?php
echo $text_dir; ?
>"
908 id="field_
<?php
echo ($idindex); ?
>_3
"
909 <?php echo $unnullify_trigger; ?>
910 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
911 ><?php echo $special_chars_encoded; ?></textarea>
915 // field size should be at least 4 and max 40
916 $fieldsize = min(max($field['len'], 4), 40);
918 echo $backup_field . "\n
";
920 <input type="text
" name="fields
<?php
echo $field_name_appendix; ?
>"
921 value="<?php
echo $special_chars; ?
>" size="<?php
echo $fieldsize; ?
>"
922 class="textfield
" <?php echo $unnullify_trigger; ?>
923 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
924 id="field_
<?php
echo ($idindex); ?
>_3
" />
926 } // end if...elseif...else
928 // Upload choice (only for BLOBs because the binary
929 // attribute does not imply binary contents)
930 // (displayed whatever value the ProtectBinary has)
932 if ($is_upload && $field['is_blob']) {
934 // check if field type is of longblob
935 if ($field['pma_type'] == "longblob
")
937 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
940 $PMA_Config = $_SESSION['PMA_Config'];
942 // is PMA_Config's data loaded? continue only if it is
943 if (!empty($PMA_Config))
945 $requiredTblType = $PMA_Config->get('PBXT_NAME');
947 if ($requiredTblType == strtolower ($tbl_type))
949 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
951 // check if blobstreaming plugins exist
954 $curlExists = $PMA_Config->get('CURL_EXISTS');
956 // check if CURL exists
959 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
961 // check for BLOBStreamable databases and if current database name is provided
962 if (!empty($bs_tables) && strlen($db) > 0)
964 $bs_tables = $bs_tables[$db];
966 // check if reference to BLOBStreaming tables exists
967 if (isset($bs_tables))
969 $allBSTablesExist = TRUE;
971 foreach ($bs_tables as $table_key=>$bs_tbl)
972 if (!$bs_tables[$table_key]['Exists'])
974 $allBSTablesExist = FALSE;
978 // check if necessary BLOBStreaming tables exist
979 if ($allBSTablesExist)
982 echo '<input type="checkbox
" name="upload_blob_repo_
' . $field['Field_md5
'] . $vkey . '" /> ' . $strBLOBRepositoryUpload;
983 } // end if ($allBSTablesExist)
984 } // end if (isset($bs_tables)
985 } // end if (!empty($bs_tables) && strlen ($db) > 0)
986 } // end if ($curlExists)
987 } // end if ($pluginsExist)
988 } // end if ($requiredTblType == strtolower ($tbl_type))
989 } // end if (!empty($PMA_Config))
990 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
994 echo '<input type="file
" name="fields_upload_
' . $field['Field_md5
'] . $vkey . '" class="textfield
" id="field_
' . $idindex . '_3
" size="10" /> ';
996 // find maximum upload size, based on field type
998 * @todo with functions this is not so easy, as you can basically
999 * process any data with function like MD5
1001 $max_field_sizes = array(
1002 'tinyblob' => '256',
1004 'mediumblob' => '16777216',
1005 'longblob' => '4294967296'); // yeah, really
1007 $this_field_max_size = $max_upload_size; // from PHP max
1008 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
1009 $this_field_max_size = $max_field_sizes[$field['pma_type']];
1011 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n
";
1012 // do not generate here the MAX_FILE_SIZE, because we should
1013 // put only one in the form to accommodate the biggest field
1014 if ($this_field_max_size > $biggest_max_file_size) {
1015 $biggest_max_file_size = $this_field_max_size;
1019 if (!empty($cfg['UploadDir'])) {
1020 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
1021 if ($files === FALSE) {
1022 echo ' <font color="red
">' . $strError . '</font><br />' . "\n
";
1023 echo ' ' . $strWebServerUploadDirectoryError . "\n
";
1024 } elseif (!empty($files)) {
1026 echo ' <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ':<br />' . "\n
";
1027 echo ' <select size="1" name="fields_uploadlocal_
' . $field['Field_md5
'] . $vkey . '">' . "\n
";
1028 echo ' <option value="" selected="selected
"></option>' . "\n
";
1030 echo ' </select>' . "\n
";
1032 } // end if (web-server upload directory)
1033 } // end elseif (binary or blob)
1035 // field size should be at least 4 and max 40
1036 $fieldsize = min(max($field['len'], 4), 40);
1037 echo $backup_field . "\n
";
1038 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n
") !== FALSE)) {
1041 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
1042 rows="<?php
echo $cfg['CharTextareaRows']; ?
>"
1043 cols="<?php
echo $cfg['CharTextareaCols']; ?
>"
1044 dir="<?php
echo $text_dir; ?
>"
1045 id="field_
<?php
echo ($idindex); ?
>_3
"
1046 <?php echo $unnullify_trigger; ?>
1047 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
1048 ><?php echo $special_chars_encoded; ?></textarea>
1052 <input type="text
" name="fields
<?php
echo $field_name_appendix; ?
>"
1053 value="<?php
echo $special_chars; ?
>" size="<?php
echo $fieldsize; ?
>"
1054 class="textfield
" <?php echo $unnullify_trigger; ?>
1055 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
1056 id="field_
<?php
echo ($idindex); ?
>_3
" />
1058 if ($field['Extra'] == 'auto_increment') {
1060 <input type="hidden
" name="auto_increment
<?php
echo $field_name_appendix; ?
>" value="1" />
1063 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
1065 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="timestamp
" />
1068 if ($field['True_Type'] == 'bit') {
1070 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="bit
" />
1073 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
1074 // the _3 suffix points to the date field
1075 // the _2 suffix points to the corresponding NULL checkbox
1077 <script type="text
/javascript
">
1079 document.write('<a title="<?php
echo $strCalendar;?
>"');
1080 document.write(' href="javascript
:openCalendar(\'<?php
echo PMA_generate_common_url();?
>\', \'insertForm\'
, \'field_
<?php
echo ($idindex); ?
>_3\'
, \'<?php
echo (substr($field['pma_type'], 0, 9) == 'timestamp') ?
'datetime' : substr($field['pma_type'], 0, 9); ?
>\', \'field_
<?php
echo ($idindex); ?
>_2\'
)">');
1081 document.write('<img class="calendar
"');
1082 document.write(' src="<?php
echo $pmaThemeImage; ?
>b_calendar
.png
"');
1083 document.write(' alt="<?php
echo $strCalendar; ?
>"/></a>');
1094 $odd_row = !$odd_row;
1097 echo ' </tbody></table><br />';
1098 } // end foreach on multi-edit
1103 <table border="0" cellpadding="5" cellspacing="0">
1105 <td valign="middle
" nowrap="nowrap
">
1106 <select name="submit_type
" tabindex="<?php
echo ($tabindex +
$tabindex_for_value +
1); ?
>">
1108 if (isset($where_clause)) {
1110 <option value="<?php
echo $strSave; ?
>"><?php echo $strSave; ?></option>
1114 <option value="<?php
echo $strInsertAsNewRow; ?
>"><?php echo $strInsertAsNewRow; ?></option>
1119 if (!isset($after_insert)) {
1120 $after_insert = 'back';
1124 <td valign="middle
">
1125 <strong><?php echo $strAndThen; ?></strong>
1127 <td valign="middle
" nowrap="nowrap
">
1128 <select name="after_insert
">
1129 <option value="back
" <?php echo ($after_insert == 'back' ? 'selected="selected
"' : ''); ?>><?php echo $strAfterInsertBack; ?></option>
1130 <option value="new_insert
" <?php echo ($after_insert == 'new_insert' ? 'selected="selected
"' : ''); ?>><?php echo $strAfterInsertNewInsert; ?></option>
1132 if (isset($where_clause)) {
1134 <option value="same_insert
" <?php echo ($after_insert == 'same_insert' ? 'selected="selected
"' : ''); ?>><?php echo $strAfterInsertSame; ?></option>
1136 // If we have just numeric primary key, we can also edit next
1137 // in 2.8.2, we were looking for `field_name` = numeric_value
1138 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
1139 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1140 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause)) {
1142 <option value="edit_next
" <?php echo ($after_insert == 'edit_next' ? 'selected="selected
"' : ''); ?>><?php echo $strAfterInsertNext; ?></option>
1153 <?php echo PMA_showHint($strUseTabKey); ?>
1155 <td colspan="3" align="right
" valign="middle
">
1156 <input type="submit
" value="<?php
echo $strGo; ?
>" tabindex="<?php
echo ($tabindex +
$tabindex_for_value +
6); ?
>" id="buttonYes
" />
1157 <input type="reset
" value="<?php
echo $strReset; ?
>" tabindex="<?php
echo ($tabindex +
$tabindex_for_value +
7); ?
>" />
1162 <?php if ($biggest_max_file_size > 0) {
1163 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n
";
1169 <!-- Restart insertion form -->
1170 <form method="post
" action="tbl_replace
.php
" name="restartForm
" >
1171 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1172 <input type="hidden
" name="goto" value="<?php
echo htmlspecialchars($GLOBALS['goto']); ?
>" />
1173 <input type="hidden
" name="err_url
" value="<?php
echo htmlspecialchars($err_url); ?
>" />
1174 <input type="hidden
" name="sql_query
" value="<?php
echo htmlspecialchars($sql_query); ?
>" />
1176 if (isset($where_clauses)) {
1177 foreach ($where_clause_array as $key_id => $where_clause) {
1178 echo '<input type="hidden
" name="where_clause
[' . $key_id . ']" value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n
";
1181 $tmp = '<select name="insert_rows
" id="insert_rows
" onchange="this
.form
.submit();" >' . "\n
";
1182 $option_values = array(1,2,5,10,15,20,30,40);
1183 foreach ($option_values as $value) {
1184 $tmp .= '<option value="' . $value . '"';
1185 if ($value == $cfg['InsertRows']) {
1186 $tmp .= ' selected="selected
"';
1188 $tmp .= '>' . $value . '</option>' . "\n
";
1190 $tmp .= '</select>' . "\n
";
1191 echo "\n
" . sprintf($strRestartInsertion, $tmp);
1193 echo '<noscript><input type="submit
" value="' . $strGo . '" /></noscript>' . "\n
";
1194 echo '</form>' . "\n
";
1198 * Displays the footer
1200 require_once './libraries/footer.inc.php';