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
28 * @todo this one is badly named, it's really a WHERE condition
29 * and exists even for tables not having a primary key or unique key
31 if (isset($_REQUEST['primary_key'])) {
32 $primary_key = $_REQUEST['primary_key'];
34 if (isset($_REQUEST['clause_is_unique'])) {
35 $clause_is_unique = $_REQUEST['clause_is_unique'];
37 if (isset($_SESSION['edit_next'])) {
38 $primary_key = $_SESSION['edit_next'];
39 unset($_SESSION['edit_next']);
40 $after_insert = 'edit_next';
42 if (isset($_REQUEST['sql_query'])) {
43 $sql_query = $_REQUEST['sql_query'];
45 if (isset($_REQUEST['ShowFunctionFields'])) {
46 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
50 * load relation data, foreign keys
52 require_once './libraries/relation.lib.php';
57 require_once './libraries/file_listing.php';
61 * Defines the url to return to in case of error in a sql statement
62 * (at this point, $GLOBALS['goto'] will be set but could be empty)
64 if (empty($GLOBALS['goto'])) {
66 // avoid a problem (see bug #2202709)
67 $GLOBALS['goto'] = 'tbl_sql.php';
69 $GLOBALS['goto'] = 'db_sql.php';
73 * @todo check if we could replace by "db_|tbl_" - please clarify!?
77 'sql_query' => $sql_query
80 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
81 $_url_params['table'] = $table;
84 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
89 * Sets parameters for links
90 * where is this variable used?
91 * replace by PMA_generate_common_url($url_params);
93 $url_query = PMA_generate_common_url($url_params, 'html', '');
96 * get table information
97 * @todo should be done by a Table object
99 require_once './libraries/tbl_info.inc.php';
102 * Get comments for table fileds/columns
104 $comments_map = array();
106 if ($GLOBALS['cfg']['ShowPropertyComments']) {
107 $comments_map = PMA_getComments($db, $table);
111 * START REGULAR OUTPUT
115 * used in ./libraries/header.inc.php to load JavaScript library file
117 $GLOBALS['js_include'][] = 'tbl_change.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($primary_key)) {
160 // when in edit mode load all selected rows from table
161 $insert_mode = false;
162 if (is_array($primary_key)) {
163 $primary_key_array = $primary_key;
165 $primary_key_array = array(0 => $primary_key);
169 $found_unique_key = false;
170 foreach ($primary_key_array as $key_id => $primary_key) {
171 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';';
172 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE
);
173 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
174 $primary_keys[$key_id] = str_replace('\\', '\\\\', $primary_key);
177 if (! $rows[$key_id]) {
178 unset($rows[$key_id], $primary_key_array[$key_id]);
179 PMA_showMessage($strEmptyResultSet, $local_query);
181 require_once './libraries/footer.inc.php';
182 } else { // end if (no row returned)
183 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
184 list($unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true);
185 if (! empty($unique_condition)) {
186 $found_unique_key = true;
188 unset($unique_condition, $tmp_clause_is_unique);
192 // no primary key given, just load first row - but what happens if table is empty?
194 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE
);
195 $rows = array_fill(0, $cfg['InsertRows'], false);
199 // retrieve keys into foreign fields, if any
200 $foreigners = PMA_getForeigners($db, $table);
206 // loic1: 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($primary_keys)) {
235 foreach ($primary_key_array as $key_id => $primary_key) {
236 $_form_params['primary_key[' . $key_id . ']'] = trim($primary_key);
239 if (isset($clause_is_unique)) {
240 $_form_params['clause_is_unique'] = $clause_is_unique;
244 <!-- Insert
/Edit form
-->
245 <form method
="post" action
="tbl_replace.php" name
="insertForm" <?php
if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?
>>
247 echo PMA_generate_common_hidden_inputs($_form_params);
249 $titles['Browse'] = PMA_getIcon('b_browse.png', $strBrowseForeignValues);
251 // Set if we passed the first timestamp field
253 $fields_cnt = count($table_fields);
256 $tabindex_for_function = +
3000;
257 $tabindex_for_null = +
6000;
258 $tabindex_for_value = 0;
260 $biggest_max_file_size = 0;
262 // user can toggle the display of Function column
263 // (currently does not work for multi-edits)
264 $url_params['db'] = $db;
265 $url_params['table'] = $table;
266 if (isset($primary_key)) {
267 $url_params['primary_key'] = trim($primary_key);
269 if (! empty($sql_query)) {
270 $url_params['sql_query'] = $sql_query;
273 if (! $cfg['ShowFunctionFields']) {
274 $this_url_params = array_merge($url_params,
275 array('ShowFunctionFields' => 1, 'goto' => 'sql.php'));
276 echo $strShow . ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . $strFunction . '</a>' . "\n";
279 foreach ($rows as $row_id => $vrow) {
280 if ($vrow === false) {
285 $browse_foreigners_uri = '&pk=' . $row_id;
286 $vkey = '[multi_edit][' . $jsvkey . ']';
288 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ?
$result[$row_id] : $result);
289 if ($insert_mode && $row_id > 0) {
290 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_check_' . $row_id . '" />';
291 echo '<label for="insert_ignore_check_' . $row_id . '">' . $strIgnore . '</label><br />' . "\n";
297 <th
><?php
echo $strField; ?
></th
>
298 <th
><?php
echo $strType; ?
></th
>
300 if ($cfg['ShowFunctionFields']) {
301 $this_url_params = array_merge($url_params,
302 array('ShowFunctionFields' => 0, 'goto' => 'sql.php'));
303 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . $strHide . '">' . $strFunction . '</a></th>' . "\n";
306 <th
><?php
echo $strNull; ?
></th
>
307 <th
><?php
echo $strValue; ?
></th
>
312 <th colspan
="5" align
="right" class="tblFooters">
313 <input type
="submit" value
="<?php echo $strGo; ?>" />
319 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
320 $m_rows = $o_rows +
1;
323 for ($i = 0; $i < $fields_cnt; $i++
) {
324 if (! isset($table_fields[$i]['processed'])) {
325 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
326 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
327 // True_Type contains only the type (stops at first bracket)
328 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
332 // loic1: current date should not be set as default if the field is NULL
333 // for the current row
334 // lem9: but do not put here the current datetime if there is a default
335 // value (the real default value will be set in the
336 // Default value logic below)
338 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
339 // $field['Default'] is not set if it contains NULL:
340 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
341 // but, look what we get if we switch to iso: (Default is NULL)
342 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
343 // so I force a NULL into it (I don't think it's possible
344 // to have an empty default value for DATETIME)
345 // then, the "if" after this one will work
346 if ($table_fields[$i]['Type'] == 'datetime'
347 && ! isset($table_fields[$i]['Default'])
348 && isset($table_fields[$i]['Null'])
349 && $table_fields[$i]['Null'] == 'YES') {
350 $table_fields[$i]['Default'] = null;
353 $table_fields[$i]['len'] =
354 preg_match('@float|double@', $table_fields[$i]['Type']) ?
100 : -1;
357 if (isset($comments_map[$table_fields[$i]['Field']])) {
358 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
359 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
360 . $table_fields[$i]['Field_html'] . '</span>';
362 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
366 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
367 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
368 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
369 $table_fields[$i]['first_timestamp'] = false;
370 switch ($table_fields[$i]['True_Type']) {
372 $table_fields[$i]['pma_type'] = 'set';
373 $table_fields[$i]['wrap'] = '';
376 $table_fields[$i]['pma_type'] = 'enum';
377 $table_fields[$i]['wrap'] = '';
380 if (!$timestamp_seen) { // can only occur once per table
382 $table_fields[$i]['first_timestamp'] = true;
384 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
385 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
389 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
390 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
394 $field = $table_fields[$i];
395 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
397 if (-1 === $field['len']) {
398 $field['len'] = PMA_DBI_field_len($vresult, $i);
401 $unnullify_trigger = $chg_evt_handler . "=\"return unNullify('"
402 . PMA_escapeJsString($field['Field_md5']) . "', '"
403 . PMA_escapeJsString($jsvkey) . "')\"";
405 // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
406 $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
407 $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]';
410 if ($field['Type'] == 'datetime'
411 && ! isset($field['Default'])
412 && ! is_null($field['Default'])
413 && ($insert_mode ||
! isset($vrow[$field['Field']]))) {
415 // UPDATE case with an NULL value
416 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
419 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
420 <td
<?php
echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ?
'rowspan="2"' : ''); ?
> align
="center">
421 <?php
echo $field['Field_title']; ?
>
422 <input type
="hidden" name
="fields_name<?php echo $field_name_appendix; ?>" value
="<?php echo $field['Field_html']; ?>"/>
424 <td align
="center"<?php
echo $field['wrap']; ?
>>
425 <?php
echo $field['pma_type']; ?
>
430 // Prepares the field value
431 $real_null_value = FALSE;
432 $special_chars_encoded = '';
434 // On a BLOB that can have a NULL value, the is_null() returns
435 // true if it has no content but for me this is different than
436 // having been set explicitely to NULL so I put an exception here
437 if (! $field['is_blob'] && is_null($vrow[$field['Field']])) {
438 $real_null_value = TRUE;
439 $vrow[$field['Field']] = '';
441 $data = $vrow[$field['Field']];
442 } elseif ($field['True_Type'] == 'bit') {
443 $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
445 // loic1: special binary "characters"
446 if ($field['is_binary'] ||
$field['is_blob']) {
447 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) {
448 $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]);
449 $field['display_binary_as_hex'] = true;
451 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
454 $special_chars = htmlspecialchars($vrow[$field['Field']]);
456 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
457 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
459 $data = $vrow[$field['Field']];
460 } // end if... else...
461 // loic1: if a timestamp field value is not included in an update
462 // statement MySQL auto-update it to the current timestamp
463 // lem9: however, things have changed since MySQL 4.1, so
464 // it's better to set a fields_prev in this situation
465 $backup_field = '<input type="hidden" name="fields_prev'
466 . $field_name_appendix . '" value="'
467 . htmlspecialchars($vrow[$field['Field']]) . '" />';
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);
486 $idindex = ($o_rows * $fields_cnt) +
$i +
1;
487 $tabindex = (($idindex - 1) * 3) +
1;
489 // The function column
490 // -------------------
491 // Change by Bernard M. Piller <bernard@bmpsystems.com>
492 // We don't want binary data to be destroyed
493 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
494 // stored or retrieved" so it does not mean that the contents is
496 if ($cfg['ShowFunctionFields']) {
497 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
498 ||
($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
499 echo ' <td align="center">' . $strBinary . '</td>' . "\n";
500 } elseif (strstr($field['True_Type'], 'enum') ||
strstr($field['True_Type'], 'set')) {
501 echo ' <td align="center">--</td>' . "\n";
505 <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">
510 // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
511 // or something similar. Then directly look up the entry in the RestrictFunctions array,
512 // which will then reveal the available dropdown options
513 if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
514 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
515 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
516 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
517 $default_function = $cfg['DefaultFunctions'][$current_func_type];
520 $default_function = '';
523 $dropdown_built = array();
524 $op_spacing_needed = FALSE;
526 // what function defined as default?
527 // for the first timestamp we don't set the default function
528 // if there is a default value for the timestamp
529 // (not including CURRENT_TIMESTAMP)
530 // and the column does not have the
531 // ON UPDATE DEFAULT TIMESTAMP attribute.
533 if ($field['True_Type'] == 'timestamp'
534 && empty($field['Default'])
535 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
536 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
539 // For primary keys of type char(36) or varchar(36) UUID if the default function
540 // Only applies to insert mode, as it would silently trash data on updates.
542 && $field['Key'] == 'PRI'
543 && ($field['Type'] == 'char(36)' ||
$field['Type'] == 'varchar(36)')
545 $default_function = $cfg['DefaultFunctions']['pk_char36'];
548 // this is set only when appropriate and is always true
549 if (isset($field['display_binary_as_hex'])) {
550 $default_function = 'UNHEX';
553 // garvin: loop on the dropdown array and print all available options for that field.
554 foreach ($dropdown as $each_dropdown){
556 if ($default_function === $each_dropdown) {
557 echo ' selected="selected"';
559 echo '>' . $each_dropdown . '</option>' . "\n";
560 $dropdown_built[$each_dropdown] = 'TRUE';
561 $op_spacing_needed = TRUE;
564 // garvin: For compatibility's sake, do not let out all other functions. Instead
565 // print a separator (blank) and then show ALL functions which weren't shown
567 $cnt_functions = count($cfg['Functions']);
568 for ($j = 0; $j < $cnt_functions; $j++
) {
569 if (!isset($dropdown_built[$cfg['Functions'][$j]]) ||
$dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
570 // Is current function defined as default?
571 $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
572 ||
(!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
573 ?
' selected="selected"'
575 if ($op_spacing_needed == TRUE) {
577 echo '<option value="">--------</option>' . "\n";
578 $op_spacing_needed = FALSE;
582 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
591 } // end if ($cfg['ShowFunctionFields'])
596 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
598 if ($field['Null'] == 'YES') {
599 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
600 if ($real_null_value && !$field['first_timestamp']) {
605 if (!(($cfg['ProtectBinary'] && $field['is_blob']) ||
($cfg['ProtectBinary'] == 'all' && $field['is_binary']))) {
607 echo ' <input type="checkbox" tabindex="' . ($tabindex +
$tabindex_for_null) . '"'
608 . ' name="fields_null' . $field_name_appendix . '"';
609 if ($real_null_value && !$field['first_timestamp']) {
610 echo ' checked="checked"';
612 echo ' id="field_' . ($idindex) . '_2"';
613 $onclick = ' onclick="if (this.checked) {nullify(';
614 if (strstr($field['True_Type'], 'enum')) {
615 if (strlen($field['Type']) > 20) {
620 } elseif (strstr($field['True_Type'], 'set')) {
622 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
623 // foreign key in a drop-down
625 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
626 // foreign key with a browsing icon
631 $onclick .= '\'' . PMA_escapeJsString($field['Field_html']) . '\', \'' . $field['Field_md5'] . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
634 echo ' <input type="hidden" name="fields_null' . $field_name_appendix . '"';
635 if ($real_null_value && !$field['first_timestamp']) {
641 echo ' </td>' . "\n";
643 // The value column (depends on type)
645 // See bug #1667887 for the reason why we don't use the maxlength
649 if ($foreignData['foreign_link'] == true) {
650 echo $backup_field . "\n";
652 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>"
654 <input type
="hidden" name
="fields<?php echo $field_name_appendix; ?>"
655 value
="" id
="field_<?php echo ($idindex); ?>_3A" />
656 <input type
="text" name
="field_<?php echo $field_name_appendix_md5; ?>"
657 class="textfield" <?php
echo $unnullify_trigger; ?
>
658 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
659 id
="field_<?php echo ($idindex); ?>_3"
660 value
="<?php echo htmlspecialchars($data); ?>" />
661 <script type
="text/javascript">
663 document
.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
664 document
.write(' href="browse_foreigners.php?');
665 document
.write('<?php echo PMA_generate_common_url($db, $table); ?>');
666 document
.writeln('&field=<?php echo PMA_escapeJsString(urlencode($field['Field
']) . $browse_foreigners_uri); ?>">');
667 document
.writeln('<?php echo str_replace("'", "\'
", $titles['Browse']); ?></a>');
671 } elseif (is_array($foreignData['disp_row'])) {
672 echo $backup_field . "\n
";
674 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>"
676 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>"
677 value="" id="field_
<?php
echo $idindex; ?
>_3A
" />
678 <select name="field_
<?php
echo $field_name_appendix_md5; ?
>"
679 <?php echo $unnullify_trigger; ?>
680 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
681 id="field_
<?php
echo ($idindex); ?
>_3
">
682 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
686 unset($foreignData['disp_row']);
687 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
691 <tr class="<?php
echo $odd_row ?
'odd' : 'even'; ?
>">
692 <td colspan="5" align="right
">
693 <?php echo $backup_field . "\n
"; ?>
694 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
695 rows="<?php
echo ($cfg['TextareaRows']*2); ?
>"
696 cols="<?php
echo ($cfg['TextareaCols']*2); ?
>"
697 dir="<?php
echo $text_dir; ?
>"
698 id="field_
<?php
echo ($idindex); ?
>_3
"
699 <?php echo $unnullify_trigger; ?>
700 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
701 ><?php echo $special_chars_encoded; ?></textarea>
703 } elseif (strstr($field['pma_type'], 'text')) {
704 echo $backup_field . "\n
";
706 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
707 rows="<?php
echo $cfg['TextareaRows']; ?
>"
708 cols="<?php
echo $cfg['TextareaCols']; ?
>"
709 dir="<?php
echo $text_dir; ?
>"
710 id="field_
<?php
echo ($idindex); ?
>_3
"
711 <?php echo $unnullify_trigger; ?>
712 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
713 ><?php echo $special_chars_encoded; ?></textarea>
716 if (strlen($special_chars) > 32000) {
718 echo ' <td>' . $strTextAreaLength;
720 } elseif ($field['pma_type'] == 'enum') {
721 if (! isset($table_fields[$i]['values'])) {
722 $table_fields[$i]['values'] = array();
723 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
724 // Removes automatic MySQL escape format
725 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
726 $table_fields[$i]['values'][] = array(
728 'html' => htmlspecialchars($val),
732 $field_enum_values = $table_fields[$i]['values'];
734 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="enum
" />
735 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>" value="" />
737 echo "\n
" . ' ' . $backup_field . "\n
";
739 // show dropdown or radio depend on length
740 if (strlen($field['Type']) > 20) {
742 <select name="field_
<?php
echo $field_name_appendix_md5; ?
>"
743 <?php echo $unnullify_trigger; ?>
744 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
745 id="field_
<?php
echo ($idindex); ?
>_3
">
746 <option value=""> </option>
750 foreach ($field_enum_values as $enum_value) {
752 echo '<option value="' . $enum_value['html
'] . '"';
753 if ($data == $enum_value['plain']
755 && (! isset($primary_key) || $field['Null'] != 'YES')
756 && isset($field['Default'])
757 && $enum_value['plain'] == $field['Default'])) {
758 echo ' selected="selected
"';
760 echo '>' . $enum_value['html'] . '</option>' . "\n
";
768 foreach ($field_enum_values as $enum_value) {
770 echo '<input type="radio
" name="field_
' . $field_name_appendix_md5 . '"';
771 echo ' value="' . $enum_value['html
'] . '"';
772 echo ' id="field_
' . ($idindex) . '_3_
' . $j . '"';
773 echo $unnullify_trigger;
774 if ($data == $enum_value['plain']
776 && (! isset($primary_key) || $field['Null'] != 'YES')
777 && isset($field['Default'])
778 && $enum_value['plain'] == $field['Default'])) {
779 echo ' checked="checked
"';
781 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
782 echo '<label for="field_
' . $idindex . '_3_
' . $j . '">'
783 . $enum_value['html'] . '</label>' . "\n
";
787 } elseif ($field['pma_type'] == 'set') {
788 if (! isset($table_fields[$i]['values'])) {
789 $table_fields[$i]['values'] = array();
790 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
791 $table_fields[$i]['values'][] = array(
793 'html' => htmlspecialchars($val),
796 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
798 $field_set_values = $table_fields[$i]['values'];
799 $select_size = $table_fields[$i]['select_size'];
801 $vset = array_flip(explode(',', $data));
802 echo $backup_field . "\n
";
804 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="set
" />
805 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>" value="" />
806 <select name="field_
<?php
echo $field_name_appendix_md5; ?
>"
807 size="<?php
echo $select_size; ?
>"
808 multiple="multiple
" <?php echo $unnullify_trigger; ?>
809 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
810 id="field_
<?php
echo ($idindex); ?
>_3
">
812 foreach ($field_set_values as $field_set_value) {
814 echo '<option value="' . $field_set_value['html
'] . '"';
815 if (isset($vset[$field_set_value['plain']])) {
816 echo ' selected="selected
"';
818 echo '>' . $field_set_value['html'] . '</option>' . "\n
";
824 // Change by Bernard M. Piller <bernard@bmpsystems.com>
825 // We don't want binary data destroyed
826 elseif ($field['is_binary'] || $field['is_blob']) {
827 if (($cfg['ProtectBinary'] && $field['is_blob'])
828 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
830 // rajk - for blobstreaming
831 $bs_reference_exists = FALSE;
833 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
836 $PMA_Config = $_SESSION['PMA_Config'];
838 if (!empty($PMA_Config))
840 $requiredTblType = $PMA_Config->get('PBXT_NAME');
842 if ($requiredTblType == strtolower ($tbl_type))
844 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
846 // check if blobstreaming plugins exist
849 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
851 if (!empty($bs_tables) && strlen($db) > 0)
853 $bs_tables = $bs_tables[$db];
855 if (isset($bs_tables))
857 $allBSTablesExist = TRUE;
859 foreach ($bs_tables as $table_key=>$bs_tbl)
860 if (!$bs_tables[$table_key]['Exists'])
862 $allBSTablesExist = FALSE;
866 if ($allBSTablesExist)
867 $bs_reference_exists = PMA_BS_ReferenceExists($data, $db);
868 } // end if (isset($bs_tables))
869 } // end if (!empty($bs_tables) && strlen($db) > 0)
870 } // end if ($pluginsExist)
871 } // end if ($requiredTblType == strtolower ($tbl_type))
872 } // end if (!empty($PMA_Config))
873 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
875 if ($bs_reference_exists)
877 echo '<input type="hidden
" name="remove_blob_ref_
' . $field['Field_md5
'] . $vkey . '" value="' . $data . '" />';
878 echo '<input type="checkbox
" name="remove_blob_repo_
' . $field['Field_md5
'] . $vkey . '" /> ' . $strBLOBRepositoryRemove . "<br
/>";
879 echo PMA_BS_CreateReferenceLink($data, $db);
884 echo $strBinaryDoNotEdit;
886 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
887 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
891 } // end if ($bs_reference_exists)
893 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="protected" />
894 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>" value="" />
896 } elseif ($field['is_blob']) {
898 echo $backup_field . "\n
";
900 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
901 rows="<?php
echo $cfg['TextareaRows']; ?
>"
902 cols="<?php
echo $cfg['TextareaCols']; ?
>"
903 dir="<?php
echo $text_dir; ?
>"
904 id="field_
<?php
echo ($idindex); ?
>_3
"
905 <?php echo $unnullify_trigger; ?>
906 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
907 ><?php echo $special_chars_encoded; ?></textarea>
911 // field size should be at least 4 and max 40
912 $fieldsize = min(max($field['len'], 4), 40);
914 echo $backup_field . "\n
";
916 <input type="text
" name="fields
<?php
echo $field_name_appendix; ?
>"
917 value="<?php
echo $special_chars; ?
>" size="<?php
echo $fieldsize; ?
>"
918 class="textfield
" <?php echo $unnullify_trigger; ?>
919 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
920 id="field_
<?php
echo ($idindex); ?
>_3
" />
922 } // end if...elseif...else
924 // Upload choice (only for BLOBs because the binary
925 // attribute does not imply binary contents)
926 // (displayed whatever value the ProtectBinary has)
928 if ($is_upload && $field['is_blob']) {
930 // check if field type is of longblob
931 if ($field['pma_type'] == "longblob
")
933 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
936 $PMA_Config = $_SESSION['PMA_Config'];
938 // is PMA_Config's data loaded? continue only if it is
939 if (!empty($PMA_Config))
941 $requiredTblType = $PMA_Config->get('PBXT_NAME');
943 if ($requiredTblType == strtolower ($tbl_type))
945 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
947 // check if blobstreaming plugins exist
950 $curlExists = $PMA_Config->get('CURL_EXISTS');
952 // check if CURL exists
955 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
957 // check for BLOBStreamable databases and if current database name is provided
958 if (!empty($bs_tables) && strlen($db) > 0)
960 $bs_tables = $bs_tables[$db];
962 // check if reference to BLOBStreaming tables exists
963 if (isset($bs_tables))
965 $allBSTablesExist = TRUE;
967 foreach ($bs_tables as $table_key=>$bs_tbl)
968 if (!$bs_tables[$table_key]['Exists'])
970 $allBSTablesExist = FALSE;
974 // check if necessary BLOBStreaming tables exist
975 if ($allBSTablesExist)
978 echo '<input type="checkbox
" name="upload_blob_repo_
' . $field['Field_md5
'] . $vkey . '" /> ' . $strBLOBRepositoryUpload;
979 } // end if ($allBSTablesExist)
980 } // end if (isset($bs_tables)
981 } // end if (!empty($bs_tables) && strlen ($db) > 0)
982 } // end if ($curlExists)
983 } // end if ($pluginsExist)
984 } // end if ($requiredTblType == strtolower ($tbl_type))
985 } // end if (!empty($PMA_Config))
986 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
990 echo '<input type="file
" name="fields_upload_
' . $field['Field_md5
'] . $vkey . '" class="textfield
" id="field_
' . $idindex . '_3
" size="10" /> ';
992 // find maximum upload size, based on field type
994 * @todo with functions this is not so easy, as you can basically
995 * process any data with function like MD5
997 $max_field_sizes = array(
1000 'mediumblob' => '16777216',
1001 'longblob' => '4294967296'); // yeah, really
1003 $this_field_max_size = $max_upload_size; // from PHP max
1004 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
1005 $this_field_max_size = $max_field_sizes[$field['pma_type']];
1007 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n
";
1008 // do not generate here the MAX_FILE_SIZE, because we should
1009 // put only one in the form to accommodate the biggest field
1010 if ($this_field_max_size > $biggest_max_file_size) {
1011 $biggest_max_file_size = $this_field_max_size;
1015 if (!empty($cfg['UploadDir'])) {
1016 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
1017 if ($files === FALSE) {
1018 echo ' <font color="red
">' . $strError . '</font><br />' . "\n
";
1019 echo ' ' . $strWebServerUploadDirectoryError . "\n
";
1020 } elseif (!empty($files)) {
1022 echo ' <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ':<br />' . "\n
";
1023 echo ' <select size="1" name="fields_uploadlocal_
' . $field['Field_md5
'] . $vkey . '">' . "\n
";
1024 echo ' <option value="" selected="selected
"></option>' . "\n
";
1026 echo ' </select>' . "\n
";
1028 } // end if (web-server upload directory)
1029 } // end elseif (binary or blob)
1031 // field size should be at least 4 and max 40
1032 $fieldsize = min(max($field['len'], 4), 40);
1033 echo $backup_field . "\n
";
1034 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n
") !== FALSE)) {
1037 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
1038 rows="<?php
echo $cfg['CharTextareaRows']; ?
>"
1039 cols="<?php
echo $cfg['CharTextareaCols']; ?
>"
1040 dir="<?php
echo $text_dir; ?
>"
1041 id="field_
<?php
echo ($idindex); ?
>_3
"
1042 <?php echo $unnullify_trigger; ?>
1043 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
1044 ><?php echo $special_chars_encoded; ?></textarea>
1048 <input type="text
" name="fields
<?php
echo $field_name_appendix; ?
>"
1049 value="<?php
echo $special_chars; ?
>" size="<?php
echo $fieldsize; ?
>"
1050 class="textfield
" <?php echo $unnullify_trigger; ?>
1051 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
1052 id="field_
<?php
echo ($idindex); ?
>_3
" />
1054 if ($field['Extra'] == 'auto_increment') {
1056 <input type="hidden
" name="auto_increment
<?php
echo $field_name_appendix; ?
>" value="1" />
1059 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
1061 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="timestamp
" />
1064 if ($field['True_Type'] == 'bit') {
1066 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="bit
" />
1069 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
1070 // the _3 suffix points to the date field
1071 // the _2 suffix points to the corresponding NULL checkbox
1073 <script type="text
/javascript
">
1075 document.write('<a title="<?php
echo $strCalendar;?
>"');
1076 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\'
)">');
1077 document.write('<img class="calendar
"');
1078 document.write(' src="<?php
echo $pmaThemeImage; ?
>b_calendar
.png
"');
1079 document.write(' alt="<?php
echo $strCalendar; ?
>"/></a>');
1090 $odd_row = !$odd_row;
1093 echo ' </tbody></table><br />';
1094 } // end foreach on multi-edit
1099 <table border="0" cellpadding="5" cellspacing="0">
1101 <td valign="middle
" nowrap="nowrap
">
1102 <select name="submit_type
" tabindex="<?php
echo ($tabindex +
$tabindex_for_value +
1); ?
>">
1104 if (isset($primary_key)) {
1106 <option value="<?php
echo $strSave; ?
>"><?php echo $strSave; ?></option>
1110 <option value="<?php
echo $strInsertAsNewRow; ?
>"><?php echo $strInsertAsNewRow; ?></option>
1115 if (!isset($after_insert)) {
1116 $after_insert = 'back';
1120 <td valign="middle
">
1121 <strong><?php echo $strAndThen; ?></strong>
1123 <td valign="middle
" nowrap="nowrap
">
1124 <select name="after_insert
">
1125 <option value="back
" <?php echo ($after_insert == 'back' ? 'selected="selected
"' : ''); ?>><?php echo $strAfterInsertBack; ?></option>
1126 <option value="new_insert
" <?php echo ($after_insert == 'new_insert' ? 'selected="selected
"' : ''); ?>><?php echo $strAfterInsertNewInsert; ?></option>
1128 if (isset($primary_key)) {
1130 <option value="same_insert
" <?php echo ($after_insert == 'same_insert' ? 'selected="selected
"' : ''); ?>><?php echo $strAfterInsertSame; ?></option>
1132 // If we have just numeric primary key, we can also edit next
1133 // in 2.8.2, we were looking for `field_name` = numeric_value
1134 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $primary_key)) {
1135 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1136 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $primary_key)) {
1138 <option value="edit_next
" <?php echo ($after_insert == 'edit_next' ? 'selected="selected
"' : ''); ?>><?php echo $strAfterInsertNext; ?></option>
1149 <?php echo PMA_showHint($strUseTabKey); ?>
1151 <td colspan="3" align="right
" valign="middle
">
1152 <input type="submit
" value="<?php
echo $strGo; ?
>" tabindex="<?php
echo ($tabindex +
$tabindex_for_value +
6); ?
>" id="buttonYes
" />
1153 <input type="reset
" value="<?php
echo $strReset; ?
>" tabindex="<?php
echo ($tabindex +
$tabindex_for_value +
7); ?
>" />
1158 <?php if ($biggest_max_file_size > 0) {
1159 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n
";
1165 <!-- Restart insertion form -->
1166 <form method="post
" action="tbl_replace
.php
" name="restartForm
" >
1167 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1168 <input type="hidden
" name="goto" value="<?php
echo htmlspecialchars($GLOBALS['goto']); ?
>" />
1169 <input type="hidden
" name="err_url
" value="<?php
echo htmlspecialchars($err_url); ?
>" />
1170 <input type="hidden
" name="sql_query
" value="<?php
echo htmlspecialchars($sql_query); ?
>" />
1172 if (isset($primary_keys)) {
1173 foreach ($primary_key_array as $key_id => $primary_key) {
1174 echo '<input type="hidden
" name="primary_key
[' . $key_id . ']" value="' . htmlspecialchars(trim($primary_key)) . '" />'. "\n
";
1177 $tmp = '<select name="insert_rows
" id="insert_rows
" onchange="this
.form
.submit();" >' . "\n
";
1178 $option_values = array(1,2,5,10,15,20,30,40);
1179 foreach ($option_values as $value) {
1180 $tmp .= '<option value="' . $value . '"';
1181 if ($value == $cfg['InsertRows']) {
1182 $tmp .= ' selected="selected
"';
1184 $tmp .= '>' . $value . '</option>' . "\n
";
1186 $tmp .= '</select>' . "\n
";
1187 echo "\n
" . sprintf($strRestartInsertion, $tmp);
1189 echo '<noscript><input type="submit
" value="' . $strGo . '" /></noscript>' . "\n
";
1190 echo '</form>' . "\n
";
1194 * Displays the footer
1196 require_once './libraries/footer.inc.php';