2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Displays form for editing and inserting new table rows
6 * register_globals_save (mark this file save for disabling register globals)
12 * Gets the variables sent or posted to this script and displays the header
14 require_once './libraries/common.inc.php';
17 * Ensures db and table are valid, else moves to the "parent" script
19 require_once './libraries/db_table_exists.lib.php';
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($_SESSION['edit_next'])) {
35 $primary_key = $_SESSION['edit_next'];
36 unset($_SESSION['edit_next']);
37 $after_insert = 'edit_next';
39 if (isset($_REQUEST['sql_query'])) {
40 $sql_query = $_REQUEST['sql_query'];
42 if (isset($_REQUEST['ShowFunctionFields'])) {
43 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
47 * load relation data, foreign keys
49 require_once './libraries/relation.lib.php';
54 require_once './libraries/file_listing.php';
58 * Defines the url to return to in case of error in a sql statement
59 * (at this point, $GLOBALS['goto'] will be set but could be empty)
61 if (empty($GLOBALS['goto'])) {
63 // avoid a problem (see bug #2202709)
64 $GLOBALS['goto'] = 'tbl_sql.php';
66 $GLOBALS['goto'] = 'db_sql.php';
70 * @todo check if we could replace by "db_|tbl_" - please clarify!?
74 'sql_query' => $sql_query
77 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
78 $_url_params['table'] = $table;
81 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
86 * Sets parameters for links
87 * where is this variable used?
88 * replace by PMA_generate_common_url($url_params);
90 $url_query = PMA_generate_common_url($url_params, 'html', '');
93 * get table information
94 * @todo should be done by a Table object
96 require_once './libraries/tbl_info.inc.php';
99 * Get comments for table fileds/columns
101 $comments_map = array();
103 if ($GLOBALS['cfg']['ShowPropertyComments']) {
104 $comments_map = PMA_getComments($db, $table);
108 * START REGULAR OUTPUT
112 * used in ./libraries/header.inc.php to load JavaScript library file
114 $GLOBALS['js_include'][] = 'tbl_change.js';
117 * HTTP and HTML headers
119 require_once './libraries/header.inc.php';
122 * Displays the query submitted and its result
124 * @todo where does $disp_message and $disp_query come from???
126 if (! empty($disp_message)) {
127 if (! isset($disp_query)) {
130 PMA_showMessage($disp_message, $disp_query);
134 * Displays top menu links
136 require_once './libraries/tbl_links.inc.php';
140 * Get the analysis of SHOW CREATE TABLE for this table
141 * @todo should be handled by class Table
143 $show_create_table = PMA_DBI_fetch_value(
144 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
146 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
147 unset($show_create_table);
150 * Get the list of the fields of the current table
152 PMA_DBI_select_db($db);
153 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
154 null, null, null, PMA_DBI_QUERY_STORE
);
156 if (isset($primary_key)) {
157 // when in edit mode load all selected rows from table
158 $insert_mode = false;
159 if (is_array($primary_key)) {
160 $primary_key_array = $primary_key;
162 $primary_key_array = array(0 => $primary_key);
166 $found_unique_key = false;
167 foreach ($primary_key_array as $key_id => $primary_key) {
168 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';';
169 $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE
);
170 $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
171 $primary_keys[$key_id] = str_replace('\\', '\\\\', $primary_key);
174 if (! $rows[$key_id]) {
175 unset($rows[$key_id], $primary_key_array[$key_id]);
176 PMA_showMessage($strEmptyResultSet, $local_query);
178 require_once './libraries/footer.inc.php';
179 } else { // end if (no record returned)
180 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
181 if ($tmp = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true)) {
182 $found_unique_key = true;
188 // no primary key given, just load first row - but what happens if tbale is empty?
190 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE
);
191 $rows = array_fill(0, $cfg['InsertRows'], false);
195 // retrieve keys into foreign fields, if any
196 $foreigners = PMA_getForeigners($db, $table);
202 // loic1: autocomplete feature of IE kills the "onchange" event handler and it
203 // must be replaced by the "onpropertychange" one in this case
204 $chg_evt_handler = (PMA_USR_BROWSER_AGENT
== 'IE' && PMA_USR_BROWSER_VER
>= 5 && PMA_USR_BROWSER_VER
< 7)
207 // Had to put the URI because when hosted on an https server,
208 // some browsers send wrongly this form to the http server.
210 if ($cfg['CtrlArrowsMoving']) {
212 <!-- Set on key handler
for moving using by Ctrl+arrows
-->
213 <script src
="./js/keyhandler.js" type
="text/javascript"></script
>
214 <script type
="text/javascript">
216 var switch_movement
= 0;
217 document
.onkeydown
= onKeyDownArrowsHandler
;
223 $_form_params = array(
226 'goto' => $GLOBALS['goto'],
227 'err_url' => $err_url,
228 'sql_query' => $sql_query,
230 if (isset($primary_keys)) {
231 foreach ($primary_key_array as $key_id => $primary_key) {
232 $_form_params['primary_key[' . $key_id . ']'] = trim($primary_key);
237 <!-- Insert
/Edit form
-->
238 <form method
="post" action
="tbl_replace.php" name
="insertForm" <?php
if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?
>>
240 echo PMA_generate_common_hidden_inputs($_form_params);
242 $titles['Browse'] = PMA_getIcon('b_browse.png', $strBrowseForeignValues);
244 // Set if we passed the first timestamp field
246 $fields_cnt = count($table_fields);
249 $tabindex_for_function = +
3000;
250 $tabindex_for_null = +
6000;
251 $tabindex_for_value = 0;
253 $biggest_max_file_size = 0;
255 // user can toggle the display of Function column
256 // (currently does not work for multi-edits)
257 $url_params['db'] = $db;
258 $url_params['table'] = $table;
259 if (isset($primary_key)) {
260 $url_params['primary_key'] = trim($primary_key);
262 if (! empty($sql_query)) {
263 $url_params['sql_query'] = $sql_query;
266 if (! $cfg['ShowFunctionFields']) {
267 $this_url_params = array_merge($url_params,
268 array('ShowFunctionFields' => 1));
269 echo $strShow . ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . $strFunction . '</a>' . "\n";
272 foreach ($rows as $row_id => $vrow) {
273 if ($vrow === false) {
278 $browse_foreigners_uri = '&pk=' . $row_id;
279 $vkey = '[multi_edit][' . $jsvkey . ']';
281 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ?
$result[$row_id] : $result);
282 if ($insert_mode && $row_id > 0) {
283 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_check_' . $row_id . '" />';
284 echo '<label for="insert_ignore_check_' . $row_id . '">' . $strIgnore . '</label><br />' . "\n";
290 <th
><?php
echo $strField; ?
></th
>
291 <th
><?php
echo $strType; ?
></th
>
293 if ($cfg['ShowFunctionFields']) {
294 $this_url_params = array_merge($url_params,
295 array('ShowFunctionFields' => 0));
296 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . $strHide . '">' . $strFunction . '</a></th>' . "\n";
299 <th
><?php
echo $strNull; ?
></th
>
300 <th
><?php
echo $strValue; ?
></th
>
305 <th colspan
="5" align
="right" class="tblFooters">
306 <input type
="submit" value
="<?php echo $strGo; ?>" />
312 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
313 $m_rows = $o_rows +
1;
316 for ($i = 0; $i < $fields_cnt; $i++
) {
317 if (! isset($table_fields[$i]['processed'])) {
318 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
319 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
320 // True_Type contains only the type (stops at first bracket)
321 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
325 // loic1: current date should not be set as default if the field is NULL
326 // for the current row
327 // lem9: but do not put here the current datetime if there is a default
328 // value (the real default value will be set in the
329 // Default value logic below)
331 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
332 // $field['Default'] is not set if it contains NULL:
333 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
334 // but, look what we get if we switch to iso: (Default is NULL)
335 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
336 // so I force a NULL into it (I don't think it's possible
337 // to have an empty default value for DATETIME)
338 // then, the "if" after this one will work
339 if ($table_fields[$i]['Type'] == 'datetime'
340 && ! isset($table_fields[$i]['Default'])
341 && isset($table_fields[$i]['Null'])
342 && $table_fields[$i]['Null'] == 'YES') {
343 $table_fields[$i]['Default'] = null;
346 $table_fields[$i]['len'] =
347 preg_match('@float|double@', $table_fields[$i]['Type']) ?
100 : -1;
350 if (isset($comments_map[$table_fields[$i]['Field']])) {
351 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
352 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
353 . $table_fields[$i]['Field_html'] . '</span>';
355 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
359 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
360 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
361 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
362 $table_fields[$i]['first_timestamp'] = false;
363 switch ($table_fields[$i]['True_Type']) {
365 $table_fields[$i]['pma_type'] = 'set';
366 $table_fields[$i]['wrap'] = '';
369 $table_fields[$i]['pma_type'] = 'enum';
370 $table_fields[$i]['wrap'] = '';
373 if (!$timestamp_seen) { // can only occur once per table
375 $table_fields[$i]['first_timestamp'] = true;
377 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
378 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
382 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
383 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
387 $field = $table_fields[$i];
388 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
390 if (-1 === $field['len']) {
391 $field['len'] = PMA_DBI_field_len($vresult, $i);
394 $unnullify_trigger = $chg_evt_handler . "=\"return unNullify('"
395 . PMA_escapeJsString($field['Field_html']) . "', '"
396 . PMA_escapeJsString($jsvkey) . "')\"";
397 $field_name_appendix = $vkey . '[' . $field['Field_html'] . ']';
398 $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]';
401 if ($field['Type'] == 'datetime'
402 && ! isset($field['Default'])
403 && ! is_null($field['Default'])
404 && ($insert_mode ||
! isset($vrow[$field['Field']]))) {
406 // UPDATE case with an NULL value
407 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
410 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
411 <td
<?php
echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ?
'rowspan="2"' : ''); ?
> align
="center"><?php
echo $field['Field_title']; ?
></td
>
412 <td align
="center"<?php
echo $field['wrap']; ?
>>
413 <?php
echo $field['pma_type']; ?
>
418 // Prepares the field value
419 $real_null_value = FALSE;
421 // On a BLOB that can have a NULL value, the is_null() returns
422 // true if it has no content but for me this is different than
423 // having been set explicitely to NULL so I put an exception here
424 if (! $field['is_blob'] && is_null($vrow[$field['Field']])) {
425 $real_null_value = TRUE;
426 $vrow[$field['Field']] = '';
428 $data = $vrow[$field['Field']];
429 } elseif ($field['True_Type'] == 'bit') {
430 $special_chars = PMA_printable_bit_value($vrow[$field], $extracted_fieldspec['spec_in_brackets']);
432 // loic1: special binary "characters"
433 if ($field['is_binary'] ||
$field['is_blob']) {
434 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
436 $special_chars = htmlspecialchars($vrow[$field['Field']]);
438 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
439 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
441 $data = $vrow[$field['Field']];
442 } // end if... else...
443 // loic1: if a timestamp field value is not included in an update
444 // statement MySQL auto-update it to the current timestamp
445 // lem9: however, things have changed since MySQL 4.1, so
446 // it's better to set a fields_prev in this situation
447 $backup_field = '<input type="hidden" name="fields_prev'
448 . $field_name_appendix . '" value="'
449 . htmlspecialchars($vrow[$field['Field']]) . '" />';
451 // loic1: display default values
452 if (!isset($field['Default'])) {
453 $field['Default'] = '';
454 $real_null_value = TRUE;
457 $data = $field['Default'];
459 if ($field['True_Type'] == 'bit') {
460 $special_chars = PMA_printable_bit_value($field['Default'], $extracted_fieldspec['spec_in_brackets']);
462 $special_chars = htmlspecialchars($field['Default']);
467 $idindex = ($o_rows * $fields_cnt) +
$i +
1;
468 $tabindex = (($idindex - 1) * 3) +
1;
470 // The function column
471 // -------------------
472 // Change by Bernard M. Piller <bernard@bmpsystems.com>
473 // We don't want binary data to be destroyed
474 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
475 // stored or retrieved" so it does not mean that the contents is
477 if ($cfg['ShowFunctionFields']) {
478 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
479 ||
($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
480 echo ' <td align="center">' . $strBinary . '</td>' . "\n";
481 } elseif (strstr($field['True_Type'], 'enum') ||
strstr($field['True_Type'], 'set')) {
482 echo ' <td align="center">--</td>' . "\n";
486 <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">
491 // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
492 // or something similar. Then directly look up the entry in the RestrictFunctions array,
493 // which will then reveal the available dropdown options
494 if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
495 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
496 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
497 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
498 $default_function = $cfg['DefaultFunctions'][$current_func_type];
501 $default_function = '';
504 $dropdown_built = array();
505 $op_spacing_needed = FALSE;
507 // what function defined as default?
508 // for the first timestamp we don't set the default function
509 // if there is a default value for the timestamp
510 // (not including CURRENT_TIMESTAMP)
511 // and the column does not have the
512 // ON UPDATE DEFAULT TIMESTAMP attribute.
514 if ($field['True_Type'] == 'timestamp'
515 && empty($field['Default'])
516 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
517 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
520 if ($field['Key'] == 'PRI'
521 && ($field['Type'] == 'char(36)' ||
$field['Type'] == 'varchar(36)')) {
522 $default_function = $cfg['DefaultFunctions']['pk_char36'];
525 // garvin: loop on the dropdown array and print all available options for that field.
526 foreach ($dropdown as $each_dropdown){
528 if ($default_function === $each_dropdown) {
529 echo ' selected="selected"';
531 echo '>' . $each_dropdown . '</option>' . "\n";
532 $dropdown_built[$each_dropdown] = 'TRUE';
533 $op_spacing_needed = TRUE;
536 // garvin: For compatibility's sake, do not let out all other functions. Instead
537 // print a separator (blank) and then show ALL functions which weren't shown
539 $cnt_functions = count($cfg['Functions']);
540 for ($j = 0; $j < $cnt_functions; $j++
) {
541 if (!isset($dropdown_built[$cfg['Functions'][$j]]) ||
$dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
542 // Is current function defined as default?
543 $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
544 ||
(!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
545 ?
' selected="selected"'
547 if ($op_spacing_needed == TRUE) {
549 echo '<option value="">--------</option>' . "\n";
550 $op_spacing_needed = FALSE;
554 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
563 } // end if ($cfg['ShowFunctionFields'])
569 if ($field['Null'] == 'YES') {
570 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
571 if ($real_null_value && !$field['first_timestamp']) {
576 if (!(($cfg['ProtectBinary'] && $field['is_blob']) ||
($cfg['ProtectBinary'] == 'all' && $field['is_binary']))) {
578 echo ' <input type="checkbox" tabindex="' . ($tabindex +
$tabindex_for_null) . '"'
579 . ' name="fields_null' . $field_name_appendix . '"';
580 if ($real_null_value && !$field['first_timestamp']) {
581 echo ' checked="checked"';
583 echo ' id="field_' . ($idindex) . '_2"';
584 $onclick = ' onclick="if (this.checked) {nullify(';
585 if (strstr($field['True_Type'], 'enum')) {
586 if (strlen($field['Type']) > 20) {
591 } elseif (strstr($field['True_Type'], 'set')) {
593 } elseif ($foreigners && isset($foreigners[$field['Field']])) {
598 $onclick .= '\'' . PMA_escapeJsString($field['Field_html']) . '\', \'' . $field['Field_md5'] . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
601 echo ' <input type="hidden" name="fields_null' . $field_name_appendix . '"';
602 if ($real_null_value && !$field['first_timestamp']) {
608 echo ' </td>' . "\n";
610 // The value column (depends on type)
612 // See bug #1667887 for the reason why we don't use the maxlength
615 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
617 if ($foreignData['foreign_link'] == true) {
618 echo $backup_field . "\n";
620 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>"
622 <input type
="hidden" name
="fields<?php echo $field_name_appendix; ?>"
623 value
="" id
="field_<?php echo ($idindex); ?>_3A" />
624 <input type
="text" name
="field_<?php echo $field_name_appendix_md5; ?>"
625 class="textfield" <?php
echo $unnullify_trigger; ?
>
626 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
627 id
="field_<?php echo ($idindex); ?>_3"
628 value
="<?php echo htmlspecialchars($data); ?>" />
629 <script type
="text/javascript">
631 document
.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
632 document
.write(' href="browse_foreigners.php?');
633 document
.write('<?php echo PMA_generate_common_url($db, $table); ?>');
634 document
.writeln('&field=<?php echo PMA_escapeJsString(urlencode($field['Field
']) . $browse_foreigners_uri); ?>">');
635 document
.writeln('<?php echo str_replace("'", "\'
", $titles['Browse']); ?></a>');
639 } elseif (is_array($foreignData['disp_row'])) {
640 echo $backup_field . "\n
";
642 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>"
644 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>"
645 value="" id="field_
<?php
echo $idindex; ?
>_3A
" />
646 <select name="field_
<?php
echo $field_name_appendix_md5; ?
>"
647 <?php echo $unnullify_trigger; ?>
648 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
649 id="field_
<?php
echo ($idindex); ?
>_3
">
650 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
654 unset($foreignData['disp_row']);
655 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
659 <tr class="<?php
echo $odd_row ?
'odd' : 'even'; ?
>">
660 <td colspan="5" align="right
">
661 <?php echo $backup_field . "\n
"; ?>
662 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
663 rows="<?php
echo ($cfg['TextareaRows']*2); ?
>"
664 cols="<?php
echo ($cfg['TextareaCols']*2); ?
>"
665 dir="<?php
echo $text_dir; ?
>"
666 id="field_
<?php
echo ($idindex); ?
>_3
"
667 <?php echo $unnullify_trigger; ?>
668 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
669 ><?php echo $special_chars_encoded; ?></textarea>
671 } elseif (strstr($field['pma_type'], 'text')) {
672 echo $backup_field . "\n
";
674 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
675 rows="<?php
echo $cfg['TextareaRows']; ?
>"
676 cols="<?php
echo $cfg['TextareaCols']; ?
>"
677 dir="<?php
echo $text_dir; ?
>"
678 id="field_
<?php
echo ($idindex); ?
>_3
"
679 <?php echo $unnullify_trigger; ?>
680 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
681 ><?php echo $special_chars_encoded; ?></textarea>
684 if (strlen($special_chars) > 32000) {
686 echo ' <td>' . $strTextAreaLength;
688 } elseif ($field['pma_type'] == 'enum') {
689 if (! isset($table_fields[$i]['values'])) {
690 $table_fields[$i]['values'] = array();
691 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
692 // Removes automatic MySQL escape format
693 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
694 $table_fields[$i]['values'][] = array(
696 'html' => htmlspecialchars($val),
700 $field_enum_values = $table_fields[$i]['values'];
702 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="enum
" />
703 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>" value="" />
705 echo "\n
" . ' ' . $backup_field . "\n
";
707 // show dropdown or radio depend on length
708 if (strlen($field['Type']) > 20) {
710 <select name="field_
<?php
echo $field_name_appendix_md5; ?
>"
711 <?php echo $unnullify_trigger; ?>
712 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
713 id="field_
<?php
echo ($idindex); ?
>_3
">
714 <option value=""> </option>
718 foreach ($field_enum_values as $enum_value) {
720 echo '<option value="' . $enum_value['html
'] . '"';
721 if ($data == $enum_value['plain']
723 && (! isset($primary_key) || $field['Null'] != 'YES')
724 && isset($field['Default'])
725 && $enum_value['plain'] == $field['Default'])) {
726 echo ' selected="selected
"';
728 echo '>' . $enum_value['html'] . '</option>' . "\n
";
736 foreach ($field_enum_values as $enum_value) {
738 echo '<input type="radio
" name="field_
' . $field_name_appendix_md5 . '"';
739 echo ' value="' . $enum_value['html
'] . '"';
740 echo ' id="field_
' . ($idindex) . '_3_
' . $j . '"';
742 echo "if (typeof(document.forms['insertForm
'].elements['fields_null
"
743 . $field_name_appendix . "']) != 'undefined
') {document.forms['insertForm
'].elements['fields_null
"
744 . $field_name_appendix . "'].checked = false}";
746 if ($data == $enum_value['plain']
748 && (! isset($primary_key) || $field['Null'] != 'YES')
749 && isset($field['Default'])
750 && $enum_value['plain'] == $field['Default'])) {
751 echo ' checked="checked
"';
753 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
754 echo '<label for="field_
' . $idindex . '_3_
' . $j . '">'
755 . $enum_value['html'] . '</label>' . "\n
";
759 } elseif ($field['pma_type'] == 'set') {
760 if (! isset($table_fields[$i]['values'])) {
761 $table_fields[$i]['values'] = array();
762 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
763 $table_fields[$i]['values'][] = array(
765 'html' => htmlspecialchars($val),
768 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
770 $field_set_values = $table_fields[$i]['values'];
771 $select_size = $table_fields[$i]['select_size'];
773 $vset = array_flip(explode(',', $data));
774 echo $backup_field . "\n
";
776 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="set
" />
777 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>" value="" />
778 <select name="field_
<?php
echo $field_name_appendix_md5; ?
>"
779 size="<?php
echo $select_size; ?
>"
780 multiple="multiple
" <?php echo $unnullify_trigger; ?>
781 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
782 id="field_
<?php
echo ($idindex); ?
>_3
">
784 foreach ($field_set_values as $field_set_value) {
786 echo '<option value="' . $field_set_value['html
'] . '"';
787 if (isset($vset[$field_set_value['plain']])) {
788 echo ' selected="selected
"';
790 echo '>' . $field_set_value['html'] . '</option>' . "\n
";
796 // Change by Bernard M. Piller <bernard@bmpsystems.com>
797 // We don't want binary data destroyed
798 elseif ($field['is_binary'] || $field['is_blob']) {
799 if (($cfg['ProtectBinary'] && $field['is_blob'])
800 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
802 // rajk - for blobstreaming
803 $bs_reference_exists = FALSE;
805 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
808 $PMA_Config = $_SESSION['PMA_Config'];
810 if (!empty($PMA_Config))
812 $requiredTblType = $PMA_Config->get('PBXT_NAME');
814 if ($requiredTblType == strtolower ($tbl_type))
816 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
818 // check if blobstreaming plugins exist
821 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
823 if (!empty($bs_tables) && strlen($db) > 0)
825 $bs_tables = $bs_tables[$db];
827 if (isset($bs_tables))
829 $allBSTablesExist = TRUE;
831 foreach ($bs_tables as $table_key=>$bs_tbl)
832 if (!$bs_tables[$table_key]['Exists'])
834 $allBSTablesExist = FALSE;
838 if ($allBSTablesExist)
839 $bs_reference_exists = PMA_BS_ReferenceExists($data, $db);
840 } // end if (isset($bs_tables))
841 } // end if (!empty($bs_tables) && strlen($db) > 0)
842 } // end if ($pluginsExist)
843 } // end if ($requiredTblType == strtolower ($tbl_type))
844 } // end if (!empty($PMA_Config))
845 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
847 if ($bs_reference_exists)
849 echo '<input type="hidden
" name="remove_blob_ref_
' . $field['Field_html
'] . $vkey . '" value="' . $data . '" />';
850 echo '<input type="checkbox
" name="remove_blob_repo_
' . $field['Field_html
'] . $vkey . '" /> ' . $strBLOBRepositoryRemove . "<br
/>";
851 echo PMA_BS_CreateReferenceLink($data, $db);
856 echo $strBinaryDoNotEdit;
858 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
859 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
863 } // end if ($bs_reference_exists)
865 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="protected" />
866 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>" value="" />
868 } elseif ($field['is_blob']) {
870 echo $backup_field . "\n
";
872 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
873 rows="<?php
echo $cfg['TextareaRows']; ?
>"
874 cols="<?php
echo $cfg['TextareaCols']; ?
>"
875 dir="<?php
echo $text_dir; ?
>"
876 id="field_
<?php
echo ($idindex); ?
>_3
"
877 <?php echo $unnullify_trigger; ?>
878 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
879 ><?php echo $special_chars_encoded; ?></textarea>
883 // field size should be at least 4 and max 40
884 $fieldsize = min(max($field['len'], 4), 40);
886 echo $backup_field . "\n
";
888 <input type="text
" name="fields
<?php
echo $field_name_appendix; ?
>"
889 value="<?php
echo $special_chars; ?
>" size="<?php
echo $fieldsize; ?
>"
890 class="textfield
" <?php echo $unnullify_trigger; ?>
891 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
892 id="field_
<?php
echo ($idindex); ?
>_3
" />
894 } // end if...elseif...else
896 // Upload choice (only for BLOBs because the binary
897 // attribute does not imply binary contents)
898 // (displayed whatever value the ProtectBinary has)
900 if ($is_upload && $field['is_blob']) {
902 // check if field type is of longblob
903 if ($field['pma_type'] == "longblob
")
905 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
908 $PMA_Config = $_SESSION['PMA_Config'];
910 // is PMA_Config's data loaded? continue only if it is
911 if (!empty($PMA_Config))
913 $requiredTblType = $PMA_Config->get('PBXT_NAME');
915 if ($requiredTblType == strtolower ($tbl_type))
917 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
919 // check if blobstreaming plugins exist
922 $curlExists = $PMA_Config->get('CURL_EXISTS');
924 // check if CURL exists
927 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
929 // check for BLOBStreamable databases and if current database name is provided
930 if (!empty($bs_tables) && strlen($db) > 0)
932 $bs_tables = $bs_tables[$db];
934 // check if reference to BLOBStreaming tables exists
935 if (isset($bs_tables))
937 $allBSTablesExist = TRUE;
939 foreach ($bs_tables as $table_key=>$bs_tbl)
940 if (!$bs_tables[$table_key]['Exists'])
942 $allBSTablesExist = FALSE;
946 // check if necessary BLOBStreaming tables exist
947 if ($allBSTablesExist)
950 echo '<input type="checkbox
" name="upload_blob_repo_
' . $field['Field_html
'] . $vkey . '" /> ' . $strBLOBRepositoryUpload;
951 } // end if ($allBSTablesExist)
952 } // end if (isset($bs_tables)
953 } // end if (!empty($bs_tables) && strlen ($db) > 0)
954 } // end if ($curlExists)
955 } // end if ($pluginsExist)
956 } // end if ($requiredTblType == strtolower ($tbl_type))
957 } // end if (!empty($PMA_Config))
958 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
962 echo '<input type="file
" name="fields_upload_
' . $field['Field_html
'] . $vkey . '" class="textfield
" id="field_
' . $idindex . '_3
" size="10" /> ';
964 // find maximum upload size, based on field type
966 * @todo with functions this is not so easy, as you can basically
967 * process any data with function like MD5
969 $max_field_sizes = array(
972 'mediumblob' => '16777216',
973 'longblob' => '4294967296'); // yeah, really
975 $this_field_max_size = $max_upload_size; // from PHP max
976 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
977 $this_field_max_size = $max_field_sizes[$field['pma_type']];
979 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n
";
980 // do not generate here the MAX_FILE_SIZE, because we should
981 // put only one in the form to accommodate the biggest field
982 if ($this_field_max_size > $biggest_max_file_size) {
983 $biggest_max_file_size = $this_field_max_size;
987 if (!empty($cfg['UploadDir'])) {
988 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
989 if ($files === FALSE) {
990 echo ' <font color="red
">' . $strError . '</font><br />' . "\n
";
991 echo ' ' . $strWebServerUploadDirectoryError . "\n
";
992 } elseif (!empty($files)) {
994 echo ' <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ':<br />' . "\n
";
995 echo ' <select size="1" name="fields_uploadlocal_
' . $field['Field_html
'] . $vkey . '">' . "\n
";
996 echo ' <option value="" selected="selected
"></option>' . "\n
";
998 echo ' </select>' . "\n
";
1000 } // end if (web-server upload directory)
1001 } // end elseif (binary or blob)
1003 // field size should be at least 4 and max 40
1004 $fieldsize = min(max($field['len'], 4), 40);
1005 echo $backup_field . "\n
";
1006 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n
") !== FALSE)) {
1009 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
1010 rows="<?php
echo $cfg['CharTextareaRows']; ?
>"
1011 cols="<?php
echo $cfg['CharTextareaCols']; ?
>"
1012 dir="<?php
echo $text_dir; ?
>"
1013 id="field_
<?php
echo ($idindex); ?
>_3
"
1014 <?php echo $unnullify_trigger; ?>
1015 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
1016 ><?php echo $special_chars_encoded; ?></textarea>
1020 <input type="text
" name="fields
<?php
echo $field_name_appendix; ?
>"
1021 value="<?php
echo $special_chars; ?
>" size="<?php
echo $fieldsize; ?
>"
1022 class="textfield
" <?php echo $unnullify_trigger; ?>
1023 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
1024 id="field_
<?php
echo ($idindex); ?
>_3
" />
1026 if ($field['Extra'] == 'auto_increment') {
1028 <input type="hidden
" name="auto_increment
<?php
echo $field_name_appendix; ?
>" value="1" />
1031 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
1033 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="timestamp
" />
1036 if ($field['True_Type'] == 'bit') {
1038 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="bit
" />
1041 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
1043 <script type="text
/javascript
">
1045 document.write('<a title="<?php
echo $strCalendar;?
>"');
1046 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); ?
>\')">');
1047 document.write('<img class="calendar
"');
1048 document.write(' src="<?php
echo $pmaThemeImage; ?
>b_calendar
.png
"');
1049 document.write(' alt="<?php
echo $strCalendar; ?
>"/></a>');
1060 $odd_row = !$odd_row;
1063 echo ' </tbody></table><br />';
1064 } // end foreach on multi-edit
1069 <table border="0" cellpadding="5" cellspacing="0">
1071 <td valign="middle
" nowrap="nowrap
">
1072 <select name="submit_type
" tabindex="<?php
echo ($tabindex +
$tabindex_for_value +
1); ?
>">
1074 if (isset($primary_key)) {
1076 <option value="<?php
echo $strSave; ?
>"><?php echo $strSave; ?></option>
1080 <option value="<?php
echo $strInsertAsNewRow; ?
>"><?php echo $strInsertAsNewRow; ?></option>
1085 if (!isset($after_insert)) {
1086 $after_insert = 'back';
1090 <td valign="middle
">
1091 <strong><?php echo $strAndThen; ?></strong>
1093 <td valign="middle
" nowrap="nowrap
">
1094 <select name="after_insert
">
1095 <option value="back
" <?php echo ($after_insert == 'back' ? 'selected="selected
"' : ''); ?>><?php echo $strAfterInsertBack; ?></option>
1096 <option value="new_insert
" <?php echo ($after_insert == 'new_insert' ? 'selected="selected
"' : ''); ?>><?php echo $strAfterInsertNewInsert; ?></option>
1098 if (isset($primary_key)) {
1100 <option value="same_insert
" <?php echo ($after_insert == 'same_insert' ? 'selected="selected
"' : ''); ?>><?php echo $strAfterInsertSame; ?></option>
1102 // If we have just numeric primary key, we can also edit next
1103 // in 2.8.2, we were looking for `field_name` = numeric_value
1104 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $primary_key)) {
1105 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1106 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $primary_key)) {
1108 <option value="edit_next
" <?php echo ($after_insert == 'edit_next' ? 'selected="selected
"' : ''); ?>><?php echo $strAfterInsertNext; ?></option>
1119 <?php echo PMA_showHint($strUseTabKey); ?>
1121 <td colspan="3" align="right
" valign="middle
">
1122 <input type="submit
" value="<?php
echo $strGo; ?
>" tabindex="<?php
echo ($tabindex +
$tabindex_for_value +
6); ?
>" id="buttonYes
" />
1123 <input type="reset
" value="<?php
echo $strReset; ?
>" tabindex="<?php
echo ($tabindex +
$tabindex_for_value +
7); ?
>" />
1128 <?php if ($biggest_max_file_size > 0) {
1129 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n
";
1135 <!-- Restart insertion form -->
1136 <form method="post
" action="tbl_replace
.php
" name="restartForm
" >
1137 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1138 <input type="hidden
" name="goto" value="<?php
echo htmlspecialchars($GLOBALS['goto']); ?
>" />
1139 <input type="hidden
" name="err_url
" value="<?php
echo htmlspecialchars($err_url); ?
>" />
1140 <input type="hidden
" name="sql_query
" value="<?php
echo htmlspecialchars($sql_query); ?
>" />
1142 if (isset($primary_keys)) {
1143 foreach ($primary_key_array as $key_id => $primary_key) {
1144 echo '<input type="hidden
" name="primary_key
[' . $key_id . ']" value="' . htmlspecialchars(trim($primary_key)) . '" />'. "\n
";
1147 $tmp = '<select name="insert_rows
" id="insert_rows
" onchange="this
.form
.submit();" >' . "\n
";
1148 $option_values = array(1,2,5,10,15,20,30,40);
1149 foreach ($option_values as $value) {
1150 $tmp .= '<option value="' . $value . '"';
1151 if ($value == $cfg['InsertRows']) {
1152 $tmp .= ' selected="selected
"';
1154 $tmp .= '>' . $value . '</option>' . "\n
";
1156 $tmp .= '</select>' . "\n
";
1157 echo "\n
" . sprintf($strRestartInsertion, $tmp);
1159 echo '<noscript><input type="submit
" value="' . $strGo . '" /></noscript>' . "\n
";
1160 echo '</form>' . "\n
";
1164 * Displays the footer
1166 require_once './libraries/footer.inc.php';