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';
24 * Sets global variables.
25 * Here it's better to use a if, instead of the '?' operator
26 * to avoid setting a variable to '' when it's not present in $_REQUEST
29 * @todo this one is badly named, it's really a WHERE condition
30 * and exists even for tables not having a primary key or unique key
32 if (isset($_REQUEST['primary_key'])) {
33 $primary_key = $_REQUEST['primary_key'];
35 if (isset($_SESSION['edit_next'])) {
36 $primary_key = $_SESSION['edit_next'];
37 unset($_SESSION['edit_next']);
38 $after_insert = 'edit_next';
40 if (isset($_REQUEST['sql_query'])) {
41 $sql_query = $_REQUEST['sql_query'];
43 if (isset($_REQUEST['ShowFunctionFields'])) {
44 $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
48 * load relation data, foreign keys
50 require_once './libraries/relation.lib.php';
55 require_once './libraries/file_listing.php';
59 * Defines the url to return to in case of error in a sql statement
60 * (at this point, $GLOBALS['goto'] will be set but could be empty)
62 if (empty($GLOBALS['goto'])) {
64 // avoid a problem (see bug #2202709)
65 $GLOBALS['goto'] = 'tbl_sql.php';
67 $GLOBALS['goto'] = 'db_sql.php';
71 * @todo check if we could replace by "db_|tbl_" - please clarify!?
75 'sql_query' => $sql_query
78 if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
79 $_url_params['table'] = $table;
82 $err_url = $GLOBALS['goto'] . PMA_generate_common_url($_url_params);
87 * Sets parameters for links
88 * where is this variable used?
89 * replace by PMA_generate_common_url($url_params);
91 $url_query = PMA_generate_common_url($url_params, 'html', '');
94 * get table information
95 * @todo should be done by a Table object
97 require_once './libraries/tbl_info.inc.php';
100 * Get comments for table fileds/columns
102 $comments_map = array();
104 if ($GLOBALS['cfg']['ShowPropertyComments']) {
105 $comments_map = PMA_getComments($db, $table);
109 * START REGULAR OUTPUT
113 * used in ./libraries/header.inc.php to load JavaScript library file
115 $GLOBALS['js_include'][] = 'tbl_change.js';
118 * HTTP and HTML headers
120 require_once './libraries/header.inc.php';
123 * Displays the query submitted and its result
125 * @todo where does $disp_message and $disp_query come from???
127 if (! empty($disp_message)) {
128 if (! isset($disp_query)) {
131 PMA_showMessage($disp_message, $disp_query);
135 * Displays top menu links
137 require_once './libraries/tbl_links.inc.php';
141 * Get the analysis of SHOW CREATE TABLE for this table
142 * @todo should be handled by class Table
144 $show_create_table = PMA_DBI_fetch_value(
145 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
147 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
148 unset($show_create_table);
151 * Get the list of the fields of the current table
153 PMA_DBI_select_db($db);
154 $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
155 null, null, null, PMA_DBI_QUERY_STORE
);
157 if (isset($primary_key)) {
158 // when in edit mode load all selected rows from table
159 $insert_mode = false;
160 if (is_array($primary_key)) {
161 $primary_key_array = $primary_key;
163 $primary_key_array = array(0 => $primary_key);
167 $found_unique_key = false;
168 foreach ($primary_key_array as $key_id => $primary_key) {
169 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';';
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 $primary_keys[$key_id] = str_replace('\\', '\\\\', $primary_key);
175 if (! $rows[$key_id]) {
176 unset($rows[$key_id], $primary_key_array[$key_id]);
177 PMA_showMessage($strEmptyResultSet, $local_query);
179 require_once './libraries/footer.inc.php';
180 } else { // end if (no record returned)
181 $meta = PMA_DBI_get_fields_meta($result[$key_id]);
182 if ($tmp = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true)) {
183 $found_unique_key = true;
189 // no primary key given, just load first row - but what happens if tbale is empty?
191 $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE
);
192 $rows = array_fill(0, $cfg['InsertRows'], false);
196 // retrieve keys into foreign fields, if any
197 $foreigners = PMA_getForeigners($db, $table);
203 // loic1: autocomplete feature of IE kills the "onchange" event handler and it
204 // must be replaced by the "onpropertychange" one in this case
205 $chg_evt_handler = (PMA_USR_BROWSER_AGENT
== 'IE' && PMA_USR_BROWSER_VER
>= 5 && PMA_USR_BROWSER_VER
< 7)
208 // Had to put the URI because when hosted on an https server,
209 // some browsers send wrongly this form to the http server.
211 if ($cfg['CtrlArrowsMoving']) {
213 <!-- Set on key handler
for moving using by Ctrl+arrows
-->
214 <script src
="./js/keyhandler.js" type
="text/javascript"></script
>
215 <script type
="text/javascript">
217 var switch_movement
= 0;
218 document
.onkeydown
= onKeyDownArrowsHandler
;
224 $_form_params = array(
227 'goto' => $GLOBALS['goto'],
228 'err_url' => $err_url,
229 'sql_query' => $sql_query,
231 if (isset($primary_keys)) {
232 foreach ($primary_key_array as $key_id => $primary_key) {
233 $_form_params['primary_key[' . $key_id . ']'] = trim($primary_key);
238 <!-- Insert
/Edit form
-->
239 <form method
="post" action
="tbl_replace.php" name
="insertForm" <?php
if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?
>>
241 echo PMA_generate_common_hidden_inputs($_form_params);
243 $titles['Browse'] = PMA_getIcon('b_browse.png', $strBrowseForeignValues);
245 // Set if we passed the first timestamp field
247 $fields_cnt = count($table_fields);
250 $tabindex_for_function = +
3000;
251 $tabindex_for_null = +
6000;
252 $tabindex_for_value = 0;
254 $biggest_max_file_size = 0;
256 // user can toggle the display of Function column
257 // (currently does not work for multi-edits)
258 $url_params['db'] = $db;
259 $url_params['table'] = $table;
260 if (isset($primary_key)) {
261 $url_params['primary_key'] = trim($primary_key);
263 if (! empty($sql_query)) {
264 $url_params['sql_query'] = $sql_query;
267 if (! $cfg['ShowFunctionFields']) {
268 $this_url_params = array_merge($url_params,
269 array('ShowFunctionFields' => 1));
270 echo $strShow . ' : <a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '">' . $strFunction . '</a>' . "\n";
273 foreach ($rows as $row_id => $vrow) {
274 if ($vrow === false) {
279 $browse_foreigners_uri = '&pk=' . $row_id;
280 $vkey = '[multi_edit][' . $jsvkey . ']';
282 $vresult = (isset($result) && is_array($result) && isset($result[$row_id]) ?
$result[$row_id] : $result);
283 if ($insert_mode && $row_id > 0) {
284 echo '<input type="checkbox" checked="checked" name="insert_ignore_' . $row_id . '" id="insert_ignore_check_' . $row_id . '" />';
285 echo '<label for="insert_ignore_check_' . $row_id . '">' . $strIgnore . '</label><br />' . "\n";
291 <th
><?php
echo $strField; ?
></th
>
292 <th
><?php
echo $strType; ?
></th
>
294 if ($cfg['ShowFunctionFields']) {
295 $this_url_params = array_merge($url_params,
296 array('ShowFunctionFields' => 0));
297 echo ' <th><a href="tbl_change.php' . PMA_generate_common_url($this_url_params) . '" title="' . $strHide . '">' . $strFunction . '</a></th>' . "\n";
300 <th
><?php
echo $strNull; ?
></th
>
301 <th
><?php
echo $strValue; ?
></th
>
306 <th colspan
="5" align
="right" class="tblFooters">
307 <input type
="submit" value
="<?php echo $strGo; ?>" />
313 // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one)
314 $m_rows = $o_rows +
1;
317 for ($i = 0; $i < $fields_cnt; $i++
) {
318 if (! isset($table_fields[$i]['processed'])) {
319 $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']);
320 $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']);
321 // True_Type contains only the type (stops at first bracket)
322 $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']);
326 // loic1: current date should not be set as default if the field is NULL
327 // for the current row
328 // lem9: but do not put here the current datetime if there is a default
329 // value (the real default value will be set in the
330 // Default value logic below)
332 // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
333 // $field['Default'] is not set if it contains NULL:
334 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime)
335 // but, look what we get if we switch to iso: (Default is NULL)
336 // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime)
337 // so I force a NULL into it (I don't think it's possible
338 // to have an empty default value for DATETIME)
339 // then, the "if" after this one will work
340 if ($table_fields[$i]['Type'] == 'datetime'
341 && ! isset($table_fields[$i]['Default'])
342 && isset($table_fields[$i]['Null'])
343 && $table_fields[$i]['Null'] == 'YES') {
344 $table_fields[$i]['Default'] = null;
347 $table_fields[$i]['len'] =
348 preg_match('@float|double@', $table_fields[$i]['Type']) ?
100 : -1;
351 if (isset($comments_map[$table_fields[$i]['Field']])) {
352 $table_fields[$i]['Field_title'] = '<span style="border-bottom: 1px dashed black;" title="'
353 . htmlspecialchars($comments_map[$table_fields[$i]['Field']]) . '">'
354 . $table_fields[$i]['Field_html'] . '</span>';
356 $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html'];
360 $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary');
361 $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob');
362 $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char');
363 $table_fields[$i]['first_timestamp'] = false;
364 switch ($table_fields[$i]['True_Type']) {
366 $table_fields[$i]['pma_type'] = 'set';
367 $table_fields[$i]['wrap'] = '';
370 $table_fields[$i]['pma_type'] = 'enum';
371 $table_fields[$i]['wrap'] = '';
374 if (!$timestamp_seen) { // can only occur once per table
376 $table_fields[$i]['first_timestamp'] = true;
378 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
379 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
383 $table_fields[$i]['pma_type'] = $table_fields[$i]['Type'];
384 $table_fields[$i]['wrap'] = ' nowrap="nowrap"';
388 $field = $table_fields[$i];
389 $extracted_fieldspec = PMA_extractFieldSpec($field['Type']);
391 if (-1 === $field['len']) {
392 $field['len'] = PMA_DBI_field_len($vresult, $i);
395 $unnullify_trigger = $chg_evt_handler . "=\"return unNullify('"
396 . PMA_escapeJsString($field['Field_md5']) . "', '"
397 . PMA_escapeJsString($jsvkey) . "')\"";
399 // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 )
400 $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']';
401 $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]';
404 if ($field['Type'] == 'datetime'
405 && ! isset($field['Default'])
406 && ! is_null($field['Default'])
407 && ($insert_mode ||
! isset($vrow[$field['Field']]))) {
409 // UPDATE case with an NULL value
410 $vrow[$field['Field']] = date('Y-m-d H:i:s', time());
413 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
414 <td
<?php
echo ($cfg['LongtextDoubleTextarea'] && strstr($field['True_Type'], 'longtext') ?
'rowspan="2"' : ''); ?
> align
="center">
415 <?php
echo $field['Field_title']; ?
>
416 <input type
="hidden" name
="fields_name<?php echo $field_name_appendix; ?>" value
="<?php echo $field['Field_html']; ?>"/>
418 <td align
="center"<?php
echo $field['wrap']; ?
>>
419 <?php
echo $field['pma_type']; ?
>
424 // Prepares the field value
425 $real_null_value = FALSE;
426 $special_chars_encoded = '';
428 // On a BLOB that can have a NULL value, the is_null() returns
429 // true if it has no content but for me this is different than
430 // having been set explicitely to NULL so I put an exception here
431 if (! $field['is_blob'] && is_null($vrow[$field['Field']])) {
432 $real_null_value = TRUE;
433 $vrow[$field['Field']] = '';
435 $data = $vrow[$field['Field']];
436 } elseif ($field['True_Type'] == 'bit') {
437 $special_chars = PMA_printable_bit_value($vrow[$field['Field']], $extracted_fieldspec['spec_in_brackets']);
439 // loic1: special binary "characters"
440 if ($field['is_binary'] ||
$field['is_blob']) {
441 $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]);
443 $special_chars = htmlspecialchars($vrow[$field['Field']]);
445 //We need to duplicate the first \n or otherwise we will lose the first newline entered in a VARCHAR or TEXT column
446 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
448 $data = $vrow[$field['Field']];
449 } // end if... else...
450 // loic1: if a timestamp field value is not included in an update
451 // statement MySQL auto-update it to the current timestamp
452 // lem9: however, things have changed since MySQL 4.1, so
453 // it's better to set a fields_prev in this situation
454 $backup_field = '<input type="hidden" name="fields_prev'
455 . $field_name_appendix . '" value="'
456 . htmlspecialchars($vrow[$field['Field']]) . '" />';
458 // loic1: display default values
459 if (!isset($field['Default'])) {
460 $field['Default'] = '';
461 $real_null_value = TRUE;
464 $data = $field['Default'];
466 if ($field['True_Type'] == 'bit') {
467 $special_chars = PMA_convert_bit_default_value($field['Default']);
469 $special_chars = htmlspecialchars($field['Default']);
472 $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
475 $idindex = ($o_rows * $fields_cnt) +
$i +
1;
476 $tabindex = (($idindex - 1) * 3) +
1;
478 // The function column
479 // -------------------
480 // Change by Bernard M. Piller <bernard@bmpsystems.com>
481 // We don't want binary data to be destroyed
482 // Note: from the MySQL manual: "BINARY doesn't affect how the column is
483 // stored or retrieved" so it does not mean that the contents is
485 if ($cfg['ShowFunctionFields']) {
486 if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload)
487 ||
($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
488 echo ' <td align="center">' . $strBinary . '</td>' . "\n";
489 } elseif (strstr($field['True_Type'], 'enum') ||
strstr($field['True_Type'], 'set')) {
490 echo ' <td align="center">--</td>' . "\n";
494 <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">
499 // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
500 // or something similar. Then directly look up the entry in the RestrictFunctions array,
501 // which will then reveal the available dropdown options
502 if (isset($cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])])
503 && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])]])) {
504 $current_func_type = $cfg['RestrictColumnTypes'][strtoupper($field['True_Type'])];
505 $dropdown = $cfg['RestrictFunctions'][$current_func_type];
506 $default_function = $cfg['DefaultFunctions'][$current_func_type];
509 $default_function = '';
512 $dropdown_built = array();
513 $op_spacing_needed = FALSE;
515 // what function defined as default?
516 // for the first timestamp we don't set the default function
517 // if there is a default value for the timestamp
518 // (not including CURRENT_TIMESTAMP)
519 // and the column does not have the
520 // ON UPDATE DEFAULT TIMESTAMP attribute.
522 if ($field['True_Type'] == 'timestamp'
523 && empty($field['Default'])
524 && ! isset($analyzed_sql[0]['create_table_fields'][$field['Field']]['on_update_current_timestamp'])) {
525 $default_function = $cfg['DefaultFunctions']['first_timestamp'];
528 if ($field['Key'] == 'PRI'
529 && ($field['Type'] == 'char(36)' ||
$field['Type'] == 'varchar(36)')) {
530 $default_function = $cfg['DefaultFunctions']['pk_char36'];
533 // garvin: loop on the dropdown array and print all available options for that field.
534 foreach ($dropdown as $each_dropdown){
536 if ($default_function === $each_dropdown) {
537 echo ' selected="selected"';
539 echo '>' . $each_dropdown . '</option>' . "\n";
540 $dropdown_built[$each_dropdown] = 'TRUE';
541 $op_spacing_needed = TRUE;
544 // garvin: For compatibility's sake, do not let out all other functions. Instead
545 // print a separator (blank) and then show ALL functions which weren't shown
547 $cnt_functions = count($cfg['Functions']);
548 for ($j = 0; $j < $cnt_functions; $j++
) {
549 if (!isset($dropdown_built[$cfg['Functions'][$j]]) ||
$dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
550 // Is current function defined as default?
551 $selected = ($field['first_timestamp'] && $cfg['Functions'][$j] == $cfg['DefaultFunctions']['first_timestamp'])
552 ||
(!$field['first_timestamp'] && $cfg['Functions'][$j] == $default_function)
553 ?
' selected="selected"'
555 if ($op_spacing_needed == TRUE) {
557 echo '<option value="">--------</option>' . "\n";
558 $op_spacing_needed = FALSE;
562 echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
571 } // end if ($cfg['ShowFunctionFields'])
576 $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', '');
578 if ($field['Null'] == 'YES') {
579 echo ' <input type="hidden" name="fields_null_prev' . $field_name_appendix . '"';
580 if ($real_null_value && !$field['first_timestamp']) {
585 if (!(($cfg['ProtectBinary'] && $field['is_blob']) ||
($cfg['ProtectBinary'] == 'all' && $field['is_binary']))) {
587 echo ' <input type="checkbox" tabindex="' . ($tabindex +
$tabindex_for_null) . '"'
588 . ' name="fields_null' . $field_name_appendix . '"';
589 if ($real_null_value && !$field['first_timestamp']) {
590 echo ' checked="checked"';
592 echo ' id="field_' . ($idindex) . '_2"';
593 $onclick = ' onclick="if (this.checked) {nullify(';
594 if (strstr($field['True_Type'], 'enum')) {
595 if (strlen($field['Type']) > 20) {
600 } elseif (strstr($field['True_Type'], 'set')) {
602 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) {
603 // foreign key in a drop-down
605 } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) {
606 // foreign key with a browsing icon
611 $onclick .= '\'' . PMA_escapeJsString($field['Field_html']) . '\', \'' . $field['Field_md5'] . '\', \'' . PMA_escapeJsString($vkey) . '\'); this.checked = true}; return true" />' . "\n";
614 echo ' <input type="hidden" name="fields_null' . $field_name_appendix . '"';
615 if ($real_null_value && !$field['first_timestamp']) {
621 echo ' </td>' . "\n";
623 // The value column (depends on type)
625 // See bug #1667887 for the reason why we don't use the maxlength
629 if ($foreignData['foreign_link'] == true) {
630 echo $backup_field . "\n";
632 <input type
="hidden" name
="fields_type<?php echo $field_name_appendix; ?>"
634 <input type
="hidden" name
="fields<?php echo $field_name_appendix; ?>"
635 value
="" id
="field_<?php echo ($idindex); ?>_3A" />
636 <input type
="text" name
="field_<?php echo $field_name_appendix_md5; ?>"
637 class="textfield" <?php
echo $unnullify_trigger; ?
>
638 tabindex
="<?php echo ($tabindex + $tabindex_for_value); ?>"
639 id
="field_<?php echo ($idindex); ?>_3"
640 value
="<?php echo htmlspecialchars($data); ?>" />
641 <script type
="text/javascript">
643 document
.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes,resizable=yes\'); return false"');
644 document
.write(' href="browse_foreigners.php?');
645 document
.write('<?php echo PMA_generate_common_url($db, $table); ?>');
646 document
.writeln('&field=<?php echo PMA_escapeJsString(urlencode($field['Field
']) . $browse_foreigners_uri); ?>">');
647 document
.writeln('<?php echo str_replace("'", "\'
", $titles['Browse']); ?></a>');
651 } elseif (is_array($foreignData['disp_row'])) {
652 echo $backup_field . "\n
";
654 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>"
656 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>"
657 value="" id="field_
<?php
echo $idindex; ?
>_3A
" />
658 <select name="field_
<?php
echo $field_name_appendix_md5; ?
>"
659 <?php echo $unnullify_trigger; ?>
660 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
661 id="field_
<?php
echo ($idindex); ?
>_3
">
662 <?php echo PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $cfg['ForeignKeyMaxLimit']); ?>
666 unset($foreignData['disp_row']);
667 } elseif ($cfg['LongtextDoubleTextarea'] && strstr($field['pma_type'], 'longtext')) {
671 <tr class="<?php
echo $odd_row ?
'odd' : 'even'; ?
>">
672 <td colspan="5" align="right
">
673 <?php echo $backup_field . "\n
"; ?>
674 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
675 rows="<?php
echo ($cfg['TextareaRows']*2); ?
>"
676 cols="<?php
echo ($cfg['TextareaCols']*2); ?
>"
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>
683 } elseif (strstr($field['pma_type'], 'text')) {
684 echo $backup_field . "\n
";
686 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
687 rows="<?php
echo $cfg['TextareaRows']; ?
>"
688 cols="<?php
echo $cfg['TextareaCols']; ?
>"
689 dir="<?php
echo $text_dir; ?
>"
690 id="field_
<?php
echo ($idindex); ?
>_3
"
691 <?php echo $unnullify_trigger; ?>
692 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
693 ><?php echo $special_chars_encoded; ?></textarea>
696 if (strlen($special_chars) > 32000) {
698 echo ' <td>' . $strTextAreaLength;
700 } elseif ($field['pma_type'] == 'enum') {
701 if (! isset($table_fields[$i]['values'])) {
702 $table_fields[$i]['values'] = array();
703 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
704 // Removes automatic MySQL escape format
705 $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
706 $table_fields[$i]['values'][] = array(
708 'html' => htmlspecialchars($val),
712 $field_enum_values = $table_fields[$i]['values'];
714 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="enum
" />
715 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>" value="" />
717 echo "\n
" . ' ' . $backup_field . "\n
";
719 // show dropdown or radio depend on length
720 if (strlen($field['Type']) > 20) {
722 <select name="field_
<?php
echo $field_name_appendix_md5; ?
>"
723 <?php echo $unnullify_trigger; ?>
724 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
725 id="field_
<?php
echo ($idindex); ?
>_3
">
726 <option value=""> </option>
730 foreach ($field_enum_values as $enum_value) {
732 echo '<option value="' . $enum_value['html
'] . '"';
733 if ($data == $enum_value['plain']
735 && (! isset($primary_key) || $field['Null'] != 'YES')
736 && isset($field['Default'])
737 && $enum_value['plain'] == $field['Default'])) {
738 echo ' selected="selected
"';
740 echo '>' . $enum_value['html'] . '</option>' . "\n
";
748 foreach ($field_enum_values as $enum_value) {
750 echo '<input type="radio
" name="field_
' . $field_name_appendix_md5 . '"';
751 echo ' value="' . $enum_value['html
'] . '"';
752 echo ' id="field_
' . ($idindex) . '_3_
' . $j . '"';
753 echo $unnullify_trigger;
754 if ($data == $enum_value['plain']
756 && (! isset($primary_key) || $field['Null'] != 'YES')
757 && isset($field['Default'])
758 && $enum_value['plain'] == $field['Default'])) {
759 echo ' checked="checked
"';
761 echo ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
762 echo '<label for="field_
' . $idindex . '_3_
' . $j . '">'
763 . $enum_value['html'] . '</label>' . "\n
";
767 } elseif ($field['pma_type'] == 'set') {
768 if (! isset($table_fields[$i]['values'])) {
769 $table_fields[$i]['values'] = array();
770 foreach ($extracted_fieldspec['enum_set_values'] as $val) {
771 $table_fields[$i]['values'][] = array(
773 'html' => htmlspecialchars($val),
776 $table_fields[$i]['select_size'] = min(4, count($table_fields[$i]['values']));
778 $field_set_values = $table_fields[$i]['values'];
779 $select_size = $table_fields[$i]['select_size'];
781 $vset = array_flip(explode(',', $data));
782 echo $backup_field . "\n
";
784 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="set
" />
785 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>" value="" />
786 <select name="field_
<?php
echo $field_name_appendix_md5; ?
>"
787 size="<?php
echo $select_size; ?
>"
788 multiple="multiple
" <?php echo $unnullify_trigger; ?>
789 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
790 id="field_
<?php
echo ($idindex); ?
>_3
">
792 foreach ($field_set_values as $field_set_value) {
794 echo '<option value="' . $field_set_value['html
'] . '"';
795 if (isset($vset[$field_set_value['plain']])) {
796 echo ' selected="selected
"';
798 echo '>' . $field_set_value['html'] . '</option>' . "\n
";
804 // Change by Bernard M. Piller <bernard@bmpsystems.com>
805 // We don't want binary data destroyed
806 elseif ($field['is_binary'] || $field['is_blob']) {
807 if (($cfg['ProtectBinary'] && $field['is_blob'])
808 || ($cfg['ProtectBinary'] == 'all' && $field['is_binary'])) {
810 // rajk - for blobstreaming
811 $bs_reference_exists = FALSE;
813 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
816 $PMA_Config = $_SESSION['PMA_Config'];
818 if (!empty($PMA_Config))
820 $requiredTblType = $PMA_Config->get('PBXT_NAME');
822 if ($requiredTblType == strtolower ($tbl_type))
824 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
826 // check if blobstreaming plugins exist
829 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
831 if (!empty($bs_tables) && strlen($db) > 0)
833 $bs_tables = $bs_tables[$db];
835 if (isset($bs_tables))
837 $allBSTablesExist = TRUE;
839 foreach ($bs_tables as $table_key=>$bs_tbl)
840 if (!$bs_tables[$table_key]['Exists'])
842 $allBSTablesExist = FALSE;
846 if ($allBSTablesExist)
847 $bs_reference_exists = PMA_BS_ReferenceExists($data, $db);
848 } // end if (isset($bs_tables))
849 } // end if (!empty($bs_tables) && strlen($db) > 0)
850 } // end if ($pluginsExist)
851 } // end if ($requiredTblType == strtolower ($tbl_type))
852 } // end if (!empty($PMA_Config))
853 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
855 if ($bs_reference_exists)
857 echo '<input type="hidden
" name="remove_blob_ref_
' . $field['Field_md5
'] . $vkey . '" value="' . $data . '" />';
858 echo '<input type="checkbox
" name="remove_blob_repo_
' . $field['Field_md5
'] . $vkey . '" /> ' . $strBLOBRepositoryRemove . "<br
/>";
859 echo PMA_BS_CreateReferenceLink($data, $db);
864 echo $strBinaryDoNotEdit;
866 $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
867 echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
871 } // end if ($bs_reference_exists)
873 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="protected" />
874 <input type="hidden
" name="fields
<?php
echo $field_name_appendix; ?
>" value="" />
876 } elseif ($field['is_blob']) {
878 echo $backup_field . "\n
";
880 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
881 rows="<?php
echo $cfg['TextareaRows']; ?
>"
882 cols="<?php
echo $cfg['TextareaCols']; ?
>"
883 dir="<?php
echo $text_dir; ?
>"
884 id="field_
<?php
echo ($idindex); ?
>_3
"
885 <?php echo $unnullify_trigger; ?>
886 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
887 ><?php echo $special_chars_encoded; ?></textarea>
891 // field size should be at least 4 and max 40
892 $fieldsize = min(max($field['len'], 4), 40);
894 echo $backup_field . "\n
";
896 <input type="text
" name="fields
<?php
echo $field_name_appendix; ?
>"
897 value="<?php
echo $special_chars; ?
>" size="<?php
echo $fieldsize; ?
>"
898 class="textfield
" <?php echo $unnullify_trigger; ?>
899 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
900 id="field_
<?php
echo ($idindex); ?
>_3
" />
902 } // end if...elseif...else
904 // Upload choice (only for BLOBs because the binary
905 // attribute does not imply binary contents)
906 // (displayed whatever value the ProtectBinary has)
908 if ($is_upload && $field['is_blob']) {
910 // check if field type is of longblob
911 if ($field['pma_type'] == "longblob
")
913 if (isset ($tbl_type) && strlen ($tbl_type) > 0)
916 $PMA_Config = $_SESSION['PMA_Config'];
918 // is PMA_Config's data loaded? continue only if it is
919 if (!empty($PMA_Config))
921 $requiredTblType = $PMA_Config->get('PBXT_NAME');
923 if ($requiredTblType == strtolower ($tbl_type))
925 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
927 // check if blobstreaming plugins exist
930 $curlExists = $PMA_Config->get('CURL_EXISTS');
932 // check if CURL exists
935 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
937 // check for BLOBStreamable databases and if current database name is provided
938 if (!empty($bs_tables) && strlen($db) > 0)
940 $bs_tables = $bs_tables[$db];
942 // check if reference to BLOBStreaming tables exists
943 if (isset($bs_tables))
945 $allBSTablesExist = TRUE;
947 foreach ($bs_tables as $table_key=>$bs_tbl)
948 if (!$bs_tables[$table_key]['Exists'])
950 $allBSTablesExist = FALSE;
954 // check if necessary BLOBStreaming tables exist
955 if ($allBSTablesExist)
958 echo '<input type="checkbox
" name="upload_blob_repo_
' . $field['Field_md5
'] . $vkey . '" /> ' . $strBLOBRepositoryUpload;
959 } // end if ($allBSTablesExist)
960 } // end if (isset($bs_tables)
961 } // end if (!empty($bs_tables) && strlen ($db) > 0)
962 } // end if ($curlExists)
963 } // end if ($pluginsExist)
964 } // end if ($requiredTblType == strtolower ($tbl_type))
965 } // end if (!empty($PMA_Config))
966 } // end if (isset ($tbl_type) && strlen ($tbl_type) > 0)
970 echo '<input type="file
" name="fields_upload_
' . $field['Field_md5
'] . $vkey . '" class="textfield
" id="field_
' . $idindex . '_3
" size="10" /> ';
972 // find maximum upload size, based on field type
974 * @todo with functions this is not so easy, as you can basically
975 * process any data with function like MD5
977 $max_field_sizes = array(
980 'mediumblob' => '16777216',
981 'longblob' => '4294967296'); // yeah, really
983 $this_field_max_size = $max_upload_size; // from PHP max
984 if ($this_field_max_size > $max_field_sizes[$field['pma_type']]) {
985 $this_field_max_size = $max_field_sizes[$field['pma_type']];
987 echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n
";
988 // do not generate here the MAX_FILE_SIZE, because we should
989 // put only one in the form to accommodate the biggest field
990 if ($this_field_max_size > $biggest_max_file_size) {
991 $biggest_max_file_size = $this_field_max_size;
995 if (!empty($cfg['UploadDir'])) {
996 $files = PMA_getFileSelectOptions(PMA_userDir($cfg['UploadDir']));
997 if ($files === FALSE) {
998 echo ' <font color="red
">' . $strError . '</font><br />' . "\n
";
999 echo ' ' . $strWebServerUploadDirectoryError . "\n
";
1000 } elseif (!empty($files)) {
1002 echo ' <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ':<br />' . "\n
";
1003 echo ' <select size="1" name="fields_uploadlocal_
' . $field['Field_md5
'] . $vkey . '">' . "\n
";
1004 echo ' <option value="" selected="selected
"></option>' . "\n
";
1006 echo ' </select>' . "\n
";
1008 } // end if (web-server upload directory)
1009 } // end elseif (binary or blob)
1011 // field size should be at least 4 and max 40
1012 $fieldsize = min(max($field['len'], 4), 40);
1013 echo $backup_field . "\n
";
1014 if ($field['is_char'] && ($cfg['CharEditing'] == 'textarea' || strpos($data, "\n
") !== FALSE)) {
1017 <textarea name="fields
<?php
echo $field_name_appendix; ?
>"
1018 rows="<?php
echo $cfg['CharTextareaRows']; ?
>"
1019 cols="<?php
echo $cfg['CharTextareaCols']; ?
>"
1020 dir="<?php
echo $text_dir; ?
>"
1021 id="field_
<?php
echo ($idindex); ?
>_3
"
1022 <?php echo $unnullify_trigger; ?>
1023 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
1024 ><?php echo $special_chars_encoded; ?></textarea>
1028 <input type="text
" name="fields
<?php
echo $field_name_appendix; ?
>"
1029 value="<?php
echo $special_chars; ?
>" size="<?php
echo $fieldsize; ?
>"
1030 class="textfield
" <?php echo $unnullify_trigger; ?>
1031 tabindex="<?php
echo ($tabindex +
$tabindex_for_value); ?
>"
1032 id="field_
<?php
echo ($idindex); ?
>_3
" />
1034 if ($field['Extra'] == 'auto_increment') {
1036 <input type="hidden
" name="auto_increment
<?php
echo $field_name_appendix; ?
>" value="1" />
1039 if (substr($field['pma_type'], 0, 9) == 'timestamp') {
1041 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="timestamp
" />
1044 if ($field['True_Type'] == 'bit') {
1046 <input type="hidden
" name="fields_type
<?php
echo $field_name_appendix; ?
>" value="bit
" />
1049 if ($field['pma_type'] == 'date' || $field['pma_type'] == 'datetime' || substr($field['pma_type'], 0, 9) == 'timestamp') {
1050 // the _3 suffix points to the date field
1051 // the _2 suffix points to the corresponding NULL checkbox
1053 <script type="text
/javascript
">
1055 document.write('<a title="<?php
echo $strCalendar;?
>"');
1056 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\'
)">');
1057 document.write('<img class="calendar
"');
1058 document.write(' src="<?php
echo $pmaThemeImage; ?
>b_calendar
.png
"');
1059 document.write(' alt="<?php
echo $strCalendar; ?
>"/></a>');
1070 $odd_row = !$odd_row;
1073 echo ' </tbody></table><br />';
1074 } // end foreach on multi-edit
1079 <table border="0" cellpadding="5" cellspacing="0">
1081 <td valign="middle
" nowrap="nowrap
">
1082 <select name="submit_type
" tabindex="<?php
echo ($tabindex +
$tabindex_for_value +
1); ?
>">
1084 if (isset($primary_key)) {
1086 <option value="<?php
echo $strSave; ?
>"><?php echo $strSave; ?></option>
1090 <option value="<?php
echo $strInsertAsNewRow; ?
>"><?php echo $strInsertAsNewRow; ?></option>
1095 if (!isset($after_insert)) {
1096 $after_insert = 'back';
1100 <td valign="middle
">
1101 <strong><?php echo $strAndThen; ?></strong>
1103 <td valign="middle
" nowrap="nowrap
">
1104 <select name="after_insert
">
1105 <option value="back
" <?php echo ($after_insert == 'back' ? 'selected="selected
"' : ''); ?>><?php echo $strAfterInsertBack; ?></option>
1106 <option value="new_insert
" <?php echo ($after_insert == 'new_insert' ? 'selected="selected
"' : ''); ?>><?php echo $strAfterInsertNewInsert; ?></option>
1108 if (isset($primary_key)) {
1110 <option value="same_insert
" <?php echo ($after_insert == 'same_insert' ? 'selected="selected
"' : ''); ?>><?php echo $strAfterInsertSame; ?></option>
1112 // If we have just numeric primary key, we can also edit next
1113 // in 2.8.2, we were looking for `field_name` = numeric_value
1114 //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $primary_key)) {
1115 // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
1116 if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $primary_key)) {
1118 <option value="edit_next
" <?php echo ($after_insert == 'edit_next' ? 'selected="selected
"' : ''); ?>><?php echo $strAfterInsertNext; ?></option>
1129 <?php echo PMA_showHint($strUseTabKey); ?>
1131 <td colspan="3" align="right
" valign="middle
">
1132 <input type="submit
" value="<?php
echo $strGo; ?
>" tabindex="<?php
echo ($tabindex +
$tabindex_for_value +
6); ?
>" id="buttonYes
" />
1133 <input type="reset
" value="<?php
echo $strReset; ?
>" tabindex="<?php
echo ($tabindex +
$tabindex_for_value +
7); ?
>" />
1138 <?php if ($biggest_max_file_size > 0) {
1139 echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n
";
1145 <!-- Restart insertion form -->
1146 <form method="post
" action="tbl_replace
.php
" name="restartForm
" >
1147 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
1148 <input type="hidden
" name="goto" value="<?php
echo htmlspecialchars($GLOBALS['goto']); ?
>" />
1149 <input type="hidden
" name="err_url
" value="<?php
echo htmlspecialchars($err_url); ?
>" />
1150 <input type="hidden
" name="sql_query
" value="<?php
echo htmlspecialchars($sql_query); ?
>" />
1152 if (isset($primary_keys)) {
1153 foreach ($primary_key_array as $key_id => $primary_key) {
1154 echo '<input type="hidden
" name="primary_key
[' . $key_id . ']" value="' . htmlspecialchars(trim($primary_key)) . '" />'. "\n
";
1157 $tmp = '<select name="insert_rows
" id="insert_rows
" onchange="this
.form
.submit();" >' . "\n
";
1158 $option_values = array(1,2,5,10,15,20,30,40);
1159 foreach ($option_values as $value) {
1160 $tmp .= '<option value="' . $value . '"';
1161 if ($value == $cfg['InsertRows']) {
1162 $tmp .= ' selected="selected
"';
1164 $tmp .= '>' . $value . '</option>' . "\n
";
1166 $tmp .= '</select>' . "\n
";
1167 echo "\n
" . sprintf($strRestartInsertion, $tmp);
1169 echo '<noscript><input type="submit
" value="' . $strGo . '" /></noscript>' . "\n
";
1170 echo '</form>' . "\n
";
1174 * Displays the footer
1176 require_once './libraries/footer.inc.php';